blob: f5a732847276d9280c23c80abd568d25213ba288 [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"
Alexey Bataev1a3320e2015-08-25 14:24:04 +000024#include "clang/AST/ExprOpenMP.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000025#include "clang/AST/Stmt.h"
26#include "clang/AST/StmtCXX.h"
27#include "clang/AST/StmtObjC.h"
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000028#include "clang/AST/StmtOpenMP.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000029#include "clang/Sema/Designator.h"
30#include "clang/Sema/Lookup.h"
31#include "clang/Sema/Ownership.h"
32#include "clang/Sema/ParsedTemplate.h"
33#include "clang/Sema/ScopeInfo.h"
34#include "clang/Sema/SemaDiagnostic.h"
35#include "clang/Sema/SemaInternal.h"
David Blaikieb9c168a2011-09-22 02:34:54 +000036#include "llvm/ADT/ArrayRef.h"
John McCall550e0c22009-10-21 00:40:46 +000037#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000038#include <algorithm>
39
40namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000041using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000042
Douglas Gregord6ff3322009-08-04 16:50:30 +000043/// \brief A semantic tree transformation that allows one to transform one
44/// abstract syntax tree into another.
45///
Mike Stump11289f42009-09-09 15:08:12 +000046/// A new tree transformation is defined by creating a new subclass \c X of
47/// \c TreeTransform<X> and then overriding certain operations to provide
48/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000049/// instantiation is implemented as a tree transformation where the
50/// transformation of TemplateTypeParmType nodes involves substituting the
51/// template arguments for their corresponding template parameters; a similar
52/// transformation is performed for non-type template parameters and
53/// template template parameters.
54///
55/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000056/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000057/// override any of the transformation or rebuild operators by providing an
58/// operation with the same signature as the default implementation. The
59/// overridding function should not be virtual.
60///
61/// Semantic tree transformations are split into two stages, either of which
62/// can be replaced by a subclass. The "transform" step transforms an AST node
63/// or the parts of an AST node using the various transformation functions,
64/// then passes the pieces on to the "rebuild" step, which constructs a new AST
65/// node of the appropriate kind from the pieces. The default transformation
66/// routines recursively transform the operands to composite AST nodes (e.g.,
67/// the pointee type of a PointerType node) and, if any of those operand nodes
68/// were changed by the transformation, invokes the rebuild operation to create
69/// a new AST node.
70///
Mike Stump11289f42009-09-09 15:08:12 +000071/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000072/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregorfd35cde2011-03-02 18:50:38 +000073/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000074/// TransformTemplateName(), or TransformTemplateArgument() with entirely
75/// new implementations.
76///
77/// For more fine-grained transformations, subclasses can replace any of the
78/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000079/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000080/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000081/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000082/// parameters. Additionally, subclasses can override the \c RebuildXXX
83/// functions to control how AST nodes are rebuilt when their operands change.
84/// By default, \c TreeTransform will invoke semantic analysis to rebuild
85/// AST nodes. However, certain other tree transformations (e.g, cloning) may
86/// be able to use more efficient rebuild steps.
87///
88/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000089/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000090/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
91/// operands have not changed (\c AlwaysRebuild()), and customize the
92/// default locations and entity names used for type-checking
93/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000094template<typename Derived>
95class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000096 /// \brief Private RAII object that helps us forget and then re-remember
97 /// the template argument corresponding to a partially-substituted parameter
98 /// pack.
99 class ForgetPartiallySubstitutedPackRAII {
100 Derived &Self;
101 TemplateArgument Old;
Chad Rosier1dcde962012-08-08 18:46:20 +0000102
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000103 public:
104 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
105 Old = Self.ForgetPartiallySubstitutedPack();
106 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000107
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000108 ~ForgetPartiallySubstitutedPackRAII() {
109 Self.RememberPartiallySubstitutedPack(Old);
110 }
111 };
Chad Rosier1dcde962012-08-08 18:46:20 +0000112
Douglas Gregord6ff3322009-08-04 16:50:30 +0000113protected:
114 Sema &SemaRef;
Chad Rosier1dcde962012-08-08 18:46:20 +0000115
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000116 /// \brief The set of local declarations that have been transformed, for
117 /// cases where we are forced to build new declarations within the transformer
118 /// rather than in the subclass (e.g., lambda closure types).
119 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
Chad Rosier1dcde962012-08-08 18:46:20 +0000120
Mike Stump11289f42009-09-09 15:08:12 +0000121public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000122 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000123 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000124
Douglas Gregord6ff3322009-08-04 16:50:30 +0000125 /// \brief Retrieves a reference to the derived class.
126 Derived &getDerived() { return static_cast<Derived&>(*this); }
127
128 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000129 const Derived &getDerived() const {
130 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000131 }
132
John McCalldadc5752010-08-24 06:29:42 +0000133 static inline ExprResult Owned(Expr *E) { return E; }
134 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000135
Douglas Gregord6ff3322009-08-04 16:50:30 +0000136 /// \brief Retrieves a reference to the semantic analysis object used for
137 /// this tree transform.
138 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000139
Douglas Gregord6ff3322009-08-04 16:50:30 +0000140 /// \brief Whether the transformation should always rebuild AST nodes, even
141 /// if none of the children have changed.
142 ///
143 /// Subclasses may override this function to specify when the transformation
144 /// should rebuild all AST nodes.
Richard Smith2aa81a72013-11-07 20:07:17 +0000145 ///
146 /// We must always rebuild all AST nodes when performing variadic template
147 /// pack expansion, in order to avoid violating the AST invariant that each
148 /// statement node appears at most once in its containing declaration.
149 bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; }
Mike Stump11289f42009-09-09 15:08:12 +0000150
Douglas Gregord6ff3322009-08-04 16:50:30 +0000151 /// \brief Returns the location of the entity being transformed, if that
152 /// information was not available elsewhere in the AST.
153 ///
Mike Stump11289f42009-09-09 15:08:12 +0000154 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000155 /// provide an alternative implementation that provides better location
156 /// information.
157 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000158
Douglas Gregord6ff3322009-08-04 16:50:30 +0000159 /// \brief Returns the name of the entity being transformed, if that
160 /// information was not available elsewhere in the AST.
161 ///
162 /// By default, returns an empty name. Subclasses can provide an alternative
163 /// implementation with a more precise name.
164 DeclarationName getBaseEntity() { return DeclarationName(); }
165
Douglas Gregora16548e2009-08-11 05:31:07 +0000166 /// \brief Sets the "base" location and entity when that
167 /// information is known based on another transformation.
168 ///
169 /// By default, the source location and entity are ignored. Subclasses can
170 /// override this function to provide a customized implementation.
171 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000172
Douglas Gregora16548e2009-08-11 05:31:07 +0000173 /// \brief RAII object that temporarily sets the base location and entity
174 /// used for reporting diagnostics in types.
175 class TemporaryBase {
176 TreeTransform &Self;
177 SourceLocation OldLocation;
178 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000179
Douglas Gregora16548e2009-08-11 05:31:07 +0000180 public:
181 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000182 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000183 OldLocation = Self.getDerived().getBaseLocation();
184 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier1dcde962012-08-08 18:46:20 +0000185
Douglas Gregora518d5b2011-01-25 17:51:48 +0000186 if (Location.isValid())
187 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000188 }
Mike Stump11289f42009-09-09 15:08:12 +0000189
Douglas Gregora16548e2009-08-11 05:31:07 +0000190 ~TemporaryBase() {
191 Self.getDerived().setBase(OldLocation, OldEntity);
192 }
193 };
Mike Stump11289f42009-09-09 15:08:12 +0000194
195 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000196 /// transformed.
197 ///
198 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000199 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000200 /// not change. For example, template instantiation need not traverse
201 /// non-dependent types.
202 bool AlreadyTransformed(QualType T) {
203 return T.isNull();
204 }
205
Douglas Gregord196a582009-12-14 19:27:10 +0000206 /// \brief Determine whether the given call argument should be dropped, e.g.,
207 /// because it is a default argument.
208 ///
209 /// Subclasses can provide an alternative implementation of this routine to
210 /// determine which kinds of call arguments get dropped. By default,
211 /// CXXDefaultArgument nodes are dropped (prior to transformation).
212 bool DropCallArgument(Expr *E) {
213 return E->isDefaultArgument();
214 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000215
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000216 /// \brief Determine whether we should expand a pack expansion with the
217 /// given set of parameter packs into separate arguments by repeatedly
218 /// transforming the pattern.
219 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000220 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000221 /// Subclasses can override this routine to provide different behavior.
222 ///
223 /// \param EllipsisLoc The location of the ellipsis that identifies the
224 /// pack expansion.
225 ///
226 /// \param PatternRange The source range that covers the entire pattern of
227 /// the pack expansion.
228 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000229 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000230 /// pattern.
231 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000232 /// \param ShouldExpand Will be set to \c true if the transformer should
233 /// expand the corresponding pack expansions into separate arguments. When
234 /// set, \c NumExpansions must also be set.
235 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000236 /// \param RetainExpansion Whether the caller should add an unexpanded
237 /// pack expansion after all of the expanded arguments. This is used
238 /// when extending explicitly-specified template argument packs per
239 /// C++0x [temp.arg.explicit]p9.
240 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000241 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000242 /// the expanded form of the corresponding pack expansion. This is both an
243 /// input and an output parameter, which can be set by the caller if the
244 /// number of expansions is known a priori (e.g., due to a prior substitution)
245 /// and will be set by the callee when the number of expansions is known.
246 /// The callee must set this value when \c ShouldExpand is \c true; it may
247 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000248 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000249 /// \returns true if an error occurred (e.g., because the parameter packs
250 /// are to be instantiated with arguments of different lengths), false
251 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000252 /// must be set.
253 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
254 SourceRange PatternRange,
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000255 ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000256 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000257 bool &RetainExpansion,
David Blaikie05785d12013-02-20 22:23:23 +0000258 Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000259 ShouldExpand = false;
260 return false;
261 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000262
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000263 /// \brief "Forget" about the partially-substituted pack template argument,
264 /// when performing an instantiation that must preserve the parameter pack
265 /// use.
266 ///
267 /// This routine is meant to be overridden by the template instantiator.
268 TemplateArgument ForgetPartiallySubstitutedPack() {
269 return TemplateArgument();
270 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000271
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000272 /// \brief "Remember" the partially-substituted pack template argument
273 /// after performing an instantiation that must preserve the parameter pack
274 /// use.
275 ///
276 /// This routine is meant to be overridden by the template instantiator.
277 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000278
Douglas Gregorf3010112011-01-07 16:43:16 +0000279 /// \brief Note to the derived class when a function parameter pack is
280 /// being expanded.
281 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000282
Douglas Gregord6ff3322009-08-04 16:50:30 +0000283 /// \brief Transforms the given type into another type.
284 ///
John McCall550e0c22009-10-21 00:40:46 +0000285 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000286 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000287 /// function. This is expensive, but we don't mind, because
288 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000289 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000290 ///
291 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000292 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000293
John McCall550e0c22009-10-21 00:40:46 +0000294 /// \brief Transforms the given type-with-location into a new
295 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000296 ///
John McCall550e0c22009-10-21 00:40:46 +0000297 /// By default, this routine transforms a type by delegating to the
298 /// appropriate TransformXXXType to build a new type. Subclasses
299 /// may override this function (to take over all type
300 /// transformations) or some set of the TransformXXXType functions
301 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000302 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000303
304 /// \brief Transform the given type-with-location into a new
305 /// type, collecting location information in the given builder
306 /// as necessary.
307 ///
John McCall31f82722010-11-12 08:19:04 +0000308 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000309
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000310 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000311 ///
Mike Stump11289f42009-09-09 15:08:12 +0000312 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000313 /// appropriate TransformXXXStmt function to transform a specific kind of
314 /// statement or the TransformExpr() function to transform an expression.
315 /// Subclasses may override this function to transform statements using some
316 /// other mechanism.
317 ///
318 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000319 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000320
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000321 /// \brief Transform the given statement.
322 ///
323 /// By default, this routine transforms a statement by delegating to the
324 /// appropriate TransformOMPXXXClause function to transform a specific kind
325 /// of clause. Subclasses may override this function to transform statements
326 /// using some other mechanism.
327 ///
328 /// \returns the transformed OpenMP clause.
329 OMPClause *TransformOMPClause(OMPClause *S);
330
Tyler Nowickic724a83e2014-10-12 20:46:07 +0000331 /// \brief Transform the given attribute.
332 ///
333 /// By default, this routine transforms a statement by delegating to the
334 /// appropriate TransformXXXAttr function to transform a specific kind
335 /// of attribute. Subclasses may override this function to transform
336 /// attributed statements using some other mechanism.
337 ///
338 /// \returns the transformed attribute
339 const Attr *TransformAttr(const Attr *S);
340
341/// \brief Transform the specified attribute.
342///
343/// Subclasses should override the transformation of attributes with a pragma
344/// spelling to transform expressions stored within the attribute.
345///
346/// \returns the transformed attribute.
347#define ATTR(X)
348#define PRAGMA_SPELLING_ATTR(X) \
349 const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; }
350#include "clang/Basic/AttrList.inc"
351
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000352 /// \brief Transform the given expression.
353 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000354 /// By default, this routine transforms an expression by delegating to the
355 /// appropriate TransformXXXExpr function to build a new expression.
356 /// Subclasses may override this function to transform expressions using some
357 /// other mechanism.
358 ///
359 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000360 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000361
Richard Smithd59b8322012-12-19 01:39:02 +0000362 /// \brief Transform the given initializer.
363 ///
364 /// By default, this routine transforms an initializer by stripping off the
365 /// semantic nodes added by initialization, then passing the result to
366 /// TransformExpr or TransformExprs.
367 ///
368 /// \returns the transformed initializer.
Richard Smithc6abd962014-07-25 01:12:44 +0000369 ExprResult TransformInitializer(Expr *Init, bool NotCopyInit);
Richard Smithd59b8322012-12-19 01:39:02 +0000370
Douglas Gregora3efea12011-01-03 19:04:46 +0000371 /// \brief Transform the given list of expressions.
372 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000373 /// This routine transforms a list of expressions by invoking
374 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregora3efea12011-01-03 19:04:46 +0000375 /// support for variadic templates by expanding any pack expansions (if the
376 /// derived class permits such expansion) along the way. When pack expansions
377 /// are present, the number of outputs may not equal the number of inputs.
378 ///
379 /// \param Inputs The set of expressions to be transformed.
380 ///
381 /// \param NumInputs The number of expressions in \c Inputs.
382 ///
383 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier1dcde962012-08-08 18:46:20 +0000384 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregora3efea12011-01-03 19:04:46 +0000385 /// be.
386 ///
387 /// \param Outputs The transformed input expressions will be added to this
388 /// vector.
389 ///
390 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
391 /// due to transformation.
392 ///
393 /// \returns true if an error occurred, false otherwise.
Craig Topper99d23532015-12-24 23:58:29 +0000394 bool TransformExprs(Expr *const *Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000395 SmallVectorImpl<Expr *> &Outputs,
Craig Topperc3ec1492014-05-26 06:22:03 +0000396 bool *ArgChanged = nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000397
Douglas Gregord6ff3322009-08-04 16:50:30 +0000398 /// \brief Transform the given declaration, which is referenced from a type
399 /// or expression.
400 ///
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000401 /// By default, acts as the identity function on declarations, unless the
402 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregor1135c352009-08-06 05:28:30 +0000403 /// may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000404 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000405 llvm::DenseMap<Decl *, Decl *>::iterator Known
406 = TransformedLocalDecls.find(D);
407 if (Known != TransformedLocalDecls.end())
408 return Known->second;
Chad Rosier1dcde962012-08-08 18:46:20 +0000409
410 return D;
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000411 }
Douglas Gregorebe10102009-08-20 07:17:43 +0000412
Chad Rosier1dcde962012-08-08 18:46:20 +0000413 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000414 /// place them on the new declaration.
415 ///
416 /// By default, this operation does nothing. Subclasses may override this
417 /// behavior to transform attributes.
418 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000419
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000420 /// \brief Note that a local declaration has been transformed by this
421 /// transformer.
422 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000423 /// Local declarations are typically transformed via a call to
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000424 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
425 /// the transformer itself has to transform the declarations. This routine
426 /// can be overridden by a subclass that keeps track of such mappings.
427 void transformedLocalDecl(Decl *Old, Decl *New) {
428 TransformedLocalDecls[Old] = New;
429 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000430
Douglas Gregorebe10102009-08-20 07:17:43 +0000431 /// \brief Transform the definition of the given declaration.
432 ///
Mike Stump11289f42009-09-09 15:08:12 +0000433 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000434 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000435 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
436 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000437 }
Mike Stump11289f42009-09-09 15:08:12 +0000438
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000439 /// \brief Transform the given declaration, which was the first part of a
440 /// nested-name-specifier in a member access expression.
441 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000442 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000443 /// identifier in a nested-name-specifier of a member access expression, e.g.,
444 /// the \c T in \c x->T::member
445 ///
446 /// By default, invokes TransformDecl() to transform the declaration.
447 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000448 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
449 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000450 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000451
Douglas Gregor14454802011-02-25 02:25:35 +0000452 /// \brief Transform the given nested-name-specifier with source-location
453 /// information.
454 ///
455 /// By default, transforms all of the types and declarations within the
456 /// nested-name-specifier. Subclasses may override this function to provide
457 /// alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000458 NestedNameSpecifierLoc
459 TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
460 QualType ObjectType = QualType(),
461 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor14454802011-02-25 02:25:35 +0000462
Douglas Gregorf816bd72009-09-03 22:13:48 +0000463 /// \brief Transform the given declaration name.
464 ///
465 /// By default, transforms the types of conversion function, constructor,
466 /// and destructor names and then (if needed) rebuilds the declaration name.
467 /// Identifiers and selectors are returned unmodified. Sublcasses may
468 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000469 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000470 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000471
Douglas Gregord6ff3322009-08-04 16:50:30 +0000472 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000473 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000474 /// \param SS The nested-name-specifier that qualifies the template
475 /// name. This nested-name-specifier must already have been transformed.
476 ///
477 /// \param Name The template name to transform.
478 ///
479 /// \param NameLoc The source location of the template name.
480 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000481 /// \param ObjectType If we're translating a template name within a member
Douglas Gregor9db53502011-03-02 18:07:45 +0000482 /// access expression, this is the type of the object whose member template
483 /// is being referenced.
484 ///
485 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
486 /// also refers to a name within the current (lexical) scope, this is the
487 /// declaration it refers to.
488 ///
489 /// By default, transforms the template name by transforming the declarations
490 /// and nested-name-specifiers that occur within the template name.
491 /// Subclasses may override this function to provide alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000492 TemplateName
493 TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
494 SourceLocation NameLoc,
495 QualType ObjectType = QualType(),
496 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor9db53502011-03-02 18:07:45 +0000497
Douglas Gregord6ff3322009-08-04 16:50:30 +0000498 /// \brief Transform the given template argument.
499 ///
Mike Stump11289f42009-09-09 15:08:12 +0000500 /// By default, this operation transforms the type, expression, or
501 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000502 /// new template argument from the transformed result. Subclasses may
503 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000504 ///
505 /// Returns true if there was an error.
506 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +0000507 TemplateArgumentLoc &Output,
508 bool Uneval = false);
John McCall0ad16662009-10-29 08:12:44 +0000509
Douglas Gregor62e06f22010-12-20 17:31:10 +0000510 /// \brief Transform the given set of template arguments.
511 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000512 /// By default, this operation transforms all of the template arguments
Douglas Gregor62e06f22010-12-20 17:31:10 +0000513 /// in the input set using \c TransformTemplateArgument(), and appends
514 /// the transformed arguments to the output list.
515 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000516 /// Note that this overload of \c TransformTemplateArguments() is merely
517 /// a convenience function. Subclasses that wish to override this behavior
518 /// should override the iterator-based member template version.
519 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000520 /// \param Inputs The set of template arguments to be transformed.
521 ///
522 /// \param NumInputs The number of template arguments in \p Inputs.
523 ///
524 /// \param Outputs The set of transformed template arguments output by this
525 /// routine.
526 ///
527 /// Returns true if an error occurred.
528 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
529 unsigned NumInputs,
Richard Smithd784e682015-09-23 21:41:42 +0000530 TemplateArgumentListInfo &Outputs,
531 bool Uneval = false) {
532 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs,
533 Uneval);
Douglas Gregorfe921a72010-12-20 23:36:19 +0000534 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000535
536 /// \brief Transform the given set of template arguments.
537 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000538 /// By default, this operation transforms all of the template arguments
Douglas Gregor42cafa82010-12-20 17:42:22 +0000539 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier1dcde962012-08-08 18:46:20 +0000540 /// the transformed arguments to the output list.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000541 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000542 /// \param First An iterator to the first template argument.
543 ///
544 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000545 ///
546 /// \param Outputs The set of transformed template arguments output by this
547 /// routine.
548 ///
549 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000550 template<typename InputIterator>
551 bool TransformTemplateArguments(InputIterator First,
552 InputIterator Last,
Richard Smithd784e682015-09-23 21:41:42 +0000553 TemplateArgumentListInfo &Outputs,
554 bool Uneval = false);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000555
John McCall0ad16662009-10-29 08:12:44 +0000556 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
557 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
558 TemplateArgumentLoc &ArgLoc);
559
John McCallbcd03502009-12-07 02:54:59 +0000560 /// \brief Fakes up a TypeSourceInfo for a type.
561 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
562 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000563 getDerived().getBaseLocation());
564 }
Mike Stump11289f42009-09-09 15:08:12 +0000565
John McCall550e0c22009-10-21 00:40:46 +0000566#define ABSTRACT_TYPELOC(CLASS, PARENT)
567#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000568 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000569#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000570
Richard Smith2e321552014-11-12 02:00:47 +0000571 template<typename Fn>
Douglas Gregor3024f072012-04-16 07:05:22 +0000572 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
573 FunctionProtoTypeLoc TL,
574 CXXRecordDecl *ThisContext,
Richard Smith2e321552014-11-12 02:00:47 +0000575 unsigned ThisTypeQuals,
576 Fn TransformExceptionSpec);
577
578 bool TransformExceptionSpec(SourceLocation Loc,
579 FunctionProtoType::ExceptionSpecInfo &ESI,
580 SmallVectorImpl<QualType> &Exceptions,
581 bool &Changed);
Douglas Gregor3024f072012-04-16 07:05:22 +0000582
David Majnemerfad8f482013-10-15 09:33:02 +0000583 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000584
Chad Rosier1dcde962012-08-08 18:46:20 +0000585 QualType
John McCall31f82722010-11-12 08:19:04 +0000586 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
587 TemplateSpecializationTypeLoc TL,
588 TemplateName Template);
589
Chad Rosier1dcde962012-08-08 18:46:20 +0000590 QualType
John McCall31f82722010-11-12 08:19:04 +0000591 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
592 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000593 TemplateName Template,
594 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000595
Nico Weberc153d242014-07-28 00:02:09 +0000596 QualType TransformDependentTemplateSpecializationType(
597 TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL,
598 NestedNameSpecifierLoc QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000599
John McCall58f10c32010-03-11 09:03:00 +0000600 /// \brief Transforms the parameters of a function type into the
601 /// given vectors.
602 ///
603 /// The result vectors should be kept in sync; null entries in the
604 /// variables vector are acceptable.
605 ///
606 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000607 bool TransformFunctionTypeParams(SourceLocation Loc,
608 ParmVarDecl **Params, unsigned NumParams,
609 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000610 SmallVectorImpl<QualType> &PTypes,
611 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000612
613 /// \brief Transforms a single function-type parameter. Return null
614 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000615 ///
616 /// \param indexAdjustment - A number to add to the parameter's
617 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000618 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000619 int indexAdjustment,
David Blaikie05785d12013-02-20 22:23:23 +0000620 Optional<unsigned> NumExpansions,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +0000621 bool ExpectParameterPack);
John McCall58f10c32010-03-11 09:03:00 +0000622
John McCall31f82722010-11-12 08:19:04 +0000623 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000624
John McCalldadc5752010-08-24 06:29:42 +0000625 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
626 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Richard Smith2589b9802012-07-25 03:56:55 +0000627
Faisal Vali2cba1332013-10-23 06:44:28 +0000628 TemplateParameterList *TransformTemplateParameterList(
629 TemplateParameterList *TPL) {
630 return TPL;
631 }
632
Richard Smithdb2630f2012-10-21 03:28:35 +0000633 ExprResult TransformAddressOfOperand(Expr *E);
Reid Kleckner32506ed2014-06-12 23:03:48 +0000634
Richard Smithdb2630f2012-10-21 03:28:35 +0000635 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +0000636 bool IsAddressOfOperand,
637 TypeSourceInfo **RecoveryTSI);
638
639 ExprResult TransformParenDependentScopeDeclRefExpr(
640 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
641 TypeSourceInfo **RecoveryTSI);
642
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000643 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000644
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000645// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
646// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000647#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000648 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000649 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000650#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000651 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000652 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000653#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000654#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000655
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000656#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000657 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000658 OMPClause *Transform ## Class(Class *S);
659#include "clang/Basic/OpenMPKinds.def"
660
Douglas Gregord6ff3322009-08-04 16:50:30 +0000661 /// \brief Build a new pointer type given its pointee type.
662 ///
663 /// By default, performs semantic analysis when building the pointer type.
664 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000665 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000666
667 /// \brief Build a new block pointer type given its pointee type.
668 ///
Mike Stump11289f42009-09-09 15:08:12 +0000669 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000670 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000671 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000672
John McCall70dd5f62009-10-30 00:06:24 +0000673 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000674 ///
John McCall70dd5f62009-10-30 00:06:24 +0000675 /// By default, performs semantic analysis when building the
676 /// reference type. Subclasses may override this routine to provide
677 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000678 ///
John McCall70dd5f62009-10-30 00:06:24 +0000679 /// \param LValue whether the type was written with an lvalue sigil
680 /// or an rvalue sigil.
681 QualType RebuildReferenceType(QualType ReferentType,
682 bool LValue,
683 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000684
Douglas Gregord6ff3322009-08-04 16:50:30 +0000685 /// \brief Build a new member pointer type given the pointee type and the
686 /// class type it refers into.
687 ///
688 /// By default, performs semantic analysis when building the member pointer
689 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000690 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
691 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000692
Douglas Gregor9bda6cf2015-07-07 03:58:14 +0000693 /// \brief Build an Objective-C object type.
694 ///
695 /// By default, performs semantic analysis when building the object type.
696 /// Subclasses may override this routine to provide different behavior.
697 QualType RebuildObjCObjectType(QualType BaseType,
698 SourceLocation Loc,
699 SourceLocation TypeArgsLAngleLoc,
700 ArrayRef<TypeSourceInfo *> TypeArgs,
701 SourceLocation TypeArgsRAngleLoc,
702 SourceLocation ProtocolLAngleLoc,
703 ArrayRef<ObjCProtocolDecl *> Protocols,
704 ArrayRef<SourceLocation> ProtocolLocs,
705 SourceLocation ProtocolRAngleLoc);
706
707 /// \brief Build a new Objective-C object pointer type given the pointee type.
708 ///
709 /// By default, directly builds the pointer type, with no additional semantic
710 /// analysis.
711 QualType RebuildObjCObjectPointerType(QualType PointeeType,
712 SourceLocation Star);
713
Douglas Gregord6ff3322009-08-04 16:50:30 +0000714 /// \brief Build a new array type given the element type, size
715 /// modifier, size of the array (if known), size expression, and index type
716 /// qualifiers.
717 ///
718 /// By default, performs semantic analysis when building the array type.
719 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000720 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000721 QualType RebuildArrayType(QualType ElementType,
722 ArrayType::ArraySizeModifier SizeMod,
723 const llvm::APInt *Size,
724 Expr *SizeExpr,
725 unsigned IndexTypeQuals,
726 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000727
Douglas Gregord6ff3322009-08-04 16:50:30 +0000728 /// \brief Build a new constant array type given the element type, size
729 /// modifier, (known) size of the array, and index type qualifiers.
730 ///
731 /// By default, performs semantic analysis when building the array type.
732 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000733 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000734 ArrayType::ArraySizeModifier SizeMod,
735 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000736 unsigned IndexTypeQuals,
737 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000738
Douglas Gregord6ff3322009-08-04 16:50:30 +0000739 /// \brief Build a new incomplete array type given the element type, size
740 /// modifier, and index type qualifiers.
741 ///
742 /// By default, performs semantic analysis when building the array type.
743 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000744 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000745 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000746 unsigned IndexTypeQuals,
747 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000748
Mike Stump11289f42009-09-09 15:08:12 +0000749 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000750 /// size modifier, size expression, and index type qualifiers.
751 ///
752 /// By default, performs semantic analysis when building the array type.
753 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000754 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000755 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000756 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000757 unsigned IndexTypeQuals,
758 SourceRange BracketsRange);
759
Mike Stump11289f42009-09-09 15:08:12 +0000760 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000761 /// size modifier, size expression, and index type qualifiers.
762 ///
763 /// By default, performs semantic analysis when building the array type.
764 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000765 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000766 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000767 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000768 unsigned IndexTypeQuals,
769 SourceRange BracketsRange);
770
771 /// \brief Build a new vector type given the element type and
772 /// number of elements.
773 ///
774 /// By default, performs semantic analysis when building the vector type.
775 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000776 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000777 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000778
Douglas Gregord6ff3322009-08-04 16:50:30 +0000779 /// \brief Build a new extended vector type given the element type and
780 /// number of elements.
781 ///
782 /// By default, performs semantic analysis when building the vector type.
783 /// Subclasses may override this routine to provide different behavior.
784 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
785 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000786
787 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000788 /// given the element type and number of elements.
789 ///
790 /// By default, performs semantic analysis when building the vector type.
791 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000792 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000793 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000794 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000795
Douglas Gregord6ff3322009-08-04 16:50:30 +0000796 /// \brief Build a new function type.
797 ///
798 /// By default, performs semantic analysis when building the function type.
799 /// Subclasses may override this routine to provide different behavior.
800 QualType RebuildFunctionProtoType(QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +0000801 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000802 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000803
John McCall550e0c22009-10-21 00:40:46 +0000804 /// \brief Build a new unprototyped function type.
805 QualType RebuildFunctionNoProtoType(QualType ResultType);
806
John McCallb96ec562009-12-04 22:46:56 +0000807 /// \brief Rebuild an unresolved typename type, given the decl that
808 /// the UnresolvedUsingTypenameDecl was transformed to.
809 QualType RebuildUnresolvedUsingType(Decl *D);
810
Douglas Gregord6ff3322009-08-04 16:50:30 +0000811 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000812 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000813 return SemaRef.Context.getTypeDeclType(Typedef);
814 }
815
816 /// \brief Build a new class/struct/union type.
817 QualType RebuildRecordType(RecordDecl *Record) {
818 return SemaRef.Context.getTypeDeclType(Record);
819 }
820
821 /// \brief Build a new Enum type.
822 QualType RebuildEnumType(EnumDecl *Enum) {
823 return SemaRef.Context.getTypeDeclType(Enum);
824 }
John McCallfcc33b02009-09-05 00:15:47 +0000825
Mike Stump11289f42009-09-09 15:08:12 +0000826 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000827 ///
828 /// By default, performs semantic analysis when building the typeof type.
829 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000830 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000831
Mike Stump11289f42009-09-09 15:08:12 +0000832 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000833 ///
834 /// By default, builds a new TypeOfType with the given underlying type.
835 QualType RebuildTypeOfType(QualType Underlying);
836
Alexis Hunte852b102011-05-24 22:41:36 +0000837 /// \brief Build a new unary transform type.
838 QualType RebuildUnaryTransformType(QualType BaseType,
839 UnaryTransformType::UTTKind UKind,
840 SourceLocation Loc);
841
Richard Smith74aeef52013-04-26 16:15:35 +0000842 /// \brief Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000843 ///
844 /// By default, performs semantic analysis when building the decltype type.
845 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000846 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000847
Richard Smith74aeef52013-04-26 16:15:35 +0000848 /// \brief Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000849 ///
850 /// By default, builds a new AutoType with the given deduced type.
Richard Smithe301ba22015-11-11 02:02:15 +0000851 QualType RebuildAutoType(QualType Deduced, AutoTypeKeyword Keyword) {
Richard Smith27d807c2013-04-30 13:56:41 +0000852 // Note, IsDependent is always false here: we implicitly convert an 'auto'
853 // which has been deduced to a dependent type into an undeduced 'auto', so
854 // that we'll retry deduction after the transformation.
Richard Smithe301ba22015-11-11 02:02:15 +0000855 return SemaRef.Context.getAutoType(Deduced, Keyword,
Faisal Vali2b391ab2013-09-26 19:54:12 +0000856 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000857 }
858
Douglas Gregord6ff3322009-08-04 16:50:30 +0000859 /// \brief Build a new template specialization type.
860 ///
861 /// By default, performs semantic analysis when building the template
862 /// specialization type. Subclasses may override this routine to provide
863 /// different behavior.
864 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000865 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000866 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000867
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000868 /// \brief Build a new parenthesized type.
869 ///
870 /// By default, builds a new ParenType type from the inner type.
871 /// Subclasses may override this routine to provide different behavior.
872 QualType RebuildParenType(QualType InnerType) {
873 return SemaRef.Context.getParenType(InnerType);
874 }
875
Douglas Gregord6ff3322009-08-04 16:50:30 +0000876 /// \brief Build a new qualified name type.
877 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000878 /// By default, builds a new ElaboratedType type from the keyword,
879 /// the nested-name-specifier and the named type.
880 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000881 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
882 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000883 NestedNameSpecifierLoc QualifierLoc,
884 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000885 return SemaRef.Context.getElaboratedType(Keyword,
886 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000887 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000888 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000889
890 /// \brief Build a new typename type that refers to a template-id.
891 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000892 /// By default, builds a new DependentNameType type from the
893 /// nested-name-specifier and the given type. Subclasses may override
894 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000895 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000896 ElaboratedTypeKeyword Keyword,
897 NestedNameSpecifierLoc QualifierLoc,
898 const IdentifierInfo *Name,
899 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000900 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000901 // Rebuild the template name.
902 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000903 CXXScopeSpec SS;
904 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +0000905 TemplateName InstName
Craig Topperc3ec1492014-05-26 06:22:03 +0000906 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(),
907 nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000908
Douglas Gregora7a795b2011-03-01 20:11:18 +0000909 if (InstName.isNull())
910 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000911
Douglas Gregora7a795b2011-03-01 20:11:18 +0000912 // If it's still dependent, make a dependent specialization.
913 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000914 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
915 QualifierLoc.getNestedNameSpecifier(),
916 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000917 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000918
Douglas Gregora7a795b2011-03-01 20:11:18 +0000919 // Otherwise, make an elaborated type wrapping a non-dependent
920 // specialization.
921 QualType T =
922 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
923 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000924
Craig Topperc3ec1492014-05-26 06:22:03 +0000925 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
Douglas Gregora7a795b2011-03-01 20:11:18 +0000926 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +0000927
928 return SemaRef.Context.getElaboratedType(Keyword,
929 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +0000930 T);
931 }
932
Douglas Gregord6ff3322009-08-04 16:50:30 +0000933 /// \brief Build a new typename type that refers to an identifier.
934 ///
935 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000936 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000937 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000938 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000939 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000940 NestedNameSpecifierLoc QualifierLoc,
941 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000942 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000943 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000944 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000945
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000946 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000947 // If the name is still dependent, just build a new dependent name type.
948 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +0000949 return SemaRef.Context.getDependentNameType(Keyword,
950 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000951 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000952 }
953
Abramo Bagnara6150c882010-05-11 21:36:43 +0000954 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000955 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000956 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000957
958 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
959
Abramo Bagnarad7548482010-05-19 21:37:53 +0000960 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000961 // into a non-dependent elaborated-type-specifier. Find the tag we're
962 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000963 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000964 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
965 if (!DC)
966 return QualType();
967
John McCallbf8c5192010-05-27 06:40:31 +0000968 if (SemaRef.RequireCompleteDeclContext(SS, DC))
969 return QualType();
970
Craig Topperc3ec1492014-05-26 06:22:03 +0000971 TagDecl *Tag = nullptr;
Douglas Gregore677daf2010-03-31 22:19:08 +0000972 SemaRef.LookupQualifiedName(Result, DC);
973 switch (Result.getResultKind()) {
974 case LookupResult::NotFound:
975 case LookupResult::NotFoundInCurrentInstantiation:
976 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000977
Douglas Gregore677daf2010-03-31 22:19:08 +0000978 case LookupResult::Found:
979 Tag = Result.getAsSingle<TagDecl>();
980 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000981
Douglas Gregore677daf2010-03-31 22:19:08 +0000982 case LookupResult::FoundOverloaded:
983 case LookupResult::FoundUnresolvedValue:
984 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +0000985
Douglas Gregore677daf2010-03-31 22:19:08 +0000986 case LookupResult::Ambiguous:
987 // Let the LookupResult structure handle ambiguities.
988 return QualType();
989 }
990
991 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000992 // Check where the name exists but isn't a tag type and use that to emit
993 // better diagnostics.
994 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
995 SemaRef.LookupQualifiedName(Result, DC);
996 switch (Result.getResultKind()) {
997 case LookupResult::Found:
998 case LookupResult::FoundOverloaded:
999 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +00001000 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky0c438082011-01-24 19:01:04 +00001001 unsigned Kind = 0;
1002 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smithdda56e42011-04-15 14:24:37 +00001003 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
1004 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky0c438082011-01-24 19:01:04 +00001005 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
1006 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1007 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +00001008 }
Nick Lewycky0c438082011-01-24 19:01:04 +00001009 default:
Nick Lewycky0c438082011-01-24 19:01:04 +00001010 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +00001011 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +00001012 break;
1013 }
Douglas Gregore677daf2010-03-31 22:19:08 +00001014 return QualType();
1015 }
Abramo Bagnara6150c882010-05-11 21:36:43 +00001016
Richard Trieucaa33d32011-06-10 03:11:26 +00001017 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
Justin Bognerc6ecb7c2015-07-10 23:05:47 +00001018 IdLoc, Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +00001019 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +00001020 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1021 return QualType();
1022 }
1023
1024 // Build the elaborated-type-specifier type.
1025 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +00001026 return SemaRef.Context.getElaboratedType(Keyword,
1027 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001028 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00001029 }
Mike Stump11289f42009-09-09 15:08:12 +00001030
Douglas Gregor822d0302011-01-12 17:07:58 +00001031 /// \brief Build a new pack expansion type.
1032 ///
1033 /// By default, builds a new PackExpansionType type from the given pattern.
1034 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001035 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00001036 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001037 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00001038 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001039 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1040 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +00001041 }
1042
Eli Friedman0dfb8892011-10-06 23:00:33 +00001043 /// \brief Build a new atomic type given its value type.
1044 ///
1045 /// By default, performs semantic analysis when building the atomic type.
1046 /// Subclasses may override this routine to provide different behavior.
1047 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1048
Douglas Gregor71dc5092009-08-06 06:41:21 +00001049 /// \brief Build a new template name given a nested name specifier, a flag
1050 /// indicating whether the "template" keyword was provided, and the template
1051 /// that the template name refers to.
1052 ///
1053 /// By default, builds the new template name directly. Subclasses may override
1054 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001055 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001056 bool TemplateKW,
1057 TemplateDecl *Template);
1058
Douglas Gregor71dc5092009-08-06 06:41:21 +00001059 /// \brief Build a new template name given a nested name specifier and the
1060 /// name that is referred to as a template.
1061 ///
1062 /// By default, performs semantic analysis to determine whether the name can
1063 /// be resolved to a specific template, then builds the appropriate kind of
1064 /// template name. Subclasses may override this routine to provide different
1065 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001066 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1067 const IdentifierInfo &Name,
1068 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00001069 QualType ObjectType,
1070 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001071
Douglas Gregor71395fa2009-11-04 00:56:37 +00001072 /// \brief Build a new template name given a nested name specifier and the
1073 /// overloaded operator name that is referred to as a template.
1074 ///
1075 /// By default, performs semantic analysis to determine whether the name can
1076 /// be resolved to a specific template, then builds the appropriate kind of
1077 /// template name. Subclasses may override this routine to provide different
1078 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001079 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001080 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00001081 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001082 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +00001083
1084 /// \brief Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001085 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001086 ///
1087 /// By default, performs semantic analysis to determine whether the name can
1088 /// be resolved to a specific template, then builds the appropriate kind of
1089 /// template name. Subclasses may override this routine to provide different
1090 /// behavior.
1091 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1092 const TemplateArgument &ArgPack) {
1093 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1094 }
1095
Douglas Gregorebe10102009-08-20 07:17:43 +00001096 /// \brief Build a new compound statement.
1097 ///
1098 /// By default, performs semantic analysis to build the new statement.
1099 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001100 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001101 MultiStmtArg Statements,
1102 SourceLocation RBraceLoc,
1103 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001104 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001105 IsStmtExpr);
1106 }
1107
1108 /// \brief Build a new case statement.
1109 ///
1110 /// By default, performs semantic analysis to build the new statement.
1111 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001112 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001113 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001114 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001115 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001116 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001117 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001118 ColonLoc);
1119 }
Mike Stump11289f42009-09-09 15:08:12 +00001120
Douglas Gregorebe10102009-08-20 07:17:43 +00001121 /// \brief Attach the body to a new case 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 RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001126 getSema().ActOnCaseStmtBody(S, Body);
1127 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001128 }
Mike Stump11289f42009-09-09 15:08:12 +00001129
Douglas Gregorebe10102009-08-20 07:17:43 +00001130 /// \brief Build a new default statement.
1131 ///
1132 /// By default, performs semantic analysis to build the new statement.
1133 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001134 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001135 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001136 Stmt *SubStmt) {
1137 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Craig Topperc3ec1492014-05-26 06:22:03 +00001138 /*CurScope=*/nullptr);
Douglas Gregorebe10102009-08-20 07:17:43 +00001139 }
Mike Stump11289f42009-09-09 15:08:12 +00001140
Douglas Gregorebe10102009-08-20 07:17:43 +00001141 /// \brief Build a new label statement.
1142 ///
1143 /// By default, performs semantic analysis to build the new statement.
1144 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001145 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1146 SourceLocation ColonLoc, Stmt *SubStmt) {
1147 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001148 }
Mike Stump11289f42009-09-09 15:08:12 +00001149
Richard Smithc202b282012-04-14 00:33:13 +00001150 /// \brief Build a new label statement.
1151 ///
1152 /// By default, performs semantic analysis to build the new statement.
1153 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001154 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1155 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001156 Stmt *SubStmt) {
1157 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1158 }
1159
Douglas Gregorebe10102009-08-20 07:17:43 +00001160 /// \brief Build a new "if" statement.
1161 ///
1162 /// By default, performs semantic analysis to build the new statement.
1163 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001164 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier1dcde962012-08-08 18:46:20 +00001165 VarDecl *CondVar, Stmt *Then,
Chris Lattnercab02a62011-02-17 20:34:02 +00001166 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001167 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001168 }
Mike Stump11289f42009-09-09 15:08:12 +00001169
Douglas Gregorebe10102009-08-20 07:17:43 +00001170 /// \brief Start building a new switch statement.
1171 ///
1172 /// By default, performs semantic analysis to build the new statement.
1173 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001174 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001175 Expr *Cond, VarDecl *CondVar) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001176 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001177 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001178 }
Mike Stump11289f42009-09-09 15:08:12 +00001179
Douglas Gregorebe10102009-08-20 07:17:43 +00001180 /// \brief Attach the body to the switch statement.
1181 ///
1182 /// By default, performs semantic analysis to build the new statement.
1183 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001184 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001185 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001186 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001187 }
1188
1189 /// \brief Build a new while statement.
1190 ///
1191 /// By default, performs semantic analysis to build the new statement.
1192 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001193 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1194 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001195 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001196 }
Mike Stump11289f42009-09-09 15:08:12 +00001197
Douglas Gregorebe10102009-08-20 07:17:43 +00001198 /// \brief Build a new do-while statement.
1199 ///
1200 /// By default, performs semantic analysis to build the new statement.
1201 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001202 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001203 SourceLocation WhileLoc, SourceLocation LParenLoc,
1204 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001205 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1206 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001207 }
1208
1209 /// \brief Build a new for statement.
1210 ///
1211 /// By default, performs semantic analysis to build the new statement.
1212 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001213 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier1dcde962012-08-08 18:46:20 +00001214 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001215 VarDecl *CondVar, Sema::FullExprArg Inc,
1216 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001217 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001218 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001219 }
Mike Stump11289f42009-09-09 15:08:12 +00001220
Douglas Gregorebe10102009-08-20 07:17:43 +00001221 /// \brief Build a new goto statement.
1222 ///
1223 /// By default, performs semantic analysis to build the new statement.
1224 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001225 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1226 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001227 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001228 }
1229
1230 /// \brief Build a new indirect goto statement.
1231 ///
1232 /// By default, performs semantic analysis to build the new statement.
1233 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001234 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001235 SourceLocation StarLoc,
1236 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001237 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001238 }
Mike Stump11289f42009-09-09 15:08:12 +00001239
Douglas Gregorebe10102009-08-20 07:17:43 +00001240 /// \brief Build a new return statement.
1241 ///
1242 /// By default, performs semantic analysis to build the new statement.
1243 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001244 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001245 return getSema().BuildReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001246 }
Mike Stump11289f42009-09-09 15:08:12 +00001247
Douglas Gregorebe10102009-08-20 07:17:43 +00001248 /// \brief Build a new declaration statement.
1249 ///
1250 /// By default, performs semantic analysis to build the new statement.
1251 /// Subclasses may override this routine to provide different behavior.
Craig Toppere3d2ecbe2014-06-28 23:22:33 +00001252 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
Rafael Espindolaab417692013-07-09 12:05:01 +00001253 SourceLocation StartLoc, SourceLocation EndLoc) {
1254 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001255 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001256 }
Mike Stump11289f42009-09-09 15:08:12 +00001257
Anders Carlssonaaeef072010-01-24 05:50:09 +00001258 /// \brief Build a new inline asm statement.
1259 ///
1260 /// By default, performs semantic analysis to build the new statement.
1261 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001262 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1263 bool IsVolatile, unsigned NumOutputs,
1264 unsigned NumInputs, IdentifierInfo **Names,
1265 MultiExprArg Constraints, MultiExprArg Exprs,
1266 Expr *AsmString, MultiExprArg Clobbers,
1267 SourceLocation RParenLoc) {
1268 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1269 NumInputs, Names, Constraints, Exprs,
1270 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001271 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001272
Chad Rosier32503022012-06-11 20:47:18 +00001273 /// \brief Build a new MS style inline asm statement.
1274 ///
1275 /// By default, performs semantic analysis to build the new statement.
1276 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001277 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001278 ArrayRef<Token> AsmToks,
1279 StringRef AsmString,
1280 unsigned NumOutputs, unsigned NumInputs,
1281 ArrayRef<StringRef> Constraints,
1282 ArrayRef<StringRef> Clobbers,
1283 ArrayRef<Expr*> Exprs,
1284 SourceLocation EndLoc) {
1285 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1286 NumOutputs, NumInputs,
1287 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001288 }
1289
Richard Smith9f690bd2015-10-27 06:02:45 +00001290 /// \brief Build a new co_return statement.
1291 ///
1292 /// By default, performs semantic analysis to build the new statement.
1293 /// Subclasses may override this routine to provide different behavior.
1294 StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result) {
1295 return getSema().BuildCoreturnStmt(CoreturnLoc, Result);
1296 }
1297
1298 /// \brief Build a new co_await expression.
1299 ///
1300 /// By default, performs semantic analysis to build the new expression.
1301 /// Subclasses may override this routine to provide different behavior.
1302 ExprResult RebuildCoawaitExpr(SourceLocation CoawaitLoc, Expr *Result) {
1303 return getSema().BuildCoawaitExpr(CoawaitLoc, Result);
1304 }
1305
1306 /// \brief Build a new co_yield expression.
1307 ///
1308 /// By default, performs semantic analysis to build the new expression.
1309 /// Subclasses may override this routine to provide different behavior.
1310 ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result) {
1311 return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1312 }
1313
James Dennett2a4d13c2012-06-15 07:13:21 +00001314 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001315 ///
1316 /// By default, performs semantic analysis to build the new statement.
1317 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001318 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001319 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001320 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001321 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001322 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001323 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001324 }
1325
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001326 /// \brief Rebuild an Objective-C exception declaration.
1327 ///
1328 /// By default, performs semantic analysis to build the new declaration.
1329 /// Subclasses may override this routine to provide different behavior.
1330 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1331 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001332 return getSema().BuildObjCExceptionDecl(TInfo, T,
1333 ExceptionDecl->getInnerLocStart(),
1334 ExceptionDecl->getLocation(),
1335 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001336 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001337
James Dennett2a4d13c2012-06-15 07:13:21 +00001338 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001339 ///
1340 /// By default, performs semantic analysis to build the new statement.
1341 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001342 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001343 SourceLocation RParenLoc,
1344 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001345 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001346 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001347 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001348 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001349
James Dennett2a4d13c2012-06-15 07:13:21 +00001350 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001351 ///
1352 /// By default, performs semantic analysis to build the new statement.
1353 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001354 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001355 Stmt *Body) {
1356 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001357 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001358
James Dennett2a4d13c2012-06-15 07:13:21 +00001359 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001360 ///
1361 /// By default, performs semantic analysis to build the new statement.
1362 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001363 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001364 Expr *Operand) {
1365 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001366 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001367
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001368 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001369 ///
1370 /// By default, performs semantic analysis to build the new statement.
1371 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001372 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001373 DeclarationNameInfo DirName,
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001374 OpenMPDirectiveKind CancelRegion,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001375 ArrayRef<OMPClause *> Clauses,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001376 Stmt *AStmt, SourceLocation StartLoc,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001377 SourceLocation EndLoc) {
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001378 return getSema().ActOnOpenMPExecutableDirective(
1379 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001380 }
1381
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001382 /// \brief Build a new OpenMP 'if' clause.
1383 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001384 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001385 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001386 OMPClause *RebuildOMPIfClause(OpenMPDirectiveKind NameModifier,
1387 Expr *Condition, SourceLocation StartLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001388 SourceLocation LParenLoc,
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001389 SourceLocation NameModifierLoc,
1390 SourceLocation ColonLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001391 SourceLocation EndLoc) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001392 return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc,
1393 LParenLoc, NameModifierLoc, ColonLoc,
1394 EndLoc);
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001395 }
1396
Alexey Bataev3778b602014-07-17 07:32:53 +00001397 /// \brief Build a new OpenMP 'final' clause.
1398 ///
1399 /// By default, performs semantic analysis to build the new OpenMP clause.
1400 /// Subclasses may override this routine to provide different behavior.
1401 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1402 SourceLocation LParenLoc,
1403 SourceLocation EndLoc) {
1404 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1405 EndLoc);
1406 }
1407
Alexey Bataev568a8332014-03-06 06:15:19 +00001408 /// \brief Build a new OpenMP 'num_threads' clause.
1409 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001410 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001411 /// Subclasses may override this routine to provide different behavior.
1412 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1413 SourceLocation StartLoc,
1414 SourceLocation LParenLoc,
1415 SourceLocation EndLoc) {
1416 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1417 LParenLoc, EndLoc);
1418 }
1419
Alexey Bataev62c87d22014-03-21 04:51:18 +00001420 /// \brief Build a new OpenMP 'safelen' clause.
1421 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001422 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001423 /// Subclasses may override this routine to provide different behavior.
1424 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1425 SourceLocation LParenLoc,
1426 SourceLocation EndLoc) {
1427 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1428 }
1429
Alexey Bataev66b15b52015-08-21 11:14:16 +00001430 /// \brief Build a new OpenMP 'simdlen' clause.
1431 ///
1432 /// By default, performs semantic analysis to build the new OpenMP clause.
1433 /// Subclasses may override this routine to provide different behavior.
1434 OMPClause *RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc,
1435 SourceLocation LParenLoc,
1436 SourceLocation EndLoc) {
1437 return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc);
1438 }
1439
Alexander Musman8bd31e62014-05-27 15:12:19 +00001440 /// \brief Build a new OpenMP 'collapse' clause.
1441 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001442 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001443 /// Subclasses may override this routine to provide different behavior.
1444 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1445 SourceLocation LParenLoc,
1446 SourceLocation EndLoc) {
1447 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1448 EndLoc);
1449 }
1450
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001451 /// \brief Build a new OpenMP 'default' clause.
1452 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001453 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001454 /// Subclasses may override this routine to provide different behavior.
1455 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1456 SourceLocation KindKwLoc,
1457 SourceLocation StartLoc,
1458 SourceLocation LParenLoc,
1459 SourceLocation EndLoc) {
1460 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1461 StartLoc, LParenLoc, EndLoc);
1462 }
1463
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001464 /// \brief Build a new OpenMP 'proc_bind' clause.
1465 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001466 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001467 /// Subclasses may override this routine to provide different behavior.
1468 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1469 SourceLocation KindKwLoc,
1470 SourceLocation StartLoc,
1471 SourceLocation LParenLoc,
1472 SourceLocation EndLoc) {
1473 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1474 StartLoc, LParenLoc, EndLoc);
1475 }
1476
Alexey Bataev56dafe82014-06-20 07:16:17 +00001477 /// \brief Build a new OpenMP 'schedule' clause.
1478 ///
1479 /// By default, performs semantic analysis to build the new OpenMP clause.
1480 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6402bca2015-12-28 07:25:51 +00001481 OMPClause *RebuildOMPScheduleClause(
1482 OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2,
1483 OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1484 SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1485 SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
Alexey Bataev56dafe82014-06-20 07:16:17 +00001486 return getSema().ActOnOpenMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00001487 M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1488 CommaLoc, EndLoc);
Alexey Bataev56dafe82014-06-20 07:16:17 +00001489 }
1490
Alexey Bataev10e775f2015-07-30 11:36:16 +00001491 /// \brief Build a new OpenMP 'ordered' clause.
1492 ///
1493 /// By default, performs semantic analysis to build the new OpenMP clause.
1494 /// Subclasses may override this routine to provide different behavior.
1495 OMPClause *RebuildOMPOrderedClause(SourceLocation StartLoc,
1496 SourceLocation EndLoc,
1497 SourceLocation LParenLoc, Expr *Num) {
1498 return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num);
1499 }
1500
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001501 /// \brief Build a new OpenMP 'private' clause.
1502 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001503 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001504 /// Subclasses may override this routine to provide different behavior.
1505 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1506 SourceLocation StartLoc,
1507 SourceLocation LParenLoc,
1508 SourceLocation EndLoc) {
1509 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1510 EndLoc);
1511 }
1512
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001513 /// \brief Build a new OpenMP 'firstprivate' clause.
1514 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001515 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001516 /// Subclasses may override this routine to provide different behavior.
1517 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1518 SourceLocation StartLoc,
1519 SourceLocation LParenLoc,
1520 SourceLocation EndLoc) {
1521 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1522 EndLoc);
1523 }
1524
Alexander Musman1bb328c2014-06-04 13:06:39 +00001525 /// \brief Build a new OpenMP 'lastprivate' clause.
1526 ///
1527 /// By default, performs semantic analysis to build the new OpenMP clause.
1528 /// Subclasses may override this routine to provide different behavior.
1529 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1530 SourceLocation StartLoc,
1531 SourceLocation LParenLoc,
1532 SourceLocation EndLoc) {
1533 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1534 EndLoc);
1535 }
1536
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001537 /// \brief Build a new OpenMP 'shared' clause.
1538 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001539 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001540 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001541 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1542 SourceLocation StartLoc,
1543 SourceLocation LParenLoc,
1544 SourceLocation EndLoc) {
1545 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1546 EndLoc);
1547 }
1548
Alexey Bataevc5e02582014-06-16 07:08:35 +00001549 /// \brief Build a new OpenMP 'reduction' clause.
1550 ///
1551 /// By default, performs semantic analysis to build the new statement.
1552 /// Subclasses may override this routine to provide different behavior.
1553 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1554 SourceLocation StartLoc,
1555 SourceLocation LParenLoc,
1556 SourceLocation ColonLoc,
1557 SourceLocation EndLoc,
1558 CXXScopeSpec &ReductionIdScopeSpec,
1559 const DeclarationNameInfo &ReductionId) {
1560 return getSema().ActOnOpenMPReductionClause(
1561 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1562 ReductionId);
1563 }
1564
Alexander Musman8dba6642014-04-22 13:09:42 +00001565 /// \brief Build a new OpenMP 'linear' clause.
1566 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001567 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001568 /// Subclasses may override this routine to provide different behavior.
1569 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1570 SourceLocation StartLoc,
1571 SourceLocation LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001572 OpenMPLinearClauseKind Modifier,
1573 SourceLocation ModifierLoc,
Alexander Musman8dba6642014-04-22 13:09:42 +00001574 SourceLocation ColonLoc,
1575 SourceLocation EndLoc) {
1576 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001577 Modifier, ModifierLoc, ColonLoc,
1578 EndLoc);
Alexander Musman8dba6642014-04-22 13:09:42 +00001579 }
1580
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001581 /// \brief Build a new OpenMP 'aligned' clause.
1582 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001583 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001584 /// Subclasses may override this routine to provide different behavior.
1585 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1586 SourceLocation StartLoc,
1587 SourceLocation LParenLoc,
1588 SourceLocation ColonLoc,
1589 SourceLocation EndLoc) {
1590 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1591 LParenLoc, ColonLoc, EndLoc);
1592 }
1593
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001594 /// \brief Build a new OpenMP 'copyin' clause.
1595 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001596 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001597 /// Subclasses may override this routine to provide different behavior.
1598 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1599 SourceLocation StartLoc,
1600 SourceLocation LParenLoc,
1601 SourceLocation EndLoc) {
1602 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1603 EndLoc);
1604 }
1605
Alexey Bataevbae9a792014-06-27 10:37:06 +00001606 /// \brief Build a new OpenMP 'copyprivate' clause.
1607 ///
1608 /// By default, performs semantic analysis to build the new OpenMP clause.
1609 /// Subclasses may override this routine to provide different behavior.
1610 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1611 SourceLocation StartLoc,
1612 SourceLocation LParenLoc,
1613 SourceLocation EndLoc) {
1614 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1615 EndLoc);
1616 }
1617
Alexey Bataev6125da92014-07-21 11:26:11 +00001618 /// \brief Build a new OpenMP 'flush' pseudo clause.
1619 ///
1620 /// By default, performs semantic analysis to build the new OpenMP clause.
1621 /// Subclasses may override this routine to provide different behavior.
1622 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1623 SourceLocation StartLoc,
1624 SourceLocation LParenLoc,
1625 SourceLocation EndLoc) {
1626 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1627 EndLoc);
1628 }
1629
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001630 /// \brief Build a new OpenMP 'depend' pseudo clause.
1631 ///
1632 /// By default, performs semantic analysis to build the new OpenMP clause.
1633 /// Subclasses may override this routine to provide different behavior.
1634 OMPClause *
1635 RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
1636 SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1637 SourceLocation StartLoc, SourceLocation LParenLoc,
1638 SourceLocation EndLoc) {
1639 return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList,
1640 StartLoc, LParenLoc, EndLoc);
1641 }
1642
Michael Wonge710d542015-08-07 16:16:36 +00001643 /// \brief Build a new OpenMP 'device' clause.
1644 ///
1645 /// By default, performs semantic analysis to build the new statement.
1646 /// Subclasses may override this routine to provide different behavior.
1647 OMPClause *RebuildOMPDeviceClause(Expr *Device, SourceLocation StartLoc,
1648 SourceLocation LParenLoc,
1649 SourceLocation EndLoc) {
Kelvin Li099bb8c2015-11-24 20:50:12 +00001650 return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc,
Michael Wonge710d542015-08-07 16:16:36 +00001651 EndLoc);
1652 }
1653
Kelvin Li0bff7af2015-11-23 05:32:03 +00001654 /// \brief Build a new OpenMP 'map' clause.
1655 ///
1656 /// By default, performs semantic analysis to build the new OpenMP clause.
1657 /// Subclasses may override this routine to provide different behavior.
1658 OMPClause *RebuildOMPMapClause(
1659 OpenMPMapClauseKind MapTypeModifier, OpenMPMapClauseKind MapType,
1660 SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1661 SourceLocation StartLoc, SourceLocation LParenLoc,
1662 SourceLocation EndLoc) {
1663 return getSema().ActOnOpenMPMapClause(MapTypeModifier, MapType, MapLoc,
1664 ColonLoc, VarList,StartLoc,
1665 LParenLoc, EndLoc);
1666 }
1667
Kelvin Li099bb8c2015-11-24 20:50:12 +00001668 /// \brief Build a new OpenMP 'num_teams' clause.
1669 ///
1670 /// By default, performs semantic analysis to build the new statement.
1671 /// Subclasses may override this routine to provide different behavior.
1672 OMPClause *RebuildOMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc,
1673 SourceLocation LParenLoc,
1674 SourceLocation EndLoc) {
1675 return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc,
1676 EndLoc);
1677 }
1678
Kelvin Lia15fb1a2015-11-27 18:47:36 +00001679 /// \brief Build a new OpenMP 'thread_limit' clause.
1680 ///
1681 /// By default, performs semantic analysis to build the new statement.
1682 /// Subclasses may override this routine to provide different behavior.
1683 OMPClause *RebuildOMPThreadLimitClause(Expr *ThreadLimit,
1684 SourceLocation StartLoc,
1685 SourceLocation LParenLoc,
1686 SourceLocation EndLoc) {
1687 return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc,
1688 LParenLoc, EndLoc);
1689 }
1690
Alexey Bataeva0569352015-12-01 10:17:31 +00001691 /// \brief Build a new OpenMP 'priority' clause.
1692 ///
1693 /// By default, performs semantic analysis to build the new statement.
1694 /// Subclasses may override this routine to provide different behavior.
1695 OMPClause *RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc,
1696 SourceLocation LParenLoc,
1697 SourceLocation EndLoc) {
1698 return getSema().ActOnOpenMPPriorityClause(Priority, StartLoc, LParenLoc,
1699 EndLoc);
1700 }
1701
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00001702 /// \brief Build a new OpenMP 'grainsize' clause.
1703 ///
1704 /// By default, performs semantic analysis to build the new statement.
1705 /// Subclasses may override this routine to provide different behavior.
1706 OMPClause *RebuildOMPGrainsizeClause(Expr *Grainsize, SourceLocation StartLoc,
1707 SourceLocation LParenLoc,
1708 SourceLocation EndLoc) {
1709 return getSema().ActOnOpenMPGrainsizeClause(Grainsize, StartLoc, LParenLoc,
1710 EndLoc);
1711 }
1712
Alexey Bataev382967a2015-12-08 12:06:20 +00001713 /// \brief Build a new OpenMP 'num_tasks' clause.
1714 ///
1715 /// By default, performs semantic analysis to build the new statement.
1716 /// Subclasses may override this routine to provide different behavior.
1717 OMPClause *RebuildOMPNumTasksClause(Expr *NumTasks, SourceLocation StartLoc,
1718 SourceLocation LParenLoc,
1719 SourceLocation EndLoc) {
1720 return getSema().ActOnOpenMPNumTasksClause(NumTasks, StartLoc, LParenLoc,
1721 EndLoc);
1722 }
1723
Alexey Bataev28c75412015-12-15 08:19:24 +00001724 /// \brief Build a new OpenMP 'hint' clause.
1725 ///
1726 /// By default, performs semantic analysis to build the new statement.
1727 /// Subclasses may override this routine to provide different behavior.
1728 OMPClause *RebuildOMPHintClause(Expr *Hint, SourceLocation StartLoc,
1729 SourceLocation LParenLoc,
1730 SourceLocation EndLoc) {
1731 return getSema().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc, EndLoc);
1732 }
1733
James Dennett2a4d13c2012-06-15 07:13:21 +00001734 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001735 ///
1736 /// By default, performs semantic analysis to build the new statement.
1737 /// Subclasses may override this routine to provide different behavior.
1738 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1739 Expr *object) {
1740 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1741 }
1742
James Dennett2a4d13c2012-06-15 07:13:21 +00001743 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001744 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001745 /// By default, performs semantic analysis to build the new statement.
1746 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001747 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001748 Expr *Object, Stmt *Body) {
1749 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001750 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001751
James Dennett2a4d13c2012-06-15 07:13:21 +00001752 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001753 ///
1754 /// By default, performs semantic analysis to build the new statement.
1755 /// Subclasses may override this routine to provide different behavior.
1756 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1757 Stmt *Body) {
1758 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1759 }
John McCall53848232011-07-27 01:07:15 +00001760
Douglas Gregorf68a5082010-04-22 23:10:45 +00001761 /// \brief Build a new Objective-C fast enumeration statement.
1762 ///
1763 /// By default, performs semantic analysis to build the new statement.
1764 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001765 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001766 Stmt *Element,
1767 Expr *Collection,
1768 SourceLocation RParenLoc,
1769 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001770 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001771 Element,
John McCallb268a282010-08-23 23:25:46 +00001772 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001773 RParenLoc);
1774 if (ForEachStmt.isInvalid())
1775 return StmtError();
1776
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001777 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001778 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001779
Douglas Gregorebe10102009-08-20 07:17:43 +00001780 /// \brief Build a new C++ exception declaration.
1781 ///
1782 /// By default, performs semantic analysis to build the new decaration.
1783 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001784 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001785 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001786 SourceLocation StartLoc,
1787 SourceLocation IdLoc,
1788 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001789 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001790 StartLoc, IdLoc, Id);
1791 if (Var)
1792 getSema().CurContext->addDecl(Var);
1793 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001794 }
1795
1796 /// \brief Build a new C++ catch statement.
1797 ///
1798 /// By default, performs semantic analysis to build the new statement.
1799 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001800 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001801 VarDecl *ExceptionDecl,
1802 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001803 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1804 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001805 }
Mike Stump11289f42009-09-09 15:08:12 +00001806
Douglas Gregorebe10102009-08-20 07:17:43 +00001807 /// \brief Build a new C++ try statement.
1808 ///
1809 /// By default, performs semantic analysis to build the new statement.
1810 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001811 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1812 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001813 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001814 }
Mike Stump11289f42009-09-09 15:08:12 +00001815
Richard Smith02e85f32011-04-14 22:09:26 +00001816 /// \brief Build a new C++0x range-based for statement.
1817 ///
1818 /// By default, performs semantic analysis to build the new statement.
1819 /// Subclasses may override this routine to provide different behavior.
1820 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
Richard Smith9f690bd2015-10-27 06:02:45 +00001821 SourceLocation CoawaitLoc,
Richard Smith02e85f32011-04-14 22:09:26 +00001822 SourceLocation ColonLoc,
1823 Stmt *Range, Stmt *BeginEnd,
1824 Expr *Cond, Expr *Inc,
1825 Stmt *LoopVar,
1826 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001827 // If we've just learned that the range is actually an Objective-C
1828 // collection, treat this as an Objective-C fast enumeration loop.
1829 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1830 if (RangeStmt->isSingleDecl()) {
1831 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001832 if (RangeVar->isInvalidDecl())
1833 return StmtError();
1834
Douglas Gregorf7106af2013-04-08 18:40:13 +00001835 Expr *RangeExpr = RangeVar->getInit();
1836 if (!RangeExpr->isTypeDependent() &&
1837 RangeExpr->getType()->isObjCObjectPointerType())
1838 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1839 RParenLoc);
1840 }
1841 }
1842 }
1843
Richard Smithcfd53b42015-10-22 06:13:50 +00001844 return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, ColonLoc,
1845 Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001846 Cond, Inc, LoopVar, RParenLoc,
1847 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001848 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001849
1850 /// \brief Build a new C++0x range-based for statement.
1851 ///
1852 /// By default, performs semantic analysis to build the new statement.
1853 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001854 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001855 bool IsIfExists,
1856 NestedNameSpecifierLoc QualifierLoc,
1857 DeclarationNameInfo NameInfo,
1858 Stmt *Nested) {
1859 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1860 QualifierLoc, NameInfo, Nested);
1861 }
1862
Richard Smith02e85f32011-04-14 22:09:26 +00001863 /// \brief Attach body to a C++0x range-based for statement.
1864 ///
1865 /// By default, performs semantic analysis to finish the new statement.
1866 /// Subclasses may override this routine to provide different behavior.
1867 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1868 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1869 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001870
David Majnemerfad8f482013-10-15 09:33:02 +00001871 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00001872 Stmt *TryBlock, Stmt *Handler) {
1873 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001874 }
1875
David Majnemerfad8f482013-10-15 09:33:02 +00001876 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001877 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001878 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001879 }
1880
David Majnemerfad8f482013-10-15 09:33:02 +00001881 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
Nico Weberd64657f2015-03-09 02:47:59 +00001882 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001883 }
1884
Alexey Bataevec474782014-10-09 08:45:04 +00001885 /// \brief Build a new predefined expression.
1886 ///
1887 /// By default, performs semantic analysis to build the new expression.
1888 /// Subclasses may override this routine to provide different behavior.
1889 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
1890 PredefinedExpr::IdentType IT) {
1891 return getSema().BuildPredefinedExpr(Loc, IT);
1892 }
1893
Douglas Gregora16548e2009-08-11 05:31:07 +00001894 /// \brief Build a new expression that references a declaration.
1895 ///
1896 /// By default, performs semantic analysis to build the new expression.
1897 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001898 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001899 LookupResult &R,
1900 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001901 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1902 }
1903
1904
1905 /// \brief Build a new expression that references a declaration.
1906 ///
1907 /// By default, performs semantic analysis to build the new expression.
1908 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001909 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001910 ValueDecl *VD,
1911 const DeclarationNameInfo &NameInfo,
1912 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001913 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001914 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001915
1916 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001917
1918 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001919 }
Mike Stump11289f42009-09-09 15:08:12 +00001920
Douglas Gregora16548e2009-08-11 05:31:07 +00001921 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001922 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001923 /// By default, performs semantic analysis to build the new expression.
1924 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001925 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001926 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001927 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001928 }
1929
Douglas Gregorad8a3362009-09-04 17:36:40 +00001930 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001931 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001932 /// By default, performs semantic analysis to build the new expression.
1933 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001934 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001935 SourceLocation OperatorLoc,
1936 bool isArrow,
1937 CXXScopeSpec &SS,
1938 TypeSourceInfo *ScopeType,
1939 SourceLocation CCLoc,
1940 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001941 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001942
Douglas Gregora16548e2009-08-11 05:31:07 +00001943 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001944 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001945 /// By default, performs semantic analysis to build the new expression.
1946 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001947 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001948 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001949 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001950 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001951 }
Mike Stump11289f42009-09-09 15:08:12 +00001952
Douglas Gregor882211c2010-04-28 22:16:22 +00001953 /// \brief Build a new builtin offsetof expression.
1954 ///
1955 /// By default, performs semantic analysis to build the new expression.
1956 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001957 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Craig Topperb5518242015-10-22 04:59:59 +00001958 TypeSourceInfo *Type,
1959 ArrayRef<Sema::OffsetOfComponent> Components,
1960 SourceLocation RParenLoc) {
Douglas Gregor882211c2010-04-28 22:16:22 +00001961 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
Craig Topperb5518242015-10-22 04:59:59 +00001962 RParenLoc);
Douglas Gregor882211c2010-04-28 22:16:22 +00001963 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001964
1965 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001966 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001967 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001968 /// By default, performs semantic analysis to build the new expression.
1969 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001970 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1971 SourceLocation OpLoc,
1972 UnaryExprOrTypeTrait ExprKind,
1973 SourceRange R) {
1974 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001975 }
1976
Peter Collingbournee190dee2011-03-11 19:24:49 +00001977 /// \brief Build a new sizeof, alignof or vec step expression with an
1978 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001979 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001980 /// By default, performs semantic analysis to build the new expression.
1981 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001982 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1983 UnaryExprOrTypeTrait ExprKind,
1984 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001985 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001986 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001987 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001988 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001989
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001990 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001991 }
Mike Stump11289f42009-09-09 15:08:12 +00001992
Douglas Gregora16548e2009-08-11 05:31:07 +00001993 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001994 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001995 /// By default, performs semantic analysis to build the new expression.
1996 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001997 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001998 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001999 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002000 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002001 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00002002 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002003 RBracketLoc);
2004 }
2005
Alexey Bataev1a3320e2015-08-25 14:24:04 +00002006 /// \brief Build a new array section expression.
2007 ///
2008 /// By default, performs semantic analysis to build the new expression.
2009 /// Subclasses may override this routine to provide different behavior.
2010 ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc,
2011 Expr *LowerBound,
2012 SourceLocation ColonLoc, Expr *Length,
2013 SourceLocation RBracketLoc) {
2014 return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound,
2015 ColonLoc, Length, RBracketLoc);
2016 }
2017
Douglas Gregora16548e2009-08-11 05:31:07 +00002018 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00002019 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002020 /// By default, performs semantic analysis to build the new expression.
2021 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002022 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002023 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00002024 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00002025 Expr *ExecConfig = nullptr) {
2026 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002027 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00002028 }
2029
2030 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002031 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002032 /// By default, performs semantic analysis to build the new expression.
2033 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002034 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002035 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00002036 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002037 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002038 const DeclarationNameInfo &MemberNameInfo,
2039 ValueDecl *Member,
2040 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00002041 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00002042 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00002043 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
2044 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00002045 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00002046 // We have a reference to an unnamed field. This is always the
2047 // base of an anonymous struct/union member access, i.e. the
2048 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00002049 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00002050 assert(Member->getType()->isRecordType() &&
2051 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00002052
Richard Smithcab9a7d2011-10-26 19:06:56 +00002053 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002054 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00002055 QualifierLoc.getNestedNameSpecifier(),
2056 FoundDecl, Member);
2057 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002058 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002059 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00002060 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Aaron Ballmanf4cb2be2015-03-24 15:07:53 +00002061 MemberExpr *ME = new (getSema().Context)
2062 MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
2063 cast<FieldDecl>(Member)->getType(), VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002064 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00002065 }
Mike Stump11289f42009-09-09 15:08:12 +00002066
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002067 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00002068 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002069
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002070 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00002071 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00002072
John McCall16df1e52010-03-30 21:47:33 +00002073 // FIXME: this involves duplicating earlier analysis in a lot of
2074 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002075 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00002076 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00002077 R.resolveKind();
2078
John McCallb268a282010-08-23 23:25:46 +00002079 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002080 SS, TemplateKWLoc,
2081 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002082 R, ExplicitTemplateArgs,
2083 /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002084 }
Mike Stump11289f42009-09-09 15:08:12 +00002085
Douglas Gregora16548e2009-08-11 05:31:07 +00002086 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002087 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002088 /// By default, performs semantic analysis to build the new expression.
2089 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002090 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00002091 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00002092 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002093 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002094 }
2095
2096 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002097 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002098 /// By default, performs semantic analysis to build the new expression.
2099 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002100 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00002101 SourceLocation QuestionLoc,
2102 Expr *LHS,
2103 SourceLocation ColonLoc,
2104 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00002105 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
2106 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002107 }
2108
Douglas Gregora16548e2009-08-11 05:31:07 +00002109 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00002110 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002111 /// By default, performs semantic analysis to build the new expression.
2112 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002113 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00002114 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002115 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002116 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00002117 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002118 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002119 }
Mike Stump11289f42009-09-09 15:08:12 +00002120
Douglas Gregora16548e2009-08-11 05:31:07 +00002121 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00002122 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002123 /// By default, performs semantic analysis to build the new expression.
2124 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002125 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00002126 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002127 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002128 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00002129 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002130 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002131 }
Mike Stump11289f42009-09-09 15:08:12 +00002132
Douglas Gregora16548e2009-08-11 05:31:07 +00002133 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002134 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002135 /// By default, performs semantic analysis to build the new expression.
2136 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002137 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00002138 SourceLocation OpLoc,
2139 SourceLocation AccessorLoc,
2140 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00002141
John McCall10eae182009-11-30 22:42:35 +00002142 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002143 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00002144 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00002145 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002146 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002147 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002148 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002149 /* TemplateArgs */ nullptr,
2150 /*S*/ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002151 }
Mike Stump11289f42009-09-09 15:08:12 +00002152
Douglas Gregora16548e2009-08-11 05:31:07 +00002153 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00002154 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002155 /// By default, performs semantic analysis to build the new expression.
2156 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002157 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00002158 MultiExprArg Inits,
2159 SourceLocation RBraceLoc,
2160 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00002161 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002162 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00002163 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002164 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002165
Douglas Gregord3d93062009-11-09 17:16:50 +00002166 // Patch in the result type we were given, which may have been computed
2167 // when the initial InitListExpr was built.
2168 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
2169 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002170 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002171 }
Mike Stump11289f42009-09-09 15:08:12 +00002172
Douglas Gregora16548e2009-08-11 05:31:07 +00002173 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00002174 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002175 /// By default, performs semantic analysis to build the new expression.
2176 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002177 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00002178 MultiExprArg ArrayExprs,
2179 SourceLocation EqualOrColonLoc,
2180 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002181 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00002182 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00002183 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002184 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002185 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002186 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002187
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002188 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002189 }
Mike Stump11289f42009-09-09 15:08:12 +00002190
Douglas Gregora16548e2009-08-11 05:31:07 +00002191 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00002192 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002193 /// By default, builds the implicit value initialization without performing
2194 /// any semantic analysis. Subclasses may override this routine to provide
2195 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002196 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002197 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00002198 }
Mike Stump11289f42009-09-09 15:08:12 +00002199
Douglas Gregora16548e2009-08-11 05:31:07 +00002200 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00002201 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002202 /// By default, performs semantic analysis to build the new expression.
2203 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002204 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002205 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002206 SourceLocation RParenLoc) {
2207 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002208 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002209 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002210 }
2211
2212 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002213 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002214 /// By default, performs semantic analysis to build the new expression.
2215 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002216 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00002217 MultiExprArg SubExprs,
2218 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002219 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002220 }
Mike Stump11289f42009-09-09 15:08:12 +00002221
Douglas Gregora16548e2009-08-11 05:31:07 +00002222 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00002223 ///
2224 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002225 /// rather than attempting to map the label statement itself.
2226 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002227 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002228 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002229 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002230 }
Mike Stump11289f42009-09-09 15:08:12 +00002231
Douglas Gregora16548e2009-08-11 05:31:07 +00002232 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002233 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002234 /// By default, performs semantic analysis to build the new expression.
2235 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002236 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002237 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002238 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002239 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002240 }
Mike Stump11289f42009-09-09 15:08:12 +00002241
Douglas Gregora16548e2009-08-11 05:31:07 +00002242 /// \brief Build a new __builtin_choose_expr expression.
2243 ///
2244 /// By default, performs semantic analysis to build the new expression.
2245 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002246 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002247 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002248 SourceLocation RParenLoc) {
2249 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002250 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002251 RParenLoc);
2252 }
Mike Stump11289f42009-09-09 15:08:12 +00002253
Peter Collingbourne91147592011-04-15 00:35:48 +00002254 /// \brief Build a new generic selection expression.
2255 ///
2256 /// By default, performs semantic analysis to build the new expression.
2257 /// Subclasses may override this routine to provide different behavior.
2258 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2259 SourceLocation DefaultLoc,
2260 SourceLocation RParenLoc,
2261 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002262 ArrayRef<TypeSourceInfo *> Types,
2263 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002264 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002265 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002266 }
2267
Douglas Gregora16548e2009-08-11 05:31:07 +00002268 /// \brief Build a new overloaded operator call expression.
2269 ///
2270 /// By default, performs semantic analysis to build the new expression.
2271 /// The semantic analysis provides the behavior of template instantiation,
2272 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002273 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002274 /// argument-dependent lookup, etc. Subclasses may override this routine to
2275 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002276 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002277 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002278 Expr *Callee,
2279 Expr *First,
2280 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002281
2282 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002283 /// reinterpret_cast.
2284 ///
2285 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002286 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002287 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002288 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002289 Stmt::StmtClass Class,
2290 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002291 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002292 SourceLocation RAngleLoc,
2293 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002294 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002295 SourceLocation RParenLoc) {
2296 switch (Class) {
2297 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002298 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002299 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002300 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002301
2302 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002303 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002304 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002305 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002306
Douglas Gregora16548e2009-08-11 05:31:07 +00002307 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002308 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002309 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002310 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002311 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002312
Douglas Gregora16548e2009-08-11 05:31:07 +00002313 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002314 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002315 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002316 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002317
Douglas Gregora16548e2009-08-11 05:31:07 +00002318 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002319 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002320 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002321 }
Mike Stump11289f42009-09-09 15:08:12 +00002322
Douglas Gregora16548e2009-08-11 05:31:07 +00002323 /// \brief Build a new C++ static_cast expression.
2324 ///
2325 /// By default, performs semantic analysis to build the new expression.
2326 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002327 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002328 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002329 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002330 SourceLocation RAngleLoc,
2331 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002332 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002333 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002334 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002335 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002336 SourceRange(LAngleLoc, RAngleLoc),
2337 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002338 }
2339
2340 /// \brief Build a new C++ dynamic_cast expression.
2341 ///
2342 /// By default, performs semantic analysis to build the new expression.
2343 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002344 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002345 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002346 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002347 SourceLocation RAngleLoc,
2348 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002349 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002350 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002351 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002352 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002353 SourceRange(LAngleLoc, RAngleLoc),
2354 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002355 }
2356
2357 /// \brief Build a new C++ reinterpret_cast expression.
2358 ///
2359 /// By default, performs semantic analysis to build the new expression.
2360 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002361 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002362 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002363 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002364 SourceLocation RAngleLoc,
2365 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002366 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002367 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002368 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002369 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002370 SourceRange(LAngleLoc, RAngleLoc),
2371 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002372 }
2373
2374 /// \brief Build a new C++ const_cast expression.
2375 ///
2376 /// By default, performs semantic analysis to build the new expression.
2377 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002378 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002379 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002380 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002381 SourceLocation RAngleLoc,
2382 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002383 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002384 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002385 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002386 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002387 SourceRange(LAngleLoc, RAngleLoc),
2388 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002389 }
Mike Stump11289f42009-09-09 15:08:12 +00002390
Douglas Gregora16548e2009-08-11 05:31:07 +00002391 /// \brief Build a new C++ functional-style cast expression.
2392 ///
2393 /// By default, performs semantic analysis to build the new expression.
2394 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002395 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2396 SourceLocation LParenLoc,
2397 Expr *Sub,
2398 SourceLocation RParenLoc) {
2399 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002400 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002401 RParenLoc);
2402 }
Mike Stump11289f42009-09-09 15:08:12 +00002403
Douglas Gregora16548e2009-08-11 05:31:07 +00002404 /// \brief Build a new C++ typeid(type) expression.
2405 ///
2406 /// By default, performs semantic analysis to build the new expression.
2407 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002408 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002409 SourceLocation TypeidLoc,
2410 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002411 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002412 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002413 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002414 }
Mike Stump11289f42009-09-09 15:08:12 +00002415
Francois Pichet9f4f2072010-09-08 12:20:18 +00002416
Douglas Gregora16548e2009-08-11 05:31:07 +00002417 /// \brief Build a new C++ typeid(expr) expression.
2418 ///
2419 /// By default, performs semantic analysis to build the new expression.
2420 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002421 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002422 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002423 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002424 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002425 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002426 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002427 }
2428
Francois Pichet9f4f2072010-09-08 12:20:18 +00002429 /// \brief Build a new C++ __uuidof(type) expression.
2430 ///
2431 /// By default, performs semantic analysis to build the new expression.
2432 /// Subclasses may override this routine to provide different behavior.
2433 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2434 SourceLocation TypeidLoc,
2435 TypeSourceInfo *Operand,
2436 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002437 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002438 RParenLoc);
2439 }
2440
2441 /// \brief Build a new C++ __uuidof(expr) expression.
2442 ///
2443 /// By default, performs semantic analysis to build the new expression.
2444 /// Subclasses may override this routine to provide different behavior.
2445 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2446 SourceLocation TypeidLoc,
2447 Expr *Operand,
2448 SourceLocation RParenLoc) {
2449 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2450 RParenLoc);
2451 }
2452
Douglas Gregora16548e2009-08-11 05:31:07 +00002453 /// \brief Build a new C++ "this" expression.
2454 ///
2455 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002456 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002457 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002458 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002459 QualType ThisType,
2460 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002461 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002462 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002463 }
2464
2465 /// \brief Build a new C++ throw expression.
2466 ///
2467 /// By default, performs semantic analysis to build the new expression.
2468 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002469 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2470 bool IsThrownVariableInScope) {
2471 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002472 }
2473
2474 /// \brief Build a new C++ default-argument expression.
2475 ///
2476 /// By default, builds a new default-argument expression, which does not
2477 /// require any semantic analysis. Subclasses may override this routine to
2478 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002479 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002480 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002481 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002482 }
2483
Richard Smith852c9db2013-04-20 22:23:05 +00002484 /// \brief Build a new C++11 default-initialization expression.
2485 ///
2486 /// By default, builds a new default field initialization expression, which
2487 /// does not require any semantic analysis. Subclasses may override this
2488 /// routine to provide different behavior.
2489 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2490 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002491 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002492 }
2493
Douglas Gregora16548e2009-08-11 05:31:07 +00002494 /// \brief Build a new C++ zero-initialization expression.
2495 ///
2496 /// By default, performs semantic analysis to build the new expression.
2497 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002498 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2499 SourceLocation LParenLoc,
2500 SourceLocation RParenLoc) {
2501 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002502 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002503 }
Mike Stump11289f42009-09-09 15:08:12 +00002504
Douglas Gregora16548e2009-08-11 05:31:07 +00002505 /// \brief Build a new C++ "new" expression.
2506 ///
2507 /// By default, performs semantic analysis to build the new expression.
2508 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002509 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002510 bool UseGlobal,
2511 SourceLocation PlacementLParen,
2512 MultiExprArg PlacementArgs,
2513 SourceLocation PlacementRParen,
2514 SourceRange TypeIdParens,
2515 QualType AllocatedType,
2516 TypeSourceInfo *AllocatedTypeInfo,
2517 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002518 SourceRange DirectInitRange,
2519 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002520 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002521 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002522 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002523 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002524 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002525 AllocatedType,
2526 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002527 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002528 DirectInitRange,
2529 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002530 }
Mike Stump11289f42009-09-09 15:08:12 +00002531
Douglas Gregora16548e2009-08-11 05:31:07 +00002532 /// \brief Build a new C++ "delete" expression.
2533 ///
2534 /// By default, performs semantic analysis to build the new expression.
2535 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002536 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002537 bool IsGlobalDelete,
2538 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002539 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002540 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002541 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002542 }
Mike Stump11289f42009-09-09 15:08:12 +00002543
Douglas Gregor29c42f22012-02-24 07:38:34 +00002544 /// \brief Build a new type trait expression.
2545 ///
2546 /// By default, performs semantic analysis to build the new expression.
2547 /// Subclasses may override this routine to provide different behavior.
2548 ExprResult RebuildTypeTrait(TypeTrait Trait,
2549 SourceLocation StartLoc,
2550 ArrayRef<TypeSourceInfo *> Args,
2551 SourceLocation RParenLoc) {
2552 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2553 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002554
John Wiegley6242b6a2011-04-28 00:16:57 +00002555 /// \brief Build a new array type trait expression.
2556 ///
2557 /// By default, performs semantic analysis to build the new expression.
2558 /// Subclasses may override this routine to provide different behavior.
2559 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2560 SourceLocation StartLoc,
2561 TypeSourceInfo *TSInfo,
2562 Expr *DimExpr,
2563 SourceLocation RParenLoc) {
2564 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2565 }
2566
John Wiegleyf9f65842011-04-25 06:54:41 +00002567 /// \brief Build a new expression trait expression.
2568 ///
2569 /// By default, performs semantic analysis to build the new expression.
2570 /// Subclasses may override this routine to provide different behavior.
2571 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2572 SourceLocation StartLoc,
2573 Expr *Queried,
2574 SourceLocation RParenLoc) {
2575 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2576 }
2577
Mike Stump11289f42009-09-09 15:08:12 +00002578 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002579 /// expression.
2580 ///
2581 /// By default, performs semantic analysis to build the new expression.
2582 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002583 ExprResult RebuildDependentScopeDeclRefExpr(
2584 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002585 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002586 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002587 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002588 bool IsAddressOfOperand,
2589 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002590 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002591 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002592
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002593 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002594 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2595 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002596
Reid Kleckner32506ed2014-06-12 23:03:48 +00002597 return getSema().BuildQualifiedDeclarationNameExpr(
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002598 SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002599 }
2600
2601 /// \brief Build a new template-id expression.
2602 ///
2603 /// By default, performs semantic analysis to build the new expression.
2604 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002605 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002606 SourceLocation TemplateKWLoc,
2607 LookupResult &R,
2608 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002609 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002610 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2611 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002612 }
2613
2614 /// \brief Build a new object-construction expression.
2615 ///
2616 /// By default, performs semantic analysis to build the new expression.
2617 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002618 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002619 SourceLocation Loc,
2620 CXXConstructorDecl *Constructor,
2621 bool IsElidable,
2622 MultiExprArg Args,
2623 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002624 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002625 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002626 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002627 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002628 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002629 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002630 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002631 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002632 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002633
Douglas Gregordb121ba2009-12-14 16:27:04 +00002634 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002635 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002636 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002637 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002638 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002639 RequiresZeroInit, ConstructKind,
2640 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002641 }
2642
2643 /// \brief Build a new object-construction expression.
2644 ///
2645 /// By default, performs semantic analysis to build the new expression.
2646 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002647 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2648 SourceLocation LParenLoc,
2649 MultiExprArg Args,
2650 SourceLocation RParenLoc) {
2651 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002652 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002653 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002654 RParenLoc);
2655 }
2656
2657 /// \brief Build a new object-construction expression.
2658 ///
2659 /// By default, performs semantic analysis to build the new expression.
2660 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002661 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2662 SourceLocation LParenLoc,
2663 MultiExprArg Args,
2664 SourceLocation RParenLoc) {
2665 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002666 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002667 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002668 RParenLoc);
2669 }
Mike Stump11289f42009-09-09 15:08:12 +00002670
Douglas Gregora16548e2009-08-11 05:31:07 +00002671 /// \brief Build a new member reference expression.
2672 ///
2673 /// By default, performs semantic analysis to build the new expression.
2674 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002675 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002676 QualType BaseType,
2677 bool IsArrow,
2678 SourceLocation OperatorLoc,
2679 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002680 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002681 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002682 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002683 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002684 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002685 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002686
John McCallb268a282010-08-23 23:25:46 +00002687 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002688 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002689 SS, TemplateKWLoc,
2690 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002691 MemberNameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002692 TemplateArgs, /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002693 }
2694
John McCall10eae182009-11-30 22:42:35 +00002695 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002696 ///
2697 /// By default, performs semantic analysis to build the new expression.
2698 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002699 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2700 SourceLocation OperatorLoc,
2701 bool IsArrow,
2702 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002703 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002704 NamedDecl *FirstQualifierInScope,
2705 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002706 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002707 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002708 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002709
John McCallb268a282010-08-23 23:25:46 +00002710 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002711 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002712 SS, TemplateKWLoc,
2713 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002714 R, TemplateArgs, /*S*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00002715 }
Mike Stump11289f42009-09-09 15:08:12 +00002716
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002717 /// \brief Build a new noexcept expression.
2718 ///
2719 /// By default, performs semantic analysis to build the new expression.
2720 /// Subclasses may override this routine to provide different behavior.
2721 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2722 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2723 }
2724
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002725 /// \brief Build a new expression to compute the length of a parameter pack.
Richard Smithd784e682015-09-23 21:41:42 +00002726 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc,
2727 NamedDecl *Pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00002728 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002729 SourceLocation RParenLoc,
Richard Smithd784e682015-09-23 21:41:42 +00002730 Optional<unsigned> Length,
2731 ArrayRef<TemplateArgument> PartialArgs) {
2732 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
2733 RParenLoc, Length, PartialArgs);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002734 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002735
Patrick Beard0caa3942012-04-19 00:25:12 +00002736 /// \brief Build a new Objective-C boxed expression.
2737 ///
2738 /// By default, performs semantic analysis to build the new expression.
2739 /// Subclasses may override this routine to provide different behavior.
2740 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2741 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2742 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002743
Ted Kremeneke65b0862012-03-06 20:05:56 +00002744 /// \brief Build a new Objective-C array literal.
2745 ///
2746 /// By default, performs semantic analysis to build the new expression.
2747 /// Subclasses may override this routine to provide different behavior.
2748 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2749 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002750 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002751 MultiExprArg(Elements, NumElements));
2752 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002753
2754 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002755 Expr *Base, Expr *Key,
2756 ObjCMethodDecl *getterMethod,
2757 ObjCMethodDecl *setterMethod) {
2758 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2759 getterMethod, setterMethod);
2760 }
2761
2762 /// \brief Build a new Objective-C dictionary literal.
2763 ///
2764 /// By default, performs semantic analysis to build the new expression.
2765 /// Subclasses may override this routine to provide different behavior.
2766 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
Craig Topperd4336e02015-12-24 23:58:15 +00002767 MutableArrayRef<ObjCDictionaryElement> Elements) {
2768 return getSema().BuildObjCDictionaryLiteral(Range, Elements);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002769 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002770
James Dennett2a4d13c2012-06-15 07:13:21 +00002771 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002772 ///
2773 /// By default, performs semantic analysis to build the new expression.
2774 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002775 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002776 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002777 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002778 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002779 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002780
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002781 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002782 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002783 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002784 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002785 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002786 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002787 MultiExprArg Args,
2788 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002789 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2790 ReceiverTypeInfo->getType(),
2791 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002792 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002793 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002794 }
2795
2796 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002797 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002798 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002799 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002800 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002801 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002802 MultiExprArg Args,
2803 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002804 return SemaRef.BuildInstanceMessage(Receiver,
2805 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002806 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002807 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002808 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002809 }
2810
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002811 /// \brief Build a new Objective-C instance/class message to 'super'.
2812 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
2813 Selector Sel,
2814 ArrayRef<SourceLocation> SelectorLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002815 QualType SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002816 ObjCMethodDecl *Method,
2817 SourceLocation LBracLoc,
2818 MultiExprArg Args,
2819 SourceLocation RBracLoc) {
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002820 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002821 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002822 SuperLoc,
2823 Sel, Method, LBracLoc, SelectorLocs,
2824 RBracLoc, Args)
2825 : SemaRef.BuildClassMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002826 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002827 SuperLoc,
2828 Sel, Method, LBracLoc, SelectorLocs,
2829 RBracLoc, Args);
2830
2831
2832 }
2833
Douglas Gregord51d90d2010-04-26 20:11:03 +00002834 /// \brief Build a new Objective-C ivar reference expression.
2835 ///
2836 /// By default, performs semantic analysis to build the new expression.
2837 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002838 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002839 SourceLocation IvarLoc,
2840 bool IsArrow, bool IsFreeIvar) {
2841 // FIXME: We lose track of the IsFreeIvar bit.
2842 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002843 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2844 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002845 /*FIXME:*/IvarLoc, IsArrow,
2846 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002847 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002848 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002849 /*TemplateArgs=*/nullptr,
2850 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002851 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002852
2853 /// \brief Build a new Objective-C property reference expression.
2854 ///
2855 /// By default, performs semantic analysis to build the new expression.
2856 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002857 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002858 ObjCPropertyDecl *Property,
2859 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002860 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002861 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2862 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2863 /*FIXME:*/PropertyLoc,
2864 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002865 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002866 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002867 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002868 /*TemplateArgs=*/nullptr,
2869 /*S=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002870 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002871
John McCallb7bd14f2010-12-02 01:19:52 +00002872 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002873 ///
2874 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002875 /// Subclasses may override this routine to provide different behavior.
2876 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2877 ObjCMethodDecl *Getter,
2878 ObjCMethodDecl *Setter,
2879 SourceLocation PropertyLoc) {
2880 // Since these expressions can only be value-dependent, we do not
2881 // need to perform semantic analysis again.
2882 return Owned(
2883 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2884 VK_LValue, OK_ObjCProperty,
2885 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002886 }
2887
Douglas Gregord51d90d2010-04-26 20:11:03 +00002888 /// \brief Build a new Objective-C "isa" expression.
2889 ///
2890 /// By default, performs semantic analysis to build the new expression.
2891 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002892 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00002893 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00002894 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002895 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2896 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002897 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002898 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002899 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002900 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002901 /*TemplateArgs=*/nullptr,
2902 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002903 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002904
Douglas Gregora16548e2009-08-11 05:31:07 +00002905 /// \brief Build a new shuffle vector expression.
2906 ///
2907 /// By default, performs semantic analysis to build the new expression.
2908 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002909 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002910 MultiExprArg SubExprs,
2911 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002912 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002913 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002914 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2915 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2916 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002917 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002918
Douglas Gregora16548e2009-08-11 05:31:07 +00002919 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002920 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002921 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2922 SemaRef.Context.BuiltinFnTy,
2923 VK_RValue, BuiltinLoc);
2924 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2925 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002926 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00002927
2928 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002929 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00002930 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002931 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002932
Douglas Gregora16548e2009-08-11 05:31:07 +00002933 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002934 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002935 }
John McCall31f82722010-11-12 08:19:04 +00002936
Hal Finkelc4d7c822013-09-18 03:29:45 +00002937 /// \brief Build a new convert vector expression.
2938 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2939 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2940 SourceLocation RParenLoc) {
2941 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2942 BuiltinLoc, RParenLoc);
2943 }
2944
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002945 /// \brief Build a new template argument pack expansion.
2946 ///
2947 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002948 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002949 /// different behavior.
2950 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002951 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002952 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002953 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002954 case TemplateArgument::Expression: {
2955 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002956 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2957 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002958 if (Result.isInvalid())
2959 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002960
Douglas Gregor98318c22011-01-03 21:37:45 +00002961 return TemplateArgumentLoc(Result.get(), Result.get());
2962 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002963
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002964 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002965 return TemplateArgumentLoc(TemplateArgument(
2966 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002967 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002968 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002969 Pattern.getTemplateNameLoc(),
2970 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002971
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002972 case TemplateArgument::Null:
2973 case TemplateArgument::Integral:
2974 case TemplateArgument::Declaration:
2975 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002976 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002977 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002978 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002979
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002980 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002981 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002982 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002983 EllipsisLoc,
2984 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002985 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2986 Expansion);
2987 break;
2988 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002989
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002990 return TemplateArgumentLoc();
2991 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002992
Douglas Gregor968f23a2011-01-03 19:31:53 +00002993 /// \brief Build a new expression pack expansion.
2994 ///
2995 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002996 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002997 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002998 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002999 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00003000 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003001 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003002
Richard Smith0f0af192014-11-08 05:07:16 +00003003 /// \brief Build a new C++1z fold-expression.
3004 ///
3005 /// By default, performs semantic analysis in order to build a new fold
3006 /// expression.
3007 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
3008 BinaryOperatorKind Operator,
3009 SourceLocation EllipsisLoc, Expr *RHS,
3010 SourceLocation RParenLoc) {
3011 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
3012 RHS, RParenLoc);
3013 }
3014
3015 /// \brief Build an empty C++1z fold-expression with the given operator.
3016 ///
3017 /// By default, produces the fallback value for the fold-expression, or
3018 /// produce an error if there is no fallback value.
3019 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
3020 BinaryOperatorKind Operator) {
3021 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
3022 }
3023
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003024 /// \brief Build a new atomic operation expression.
3025 ///
3026 /// By default, performs semantic analysis to build the new expression.
3027 /// Subclasses may override this routine to provide different behavior.
3028 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
3029 MultiExprArg SubExprs,
3030 QualType RetTy,
3031 AtomicExpr::AtomicOp Op,
3032 SourceLocation RParenLoc) {
3033 // Just create the expression; there is not any interesting semantic
3034 // analysis here because we can't actually build an AtomicExpr until
3035 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00003036 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003037 RParenLoc);
3038 }
3039
John McCall31f82722010-11-12 08:19:04 +00003040private:
Douglas Gregor14454802011-02-25 02:25:35 +00003041 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
3042 QualType ObjectType,
3043 NamedDecl *FirstQualifierInScope,
3044 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003045
3046 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3047 QualType ObjectType,
3048 NamedDecl *FirstQualifierInScope,
3049 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003050
3051 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
3052 NamedDecl *FirstQualifierInScope,
3053 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003054};
Douglas Gregora16548e2009-08-11 05:31:07 +00003055
Douglas Gregorebe10102009-08-20 07:17:43 +00003056template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003057StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003058 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003059 return S;
Mike Stump11289f42009-09-09 15:08:12 +00003060
Douglas Gregorebe10102009-08-20 07:17:43 +00003061 switch (S->getStmtClass()) {
3062 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00003063
Douglas Gregorebe10102009-08-20 07:17:43 +00003064 // Transform individual statement nodes
3065#define STMT(Node, Parent) \
3066 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00003067#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00003068#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00003069#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003070
Douglas Gregorebe10102009-08-20 07:17:43 +00003071 // Transform expressions by calling TransformExpr.
3072#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00003073#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00003074#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00003075#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00003076 {
John McCalldadc5752010-08-24 06:29:42 +00003077 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00003078 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003079 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003080
Richard Smith945f8d32013-01-14 22:39:08 +00003081 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00003082 }
Mike Stump11289f42009-09-09 15:08:12 +00003083 }
3084
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003085 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00003086}
Mike Stump11289f42009-09-09 15:08:12 +00003087
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00003088template<typename Derived>
3089OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
3090 if (!S)
3091 return S;
3092
3093 switch (S->getClauseKind()) {
3094 default: break;
3095 // Transform individual clause nodes
3096#define OPENMP_CLAUSE(Name, Class) \
3097 case OMPC_ ## Name : \
3098 return getDerived().Transform ## Class(cast<Class>(S));
3099#include "clang/Basic/OpenMPKinds.def"
3100 }
3101
3102 return S;
3103}
3104
Mike Stump11289f42009-09-09 15:08:12 +00003105
Douglas Gregore922c772009-08-04 22:27:00 +00003106template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003107ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003108 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003109 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00003110
3111 switch (E->getStmtClass()) {
3112 case Stmt::NoStmtClass: break;
3113#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00003114#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00003115#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00003116 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00003117#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003118 }
3119
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003120 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00003121}
3122
3123template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00003124ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00003125 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00003126 // Initializers are instantiated like expressions, except that various outer
3127 // layers are stripped.
3128 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003129 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00003130
3131 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
3132 Init = ExprTemp->getSubExpr();
3133
Richard Smithe6ca4752013-05-30 22:40:16 +00003134 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
3135 Init = MTE->GetTemporaryExpr();
3136
Richard Smithd59b8322012-12-19 01:39:02 +00003137 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
3138 Init = Binder->getSubExpr();
3139
3140 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
3141 Init = ICE->getSubExprAsWritten();
3142
Richard Smithcc1b96d2013-06-12 22:31:48 +00003143 if (CXXStdInitializerListExpr *ILE =
3144 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00003145 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00003146
Richard Smithc6abd962014-07-25 01:12:44 +00003147 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00003148 // InitListExprs. Other forms of copy-initialization will be a no-op if
3149 // the initializer is already the right type.
3150 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00003151 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00003152 return getDerived().TransformExpr(Init);
3153
3154 // Revert value-initialization back to empty parens.
3155 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
3156 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003157 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003158 Parens.getEnd());
3159 }
3160
3161 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3162 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003163 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003164 SourceLocation());
3165
3166 // Revert initialization by constructor back to a parenthesized or braced list
3167 // of expressions. Any other form of initializer can just be reused directly.
3168 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00003169 return getDerived().TransformExpr(Init);
3170
Richard Smithf8adcdc2014-07-17 05:12:35 +00003171 // If the initialization implicitly converted an initializer list to a
3172 // std::initializer_list object, unwrap the std::initializer_list too.
3173 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00003174 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00003175
Richard Smithd59b8322012-12-19 01:39:02 +00003176 SmallVector<Expr*, 8> NewArgs;
3177 bool ArgChanged = false;
3178 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00003179 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00003180 return ExprError();
3181
3182 // If this was list initialization, revert to list form.
3183 if (Construct->isListInitialization())
3184 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
3185 Construct->getLocEnd(),
3186 Construct->getType());
3187
Richard Smithd59b8322012-12-19 01:39:02 +00003188 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00003189 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00003190 if (Parens.isInvalid()) {
3191 // This was a variable declaration's initialization for which no initializer
3192 // was specified.
3193 assert(NewArgs.empty() &&
3194 "no parens or braces but have direct init with arguments?");
3195 return ExprEmpty();
3196 }
Richard Smithd59b8322012-12-19 01:39:02 +00003197 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3198 Parens.getEnd());
3199}
3200
3201template<typename Derived>
Craig Topper99d23532015-12-24 23:58:29 +00003202bool TreeTransform<Derived>::TransformExprs(Expr *const *Inputs,
Chad Rosier1dcde962012-08-08 18:46:20 +00003203 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003204 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003205 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003206 bool *ArgChanged) {
3207 for (unsigned I = 0; I != NumInputs; ++I) {
3208 // If requested, drop call arguments that need to be dropped.
3209 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3210 if (ArgChanged)
3211 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003212
Douglas Gregora3efea12011-01-03 19:04:46 +00003213 break;
3214 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003215
Douglas Gregor968f23a2011-01-03 19:31:53 +00003216 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3217 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00003218
Chris Lattner01cf8db2011-07-20 06:58:45 +00003219 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003220 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3221 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003222
Douglas Gregor968f23a2011-01-03 19:31:53 +00003223 // Determine whether the set of unexpanded parameter packs can and should
3224 // be expanded.
3225 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003226 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003227 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3228 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003229 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3230 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003231 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003232 Expand, RetainExpansion,
3233 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00003234 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003235
Douglas Gregor968f23a2011-01-03 19:31:53 +00003236 if (!Expand) {
3237 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003238 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00003239 // expansion.
3240 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3241 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3242 if (OutPattern.isInvalid())
3243 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003244
3245 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00003246 Expansion->getEllipsisLoc(),
3247 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003248 if (Out.isInvalid())
3249 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003250
Douglas Gregor968f23a2011-01-03 19:31:53 +00003251 if (ArgChanged)
3252 *ArgChanged = true;
3253 Outputs.push_back(Out.get());
3254 continue;
3255 }
John McCall542e7c62011-07-06 07:30:07 +00003256
3257 // Record right away that the argument was changed. This needs
3258 // to happen even if the array expands to nothing.
3259 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003260
Douglas Gregor968f23a2011-01-03 19:31:53 +00003261 // The transform has determined that we should perform an elementwise
3262 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003263 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00003264 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3265 ExprResult Out = getDerived().TransformExpr(Pattern);
3266 if (Out.isInvalid())
3267 return true;
3268
Richard Smith9467be42014-06-06 17:33:35 +00003269 // FIXME: Can this happen? We should not try to expand the pack
3270 // in this case.
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003271 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003272 Out = getDerived().RebuildPackExpansion(
3273 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003274 if (Out.isInvalid())
3275 return true;
3276 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003277
Douglas Gregor968f23a2011-01-03 19:31:53 +00003278 Outputs.push_back(Out.get());
3279 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003280
Richard Smith9467be42014-06-06 17:33:35 +00003281 // If we're supposed to retain a pack expansion, do so by temporarily
3282 // forgetting the partially-substituted parameter pack.
3283 if (RetainExpansion) {
3284 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3285
3286 ExprResult Out = getDerived().TransformExpr(Pattern);
3287 if (Out.isInvalid())
3288 return true;
3289
3290 Out = getDerived().RebuildPackExpansion(
3291 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3292 if (Out.isInvalid())
3293 return true;
3294
3295 Outputs.push_back(Out.get());
3296 }
3297
Douglas Gregor968f23a2011-01-03 19:31:53 +00003298 continue;
3299 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003300
Richard Smithd59b8322012-12-19 01:39:02 +00003301 ExprResult Result =
3302 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3303 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003304 if (Result.isInvalid())
3305 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003306
Douglas Gregora3efea12011-01-03 19:04:46 +00003307 if (Result.get() != Inputs[I] && ArgChanged)
3308 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003309
3310 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003311 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003312
Douglas Gregora3efea12011-01-03 19:04:46 +00003313 return false;
3314}
3315
3316template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003317NestedNameSpecifierLoc
3318TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3319 NestedNameSpecifierLoc NNS,
3320 QualType ObjectType,
3321 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003322 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003323 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003324 Qualifier = Qualifier.getPrefix())
3325 Qualifiers.push_back(Qualifier);
3326
3327 CXXScopeSpec SS;
3328 while (!Qualifiers.empty()) {
3329 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3330 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003331
Douglas Gregor14454802011-02-25 02:25:35 +00003332 switch (QNNS->getKind()) {
3333 case NestedNameSpecifier::Identifier:
Craig Topperc3ec1492014-05-26 06:22:03 +00003334 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
Douglas Gregor14454802011-02-25 02:25:35 +00003335 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003336 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003337 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003338 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00003339 FirstQualifierInScope, false))
3340 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003341
Douglas Gregor14454802011-02-25 02:25:35 +00003342 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003343
Douglas Gregor14454802011-02-25 02:25:35 +00003344 case NestedNameSpecifier::Namespace: {
3345 NamespaceDecl *NS
3346 = cast_or_null<NamespaceDecl>(
3347 getDerived().TransformDecl(
3348 Q.getLocalBeginLoc(),
3349 QNNS->getAsNamespace()));
3350 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3351 break;
3352 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003353
Douglas Gregor14454802011-02-25 02:25:35 +00003354 case NestedNameSpecifier::NamespaceAlias: {
3355 NamespaceAliasDecl *Alias
3356 = cast_or_null<NamespaceAliasDecl>(
3357 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3358 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003359 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003360 Q.getLocalEndLoc());
3361 break;
3362 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003363
Douglas Gregor14454802011-02-25 02:25:35 +00003364 case NestedNameSpecifier::Global:
3365 // There is no meaningful transformation that one could perform on the
3366 // global scope.
3367 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3368 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003369
Nikola Smiljanic67860242014-09-26 00:28:20 +00003370 case NestedNameSpecifier::Super: {
3371 CXXRecordDecl *RD =
3372 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3373 SourceLocation(), QNNS->getAsRecordDecl()));
3374 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3375 break;
3376 }
3377
Douglas Gregor14454802011-02-25 02:25:35 +00003378 case NestedNameSpecifier::TypeSpecWithTemplate:
3379 case NestedNameSpecifier::TypeSpec: {
3380 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3381 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003382
Douglas Gregor14454802011-02-25 02:25:35 +00003383 if (!TL)
3384 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003385
Douglas Gregor14454802011-02-25 02:25:35 +00003386 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003387 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003388 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003389 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003390 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003391 if (TL.getType()->isEnumeralType())
3392 SemaRef.Diag(TL.getBeginLoc(),
3393 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003394 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3395 Q.getLocalEndLoc());
3396 break;
3397 }
Richard Trieude756fb2011-05-07 01:36:37 +00003398 // If the nested-name-specifier is an invalid type def, don't emit an
3399 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003400 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3401 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003402 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003403 << TL.getType() << SS.getRange();
3404 }
Douglas Gregor14454802011-02-25 02:25:35 +00003405 return NestedNameSpecifierLoc();
3406 }
Douglas Gregore16af532011-02-28 18:50:33 +00003407 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003408
Douglas Gregore16af532011-02-28 18:50:33 +00003409 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003410 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003411 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003412 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003413
Douglas Gregor14454802011-02-25 02:25:35 +00003414 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003415 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003416 !getDerived().AlwaysRebuild())
3417 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003418
3419 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003420 // nested-name-specifier, do so.
3421 if (SS.location_size() == NNS.getDataLength() &&
3422 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3423 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3424
3425 // Allocate new nested-name-specifier location information.
3426 return SS.getWithLocInContext(SemaRef.Context);
3427}
3428
3429template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003430DeclarationNameInfo
3431TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003432::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003433 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003434 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003435 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003436
3437 switch (Name.getNameKind()) {
3438 case DeclarationName::Identifier:
3439 case DeclarationName::ObjCZeroArgSelector:
3440 case DeclarationName::ObjCOneArgSelector:
3441 case DeclarationName::ObjCMultiArgSelector:
3442 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003443 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003444 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003445 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003446
Douglas Gregorf816bd72009-09-03 22:13:48 +00003447 case DeclarationName::CXXConstructorName:
3448 case DeclarationName::CXXDestructorName:
3449 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003450 TypeSourceInfo *NewTInfo;
3451 CanQualType NewCanTy;
3452 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003453 NewTInfo = getDerived().TransformType(OldTInfo);
3454 if (!NewTInfo)
3455 return DeclarationNameInfo();
3456 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003457 }
3458 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003459 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003460 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003461 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003462 if (NewT.isNull())
3463 return DeclarationNameInfo();
3464 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3465 }
Mike Stump11289f42009-09-09 15:08:12 +00003466
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003467 DeclarationName NewName
3468 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3469 NewCanTy);
3470 DeclarationNameInfo NewNameInfo(NameInfo);
3471 NewNameInfo.setName(NewName);
3472 NewNameInfo.setNamedTypeInfo(NewTInfo);
3473 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003474 }
Mike Stump11289f42009-09-09 15:08:12 +00003475 }
3476
David Blaikie83d382b2011-09-23 05:06:16 +00003477 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003478}
3479
3480template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003481TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003482TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3483 TemplateName Name,
3484 SourceLocation NameLoc,
3485 QualType ObjectType,
3486 NamedDecl *FirstQualifierInScope) {
3487 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3488 TemplateDecl *Template = QTN->getTemplateDecl();
3489 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003490
Douglas Gregor9db53502011-03-02 18:07:45 +00003491 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003492 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003493 Template));
3494 if (!TransTemplate)
3495 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003496
Douglas Gregor9db53502011-03-02 18:07:45 +00003497 if (!getDerived().AlwaysRebuild() &&
3498 SS.getScopeRep() == QTN->getQualifier() &&
3499 TransTemplate == Template)
3500 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003501
Douglas Gregor9db53502011-03-02 18:07:45 +00003502 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3503 TransTemplate);
3504 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003505
Douglas Gregor9db53502011-03-02 18:07:45 +00003506 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3507 if (SS.getScopeRep()) {
3508 // These apply to the scope specifier, not the template.
3509 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003510 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003511 }
3512
Douglas Gregor9db53502011-03-02 18:07:45 +00003513 if (!getDerived().AlwaysRebuild() &&
3514 SS.getScopeRep() == DTN->getQualifier() &&
3515 ObjectType.isNull())
3516 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003517
Douglas Gregor9db53502011-03-02 18:07:45 +00003518 if (DTN->isIdentifier()) {
3519 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003520 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003521 NameLoc,
3522 ObjectType,
3523 FirstQualifierInScope);
3524 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003525
Douglas Gregor9db53502011-03-02 18:07:45 +00003526 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3527 ObjectType);
3528 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003529
Douglas Gregor9db53502011-03-02 18:07:45 +00003530 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3531 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003532 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003533 Template));
3534 if (!TransTemplate)
3535 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003536
Douglas Gregor9db53502011-03-02 18:07:45 +00003537 if (!getDerived().AlwaysRebuild() &&
3538 TransTemplate == Template)
3539 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003540
Douglas Gregor9db53502011-03-02 18:07:45 +00003541 return TemplateName(TransTemplate);
3542 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003543
Douglas Gregor9db53502011-03-02 18:07:45 +00003544 if (SubstTemplateTemplateParmPackStorage *SubstPack
3545 = Name.getAsSubstTemplateTemplateParmPack()) {
3546 TemplateTemplateParmDecl *TransParam
3547 = cast_or_null<TemplateTemplateParmDecl>(
3548 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3549 if (!TransParam)
3550 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003551
Douglas Gregor9db53502011-03-02 18:07:45 +00003552 if (!getDerived().AlwaysRebuild() &&
3553 TransParam == SubstPack->getParameterPack())
3554 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003555
3556 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003557 SubstPack->getArgumentPack());
3558 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003559
Douglas Gregor9db53502011-03-02 18:07:45 +00003560 // These should be getting filtered out before they reach the AST.
3561 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003562}
3563
3564template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003565void TreeTransform<Derived>::InventTemplateArgumentLoc(
3566 const TemplateArgument &Arg,
3567 TemplateArgumentLoc &Output) {
3568 SourceLocation Loc = getDerived().getBaseLocation();
3569 switch (Arg.getKind()) {
3570 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003571 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003572 break;
3573
3574 case TemplateArgument::Type:
3575 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003576 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003577
John McCall0ad16662009-10-29 08:12:44 +00003578 break;
3579
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003580 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003581 case TemplateArgument::TemplateExpansion: {
3582 NestedNameSpecifierLocBuilder Builder;
3583 TemplateName Template = Arg.getAsTemplate();
3584 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3585 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3586 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3587 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003588
Douglas Gregor9d802122011-03-02 17:09:35 +00003589 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003590 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003591 Builder.getWithLocInContext(SemaRef.Context),
3592 Loc);
3593 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003594 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003595 Builder.getWithLocInContext(SemaRef.Context),
3596 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003597
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003598 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003599 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003600
John McCall0ad16662009-10-29 08:12:44 +00003601 case TemplateArgument::Expression:
3602 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3603 break;
3604
3605 case TemplateArgument::Declaration:
3606 case TemplateArgument::Integral:
3607 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003608 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003609 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003610 break;
3611 }
3612}
3613
3614template<typename Derived>
3615bool TreeTransform<Derived>::TransformTemplateArgument(
3616 const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +00003617 TemplateArgumentLoc &Output, bool Uneval) {
John McCall0ad16662009-10-29 08:12:44 +00003618 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003619 switch (Arg.getKind()) {
3620 case TemplateArgument::Null:
3621 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003622 case TemplateArgument::Pack:
3623 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003624 case TemplateArgument::NullPtr:
3625 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003626
Douglas Gregore922c772009-08-04 22:27:00 +00003627 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003628 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003629 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003630 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003631
3632 DI = getDerived().TransformType(DI);
3633 if (!DI) return true;
3634
3635 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3636 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003637 }
Mike Stump11289f42009-09-09 15:08:12 +00003638
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003639 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003640 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3641 if (QualifierLoc) {
3642 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3643 if (!QualifierLoc)
3644 return true;
3645 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003646
Douglas Gregordf846d12011-03-02 18:46:51 +00003647 CXXScopeSpec SS;
3648 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003649 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003650 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3651 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003652 if (Template.isNull())
3653 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003654
Douglas Gregor9d802122011-03-02 17:09:35 +00003655 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003656 Input.getTemplateNameLoc());
3657 return false;
3658 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003659
3660 case TemplateArgument::TemplateExpansion:
3661 llvm_unreachable("Caller should expand pack expansions");
3662
Douglas Gregore922c772009-08-04 22:27:00 +00003663 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003664 // Template argument expressions are constant expressions.
Richard Smithd784e682015-09-23 21:41:42 +00003665 EnterExpressionEvaluationContext Unevaluated(
3666 getSema(), Uneval ? Sema::Unevaluated : Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003667
John McCall0ad16662009-10-29 08:12:44 +00003668 Expr *InputExpr = Input.getSourceExpression();
3669 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3670
Chris Lattnercdb591a2011-04-25 20:37:58 +00003671 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003672 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003673 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003674 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003675 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003676 }
Douglas Gregore922c772009-08-04 22:27:00 +00003677 }
Mike Stump11289f42009-09-09 15:08:12 +00003678
Douglas Gregore922c772009-08-04 22:27:00 +00003679 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003680 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003681}
3682
Douglas Gregorfe921a72010-12-20 23:36:19 +00003683/// \brief Iterator adaptor that invents template argument location information
3684/// for each of the template arguments in its underlying iterator.
3685template<typename Derived, typename InputIterator>
3686class TemplateArgumentLocInventIterator {
3687 TreeTransform<Derived> &Self;
3688 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003689
Douglas Gregorfe921a72010-12-20 23:36:19 +00003690public:
3691 typedef TemplateArgumentLoc value_type;
3692 typedef TemplateArgumentLoc reference;
3693 typedef typename std::iterator_traits<InputIterator>::difference_type
3694 difference_type;
3695 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003696
Douglas Gregorfe921a72010-12-20 23:36:19 +00003697 class pointer {
3698 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003699
Douglas Gregorfe921a72010-12-20 23:36:19 +00003700 public:
3701 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003702
Douglas Gregorfe921a72010-12-20 23:36:19 +00003703 const TemplateArgumentLoc *operator->() const { return &Arg; }
3704 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003705
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00003706 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003707
Douglas Gregorfe921a72010-12-20 23:36:19 +00003708 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3709 InputIterator Iter)
3710 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003711
Douglas Gregorfe921a72010-12-20 23:36:19 +00003712 TemplateArgumentLocInventIterator &operator++() {
3713 ++Iter;
3714 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003715 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003716
Douglas Gregorfe921a72010-12-20 23:36:19 +00003717 TemplateArgumentLocInventIterator operator++(int) {
3718 TemplateArgumentLocInventIterator Old(*this);
3719 ++(*this);
3720 return Old;
3721 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003722
Douglas Gregorfe921a72010-12-20 23:36:19 +00003723 reference operator*() const {
3724 TemplateArgumentLoc Result;
3725 Self.InventTemplateArgumentLoc(*Iter, Result);
3726 return Result;
3727 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003728
Douglas Gregorfe921a72010-12-20 23:36:19 +00003729 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003730
Douglas Gregorfe921a72010-12-20 23:36:19 +00003731 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3732 const TemplateArgumentLocInventIterator &Y) {
3733 return X.Iter == Y.Iter;
3734 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003735
Douglas Gregorfe921a72010-12-20 23:36:19 +00003736 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3737 const TemplateArgumentLocInventIterator &Y) {
3738 return X.Iter != Y.Iter;
3739 }
3740};
Chad Rosier1dcde962012-08-08 18:46:20 +00003741
Douglas Gregor42cafa82010-12-20 17:42:22 +00003742template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003743template<typename InputIterator>
Richard Smithd784e682015-09-23 21:41:42 +00003744bool TreeTransform<Derived>::TransformTemplateArguments(
3745 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
3746 bool Uneval) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003747 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003748 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003749 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003750
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003751 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3752 // Unpack argument packs, which we translate them into separate
3753 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003754 // FIXME: We could do much better if we could guarantee that the
3755 // TemplateArgumentLocInfo for the pack expansion would be usable for
3756 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003757 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003758 TemplateArgument::pack_iterator>
3759 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003760 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003761 In.getArgument().pack_begin()),
3762 PackLocIterator(*this,
3763 In.getArgument().pack_end()),
Richard Smithd784e682015-09-23 21:41:42 +00003764 Outputs, Uneval))
Douglas Gregorfe921a72010-12-20 23:36:19 +00003765 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003766
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003767 continue;
3768 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003769
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003770 if (In.getArgument().isPackExpansion()) {
3771 // We have a pack expansion, for which we will be substituting into
3772 // the pattern.
3773 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003774 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003775 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003776 = getSema().getTemplateArgumentPackExpansionPattern(
3777 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003778
Chris Lattner01cf8db2011-07-20 06:58:45 +00003779 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003780 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3781 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003782
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003783 // Determine whether the set of unexpanded parameter packs can and should
3784 // be expanded.
3785 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003786 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003787 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003788 if (getDerived().TryExpandParameterPacks(Ellipsis,
3789 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003790 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003791 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003792 RetainExpansion,
3793 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003794 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003795
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003796 if (!Expand) {
3797 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003798 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003799 // expansion.
3800 TemplateArgumentLoc OutPattern;
3801 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Richard Smithd784e682015-09-23 21:41:42 +00003802 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003803 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003804
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003805 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3806 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003807 if (Out.getArgument().isNull())
3808 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003809
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003810 Outputs.addArgument(Out);
3811 continue;
3812 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003813
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003814 // The transform has determined that we should perform an elementwise
3815 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003816 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003817 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3818
Richard Smithd784e682015-09-23 21:41:42 +00003819 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003820 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003821
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003822 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003823 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3824 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003825 if (Out.getArgument().isNull())
3826 return true;
3827 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003828
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003829 Outputs.addArgument(Out);
3830 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003831
Douglas Gregor48d24112011-01-10 20:53:55 +00003832 // If we're supposed to retain a pack expansion, do so by temporarily
3833 // forgetting the partially-substituted parameter pack.
3834 if (RetainExpansion) {
3835 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003836
Richard Smithd784e682015-09-23 21:41:42 +00003837 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor48d24112011-01-10 20:53:55 +00003838 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003839
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003840 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3841 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003842 if (Out.getArgument().isNull())
3843 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003844
Douglas Gregor48d24112011-01-10 20:53:55 +00003845 Outputs.addArgument(Out);
3846 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003847
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003848 continue;
3849 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003850
3851 // The simple case:
Richard Smithd784e682015-09-23 21:41:42 +00003852 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003853 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003854
Douglas Gregor42cafa82010-12-20 17:42:22 +00003855 Outputs.addArgument(Out);
3856 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003857
Douglas Gregor42cafa82010-12-20 17:42:22 +00003858 return false;
3859
3860}
3861
Douglas Gregord6ff3322009-08-04 16:50:30 +00003862//===----------------------------------------------------------------------===//
3863// Type transformation
3864//===----------------------------------------------------------------------===//
3865
3866template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003867QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003868 if (getDerived().AlreadyTransformed(T))
3869 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003870
John McCall550e0c22009-10-21 00:40:46 +00003871 // Temporary workaround. All of these transformations should
3872 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003873 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3874 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003875
John McCall31f82722010-11-12 08:19:04 +00003876 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003877
John McCall550e0c22009-10-21 00:40:46 +00003878 if (!NewDI)
3879 return QualType();
3880
3881 return NewDI->getType();
3882}
3883
3884template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003885TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003886 // Refine the base location to the type's location.
3887 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3888 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003889 if (getDerived().AlreadyTransformed(DI->getType()))
3890 return DI;
3891
3892 TypeLocBuilder TLB;
3893
3894 TypeLoc TL = DI->getTypeLoc();
3895 TLB.reserve(TL.getFullDataSize());
3896
John McCall31f82722010-11-12 08:19:04 +00003897 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003898 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003899 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00003900
John McCallbcd03502009-12-07 02:54:59 +00003901 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003902}
3903
3904template<typename Derived>
3905QualType
John McCall31f82722010-11-12 08:19:04 +00003906TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003907 switch (T.getTypeLocClass()) {
3908#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003909#define TYPELOC(CLASS, PARENT) \
3910 case TypeLoc::CLASS: \
3911 return getDerived().Transform##CLASS##Type(TLB, \
3912 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003913#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003914 }
Mike Stump11289f42009-09-09 15:08:12 +00003915
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003916 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003917}
3918
3919/// FIXME: By default, this routine adds type qualifiers only to types
3920/// that can have qualifiers, and silently suppresses those qualifiers
3921/// that are not permitted (e.g., qualifiers on reference or function
3922/// types). This is the right thing for template instantiation, but
3923/// probably not for other clients.
3924template<typename Derived>
3925QualType
3926TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003927 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003928 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003929
John McCall31f82722010-11-12 08:19:04 +00003930 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003931 if (Result.isNull())
3932 return QualType();
3933
3934 // Silently suppress qualifiers if the result type can't be qualified.
3935 // FIXME: this is the right thing for template instantiation, but
3936 // probably not for other clients.
3937 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003938 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003939
John McCall31168b02011-06-15 23:02:42 +00003940 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003941 // resulting type.
3942 if (Quals.hasObjCLifetime()) {
3943 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3944 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003945 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003946 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003947 // A lifetime qualifier applied to a substituted template parameter
3948 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003949 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003950 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003951 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3952 QualType Replacement = SubstTypeParam->getReplacementType();
3953 Qualifiers Qs = Replacement.getQualifiers();
3954 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003955 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003956 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3957 Qs);
3958 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003959 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003960 Replacement);
3961 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003962 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3963 // 'auto' types behave the same way as template parameters.
3964 QualType Deduced = AutoTy->getDeducedType();
3965 Qualifiers Qs = Deduced.getQualifiers();
3966 Qs.removeObjCLifetime();
3967 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3968 Qs);
Richard Smithe301ba22015-11-11 02:02:15 +00003969 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
Faisal Vali2b391ab2013-09-26 19:54:12 +00003970 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003971 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003972 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003973 // Otherwise, complain about the addition of a qualifier to an
3974 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003975 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003976 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003977 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003978
Douglas Gregore46db902011-06-17 22:11:49 +00003979 Quals.removeObjCLifetime();
3980 }
3981 }
3982 }
John McCallcb0f89a2010-06-05 06:41:15 +00003983 if (!Quals.empty()) {
3984 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003985 // BuildQualifiedType might not add qualifiers if they are invalid.
3986 if (Result.hasLocalQualifiers())
3987 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003988 // No location information to preserve.
3989 }
John McCall550e0c22009-10-21 00:40:46 +00003990
3991 return Result;
3992}
3993
Douglas Gregor14454802011-02-25 02:25:35 +00003994template<typename Derived>
3995TypeLoc
3996TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3997 QualType ObjectType,
3998 NamedDecl *UnqualLookup,
3999 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004000 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00004001 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00004002
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004003 TypeSourceInfo *TSI =
4004 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
4005 if (TSI)
4006 return TSI->getTypeLoc();
4007 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00004008}
4009
Douglas Gregor579c15f2011-03-02 18:32:08 +00004010template<typename Derived>
4011TypeSourceInfo *
4012TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4013 QualType ObjectType,
4014 NamedDecl *UnqualLookup,
4015 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004016 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00004017 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00004018
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004019 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
4020 UnqualLookup, SS);
4021}
4022
4023template <typename Derived>
4024TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
4025 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
4026 CXXScopeSpec &SS) {
4027 QualType T = TL.getType();
4028 assert(!getDerived().AlreadyTransformed(T));
4029
Douglas Gregor579c15f2011-03-02 18:32:08 +00004030 TypeLocBuilder TLB;
4031 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00004032
Douglas Gregor579c15f2011-03-02 18:32:08 +00004033 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004034 TemplateSpecializationTypeLoc SpecTL =
4035 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004036
Douglas Gregor579c15f2011-03-02 18:32:08 +00004037 TemplateName Template
4038 = getDerived().TransformTemplateName(SS,
4039 SpecTL.getTypePtr()->getTemplateName(),
4040 SpecTL.getTemplateNameLoc(),
4041 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00004042 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004043 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004044
4045 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004046 Template);
4047 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004048 DependentTemplateSpecializationTypeLoc SpecTL =
4049 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004050
Douglas Gregor579c15f2011-03-02 18:32:08 +00004051 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00004052 = getDerived().RebuildTemplateName(SS,
4053 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004054 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00004055 ObjectType, UnqualLookup);
4056 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004057 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004058
4059 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004060 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004061 Template,
4062 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00004063 } else {
4064 // Nothing special needs to be done for these.
4065 Result = getDerived().TransformType(TLB, TL);
4066 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004067
4068 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004069 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004070
Douglas Gregor579c15f2011-03-02 18:32:08 +00004071 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4072}
4073
John McCall550e0c22009-10-21 00:40:46 +00004074template <class TyLoc> static inline
4075QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
4076 TyLoc NewT = TLB.push<TyLoc>(T.getType());
4077 NewT.setNameLoc(T.getNameLoc());
4078 return T.getType();
4079}
4080
John McCall550e0c22009-10-21 00:40:46 +00004081template<typename Derived>
4082QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004083 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00004084 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
4085 NewT.setBuiltinLoc(T.getBuiltinLoc());
4086 if (T.needsExtraLocalData())
4087 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
4088 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004089}
Mike Stump11289f42009-09-09 15:08:12 +00004090
Douglas Gregord6ff3322009-08-04 16:50:30 +00004091template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004092QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004093 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00004094 // FIXME: recurse?
4095 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004096}
Mike Stump11289f42009-09-09 15:08:12 +00004097
Reid Kleckner0503a872013-12-05 01:23:43 +00004098template <typename Derived>
4099QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
4100 AdjustedTypeLoc TL) {
4101 // Adjustments applied during transformation are handled elsewhere.
4102 return getDerived().TransformType(TLB, TL.getOriginalLoc());
4103}
4104
Douglas Gregord6ff3322009-08-04 16:50:30 +00004105template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00004106QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
4107 DecayedTypeLoc TL) {
4108 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
4109 if (OriginalType.isNull())
4110 return QualType();
4111
4112 QualType Result = TL.getType();
4113 if (getDerived().AlwaysRebuild() ||
4114 OriginalType != TL.getOriginalLoc().getType())
4115 Result = SemaRef.Context.getDecayedType(OriginalType);
4116 TLB.push<DecayedTypeLoc>(Result);
4117 // Nothing to set for DecayedTypeLoc.
4118 return Result;
4119}
4120
4121template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004122QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004123 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004124 QualType PointeeType
4125 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004126 if (PointeeType.isNull())
4127 return QualType();
4128
4129 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00004130 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004131 // A dependent pointer type 'T *' has is being transformed such
4132 // that an Objective-C class type is being replaced for 'T'. The
4133 // resulting pointer type is an ObjCObjectPointerType, not a
4134 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00004135 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00004136
John McCall8b07ec22010-05-15 11:32:37 +00004137 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
4138 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004139 return Result;
4140 }
John McCall31f82722010-11-12 08:19:04 +00004141
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004142 if (getDerived().AlwaysRebuild() ||
4143 PointeeType != TL.getPointeeLoc().getType()) {
4144 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
4145 if (Result.isNull())
4146 return QualType();
4147 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004148
John McCall31168b02011-06-15 23:02:42 +00004149 // Objective-C ARC can add lifetime qualifiers to the type that we're
4150 // pointing to.
4151 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00004152
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004153 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
4154 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00004155 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004156}
Mike Stump11289f42009-09-09 15:08:12 +00004157
4158template<typename Derived>
4159QualType
John McCall550e0c22009-10-21 00:40:46 +00004160TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004161 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00004162 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00004163 = getDerived().TransformType(TLB, TL.getPointeeLoc());
4164 if (PointeeType.isNull())
4165 return QualType();
4166
4167 QualType Result = TL.getType();
4168 if (getDerived().AlwaysRebuild() ||
4169 PointeeType != TL.getPointeeLoc().getType()) {
4170 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00004171 TL.getSigilLoc());
4172 if (Result.isNull())
4173 return QualType();
4174 }
4175
Douglas Gregor049211a2010-04-22 16:50:51 +00004176 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00004177 NewT.setSigilLoc(TL.getSigilLoc());
4178 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004179}
4180
John McCall70dd5f62009-10-30 00:06:24 +00004181/// Transforms a reference type. Note that somewhat paradoxically we
4182/// don't care whether the type itself is an l-value type or an r-value
4183/// type; we only care if the type was *written* as an l-value type
4184/// or an r-value type.
4185template<typename Derived>
4186QualType
4187TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004188 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00004189 const ReferenceType *T = TL.getTypePtr();
4190
4191 // Note that this works with the pointee-as-written.
4192 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4193 if (PointeeType.isNull())
4194 return QualType();
4195
4196 QualType Result = TL.getType();
4197 if (getDerived().AlwaysRebuild() ||
4198 PointeeType != T->getPointeeTypeAsWritten()) {
4199 Result = getDerived().RebuildReferenceType(PointeeType,
4200 T->isSpelledAsLValue(),
4201 TL.getSigilLoc());
4202 if (Result.isNull())
4203 return QualType();
4204 }
4205
John McCall31168b02011-06-15 23:02:42 +00004206 // Objective-C ARC can add lifetime qualifiers to the type that we're
4207 // referring to.
4208 TLB.TypeWasModifiedSafely(
4209 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4210
John McCall70dd5f62009-10-30 00:06:24 +00004211 // r-value references can be rebuilt as l-value references.
4212 ReferenceTypeLoc NewTL;
4213 if (isa<LValueReferenceType>(Result))
4214 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4215 else
4216 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4217 NewTL.setSigilLoc(TL.getSigilLoc());
4218
4219 return Result;
4220}
4221
Mike Stump11289f42009-09-09 15:08:12 +00004222template<typename Derived>
4223QualType
John McCall550e0c22009-10-21 00:40:46 +00004224TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004225 LValueReferenceTypeLoc TL) {
4226 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004227}
4228
Mike Stump11289f42009-09-09 15:08:12 +00004229template<typename Derived>
4230QualType
John McCall550e0c22009-10-21 00:40:46 +00004231TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004232 RValueReferenceTypeLoc TL) {
4233 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004234}
Mike Stump11289f42009-09-09 15:08:12 +00004235
Douglas Gregord6ff3322009-08-04 16:50:30 +00004236template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004237QualType
John McCall550e0c22009-10-21 00:40:46 +00004238TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004239 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004240 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004241 if (PointeeType.isNull())
4242 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004243
Abramo Bagnara509357842011-03-05 14:42:21 +00004244 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004245 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00004246 if (OldClsTInfo) {
4247 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4248 if (!NewClsTInfo)
4249 return QualType();
4250 }
4251
4252 const MemberPointerType *T = TL.getTypePtr();
4253 QualType OldClsType = QualType(T->getClass(), 0);
4254 QualType NewClsType;
4255 if (NewClsTInfo)
4256 NewClsType = NewClsTInfo->getType();
4257 else {
4258 NewClsType = getDerived().TransformType(OldClsType);
4259 if (NewClsType.isNull())
4260 return QualType();
4261 }
Mike Stump11289f42009-09-09 15:08:12 +00004262
John McCall550e0c22009-10-21 00:40:46 +00004263 QualType Result = TL.getType();
4264 if (getDerived().AlwaysRebuild() ||
4265 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00004266 NewClsType != OldClsType) {
4267 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004268 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004269 if (Result.isNull())
4270 return QualType();
4271 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004272
Reid Kleckner0503a872013-12-05 01:23:43 +00004273 // If we had to adjust the pointee type when building a member pointer, make
4274 // sure to push TypeLoc info for it.
4275 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4276 if (MPT && PointeeType != MPT->getPointeeType()) {
4277 assert(isa<AdjustedType>(MPT->getPointeeType()));
4278 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4279 }
4280
John McCall550e0c22009-10-21 00:40:46 +00004281 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4282 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004283 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004284
4285 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004286}
4287
Mike Stump11289f42009-09-09 15:08:12 +00004288template<typename Derived>
4289QualType
John McCall550e0c22009-10-21 00:40:46 +00004290TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004291 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004292 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004293 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004294 if (ElementType.isNull())
4295 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004296
John McCall550e0c22009-10-21 00:40:46 +00004297 QualType Result = TL.getType();
4298 if (getDerived().AlwaysRebuild() ||
4299 ElementType != T->getElementType()) {
4300 Result = getDerived().RebuildConstantArrayType(ElementType,
4301 T->getSizeModifier(),
4302 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004303 T->getIndexTypeCVRQualifiers(),
4304 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004305 if (Result.isNull())
4306 return QualType();
4307 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004308
4309 // We might have either a ConstantArrayType or a VariableArrayType now:
4310 // a ConstantArrayType is allowed to have an element type which is a
4311 // VariableArrayType if the type is dependent. Fortunately, all array
4312 // types have the same location layout.
4313 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004314 NewTL.setLBracketLoc(TL.getLBracketLoc());
4315 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004316
John McCall550e0c22009-10-21 00:40:46 +00004317 Expr *Size = TL.getSizeExpr();
4318 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004319 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4320 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004321 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4322 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004323 }
4324 NewTL.setSizeExpr(Size);
4325
4326 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004327}
Mike Stump11289f42009-09-09 15:08:12 +00004328
Douglas Gregord6ff3322009-08-04 16:50:30 +00004329template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004330QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004331 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004332 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004333 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004334 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004335 if (ElementType.isNull())
4336 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004337
John McCall550e0c22009-10-21 00:40:46 +00004338 QualType Result = TL.getType();
4339 if (getDerived().AlwaysRebuild() ||
4340 ElementType != T->getElementType()) {
4341 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004342 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004343 T->getIndexTypeCVRQualifiers(),
4344 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004345 if (Result.isNull())
4346 return QualType();
4347 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004348
John McCall550e0c22009-10-21 00:40:46 +00004349 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4350 NewTL.setLBracketLoc(TL.getLBracketLoc());
4351 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004352 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004353
4354 return Result;
4355}
4356
4357template<typename Derived>
4358QualType
4359TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004360 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004361 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004362 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4363 if (ElementType.isNull())
4364 return QualType();
4365
John McCalldadc5752010-08-24 06:29:42 +00004366 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00004367 = getDerived().TransformExpr(T->getSizeExpr());
4368 if (SizeResult.isInvalid())
4369 return QualType();
4370
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004371 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004372
4373 QualType Result = TL.getType();
4374 if (getDerived().AlwaysRebuild() ||
4375 ElementType != T->getElementType() ||
4376 Size != T->getSizeExpr()) {
4377 Result = getDerived().RebuildVariableArrayType(ElementType,
4378 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004379 Size,
John McCall550e0c22009-10-21 00:40:46 +00004380 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004381 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004382 if (Result.isNull())
4383 return QualType();
4384 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004385
Serge Pavlov774c6d02014-02-06 03:49:11 +00004386 // We might have constant size array now, but fortunately it has the same
4387 // location layout.
4388 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004389 NewTL.setLBracketLoc(TL.getLBracketLoc());
4390 NewTL.setRBracketLoc(TL.getRBracketLoc());
4391 NewTL.setSizeExpr(Size);
4392
4393 return Result;
4394}
4395
4396template<typename Derived>
4397QualType
4398TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004399 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004400 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004401 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4402 if (ElementType.isNull())
4403 return QualType();
4404
Richard Smith764d2fe2011-12-20 02:08:33 +00004405 // Array bounds are constant expressions.
4406 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4407 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004408
John McCall33ddac02011-01-19 10:06:00 +00004409 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4410 Expr *origSize = TL.getSizeExpr();
4411 if (!origSize) origSize = T->getSizeExpr();
4412
4413 ExprResult sizeResult
4414 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004415 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004416 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004417 return QualType();
4418
John McCall33ddac02011-01-19 10:06:00 +00004419 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004420
4421 QualType Result = TL.getType();
4422 if (getDerived().AlwaysRebuild() ||
4423 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004424 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004425 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4426 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004427 size,
John McCall550e0c22009-10-21 00:40:46 +00004428 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004429 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004430 if (Result.isNull())
4431 return QualType();
4432 }
John McCall550e0c22009-10-21 00:40:46 +00004433
4434 // We might have any sort of array type now, but fortunately they
4435 // all have the same location layout.
4436 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4437 NewTL.setLBracketLoc(TL.getLBracketLoc());
4438 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004439 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004440
4441 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004442}
Mike Stump11289f42009-09-09 15:08:12 +00004443
4444template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004445QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004446 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004447 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004448 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004449
4450 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004451 QualType ElementType = getDerived().TransformType(T->getElementType());
4452 if (ElementType.isNull())
4453 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004454
Richard Smith764d2fe2011-12-20 02:08:33 +00004455 // Vector sizes are constant expressions.
4456 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4457 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004458
John McCalldadc5752010-08-24 06:29:42 +00004459 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004460 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004461 if (Size.isInvalid())
4462 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004463
John McCall550e0c22009-10-21 00:40:46 +00004464 QualType Result = TL.getType();
4465 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004466 ElementType != T->getElementType() ||
4467 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004468 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004469 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004470 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004471 if (Result.isNull())
4472 return QualType();
4473 }
John McCall550e0c22009-10-21 00:40:46 +00004474
4475 // Result might be dependent or not.
4476 if (isa<DependentSizedExtVectorType>(Result)) {
4477 DependentSizedExtVectorTypeLoc NewTL
4478 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4479 NewTL.setNameLoc(TL.getNameLoc());
4480 } else {
4481 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4482 NewTL.setNameLoc(TL.getNameLoc());
4483 }
4484
4485 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004486}
Mike Stump11289f42009-09-09 15:08:12 +00004487
4488template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004489QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004490 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004491 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004492 QualType ElementType = getDerived().TransformType(T->getElementType());
4493 if (ElementType.isNull())
4494 return QualType();
4495
John McCall550e0c22009-10-21 00:40:46 +00004496 QualType Result = TL.getType();
4497 if (getDerived().AlwaysRebuild() ||
4498 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004499 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004500 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004501 if (Result.isNull())
4502 return QualType();
4503 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004504
John McCall550e0c22009-10-21 00:40:46 +00004505 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4506 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004507
John McCall550e0c22009-10-21 00:40:46 +00004508 return Result;
4509}
4510
4511template<typename Derived>
4512QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004513 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004514 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004515 QualType ElementType = getDerived().TransformType(T->getElementType());
4516 if (ElementType.isNull())
4517 return QualType();
4518
4519 QualType Result = TL.getType();
4520 if (getDerived().AlwaysRebuild() ||
4521 ElementType != T->getElementType()) {
4522 Result = getDerived().RebuildExtVectorType(ElementType,
4523 T->getNumElements(),
4524 /*FIXME*/ SourceLocation());
4525 if (Result.isNull())
4526 return QualType();
4527 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004528
John McCall550e0c22009-10-21 00:40:46 +00004529 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4530 NewTL.setNameLoc(TL.getNameLoc());
4531
4532 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004533}
Mike Stump11289f42009-09-09 15:08:12 +00004534
David Blaikie05785d12013-02-20 22:23:23 +00004535template <typename Derived>
4536ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4537 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4538 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004539 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004540 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004541
Douglas Gregor715e4612011-01-14 22:40:04 +00004542 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004543 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004544 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004545 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004546 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004547
Douglas Gregor715e4612011-01-14 22:40:04 +00004548 TypeLocBuilder TLB;
4549 TypeLoc NewTL = OldDI->getTypeLoc();
4550 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004551
4552 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004553 OldExpansionTL.getPatternLoc());
4554 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004555 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004556
4557 Result = RebuildPackExpansionType(Result,
4558 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004559 OldExpansionTL.getEllipsisLoc(),
4560 NumExpansions);
4561 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004562 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004563
Douglas Gregor715e4612011-01-14 22:40:04 +00004564 PackExpansionTypeLoc NewExpansionTL
4565 = TLB.push<PackExpansionTypeLoc>(Result);
4566 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4567 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4568 } else
4569 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004570 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004571 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004572
John McCall8fb0d9d2011-05-01 22:35:37 +00004573 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004574 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004575
4576 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4577 OldParm->getDeclContext(),
4578 OldParm->getInnerLocStart(),
4579 OldParm->getLocation(),
4580 OldParm->getIdentifier(),
4581 NewDI->getType(),
4582 NewDI,
4583 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004584 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004585 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4586 OldParm->getFunctionScopeIndex() + indexAdjustment);
4587 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004588}
4589
4590template<typename Derived>
4591bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004592 TransformFunctionTypeParams(SourceLocation Loc,
4593 ParmVarDecl **Params, unsigned NumParams,
4594 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004595 SmallVectorImpl<QualType> &OutParamTypes,
4596 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004597 int indexAdjustment = 0;
4598
Douglas Gregordd472162011-01-07 00:20:55 +00004599 for (unsigned i = 0; i != NumParams; ++i) {
4600 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004601 assert(OldParm->getFunctionScopeIndex() == i);
4602
David Blaikie05785d12013-02-20 22:23:23 +00004603 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004604 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004605 if (OldParm->isParameterPack()) {
4606 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004607 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004608
Douglas Gregor5499af42011-01-05 23:12:31 +00004609 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004610 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004611 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004612 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4613 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004614 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4615
Douglas Gregor5499af42011-01-05 23:12:31 +00004616 // Determine whether we should expand the parameter packs.
4617 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004618 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004619 Optional<unsigned> OrigNumExpansions =
4620 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004621 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004622 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4623 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004624 Unexpanded,
4625 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004626 RetainExpansion,
4627 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004628 return true;
4629 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004630
Douglas Gregor5499af42011-01-05 23:12:31 +00004631 if (ShouldExpand) {
4632 // Expand the function parameter pack into multiple, separate
4633 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004634 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004635 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004636 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004637 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004638 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004639 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004640 OrigNumExpansions,
4641 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004642 if (!NewParm)
4643 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004644
Douglas Gregordd472162011-01-07 00:20:55 +00004645 OutParamTypes.push_back(NewParm->getType());
4646 if (PVars)
4647 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004648 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004649
4650 // If we're supposed to retain a pack expansion, do so by temporarily
4651 // forgetting the partially-substituted parameter pack.
4652 if (RetainExpansion) {
4653 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004654 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004655 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004656 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004657 OrigNumExpansions,
4658 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004659 if (!NewParm)
4660 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004661
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004662 OutParamTypes.push_back(NewParm->getType());
4663 if (PVars)
4664 PVars->push_back(NewParm);
4665 }
4666
John McCall8fb0d9d2011-05-01 22:35:37 +00004667 // The next parameter should have the same adjustment as the
4668 // last thing we pushed, but we post-incremented indexAdjustment
4669 // on every push. Also, if we push nothing, the adjustment should
4670 // go down by one.
4671 indexAdjustment--;
4672
Douglas Gregor5499af42011-01-05 23:12:31 +00004673 // We're done with the pack expansion.
4674 continue;
4675 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004676
4677 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004678 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004679 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4680 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004681 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004682 NumExpansions,
4683 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004684 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004685 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004686 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004687 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004688
John McCall58f10c32010-03-11 09:03:00 +00004689 if (!NewParm)
4690 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004691
Douglas Gregordd472162011-01-07 00:20:55 +00004692 OutParamTypes.push_back(NewParm->getType());
4693 if (PVars)
4694 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004695 continue;
4696 }
John McCall58f10c32010-03-11 09:03:00 +00004697
4698 // Deal with the possibility that we don't have a parameter
4699 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004700 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004701 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004702 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004703 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004704 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004705 = dyn_cast<PackExpansionType>(OldType)) {
4706 // We have a function parameter pack that may need to be expanded.
4707 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004708 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004709 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004710
Douglas Gregor5499af42011-01-05 23:12:31 +00004711 // Determine whether we should expand the parameter packs.
4712 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004713 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004714 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004715 Unexpanded,
4716 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004717 RetainExpansion,
4718 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004719 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004720 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004721
Douglas Gregor5499af42011-01-05 23:12:31 +00004722 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004723 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004724 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004725 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004726 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4727 QualType NewType = getDerived().TransformType(Pattern);
4728 if (NewType.isNull())
4729 return true;
John McCall58f10c32010-03-11 09:03:00 +00004730
Douglas Gregordd472162011-01-07 00:20:55 +00004731 OutParamTypes.push_back(NewType);
4732 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004733 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004734 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004735
Douglas Gregor5499af42011-01-05 23:12:31 +00004736 // We're done with the pack expansion.
4737 continue;
4738 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004739
Douglas Gregor48d24112011-01-10 20:53:55 +00004740 // If we're supposed to retain a pack expansion, do so by temporarily
4741 // forgetting the partially-substituted parameter pack.
4742 if (RetainExpansion) {
4743 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4744 QualType NewType = getDerived().TransformType(Pattern);
4745 if (NewType.isNull())
4746 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004747
Douglas Gregor48d24112011-01-10 20:53:55 +00004748 OutParamTypes.push_back(NewType);
4749 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004750 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004751 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004752
Chad Rosier1dcde962012-08-08 18:46:20 +00004753 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004754 // expansion.
4755 OldType = Expansion->getPattern();
4756 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004757 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4758 NewType = getDerived().TransformType(OldType);
4759 } else {
4760 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004761 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004762
Douglas Gregor5499af42011-01-05 23:12:31 +00004763 if (NewType.isNull())
4764 return true;
4765
4766 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004767 NewType = getSema().Context.getPackExpansionType(NewType,
4768 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004769
Douglas Gregordd472162011-01-07 00:20:55 +00004770 OutParamTypes.push_back(NewType);
4771 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004772 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004773 }
4774
John McCall8fb0d9d2011-05-01 22:35:37 +00004775#ifndef NDEBUG
4776 if (PVars) {
4777 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4778 if (ParmVarDecl *parm = (*PVars)[i])
4779 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004780 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004781#endif
4782
4783 return false;
4784}
John McCall58f10c32010-03-11 09:03:00 +00004785
4786template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004787QualType
John McCall550e0c22009-10-21 00:40:46 +00004788TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004789 FunctionProtoTypeLoc TL) {
Richard Smith2e321552014-11-12 02:00:47 +00004790 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00004791 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00004792 return getDerived().TransformFunctionProtoType(
4793 TLB, TL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00004794 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
4795 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
4796 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00004797 });
Douglas Gregor3024f072012-04-16 07:05:22 +00004798}
4799
Richard Smith2e321552014-11-12 02:00:47 +00004800template<typename Derived> template<typename Fn>
4801QualType TreeTransform<Derived>::TransformFunctionProtoType(
4802 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
4803 unsigned ThisTypeQuals, Fn TransformExceptionSpec) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004804 // Transform the parameters and return type.
4805 //
Richard Smithf623c962012-04-17 00:58:00 +00004806 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004807 // When the function has a trailing return type, we instantiate the
4808 // parameters before the return type, since the return type can then refer
4809 // to the parameters themselves (via decltype, sizeof, etc.).
4810 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004811 SmallVector<QualType, 4> ParamTypes;
4812 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004813 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004814
Douglas Gregor7fb25412010-10-01 18:44:50 +00004815 QualType ResultType;
4816
Richard Smith1226c602012-08-14 22:51:13 +00004817 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004818 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004819 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004820 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004821 return QualType();
4822
Douglas Gregor3024f072012-04-16 07:05:22 +00004823 {
4824 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004825 // If a declaration declares a member function or member function
4826 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004827 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004828 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004829 // declarator.
4830 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004831
Alp Toker42a16a62014-01-25 23:51:36 +00004832 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004833 if (ResultType.isNull())
4834 return QualType();
4835 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004836 }
4837 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004838 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004839 if (ResultType.isNull())
4840 return QualType();
4841
Alp Toker9cacbab2014-01-20 20:26:09 +00004842 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004843 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004844 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004845 return QualType();
4846 }
4847
Richard Smith2e321552014-11-12 02:00:47 +00004848 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
4849
4850 bool EPIChanged = false;
4851 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
4852 return QualType();
4853
4854 // FIXME: Need to transform ConsumedParameters for variadic template
4855 // expansion.
Richard Smithf623c962012-04-17 00:58:00 +00004856
John McCall550e0c22009-10-21 00:40:46 +00004857 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004858 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Benjamin Kramere1c08b02015-08-18 08:10:39 +00004859 T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) {
Richard Smith2e321552014-11-12 02:00:47 +00004860 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
John McCall550e0c22009-10-21 00:40:46 +00004861 if (Result.isNull())
4862 return QualType();
4863 }
Mike Stump11289f42009-09-09 15:08:12 +00004864
John McCall550e0c22009-10-21 00:40:46 +00004865 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004866 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004867 NewTL.setLParenLoc(TL.getLParenLoc());
4868 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004869 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004870 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4871 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004872
4873 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004874}
Mike Stump11289f42009-09-09 15:08:12 +00004875
Douglas Gregord6ff3322009-08-04 16:50:30 +00004876template<typename Derived>
Richard Smith2e321552014-11-12 02:00:47 +00004877bool TreeTransform<Derived>::TransformExceptionSpec(
4878 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
4879 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
4880 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
4881
4882 // Instantiate a dynamic noexcept expression, if any.
4883 if (ESI.Type == EST_ComputedNoexcept) {
4884 EnterExpressionEvaluationContext Unevaluated(getSema(),
4885 Sema::ConstantEvaluated);
4886 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
4887 if (NoexceptExpr.isInvalid())
4888 return true;
4889
4890 NoexceptExpr = getSema().CheckBooleanCondition(
4891 NoexceptExpr.get(), NoexceptExpr.get()->getLocStart());
4892 if (NoexceptExpr.isInvalid())
4893 return true;
4894
4895 if (!NoexceptExpr.get()->isValueDependent()) {
4896 NoexceptExpr = getSema().VerifyIntegerConstantExpression(
4897 NoexceptExpr.get(), nullptr,
4898 diag::err_noexcept_needs_constant_expression,
4899 /*AllowFold*/false);
4900 if (NoexceptExpr.isInvalid())
4901 return true;
4902 }
4903
4904 if (ESI.NoexceptExpr != NoexceptExpr.get())
4905 Changed = true;
4906 ESI.NoexceptExpr = NoexceptExpr.get();
4907 }
4908
4909 if (ESI.Type != EST_Dynamic)
4910 return false;
4911
4912 // Instantiate a dynamic exception specification's type.
4913 for (QualType T : ESI.Exceptions) {
4914 if (const PackExpansionType *PackExpansion =
4915 T->getAs<PackExpansionType>()) {
4916 Changed = true;
4917
4918 // We have a pack expansion. Instantiate it.
4919 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
4920 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
4921 Unexpanded);
4922 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4923
4924 // Determine whether the set of unexpanded parameter packs can and
4925 // should
4926 // be expanded.
4927 bool Expand = false;
4928 bool RetainExpansion = false;
4929 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
4930 // FIXME: Track the location of the ellipsis (and track source location
4931 // information for the types in the exception specification in general).
4932 if (getDerived().TryExpandParameterPacks(
4933 Loc, SourceRange(), Unexpanded, Expand,
4934 RetainExpansion, NumExpansions))
4935 return true;
4936
4937 if (!Expand) {
4938 // We can't expand this pack expansion into separate arguments yet;
4939 // just substitute into the pattern and create a new pack expansion
4940 // type.
4941 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4942 QualType U = getDerived().TransformType(PackExpansion->getPattern());
4943 if (U.isNull())
4944 return true;
4945
4946 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
4947 Exceptions.push_back(U);
4948 continue;
4949 }
4950
4951 // Substitute into the pack expansion pattern for each slice of the
4952 // pack.
4953 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
4954 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
4955
4956 QualType U = getDerived().TransformType(PackExpansion->getPattern());
4957 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
4958 return true;
4959
4960 Exceptions.push_back(U);
4961 }
4962 } else {
4963 QualType U = getDerived().TransformType(T);
4964 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
4965 return true;
4966 if (T != U)
4967 Changed = true;
4968
4969 Exceptions.push_back(U);
4970 }
4971 }
4972
4973 ESI.Exceptions = Exceptions;
4974 return false;
4975}
4976
4977template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004978QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004979 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004980 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004981 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00004982 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00004983 if (ResultType.isNull())
4984 return QualType();
4985
4986 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004987 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00004988 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4989
4990 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004991 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004992 NewTL.setLParenLoc(TL.getLParenLoc());
4993 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004994 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004995
4996 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004997}
Mike Stump11289f42009-09-09 15:08:12 +00004998
John McCallb96ec562009-12-04 22:46:56 +00004999template<typename Derived> QualType
5000TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005001 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005002 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005003 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00005004 if (!D)
5005 return QualType();
5006
5007 QualType Result = TL.getType();
5008 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
5009 Result = getDerived().RebuildUnresolvedUsingType(D);
5010 if (Result.isNull())
5011 return QualType();
5012 }
5013
5014 // We might get an arbitrary type spec type back. We should at
5015 // least always get a type spec type, though.
5016 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
5017 NewTL.setNameLoc(TL.getNameLoc());
5018
5019 return Result;
5020}
5021
Douglas Gregord6ff3322009-08-04 16:50:30 +00005022template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005023QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005024 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005025 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00005026 TypedefNameDecl *Typedef
5027 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5028 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005029 if (!Typedef)
5030 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005031
John McCall550e0c22009-10-21 00:40:46 +00005032 QualType Result = TL.getType();
5033 if (getDerived().AlwaysRebuild() ||
5034 Typedef != T->getDecl()) {
5035 Result = getDerived().RebuildTypedefType(Typedef);
5036 if (Result.isNull())
5037 return QualType();
5038 }
Mike Stump11289f42009-09-09 15:08:12 +00005039
John McCall550e0c22009-10-21 00:40:46 +00005040 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
5041 NewTL.setNameLoc(TL.getNameLoc());
5042
5043 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005044}
Mike Stump11289f42009-09-09 15:08:12 +00005045
Douglas Gregord6ff3322009-08-04 16:50:30 +00005046template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005047QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005048 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00005049 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00005050 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
5051 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00005052
John McCalldadc5752010-08-24 06:29:42 +00005053 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005054 if (E.isInvalid())
5055 return QualType();
5056
Eli Friedmane4f22df2012-02-29 04:03:55 +00005057 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
5058 if (E.isInvalid())
5059 return QualType();
5060
John McCall550e0c22009-10-21 00:40:46 +00005061 QualType Result = TL.getType();
5062 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00005063 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005064 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00005065 if (Result.isNull())
5066 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005067 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005068 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005069
John McCall550e0c22009-10-21 00:40:46 +00005070 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005071 NewTL.setTypeofLoc(TL.getTypeofLoc());
5072 NewTL.setLParenLoc(TL.getLParenLoc());
5073 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00005074
5075 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005076}
Mike Stump11289f42009-09-09 15:08:12 +00005077
5078template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005079QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005080 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00005081 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
5082 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
5083 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005084 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005085
John McCall550e0c22009-10-21 00:40:46 +00005086 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00005087 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
5088 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00005089 if (Result.isNull())
5090 return QualType();
5091 }
Mike Stump11289f42009-09-09 15:08:12 +00005092
John McCall550e0c22009-10-21 00:40:46 +00005093 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005094 NewTL.setTypeofLoc(TL.getTypeofLoc());
5095 NewTL.setLParenLoc(TL.getLParenLoc());
5096 NewTL.setRParenLoc(TL.getRParenLoc());
5097 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00005098
5099 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005100}
Mike Stump11289f42009-09-09 15:08:12 +00005101
5102template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005103QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005104 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005105 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00005106
Douglas Gregore922c772009-08-04 22:27:00 +00005107 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00005108 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
5109 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00005110
John McCalldadc5752010-08-24 06:29:42 +00005111 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005112 if (E.isInvalid())
5113 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005114
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005115 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00005116 if (E.isInvalid())
5117 return QualType();
5118
John McCall550e0c22009-10-21 00:40:46 +00005119 QualType Result = TL.getType();
5120 if (getDerived().AlwaysRebuild() ||
5121 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005122 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005123 if (Result.isNull())
5124 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005125 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005126 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005127
John McCall550e0c22009-10-21 00:40:46 +00005128 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
5129 NewTL.setNameLoc(TL.getNameLoc());
5130
5131 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005132}
5133
5134template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00005135QualType TreeTransform<Derived>::TransformUnaryTransformType(
5136 TypeLocBuilder &TLB,
5137 UnaryTransformTypeLoc TL) {
5138 QualType Result = TL.getType();
5139 if (Result->isDependentType()) {
5140 const UnaryTransformType *T = TL.getTypePtr();
5141 QualType NewBase =
5142 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
5143 Result = getDerived().RebuildUnaryTransformType(NewBase,
5144 T->getUTTKind(),
5145 TL.getKWLoc());
5146 if (Result.isNull())
5147 return QualType();
5148 }
5149
5150 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
5151 NewTL.setKWLoc(TL.getKWLoc());
5152 NewTL.setParensRange(TL.getParensRange());
5153 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
5154 return Result;
5155}
5156
5157template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00005158QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
5159 AutoTypeLoc TL) {
5160 const AutoType *T = TL.getTypePtr();
5161 QualType OldDeduced = T->getDeducedType();
5162 QualType NewDeduced;
5163 if (!OldDeduced.isNull()) {
5164 NewDeduced = getDerived().TransformType(OldDeduced);
5165 if (NewDeduced.isNull())
5166 return QualType();
5167 }
5168
5169 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00005170 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
5171 T->isDependentType()) {
Richard Smithe301ba22015-11-11 02:02:15 +00005172 Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword());
Richard Smith30482bc2011-02-20 03:19:35 +00005173 if (Result.isNull())
5174 return QualType();
5175 }
5176
5177 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5178 NewTL.setNameLoc(TL.getNameLoc());
5179
5180 return Result;
5181}
5182
5183template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005184QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005185 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005186 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005187 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005188 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5189 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005190 if (!Record)
5191 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005192
John McCall550e0c22009-10-21 00:40:46 +00005193 QualType Result = TL.getType();
5194 if (getDerived().AlwaysRebuild() ||
5195 Record != T->getDecl()) {
5196 Result = getDerived().RebuildRecordType(Record);
5197 if (Result.isNull())
5198 return QualType();
5199 }
Mike Stump11289f42009-09-09 15:08:12 +00005200
John McCall550e0c22009-10-21 00:40:46 +00005201 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5202 NewTL.setNameLoc(TL.getNameLoc());
5203
5204 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005205}
Mike Stump11289f42009-09-09 15:08:12 +00005206
5207template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005208QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005209 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005210 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005211 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005212 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5213 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005214 if (!Enum)
5215 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005216
John McCall550e0c22009-10-21 00:40:46 +00005217 QualType Result = TL.getType();
5218 if (getDerived().AlwaysRebuild() ||
5219 Enum != T->getDecl()) {
5220 Result = getDerived().RebuildEnumType(Enum);
5221 if (Result.isNull())
5222 return QualType();
5223 }
Mike Stump11289f42009-09-09 15:08:12 +00005224
John McCall550e0c22009-10-21 00:40:46 +00005225 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5226 NewTL.setNameLoc(TL.getNameLoc());
5227
5228 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005229}
John McCallfcc33b02009-09-05 00:15:47 +00005230
John McCalle78aac42010-03-10 03:28:59 +00005231template<typename Derived>
5232QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5233 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005234 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00005235 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5236 TL.getTypePtr()->getDecl());
5237 if (!D) return QualType();
5238
5239 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5240 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5241 return T;
5242}
5243
Douglas Gregord6ff3322009-08-04 16:50:30 +00005244template<typename Derived>
5245QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005246 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005247 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00005248 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005249}
5250
Mike Stump11289f42009-09-09 15:08:12 +00005251template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00005252QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005253 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005254 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005255 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005256
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005257 // Substitute into the replacement type, which itself might involve something
5258 // that needs to be transformed. This only tends to occur with default
5259 // template arguments of template template parameters.
5260 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5261 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5262 if (Replacement.isNull())
5263 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005264
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005265 // Always canonicalize the replacement type.
5266 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5267 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00005268 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005269 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00005270
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005271 // Propagate type-source information.
5272 SubstTemplateTypeParmTypeLoc NewTL
5273 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5274 NewTL.setNameLoc(TL.getNameLoc());
5275 return Result;
5276
John McCallcebee162009-10-18 09:09:24 +00005277}
5278
5279template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00005280QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5281 TypeLocBuilder &TLB,
5282 SubstTemplateTypeParmPackTypeLoc TL) {
5283 return TransformTypeSpecType(TLB, TL);
5284}
5285
5286template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00005287QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005288 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005289 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00005290 const TemplateSpecializationType *T = TL.getTypePtr();
5291
Douglas Gregordf846d12011-03-02 18:46:51 +00005292 // The nested-name-specifier never matters in a TemplateSpecializationType,
5293 // because we can't have a dependent nested-name-specifier anyway.
5294 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00005295 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00005296 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5297 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005298 if (Template.isNull())
5299 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005300
John McCall31f82722010-11-12 08:19:04 +00005301 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5302}
5303
Eli Friedman0dfb8892011-10-06 23:00:33 +00005304template<typename Derived>
5305QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5306 AtomicTypeLoc TL) {
5307 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5308 if (ValueType.isNull())
5309 return QualType();
5310
5311 QualType Result = TL.getType();
5312 if (getDerived().AlwaysRebuild() ||
5313 ValueType != TL.getValueLoc().getType()) {
5314 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5315 if (Result.isNull())
5316 return QualType();
5317 }
5318
5319 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5320 NewTL.setKWLoc(TL.getKWLoc());
5321 NewTL.setLParenLoc(TL.getLParenLoc());
5322 NewTL.setRParenLoc(TL.getRParenLoc());
5323
5324 return Result;
5325}
5326
Chad Rosier1dcde962012-08-08 18:46:20 +00005327 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00005328 /// container that provides a \c getArgLoc() member function.
5329 ///
5330 /// This iterator is intended to be used with the iterator form of
5331 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5332 template<typename ArgLocContainer>
5333 class TemplateArgumentLocContainerIterator {
5334 ArgLocContainer *Container;
5335 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00005336
Douglas Gregorfe921a72010-12-20 23:36:19 +00005337 public:
5338 typedef TemplateArgumentLoc value_type;
5339 typedef TemplateArgumentLoc reference;
5340 typedef int difference_type;
5341 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00005342
Douglas Gregorfe921a72010-12-20 23:36:19 +00005343 class pointer {
5344 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00005345
Douglas Gregorfe921a72010-12-20 23:36:19 +00005346 public:
5347 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005348
Douglas Gregorfe921a72010-12-20 23:36:19 +00005349 const TemplateArgumentLoc *operator->() const {
5350 return &Arg;
5351 }
5352 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005353
5354
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00005355 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00005356
Douglas Gregorfe921a72010-12-20 23:36:19 +00005357 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5358 unsigned Index)
5359 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005360
Douglas Gregorfe921a72010-12-20 23:36:19 +00005361 TemplateArgumentLocContainerIterator &operator++() {
5362 ++Index;
5363 return *this;
5364 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005365
Douglas Gregorfe921a72010-12-20 23:36:19 +00005366 TemplateArgumentLocContainerIterator operator++(int) {
5367 TemplateArgumentLocContainerIterator Old(*this);
5368 ++(*this);
5369 return Old;
5370 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005371
Douglas Gregorfe921a72010-12-20 23:36:19 +00005372 TemplateArgumentLoc operator*() const {
5373 return Container->getArgLoc(Index);
5374 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005375
Douglas Gregorfe921a72010-12-20 23:36:19 +00005376 pointer operator->() const {
5377 return pointer(Container->getArgLoc(Index));
5378 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005379
Douglas Gregorfe921a72010-12-20 23:36:19 +00005380 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005381 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005382 return X.Container == Y.Container && X.Index == Y.Index;
5383 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005384
Douglas Gregorfe921a72010-12-20 23:36:19 +00005385 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005386 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005387 return !(X == Y);
5388 }
5389 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005390
5391
John McCall31f82722010-11-12 08:19:04 +00005392template <typename Derived>
5393QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5394 TypeLocBuilder &TLB,
5395 TemplateSpecializationTypeLoc TL,
5396 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005397 TemplateArgumentListInfo NewTemplateArgs;
5398 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5399 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005400 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5401 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005402 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005403 ArgIterator(TL, TL.getNumArgs()),
5404 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005405 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005406
John McCall0ad16662009-10-29 08:12:44 +00005407 // FIXME: maybe don't rebuild if all the template arguments are the same.
5408
5409 QualType Result =
5410 getDerived().RebuildTemplateSpecializationType(Template,
5411 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005412 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005413
5414 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005415 // Specializations of template template parameters are represented as
5416 // TemplateSpecializationTypes, and substitution of type alias templates
5417 // within a dependent context can transform them into
5418 // DependentTemplateSpecializationTypes.
5419 if (isa<DependentTemplateSpecializationType>(Result)) {
5420 DependentTemplateSpecializationTypeLoc NewTL
5421 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005422 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005423 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005424 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005425 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005426 NewTL.setLAngleLoc(TL.getLAngleLoc());
5427 NewTL.setRAngleLoc(TL.getRAngleLoc());
5428 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5429 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5430 return Result;
5431 }
5432
John McCall0ad16662009-10-29 08:12:44 +00005433 TemplateSpecializationTypeLoc NewTL
5434 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005435 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005436 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5437 NewTL.setLAngleLoc(TL.getLAngleLoc());
5438 NewTL.setRAngleLoc(TL.getRAngleLoc());
5439 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5440 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005441 }
Mike Stump11289f42009-09-09 15:08:12 +00005442
John McCall0ad16662009-10-29 08:12:44 +00005443 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005444}
Mike Stump11289f42009-09-09 15:08:12 +00005445
Douglas Gregor5a064722011-02-28 17:23:35 +00005446template <typename Derived>
5447QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5448 TypeLocBuilder &TLB,
5449 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005450 TemplateName Template,
5451 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005452 TemplateArgumentListInfo NewTemplateArgs;
5453 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5454 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5455 typedef TemplateArgumentLocContainerIterator<
5456 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005457 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005458 ArgIterator(TL, TL.getNumArgs()),
5459 NewTemplateArgs))
5460 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005461
Douglas Gregor5a064722011-02-28 17:23:35 +00005462 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005463
Douglas Gregor5a064722011-02-28 17:23:35 +00005464 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5465 QualType Result
5466 = getSema().Context.getDependentTemplateSpecializationType(
5467 TL.getTypePtr()->getKeyword(),
5468 DTN->getQualifier(),
5469 DTN->getIdentifier(),
5470 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005471
Douglas Gregor5a064722011-02-28 17:23:35 +00005472 DependentTemplateSpecializationTypeLoc NewTL
5473 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005474 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005475 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005476 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005477 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005478 NewTL.setLAngleLoc(TL.getLAngleLoc());
5479 NewTL.setRAngleLoc(TL.getRAngleLoc());
5480 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5481 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5482 return Result;
5483 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005484
5485 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005486 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005487 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005488 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005489
Douglas Gregor5a064722011-02-28 17:23:35 +00005490 if (!Result.isNull()) {
5491 /// FIXME: Wrap this in an elaborated-type-specifier?
5492 TemplateSpecializationTypeLoc NewTL
5493 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005494 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005495 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005496 NewTL.setLAngleLoc(TL.getLAngleLoc());
5497 NewTL.setRAngleLoc(TL.getRAngleLoc());
5498 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5499 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5500 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005501
Douglas Gregor5a064722011-02-28 17:23:35 +00005502 return Result;
5503}
5504
Mike Stump11289f42009-09-09 15:08:12 +00005505template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005506QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005507TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005508 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005509 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005510
Douglas Gregor844cb502011-03-01 18:12:44 +00005511 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005512 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005513 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005514 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005515 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5516 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005517 return QualType();
5518 }
Mike Stump11289f42009-09-09 15:08:12 +00005519
John McCall31f82722010-11-12 08:19:04 +00005520 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5521 if (NamedT.isNull())
5522 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005523
Richard Smith3f1b5d02011-05-05 21:57:07 +00005524 // C++0x [dcl.type.elab]p2:
5525 // If the identifier resolves to a typedef-name or the simple-template-id
5526 // resolves to an alias template specialization, the
5527 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005528 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5529 if (const TemplateSpecializationType *TST =
5530 NamedT->getAs<TemplateSpecializationType>()) {
5531 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00005532 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5533 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00005534 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5535 diag::err_tag_reference_non_tag) << 4;
5536 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5537 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005538 }
5539 }
5540
John McCall550e0c22009-10-21 00:40:46 +00005541 QualType Result = TL.getType();
5542 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005543 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005544 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005545 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005546 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005547 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005548 if (Result.isNull())
5549 return QualType();
5550 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005551
Abramo Bagnara6150c882010-05-11 21:36:43 +00005552 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005553 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005554 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005555 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005556}
Mike Stump11289f42009-09-09 15:08:12 +00005557
5558template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005559QualType TreeTransform<Derived>::TransformAttributedType(
5560 TypeLocBuilder &TLB,
5561 AttributedTypeLoc TL) {
5562 const AttributedType *oldType = TL.getTypePtr();
5563 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5564 if (modifiedType.isNull())
5565 return QualType();
5566
5567 QualType result = TL.getType();
5568
5569 // FIXME: dependent operand expressions?
5570 if (getDerived().AlwaysRebuild() ||
5571 modifiedType != oldType->getModifiedType()) {
5572 // TODO: this is really lame; we should really be rebuilding the
5573 // equivalent type from first principles.
5574 QualType equivalentType
5575 = getDerived().TransformType(oldType->getEquivalentType());
5576 if (equivalentType.isNull())
5577 return QualType();
Douglas Gregor261a89b2015-06-19 17:51:05 +00005578
5579 // Check whether we can add nullability; it is only represented as
5580 // type sugar, and therefore cannot be diagnosed in any other way.
5581 if (auto nullability = oldType->getImmediateNullability()) {
5582 if (!modifiedType->canHaveNullability()) {
5583 SemaRef.Diag(TL.getAttrNameLoc(), diag::err_nullability_nonpointer)
Douglas Gregoraea7afd2015-06-24 22:02:08 +00005584 << DiagNullabilityKind(*nullability, false) << modifiedType;
Douglas Gregor261a89b2015-06-19 17:51:05 +00005585 return QualType();
5586 }
5587 }
5588
John McCall81904512011-01-06 01:58:22 +00005589 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5590 modifiedType,
5591 equivalentType);
5592 }
5593
5594 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5595 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5596 if (TL.hasAttrOperand())
5597 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5598 if (TL.hasAttrExprOperand())
5599 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5600 else if (TL.hasAttrEnumOperand())
5601 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5602
5603 return result;
5604}
5605
5606template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005607QualType
5608TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5609 ParenTypeLoc TL) {
5610 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5611 if (Inner.isNull())
5612 return QualType();
5613
5614 QualType Result = TL.getType();
5615 if (getDerived().AlwaysRebuild() ||
5616 Inner != TL.getInnerLoc().getType()) {
5617 Result = getDerived().RebuildParenType(Inner);
5618 if (Result.isNull())
5619 return QualType();
5620 }
5621
5622 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5623 NewTL.setLParenLoc(TL.getLParenLoc());
5624 NewTL.setRParenLoc(TL.getRParenLoc());
5625 return Result;
5626}
5627
5628template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005629QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005630 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005631 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005632
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005633 NestedNameSpecifierLoc QualifierLoc
5634 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5635 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005636 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005637
John McCallc392f372010-06-11 00:33:02 +00005638 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005639 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005640 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005641 QualifierLoc,
5642 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005643 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005644 if (Result.isNull())
5645 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005646
Abramo Bagnarad7548482010-05-19 21:37:53 +00005647 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5648 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005649 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5650
Abramo Bagnarad7548482010-05-19 21:37:53 +00005651 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005652 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005653 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005654 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005655 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005656 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005657 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005658 NewTL.setNameLoc(TL.getNameLoc());
5659 }
John McCall550e0c22009-10-21 00:40:46 +00005660 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005661}
Mike Stump11289f42009-09-09 15:08:12 +00005662
Douglas Gregord6ff3322009-08-04 16:50:30 +00005663template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005664QualType TreeTransform<Derived>::
5665 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005666 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005667 NestedNameSpecifierLoc QualifierLoc;
5668 if (TL.getQualifierLoc()) {
5669 QualifierLoc
5670 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5671 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005672 return QualType();
5673 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005674
John McCall31f82722010-11-12 08:19:04 +00005675 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005676 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005677}
5678
5679template<typename Derived>
5680QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005681TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5682 DependentTemplateSpecializationTypeLoc TL,
5683 NestedNameSpecifierLoc QualifierLoc) {
5684 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005685
Douglas Gregora7a795b2011-03-01 20:11:18 +00005686 TemplateArgumentListInfo NewTemplateArgs;
5687 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5688 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005689
Douglas Gregora7a795b2011-03-01 20:11:18 +00005690 typedef TemplateArgumentLocContainerIterator<
5691 DependentTemplateSpecializationTypeLoc> ArgIterator;
5692 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5693 ArgIterator(TL, TL.getNumArgs()),
5694 NewTemplateArgs))
5695 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005696
Douglas Gregora7a795b2011-03-01 20:11:18 +00005697 QualType Result
5698 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5699 QualifierLoc,
5700 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005701 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005702 NewTemplateArgs);
5703 if (Result.isNull())
5704 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005705
Douglas Gregora7a795b2011-03-01 20:11:18 +00005706 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5707 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005708
Douglas Gregora7a795b2011-03-01 20:11:18 +00005709 // Copy information relevant to the template specialization.
5710 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005711 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005712 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005713 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005714 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5715 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005716 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005717 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005718
Douglas Gregora7a795b2011-03-01 20:11:18 +00005719 // Copy information relevant to the elaborated type.
5720 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005721 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005722 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005723 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5724 DependentTemplateSpecializationTypeLoc SpecTL
5725 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005726 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005727 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005728 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005729 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005730 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5731 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005732 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005733 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005734 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005735 TemplateSpecializationTypeLoc SpecTL
5736 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005737 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005738 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005739 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5740 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005741 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005742 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005743 }
5744 return Result;
5745}
5746
5747template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005748QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5749 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005750 QualType Pattern
5751 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005752 if (Pattern.isNull())
5753 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005754
5755 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005756 if (getDerived().AlwaysRebuild() ||
5757 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005758 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005759 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005760 TL.getEllipsisLoc(),
5761 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005762 if (Result.isNull())
5763 return QualType();
5764 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005765
Douglas Gregor822d0302011-01-12 17:07:58 +00005766 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5767 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5768 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005769}
5770
5771template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005772QualType
5773TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005774 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005775 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005776 TLB.pushFullCopy(TL);
5777 return TL.getType();
5778}
5779
5780template<typename Derived>
5781QualType
5782TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005783 ObjCObjectTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00005784 // Transform base type.
5785 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
5786 if (BaseType.isNull())
5787 return QualType();
5788
5789 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
5790
5791 // Transform type arguments.
5792 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
5793 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
5794 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
5795 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
5796 QualType TypeArg = TypeArgInfo->getType();
5797 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
5798 AnyChanged = true;
5799
5800 // We have a pack expansion. Instantiate it.
5801 const auto *PackExpansion = PackExpansionLoc.getType()
5802 ->castAs<PackExpansionType>();
5803 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5804 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5805 Unexpanded);
5806 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5807
5808 // Determine whether the set of unexpanded parameter packs can
5809 // and should be expanded.
5810 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
5811 bool Expand = false;
5812 bool RetainExpansion = false;
5813 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5814 if (getDerived().TryExpandParameterPacks(
5815 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
5816 Unexpanded, Expand, RetainExpansion, NumExpansions))
5817 return QualType();
5818
5819 if (!Expand) {
5820 // We can't expand this pack expansion into separate arguments yet;
5821 // just substitute into the pattern and create a new pack expansion
5822 // type.
5823 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5824
5825 TypeLocBuilder TypeArgBuilder;
5826 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
5827 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
5828 PatternLoc);
5829 if (NewPatternType.isNull())
5830 return QualType();
5831
5832 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
5833 NewPatternType, NumExpansions);
5834 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
5835 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
5836 NewTypeArgInfos.push_back(
5837 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
5838 continue;
5839 }
5840
5841 // Substitute into the pack expansion pattern for each slice of the
5842 // pack.
5843 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5844 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5845
5846 TypeLocBuilder TypeArgBuilder;
5847 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
5848
5849 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
5850 PatternLoc);
5851 if (NewTypeArg.isNull())
5852 return QualType();
5853
5854 NewTypeArgInfos.push_back(
5855 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
5856 }
5857
5858 continue;
5859 }
5860
5861 TypeLocBuilder TypeArgBuilder;
5862 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
5863 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
5864 if (NewTypeArg.isNull())
5865 return QualType();
5866
5867 // If nothing changed, just keep the old TypeSourceInfo.
5868 if (NewTypeArg == TypeArg) {
5869 NewTypeArgInfos.push_back(TypeArgInfo);
5870 continue;
5871 }
5872
5873 NewTypeArgInfos.push_back(
5874 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
5875 AnyChanged = true;
5876 }
5877
5878 QualType Result = TL.getType();
5879 if (getDerived().AlwaysRebuild() || AnyChanged) {
5880 // Rebuild the type.
5881 Result = getDerived().RebuildObjCObjectType(
5882 BaseType,
5883 TL.getLocStart(),
5884 TL.getTypeArgsLAngleLoc(),
5885 NewTypeArgInfos,
5886 TL.getTypeArgsRAngleLoc(),
5887 TL.getProtocolLAngleLoc(),
5888 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
5889 TL.getNumProtocols()),
5890 TL.getProtocolLocs(),
5891 TL.getProtocolRAngleLoc());
5892
5893 if (Result.isNull())
5894 return QualType();
5895 }
5896
5897 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
5898 assert(TL.hasBaseTypeAsWritten() && "Can't be dependent");
5899 NewT.setHasBaseTypeAsWritten(true);
5900 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
5901 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
5902 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
5903 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
5904 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
5905 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
5906 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
5907 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
5908 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005909}
Mike Stump11289f42009-09-09 15:08:12 +00005910
5911template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005912QualType
5913TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005914 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00005915 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
5916 if (PointeeType.isNull())
5917 return QualType();
5918
5919 QualType Result = TL.getType();
5920 if (getDerived().AlwaysRebuild() ||
5921 PointeeType != TL.getPointeeLoc().getType()) {
5922 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
5923 TL.getStarLoc());
5924 if (Result.isNull())
5925 return QualType();
5926 }
5927
5928 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
5929 NewT.setStarLoc(TL.getStarLoc());
5930 return Result;
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005931}
5932
Douglas Gregord6ff3322009-08-04 16:50:30 +00005933//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005934// Statement transformation
5935//===----------------------------------------------------------------------===//
5936template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005937StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005938TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005939 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005940}
5941
5942template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005943StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005944TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5945 return getDerived().TransformCompoundStmt(S, false);
5946}
5947
5948template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005949StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005950TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005951 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005952 Sema::CompoundScopeRAII CompoundScope(getSema());
5953
John McCall1ababa62010-08-27 19:56:05 +00005954 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005955 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005956 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005957 for (auto *B : S->body()) {
5958 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00005959 if (Result.isInvalid()) {
5960 // Immediately fail if this was a DeclStmt, since it's very
5961 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005962 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00005963 return StmtError();
5964
5965 // Otherwise, just keep processing substatements and fail later.
5966 SubStmtInvalid = true;
5967 continue;
5968 }
Mike Stump11289f42009-09-09 15:08:12 +00005969
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005970 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005971 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00005972 }
Mike Stump11289f42009-09-09 15:08:12 +00005973
John McCall1ababa62010-08-27 19:56:05 +00005974 if (SubStmtInvalid)
5975 return StmtError();
5976
Douglas Gregorebe10102009-08-20 07:17:43 +00005977 if (!getDerived().AlwaysRebuild() &&
5978 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005979 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005980
5981 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005982 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005983 S->getRBracLoc(),
5984 IsStmtExpr);
5985}
Mike Stump11289f42009-09-09 15:08:12 +00005986
Douglas Gregorebe10102009-08-20 07:17:43 +00005987template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005988StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005989TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005990 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005991 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005992 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5993 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005994
Eli Friedman06577382009-11-19 03:14:00 +00005995 // Transform the left-hand case value.
5996 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005997 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005998 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005999 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006000
Eli Friedman06577382009-11-19 03:14:00 +00006001 // Transform the right-hand case value (for the GNU case-range extension).
6002 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00006003 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00006004 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006005 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00006006 }
Mike Stump11289f42009-09-09 15:08:12 +00006007
Douglas Gregorebe10102009-08-20 07:17:43 +00006008 // Build the case statement.
6009 // Case statements are always rebuilt so that they will attached to their
6010 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006011 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00006012 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006013 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00006014 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006015 S->getColonLoc());
6016 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006017 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006018
Douglas Gregorebe10102009-08-20 07:17:43 +00006019 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00006020 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006021 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006022 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006023
Douglas Gregorebe10102009-08-20 07:17:43 +00006024 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00006025 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006026}
6027
6028template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006029StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006030TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006031 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00006032 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006033 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006034 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006035
Douglas Gregorebe10102009-08-20 07:17:43 +00006036 // Default statements are always rebuilt
6037 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006038 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006039}
Mike Stump11289f42009-09-09 15:08:12 +00006040
Douglas Gregorebe10102009-08-20 07:17:43 +00006041template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006042StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006043TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006044 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006045 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006046 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006047
Chris Lattnercab02a62011-02-17 20:34:02 +00006048 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
6049 S->getDecl());
6050 if (!LD)
6051 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00006052
6053
Douglas Gregorebe10102009-08-20 07:17:43 +00006054 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00006055 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006056 cast<LabelDecl>(LD), SourceLocation(),
6057 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006058}
Mike Stump11289f42009-09-09 15:08:12 +00006059
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006060template <typename Derived>
6061const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
6062 if (!R)
6063 return R;
6064
6065 switch (R->getKind()) {
6066// Transform attributes with a pragma spelling by calling TransformXXXAttr.
6067#define ATTR(X)
6068#define PRAGMA_SPELLING_ATTR(X) \
6069 case attr::X: \
6070 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
6071#include "clang/Basic/AttrList.inc"
6072 default:
6073 return R;
6074 }
6075}
6076
6077template <typename Derived>
6078StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
6079 bool AttrsChanged = false;
6080 SmallVector<const Attr *, 1> Attrs;
6081
6082 // Visit attributes and keep track if any are transformed.
6083 for (const auto *I : S->getAttrs()) {
6084 const Attr *R = getDerived().TransformAttr(I);
6085 AttrsChanged |= (I != R);
6086 Attrs.push_back(R);
6087 }
6088
Richard Smithc202b282012-04-14 00:33:13 +00006089 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6090 if (SubStmt.isInvalid())
6091 return StmtError();
6092
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006093 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
Richard Smithc202b282012-04-14 00:33:13 +00006094 return S;
6095
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006096 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00006097 SubStmt.get());
6098}
6099
6100template<typename Derived>
6101StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006102TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006103 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006104 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006105 VarDecl *ConditionVar = nullptr;
Douglas Gregor633caca2009-11-23 23:44:04 +00006106 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006107 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00006108 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006109 getDerived().TransformDefinition(
6110 S->getConditionVariable()->getLocation(),
6111 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00006112 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006113 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006114 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00006115 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006116
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006117 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006118 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006119
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006120 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00006121 if (S->getCond()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006122 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00006123 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00006124 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006125 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006126
John McCallb268a282010-08-23 23:25:46 +00006127 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006128 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006129 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006130
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006131 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00006132 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006133 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006134
Douglas Gregorebe10102009-08-20 07:17:43 +00006135 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00006136 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00006137 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006138 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006139
Douglas Gregorebe10102009-08-20 07:17:43 +00006140 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00006141 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00006142 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006143 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006144
Douglas Gregorebe10102009-08-20 07:17:43 +00006145 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00006146 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006147 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006148 Then.get() == S->getThen() &&
6149 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006150 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006151
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006152 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00006153 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00006154 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006155}
6156
6157template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006158StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006159TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006160 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00006161 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006162 VarDecl *ConditionVar = nullptr;
Douglas Gregordcf19622009-11-24 17:07:59 +00006163 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006164 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00006165 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006166 getDerived().TransformDefinition(
6167 S->getConditionVariable()->getLocation(),
6168 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00006169 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006170 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006171 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00006172 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006173
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006174 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006175 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006176 }
Mike Stump11289f42009-09-09 15:08:12 +00006177
Douglas Gregorebe10102009-08-20 07:17:43 +00006178 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006179 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00006180 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00006181 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00006182 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006183 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006184
Douglas Gregorebe10102009-08-20 07:17:43 +00006185 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006186 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006187 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006188 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006189
Douglas Gregorebe10102009-08-20 07:17:43 +00006190 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00006191 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
6192 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006193}
Mike Stump11289f42009-09-09 15:08:12 +00006194
Douglas Gregorebe10102009-08-20 07:17:43 +00006195template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006196StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006197TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006198 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006199 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006200 VarDecl *ConditionVar = nullptr;
Douglas Gregor680f8612009-11-24 21:15:44 +00006201 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006202 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00006203 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006204 getDerived().TransformDefinition(
6205 S->getConditionVariable()->getLocation(),
6206 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00006207 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006208 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006209 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00006210 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006211
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006212 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006213 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006214
6215 if (S->getCond()) {
6216 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00006217 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
6218 S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00006219 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00006220 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006221 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00006222 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00006223 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006224 }
Mike Stump11289f42009-09-09 15:08:12 +00006225
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006226 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00006227 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006228 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006229
Douglas Gregorebe10102009-08-20 07:17:43 +00006230 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006231 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006232 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006233 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006234
Douglas Gregorebe10102009-08-20 07:17:43 +00006235 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00006236 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006237 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006238 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00006239 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00006240
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006241 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00006242 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006243}
Mike Stump11289f42009-09-09 15:08:12 +00006244
Douglas Gregorebe10102009-08-20 07:17:43 +00006245template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006246StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006247TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006248 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006249 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006250 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006251 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006252
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006253 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006254 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006255 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006256 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006257
Douglas Gregorebe10102009-08-20 07:17:43 +00006258 if (!getDerived().AlwaysRebuild() &&
6259 Cond.get() == S->getCond() &&
6260 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006261 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006262
John McCallb268a282010-08-23 23:25:46 +00006263 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
6264 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006265 S->getRParenLoc());
6266}
Mike Stump11289f42009-09-09 15:08:12 +00006267
Douglas Gregorebe10102009-08-20 07:17:43 +00006268template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006269StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006270TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006271 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00006272 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00006273 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006274 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006275
Alexey Bataeva636c7f2015-12-23 10:27:45 +00006276 // In OpenMP loop region loop control variable must be captured and be
6277 // private. Perform analysis of first part (if any).
6278 if (getSema().getLangOpts().OpenMP && Init.isUsable())
6279 getSema().ActOnOpenMPLoopInitialization(S->getForLoc(), Init.get());
6280
Douglas Gregorebe10102009-08-20 07:17:43 +00006281 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006282 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006283 VarDecl *ConditionVar = nullptr;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006284 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006285 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006286 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006287 getDerived().TransformDefinition(
6288 S->getConditionVariable()->getLocation(),
6289 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006290 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006291 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006292 } else {
6293 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006294
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006295 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006296 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006297
6298 if (S->getCond()) {
6299 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00006300 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
6301 S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00006302 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00006303 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006304 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006305
John McCallb268a282010-08-23 23:25:46 +00006306 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006307 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006308 }
Mike Stump11289f42009-09-09 15:08:12 +00006309
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006310 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00006311 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006312 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006313
Douglas Gregorebe10102009-08-20 07:17:43 +00006314 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00006315 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006316 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006317 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006318
Richard Smith945f8d32013-01-14 22:39:08 +00006319 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00006320 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006321 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006322
Douglas Gregorebe10102009-08-20 07:17:43 +00006323 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006324 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006325 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006326 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006327
Douglas Gregorebe10102009-08-20 07:17:43 +00006328 if (!getDerived().AlwaysRebuild() &&
6329 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00006330 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006331 Inc.get() == S->getInc() &&
6332 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006333 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006334
Douglas Gregorebe10102009-08-20 07:17:43 +00006335 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006336 Init.get(), FullCond, ConditionVar,
6337 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006338}
6339
6340template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006341StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006342TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006343 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6344 S->getLabel());
6345 if (!LD)
6346 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006347
Douglas Gregorebe10102009-08-20 07:17:43 +00006348 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00006349 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006350 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00006351}
6352
6353template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006354StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006355TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006356 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00006357 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006358 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006359 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00006360
Douglas Gregorebe10102009-08-20 07:17:43 +00006361 if (!getDerived().AlwaysRebuild() &&
6362 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006363 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006364
6365 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00006366 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006367}
6368
6369template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006370StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006371TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006372 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006373}
Mike Stump11289f42009-09-09 15:08:12 +00006374
Douglas Gregorebe10102009-08-20 07:17:43 +00006375template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006376StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006377TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006378 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006379}
Mike Stump11289f42009-09-09 15:08:12 +00006380
Douglas Gregorebe10102009-08-20 07:17:43 +00006381template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006382StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006383TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00006384 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6385 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00006386 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006387 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006388
Mike Stump11289f42009-09-09 15:08:12 +00006389 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00006390 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00006391 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006392}
Mike Stump11289f42009-09-09 15:08:12 +00006393
Douglas Gregorebe10102009-08-20 07:17:43 +00006394template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006395StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006396TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006397 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006398 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006399 for (auto *D : S->decls()) {
6400 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00006401 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00006402 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006403
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006404 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00006405 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00006406
Douglas Gregorebe10102009-08-20 07:17:43 +00006407 Decls.push_back(Transformed);
6408 }
Mike Stump11289f42009-09-09 15:08:12 +00006409
Douglas Gregorebe10102009-08-20 07:17:43 +00006410 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006411 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006412
Rafael Espindolaab417692013-07-09 12:05:01 +00006413 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006414}
Mike Stump11289f42009-09-09 15:08:12 +00006415
Douglas Gregorebe10102009-08-20 07:17:43 +00006416template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006417StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00006418TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006419
Benjamin Kramerf0623432012-08-23 22:51:59 +00006420 SmallVector<Expr*, 8> Constraints;
6421 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006422 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00006423
John McCalldadc5752010-08-24 06:29:42 +00006424 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006425 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006426
6427 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00006428
Anders Carlssonaaeef072010-01-24 05:50:09 +00006429 // Go through the outputs.
6430 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006431 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006432
Anders Carlssonaaeef072010-01-24 05:50:09 +00006433 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006434 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006435
Anders Carlssonaaeef072010-01-24 05:50:09 +00006436 // Transform the output expr.
6437 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006438 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006439 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006440 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006441
Anders Carlssonaaeef072010-01-24 05:50:09 +00006442 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006443
John McCallb268a282010-08-23 23:25:46 +00006444 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006445 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006446
Anders Carlssonaaeef072010-01-24 05:50:09 +00006447 // Go through the inputs.
6448 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006449 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006450
Anders Carlssonaaeef072010-01-24 05:50:09 +00006451 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006452 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006453
Anders Carlssonaaeef072010-01-24 05:50:09 +00006454 // Transform the input expr.
6455 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006456 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006457 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006458 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006459
Anders Carlssonaaeef072010-01-24 05:50:09 +00006460 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006461
John McCallb268a282010-08-23 23:25:46 +00006462 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006463 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006464
Anders Carlssonaaeef072010-01-24 05:50:09 +00006465 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006466 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006467
6468 // Go through the clobbers.
6469 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00006470 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00006471
6472 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006473 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00006474 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
6475 S->isVolatile(), S->getNumOutputs(),
6476 S->getNumInputs(), Names.data(),
6477 Constraints, Exprs, AsmString.get(),
6478 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006479}
6480
Chad Rosier32503022012-06-11 20:47:18 +00006481template<typename Derived>
6482StmtResult
6483TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00006484 ArrayRef<Token> AsmToks =
6485 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00006486
John McCallf413f5e2013-05-03 00:10:13 +00006487 bool HadError = false, HadChange = false;
6488
6489 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6490 SmallVector<Expr*, 8> TransformedExprs;
6491 TransformedExprs.reserve(SrcExprs.size());
6492 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6493 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
6494 if (!Result.isUsable()) {
6495 HadError = true;
6496 } else {
6497 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006498 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00006499 }
6500 }
6501
6502 if (HadError) return StmtError();
6503 if (!HadChange && !getDerived().AlwaysRebuild())
6504 return Owned(S);
6505
Chad Rosierb6f46c12012-08-15 16:53:30 +00006506 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00006507 AsmToks, S->getAsmString(),
6508 S->getNumOutputs(), S->getNumInputs(),
6509 S->getAllConstraints(), S->getClobbers(),
6510 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00006511}
Douglas Gregorebe10102009-08-20 07:17:43 +00006512
Richard Smith9f690bd2015-10-27 06:02:45 +00006513// C++ Coroutines TS
6514
6515template<typename Derived>
6516StmtResult
6517TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) {
6518 // The coroutine body should be re-formed by the caller if necessary.
6519 return getDerived().TransformStmt(S->getBody());
6520}
6521
6522template<typename Derived>
6523StmtResult
6524TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
6525 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
6526 /*NotCopyInit*/false);
6527 if (Result.isInvalid())
6528 return StmtError();
6529
6530 // Always rebuild; we don't know if this needs to be injected into a new
6531 // context or if the promise type has changed.
6532 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get());
6533}
6534
6535template<typename Derived>
6536ExprResult
6537TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) {
6538 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
6539 /*NotCopyInit*/false);
6540 if (Result.isInvalid())
6541 return ExprError();
6542
6543 // Always rebuild; we don't know if this needs to be injected into a new
6544 // context or if the promise type has changed.
6545 return getDerived().RebuildCoawaitExpr(E->getKeywordLoc(), Result.get());
6546}
6547
6548template<typename Derived>
6549ExprResult
6550TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) {
6551 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
6552 /*NotCopyInit*/false);
6553 if (Result.isInvalid())
6554 return ExprError();
6555
6556 // Always rebuild; we don't know if this needs to be injected into a new
6557 // context or if the promise type has changed.
6558 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
6559}
6560
6561// Objective-C Statements.
6562
Douglas Gregorebe10102009-08-20 07:17:43 +00006563template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006564StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006565TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006566 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00006567 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006568 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006569 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006570
Douglas Gregor96c79492010-04-23 22:50:49 +00006571 // Transform the @catch statements (if present).
6572 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006573 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00006574 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006575 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00006576 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006577 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00006578 if (Catch.get() != S->getCatchStmt(I))
6579 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006580 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006581 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006582
Douglas Gregor306de2f2010-04-22 23:59:56 +00006583 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00006584 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006585 if (S->getFinallyStmt()) {
6586 Finally = getDerived().TransformStmt(S->getFinallyStmt());
6587 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006588 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00006589 }
6590
6591 // If nothing changed, just retain this statement.
6592 if (!getDerived().AlwaysRebuild() &&
6593 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00006594 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00006595 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006596 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006597
Douglas Gregor306de2f2010-04-22 23:59:56 +00006598 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00006599 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006600 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006601}
Mike Stump11289f42009-09-09 15:08:12 +00006602
Douglas Gregorebe10102009-08-20 07:17:43 +00006603template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006604StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006605TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006606 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00006607 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006608 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006609 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006610 if (FromVar->getTypeSourceInfo()) {
6611 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
6612 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006613 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006614 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006615
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006616 QualType T;
6617 if (TSInfo)
6618 T = TSInfo->getType();
6619 else {
6620 T = getDerived().TransformType(FromVar->getType());
6621 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00006622 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006623 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006624
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006625 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6626 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00006627 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006628 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006629
John McCalldadc5752010-08-24 06:29:42 +00006630 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006631 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006632 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006633
6634 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006635 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006636 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006637}
Mike Stump11289f42009-09-09 15:08:12 +00006638
Douglas Gregorebe10102009-08-20 07:17:43 +00006639template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006640StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006641TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006642 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006643 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006644 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006645 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006646
Douglas Gregor306de2f2010-04-22 23:59:56 +00006647 // If nothing changed, just retain this statement.
6648 if (!getDerived().AlwaysRebuild() &&
6649 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006650 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006651
6652 // Build a new statement.
6653 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00006654 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006655}
Mike Stump11289f42009-09-09 15:08:12 +00006656
Douglas Gregorebe10102009-08-20 07:17:43 +00006657template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006658StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006659TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006660 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00006661 if (S->getThrowExpr()) {
6662 Operand = getDerived().TransformExpr(S->getThrowExpr());
6663 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006664 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00006665 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006666
Douglas Gregor2900c162010-04-22 21:44:01 +00006667 if (!getDerived().AlwaysRebuild() &&
6668 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006669 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006670
John McCallb268a282010-08-23 23:25:46 +00006671 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006672}
Mike Stump11289f42009-09-09 15:08:12 +00006673
Douglas Gregorebe10102009-08-20 07:17:43 +00006674template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006675StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006676TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006677 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00006678 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00006679 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00006680 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006681 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00006682 Object =
6683 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6684 Object.get());
6685 if (Object.isInvalid())
6686 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006687
Douglas Gregor6148de72010-04-22 22:01:21 +00006688 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006689 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00006690 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006691 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006692
Douglas Gregor6148de72010-04-22 22:01:21 +00006693 // If nothing change, just retain the current statement.
6694 if (!getDerived().AlwaysRebuild() &&
6695 Object.get() == S->getSynchExpr() &&
6696 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006697 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00006698
6699 // Build a new statement.
6700 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00006701 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006702}
6703
6704template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006705StmtResult
John McCall31168b02011-06-15 23:02:42 +00006706TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6707 ObjCAutoreleasePoolStmt *S) {
6708 // Transform the body.
6709 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6710 if (Body.isInvalid())
6711 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006712
John McCall31168b02011-06-15 23:02:42 +00006713 // If nothing changed, just retain this statement.
6714 if (!getDerived().AlwaysRebuild() &&
6715 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006716 return S;
John McCall31168b02011-06-15 23:02:42 +00006717
6718 // Build a new statement.
6719 return getDerived().RebuildObjCAutoreleasePoolStmt(
6720 S->getAtLoc(), Body.get());
6721}
6722
6723template<typename Derived>
6724StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006725TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006726 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006727 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006728 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006729 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006730 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006731
Douglas Gregorf68a5082010-04-22 23:10:45 +00006732 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006733 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006734 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006735 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006736
Douglas Gregorf68a5082010-04-22 23:10:45 +00006737 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006738 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006739 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006740 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006741
Douglas Gregorf68a5082010-04-22 23:10:45 +00006742 // If nothing changed, just retain this statement.
6743 if (!getDerived().AlwaysRebuild() &&
6744 Element.get() == S->getElement() &&
6745 Collection.get() == S->getCollection() &&
6746 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006747 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006748
Douglas Gregorf68a5082010-04-22 23:10:45 +00006749 // Build a new statement.
6750 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006751 Element.get(),
6752 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006753 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006754 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006755}
6756
David Majnemer5f7efef2013-10-15 09:50:08 +00006757template <typename Derived>
6758StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006759 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006760 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006761 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6762 TypeSourceInfo *T =
6763 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006764 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006765 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006766
David Majnemer5f7efef2013-10-15 09:50:08 +00006767 Var = getDerived().RebuildExceptionDecl(
6768 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6769 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006770 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006771 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006772 }
Mike Stump11289f42009-09-09 15:08:12 +00006773
Douglas Gregorebe10102009-08-20 07:17:43 +00006774 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006775 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006776 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006777 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006778
David Majnemer5f7efef2013-10-15 09:50:08 +00006779 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006780 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006781 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006782
David Majnemer5f7efef2013-10-15 09:50:08 +00006783 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006784}
Mike Stump11289f42009-09-09 15:08:12 +00006785
David Majnemer5f7efef2013-10-15 09:50:08 +00006786template <typename Derived>
6787StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006788 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006789 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006790 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006791 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006792
Douglas Gregorebe10102009-08-20 07:17:43 +00006793 // Transform the handlers.
6794 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006795 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006796 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006797 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006798 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006799 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006800
Douglas Gregorebe10102009-08-20 07:17:43 +00006801 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006802 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006803 }
Mike Stump11289f42009-09-09 15:08:12 +00006804
David Majnemer5f7efef2013-10-15 09:50:08 +00006805 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006806 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006807 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006808
John McCallb268a282010-08-23 23:25:46 +00006809 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006810 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006811}
Mike Stump11289f42009-09-09 15:08:12 +00006812
Richard Smith02e85f32011-04-14 22:09:26 +00006813template<typename Derived>
6814StmtResult
6815TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6816 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6817 if (Range.isInvalid())
6818 return StmtError();
6819
6820 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6821 if (BeginEnd.isInvalid())
6822 return StmtError();
6823
6824 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6825 if (Cond.isInvalid())
6826 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006827 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006828 Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc());
Eli Friedman87d32802012-01-31 22:45:40 +00006829 if (Cond.isInvalid())
6830 return StmtError();
6831 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006832 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006833
6834 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6835 if (Inc.isInvalid())
6836 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006837 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006838 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006839
6840 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6841 if (LoopVar.isInvalid())
6842 return StmtError();
6843
6844 StmtResult NewStmt = S;
6845 if (getDerived().AlwaysRebuild() ||
6846 Range.get() != S->getRangeStmt() ||
6847 BeginEnd.get() != S->getBeginEndStmt() ||
6848 Cond.get() != S->getCond() ||
6849 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006850 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006851 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00006852 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00006853 S->getColonLoc(), Range.get(),
6854 BeginEnd.get(), Cond.get(),
6855 Inc.get(), LoopVar.get(),
6856 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006857 if (NewStmt.isInvalid())
6858 return StmtError();
6859 }
Richard Smith02e85f32011-04-14 22:09:26 +00006860
6861 StmtResult Body = getDerived().TransformStmt(S->getBody());
6862 if (Body.isInvalid())
6863 return StmtError();
6864
6865 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6866 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006867 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006868 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00006869 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00006870 S->getColonLoc(), Range.get(),
6871 BeginEnd.get(), Cond.get(),
6872 Inc.get(), LoopVar.get(),
6873 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006874 if (NewStmt.isInvalid())
6875 return StmtError();
6876 }
Richard Smith02e85f32011-04-14 22:09:26 +00006877
6878 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006879 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00006880
6881 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6882}
6883
John Wiegley1c0675e2011-04-28 01:08:34 +00006884template<typename Derived>
6885StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006886TreeTransform<Derived>::TransformMSDependentExistsStmt(
6887 MSDependentExistsStmt *S) {
6888 // Transform the nested-name-specifier, if any.
6889 NestedNameSpecifierLoc QualifierLoc;
6890 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006891 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006892 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6893 if (!QualifierLoc)
6894 return StmtError();
6895 }
6896
6897 // Transform the declaration name.
6898 DeclarationNameInfo NameInfo = S->getNameInfo();
6899 if (NameInfo.getName()) {
6900 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6901 if (!NameInfo.getName())
6902 return StmtError();
6903 }
6904
6905 // Check whether anything changed.
6906 if (!getDerived().AlwaysRebuild() &&
6907 QualifierLoc == S->getQualifierLoc() &&
6908 NameInfo.getName() == S->getNameInfo().getName())
6909 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006910
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006911 // Determine whether this name exists, if we can.
6912 CXXScopeSpec SS;
6913 SS.Adopt(QualifierLoc);
6914 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00006915 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006916 case Sema::IER_Exists:
6917 if (S->isIfExists())
6918 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006919
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006920 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6921
6922 case Sema::IER_DoesNotExist:
6923 if (S->isIfNotExists())
6924 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006925
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006926 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006927
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006928 case Sema::IER_Dependent:
6929 Dependent = true;
6930 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006931
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006932 case Sema::IER_Error:
6933 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006934 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006935
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006936 // We need to continue with the instantiation, so do so now.
6937 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6938 if (SubStmt.isInvalid())
6939 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006940
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006941 // If we have resolved the name, just transform to the substatement.
6942 if (!Dependent)
6943 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006944
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006945 // The name is still dependent, so build a dependent expression again.
6946 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6947 S->isIfExists(),
6948 QualifierLoc,
6949 NameInfo,
6950 SubStmt.get());
6951}
6952
6953template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006954ExprResult
6955TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6956 NestedNameSpecifierLoc QualifierLoc;
6957 if (E->getQualifierLoc()) {
6958 QualifierLoc
6959 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6960 if (!QualifierLoc)
6961 return ExprError();
6962 }
6963
6964 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6965 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6966 if (!PD)
6967 return ExprError();
6968
6969 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6970 if (Base.isInvalid())
6971 return ExprError();
6972
6973 return new (SemaRef.getASTContext())
6974 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6975 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6976 QualifierLoc, E->getMemberLoc());
6977}
6978
David Majnemerfad8f482013-10-15 09:33:02 +00006979template <typename Derived>
Alexey Bataevf7630272015-11-25 12:01:00 +00006980ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr(
6981 MSPropertySubscriptExpr *E) {
6982 auto BaseRes = getDerived().TransformExpr(E->getBase());
6983 if (BaseRes.isInvalid())
6984 return ExprError();
6985 auto IdxRes = getDerived().TransformExpr(E->getIdx());
6986 if (IdxRes.isInvalid())
6987 return ExprError();
6988
6989 if (!getDerived().AlwaysRebuild() &&
6990 BaseRes.get() == E->getBase() &&
6991 IdxRes.get() == E->getIdx())
6992 return E;
6993
6994 return getDerived().RebuildArraySubscriptExpr(
6995 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
6996}
6997
6998template <typename Derived>
David Majnemerfad8f482013-10-15 09:33:02 +00006999StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007000 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007001 if (TryBlock.isInvalid())
7002 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007003
7004 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00007005 if (Handler.isInvalid())
7006 return StmtError();
7007
David Majnemerfad8f482013-10-15 09:33:02 +00007008 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
7009 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007010 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00007011
Warren Huntf6be4cb2014-07-25 20:52:51 +00007012 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
7013 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007014}
7015
David Majnemerfad8f482013-10-15 09:33:02 +00007016template <typename Derived>
7017StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007018 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007019 if (Block.isInvalid())
7020 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007021
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007022 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007023}
7024
David Majnemerfad8f482013-10-15 09:33:02 +00007025template <typename Derived>
7026StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00007027 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00007028 if (FilterExpr.isInvalid())
7029 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007030
David Majnemer7e755502013-10-15 09:30:14 +00007031 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007032 if (Block.isInvalid())
7033 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007034
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007035 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
7036 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007037}
7038
David Majnemerfad8f482013-10-15 09:33:02 +00007039template <typename Derived>
7040StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
7041 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00007042 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
7043 else
7044 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
7045}
7046
Nico Weber9b982072014-07-07 00:12:30 +00007047template<typename Derived>
7048StmtResult
7049TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
7050 return S;
7051}
7052
Alexander Musman64d33f12014-06-04 07:53:32 +00007053//===----------------------------------------------------------------------===//
7054// OpenMP directive transformation
7055//===----------------------------------------------------------------------===//
7056template <typename Derived>
7057StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
7058 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007059
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007060 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00007061 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007062 ArrayRef<OMPClause *> Clauses = D->clauses();
7063 TClauses.reserve(Clauses.size());
7064 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
7065 I != E; ++I) {
7066 if (*I) {
Alexey Bataevaac108a2015-06-23 04:51:00 +00007067 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007068 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevaac108a2015-06-23 04:51:00 +00007069 getDerived().getSema().EndOpenMPClause();
Alexey Bataevc5e02582014-06-16 07:08:35 +00007070 if (Clause)
7071 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00007072 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00007073 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007074 }
7075 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007076 StmtResult AssociatedStmt;
Alexey Bataeveb482352015-12-18 05:05:56 +00007077 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00007078 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
7079 /*CurScope=*/nullptr);
7080 StmtResult Body;
7081 {
7082 Sema::CompoundScopeRAII CompoundScope(getSema());
7083 Body = getDerived().TransformStmt(
7084 cast<CapturedStmt>(D->getAssociatedStmt())->getCapturedStmt());
7085 }
7086 AssociatedStmt =
7087 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
Alexey Bataev68446b72014-07-18 07:47:19 +00007088 if (AssociatedStmt.isInvalid()) {
7089 return StmtError();
7090 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00007091 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007092 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007093 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00007094 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007095
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007096 // Transform directive name for 'omp critical' directive.
7097 DeclarationNameInfo DirName;
7098 if (D->getDirectiveKind() == OMPD_critical) {
7099 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
7100 DirName = getDerived().TransformDeclarationNameInfo(DirName);
7101 }
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007102 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
7103 if (D->getDirectiveKind() == OMPD_cancellation_point) {
7104 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
Alexey Bataev80909872015-07-02 11:25:17 +00007105 } else if (D->getDirectiveKind() == OMPD_cancel) {
7106 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007107 }
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007108
Alexander Musman64d33f12014-06-04 07:53:32 +00007109 return getDerived().RebuildOMPExecutableDirective(
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007110 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
7111 AssociatedStmt.get(), D->getLocStart(), D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007112}
7113
Alexander Musman64d33f12014-06-04 07:53:32 +00007114template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007115StmtResult
7116TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
7117 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007118 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
7119 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007120 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7121 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7122 return Res;
7123}
7124
Alexander Musman64d33f12014-06-04 07:53:32 +00007125template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007126StmtResult
7127TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
7128 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007129 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
7130 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007131 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7132 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007133 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007134}
7135
Alexey Bataevf29276e2014-06-18 04:14:57 +00007136template <typename Derived>
7137StmtResult
7138TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
7139 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007140 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
7141 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00007142 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7143 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7144 return Res;
7145}
7146
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007147template <typename Derived>
7148StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00007149TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
7150 DeclarationNameInfo DirName;
7151 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
7152 D->getLocStart());
7153 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7154 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7155 return Res;
7156}
7157
7158template <typename Derived>
7159StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007160TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
7161 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007162 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
7163 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007164 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7165 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7166 return Res;
7167}
7168
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007169template <typename Derived>
7170StmtResult
7171TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
7172 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007173 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
7174 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007175 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7176 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7177 return Res;
7178}
7179
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007180template <typename Derived>
7181StmtResult
7182TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
7183 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007184 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
7185 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007186 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7187 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7188 return Res;
7189}
7190
Alexey Bataev4acb8592014-07-07 13:01:15 +00007191template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00007192StmtResult
7193TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
7194 DeclarationNameInfo DirName;
7195 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
7196 D->getLocStart());
7197 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7198 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7199 return Res;
7200}
7201
7202template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007203StmtResult
7204TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
7205 getDerived().getSema().StartOpenMPDSABlock(
7206 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
7207 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7208 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7209 return Res;
7210}
7211
7212template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00007213StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
7214 OMPParallelForDirective *D) {
7215 DeclarationNameInfo DirName;
7216 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
7217 nullptr, D->getLocStart());
7218 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7219 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7220 return Res;
7221}
7222
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007223template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00007224StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
7225 OMPParallelForSimdDirective *D) {
7226 DeclarationNameInfo DirName;
7227 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
7228 nullptr, D->getLocStart());
7229 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7230 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7231 return Res;
7232}
7233
7234template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007235StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
7236 OMPParallelSectionsDirective *D) {
7237 DeclarationNameInfo DirName;
7238 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
7239 nullptr, D->getLocStart());
7240 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7241 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7242 return Res;
7243}
7244
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00007245template <typename Derived>
7246StmtResult
7247TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
7248 DeclarationNameInfo DirName;
7249 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
7250 D->getLocStart());
7251 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7252 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7253 return Res;
7254}
7255
Alexey Bataev68446b72014-07-18 07:47:19 +00007256template <typename Derived>
7257StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
7258 OMPTaskyieldDirective *D) {
7259 DeclarationNameInfo DirName;
7260 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
7261 D->getLocStart());
7262 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7263 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7264 return Res;
7265}
7266
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00007267template <typename Derived>
7268StmtResult
7269TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
7270 DeclarationNameInfo DirName;
7271 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
7272 D->getLocStart());
7273 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7274 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7275 return Res;
7276}
7277
Alexey Bataev2df347a2014-07-18 10:17:07 +00007278template <typename Derived>
7279StmtResult
7280TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
7281 DeclarationNameInfo DirName;
7282 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
7283 D->getLocStart());
7284 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7285 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7286 return Res;
7287}
7288
Alexey Bataev6125da92014-07-21 11:26:11 +00007289template <typename Derived>
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00007290StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
7291 OMPTaskgroupDirective *D) {
7292 DeclarationNameInfo DirName;
7293 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
7294 D->getLocStart());
7295 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7296 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7297 return Res;
7298}
7299
7300template <typename Derived>
Alexey Bataev6125da92014-07-21 11:26:11 +00007301StmtResult
7302TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
7303 DeclarationNameInfo DirName;
7304 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
7305 D->getLocStart());
7306 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7307 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7308 return Res;
7309}
7310
Alexey Bataev9fb6e642014-07-22 06:45:04 +00007311template <typename Derived>
7312StmtResult
7313TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
7314 DeclarationNameInfo DirName;
7315 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
7316 D->getLocStart());
7317 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7318 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7319 return Res;
7320}
7321
Alexey Bataev0162e452014-07-22 10:10:35 +00007322template <typename Derived>
7323StmtResult
7324TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
7325 DeclarationNameInfo DirName;
7326 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
7327 D->getLocStart());
7328 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7329 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7330 return Res;
7331}
7332
Alexey Bataev0bd520b2014-09-19 08:19:49 +00007333template <typename Derived>
7334StmtResult
7335TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
7336 DeclarationNameInfo DirName;
7337 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
7338 D->getLocStart());
7339 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7340 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7341 return Res;
7342}
7343
Alexey Bataev13314bf2014-10-09 04:18:56 +00007344template <typename Derived>
Michael Wong65f367f2015-07-21 13:44:28 +00007345StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
7346 OMPTargetDataDirective *D) {
7347 DeclarationNameInfo DirName;
7348 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
7349 D->getLocStart());
7350 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7351 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7352 return Res;
7353}
7354
7355template <typename Derived>
Alexey Bataev13314bf2014-10-09 04:18:56 +00007356StmtResult
7357TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
7358 DeclarationNameInfo DirName;
7359 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
7360 D->getLocStart());
7361 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7362 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7363 return Res;
7364}
7365
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007366template <typename Derived>
7367StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
7368 OMPCancellationPointDirective *D) {
7369 DeclarationNameInfo DirName;
7370 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
7371 nullptr, D->getLocStart());
7372 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7373 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7374 return Res;
7375}
7376
Alexey Bataev80909872015-07-02 11:25:17 +00007377template <typename Derived>
7378StmtResult
7379TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
7380 DeclarationNameInfo DirName;
7381 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
7382 D->getLocStart());
7383 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7384 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7385 return Res;
7386}
7387
Alexey Bataev49f6e782015-12-01 04:18:41 +00007388template <typename Derived>
7389StmtResult
7390TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
7391 DeclarationNameInfo DirName;
7392 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr,
7393 D->getLocStart());
7394 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7395 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7396 return Res;
7397}
7398
Alexey Bataev0a6ed842015-12-03 09:40:15 +00007399template <typename Derived>
7400StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective(
7401 OMPTaskLoopSimdDirective *D) {
7402 DeclarationNameInfo DirName;
7403 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop_simd, DirName,
7404 nullptr, D->getLocStart());
7405 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7406 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7407 return Res;
7408}
7409
Carlo Bertolli6200a3d2015-12-14 14:51:25 +00007410template <typename Derived>
7411StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective(
7412 OMPDistributeDirective *D) {
7413 DeclarationNameInfo DirName;
7414 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr,
7415 D->getLocStart());
7416 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7417 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7418 return Res;
7419}
7420
Alexander Musman64d33f12014-06-04 07:53:32 +00007421//===----------------------------------------------------------------------===//
7422// OpenMP clause transformation
7423//===----------------------------------------------------------------------===//
7424template <typename Derived>
7425OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00007426 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7427 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007428 return nullptr;
Alexey Bataev6b8046a2015-09-03 07:23:48 +00007429 return getDerived().RebuildOMPIfClause(
7430 C->getNameModifier(), Cond.get(), C->getLocStart(), C->getLParenLoc(),
7431 C->getNameModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007432}
7433
Alexander Musman64d33f12014-06-04 07:53:32 +00007434template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00007435OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
7436 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7437 if (Cond.isInvalid())
7438 return nullptr;
7439 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
7440 C->getLParenLoc(), C->getLocEnd());
7441}
7442
7443template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007444OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00007445TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
7446 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
7447 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007448 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00007449 return getDerived().RebuildOMPNumThreadsClause(
7450 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00007451}
7452
Alexey Bataev62c87d22014-03-21 04:51:18 +00007453template <typename Derived>
7454OMPClause *
7455TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
7456 ExprResult E = getDerived().TransformExpr(C->getSafelen());
7457 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007458 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00007459 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007460 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00007461}
7462
Alexander Musman8bd31e62014-05-27 15:12:19 +00007463template <typename Derived>
7464OMPClause *
Alexey Bataev66b15b52015-08-21 11:14:16 +00007465TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
7466 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
7467 if (E.isInvalid())
7468 return nullptr;
7469 return getDerived().RebuildOMPSimdlenClause(
7470 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7471}
7472
7473template <typename Derived>
7474OMPClause *
Alexander Musman8bd31e62014-05-27 15:12:19 +00007475TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
7476 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
7477 if (E.isInvalid())
Hans Wennborg59dbe862015-09-29 20:56:43 +00007478 return nullptr;
Alexander Musman8bd31e62014-05-27 15:12:19 +00007479 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007480 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00007481}
7482
Alexander Musman64d33f12014-06-04 07:53:32 +00007483template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00007484OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007485TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007486 return getDerived().RebuildOMPDefaultClause(
7487 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
7488 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007489}
7490
Alexander Musman64d33f12014-06-04 07:53:32 +00007491template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007492OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007493TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007494 return getDerived().RebuildOMPProcBindClause(
7495 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
7496 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007497}
7498
Alexander Musman64d33f12014-06-04 07:53:32 +00007499template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007500OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00007501TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
7502 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
7503 if (E.isInvalid())
7504 return nullptr;
7505 return getDerived().RebuildOMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00007506 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
Alexey Bataev56dafe82014-06-20 07:16:17 +00007507 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
Alexey Bataev6402bca2015-12-28 07:25:51 +00007508 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
Alexey Bataev56dafe82014-06-20 07:16:17 +00007509 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
7510}
7511
7512template <typename Derived>
7513OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007514TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
Alexey Bataev10e775f2015-07-30 11:36:16 +00007515 ExprResult E;
7516 if (auto *Num = C->getNumForLoops()) {
7517 E = getDerived().TransformExpr(Num);
7518 if (E.isInvalid())
7519 return nullptr;
7520 }
7521 return getDerived().RebuildOMPOrderedClause(C->getLocStart(), C->getLocEnd(),
7522 C->getLParenLoc(), E.get());
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007523}
7524
7525template <typename Derived>
7526OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00007527TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
7528 // No need to rebuild this clause, no template-dependent parameters.
7529 return C;
7530}
7531
7532template <typename Derived>
7533OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00007534TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
7535 // No need to rebuild this clause, no template-dependent parameters.
7536 return C;
7537}
7538
7539template <typename Derived>
7540OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007541TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
7542 // No need to rebuild this clause, no template-dependent parameters.
7543 return C;
7544}
7545
7546template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00007547OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
7548 // No need to rebuild this clause, no template-dependent parameters.
7549 return C;
7550}
7551
7552template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00007553OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
7554 // No need to rebuild this clause, no template-dependent parameters.
7555 return C;
7556}
7557
7558template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007559OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00007560TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
7561 // No need to rebuild this clause, no template-dependent parameters.
7562 return C;
7563}
7564
7565template <typename Derived>
7566OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00007567TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
7568 // No need to rebuild this clause, no template-dependent parameters.
7569 return C;
7570}
7571
7572template <typename Derived>
7573OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00007574TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
7575 // No need to rebuild this clause, no template-dependent parameters.
7576 return C;
7577}
7578
7579template <typename Derived>
7580OMPClause *
Alexey Bataev346265e2015-09-25 10:37:12 +00007581TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
7582 // No need to rebuild this clause, no template-dependent parameters.
7583 return C;
7584}
7585
7586template <typename Derived>
Alexey Bataevd14d1e62015-09-28 06:39:35 +00007587OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
7588 // No need to rebuild this clause, no template-dependent parameters.
7589 return C;
7590}
7591
7592template <typename Derived>
Alexey Bataev346265e2015-09-25 10:37:12 +00007593OMPClause *
Alexey Bataevb825de12015-12-07 10:51:44 +00007594TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
7595 // No need to rebuild this clause, no template-dependent parameters.
7596 return C;
7597}
7598
7599template <typename Derived>
7600OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007601TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007602 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007603 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007604 for (auto *VE : C->varlists()) {
7605 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007606 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007607 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007608 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007609 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007610 return getDerived().RebuildOMPPrivateClause(
7611 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007612}
7613
Alexander Musman64d33f12014-06-04 07:53:32 +00007614template <typename Derived>
7615OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
7616 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007617 llvm::SmallVector<Expr *, 16> Vars;
7618 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007619 for (auto *VE : C->varlists()) {
7620 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007621 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007622 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007623 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007624 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007625 return getDerived().RebuildOMPFirstprivateClause(
7626 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007627}
7628
Alexander Musman64d33f12014-06-04 07:53:32 +00007629template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007630OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00007631TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
7632 llvm::SmallVector<Expr *, 16> Vars;
7633 Vars.reserve(C->varlist_size());
7634 for (auto *VE : C->varlists()) {
7635 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7636 if (EVar.isInvalid())
7637 return nullptr;
7638 Vars.push_back(EVar.get());
7639 }
7640 return getDerived().RebuildOMPLastprivateClause(
7641 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7642}
7643
7644template <typename Derived>
7645OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00007646TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
7647 llvm::SmallVector<Expr *, 16> Vars;
7648 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007649 for (auto *VE : C->varlists()) {
7650 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00007651 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007652 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007653 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007654 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007655 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
7656 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007657}
7658
Alexander Musman64d33f12014-06-04 07:53:32 +00007659template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007660OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00007661TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
7662 llvm::SmallVector<Expr *, 16> Vars;
7663 Vars.reserve(C->varlist_size());
7664 for (auto *VE : C->varlists()) {
7665 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7666 if (EVar.isInvalid())
7667 return nullptr;
7668 Vars.push_back(EVar.get());
7669 }
7670 CXXScopeSpec ReductionIdScopeSpec;
7671 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
7672
7673 DeclarationNameInfo NameInfo = C->getNameInfo();
7674 if (NameInfo.getName()) {
7675 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7676 if (!NameInfo.getName())
7677 return nullptr;
7678 }
7679 return getDerived().RebuildOMPReductionClause(
7680 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
7681 C->getLocEnd(), ReductionIdScopeSpec, NameInfo);
7682}
7683
7684template <typename Derived>
7685OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00007686TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
7687 llvm::SmallVector<Expr *, 16> Vars;
7688 Vars.reserve(C->varlist_size());
7689 for (auto *VE : C->varlists()) {
7690 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7691 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007692 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007693 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00007694 }
7695 ExprResult Step = getDerived().TransformExpr(C->getStep());
7696 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007697 return nullptr;
Alexey Bataev182227b2015-08-20 10:54:39 +00007698 return getDerived().RebuildOMPLinearClause(
7699 Vars, Step.get(), C->getLocStart(), C->getLParenLoc(), C->getModifier(),
7700 C->getModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00007701}
7702
Alexander Musman64d33f12014-06-04 07:53:32 +00007703template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00007704OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007705TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
7706 llvm::SmallVector<Expr *, 16> Vars;
7707 Vars.reserve(C->varlist_size());
7708 for (auto *VE : C->varlists()) {
7709 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7710 if (EVar.isInvalid())
7711 return nullptr;
7712 Vars.push_back(EVar.get());
7713 }
7714 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
7715 if (Alignment.isInvalid())
7716 return nullptr;
7717 return getDerived().RebuildOMPAlignedClause(
7718 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
7719 C->getColonLoc(), C->getLocEnd());
7720}
7721
Alexander Musman64d33f12014-06-04 07:53:32 +00007722template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007723OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007724TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
7725 llvm::SmallVector<Expr *, 16> Vars;
7726 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007727 for (auto *VE : C->varlists()) {
7728 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007729 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007730 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007731 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007732 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007733 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
7734 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007735}
7736
Alexey Bataevbae9a792014-06-27 10:37:06 +00007737template <typename Derived>
7738OMPClause *
7739TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
7740 llvm::SmallVector<Expr *, 16> Vars;
7741 Vars.reserve(C->varlist_size());
7742 for (auto *VE : C->varlists()) {
7743 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7744 if (EVar.isInvalid())
7745 return nullptr;
7746 Vars.push_back(EVar.get());
7747 }
7748 return getDerived().RebuildOMPCopyprivateClause(
7749 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7750}
7751
Alexey Bataev6125da92014-07-21 11:26:11 +00007752template <typename Derived>
7753OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
7754 llvm::SmallVector<Expr *, 16> Vars;
7755 Vars.reserve(C->varlist_size());
7756 for (auto *VE : C->varlists()) {
7757 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7758 if (EVar.isInvalid())
7759 return nullptr;
7760 Vars.push_back(EVar.get());
7761 }
7762 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
7763 C->getLParenLoc(), C->getLocEnd());
7764}
7765
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00007766template <typename Derived>
7767OMPClause *
7768TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
7769 llvm::SmallVector<Expr *, 16> Vars;
7770 Vars.reserve(C->varlist_size());
7771 for (auto *VE : C->varlists()) {
7772 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7773 if (EVar.isInvalid())
7774 return nullptr;
7775 Vars.push_back(EVar.get());
7776 }
7777 return getDerived().RebuildOMPDependClause(
7778 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
7779 C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7780}
7781
Michael Wonge710d542015-08-07 16:16:36 +00007782template <typename Derived>
7783OMPClause *
7784TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
7785 ExprResult E = getDerived().TransformExpr(C->getDevice());
7786 if (E.isInvalid())
7787 return nullptr;
7788 return getDerived().RebuildOMPDeviceClause(
7789 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7790}
7791
Kelvin Li0bff7af2015-11-23 05:32:03 +00007792template <typename Derived>
7793OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
7794 llvm::SmallVector<Expr *, 16> Vars;
7795 Vars.reserve(C->varlist_size());
7796 for (auto *VE : C->varlists()) {
7797 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7798 if (EVar.isInvalid())
7799 return nullptr;
7800 Vars.push_back(EVar.get());
7801 }
7802 return getDerived().RebuildOMPMapClause(
7803 C->getMapTypeModifier(), C->getMapType(), C->getMapLoc(),
7804 C->getColonLoc(), Vars, C->getLocStart(), C->getLParenLoc(),
7805 C->getLocEnd());
7806}
7807
Kelvin Li099bb8c2015-11-24 20:50:12 +00007808template <typename Derived>
7809OMPClause *
7810TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
7811 ExprResult E = getDerived().TransformExpr(C->getNumTeams());
7812 if (E.isInvalid())
7813 return nullptr;
7814 return getDerived().RebuildOMPNumTeamsClause(
7815 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7816}
7817
Kelvin Lia15fb1a2015-11-27 18:47:36 +00007818template <typename Derived>
7819OMPClause *
7820TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
7821 ExprResult E = getDerived().TransformExpr(C->getThreadLimit());
7822 if (E.isInvalid())
7823 return nullptr;
7824 return getDerived().RebuildOMPThreadLimitClause(
7825 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7826}
7827
Alexey Bataeva0569352015-12-01 10:17:31 +00007828template <typename Derived>
7829OMPClause *
7830TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
7831 ExprResult E = getDerived().TransformExpr(C->getPriority());
7832 if (E.isInvalid())
7833 return nullptr;
7834 return getDerived().RebuildOMPPriorityClause(
7835 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7836}
7837
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00007838template <typename Derived>
7839OMPClause *
7840TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
7841 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
7842 if (E.isInvalid())
7843 return nullptr;
7844 return getDerived().RebuildOMPGrainsizeClause(
7845 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7846}
7847
Alexey Bataev382967a2015-12-08 12:06:20 +00007848template <typename Derived>
7849OMPClause *
7850TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
7851 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
7852 if (E.isInvalid())
7853 return nullptr;
7854 return getDerived().RebuildOMPNumTasksClause(
7855 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7856}
7857
Alexey Bataev28c75412015-12-15 08:19:24 +00007858template <typename Derived>
7859OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) {
7860 ExprResult E = getDerived().TransformExpr(C->getHint());
7861 if (E.isInvalid())
7862 return nullptr;
7863 return getDerived().RebuildOMPHintClause(E.get(), C->getLocStart(),
7864 C->getLParenLoc(), C->getLocEnd());
7865}
7866
Douglas Gregorebe10102009-08-20 07:17:43 +00007867//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00007868// Expression transformation
7869//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00007870template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007871ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007872TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00007873 if (!E->isTypeDependent())
7874 return E;
7875
7876 return getDerived().RebuildPredefinedExpr(E->getLocation(),
7877 E->getIdentType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007878}
Mike Stump11289f42009-09-09 15:08:12 +00007879
7880template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007881ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007882TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007883 NestedNameSpecifierLoc QualifierLoc;
7884 if (E->getQualifierLoc()) {
7885 QualifierLoc
7886 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7887 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007888 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007889 }
John McCallce546572009-12-08 09:08:17 +00007890
7891 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007892 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7893 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007894 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007895 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007896
John McCall815039a2010-08-17 21:27:17 +00007897 DeclarationNameInfo NameInfo = E->getNameInfo();
7898 if (NameInfo.getName()) {
7899 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7900 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007901 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00007902 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007903
7904 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007905 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007906 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007907 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00007908 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007909
7910 // Mark it referenced in the new context regardless.
7911 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007912 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00007913
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007914 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007915 }
John McCallce546572009-12-08 09:08:17 +00007916
Craig Topperc3ec1492014-05-26 06:22:03 +00007917 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00007918 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007919 TemplateArgs = &TransArgs;
7920 TransArgs.setLAngleLoc(E->getLAngleLoc());
7921 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007922 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7923 E->getNumTemplateArgs(),
7924 TransArgs))
7925 return ExprError();
John McCallce546572009-12-08 09:08:17 +00007926 }
7927
Chad Rosier1dcde962012-08-08 18:46:20 +00007928 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00007929 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007930}
Mike Stump11289f42009-09-09 15:08:12 +00007931
Douglas Gregora16548e2009-08-11 05:31:07 +00007932template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007933ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007934TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007935 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007936}
Mike Stump11289f42009-09-09 15:08:12 +00007937
Douglas Gregora16548e2009-08-11 05:31:07 +00007938template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007939ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007940TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007941 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007942}
Mike Stump11289f42009-09-09 15:08:12 +00007943
Douglas Gregora16548e2009-08-11 05:31:07 +00007944template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007945ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007946TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007947 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007948}
Mike Stump11289f42009-09-09 15:08:12 +00007949
Douglas Gregora16548e2009-08-11 05:31:07 +00007950template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007951ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007952TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007953 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007954}
Mike Stump11289f42009-09-09 15:08:12 +00007955
Douglas Gregora16548e2009-08-11 05:31:07 +00007956template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007957ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007958TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007959 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007960}
7961
7962template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007963ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00007964TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00007965 if (FunctionDecl *FD = E->getDirectCallee())
7966 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00007967 return SemaRef.MaybeBindToTemporary(E);
7968}
7969
7970template<typename Derived>
7971ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00007972TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
7973 ExprResult ControllingExpr =
7974 getDerived().TransformExpr(E->getControllingExpr());
7975 if (ControllingExpr.isInvalid())
7976 return ExprError();
7977
Chris Lattner01cf8db2011-07-20 06:58:45 +00007978 SmallVector<Expr *, 4> AssocExprs;
7979 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00007980 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
7981 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
7982 if (TS) {
7983 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
7984 if (!AssocType)
7985 return ExprError();
7986 AssocTypes.push_back(AssocType);
7987 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00007988 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00007989 }
7990
7991 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
7992 if (AssocExpr.isInvalid())
7993 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007994 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00007995 }
7996
7997 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
7998 E->getDefaultLoc(),
7999 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008000 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00008001 AssocTypes,
8002 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00008003}
8004
8005template<typename Derived>
8006ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008007TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008008 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008009 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008010 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008011
Douglas Gregora16548e2009-08-11 05:31:07 +00008012 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008013 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008014
John McCallb268a282010-08-23 23:25:46 +00008015 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008016 E->getRParen());
8017}
8018
Richard Smithdb2630f2012-10-21 03:28:35 +00008019/// \brief The operand of a unary address-of operator has special rules: it's
8020/// allowed to refer to a non-static member of a class even if there's no 'this'
8021/// object available.
8022template<typename Derived>
8023ExprResult
8024TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
8025 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00008026 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00008027 else
8028 return getDerived().TransformExpr(E);
8029}
8030
Mike Stump11289f42009-09-09 15:08:12 +00008031template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008032ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008033TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00008034 ExprResult SubExpr;
8035 if (E->getOpcode() == UO_AddrOf)
8036 SubExpr = TransformAddressOfOperand(E->getSubExpr());
8037 else
8038 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008039 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008040 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008041
Douglas Gregora16548e2009-08-11 05:31:07 +00008042 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008043 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008044
Douglas Gregora16548e2009-08-11 05:31:07 +00008045 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
8046 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008047 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008048}
Mike Stump11289f42009-09-09 15:08:12 +00008049
Douglas Gregora16548e2009-08-11 05:31:07 +00008050template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008051ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00008052TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
8053 // Transform the type.
8054 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
8055 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00008056 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008057
Douglas Gregor882211c2010-04-28 22:16:22 +00008058 // Transform all of the components into components similar to what the
8059 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00008060 // FIXME: It would be slightly more efficient in the non-dependent case to
8061 // just map FieldDecls, rather than requiring the rebuilder to look for
8062 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00008063 // template code that we don't care.
8064 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00008065 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00008066 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00008067 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00008068 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
8069 const Node &ON = E->getComponent(I);
8070 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00008071 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00008072 Comp.LocStart = ON.getSourceRange().getBegin();
8073 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00008074 switch (ON.getKind()) {
8075 case Node::Array: {
8076 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00008077 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00008078 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008079 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008080
Douglas Gregor882211c2010-04-28 22:16:22 +00008081 ExprChanged = ExprChanged || Index.get() != FromIndex;
8082 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00008083 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00008084 break;
8085 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008086
Douglas Gregor882211c2010-04-28 22:16:22 +00008087 case Node::Field:
8088 case Node::Identifier:
8089 Comp.isBrackets = false;
8090 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00008091 if (!Comp.U.IdentInfo)
8092 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008093
Douglas Gregor882211c2010-04-28 22:16:22 +00008094 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00008095
Douglas Gregord1702062010-04-29 00:18:15 +00008096 case Node::Base:
8097 // Will be recomputed during the rebuild.
8098 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00008099 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008100
Douglas Gregor882211c2010-04-28 22:16:22 +00008101 Components.push_back(Comp);
8102 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008103
Douglas Gregor882211c2010-04-28 22:16:22 +00008104 // If nothing changed, retain the existing expression.
8105 if (!getDerived().AlwaysRebuild() &&
8106 Type == E->getTypeSourceInfo() &&
8107 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008108 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00008109
Douglas Gregor882211c2010-04-28 22:16:22 +00008110 // Build a new offsetof expression.
8111 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
Craig Topperb5518242015-10-22 04:59:59 +00008112 Components, E->getRParenLoc());
Douglas Gregor882211c2010-04-28 22:16:22 +00008113}
8114
8115template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008116ExprResult
John McCall8d69a212010-11-15 23:31:06 +00008117TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
Hubert Tong2cded442015-09-01 22:50:31 +00008118 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
John McCall8d69a212010-11-15 23:31:06 +00008119 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008120 return E;
John McCall8d69a212010-11-15 23:31:06 +00008121}
8122
8123template<typename Derived>
8124ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00008125TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
8126 return E;
8127}
8128
8129template<typename Derived>
8130ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00008131TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00008132 // Rebuild the syntactic form. The original syntactic form has
8133 // opaque-value expressions in it, so strip those away and rebuild
8134 // the result. This is a really awful way of doing this, but the
8135 // better solution (rebuilding the semantic expressions and
8136 // rebinding OVEs as necessary) doesn't work; we'd need
8137 // TreeTransform to not strip away implicit conversions.
8138 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
8139 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00008140 if (result.isInvalid()) return ExprError();
8141
8142 // If that gives us a pseudo-object result back, the pseudo-object
8143 // expression must have been an lvalue-to-rvalue conversion which we
8144 // should reapply.
8145 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008146 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00008147
8148 return result;
8149}
8150
8151template<typename Derived>
8152ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00008153TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
8154 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008155 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00008156 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00008157
John McCallbcd03502009-12-07 02:54:59 +00008158 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00008159 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008160 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008161
John McCall4c98fd82009-11-04 07:28:41 +00008162 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008163 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008164
Peter Collingbournee190dee2011-03-11 19:24:49 +00008165 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
8166 E->getKind(),
8167 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008168 }
Mike Stump11289f42009-09-09 15:08:12 +00008169
Eli Friedmane4f22df2012-02-29 04:03:55 +00008170 // C++0x [expr.sizeof]p1:
8171 // The operand is either an expression, which is an unevaluated operand
8172 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00008173 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8174 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008175
Reid Kleckner32506ed2014-06-12 23:03:48 +00008176 // Try to recover if we have something like sizeof(T::X) where X is a type.
8177 // Notably, there must be *exactly* one set of parens if X is a type.
8178 TypeSourceInfo *RecoveryTSI = nullptr;
8179 ExprResult SubExpr;
8180 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
8181 if (auto *DRE =
8182 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
8183 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
8184 PE, DRE, false, &RecoveryTSI);
8185 else
8186 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
8187
8188 if (RecoveryTSI) {
8189 return getDerived().RebuildUnaryExprOrTypeTrait(
8190 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
8191 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00008192 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008193
Eli Friedmane4f22df2012-02-29 04:03:55 +00008194 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008195 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008196
Peter Collingbournee190dee2011-03-11 19:24:49 +00008197 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
8198 E->getOperatorLoc(),
8199 E->getKind(),
8200 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008201}
Mike Stump11289f42009-09-09 15:08:12 +00008202
Douglas Gregora16548e2009-08-11 05:31:07 +00008203template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008204ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008205TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008206 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008207 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008208 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008209
John McCalldadc5752010-08-24 06:29:42 +00008210 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008211 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008212 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008213
8214
Douglas Gregora16548e2009-08-11 05:31:07 +00008215 if (!getDerived().AlwaysRebuild() &&
8216 LHS.get() == E->getLHS() &&
8217 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008218 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008219
John McCallb268a282010-08-23 23:25:46 +00008220 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008221 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008222 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008223 E->getRBracketLoc());
8224}
Mike Stump11289f42009-09-09 15:08:12 +00008225
Alexey Bataev1a3320e2015-08-25 14:24:04 +00008226template <typename Derived>
8227ExprResult
8228TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
8229 ExprResult Base = getDerived().TransformExpr(E->getBase());
8230 if (Base.isInvalid())
8231 return ExprError();
8232
8233 ExprResult LowerBound;
8234 if (E->getLowerBound()) {
8235 LowerBound = getDerived().TransformExpr(E->getLowerBound());
8236 if (LowerBound.isInvalid())
8237 return ExprError();
8238 }
8239
8240 ExprResult Length;
8241 if (E->getLength()) {
8242 Length = getDerived().TransformExpr(E->getLength());
8243 if (Length.isInvalid())
8244 return ExprError();
8245 }
8246
8247 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
8248 LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
8249 return E;
8250
8251 return getDerived().RebuildOMPArraySectionExpr(
8252 Base.get(), E->getBase()->getLocEnd(), LowerBound.get(), E->getColonLoc(),
8253 Length.get(), E->getRBracketLoc());
8254}
8255
Mike Stump11289f42009-09-09 15:08:12 +00008256template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008257ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008258TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008259 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00008260 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00008261 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008262 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008263
8264 // Transform arguments.
8265 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008266 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008267 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008268 &ArgChanged))
8269 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008270
Douglas Gregora16548e2009-08-11 05:31:07 +00008271 if (!getDerived().AlwaysRebuild() &&
8272 Callee.get() == E->getCallee() &&
8273 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00008274 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00008275
Douglas Gregora16548e2009-08-11 05:31:07 +00008276 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00008277 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00008278 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00008279 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008280 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008281 E->getRParenLoc());
8282}
Mike Stump11289f42009-09-09 15:08:12 +00008283
8284template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008285ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008286TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008287 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008288 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008289 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008290
Douglas Gregorea972d32011-02-28 21:54:11 +00008291 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00008292 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00008293 QualifierLoc
8294 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00008295
Douglas Gregorea972d32011-02-28 21:54:11 +00008296 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008297 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00008298 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00008299 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008300
Eli Friedman2cfcef62009-12-04 06:40:45 +00008301 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008302 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
8303 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008304 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00008305 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008306
John McCall16df1e52010-03-30 21:47:33 +00008307 NamedDecl *FoundDecl = E->getFoundDecl();
8308 if (FoundDecl == E->getMemberDecl()) {
8309 FoundDecl = Member;
8310 } else {
8311 FoundDecl = cast_or_null<NamedDecl>(
8312 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
8313 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00008314 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00008315 }
8316
Douglas Gregora16548e2009-08-11 05:31:07 +00008317 if (!getDerived().AlwaysRebuild() &&
8318 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00008319 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008320 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00008321 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00008322 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008323
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008324 // Mark it referenced in the new context regardless.
8325 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00008326 SemaRef.MarkMemberReferenced(E);
8327
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008328 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008329 }
Douglas Gregora16548e2009-08-11 05:31:07 +00008330
John McCall6b51f282009-11-23 01:53:49 +00008331 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00008332 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00008333 TransArgs.setLAngleLoc(E->getLAngleLoc());
8334 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008335 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8336 E->getNumTemplateArgs(),
8337 TransArgs))
8338 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008339 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008340
Douglas Gregora16548e2009-08-11 05:31:07 +00008341 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00008342 SourceLocation FakeOperatorLoc =
8343 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00008344
John McCall38836f02010-01-15 08:34:02 +00008345 // FIXME: to do this check properly, we will need to preserve the
8346 // first-qualifier-in-scope here, just in case we had a dependent
8347 // base (and therefore couldn't do the check) and a
8348 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00008349 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00008350
John McCallb268a282010-08-23 23:25:46 +00008351 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008352 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00008353 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008354 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008355 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008356 Member,
John McCall16df1e52010-03-30 21:47:33 +00008357 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00008358 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00008359 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00008360 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00008361}
Mike Stump11289f42009-09-09 15:08:12 +00008362
Douglas Gregora16548e2009-08-11 05:31:07 +00008363template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008364ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008365TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008366 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008367 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008368 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008369
John McCalldadc5752010-08-24 06:29:42 +00008370 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008371 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008372 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008373
Douglas Gregora16548e2009-08-11 05:31:07 +00008374 if (!getDerived().AlwaysRebuild() &&
8375 LHS.get() == E->getLHS() &&
8376 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008377 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008378
Lang Hames5de91cc2012-10-02 04:45:10 +00008379 Sema::FPContractStateRAII FPContractState(getSema());
8380 getSema().FPFeatures.fp_contract = E->isFPContractable();
8381
Douglas Gregora16548e2009-08-11 05:31:07 +00008382 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008383 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008384}
8385
Mike Stump11289f42009-09-09 15:08:12 +00008386template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008387ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008388TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00008389 CompoundAssignOperator *E) {
8390 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008391}
Mike Stump11289f42009-09-09 15:08:12 +00008392
Douglas Gregora16548e2009-08-11 05:31:07 +00008393template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00008394ExprResult TreeTransform<Derived>::
8395TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
8396 // Just rebuild the common and RHS expressions and see whether we
8397 // get any changes.
8398
8399 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
8400 if (commonExpr.isInvalid())
8401 return ExprError();
8402
8403 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
8404 if (rhs.isInvalid())
8405 return ExprError();
8406
8407 if (!getDerived().AlwaysRebuild() &&
8408 commonExpr.get() == e->getCommon() &&
8409 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008410 return e;
John McCallc07a0c72011-02-17 10:25:35 +00008411
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008412 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00008413 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008414 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00008415 e->getColonLoc(),
8416 rhs.get());
8417}
8418
8419template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008420ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008421TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008422 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008423 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008424 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008425
John McCalldadc5752010-08-24 06:29:42 +00008426 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008427 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008428 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008429
John McCalldadc5752010-08-24 06:29:42 +00008430 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008431 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008432 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008433
Douglas Gregora16548e2009-08-11 05:31:07 +00008434 if (!getDerived().AlwaysRebuild() &&
8435 Cond.get() == E->getCond() &&
8436 LHS.get() == E->getLHS() &&
8437 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008438 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008439
John McCallb268a282010-08-23 23:25:46 +00008440 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008441 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00008442 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008443 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008444 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008445}
Mike Stump11289f42009-09-09 15:08:12 +00008446
8447template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008448ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008449TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00008450 // Implicit casts are eliminated during transformation, since they
8451 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00008452 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008453}
Mike Stump11289f42009-09-09 15:08:12 +00008454
Douglas Gregora16548e2009-08-11 05:31:07 +00008455template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008456ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008457TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008458 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8459 if (!Type)
8460 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008461
John McCalldadc5752010-08-24 06:29:42 +00008462 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008463 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008464 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008465 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008466
Douglas Gregora16548e2009-08-11 05:31:07 +00008467 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008468 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008469 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008470 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008471
John McCall97513962010-01-15 18:39:57 +00008472 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008473 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00008474 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008475 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008476}
Mike Stump11289f42009-09-09 15:08:12 +00008477
Douglas Gregora16548e2009-08-11 05:31:07 +00008478template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008479ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008480TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00008481 TypeSourceInfo *OldT = E->getTypeSourceInfo();
8482 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
8483 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008484 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008485
John McCalldadc5752010-08-24 06:29:42 +00008486 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00008487 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008488 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008489
Douglas Gregora16548e2009-08-11 05:31:07 +00008490 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00008491 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008492 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008493 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008494
John McCall5d7aa7f2010-01-19 22:33:45 +00008495 // Note: the expression type doesn't necessarily match the
8496 // type-as-written, but that's okay, because it should always be
8497 // derivable from the initializer.
8498
John McCalle15bbff2010-01-18 19:35:47 +00008499 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00008500 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00008501 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008502}
Mike Stump11289f42009-09-09 15:08:12 +00008503
Douglas Gregora16548e2009-08-11 05:31:07 +00008504template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008505ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008506TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008507 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008508 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008509 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008510
Douglas Gregora16548e2009-08-11 05:31:07 +00008511 if (!getDerived().AlwaysRebuild() &&
8512 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008513 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008514
Douglas Gregora16548e2009-08-11 05:31:07 +00008515 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00008516 SourceLocation FakeOperatorLoc =
8517 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00008518 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008519 E->getAccessorLoc(),
8520 E->getAccessor());
8521}
Mike Stump11289f42009-09-09 15:08:12 +00008522
Douglas Gregora16548e2009-08-11 05:31:07 +00008523template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008524ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008525TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Richard Smith520449d2015-02-05 06:15:50 +00008526 if (InitListExpr *Syntactic = E->getSyntacticForm())
8527 E = Syntactic;
8528
Douglas Gregora16548e2009-08-11 05:31:07 +00008529 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00008530
Benjamin Kramerf0623432012-08-23 22:51:59 +00008531 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00008532 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00008533 Inits, &InitChanged))
8534 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008535
Richard Smith520449d2015-02-05 06:15:50 +00008536 if (!getDerived().AlwaysRebuild() && !InitChanged) {
8537 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
8538 // in some cases. We can't reuse it in general, because the syntactic and
8539 // semantic forms are linked, and we can't know that semantic form will
8540 // match even if the syntactic form does.
8541 }
Mike Stump11289f42009-09-09 15:08:12 +00008542
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008543 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00008544 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008545}
Mike Stump11289f42009-09-09 15:08:12 +00008546
Douglas Gregora16548e2009-08-11 05:31:07 +00008547template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008548ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008549TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008550 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00008551
Douglas Gregorebe10102009-08-20 07:17:43 +00008552 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00008553 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008554 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008555 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008556
Douglas Gregorebe10102009-08-20 07:17:43 +00008557 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008558 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00008559 bool ExprChanged = false;
8560 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
8561 DEnd = E->designators_end();
8562 D != DEnd; ++D) {
8563 if (D->isFieldDesignator()) {
8564 Desig.AddDesignator(Designator::getField(D->getFieldName(),
8565 D->getDotLoc(),
8566 D->getFieldLoc()));
8567 continue;
8568 }
Mike Stump11289f42009-09-09 15:08:12 +00008569
Douglas Gregora16548e2009-08-11 05:31:07 +00008570 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00008571 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008572 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008573 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008574
8575 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008576 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008577
Douglas Gregora16548e2009-08-11 05:31:07 +00008578 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008579 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008580 continue;
8581 }
Mike Stump11289f42009-09-09 15:08:12 +00008582
Douglas Gregora16548e2009-08-11 05:31:07 +00008583 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00008584 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00008585 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
8586 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008587 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008588
John McCalldadc5752010-08-24 06:29:42 +00008589 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008590 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008591 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008592
8593 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008594 End.get(),
8595 D->getLBracketLoc(),
8596 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008597
Douglas Gregora16548e2009-08-11 05:31:07 +00008598 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
8599 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00008600
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008601 ArrayExprs.push_back(Start.get());
8602 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008603 }
Mike Stump11289f42009-09-09 15:08:12 +00008604
Douglas Gregora16548e2009-08-11 05:31:07 +00008605 if (!getDerived().AlwaysRebuild() &&
8606 Init.get() == E->getInit() &&
8607 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008608 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008609
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008610 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008611 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008612 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008613}
Mike Stump11289f42009-09-09 15:08:12 +00008614
Yunzhong Gaocb779302015-06-10 00:27:52 +00008615// Seems that if TransformInitListExpr() only works on the syntactic form of an
8616// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
8617template<typename Derived>
8618ExprResult
8619TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
8620 DesignatedInitUpdateExpr *E) {
8621 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
8622 "initializer");
8623 return ExprError();
8624}
8625
8626template<typename Derived>
8627ExprResult
8628TreeTransform<Derived>::TransformNoInitExpr(
8629 NoInitExpr *E) {
8630 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
8631 return ExprError();
8632}
8633
Douglas Gregora16548e2009-08-11 05:31:07 +00008634template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008635ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008636TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008637 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00008638 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00008639
Douglas Gregor3da3c062009-10-28 00:29:27 +00008640 // FIXME: Will we ever have proper type location here? Will we actually
8641 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00008642 QualType T = getDerived().TransformType(E->getType());
8643 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008644 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008645
Douglas Gregora16548e2009-08-11 05:31:07 +00008646 if (!getDerived().AlwaysRebuild() &&
8647 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008648 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008649
Douglas Gregora16548e2009-08-11 05:31:07 +00008650 return getDerived().RebuildImplicitValueInitExpr(T);
8651}
Mike Stump11289f42009-09-09 15:08:12 +00008652
Douglas Gregora16548e2009-08-11 05:31:07 +00008653template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008654ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008655TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00008656 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
8657 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008658 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008659
John McCalldadc5752010-08-24 06:29:42 +00008660 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008661 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008662 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008663
Douglas Gregora16548e2009-08-11 05:31:07 +00008664 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00008665 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008666 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008667 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008668
John McCallb268a282010-08-23 23:25:46 +00008669 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00008670 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008671}
8672
8673template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008674ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008675TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008676 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008677 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00008678 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
8679 &ArgumentChanged))
8680 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008681
Douglas Gregora16548e2009-08-11 05:31:07 +00008682 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008683 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00008684 E->getRParenLoc());
8685}
Mike Stump11289f42009-09-09 15:08:12 +00008686
Douglas Gregora16548e2009-08-11 05:31:07 +00008687/// \brief Transform an address-of-label expression.
8688///
8689/// By default, the transformation of an address-of-label expression always
8690/// rebuilds the expression, so that the label identifier can be resolved to
8691/// the corresponding label statement by semantic analysis.
8692template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008693ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008694TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00008695 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
8696 E->getLabel());
8697 if (!LD)
8698 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008699
Douglas Gregora16548e2009-08-11 05:31:07 +00008700 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00008701 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00008702}
Mike Stump11289f42009-09-09 15:08:12 +00008703
8704template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00008705ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008706TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00008707 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00008708 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00008709 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00008710 if (SubStmt.isInvalid()) {
8711 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00008712 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00008713 }
Mike Stump11289f42009-09-09 15:08:12 +00008714
Douglas Gregora16548e2009-08-11 05:31:07 +00008715 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00008716 SubStmt.get() == E->getSubStmt()) {
8717 // Calling this an 'error' is unintuitive, but it does the right thing.
8718 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008719 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00008720 }
Mike Stump11289f42009-09-09 15:08:12 +00008721
8722 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008723 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008724 E->getRParenLoc());
8725}
Mike Stump11289f42009-09-09 15:08:12 +00008726
Douglas Gregora16548e2009-08-11 05:31:07 +00008727template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008728ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008729TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008730 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008731 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008732 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008733
John McCalldadc5752010-08-24 06:29:42 +00008734 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008735 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008736 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008737
John McCalldadc5752010-08-24 06:29:42 +00008738 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008739 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008740 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008741
Douglas Gregora16548e2009-08-11 05:31:07 +00008742 if (!getDerived().AlwaysRebuild() &&
8743 Cond.get() == E->getCond() &&
8744 LHS.get() == E->getLHS() &&
8745 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008746 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008747
Douglas Gregora16548e2009-08-11 05:31:07 +00008748 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00008749 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008750 E->getRParenLoc());
8751}
Mike Stump11289f42009-09-09 15:08:12 +00008752
Douglas Gregora16548e2009-08-11 05:31:07 +00008753template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008754ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008755TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008756 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008757}
8758
8759template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008760ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008761TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008762 switch (E->getOperator()) {
8763 case OO_New:
8764 case OO_Delete:
8765 case OO_Array_New:
8766 case OO_Array_Delete:
8767 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00008768
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008769 case OO_Call: {
8770 // This is a call to an object's operator().
8771 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
8772
8773 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00008774 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008775 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008776 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008777
8778 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00008779 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
8780 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008781
8782 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008783 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008784 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00008785 Args))
8786 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008787
John McCallb268a282010-08-23 23:25:46 +00008788 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008789 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008790 E->getLocEnd());
8791 }
8792
8793#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
8794 case OO_##Name:
8795#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
8796#include "clang/Basic/OperatorKinds.def"
8797 case OO_Subscript:
8798 // Handled below.
8799 break;
8800
8801 case OO_Conditional:
8802 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008803
8804 case OO_None:
8805 case NUM_OVERLOADED_OPERATORS:
8806 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008807 }
8808
John McCalldadc5752010-08-24 06:29:42 +00008809 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00008810 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008811 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008812
Richard Smithdb2630f2012-10-21 03:28:35 +00008813 ExprResult First;
8814 if (E->getOperator() == OO_Amp)
8815 First = getDerived().TransformAddressOfOperand(E->getArg(0));
8816 else
8817 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00008818 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008819 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008820
John McCalldadc5752010-08-24 06:29:42 +00008821 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00008822 if (E->getNumArgs() == 2) {
8823 Second = getDerived().TransformExpr(E->getArg(1));
8824 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008825 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008826 }
Mike Stump11289f42009-09-09 15:08:12 +00008827
Douglas Gregora16548e2009-08-11 05:31:07 +00008828 if (!getDerived().AlwaysRebuild() &&
8829 Callee.get() == E->getCallee() &&
8830 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00008831 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008832 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00008833
Lang Hames5de91cc2012-10-02 04:45:10 +00008834 Sema::FPContractStateRAII FPContractState(getSema());
8835 getSema().FPFeatures.fp_contract = E->isFPContractable();
8836
Douglas Gregora16548e2009-08-11 05:31:07 +00008837 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
8838 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00008839 Callee.get(),
8840 First.get(),
8841 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008842}
Mike Stump11289f42009-09-09 15:08:12 +00008843
Douglas Gregora16548e2009-08-11 05:31:07 +00008844template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008845ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008846TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
8847 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008848}
Mike Stump11289f42009-09-09 15:08:12 +00008849
Douglas Gregora16548e2009-08-11 05:31:07 +00008850template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008851ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00008852TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
8853 // Transform the callee.
8854 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
8855 if (Callee.isInvalid())
8856 return ExprError();
8857
8858 // Transform exec config.
8859 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
8860 if (EC.isInvalid())
8861 return ExprError();
8862
8863 // Transform arguments.
8864 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008865 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008866 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00008867 &ArgChanged))
8868 return ExprError();
8869
8870 if (!getDerived().AlwaysRebuild() &&
8871 Callee.get() == E->getCallee() &&
8872 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008873 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00008874
8875 // FIXME: Wrong source location information for the '('.
8876 SourceLocation FakeLParenLoc
8877 = ((Expr *)Callee.get())->getSourceRange().getBegin();
8878 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008879 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00008880 E->getRParenLoc(), EC.get());
8881}
8882
8883template<typename Derived>
8884ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008885TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008886 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8887 if (!Type)
8888 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008889
John McCalldadc5752010-08-24 06:29:42 +00008890 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008891 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008892 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008893 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008894
Douglas Gregora16548e2009-08-11 05:31:07 +00008895 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008896 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008897 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008898 return E;
Nico Weberc153d242014-07-28 00:02:09 +00008899 return getDerived().RebuildCXXNamedCastExpr(
8900 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
8901 Type, E->getAngleBrackets().getEnd(),
8902 // FIXME. this should be '(' location
8903 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008904}
Mike Stump11289f42009-09-09 15:08:12 +00008905
Douglas Gregora16548e2009-08-11 05:31:07 +00008906template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008907ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008908TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
8909 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008910}
Mike Stump11289f42009-09-09 15:08:12 +00008911
8912template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008913ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008914TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
8915 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00008916}
8917
Douglas Gregora16548e2009-08-11 05:31:07 +00008918template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008919ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008920TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008921 CXXReinterpretCastExpr *E) {
8922 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008923}
Mike Stump11289f42009-09-09 15:08:12 +00008924
Douglas Gregora16548e2009-08-11 05:31:07 +00008925template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008926ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008927TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
8928 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008929}
Mike Stump11289f42009-09-09 15:08:12 +00008930
Douglas Gregora16548e2009-08-11 05:31:07 +00008931template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008932ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008933TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008934 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008935 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8936 if (!Type)
8937 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008938
John McCalldadc5752010-08-24 06:29:42 +00008939 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008940 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008941 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008942 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008943
Douglas Gregora16548e2009-08-11 05:31:07 +00008944 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008945 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008946 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008947 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008948
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008949 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00008950 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008951 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008952 E->getRParenLoc());
8953}
Mike Stump11289f42009-09-09 15:08:12 +00008954
Douglas Gregora16548e2009-08-11 05:31:07 +00008955template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008956ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008957TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008958 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00008959 TypeSourceInfo *TInfo
8960 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8961 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008962 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008963
Douglas Gregora16548e2009-08-11 05:31:07 +00008964 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00008965 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008966 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008967
Douglas Gregor9da64192010-04-26 22:37:10 +00008968 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8969 E->getLocStart(),
8970 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00008971 E->getLocEnd());
8972 }
Mike Stump11289f42009-09-09 15:08:12 +00008973
Eli Friedman456f0182012-01-20 01:26:23 +00008974 // We don't know whether the subexpression is potentially evaluated until
8975 // after we perform semantic analysis. We speculatively assume it is
8976 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00008977 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00008978 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8979 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008980
John McCalldadc5752010-08-24 06:29:42 +00008981 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00008982 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008983 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008984
Douglas Gregora16548e2009-08-11 05:31:07 +00008985 if (!getDerived().AlwaysRebuild() &&
8986 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008987 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008988
Douglas Gregor9da64192010-04-26 22:37:10 +00008989 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8990 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008991 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008992 E->getLocEnd());
8993}
8994
8995template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008996ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00008997TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
8998 if (E->isTypeOperand()) {
8999 TypeSourceInfo *TInfo
9000 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9001 if (!TInfo)
9002 return ExprError();
9003
9004 if (!getDerived().AlwaysRebuild() &&
9005 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009006 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00009007
Douglas Gregor69735112011-03-06 17:40:41 +00009008 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00009009 E->getLocStart(),
9010 TInfo,
9011 E->getLocEnd());
9012 }
9013
Francois Pichet9f4f2072010-09-08 12:20:18 +00009014 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9015
9016 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
9017 if (SubExpr.isInvalid())
9018 return ExprError();
9019
9020 if (!getDerived().AlwaysRebuild() &&
9021 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009022 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00009023
9024 return getDerived().RebuildCXXUuidofExpr(E->getType(),
9025 E->getLocStart(),
9026 SubExpr.get(),
9027 E->getLocEnd());
9028}
9029
9030template<typename Derived>
9031ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009032TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009033 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009034}
Mike Stump11289f42009-09-09 15:08:12 +00009035
Douglas Gregora16548e2009-08-11 05:31:07 +00009036template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009037ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009038TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009039 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009040 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009041}
Mike Stump11289f42009-09-09 15:08:12 +00009042
Douglas Gregora16548e2009-08-11 05:31:07 +00009043template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009044ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009045TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00009046 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00009047
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009048 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
9049 // Make sure that we capture 'this'.
9050 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009051 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009052 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009053
Douglas Gregorb15af892010-01-07 23:12:05 +00009054 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00009055}
Mike Stump11289f42009-09-09 15:08:12 +00009056
Douglas Gregora16548e2009-08-11 05:31:07 +00009057template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009058ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009059TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009060 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009061 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009062 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009063
Douglas Gregora16548e2009-08-11 05:31:07 +00009064 if (!getDerived().AlwaysRebuild() &&
9065 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009066 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009067
Douglas Gregor53e191ed2011-07-06 22:04:06 +00009068 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
9069 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00009070}
Mike Stump11289f42009-09-09 15:08:12 +00009071
Douglas Gregora16548e2009-08-11 05:31:07 +00009072template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009073ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009074TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00009075 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009076 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
9077 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009078 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00009079 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009080
Chandler Carruth794da4c2010-02-08 06:42:49 +00009081 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009082 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009083 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009084
Douglas Gregor033f6752009-12-23 23:03:06 +00009085 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00009086}
Mike Stump11289f42009-09-09 15:08:12 +00009087
Douglas Gregora16548e2009-08-11 05:31:07 +00009088template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009089ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00009090TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
9091 FieldDecl *Field
9092 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
9093 E->getField()));
9094 if (!Field)
9095 return ExprError();
9096
9097 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009098 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00009099
9100 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
9101}
9102
9103template<typename Derived>
9104ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00009105TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
9106 CXXScalarValueInitExpr *E) {
9107 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9108 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009109 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009110
Douglas Gregora16548e2009-08-11 05:31:07 +00009111 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009112 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009113 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009114
Chad Rosier1dcde962012-08-08 18:46:20 +00009115 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00009116 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00009117 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009118}
Mike Stump11289f42009-09-09 15:08:12 +00009119
Douglas Gregora16548e2009-08-11 05:31:07 +00009120template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009121ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009122TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009123 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00009124 TypeSourceInfo *AllocTypeInfo
9125 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
9126 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009127 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009128
Douglas Gregora16548e2009-08-11 05:31:07 +00009129 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00009130 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00009131 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009132 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009133
Douglas Gregora16548e2009-08-11 05:31:07 +00009134 // Transform the placement arguments (if any).
9135 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009136 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00009137 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00009138 E->getNumPlacementArgs(), true,
9139 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00009140 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009141
Sebastian Redl6047f072012-02-16 12:22:20 +00009142 // Transform the initializer (if any).
9143 Expr *OldInit = E->getInitializer();
9144 ExprResult NewInit;
9145 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +00009146 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +00009147 if (NewInit.isInvalid())
9148 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009149
Sebastian Redl6047f072012-02-16 12:22:20 +00009150 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00009151 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009152 if (E->getOperatorNew()) {
9153 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009154 getDerived().TransformDecl(E->getLocStart(),
9155 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009156 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00009157 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009158 }
9159
Craig Topperc3ec1492014-05-26 06:22:03 +00009160 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009161 if (E->getOperatorDelete()) {
9162 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009163 getDerived().TransformDecl(E->getLocStart(),
9164 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009165 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00009166 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009167 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009168
Douglas Gregora16548e2009-08-11 05:31:07 +00009169 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00009170 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009171 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00009172 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00009173 OperatorNew == E->getOperatorNew() &&
9174 OperatorDelete == E->getOperatorDelete() &&
9175 !ArgumentChanged) {
9176 // Mark any declarations we need as referenced.
9177 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00009178 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009179 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00009180 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009181 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00009182
Sebastian Redl6047f072012-02-16 12:22:20 +00009183 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00009184 QualType ElementType
9185 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
9186 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
9187 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
9188 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00009189 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00009190 }
9191 }
9192 }
Sebastian Redl6047f072012-02-16 12:22:20 +00009193
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009194 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009195 }
Mike Stump11289f42009-09-09 15:08:12 +00009196
Douglas Gregor0744ef62010-09-07 21:49:58 +00009197 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009198 if (!ArraySize.get()) {
9199 // If no array size was specified, but the new expression was
9200 // instantiated with an array type (e.g., "new T" where T is
9201 // instantiated with "int[4]"), extract the outer bound from the
9202 // array type as our array size. We do this with constant and
9203 // dependently-sized array types.
9204 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
9205 if (!ArrayT) {
9206 // Do nothing
9207 } else if (const ConstantArrayType *ConsArrayT
9208 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009209 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
9210 SemaRef.Context.getSizeType(),
9211 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009212 AllocType = ConsArrayT->getElementType();
9213 } else if (const DependentSizedArrayType *DepArrayT
9214 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
9215 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009216 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009217 AllocType = DepArrayT->getElementType();
9218 }
9219 }
9220 }
Sebastian Redl6047f072012-02-16 12:22:20 +00009221
Douglas Gregora16548e2009-08-11 05:31:07 +00009222 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
9223 E->isGlobalNew(),
9224 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009225 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009226 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00009227 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009228 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00009229 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00009230 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00009231 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009232 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009233}
Mike Stump11289f42009-09-09 15:08:12 +00009234
Douglas Gregora16548e2009-08-11 05:31:07 +00009235template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009236ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009237TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009238 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00009239 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009240 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009241
Douglas Gregord2d9da02010-02-26 00:38:10 +00009242 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00009243 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009244 if (E->getOperatorDelete()) {
9245 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009246 getDerived().TransformDecl(E->getLocStart(),
9247 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009248 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00009249 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009250 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009251
Douglas Gregora16548e2009-08-11 05:31:07 +00009252 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00009253 Operand.get() == E->getArgument() &&
9254 OperatorDelete == E->getOperatorDelete()) {
9255 // Mark any declarations we need as referenced.
9256 // FIXME: instantiation-specific.
9257 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009258 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00009259
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00009260 if (!E->getArgument()->isTypeDependent()) {
9261 QualType Destroyed = SemaRef.Context.getBaseElementType(
9262 E->getDestroyedType());
9263 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
9264 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00009265 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00009266 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00009267 }
9268 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009269
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009270 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009271 }
Mike Stump11289f42009-09-09 15:08:12 +00009272
Douglas Gregora16548e2009-08-11 05:31:07 +00009273 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
9274 E->isGlobalDelete(),
9275 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00009276 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009277}
Mike Stump11289f42009-09-09 15:08:12 +00009278
Douglas Gregora16548e2009-08-11 05:31:07 +00009279template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009280ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00009281TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009282 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009283 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00009284 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009285 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009286
John McCallba7bf592010-08-24 05:47:05 +00009287 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00009288 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00009289 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009290 E->getOperatorLoc(),
9291 E->isArrow()? tok::arrow : tok::period,
9292 ObjectTypePtr,
9293 MayBePseudoDestructor);
9294 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009295 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009296
John McCallba7bf592010-08-24 05:47:05 +00009297 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00009298 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
9299 if (QualifierLoc) {
9300 QualifierLoc
9301 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
9302 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00009303 return ExprError();
9304 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00009305 CXXScopeSpec SS;
9306 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00009307
Douglas Gregor678f90d2010-02-25 01:56:36 +00009308 PseudoDestructorTypeStorage Destroyed;
9309 if (E->getDestroyedTypeInfo()) {
9310 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00009311 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009312 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00009313 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009314 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00009315 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00009316 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00009317 // We aren't likely to be able to resolve the identifier down to a type
9318 // now anyway, so just retain the identifier.
9319 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
9320 E->getDestroyedTypeLoc());
9321 } else {
9322 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00009323 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009324 *E->getDestroyedTypeIdentifier(),
9325 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009326 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009327 SS, ObjectTypePtr,
9328 false);
9329 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009330 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009331
Douglas Gregor678f90d2010-02-25 01:56:36 +00009332 Destroyed
9333 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
9334 E->getDestroyedTypeLoc());
9335 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009336
Craig Topperc3ec1492014-05-26 06:22:03 +00009337 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009338 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00009339 CXXScopeSpec EmptySS;
9340 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00009341 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009342 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009343 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00009344 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009345
John McCallb268a282010-08-23 23:25:46 +00009346 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00009347 E->getOperatorLoc(),
9348 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00009349 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009350 ScopeTypeInfo,
9351 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009352 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009353 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00009354}
Mike Stump11289f42009-09-09 15:08:12 +00009355
Douglas Gregorad8a3362009-09-04 17:36:40 +00009356template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009357ExprResult
John McCalld14a8642009-11-21 08:51:07 +00009358TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009359 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00009360 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
9361 Sema::LookupOrdinaryName);
9362
9363 // Transform all the decls.
9364 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
9365 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009366 NamedDecl *InstD = static_cast<NamedDecl*>(
9367 getDerived().TransformDecl(Old->getNameLoc(),
9368 *I));
John McCall84d87672009-12-10 09:41:52 +00009369 if (!InstD) {
9370 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9371 // This can happen because of dependent hiding.
9372 if (isa<UsingShadowDecl>(*I))
9373 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00009374 else {
9375 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009376 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009377 }
John McCall84d87672009-12-10 09:41:52 +00009378 }
John McCalle66edc12009-11-24 19:00:30 +00009379
9380 // Expand using declarations.
9381 if (isa<UsingDecl>(InstD)) {
9382 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009383 for (auto *I : UD->shadows())
9384 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00009385 continue;
9386 }
9387
9388 R.addDecl(InstD);
9389 }
9390
9391 // Resolve a kind, but don't do any further analysis. If it's
9392 // ambiguous, the callee needs to deal with it.
9393 R.resolveKind();
9394
9395 // Rebuild the nested-name qualifier, if present.
9396 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00009397 if (Old->getQualifierLoc()) {
9398 NestedNameSpecifierLoc QualifierLoc
9399 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9400 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009401 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009402
Douglas Gregor0da1d432011-02-28 20:01:57 +00009403 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00009404 }
9405
Douglas Gregor9262f472010-04-27 18:19:34 +00009406 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00009407 CXXRecordDecl *NamingClass
9408 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
9409 Old->getNameLoc(),
9410 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00009411 if (!NamingClass) {
9412 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009413 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009414 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009415
Douglas Gregorda7be082010-04-27 16:10:10 +00009416 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00009417 }
9418
Abramo Bagnara7945c982012-01-27 09:46:47 +00009419 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9420
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009421 // If we have neither explicit template arguments, nor the template keyword,
Reid Kleckner744e3e72015-10-20 21:04:13 +00009422 // it's a normal declaration name or member reference.
9423 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
9424 NamedDecl *D = R.getAsSingle<NamedDecl>();
9425 // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
9426 // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
9427 // give a good diagnostic.
9428 if (D && D->isCXXInstanceMember()) {
9429 return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R,
9430 /*TemplateArgs=*/nullptr,
9431 /*Scope=*/nullptr);
9432 }
9433
John McCalle66edc12009-11-24 19:00:30 +00009434 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
Reid Kleckner744e3e72015-10-20 21:04:13 +00009435 }
John McCalle66edc12009-11-24 19:00:30 +00009436
9437 // If we have template arguments, rebuild them, then rebuild the
9438 // templateid expression.
9439 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00009440 if (Old->hasExplicitTemplateArgs() &&
9441 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00009442 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00009443 TransArgs)) {
9444 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00009445 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009446 }
John McCalle66edc12009-11-24 19:00:30 +00009447
Abramo Bagnara7945c982012-01-27 09:46:47 +00009448 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009449 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00009450}
Mike Stump11289f42009-09-09 15:08:12 +00009451
Douglas Gregora16548e2009-08-11 05:31:07 +00009452template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009453ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00009454TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
9455 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009456 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009457 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
9458 TypeSourceInfo *From = E->getArg(I);
9459 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00009460 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00009461 TypeLocBuilder TLB;
9462 TLB.reserve(FromTL.getFullDataSize());
9463 QualType To = getDerived().TransformType(TLB, FromTL);
9464 if (To.isNull())
9465 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009466
Douglas Gregor29c42f22012-02-24 07:38:34 +00009467 if (To == From->getType())
9468 Args.push_back(From);
9469 else {
9470 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9471 ArgChanged = true;
9472 }
9473 continue;
9474 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009475
Douglas Gregor29c42f22012-02-24 07:38:34 +00009476 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009477
Douglas Gregor29c42f22012-02-24 07:38:34 +00009478 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00009479 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00009480 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
9481 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9482 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00009483
Douglas Gregor29c42f22012-02-24 07:38:34 +00009484 // Determine whether the set of unexpanded parameter packs can and should
9485 // be expanded.
9486 bool Expand = true;
9487 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009488 Optional<unsigned> OrigNumExpansions =
9489 ExpansionTL.getTypePtr()->getNumExpansions();
9490 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009491 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
9492 PatternTL.getSourceRange(),
9493 Unexpanded,
9494 Expand, RetainExpansion,
9495 NumExpansions))
9496 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009497
Douglas Gregor29c42f22012-02-24 07:38:34 +00009498 if (!Expand) {
9499 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009500 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00009501 // expansion.
9502 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00009503
Douglas Gregor29c42f22012-02-24 07:38:34 +00009504 TypeLocBuilder TLB;
9505 TLB.reserve(From->getTypeLoc().getFullDataSize());
9506
9507 QualType To = getDerived().TransformType(TLB, PatternTL);
9508 if (To.isNull())
9509 return ExprError();
9510
Chad Rosier1dcde962012-08-08 18:46:20 +00009511 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009512 PatternTL.getSourceRange(),
9513 ExpansionTL.getEllipsisLoc(),
9514 NumExpansions);
9515 if (To.isNull())
9516 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009517
Douglas Gregor29c42f22012-02-24 07:38:34 +00009518 PackExpansionTypeLoc ToExpansionTL
9519 = TLB.push<PackExpansionTypeLoc>(To);
9520 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9521 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9522 continue;
9523 }
9524
9525 // Expand the pack expansion by substituting for each argument in the
9526 // pack(s).
9527 for (unsigned I = 0; I != *NumExpansions; ++I) {
9528 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
9529 TypeLocBuilder TLB;
9530 TLB.reserve(PatternTL.getFullDataSize());
9531 QualType To = getDerived().TransformType(TLB, PatternTL);
9532 if (To.isNull())
9533 return ExprError();
9534
Eli Friedman5e05c4a2013-07-19 21:49:32 +00009535 if (To->containsUnexpandedParameterPack()) {
9536 To = getDerived().RebuildPackExpansionType(To,
9537 PatternTL.getSourceRange(),
9538 ExpansionTL.getEllipsisLoc(),
9539 NumExpansions);
9540 if (To.isNull())
9541 return ExprError();
9542
9543 PackExpansionTypeLoc ToExpansionTL
9544 = TLB.push<PackExpansionTypeLoc>(To);
9545 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9546 }
9547
Douglas Gregor29c42f22012-02-24 07:38:34 +00009548 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9549 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009550
Douglas Gregor29c42f22012-02-24 07:38:34 +00009551 if (!RetainExpansion)
9552 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009553
Douglas Gregor29c42f22012-02-24 07:38:34 +00009554 // If we're supposed to retain a pack expansion, do so by temporarily
9555 // forgetting the partially-substituted parameter pack.
9556 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
9557
9558 TypeLocBuilder TLB;
9559 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00009560
Douglas Gregor29c42f22012-02-24 07:38:34 +00009561 QualType To = getDerived().TransformType(TLB, PatternTL);
9562 if (To.isNull())
9563 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009564
9565 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009566 PatternTL.getSourceRange(),
9567 ExpansionTL.getEllipsisLoc(),
9568 NumExpansions);
9569 if (To.isNull())
9570 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009571
Douglas Gregor29c42f22012-02-24 07:38:34 +00009572 PackExpansionTypeLoc ToExpansionTL
9573 = TLB.push<PackExpansionTypeLoc>(To);
9574 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9575 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9576 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009577
Douglas Gregor29c42f22012-02-24 07:38:34 +00009578 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009579 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009580
9581 return getDerived().RebuildTypeTrait(E->getTrait(),
9582 E->getLocStart(),
9583 Args,
9584 E->getLocEnd());
9585}
9586
9587template<typename Derived>
9588ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00009589TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
9590 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
9591 if (!T)
9592 return ExprError();
9593
9594 if (!getDerived().AlwaysRebuild() &&
9595 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009596 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009597
9598 ExprResult SubExpr;
9599 {
9600 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9601 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
9602 if (SubExpr.isInvalid())
9603 return ExprError();
9604
9605 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009606 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009607 }
9608
9609 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
9610 E->getLocStart(),
9611 T,
9612 SubExpr.get(),
9613 E->getLocEnd());
9614}
9615
9616template<typename Derived>
9617ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00009618TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
9619 ExprResult SubExpr;
9620 {
9621 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9622 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
9623 if (SubExpr.isInvalid())
9624 return ExprError();
9625
9626 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009627 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +00009628 }
9629
9630 return getDerived().RebuildExpressionTrait(
9631 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
9632}
9633
Reid Kleckner32506ed2014-06-12 23:03:48 +00009634template <typename Derived>
9635ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
9636 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
9637 TypeSourceInfo **RecoveryTSI) {
9638 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
9639 DRE, AddrTaken, RecoveryTSI);
9640
9641 // Propagate both errors and recovered types, which return ExprEmpty.
9642 if (!NewDRE.isUsable())
9643 return NewDRE;
9644
9645 // We got an expr, wrap it up in parens.
9646 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
9647 return PE;
9648 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
9649 PE->getRParen());
9650}
9651
9652template <typename Derived>
9653ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9654 DependentScopeDeclRefExpr *E) {
9655 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
9656 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00009657}
9658
9659template<typename Derived>
9660ExprResult
9661TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9662 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +00009663 bool IsAddressOfOperand,
9664 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00009665 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009666 NestedNameSpecifierLoc QualifierLoc
9667 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9668 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009669 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00009670 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00009671
John McCall31f82722010-11-12 08:19:04 +00009672 // TODO: If this is a conversion-function-id, verify that the
9673 // destination type name (if present) resolves the same way after
9674 // instantiation as it did in the local scope.
9675
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009676 DeclarationNameInfo NameInfo
9677 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
9678 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009679 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009680
John McCalle66edc12009-11-24 19:00:30 +00009681 if (!E->hasExplicitTemplateArgs()) {
9682 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009683 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009684 // Note: it is sufficient to compare the Name component of NameInfo:
9685 // if name has not changed, DNLoc has not changed either.
9686 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009687 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009688
Reid Kleckner32506ed2014-06-12 23:03:48 +00009689 return getDerived().RebuildDependentScopeDeclRefExpr(
9690 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
9691 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +00009692 }
John McCall6b51f282009-11-23 01:53:49 +00009693
9694 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009695 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9696 E->getNumTemplateArgs(),
9697 TransArgs))
9698 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009699
Reid Kleckner32506ed2014-06-12 23:03:48 +00009700 return getDerived().RebuildDependentScopeDeclRefExpr(
9701 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
9702 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00009703}
9704
9705template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009706ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009707TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00009708 // CXXConstructExprs other than for list-initialization and
9709 // CXXTemporaryObjectExpr are always implicit, so when we have
9710 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00009711 if ((E->getNumArgs() == 1 ||
9712 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00009713 (!getDerived().DropCallArgument(E->getArg(0))) &&
9714 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00009715 return getDerived().TransformExpr(E->getArg(0));
9716
Douglas Gregora16548e2009-08-11 05:31:07 +00009717 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
9718
9719 QualType T = getDerived().TransformType(E->getType());
9720 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00009721 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009722
9723 CXXConstructorDecl *Constructor
9724 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009725 getDerived().TransformDecl(E->getLocStart(),
9726 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009727 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009728 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009729
Douglas Gregora16548e2009-08-11 05:31:07 +00009730 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009731 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009732 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009733 &ArgumentChanged))
9734 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009735
Douglas Gregora16548e2009-08-11 05:31:07 +00009736 if (!getDerived().AlwaysRebuild() &&
9737 T == E->getType() &&
9738 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00009739 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00009740 // Mark the constructor as referenced.
9741 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009742 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009743 return E;
Douglas Gregorde550352010-02-26 00:01:57 +00009744 }
Mike Stump11289f42009-09-09 15:08:12 +00009745
Douglas Gregordb121ba2009-12-14 16:27:04 +00009746 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
9747 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009748 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00009749 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00009750 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +00009751 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00009752 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00009753 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00009754 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009755}
Mike Stump11289f42009-09-09 15:08:12 +00009756
Douglas Gregora16548e2009-08-11 05:31:07 +00009757/// \brief Transform a C++ temporary-binding expression.
9758///
Douglas Gregor363b1512009-12-24 18:51:59 +00009759/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
9760/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009761template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009762ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009763TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009764 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009765}
Mike Stump11289f42009-09-09 15:08:12 +00009766
John McCall5d413782010-12-06 08:20:24 +00009767/// \brief Transform a C++ expression that contains cleanups that should
9768/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00009769///
John McCall5d413782010-12-06 08:20:24 +00009770/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00009771/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009772template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009773ExprResult
John McCall5d413782010-12-06 08:20:24 +00009774TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009775 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009776}
Mike Stump11289f42009-09-09 15:08:12 +00009777
Douglas Gregora16548e2009-08-11 05:31:07 +00009778template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009779ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009780TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00009781 CXXTemporaryObjectExpr *E) {
9782 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9783 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009784 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009785
Douglas Gregora16548e2009-08-11 05:31:07 +00009786 CXXConstructorDecl *Constructor
9787 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00009788 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009789 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009790 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009791 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009792
Douglas Gregora16548e2009-08-11 05:31:07 +00009793 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009794 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00009795 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009796 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009797 &ArgumentChanged))
9798 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009799
Douglas Gregora16548e2009-08-11 05:31:07 +00009800 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009801 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009802 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009803 !ArgumentChanged) {
9804 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009805 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00009806 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009807 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009808
Richard Smithd59b8322012-12-19 01:39:02 +00009809 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00009810 return getDerived().RebuildCXXTemporaryObjectExpr(T,
9811 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009812 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009813 E->getLocEnd());
9814}
Mike Stump11289f42009-09-09 15:08:12 +00009815
Douglas Gregora16548e2009-08-11 05:31:07 +00009816template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009817ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00009818TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +00009819 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009820 // lambda body, because they are not semantically within that scope.
Richard Smithc38498f2015-04-27 21:27:54 +00009821 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009822 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
9823 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
Richard Smithc38498f2015-04-27 21:27:54 +00009824 E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009825 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +00009826 CEnd = E->capture_end();
9827 C != CEnd; ++C) {
James Dennettdd2ffea22015-05-07 18:48:18 +00009828 if (!E->isInitCapture(C))
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009829 continue;
Richard Smith01014ce2014-11-20 23:53:14 +00009830 EnterExpressionEvaluationContext EEEC(getSema(),
9831 Sema::PotentiallyEvaluated);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009832 ExprResult NewExprInitResult = getDerived().TransformInitializer(
9833 C->getCapturedVar()->getInit(),
9834 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith01014ce2014-11-20 23:53:14 +00009835
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009836 if (NewExprInitResult.isInvalid())
9837 return ExprError();
9838 Expr *NewExprInit = NewExprInitResult.get();
Richard Smith01014ce2014-11-20 23:53:14 +00009839
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009840 VarDecl *OldVD = C->getCapturedVar();
Richard Smith01014ce2014-11-20 23:53:14 +00009841 QualType NewInitCaptureType =
Richard Smith42b10572015-11-11 01:36:17 +00009842 getSema().buildLambdaInitCaptureInitialization(
9843 C->getLocation(), OldVD->getType()->isReferenceType(),
9844 OldVD->getIdentifier(),
9845 C->getCapturedVar()->getInitStyle() != VarDecl::CInit, NewExprInit);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009846 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009847 InitCaptureExprsAndTypes[C - E->capture_begin()] =
9848 std::make_pair(NewExprInitResult, NewInitCaptureType);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009849 }
9850
Faisal Vali2cba1332013-10-23 06:44:28 +00009851 // Transform the template parameters, and add them to the current
9852 // instantiation scope. The null case is handled correctly.
Richard Smithc38498f2015-04-27 21:27:54 +00009853 auto TPL = getDerived().TransformTemplateParameterList(
Faisal Vali2cba1332013-10-23 06:44:28 +00009854 E->getTemplateParameterList());
9855
Richard Smith01014ce2014-11-20 23:53:14 +00009856 // Transform the type of the original lambda's call operator.
9857 // The transformation MUST be done in the CurrentInstantiationScope since
9858 // it introduces a mapping of the original to the newly created
9859 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +00009860 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +00009861 {
9862 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
9863 FunctionProtoTypeLoc OldCallOpFPTL =
9864 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +00009865
9866 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +00009867 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00009868 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00009869 QualType NewCallOpType = TransformFunctionProtoType(
9870 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00009871 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
9872 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
9873 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00009874 });
Reid Kleckneraac43c62014-12-15 21:07:16 +00009875 if (NewCallOpType.isNull())
9876 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +00009877 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
9878 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00009879 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009880
Richard Smithc38498f2015-04-27 21:27:54 +00009881 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
9882 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
9883 LSI->GLTemplateParameterList = TPL;
9884
Eli Friedmand564afb2012-09-19 01:18:11 +00009885 // Create the local class that will describe the lambda.
9886 CXXRecordDecl *Class
9887 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00009888 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00009889 /*KnownDependent=*/false,
9890 E->getCaptureDefault());
Eli Friedmand564afb2012-09-19 01:18:11 +00009891 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
9892
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009893 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +00009894 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
9895 Class, E->getIntroducerRange(), NewCallOpTSI,
9896 E->getCallOperator()->getLocEnd(),
9897 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams());
Faisal Vali2cba1332013-10-23 06:44:28 +00009898 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00009899
Faisal Vali2cba1332013-10-23 06:44:28 +00009900 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
Richard Smithc38498f2015-04-27 21:27:54 +00009901 getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
Richard Smithba71c082013-05-16 06:20:58 +00009902
Douglas Gregorb4328232012-02-14 00:00:48 +00009903 // Introduce the context of the call operator.
Richard Smithc38498f2015-04-27 21:27:54 +00009904 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
Richard Smith7ff2bcb2014-01-24 01:54:52 +00009905 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00009906
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009907 // Enter the scope of the lambda.
Richard Smithc38498f2015-04-27 21:27:54 +00009908 getSema().buildLambdaScope(LSI, NewCallOperator,
9909 E->getIntroducerRange(),
9910 E->getCaptureDefault(),
9911 E->getCaptureDefaultLoc(),
9912 E->hasExplicitParameters(),
9913 E->hasExplicitResultType(),
9914 E->isMutable());
9915
9916 bool Invalid = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009917
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009918 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009919 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009920 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009921 CEnd = E->capture_end();
9922 C != CEnd; ++C) {
9923 // When we hit the first implicit capture, tell Sema that we've finished
9924 // the list of explicit captures.
9925 if (!FinishedExplicitCaptures && C->isImplicit()) {
9926 getSema().finishLambdaExplicitCaptures(LSI);
9927 FinishedExplicitCaptures = true;
9928 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009929
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009930 // Capturing 'this' is trivial.
9931 if (C->capturesThis()) {
9932 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
9933 continue;
9934 }
Alexey Bataev39c81e22014-08-28 04:28:19 +00009935 // Captured expression will be recaptured during captured variables
9936 // rebuilding.
9937 if (C->capturesVLAType())
9938 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009939
Richard Smithba71c082013-05-16 06:20:58 +00009940 // Rebuild init-captures, including the implied field declaration.
James Dennettdd2ffea22015-05-07 18:48:18 +00009941 if (E->isInitCapture(C)) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009942 InitCaptureInfoTy InitExprTypePair =
9943 InitCaptureExprsAndTypes[C - E->capture_begin()];
9944 ExprResult Init = InitExprTypePair.first;
9945 QualType InitQualType = InitExprTypePair.second;
9946 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00009947 Invalid = true;
9948 continue;
9949 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009950 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009951 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
Richard Smith42b10572015-11-11 01:36:17 +00009952 OldVD->getLocation(), InitExprTypePair.second, OldVD->getIdentifier(),
9953 OldVD->getInitStyle(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00009954 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00009955 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009956 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00009957 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009958 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009959 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00009960 continue;
9961 }
9962
9963 assert(C->capturesVariable() && "unexpected kind of lambda capture");
9964
Douglas Gregor3e308b12012-02-14 19:27:52 +00009965 // Determine the capture kind for Sema.
9966 Sema::TryCaptureKind Kind
9967 = C->isImplicit()? Sema::TryCapture_Implicit
9968 : C->getCaptureKind() == LCK_ByCopy
9969 ? Sema::TryCapture_ExplicitByVal
9970 : Sema::TryCapture_ExplicitByRef;
9971 SourceLocation EllipsisLoc;
9972 if (C->isPackExpansion()) {
9973 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
9974 bool ShouldExpand = false;
9975 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009976 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009977 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
9978 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009979 Unexpanded,
9980 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00009981 NumExpansions)) {
9982 Invalid = true;
9983 continue;
9984 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009985
Douglas Gregor3e308b12012-02-14 19:27:52 +00009986 if (ShouldExpand) {
9987 // The transform has determined that we should perform an expansion;
9988 // transform and capture each of the arguments.
9989 // expansion of the pattern. Do so.
9990 VarDecl *Pack = C->getCapturedVar();
9991 for (unsigned I = 0; I != *NumExpansions; ++I) {
9992 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9993 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009994 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009995 Pack));
9996 if (!CapturedVar) {
9997 Invalid = true;
9998 continue;
9999 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010000
Douglas Gregor3e308b12012-02-14 19:27:52 +000010001 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +000010002 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
10003 }
Richard Smith9467be42014-06-06 17:33:35 +000010004
10005 // FIXME: Retain a pack expansion if RetainExpansion is true.
10006
Douglas Gregor3e308b12012-02-14 19:27:52 +000010007 continue;
10008 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010009
Douglas Gregor3e308b12012-02-14 19:27:52 +000010010 EllipsisLoc = C->getEllipsisLoc();
10011 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010012
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010013 // Transform the captured variable.
10014 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000010015 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010016 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +000010017 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010018 Invalid = true;
10019 continue;
10020 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010021
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010022 // Capture the transformed variable.
Meador Inge4f9dee72015-06-26 00:09:55 +000010023 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
10024 EllipsisLoc);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010025 }
10026 if (!FinishedExplicitCaptures)
10027 getSema().finishLambdaExplicitCaptures(LSI);
10028
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010029 // Enter a new evaluation context to insulate the lambda from any
10030 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +000010031 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010032
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010033 // Instantiate the body of the lambda expression.
Richard Smithc38498f2015-04-27 21:27:54 +000010034 StmtResult Body =
10035 Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
10036
10037 // ActOnLambda* will pop the function scope for us.
10038 FuncScopeCleanup.disable();
10039
Douglas Gregorb4328232012-02-14 00:00:48 +000010040 if (Body.isInvalid()) {
Richard Smithc38498f2015-04-27 21:27:54 +000010041 SavedContext.pop();
Craig Topperc3ec1492014-05-26 06:22:03 +000010042 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +000010043 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +000010044 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +000010045 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +000010046
Richard Smithc38498f2015-04-27 21:27:54 +000010047 // Copy the LSI before ActOnFinishFunctionBody removes it.
10048 // FIXME: This is dumb. Store the lambda information somewhere that outlives
10049 // the call operator.
10050 auto LSICopy = *LSI;
10051 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
10052 /*IsInstantiation*/ true);
10053 SavedContext.pop();
10054
10055 return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(),
10056 &LSICopy);
Douglas Gregore31e6062012-02-07 10:09:13 +000010057}
10058
10059template<typename Derived>
10060ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010061TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010062 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +000010063 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10064 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010065 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010066
Douglas Gregora16548e2009-08-11 05:31:07 +000010067 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010068 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000010069 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +000010070 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010071 &ArgumentChanged))
10072 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010073
Douglas Gregora16548e2009-08-11 05:31:07 +000010074 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010075 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010076 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010077 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010078
Douglas Gregora16548e2009-08-11 05:31:07 +000010079 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +000010080 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +000010081 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010082 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +000010083 E->getRParenLoc());
10084}
Mike Stump11289f42009-09-09 15:08:12 +000010085
Douglas Gregora16548e2009-08-11 05:31:07 +000010086template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010087ExprResult
John McCall8cd78132009-11-19 22:55:06 +000010088TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010089 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010090 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000010091 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000010092 Expr *OldBase;
10093 QualType BaseType;
10094 QualType ObjectType;
10095 if (!E->isImplicitAccess()) {
10096 OldBase = E->getBase();
10097 Base = getDerived().TransformExpr(OldBase);
10098 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010099 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010100
John McCall2d74de92009-12-01 22:10:20 +000010101 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +000010102 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +000010103 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +000010104 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010105 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010106 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +000010107 ObjectTy,
10108 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +000010109 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010110 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +000010111
John McCallba7bf592010-08-24 05:47:05 +000010112 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +000010113 BaseType = ((Expr*) Base.get())->getType();
10114 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +000010115 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +000010116 BaseType = getDerived().TransformType(E->getBaseType());
10117 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
10118 }
Mike Stump11289f42009-09-09 15:08:12 +000010119
Douglas Gregora5cb6da2009-10-20 05:58:46 +000010120 // Transform the first part of the nested-name-specifier that qualifies
10121 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +000010122 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +000010123 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +000010124 E->getFirstQualifierFoundInScope(),
10125 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +000010126
Douglas Gregore16af532011-02-28 18:50:33 +000010127 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010128 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +000010129 QualifierLoc
10130 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
10131 ObjectType,
10132 FirstQualifierInScope);
10133 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010134 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010135 }
Mike Stump11289f42009-09-09 15:08:12 +000010136
Abramo Bagnara7945c982012-01-27 09:46:47 +000010137 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
10138
John McCall31f82722010-11-12 08:19:04 +000010139 // TODO: If this is a conversion-function-id, verify that the
10140 // destination type name (if present) resolves the same way after
10141 // instantiation as it did in the local scope.
10142
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010143 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +000010144 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010145 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000010146 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010147
John McCall2d74de92009-12-01 22:10:20 +000010148 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +000010149 // This is a reference to a member without an explicitly-specified
10150 // template argument list. Optimize for this common case.
10151 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +000010152 Base.get() == OldBase &&
10153 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +000010154 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010155 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +000010156 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010157 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010158
John McCallb268a282010-08-23 23:25:46 +000010159 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010160 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +000010161 E->isArrow(),
10162 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000010163 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010164 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +000010165 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010166 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000010167 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +000010168 }
10169
John McCall6b51f282009-11-23 01:53:49 +000010170 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010171 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
10172 E->getNumTemplateArgs(),
10173 TransArgs))
10174 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010175
John McCallb268a282010-08-23 23:25:46 +000010176 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010177 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +000010178 E->isArrow(),
10179 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000010180 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010181 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +000010182 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010183 NameInfo,
John McCall10eae182009-11-30 22:42:35 +000010184 &TransArgs);
10185}
10186
10187template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010188ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010189TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +000010190 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000010191 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000010192 QualType BaseType;
10193 if (!Old->isImplicitAccess()) {
10194 Base = getDerived().TransformExpr(Old->getBase());
10195 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010196 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010197 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +000010198 Old->isArrow());
10199 if (Base.isInvalid())
10200 return ExprError();
10201 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +000010202 } else {
10203 BaseType = getDerived().TransformType(Old->getBaseType());
10204 }
John McCall10eae182009-11-30 22:42:35 +000010205
Douglas Gregor0da1d432011-02-28 20:01:57 +000010206 NestedNameSpecifierLoc QualifierLoc;
10207 if (Old->getQualifierLoc()) {
10208 QualifierLoc
10209 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
10210 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010211 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000010212 }
10213
Abramo Bagnara7945c982012-01-27 09:46:47 +000010214 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
10215
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010216 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +000010217 Sema::LookupOrdinaryName);
10218
10219 // Transform all the decls.
10220 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
10221 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010222 NamedDecl *InstD = static_cast<NamedDecl*>(
10223 getDerived().TransformDecl(Old->getMemberLoc(),
10224 *I));
John McCall84d87672009-12-10 09:41:52 +000010225 if (!InstD) {
10226 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
10227 // This can happen because of dependent hiding.
10228 if (isa<UsingShadowDecl>(*I))
10229 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +000010230 else {
10231 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +000010232 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +000010233 }
John McCall84d87672009-12-10 09:41:52 +000010234 }
John McCall10eae182009-11-30 22:42:35 +000010235
10236 // Expand using declarations.
10237 if (isa<UsingDecl>(InstD)) {
10238 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +000010239 for (auto *I : UD->shadows())
10240 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +000010241 continue;
10242 }
10243
10244 R.addDecl(InstD);
10245 }
10246
10247 R.resolveKind();
10248
Douglas Gregor9262f472010-04-27 18:19:34 +000010249 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +000010250 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +000010251 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +000010252 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +000010253 Old->getMemberLoc(),
10254 Old->getNamingClass()));
10255 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +000010256 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010257
Douglas Gregorda7be082010-04-27 16:10:10 +000010258 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +000010259 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010260
John McCall10eae182009-11-30 22:42:35 +000010261 TemplateArgumentListInfo TransArgs;
10262 if (Old->hasExplicitTemplateArgs()) {
10263 TransArgs.setLAngleLoc(Old->getLAngleLoc());
10264 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010265 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
10266 Old->getNumTemplateArgs(),
10267 TransArgs))
10268 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000010269 }
John McCall38836f02010-01-15 08:34:02 +000010270
10271 // FIXME: to do this check properly, we will need to preserve the
10272 // first-qualifier-in-scope here, just in case we had a dependent
10273 // base (and therefore couldn't do the check) and a
10274 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +000010275 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +000010276
John McCallb268a282010-08-23 23:25:46 +000010277 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010278 BaseType,
John McCall10eae182009-11-30 22:42:35 +000010279 Old->getOperatorLoc(),
10280 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +000010281 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010282 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +000010283 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +000010284 R,
10285 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +000010286 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +000010287}
10288
10289template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010290ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010291TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +000010292 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010293 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
10294 if (SubExpr.isInvalid())
10295 return ExprError();
10296
10297 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010298 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010299
10300 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
10301}
10302
10303template<typename Derived>
10304ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010305TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010306 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
10307 if (Pattern.isInvalid())
10308 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010309
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010310 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010311 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010312
Douglas Gregorb8840002011-01-14 21:20:45 +000010313 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
10314 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010315}
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010316
10317template<typename Derived>
10318ExprResult
10319TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
10320 // If E is not value-dependent, then nothing will change when we transform it.
10321 // Note: This is an instantiation-centric view.
10322 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010323 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010324
Richard Smithd784e682015-09-23 21:41:42 +000010325 EnterExpressionEvaluationContext Unevaluated(getSema(), Sema::Unevaluated);
Chad Rosier1dcde962012-08-08 18:46:20 +000010326
Richard Smithd784e682015-09-23 21:41:42 +000010327 ArrayRef<TemplateArgument> PackArgs;
10328 TemplateArgument ArgStorage;
Chad Rosier1dcde962012-08-08 18:46:20 +000010329
Richard Smithd784e682015-09-23 21:41:42 +000010330 // Find the argument list to transform.
10331 if (E->isPartiallySubstituted()) {
10332 PackArgs = E->getPartialArguments();
10333 } else if (E->isValueDependent()) {
10334 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
10335 bool ShouldExpand = false;
10336 bool RetainExpansion = false;
10337 Optional<unsigned> NumExpansions;
10338 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
10339 Unexpanded,
10340 ShouldExpand, RetainExpansion,
10341 NumExpansions))
10342 return ExprError();
10343
10344 // If we need to expand the pack, build a template argument from it and
10345 // expand that.
10346 if (ShouldExpand) {
10347 auto *Pack = E->getPack();
10348 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
10349 ArgStorage = getSema().Context.getPackExpansionType(
10350 getSema().Context.getTypeDeclType(TTPD), None);
10351 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
10352 ArgStorage = TemplateArgument(TemplateName(TTPD), None);
10353 } else {
10354 auto *VD = cast<ValueDecl>(Pack);
10355 ExprResult DRE = getSema().BuildDeclRefExpr(VD, VD->getType(),
10356 VK_RValue, E->getPackLoc());
10357 if (DRE.isInvalid())
10358 return ExprError();
10359 ArgStorage = new (getSema().Context) PackExpansionExpr(
10360 getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
10361 }
10362 PackArgs = ArgStorage;
10363 }
10364 }
10365
10366 // If we're not expanding the pack, just transform the decl.
10367 if (!PackArgs.size()) {
10368 auto *Pack = cast_or_null<NamedDecl>(
10369 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010370 if (!Pack)
10371 return ExprError();
Richard Smithd784e682015-09-23 21:41:42 +000010372 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
10373 E->getPackLoc(),
10374 E->getRParenLoc(), None, None);
10375 }
10376
10377 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
10378 E->getPackLoc());
10379 {
10380 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
10381 typedef TemplateArgumentLocInventIterator<
10382 Derived, const TemplateArgument*> PackLocIterator;
10383 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
10384 PackLocIterator(*this, PackArgs.end()),
10385 TransformedPackArgs, /*Uneval*/true))
10386 return ExprError();
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010387 }
10388
Richard Smithd784e682015-09-23 21:41:42 +000010389 SmallVector<TemplateArgument, 8> Args;
10390 bool PartialSubstitution = false;
10391 for (auto &Loc : TransformedPackArgs.arguments()) {
10392 Args.push_back(Loc.getArgument());
10393 if (Loc.getArgument().isPackExpansion())
10394 PartialSubstitution = true;
10395 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010396
Richard Smithd784e682015-09-23 21:41:42 +000010397 if (PartialSubstitution)
10398 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
10399 E->getPackLoc(),
10400 E->getRParenLoc(), None, Args);
10401
10402 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
Chad Rosier1dcde962012-08-08 18:46:20 +000010403 E->getPackLoc(), E->getRParenLoc(),
Richard Smithd784e682015-09-23 21:41:42 +000010404 Args.size(), None);
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010405}
10406
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010407template<typename Derived>
10408ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010409TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
10410 SubstNonTypeTemplateParmPackExpr *E) {
10411 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010412 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010413}
10414
10415template<typename Derived>
10416ExprResult
John McCall7c454bb2011-07-15 05:09:51 +000010417TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
10418 SubstNonTypeTemplateParmExpr *E) {
10419 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010420 return E;
John McCall7c454bb2011-07-15 05:09:51 +000010421}
10422
10423template<typename Derived>
10424ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +000010425TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
10426 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010427 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +000010428}
10429
10430template<typename Derived>
10431ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +000010432TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
10433 MaterializeTemporaryExpr *E) {
10434 return getDerived().TransformExpr(E->GetTemporaryExpr());
10435}
Chad Rosier1dcde962012-08-08 18:46:20 +000010436
Douglas Gregorfe314812011-06-21 17:03:29 +000010437template<typename Derived>
10438ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +000010439TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
10440 Expr *Pattern = E->getPattern();
10441
10442 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10443 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
10444 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10445
10446 // Determine whether the set of unexpanded parameter packs can and should
10447 // be expanded.
10448 bool Expand = true;
10449 bool RetainExpansion = false;
10450 Optional<unsigned> NumExpansions;
10451 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
10452 Pattern->getSourceRange(),
10453 Unexpanded,
10454 Expand, RetainExpansion,
10455 NumExpansions))
10456 return true;
10457
10458 if (!Expand) {
10459 // Do not expand any packs here, just transform and rebuild a fold
10460 // expression.
10461 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10462
10463 ExprResult LHS =
10464 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
10465 if (LHS.isInvalid())
10466 return true;
10467
10468 ExprResult RHS =
10469 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
10470 if (RHS.isInvalid())
10471 return true;
10472
10473 if (!getDerived().AlwaysRebuild() &&
10474 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
10475 return E;
10476
10477 return getDerived().RebuildCXXFoldExpr(
10478 E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
10479 RHS.get(), E->getLocEnd());
10480 }
10481
10482 // The transform has determined that we should perform an elementwise
10483 // expansion of the pattern. Do so.
10484 ExprResult Result = getDerived().TransformExpr(E->getInit());
10485 if (Result.isInvalid())
10486 return true;
10487 bool LeftFold = E->isLeftFold();
10488
10489 // If we're retaining an expansion for a right fold, it is the innermost
10490 // component and takes the init (if any).
10491 if (!LeftFold && RetainExpansion) {
10492 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10493
10494 ExprResult Out = getDerived().TransformExpr(Pattern);
10495 if (Out.isInvalid())
10496 return true;
10497
10498 Result = getDerived().RebuildCXXFoldExpr(
10499 E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
10500 Result.get(), E->getLocEnd());
10501 if (Result.isInvalid())
10502 return true;
10503 }
10504
10505 for (unsigned I = 0; I != *NumExpansions; ++I) {
10506 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
10507 getSema(), LeftFold ? I : *NumExpansions - I - 1);
10508 ExprResult Out = getDerived().TransformExpr(Pattern);
10509 if (Out.isInvalid())
10510 return true;
10511
10512 if (Out.get()->containsUnexpandedParameterPack()) {
10513 // We still have a pack; retain a pack expansion for this slice.
10514 Result = getDerived().RebuildCXXFoldExpr(
10515 E->getLocStart(),
10516 LeftFold ? Result.get() : Out.get(),
10517 E->getOperator(), E->getEllipsisLoc(),
10518 LeftFold ? Out.get() : Result.get(),
10519 E->getLocEnd());
10520 } else if (Result.isUsable()) {
10521 // We've got down to a single element; build a binary operator.
10522 Result = getDerived().RebuildBinaryOperator(
10523 E->getEllipsisLoc(), E->getOperator(),
10524 LeftFold ? Result.get() : Out.get(),
10525 LeftFold ? Out.get() : Result.get());
10526 } else
10527 Result = Out;
10528
10529 if (Result.isInvalid())
10530 return true;
10531 }
10532
10533 // If we're retaining an expansion for a left fold, it is the outermost
10534 // component and takes the complete expansion so far as its init (if any).
10535 if (LeftFold && RetainExpansion) {
10536 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10537
10538 ExprResult Out = getDerived().TransformExpr(Pattern);
10539 if (Out.isInvalid())
10540 return true;
10541
10542 Result = getDerived().RebuildCXXFoldExpr(
10543 E->getLocStart(), Result.get(),
10544 E->getOperator(), E->getEllipsisLoc(),
10545 Out.get(), E->getLocEnd());
10546 if (Result.isInvalid())
10547 return true;
10548 }
10549
10550 // If we had no init and an empty pack, and we're not retaining an expansion,
10551 // then produce a fallback value or error.
10552 if (Result.isUnset())
10553 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
10554 E->getOperator());
10555
10556 return Result;
10557}
10558
10559template<typename Derived>
10560ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +000010561TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
10562 CXXStdInitializerListExpr *E) {
10563 return getDerived().TransformExpr(E->getSubExpr());
10564}
10565
10566template<typename Derived>
10567ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010568TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010569 return SemaRef.MaybeBindToTemporary(E);
10570}
10571
10572template<typename Derived>
10573ExprResult
10574TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010575 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010576}
10577
10578template<typename Derived>
10579ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +000010580TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
10581 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
10582 if (SubExpr.isInvalid())
10583 return ExprError();
10584
10585 if (!getDerived().AlwaysRebuild() &&
10586 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010587 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +000010588
10589 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +000010590}
10591
10592template<typename Derived>
10593ExprResult
10594TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
10595 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010596 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010597 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010598 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000010599 /*IsCall=*/false, Elements, &ArgChanged))
10600 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010601
Ted Kremeneke65b0862012-03-06 20:05:56 +000010602 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10603 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000010604
Ted Kremeneke65b0862012-03-06 20:05:56 +000010605 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
10606 Elements.data(),
10607 Elements.size());
10608}
10609
10610template<typename Derived>
10611ExprResult
10612TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +000010613 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010614 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010615 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010616 bool ArgChanged = false;
10617 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
10618 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +000010619
Ted Kremeneke65b0862012-03-06 20:05:56 +000010620 if (OrigElement.isPackExpansion()) {
10621 // This key/value element is a pack expansion.
10622 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10623 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
10624 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
10625 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10626
10627 // Determine whether the set of unexpanded parameter packs can
10628 // and should be expanded.
10629 bool Expand = true;
10630 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010631 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
10632 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010633 SourceRange PatternRange(OrigElement.Key->getLocStart(),
10634 OrigElement.Value->getLocEnd());
10635 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
10636 PatternRange,
10637 Unexpanded,
10638 Expand, RetainExpansion,
10639 NumExpansions))
10640 return ExprError();
10641
10642 if (!Expand) {
10643 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000010644 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +000010645 // expansion.
10646 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10647 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10648 if (Key.isInvalid())
10649 return ExprError();
10650
10651 if (Key.get() != OrigElement.Key)
10652 ArgChanged = true;
10653
10654 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10655 if (Value.isInvalid())
10656 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010657
Ted Kremeneke65b0862012-03-06 20:05:56 +000010658 if (Value.get() != OrigElement.Value)
10659 ArgChanged = true;
10660
Chad Rosier1dcde962012-08-08 18:46:20 +000010661 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010662 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
10663 };
10664 Elements.push_back(Expansion);
10665 continue;
10666 }
10667
10668 // Record right away that the argument was changed. This needs
10669 // to happen even if the array expands to nothing.
10670 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010671
Ted Kremeneke65b0862012-03-06 20:05:56 +000010672 // The transform has determined that we should perform an elementwise
10673 // expansion of the pattern. Do so.
10674 for (unsigned I = 0; I != *NumExpansions; ++I) {
10675 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10676 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10677 if (Key.isInvalid())
10678 return ExprError();
10679
10680 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10681 if (Value.isInvalid())
10682 return ExprError();
10683
Chad Rosier1dcde962012-08-08 18:46:20 +000010684 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010685 Key.get(), Value.get(), SourceLocation(), NumExpansions
10686 };
10687
10688 // If any unexpanded parameter packs remain, we still have a
10689 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +000010690 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +000010691 if (Key.get()->containsUnexpandedParameterPack() ||
10692 Value.get()->containsUnexpandedParameterPack())
10693 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +000010694
Ted Kremeneke65b0862012-03-06 20:05:56 +000010695 Elements.push_back(Element);
10696 }
10697
Richard Smith9467be42014-06-06 17:33:35 +000010698 // FIXME: Retain a pack expansion if RetainExpansion is true.
10699
Ted Kremeneke65b0862012-03-06 20:05:56 +000010700 // We've finished with this pack expansion.
10701 continue;
10702 }
10703
10704 // Transform and check key.
10705 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10706 if (Key.isInvalid())
10707 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010708
Ted Kremeneke65b0862012-03-06 20:05:56 +000010709 if (Key.get() != OrigElement.Key)
10710 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010711
Ted Kremeneke65b0862012-03-06 20:05:56 +000010712 // Transform and check value.
10713 ExprResult Value
10714 = getDerived().TransformExpr(OrigElement.Value);
10715 if (Value.isInvalid())
10716 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010717
Ted Kremeneke65b0862012-03-06 20:05:56 +000010718 if (Value.get() != OrigElement.Value)
10719 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010720
10721 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +000010722 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +000010723 };
10724 Elements.push_back(Element);
10725 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010726
Ted Kremeneke65b0862012-03-06 20:05:56 +000010727 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10728 return SemaRef.MaybeBindToTemporary(E);
10729
10730 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
Craig Topperd4336e02015-12-24 23:58:15 +000010731 Elements);
Douglas Gregora16548e2009-08-11 05:31:07 +000010732}
10733
Mike Stump11289f42009-09-09 15:08:12 +000010734template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010735ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010736TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +000010737 TypeSourceInfo *EncodedTypeInfo
10738 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
10739 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010740 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010741
Douglas Gregora16548e2009-08-11 05:31:07 +000010742 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +000010743 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010744 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010745
10746 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +000010747 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000010748 E->getRParenLoc());
10749}
Mike Stump11289f42009-09-09 15:08:12 +000010750
Douglas Gregora16548e2009-08-11 05:31:07 +000010751template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +000010752ExprResult TreeTransform<Derived>::
10753TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +000010754 // This is a kind of implicit conversion, and it needs to get dropped
10755 // and recomputed for the same general reasons that ImplicitCastExprs
10756 // do, as well a more specific one: this expression is only valid when
10757 // it appears *immediately* as an argument expression.
10758 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +000010759}
10760
10761template<typename Derived>
10762ExprResult TreeTransform<Derived>::
10763TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +000010764 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +000010765 = getDerived().TransformType(E->getTypeInfoAsWritten());
10766 if (!TSInfo)
10767 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010768
John McCall31168b02011-06-15 23:02:42 +000010769 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +000010770 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +000010771 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010772
John McCall31168b02011-06-15 23:02:42 +000010773 if (!getDerived().AlwaysRebuild() &&
10774 TSInfo == E->getTypeInfoAsWritten() &&
10775 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010776 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010777
John McCall31168b02011-06-15 23:02:42 +000010778 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000010779 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000010780 Result.get());
10781}
10782
10783template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010784ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010785TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010786 // Transform arguments.
10787 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010788 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000010789 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010790 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010791 &ArgChanged))
10792 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010793
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010794 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
10795 // Class message: transform the receiver type.
10796 TypeSourceInfo *ReceiverTypeInfo
10797 = getDerived().TransformType(E->getClassReceiverTypeInfo());
10798 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010799 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010800
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010801 // If nothing changed, just retain the existing message send.
10802 if (!getDerived().AlwaysRebuild() &&
10803 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010804 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010805
10806 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010807 SmallVector<SourceLocation, 16> SelLocs;
10808 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010809 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
10810 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010811 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010812 E->getMethodDecl(),
10813 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010814 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010815 E->getRightLoc());
10816 }
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000010817 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
10818 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
10819 // Build a new class message send to 'super'.
10820 SmallVector<SourceLocation, 16> SelLocs;
10821 E->getSelectorLocs(SelLocs);
10822 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
10823 E->getSelector(),
10824 SelLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +000010825 E->getReceiverType(),
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000010826 E->getMethodDecl(),
10827 E->getLeftLoc(),
10828 Args,
10829 E->getRightLoc());
10830 }
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010831
10832 // Instance message: transform the receiver
10833 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
10834 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000010835 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010836 = getDerived().TransformExpr(E->getInstanceReceiver());
10837 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010838 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010839
10840 // If nothing changed, just retain the existing message send.
10841 if (!getDerived().AlwaysRebuild() &&
10842 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010843 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000010844
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010845 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010846 SmallVector<SourceLocation, 16> SelLocs;
10847 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000010848 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010849 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010850 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010851 E->getMethodDecl(),
10852 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010853 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010854 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010855}
10856
Mike Stump11289f42009-09-09 15:08:12 +000010857template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010858ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010859TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010860 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010861}
10862
Mike Stump11289f42009-09-09 15:08:12 +000010863template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010864ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010865TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010866 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010867}
10868
Mike Stump11289f42009-09-09 15:08:12 +000010869template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010870ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010871TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000010872 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010873 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000010874 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010875 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000010876
10877 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000010878
Douglas Gregord51d90d2010-04-26 20:11:03 +000010879 // If nothing changed, just retain the existing expression.
10880 if (!getDerived().AlwaysRebuild() &&
10881 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010882 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010883
John McCallb268a282010-08-23 23:25:46 +000010884 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000010885 E->getLocation(),
10886 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000010887}
10888
Mike Stump11289f42009-09-09 15:08:12 +000010889template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010890ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010891TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000010892 // 'super' and types never change. Property never changes. Just
10893 // retain the existing expression.
10894 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010895 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010896
Douglas Gregor9faee212010-04-26 20:47:02 +000010897 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010898 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000010899 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010900 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010901
Douglas Gregor9faee212010-04-26 20:47:02 +000010902 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000010903
Douglas Gregor9faee212010-04-26 20:47:02 +000010904 // If nothing changed, just retain the existing expression.
10905 if (!getDerived().AlwaysRebuild() &&
10906 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010907 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010908
John McCallb7bd14f2010-12-02 01:19:52 +000010909 if (E->isExplicitProperty())
10910 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
10911 E->getExplicitProperty(),
10912 E->getLocation());
10913
10914 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000010915 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000010916 E->getImplicitPropertyGetter(),
10917 E->getImplicitPropertySetter(),
10918 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000010919}
10920
Mike Stump11289f42009-09-09 15:08:12 +000010921template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010922ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000010923TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
10924 // Transform the base expression.
10925 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
10926 if (Base.isInvalid())
10927 return ExprError();
10928
10929 // Transform the key expression.
10930 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
10931 if (Key.isInvalid())
10932 return ExprError();
10933
10934 // If nothing changed, just retain the existing expression.
10935 if (!getDerived().AlwaysRebuild() &&
10936 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010937 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010938
Chad Rosier1dcde962012-08-08 18:46:20 +000010939 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000010940 Base.get(), Key.get(),
10941 E->getAtIndexMethodDecl(),
10942 E->setAtIndexMethodDecl());
10943}
10944
10945template<typename Derived>
10946ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010947TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000010948 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010949 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000010950 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010951 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010952
Douglas Gregord51d90d2010-04-26 20:11:03 +000010953 // If nothing changed, just retain the existing expression.
10954 if (!getDerived().AlwaysRebuild() &&
10955 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010956 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010957
John McCallb268a282010-08-23 23:25:46 +000010958 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000010959 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000010960 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000010961}
10962
Mike Stump11289f42009-09-09 15:08:12 +000010963template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010964ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010965TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010966 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010967 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000010968 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010969 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000010970 SubExprs, &ArgumentChanged))
10971 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010972
Douglas Gregora16548e2009-08-11 05:31:07 +000010973 if (!getDerived().AlwaysRebuild() &&
10974 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010975 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010976
Douglas Gregora16548e2009-08-11 05:31:07 +000010977 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010978 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000010979 E->getRParenLoc());
10980}
10981
Mike Stump11289f42009-09-09 15:08:12 +000010982template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010983ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000010984TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
10985 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
10986 if (SrcExpr.isInvalid())
10987 return ExprError();
10988
10989 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
10990 if (!Type)
10991 return ExprError();
10992
10993 if (!getDerived().AlwaysRebuild() &&
10994 Type == E->getTypeSourceInfo() &&
10995 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010996 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000010997
10998 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
10999 SrcExpr.get(), Type,
11000 E->getRParenLoc());
11001}
11002
11003template<typename Derived>
11004ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011005TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000011006 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000011007
Craig Topperc3ec1492014-05-26 06:22:03 +000011008 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000011009 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
11010
11011 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000011012 blockScope->TheDecl->setBlockMissingReturnType(
11013 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000011014
Chris Lattner01cf8db2011-07-20 06:58:45 +000011015 SmallVector<ParmVarDecl*, 4> params;
11016 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000011017
Fariborz Jahanian1babe772010-07-09 18:44:02 +000011018 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +000011019 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
11020 oldBlock->param_begin(),
11021 oldBlock->param_size(),
Craig Topperc3ec1492014-05-26 06:22:03 +000011022 nullptr, paramTypes, &params)) {
11023 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011024 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011025 }
John McCall490112f2011-02-04 18:33:18 +000011026
Jordan Rosea0a86be2013-03-08 22:25:36 +000011027 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +000011028 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000011029 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000011030
Jordan Rose5c382722013-03-08 21:51:21 +000011031 QualType functionType =
11032 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000011033 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +000011034 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000011035
11036 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000011037 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000011038 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000011039
11040 if (!oldBlock->blockMissingReturnType()) {
11041 blockScope->HasImplicitReturnType = false;
11042 blockScope->ReturnType = exprResultType;
11043 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011044
John McCall3882ace2011-01-05 12:14:39 +000011045 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000011046 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011047 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011048 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000011049 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011050 }
John McCall3882ace2011-01-05 12:14:39 +000011051
John McCall490112f2011-02-04 18:33:18 +000011052#ifndef NDEBUG
11053 // In builds with assertions, make sure that we captured everything we
11054 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011055 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000011056 for (const auto &I : oldBlock->captures()) {
11057 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000011058
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011059 // Ignore parameter packs.
11060 if (isa<ParmVarDecl>(oldCapture) &&
11061 cast<ParmVarDecl>(oldCapture)->isParameterPack())
11062 continue;
John McCall490112f2011-02-04 18:33:18 +000011063
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011064 VarDecl *newCapture =
11065 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
11066 oldCapture));
11067 assert(blockScope->CaptureMap.count(newCapture));
11068 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000011069 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000011070 }
11071#endif
11072
11073 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000011074 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000011075}
11076
Mike Stump11289f42009-09-09 15:08:12 +000011077template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011078ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000011079TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000011080 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000011081}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000011082
11083template<typename Derived>
11084ExprResult
11085TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011086 QualType RetTy = getDerived().TransformType(E->getType());
11087 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011088 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011089 SubExprs.reserve(E->getNumSubExprs());
11090 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
11091 SubExprs, &ArgumentChanged))
11092 return ExprError();
11093
11094 if (!getDerived().AlwaysRebuild() &&
11095 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011096 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011097
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011098 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011099 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000011100}
Chad Rosier1dcde962012-08-08 18:46:20 +000011101
Douglas Gregora16548e2009-08-11 05:31:07 +000011102//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000011103// Type reconstruction
11104//===----------------------------------------------------------------------===//
11105
Mike Stump11289f42009-09-09 15:08:12 +000011106template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000011107QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
11108 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000011109 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011110 getDerived().getBaseEntity());
11111}
11112
Mike Stump11289f42009-09-09 15:08:12 +000011113template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000011114QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
11115 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000011116 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011117 getDerived().getBaseEntity());
11118}
11119
Mike Stump11289f42009-09-09 15:08:12 +000011120template<typename Derived>
11121QualType
John McCall70dd5f62009-10-30 00:06:24 +000011122TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
11123 bool WrittenAsLValue,
11124 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000011125 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000011126 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011127}
11128
11129template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011130QualType
John McCall70dd5f62009-10-30 00:06:24 +000011131TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
11132 QualType ClassType,
11133 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000011134 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
11135 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011136}
11137
11138template<typename Derived>
Douglas Gregor9bda6cf2015-07-07 03:58:14 +000011139QualType TreeTransform<Derived>::RebuildObjCObjectType(
11140 QualType BaseType,
11141 SourceLocation Loc,
11142 SourceLocation TypeArgsLAngleLoc,
11143 ArrayRef<TypeSourceInfo *> TypeArgs,
11144 SourceLocation TypeArgsRAngleLoc,
11145 SourceLocation ProtocolLAngleLoc,
11146 ArrayRef<ObjCProtocolDecl *> Protocols,
11147 ArrayRef<SourceLocation> ProtocolLocs,
11148 SourceLocation ProtocolRAngleLoc) {
11149 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
11150 TypeArgs, TypeArgsRAngleLoc,
11151 ProtocolLAngleLoc, Protocols, ProtocolLocs,
11152 ProtocolRAngleLoc,
11153 /*FailOnError=*/true);
11154}
11155
11156template<typename Derived>
11157QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
11158 QualType PointeeType,
11159 SourceLocation Star) {
11160 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
11161}
11162
11163template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011164QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000011165TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
11166 ArrayType::ArraySizeModifier SizeMod,
11167 const llvm::APInt *Size,
11168 Expr *SizeExpr,
11169 unsigned IndexTypeQuals,
11170 SourceRange BracketsRange) {
11171 if (SizeExpr || !Size)
11172 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
11173 IndexTypeQuals, BracketsRange,
11174 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000011175
11176 QualType Types[] = {
11177 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
11178 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
11179 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000011180 };
Craig Toppere5ce8312013-07-15 03:38:40 +000011181 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011182 QualType SizeType;
11183 for (unsigned I = 0; I != NumTypes; ++I)
11184 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
11185 SizeType = Types[I];
11186 break;
11187 }
Mike Stump11289f42009-09-09 15:08:12 +000011188
Eli Friedman9562f392012-01-25 23:20:27 +000011189 // Note that we can return a VariableArrayType here in the case where
11190 // the element type was a dependent VariableArrayType.
11191 IntegerLiteral *ArraySize
11192 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
11193 /*FIXME*/BracketsRange.getBegin());
11194 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011195 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000011196 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011197}
Mike Stump11289f42009-09-09 15:08:12 +000011198
Douglas Gregord6ff3322009-08-04 16:50:30 +000011199template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011200QualType
11201TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011202 ArrayType::ArraySizeModifier SizeMod,
11203 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000011204 unsigned IndexTypeQuals,
11205 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011206 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000011207 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011208}
11209
11210template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011211QualType
Mike Stump11289f42009-09-09 15:08:12 +000011212TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011213 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000011214 unsigned IndexTypeQuals,
11215 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011216 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000011217 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011218}
Mike Stump11289f42009-09-09 15:08:12 +000011219
Douglas Gregord6ff3322009-08-04 16:50:30 +000011220template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011221QualType
11222TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011223 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000011224 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011225 unsigned IndexTypeQuals,
11226 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011227 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000011228 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011229 IndexTypeQuals, BracketsRange);
11230}
11231
11232template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011233QualType
11234TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011235 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000011236 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011237 unsigned IndexTypeQuals,
11238 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011239 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000011240 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011241 IndexTypeQuals, BracketsRange);
11242}
11243
11244template<typename Derived>
11245QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +000011246 unsigned NumElements,
11247 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000011248 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000011249 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011250}
Mike Stump11289f42009-09-09 15:08:12 +000011251
Douglas Gregord6ff3322009-08-04 16:50:30 +000011252template<typename Derived>
11253QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
11254 unsigned NumElements,
11255 SourceLocation AttributeLoc) {
11256 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
11257 NumElements, true);
11258 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000011259 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
11260 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000011261 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011262}
Mike Stump11289f42009-09-09 15:08:12 +000011263
Douglas Gregord6ff3322009-08-04 16:50:30 +000011264template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011265QualType
11266TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000011267 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011268 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000011269 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011270}
Mike Stump11289f42009-09-09 15:08:12 +000011271
Douglas Gregord6ff3322009-08-04 16:50:30 +000011272template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000011273QualType TreeTransform<Derived>::RebuildFunctionProtoType(
11274 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000011275 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000011276 const FunctionProtoType::ExtProtoInfo &EPI) {
11277 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011278 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000011279 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000011280 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011281}
Mike Stump11289f42009-09-09 15:08:12 +000011282
Douglas Gregord6ff3322009-08-04 16:50:30 +000011283template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000011284QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
11285 return SemaRef.Context.getFunctionNoProtoType(T);
11286}
11287
11288template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +000011289QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
11290 assert(D && "no decl found");
11291 if (D->isInvalidDecl()) return QualType();
11292
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011293 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000011294 TypeDecl *Ty;
11295 if (isa<UsingDecl>(D)) {
11296 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000011297 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000011298 "UnresolvedUsingTypenameDecl transformed to non-typename using");
11299
11300 // A valid resolved using typename decl points to exactly one type decl.
11301 assert(++Using->shadow_begin() == Using->shadow_end());
11302 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000011303
John McCallb96ec562009-12-04 22:46:56 +000011304 } else {
11305 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
11306 "UnresolvedUsingTypenameDecl transformed to non-using decl");
11307 Ty = cast<UnresolvedUsingTypenameDecl>(D);
11308 }
11309
11310 return SemaRef.Context.getTypeDeclType(Ty);
11311}
11312
11313template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000011314QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
11315 SourceLocation Loc) {
11316 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011317}
11318
11319template<typename Derived>
11320QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
11321 return SemaRef.Context.getTypeOfType(Underlying);
11322}
11323
11324template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000011325QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
11326 SourceLocation Loc) {
11327 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011328}
11329
11330template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000011331QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
11332 UnaryTransformType::UTTKind UKind,
11333 SourceLocation Loc) {
11334 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
11335}
11336
11337template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000011338QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000011339 TemplateName Template,
11340 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000011341 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000011342 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011343}
Mike Stump11289f42009-09-09 15:08:12 +000011344
Douglas Gregor1135c352009-08-06 05:28:30 +000011345template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000011346QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
11347 SourceLocation KWLoc) {
11348 return SemaRef.BuildAtomicType(ValueType, KWLoc);
11349}
11350
11351template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011352TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011353TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000011354 bool TemplateKW,
11355 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000011356 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000011357 Template);
11358}
11359
11360template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011361TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011362TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
11363 const IdentifierInfo &Name,
11364 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000011365 QualType ObjectType,
11366 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +000011367 UnqualifiedId TemplateName;
11368 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000011369 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000011370 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000011371 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011372 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000011373 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000011374 /*EnteringContext=*/false,
11375 Template);
John McCall31f82722010-11-12 08:19:04 +000011376 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000011377}
Mike Stump11289f42009-09-09 15:08:12 +000011378
Douglas Gregora16548e2009-08-11 05:31:07 +000011379template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000011380TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011381TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000011382 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000011383 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000011384 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000011385 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000011386 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000011387 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000011388 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000011389 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000011390 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000011391 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011392 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000011393 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000011394 /*EnteringContext=*/false,
11395 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000011396 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000011397}
Chad Rosier1dcde962012-08-08 18:46:20 +000011398
Douglas Gregor71395fa2009-11-04 00:56:37 +000011399template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011400ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000011401TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
11402 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000011403 Expr *OrigCallee,
11404 Expr *First,
11405 Expr *Second) {
11406 Expr *Callee = OrigCallee->IgnoreParenCasts();
11407 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000011408
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000011409 if (First->getObjectKind() == OK_ObjCProperty) {
11410 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
11411 if (BinaryOperator::isAssignmentOp(Opc))
11412 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
11413 First, Second);
11414 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
11415 if (Result.isInvalid())
11416 return ExprError();
11417 First = Result.get();
11418 }
11419
11420 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
11421 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
11422 if (Result.isInvalid())
11423 return ExprError();
11424 Second = Result.get();
11425 }
11426
Douglas Gregora16548e2009-08-11 05:31:07 +000011427 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000011428 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000011429 if (!First->getType()->isOverloadableType() &&
11430 !Second->getType()->isOverloadableType())
11431 return getSema().CreateBuiltinArraySubscriptExpr(First,
11432 Callee->getLocStart(),
11433 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000011434 } else if (Op == OO_Arrow) {
11435 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000011436 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
11437 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000011438 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011439 // The argument is not of overloadable type, so try to create a
11440 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000011441 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011442 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000011443
John McCallb268a282010-08-23 23:25:46 +000011444 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011445 }
11446 } else {
John McCallb268a282010-08-23 23:25:46 +000011447 if (!First->getType()->isOverloadableType() &&
11448 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011449 // Neither of the arguments is an overloadable type, so try to
11450 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000011451 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011452 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000011453 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000011454 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011455 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011456
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011457 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011458 }
11459 }
Mike Stump11289f42009-09-09 15:08:12 +000011460
11461 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000011462 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000011463 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000011464
John McCallb268a282010-08-23 23:25:46 +000011465 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000011466 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000011467 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000011468 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000011469 // If we've resolved this to a particular non-member function, just call
11470 // that function. If we resolved it to a member function,
11471 // CreateOverloaded* will find that function for us.
11472 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
11473 if (!isa<CXXMethodDecl>(ND))
11474 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000011475 }
Mike Stump11289f42009-09-09 15:08:12 +000011476
Douglas Gregora16548e2009-08-11 05:31:07 +000011477 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000011478 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000011479 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000011480
Douglas Gregora16548e2009-08-11 05:31:07 +000011481 // Create the overloaded operator invocation for unary operators.
11482 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000011483 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011484 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000011485 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011486 }
Mike Stump11289f42009-09-09 15:08:12 +000011487
Douglas Gregore9d62932011-07-15 16:25:15 +000011488 if (Op == OO_Subscript) {
11489 SourceLocation LBrace;
11490 SourceLocation RBrace;
11491
11492 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000011493 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000011494 LBrace = SourceLocation::getFromRawEncoding(
11495 NameLoc.CXXOperatorName.BeginOpNameLoc);
11496 RBrace = SourceLocation::getFromRawEncoding(
11497 NameLoc.CXXOperatorName.EndOpNameLoc);
11498 } else {
11499 LBrace = Callee->getLocStart();
11500 RBrace = OpLoc;
11501 }
11502
11503 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
11504 First, Second);
11505 }
Sebastian Redladba46e2009-10-29 20:17:01 +000011506
Douglas Gregora16548e2009-08-11 05:31:07 +000011507 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000011508 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011509 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000011510 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
11511 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011512 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011513
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011514 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011515}
Mike Stump11289f42009-09-09 15:08:12 +000011516
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011517template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000011518ExprResult
John McCallb268a282010-08-23 23:25:46 +000011519TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011520 SourceLocation OperatorLoc,
11521 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000011522 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011523 TypeSourceInfo *ScopeType,
11524 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000011525 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000011526 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000011527 QualType BaseType = Base->getType();
11528 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011529 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000011530 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000011531 !BaseType->getAs<PointerType>()->getPointeeType()
11532 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011533 // This pseudo-destructor expression is still a pseudo-destructor.
David Majnemerced8bdf2015-02-25 17:36:15 +000011534 return SemaRef.BuildPseudoDestructorExpr(
11535 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
11536 CCLoc, TildeLoc, Destroyed);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011537 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011538
Douglas Gregor678f90d2010-02-25 01:56:36 +000011539 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011540 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
11541 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
11542 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
11543 NameInfo.setNamedTypeInfo(DestroyedType);
11544
Richard Smith8e4a3862012-05-15 06:15:11 +000011545 // The scope type is now known to be a valid nested name specifier
11546 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000011547 if (ScopeType) {
11548 if (!ScopeType->getType()->getAs<TagType>()) {
11549 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
11550 diag::err_expected_class_or_namespace)
11551 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
11552 return ExprError();
11553 }
11554 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
11555 CCLoc);
11556 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011557
Abramo Bagnara7945c982012-01-27 09:46:47 +000011558 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000011559 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011560 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011561 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000011562 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011563 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +000011564 /*TemplateArgs*/ nullptr,
11565 /*S*/nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011566}
11567
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000011568template<typename Derived>
11569StmtResult
11570TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000011571 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000011572 CapturedDecl *CD = S->getCapturedDecl();
11573 unsigned NumParams = CD->getNumParams();
11574 unsigned ContextParamPos = CD->getContextParamPosition();
11575 SmallVector<Sema::CapturedParamNameType, 4> Params;
11576 for (unsigned I = 0; I < NumParams; ++I) {
11577 if (I != ContextParamPos) {
11578 Params.push_back(
11579 std::make_pair(
11580 CD->getParam(I)->getName(),
11581 getDerived().TransformType(CD->getParam(I)->getType())));
11582 } else {
11583 Params.push_back(std::make_pair(StringRef(), QualType()));
11584 }
11585 }
Craig Topperc3ec1492014-05-26 06:22:03 +000011586 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000011587 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000011588 StmtResult Body;
11589 {
11590 Sema::CompoundScopeRAII CompoundScope(getSema());
11591 Body = getDerived().TransformStmt(S->getCapturedStmt());
11592 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000011593
11594 if (Body.isInvalid()) {
11595 getSema().ActOnCapturedRegionError();
11596 return StmtError();
11597 }
11598
Nikola Smiljanic01a75982014-05-29 10:55:11 +000011599 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000011600}
11601
Douglas Gregord6ff3322009-08-04 16:50:30 +000011602} // end namespace clang
11603
Hans Wennborg59dbe862015-09-29 20:56:43 +000011604#endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H