blob: 5814197a7a7a5e550ea488f428635886d366b84b [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
Richard Smith03a4aa32016-06-23 19:02:52 +0000413 /// \brief Transform the specified condition.
414 ///
415 /// By default, this transforms the variable and expression and rebuilds
416 /// the condition.
417 Sema::ConditionResult TransformCondition(SourceLocation Loc, VarDecl *Var,
418 Expr *Expr,
419 Sema::ConditionKind Kind);
420
Chad Rosier1dcde962012-08-08 18:46:20 +0000421 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000422 /// place them on the new declaration.
423 ///
424 /// By default, this operation does nothing. Subclasses may override this
425 /// behavior to transform attributes.
426 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000427
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000428 /// \brief Note that a local declaration has been transformed by this
429 /// transformer.
430 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000431 /// Local declarations are typically transformed via a call to
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000432 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
433 /// the transformer itself has to transform the declarations. This routine
434 /// can be overridden by a subclass that keeps track of such mappings.
435 void transformedLocalDecl(Decl *Old, Decl *New) {
436 TransformedLocalDecls[Old] = New;
437 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000438
Douglas Gregorebe10102009-08-20 07:17:43 +0000439 /// \brief Transform the definition of the given declaration.
440 ///
Mike Stump11289f42009-09-09 15:08:12 +0000441 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000442 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000443 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
444 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000445 }
Mike Stump11289f42009-09-09 15:08:12 +0000446
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000447 /// \brief Transform the given declaration, which was the first part of a
448 /// nested-name-specifier in a member access expression.
449 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000450 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000451 /// identifier in a nested-name-specifier of a member access expression, e.g.,
452 /// the \c T in \c x->T::member
453 ///
454 /// By default, invokes TransformDecl() to transform the declaration.
455 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000456 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
457 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000458 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000459
Douglas Gregor14454802011-02-25 02:25:35 +0000460 /// \brief Transform the given nested-name-specifier with source-location
461 /// information.
462 ///
463 /// By default, transforms all of the types and declarations within the
464 /// nested-name-specifier. Subclasses may override this function to provide
465 /// alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000466 NestedNameSpecifierLoc
467 TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
468 QualType ObjectType = QualType(),
469 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor14454802011-02-25 02:25:35 +0000470
Douglas Gregorf816bd72009-09-03 22:13:48 +0000471 /// \brief Transform the given declaration name.
472 ///
473 /// By default, transforms the types of conversion function, constructor,
474 /// and destructor names and then (if needed) rebuilds the declaration name.
475 /// Identifiers and selectors are returned unmodified. Sublcasses may
476 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000477 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000478 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000479
Douglas Gregord6ff3322009-08-04 16:50:30 +0000480 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000481 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000482 /// \param SS The nested-name-specifier that qualifies the template
483 /// name. This nested-name-specifier must already have been transformed.
484 ///
485 /// \param Name The template name to transform.
486 ///
487 /// \param NameLoc The source location of the template name.
488 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000489 /// \param ObjectType If we're translating a template name within a member
Douglas Gregor9db53502011-03-02 18:07:45 +0000490 /// access expression, this is the type of the object whose member template
491 /// is being referenced.
492 ///
493 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
494 /// also refers to a name within the current (lexical) scope, this is the
495 /// declaration it refers to.
496 ///
497 /// By default, transforms the template name by transforming the declarations
498 /// and nested-name-specifiers that occur within the template name.
499 /// Subclasses may override this function to provide alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000500 TemplateName
501 TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
502 SourceLocation NameLoc,
503 QualType ObjectType = QualType(),
504 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor9db53502011-03-02 18:07:45 +0000505
Douglas Gregord6ff3322009-08-04 16:50:30 +0000506 /// \brief Transform the given template argument.
507 ///
Mike Stump11289f42009-09-09 15:08:12 +0000508 /// By default, this operation transforms the type, expression, or
509 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000510 /// new template argument from the transformed result. Subclasses may
511 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000512 ///
513 /// Returns true if there was an error.
514 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +0000515 TemplateArgumentLoc &Output,
516 bool Uneval = false);
John McCall0ad16662009-10-29 08:12:44 +0000517
Douglas Gregor62e06f22010-12-20 17:31:10 +0000518 /// \brief Transform the given set of template arguments.
519 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000520 /// By default, this operation transforms all of the template arguments
Douglas Gregor62e06f22010-12-20 17:31:10 +0000521 /// in the input set using \c TransformTemplateArgument(), and appends
522 /// the transformed arguments to the output list.
523 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000524 /// Note that this overload of \c TransformTemplateArguments() is merely
525 /// a convenience function. Subclasses that wish to override this behavior
526 /// should override the iterator-based member template version.
527 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000528 /// \param Inputs The set of template arguments to be transformed.
529 ///
530 /// \param NumInputs The number of template arguments in \p Inputs.
531 ///
532 /// \param Outputs The set of transformed template arguments output by this
533 /// routine.
534 ///
535 /// Returns true if an error occurred.
536 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
537 unsigned NumInputs,
Richard Smithd784e682015-09-23 21:41:42 +0000538 TemplateArgumentListInfo &Outputs,
539 bool Uneval = false) {
540 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs,
541 Uneval);
Douglas Gregorfe921a72010-12-20 23:36:19 +0000542 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000543
544 /// \brief Transform the given set of template arguments.
545 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000546 /// By default, this operation transforms all of the template arguments
Douglas Gregor42cafa82010-12-20 17:42:22 +0000547 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier1dcde962012-08-08 18:46:20 +0000548 /// the transformed arguments to the output list.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000549 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000550 /// \param First An iterator to the first template argument.
551 ///
552 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000553 ///
554 /// \param Outputs The set of transformed template arguments output by this
555 /// routine.
556 ///
557 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000558 template<typename InputIterator>
559 bool TransformTemplateArguments(InputIterator First,
560 InputIterator Last,
Richard Smithd784e682015-09-23 21:41:42 +0000561 TemplateArgumentListInfo &Outputs,
562 bool Uneval = false);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000563
John McCall0ad16662009-10-29 08:12:44 +0000564 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
565 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
566 TemplateArgumentLoc &ArgLoc);
567
John McCallbcd03502009-12-07 02:54:59 +0000568 /// \brief Fakes up a TypeSourceInfo for a type.
569 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
570 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000571 getDerived().getBaseLocation());
572 }
Mike Stump11289f42009-09-09 15:08:12 +0000573
John McCall550e0c22009-10-21 00:40:46 +0000574#define ABSTRACT_TYPELOC(CLASS, PARENT)
575#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000576 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000577#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000578
Richard Smith2e321552014-11-12 02:00:47 +0000579 template<typename Fn>
Douglas Gregor3024f072012-04-16 07:05:22 +0000580 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
581 FunctionProtoTypeLoc TL,
582 CXXRecordDecl *ThisContext,
Richard Smith2e321552014-11-12 02:00:47 +0000583 unsigned ThisTypeQuals,
584 Fn TransformExceptionSpec);
585
586 bool TransformExceptionSpec(SourceLocation Loc,
587 FunctionProtoType::ExceptionSpecInfo &ESI,
588 SmallVectorImpl<QualType> &Exceptions,
589 bool &Changed);
Douglas Gregor3024f072012-04-16 07:05:22 +0000590
David Majnemerfad8f482013-10-15 09:33:02 +0000591 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000592
Chad Rosier1dcde962012-08-08 18:46:20 +0000593 QualType
John McCall31f82722010-11-12 08:19:04 +0000594 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
595 TemplateSpecializationTypeLoc TL,
596 TemplateName Template);
597
Chad Rosier1dcde962012-08-08 18:46:20 +0000598 QualType
John McCall31f82722010-11-12 08:19:04 +0000599 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
600 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000601 TemplateName Template,
602 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000603
Nico Weberc153d242014-07-28 00:02:09 +0000604 QualType TransformDependentTemplateSpecializationType(
605 TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL,
606 NestedNameSpecifierLoc QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000607
John McCall58f10c32010-03-11 09:03:00 +0000608 /// \brief Transforms the parameters of a function type into the
609 /// given vectors.
610 ///
611 /// The result vectors should be kept in sync; null entries in the
612 /// variables vector are acceptable.
613 ///
614 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000615 bool TransformFunctionTypeParams(SourceLocation Loc,
616 ParmVarDecl **Params, unsigned NumParams,
617 const QualType *ParamTypes,
John McCallc8e321d2016-03-01 02:09:25 +0000618 const FunctionProtoType::ExtParameterInfo *ParamInfos,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000619 SmallVectorImpl<QualType> &PTypes,
John McCallc8e321d2016-03-01 02:09:25 +0000620 SmallVectorImpl<ParmVarDecl*> *PVars,
621 Sema::ExtParameterInfoBuilder &PInfos);
John McCall58f10c32010-03-11 09:03:00 +0000622
623 /// \brief Transforms a single function-type parameter. Return null
624 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000625 ///
626 /// \param indexAdjustment - A number to add to the parameter's
627 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000628 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000629 int indexAdjustment,
David Blaikie05785d12013-02-20 22:23:23 +0000630 Optional<unsigned> NumExpansions,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +0000631 bool ExpectParameterPack);
John McCall58f10c32010-03-11 09:03:00 +0000632
John McCall31f82722010-11-12 08:19:04 +0000633 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000634
John McCalldadc5752010-08-24 06:29:42 +0000635 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
636 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Richard Smith2589b9802012-07-25 03:56:55 +0000637
Faisal Vali2cba1332013-10-23 06:44:28 +0000638 TemplateParameterList *TransformTemplateParameterList(
639 TemplateParameterList *TPL) {
640 return TPL;
641 }
642
Richard Smithdb2630f2012-10-21 03:28:35 +0000643 ExprResult TransformAddressOfOperand(Expr *E);
Reid Kleckner32506ed2014-06-12 23:03:48 +0000644
Richard Smithdb2630f2012-10-21 03:28:35 +0000645 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +0000646 bool IsAddressOfOperand,
647 TypeSourceInfo **RecoveryTSI);
648
649 ExprResult TransformParenDependentScopeDeclRefExpr(
650 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
651 TypeSourceInfo **RecoveryTSI);
652
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000653 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000654
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000655// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
656// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000657#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000658 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000659 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000660#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000661 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000662 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000663#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000664#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000665
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000666#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000667 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000668 OMPClause *Transform ## Class(Class *S);
669#include "clang/Basic/OpenMPKinds.def"
670
Douglas Gregord6ff3322009-08-04 16:50:30 +0000671 /// \brief Build a new pointer type given its pointee type.
672 ///
673 /// By default, performs semantic analysis when building the pointer type.
674 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000675 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000676
677 /// \brief Build a new block pointer type given its pointee type.
678 ///
Mike Stump11289f42009-09-09 15:08:12 +0000679 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000680 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000681 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000682
John McCall70dd5f62009-10-30 00:06:24 +0000683 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000684 ///
John McCall70dd5f62009-10-30 00:06:24 +0000685 /// By default, performs semantic analysis when building the
686 /// reference type. Subclasses may override this routine to provide
687 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000688 ///
John McCall70dd5f62009-10-30 00:06:24 +0000689 /// \param LValue whether the type was written with an lvalue sigil
690 /// or an rvalue sigil.
691 QualType RebuildReferenceType(QualType ReferentType,
692 bool LValue,
693 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000694
Douglas Gregord6ff3322009-08-04 16:50:30 +0000695 /// \brief Build a new member pointer type given the pointee type and the
696 /// class type it refers into.
697 ///
698 /// By default, performs semantic analysis when building the member pointer
699 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000700 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
701 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000702
Douglas Gregor9bda6cf2015-07-07 03:58:14 +0000703 /// \brief Build an Objective-C object type.
704 ///
705 /// By default, performs semantic analysis when building the object type.
706 /// Subclasses may override this routine to provide different behavior.
707 QualType RebuildObjCObjectType(QualType BaseType,
708 SourceLocation Loc,
709 SourceLocation TypeArgsLAngleLoc,
710 ArrayRef<TypeSourceInfo *> TypeArgs,
711 SourceLocation TypeArgsRAngleLoc,
712 SourceLocation ProtocolLAngleLoc,
713 ArrayRef<ObjCProtocolDecl *> Protocols,
714 ArrayRef<SourceLocation> ProtocolLocs,
715 SourceLocation ProtocolRAngleLoc);
716
717 /// \brief Build a new Objective-C object pointer type given the pointee type.
718 ///
719 /// By default, directly builds the pointer type, with no additional semantic
720 /// analysis.
721 QualType RebuildObjCObjectPointerType(QualType PointeeType,
722 SourceLocation Star);
723
Douglas Gregord6ff3322009-08-04 16:50:30 +0000724 /// \brief Build a new array type given the element type, size
725 /// modifier, size of the array (if known), size expression, and index type
726 /// qualifiers.
727 ///
728 /// By default, performs semantic analysis when building the array type.
729 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000730 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000731 QualType RebuildArrayType(QualType ElementType,
732 ArrayType::ArraySizeModifier SizeMod,
733 const llvm::APInt *Size,
734 Expr *SizeExpr,
735 unsigned IndexTypeQuals,
736 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000737
Douglas Gregord6ff3322009-08-04 16:50:30 +0000738 /// \brief Build a new constant array type given the element type, size
739 /// modifier, (known) size of the array, and index type qualifiers.
740 ///
741 /// By default, performs semantic analysis when building the array type.
742 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000743 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000744 ArrayType::ArraySizeModifier SizeMod,
745 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000746 unsigned IndexTypeQuals,
747 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000748
Douglas Gregord6ff3322009-08-04 16:50:30 +0000749 /// \brief Build a new incomplete array type given the element type, size
750 /// modifier, 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 RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000755 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000756 unsigned IndexTypeQuals,
757 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000758
Mike Stump11289f42009-09-09 15:08:12 +0000759 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000760 /// size modifier, size expression, and index type qualifiers.
761 ///
762 /// By default, performs semantic analysis when building the array type.
763 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000764 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000765 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000766 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000767 unsigned IndexTypeQuals,
768 SourceRange BracketsRange);
769
Mike Stump11289f42009-09-09 15:08:12 +0000770 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000771 /// size modifier, size expression, and index type qualifiers.
772 ///
773 /// By default, performs semantic analysis when building the array type.
774 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000775 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000776 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000777 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000778 unsigned IndexTypeQuals,
779 SourceRange BracketsRange);
780
781 /// \brief Build a new vector type given the element type and
782 /// number of elements.
783 ///
784 /// By default, performs semantic analysis when building the vector type.
785 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000786 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000787 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000788
Douglas Gregord6ff3322009-08-04 16:50:30 +0000789 /// \brief Build a new extended vector type given the element type and
790 /// number of elements.
791 ///
792 /// By default, performs semantic analysis when building the vector type.
793 /// Subclasses may override this routine to provide different behavior.
794 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
795 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000796
797 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000798 /// given the element type and number of elements.
799 ///
800 /// By default, performs semantic analysis when building the vector type.
801 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000802 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000803 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000804 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000805
Douglas Gregord6ff3322009-08-04 16:50:30 +0000806 /// \brief Build a new function type.
807 ///
808 /// By default, performs semantic analysis when building the function type.
809 /// Subclasses may override this routine to provide different behavior.
810 QualType RebuildFunctionProtoType(QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +0000811 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000812 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000813
John McCall550e0c22009-10-21 00:40:46 +0000814 /// \brief Build a new unprototyped function type.
815 QualType RebuildFunctionNoProtoType(QualType ResultType);
816
John McCallb96ec562009-12-04 22:46:56 +0000817 /// \brief Rebuild an unresolved typename type, given the decl that
818 /// the UnresolvedUsingTypenameDecl was transformed to.
819 QualType RebuildUnresolvedUsingType(Decl *D);
820
Douglas Gregord6ff3322009-08-04 16:50:30 +0000821 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000822 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000823 return SemaRef.Context.getTypeDeclType(Typedef);
824 }
825
826 /// \brief Build a new class/struct/union type.
827 QualType RebuildRecordType(RecordDecl *Record) {
828 return SemaRef.Context.getTypeDeclType(Record);
829 }
830
831 /// \brief Build a new Enum type.
832 QualType RebuildEnumType(EnumDecl *Enum) {
833 return SemaRef.Context.getTypeDeclType(Enum);
834 }
John McCallfcc33b02009-09-05 00:15:47 +0000835
Mike Stump11289f42009-09-09 15:08:12 +0000836 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000837 ///
838 /// By default, performs semantic analysis when building the typeof type.
839 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000840 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000841
Mike Stump11289f42009-09-09 15:08:12 +0000842 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000843 ///
844 /// By default, builds a new TypeOfType with the given underlying type.
845 QualType RebuildTypeOfType(QualType Underlying);
846
Alexis Hunte852b102011-05-24 22:41:36 +0000847 /// \brief Build a new unary transform type.
848 QualType RebuildUnaryTransformType(QualType BaseType,
849 UnaryTransformType::UTTKind UKind,
850 SourceLocation Loc);
851
Richard Smith74aeef52013-04-26 16:15:35 +0000852 /// \brief Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000853 ///
854 /// By default, performs semantic analysis when building the decltype type.
855 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000856 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000857
Richard Smith74aeef52013-04-26 16:15:35 +0000858 /// \brief Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000859 ///
860 /// By default, builds a new AutoType with the given deduced type.
Richard Smithe301ba22015-11-11 02:02:15 +0000861 QualType RebuildAutoType(QualType Deduced, AutoTypeKeyword Keyword) {
Richard Smith27d807c2013-04-30 13:56:41 +0000862 // Note, IsDependent is always false here: we implicitly convert an 'auto'
863 // which has been deduced to a dependent type into an undeduced 'auto', so
864 // that we'll retry deduction after the transformation.
Richard Smithe301ba22015-11-11 02:02:15 +0000865 return SemaRef.Context.getAutoType(Deduced, Keyword,
Faisal Vali2b391ab2013-09-26 19:54:12 +0000866 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000867 }
868
Douglas Gregord6ff3322009-08-04 16:50:30 +0000869 /// \brief Build a new template specialization type.
870 ///
871 /// By default, performs semantic analysis when building the template
872 /// specialization type. Subclasses may override this routine to provide
873 /// different behavior.
874 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000875 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000876 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000877
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000878 /// \brief Build a new parenthesized type.
879 ///
880 /// By default, builds a new ParenType type from the inner type.
881 /// Subclasses may override this routine to provide different behavior.
882 QualType RebuildParenType(QualType InnerType) {
883 return SemaRef.Context.getParenType(InnerType);
884 }
885
Douglas Gregord6ff3322009-08-04 16:50:30 +0000886 /// \brief Build a new qualified name type.
887 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000888 /// By default, builds a new ElaboratedType type from the keyword,
889 /// the nested-name-specifier and the named type.
890 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000891 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
892 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000893 NestedNameSpecifierLoc QualifierLoc,
894 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000895 return SemaRef.Context.getElaboratedType(Keyword,
896 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000897 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000898 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000899
900 /// \brief Build a new typename type that refers to a template-id.
901 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000902 /// By default, builds a new DependentNameType type from the
903 /// nested-name-specifier and the given type. Subclasses may override
904 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000905 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000906 ElaboratedTypeKeyword Keyword,
907 NestedNameSpecifierLoc QualifierLoc,
908 const IdentifierInfo *Name,
909 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000910 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000911 // Rebuild the template name.
912 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000913 CXXScopeSpec SS;
914 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +0000915 TemplateName InstName
Craig Topperc3ec1492014-05-26 06:22:03 +0000916 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(),
917 nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000918
Douglas Gregora7a795b2011-03-01 20:11:18 +0000919 if (InstName.isNull())
920 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000921
Douglas Gregora7a795b2011-03-01 20:11:18 +0000922 // If it's still dependent, make a dependent specialization.
923 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000924 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
925 QualifierLoc.getNestedNameSpecifier(),
926 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000927 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000928
Douglas Gregora7a795b2011-03-01 20:11:18 +0000929 // Otherwise, make an elaborated type wrapping a non-dependent
930 // specialization.
931 QualType T =
932 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
933 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000934
Craig Topperc3ec1492014-05-26 06:22:03 +0000935 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
Douglas Gregora7a795b2011-03-01 20:11:18 +0000936 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +0000937
938 return SemaRef.Context.getElaboratedType(Keyword,
939 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +0000940 T);
941 }
942
Douglas Gregord6ff3322009-08-04 16:50:30 +0000943 /// \brief Build a new typename type that refers to an identifier.
944 ///
945 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000946 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000947 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000948 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000949 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000950 NestedNameSpecifierLoc QualifierLoc,
951 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000952 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000953 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000954 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000955
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000956 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000957 // If the name is still dependent, just build a new dependent name type.
958 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +0000959 return SemaRef.Context.getDependentNameType(Keyword,
960 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000961 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000962 }
963
Abramo Bagnara6150c882010-05-11 21:36:43 +0000964 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000965 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000966 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000967
968 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
969
Abramo Bagnarad7548482010-05-19 21:37:53 +0000970 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000971 // into a non-dependent elaborated-type-specifier. Find the tag we're
972 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000973 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000974 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
975 if (!DC)
976 return QualType();
977
John McCallbf8c5192010-05-27 06:40:31 +0000978 if (SemaRef.RequireCompleteDeclContext(SS, DC))
979 return QualType();
980
Craig Topperc3ec1492014-05-26 06:22:03 +0000981 TagDecl *Tag = nullptr;
Douglas Gregore677daf2010-03-31 22:19:08 +0000982 SemaRef.LookupQualifiedName(Result, DC);
983 switch (Result.getResultKind()) {
984 case LookupResult::NotFound:
985 case LookupResult::NotFoundInCurrentInstantiation:
986 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000987
Douglas Gregore677daf2010-03-31 22:19:08 +0000988 case LookupResult::Found:
989 Tag = Result.getAsSingle<TagDecl>();
990 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000991
Douglas Gregore677daf2010-03-31 22:19:08 +0000992 case LookupResult::FoundOverloaded:
993 case LookupResult::FoundUnresolvedValue:
994 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +0000995
Douglas Gregore677daf2010-03-31 22:19:08 +0000996 case LookupResult::Ambiguous:
997 // Let the LookupResult structure handle ambiguities.
998 return QualType();
999 }
1000
1001 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +00001002 // Check where the name exists but isn't a tag type and use that to emit
1003 // better diagnostics.
1004 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
1005 SemaRef.LookupQualifiedName(Result, DC);
1006 switch (Result.getResultKind()) {
1007 case LookupResult::Found:
1008 case LookupResult::FoundOverloaded:
1009 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +00001010 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky0c438082011-01-24 19:01:04 +00001011 unsigned Kind = 0;
1012 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smithdda56e42011-04-15 14:24:37 +00001013 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
1014 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky0c438082011-01-24 19:01:04 +00001015 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
1016 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1017 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +00001018 }
Nick Lewycky0c438082011-01-24 19:01:04 +00001019 default:
Nick Lewycky0c438082011-01-24 19:01:04 +00001020 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +00001021 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +00001022 break;
1023 }
Douglas Gregore677daf2010-03-31 22:19:08 +00001024 return QualType();
1025 }
Abramo Bagnara6150c882010-05-11 21:36:43 +00001026
Richard Trieucaa33d32011-06-10 03:11:26 +00001027 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
Justin Bognerc6ecb7c2015-07-10 23:05:47 +00001028 IdLoc, Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +00001029 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +00001030 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1031 return QualType();
1032 }
1033
1034 // Build the elaborated-type-specifier type.
1035 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +00001036 return SemaRef.Context.getElaboratedType(Keyword,
1037 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001038 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00001039 }
Mike Stump11289f42009-09-09 15:08:12 +00001040
Douglas Gregor822d0302011-01-12 17:07:58 +00001041 /// \brief Build a new pack expansion type.
1042 ///
1043 /// By default, builds a new PackExpansionType type from the given pattern.
1044 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001045 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00001046 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001047 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00001048 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001049 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1050 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +00001051 }
1052
Eli Friedman0dfb8892011-10-06 23:00:33 +00001053 /// \brief Build a new atomic type given its value type.
1054 ///
1055 /// By default, performs semantic analysis when building the atomic type.
1056 /// Subclasses may override this routine to provide different behavior.
1057 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1058
Xiuli Pan9c14e282016-01-09 12:53:17 +00001059 /// \brief Build a new pipe type given its value type.
1060 QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc);
1061
Douglas Gregor71dc5092009-08-06 06:41:21 +00001062 /// \brief Build a new template name given a nested name specifier, a flag
1063 /// indicating whether the "template" keyword was provided, and the template
1064 /// that the template name refers to.
1065 ///
1066 /// By default, builds the new template name directly. Subclasses may override
1067 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001068 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001069 bool TemplateKW,
1070 TemplateDecl *Template);
1071
Douglas Gregor71dc5092009-08-06 06:41:21 +00001072 /// \brief Build a new template name given a nested name specifier and the
1073 /// 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,
1080 const IdentifierInfo &Name,
1081 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00001082 QualType ObjectType,
1083 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001084
Douglas Gregor71395fa2009-11-04 00:56:37 +00001085 /// \brief Build a new template name given a nested name specifier and the
1086 /// overloaded operator name that is referred to as a template.
1087 ///
1088 /// By default, performs semantic analysis to determine whether the name can
1089 /// be resolved to a specific template, then builds the appropriate kind of
1090 /// template name. Subclasses may override this routine to provide different
1091 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001092 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001093 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00001094 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001095 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +00001096
1097 /// \brief Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001098 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001099 ///
1100 /// By default, performs semantic analysis to determine whether the name can
1101 /// be resolved to a specific template, then builds the appropriate kind of
1102 /// template name. Subclasses may override this routine to provide different
1103 /// behavior.
1104 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1105 const TemplateArgument &ArgPack) {
1106 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1107 }
1108
Douglas Gregorebe10102009-08-20 07:17:43 +00001109 /// \brief Build a new compound statement.
1110 ///
1111 /// By default, performs semantic analysis to build the new statement.
1112 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001113 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001114 MultiStmtArg Statements,
1115 SourceLocation RBraceLoc,
1116 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001117 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001118 IsStmtExpr);
1119 }
1120
1121 /// \brief Build 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 RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001126 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001127 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001128 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001129 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001130 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001131 ColonLoc);
1132 }
Mike Stump11289f42009-09-09 15:08:12 +00001133
Douglas Gregorebe10102009-08-20 07:17:43 +00001134 /// \brief Attach the body to a new case statement.
1135 ///
1136 /// By default, performs semantic analysis to build the new statement.
1137 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001138 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001139 getSema().ActOnCaseStmtBody(S, Body);
1140 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001141 }
Mike Stump11289f42009-09-09 15:08:12 +00001142
Douglas Gregorebe10102009-08-20 07:17:43 +00001143 /// \brief Build a new default statement.
1144 ///
1145 /// By default, performs semantic analysis to build the new statement.
1146 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001147 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001148 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001149 Stmt *SubStmt) {
1150 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Craig Topperc3ec1492014-05-26 06:22:03 +00001151 /*CurScope=*/nullptr);
Douglas Gregorebe10102009-08-20 07:17:43 +00001152 }
Mike Stump11289f42009-09-09 15:08:12 +00001153
Douglas Gregorebe10102009-08-20 07:17:43 +00001154 /// \brief Build a new label statement.
1155 ///
1156 /// By default, performs semantic analysis to build the new statement.
1157 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001158 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1159 SourceLocation ColonLoc, Stmt *SubStmt) {
1160 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001161 }
Mike Stump11289f42009-09-09 15:08:12 +00001162
Richard Smithc202b282012-04-14 00:33:13 +00001163 /// \brief Build a new label statement.
1164 ///
1165 /// By default, performs semantic analysis to build the new statement.
1166 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001167 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1168 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001169 Stmt *SubStmt) {
1170 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1171 }
1172
Douglas Gregorebe10102009-08-20 07:17:43 +00001173 /// \brief Build a new "if" statement.
1174 ///
1175 /// By default, performs semantic analysis to build the new statement.
1176 /// Subclasses may override this routine to provide different behavior.
Richard Smith03a4aa32016-06-23 19:02:52 +00001177 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::ConditionResult Cond,
1178 Stmt *Then, SourceLocation ElseLoc, Stmt *Else) {
1179 return getSema().ActOnIfStmt(IfLoc, Cond, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001180 }
Mike Stump11289f42009-09-09 15:08:12 +00001181
Douglas Gregorebe10102009-08-20 07:17:43 +00001182 /// \brief Start building a new switch statement.
1183 ///
1184 /// By default, performs semantic analysis to build the new statement.
1185 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001186 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Richard Smith03a4aa32016-06-23 19:02:52 +00001187 Sema::ConditionResult Cond) {
1188 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond);
Douglas Gregorebe10102009-08-20 07:17:43 +00001189 }
Mike Stump11289f42009-09-09 15:08:12 +00001190
Douglas Gregorebe10102009-08-20 07:17:43 +00001191 /// \brief Attach the body to the switch statement.
1192 ///
1193 /// By default, performs semantic analysis to build the new statement.
1194 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001195 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001196 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001197 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001198 }
1199
1200 /// \brief Build a new while statement.
1201 ///
1202 /// By default, performs semantic analysis to build the new statement.
1203 /// Subclasses may override this routine to provide different behavior.
Richard Smith03a4aa32016-06-23 19:02:52 +00001204 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
1205 Sema::ConditionResult Cond, Stmt *Body) {
1206 return getSema().ActOnWhileStmt(WhileLoc, Cond, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001207 }
Mike Stump11289f42009-09-09 15:08:12 +00001208
Douglas Gregorebe10102009-08-20 07:17:43 +00001209 /// \brief Build a new do-while statement.
1210 ///
1211 /// By default, performs semantic analysis to build the new statement.
1212 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001213 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001214 SourceLocation WhileLoc, SourceLocation LParenLoc,
1215 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001216 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1217 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001218 }
1219
1220 /// \brief Build a new for statement.
1221 ///
1222 /// By default, performs semantic analysis to build the new statement.
1223 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001224 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Richard Smith03a4aa32016-06-23 19:02:52 +00001225 Stmt *Init, Sema::ConditionResult Cond,
1226 Sema::FullExprArg Inc, SourceLocation RParenLoc,
1227 Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001228 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Richard Smith03a4aa32016-06-23 19:02:52 +00001229 Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001230 }
Mike Stump11289f42009-09-09 15:08:12 +00001231
Douglas Gregorebe10102009-08-20 07:17:43 +00001232 /// \brief Build a new goto statement.
1233 ///
1234 /// By default, performs semantic analysis to build the new statement.
1235 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001236 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1237 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001238 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001239 }
1240
1241 /// \brief Build a new indirect goto statement.
1242 ///
1243 /// By default, performs semantic analysis to build the new statement.
1244 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001245 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001246 SourceLocation StarLoc,
1247 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001248 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001249 }
Mike Stump11289f42009-09-09 15:08:12 +00001250
Douglas Gregorebe10102009-08-20 07:17:43 +00001251 /// \brief Build a new return statement.
1252 ///
1253 /// By default, performs semantic analysis to build the new statement.
1254 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001255 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001256 return getSema().BuildReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001257 }
Mike Stump11289f42009-09-09 15:08:12 +00001258
Douglas Gregorebe10102009-08-20 07:17:43 +00001259 /// \brief Build a new declaration statement.
1260 ///
1261 /// By default, performs semantic analysis to build the new statement.
1262 /// Subclasses may override this routine to provide different behavior.
Craig Toppere3d2ecbe2014-06-28 23:22:33 +00001263 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
Rafael Espindolaab417692013-07-09 12:05:01 +00001264 SourceLocation StartLoc, SourceLocation EndLoc) {
1265 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001266 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001267 }
Mike Stump11289f42009-09-09 15:08:12 +00001268
Anders Carlssonaaeef072010-01-24 05:50:09 +00001269 /// \brief Build a new inline asm statement.
1270 ///
1271 /// By default, performs semantic analysis to build the new statement.
1272 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001273 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1274 bool IsVolatile, unsigned NumOutputs,
1275 unsigned NumInputs, IdentifierInfo **Names,
1276 MultiExprArg Constraints, MultiExprArg Exprs,
1277 Expr *AsmString, MultiExprArg Clobbers,
1278 SourceLocation RParenLoc) {
1279 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1280 NumInputs, Names, Constraints, Exprs,
1281 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001282 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001283
Chad Rosier32503022012-06-11 20:47:18 +00001284 /// \brief Build a new MS style inline asm statement.
1285 ///
1286 /// By default, performs semantic analysis to build the new statement.
1287 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001288 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001289 ArrayRef<Token> AsmToks,
1290 StringRef AsmString,
1291 unsigned NumOutputs, unsigned NumInputs,
1292 ArrayRef<StringRef> Constraints,
1293 ArrayRef<StringRef> Clobbers,
1294 ArrayRef<Expr*> Exprs,
1295 SourceLocation EndLoc) {
1296 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1297 NumOutputs, NumInputs,
1298 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001299 }
1300
Richard Smith9f690bd2015-10-27 06:02:45 +00001301 /// \brief Build a new co_return statement.
1302 ///
1303 /// By default, performs semantic analysis to build the new statement.
1304 /// Subclasses may override this routine to provide different behavior.
1305 StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result) {
1306 return getSema().BuildCoreturnStmt(CoreturnLoc, Result);
1307 }
1308
1309 /// \brief Build a new co_await expression.
1310 ///
1311 /// By default, performs semantic analysis to build the new expression.
1312 /// Subclasses may override this routine to provide different behavior.
1313 ExprResult RebuildCoawaitExpr(SourceLocation CoawaitLoc, Expr *Result) {
1314 return getSema().BuildCoawaitExpr(CoawaitLoc, Result);
1315 }
1316
1317 /// \brief Build a new co_yield expression.
1318 ///
1319 /// By default, performs semantic analysis to build the new expression.
1320 /// Subclasses may override this routine to provide different behavior.
1321 ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result) {
1322 return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1323 }
1324
James Dennett2a4d13c2012-06-15 07:13:21 +00001325 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001326 ///
1327 /// By default, performs semantic analysis to build the new statement.
1328 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001329 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001330 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001331 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001332 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001333 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001334 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001335 }
1336
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001337 /// \brief Rebuild an Objective-C exception declaration.
1338 ///
1339 /// By default, performs semantic analysis to build the new declaration.
1340 /// Subclasses may override this routine to provide different behavior.
1341 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1342 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001343 return getSema().BuildObjCExceptionDecl(TInfo, T,
1344 ExceptionDecl->getInnerLocStart(),
1345 ExceptionDecl->getLocation(),
1346 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001347 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001348
James Dennett2a4d13c2012-06-15 07:13:21 +00001349 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001350 ///
1351 /// By default, performs semantic analysis to build the new statement.
1352 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001353 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001354 SourceLocation RParenLoc,
1355 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001356 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001357 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001358 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001359 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001360
James Dennett2a4d13c2012-06-15 07:13:21 +00001361 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001362 ///
1363 /// By default, performs semantic analysis to build the new statement.
1364 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001365 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001366 Stmt *Body) {
1367 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001368 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001369
James Dennett2a4d13c2012-06-15 07:13:21 +00001370 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001371 ///
1372 /// By default, performs semantic analysis to build the new statement.
1373 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001374 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001375 Expr *Operand) {
1376 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001377 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001378
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001379 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001380 ///
1381 /// By default, performs semantic analysis to build the new statement.
1382 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001383 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001384 DeclarationNameInfo DirName,
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001385 OpenMPDirectiveKind CancelRegion,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001386 ArrayRef<OMPClause *> Clauses,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001387 Stmt *AStmt, SourceLocation StartLoc,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001388 SourceLocation EndLoc) {
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001389 return getSema().ActOnOpenMPExecutableDirective(
1390 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001391 }
1392
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001393 /// \brief Build a new OpenMP 'if' clause.
1394 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001395 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001396 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001397 OMPClause *RebuildOMPIfClause(OpenMPDirectiveKind NameModifier,
1398 Expr *Condition, SourceLocation StartLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001399 SourceLocation LParenLoc,
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001400 SourceLocation NameModifierLoc,
1401 SourceLocation ColonLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001402 SourceLocation EndLoc) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001403 return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc,
1404 LParenLoc, NameModifierLoc, ColonLoc,
1405 EndLoc);
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001406 }
1407
Alexey Bataev3778b602014-07-17 07:32:53 +00001408 /// \brief Build a new OpenMP 'final' clause.
1409 ///
1410 /// By default, performs semantic analysis to build the new OpenMP clause.
1411 /// Subclasses may override this routine to provide different behavior.
1412 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1413 SourceLocation LParenLoc,
1414 SourceLocation EndLoc) {
1415 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1416 EndLoc);
1417 }
1418
Alexey Bataev568a8332014-03-06 06:15:19 +00001419 /// \brief Build a new OpenMP 'num_threads' clause.
1420 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001421 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001422 /// Subclasses may override this routine to provide different behavior.
1423 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1424 SourceLocation StartLoc,
1425 SourceLocation LParenLoc,
1426 SourceLocation EndLoc) {
1427 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1428 LParenLoc, EndLoc);
1429 }
1430
Alexey Bataev62c87d22014-03-21 04:51:18 +00001431 /// \brief Build a new OpenMP 'safelen' clause.
1432 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001433 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001434 /// Subclasses may override this routine to provide different behavior.
1435 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1436 SourceLocation LParenLoc,
1437 SourceLocation EndLoc) {
1438 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1439 }
1440
Alexey Bataev66b15b52015-08-21 11:14:16 +00001441 /// \brief Build a new OpenMP 'simdlen' clause.
1442 ///
1443 /// By default, performs semantic analysis to build the new OpenMP clause.
1444 /// Subclasses may override this routine to provide different behavior.
1445 OMPClause *RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc,
1446 SourceLocation LParenLoc,
1447 SourceLocation EndLoc) {
1448 return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc);
1449 }
1450
Alexander Musman8bd31e62014-05-27 15:12:19 +00001451 /// \brief Build a new OpenMP 'collapse' clause.
1452 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001453 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001454 /// Subclasses may override this routine to provide different behavior.
1455 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1456 SourceLocation LParenLoc,
1457 SourceLocation EndLoc) {
1458 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1459 EndLoc);
1460 }
1461
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001462 /// \brief Build a new OpenMP 'default' clause.
1463 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001464 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001465 /// Subclasses may override this routine to provide different behavior.
1466 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1467 SourceLocation KindKwLoc,
1468 SourceLocation StartLoc,
1469 SourceLocation LParenLoc,
1470 SourceLocation EndLoc) {
1471 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1472 StartLoc, LParenLoc, EndLoc);
1473 }
1474
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001475 /// \brief Build a new OpenMP 'proc_bind' clause.
1476 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001477 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001478 /// Subclasses may override this routine to provide different behavior.
1479 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1480 SourceLocation KindKwLoc,
1481 SourceLocation StartLoc,
1482 SourceLocation LParenLoc,
1483 SourceLocation EndLoc) {
1484 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1485 StartLoc, LParenLoc, EndLoc);
1486 }
1487
Alexey Bataev56dafe82014-06-20 07:16:17 +00001488 /// \brief Build a new OpenMP 'schedule' clause.
1489 ///
1490 /// By default, performs semantic analysis to build the new OpenMP clause.
1491 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6402bca2015-12-28 07:25:51 +00001492 OMPClause *RebuildOMPScheduleClause(
1493 OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2,
1494 OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1495 SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1496 SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
Alexey Bataev56dafe82014-06-20 07:16:17 +00001497 return getSema().ActOnOpenMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00001498 M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1499 CommaLoc, EndLoc);
Alexey Bataev56dafe82014-06-20 07:16:17 +00001500 }
1501
Alexey Bataev10e775f2015-07-30 11:36:16 +00001502 /// \brief Build a new OpenMP 'ordered' clause.
1503 ///
1504 /// By default, performs semantic analysis to build the new OpenMP clause.
1505 /// Subclasses may override this routine to provide different behavior.
1506 OMPClause *RebuildOMPOrderedClause(SourceLocation StartLoc,
1507 SourceLocation EndLoc,
1508 SourceLocation LParenLoc, Expr *Num) {
1509 return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num);
1510 }
1511
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001512 /// \brief Build a new OpenMP 'private' clause.
1513 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001514 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001515 /// Subclasses may override this routine to provide different behavior.
1516 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1517 SourceLocation StartLoc,
1518 SourceLocation LParenLoc,
1519 SourceLocation EndLoc) {
1520 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1521 EndLoc);
1522 }
1523
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001524 /// \brief Build a new OpenMP 'firstprivate' clause.
1525 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001526 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001527 /// Subclasses may override this routine to provide different behavior.
1528 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1529 SourceLocation StartLoc,
1530 SourceLocation LParenLoc,
1531 SourceLocation EndLoc) {
1532 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1533 EndLoc);
1534 }
1535
Alexander Musman1bb328c2014-06-04 13:06:39 +00001536 /// \brief Build a new OpenMP 'lastprivate' clause.
1537 ///
1538 /// By default, performs semantic analysis to build the new OpenMP clause.
1539 /// Subclasses may override this routine to provide different behavior.
1540 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1541 SourceLocation StartLoc,
1542 SourceLocation LParenLoc,
1543 SourceLocation EndLoc) {
1544 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1545 EndLoc);
1546 }
1547
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001548 /// \brief Build a new OpenMP 'shared' clause.
1549 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001550 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001551 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001552 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1553 SourceLocation StartLoc,
1554 SourceLocation LParenLoc,
1555 SourceLocation EndLoc) {
1556 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1557 EndLoc);
1558 }
1559
Alexey Bataevc5e02582014-06-16 07:08:35 +00001560 /// \brief Build a new OpenMP 'reduction' clause.
1561 ///
1562 /// By default, performs semantic analysis to build the new statement.
1563 /// Subclasses may override this routine to provide different behavior.
1564 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1565 SourceLocation StartLoc,
1566 SourceLocation LParenLoc,
1567 SourceLocation ColonLoc,
1568 SourceLocation EndLoc,
1569 CXXScopeSpec &ReductionIdScopeSpec,
Alexey Bataeva839ddd2016-03-17 10:19:46 +00001570 const DeclarationNameInfo &ReductionId,
1571 ArrayRef<Expr *> UnresolvedReductions) {
Alexey Bataevc5e02582014-06-16 07:08:35 +00001572 return getSema().ActOnOpenMPReductionClause(
1573 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
Alexey Bataeva839ddd2016-03-17 10:19:46 +00001574 ReductionId, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00001575 }
1576
Alexander Musman8dba6642014-04-22 13:09:42 +00001577 /// \brief Build a new OpenMP 'linear' clause.
1578 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001579 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001580 /// Subclasses may override this routine to provide different behavior.
1581 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1582 SourceLocation StartLoc,
1583 SourceLocation LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001584 OpenMPLinearClauseKind Modifier,
1585 SourceLocation ModifierLoc,
Alexander Musman8dba6642014-04-22 13:09:42 +00001586 SourceLocation ColonLoc,
1587 SourceLocation EndLoc) {
1588 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001589 Modifier, ModifierLoc, ColonLoc,
1590 EndLoc);
Alexander Musman8dba6642014-04-22 13:09:42 +00001591 }
1592
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001593 /// \brief Build a new OpenMP 'aligned' clause.
1594 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001595 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001596 /// Subclasses may override this routine to provide different behavior.
1597 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1598 SourceLocation StartLoc,
1599 SourceLocation LParenLoc,
1600 SourceLocation ColonLoc,
1601 SourceLocation EndLoc) {
1602 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1603 LParenLoc, ColonLoc, EndLoc);
1604 }
1605
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001606 /// \brief Build a new OpenMP 'copyin' clause.
1607 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001608 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001609 /// Subclasses may override this routine to provide different behavior.
1610 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1611 SourceLocation StartLoc,
1612 SourceLocation LParenLoc,
1613 SourceLocation EndLoc) {
1614 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1615 EndLoc);
1616 }
1617
Alexey Bataevbae9a792014-06-27 10:37:06 +00001618 /// \brief Build a new OpenMP 'copyprivate' 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 *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1623 SourceLocation StartLoc,
1624 SourceLocation LParenLoc,
1625 SourceLocation EndLoc) {
1626 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1627 EndLoc);
1628 }
1629
Alexey Bataev6125da92014-07-21 11:26:11 +00001630 /// \brief Build a new OpenMP 'flush' 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 *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1635 SourceLocation StartLoc,
1636 SourceLocation LParenLoc,
1637 SourceLocation EndLoc) {
1638 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1639 EndLoc);
1640 }
1641
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001642 /// \brief Build a new OpenMP 'depend' pseudo clause.
1643 ///
1644 /// By default, performs semantic analysis to build the new OpenMP clause.
1645 /// Subclasses may override this routine to provide different behavior.
1646 OMPClause *
1647 RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
1648 SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1649 SourceLocation StartLoc, SourceLocation LParenLoc,
1650 SourceLocation EndLoc) {
1651 return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList,
1652 StartLoc, LParenLoc, EndLoc);
1653 }
1654
Michael Wonge710d542015-08-07 16:16:36 +00001655 /// \brief Build a new OpenMP 'device' clause.
1656 ///
1657 /// By default, performs semantic analysis to build the new statement.
1658 /// Subclasses may override this routine to provide different behavior.
1659 OMPClause *RebuildOMPDeviceClause(Expr *Device, SourceLocation StartLoc,
1660 SourceLocation LParenLoc,
1661 SourceLocation EndLoc) {
Kelvin Li099bb8c2015-11-24 20:50:12 +00001662 return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc,
Michael Wonge710d542015-08-07 16:16:36 +00001663 EndLoc);
1664 }
1665
Kelvin Li0bff7af2015-11-23 05:32:03 +00001666 /// \brief Build a new OpenMP 'map' clause.
1667 ///
1668 /// By default, performs semantic analysis to build the new OpenMP clause.
1669 /// Subclasses may override this routine to provide different behavior.
Samuel Antao23abd722016-01-19 20:40:49 +00001670 OMPClause *
1671 RebuildOMPMapClause(OpenMPMapClauseKind MapTypeModifier,
1672 OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
1673 SourceLocation MapLoc, SourceLocation ColonLoc,
1674 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1675 SourceLocation LParenLoc, SourceLocation EndLoc) {
1676 return getSema().ActOnOpenMPMapClause(MapTypeModifier, MapType,
1677 IsMapTypeImplicit, MapLoc, ColonLoc,
1678 VarList, StartLoc, LParenLoc, EndLoc);
Kelvin Li0bff7af2015-11-23 05:32:03 +00001679 }
1680
Kelvin Li099bb8c2015-11-24 20:50:12 +00001681 /// \brief Build a new OpenMP 'num_teams' clause.
1682 ///
1683 /// By default, performs semantic analysis to build the new statement.
1684 /// Subclasses may override this routine to provide different behavior.
1685 OMPClause *RebuildOMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc,
1686 SourceLocation LParenLoc,
1687 SourceLocation EndLoc) {
1688 return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc,
1689 EndLoc);
1690 }
1691
Kelvin Lia15fb1a2015-11-27 18:47:36 +00001692 /// \brief Build a new OpenMP 'thread_limit' clause.
1693 ///
1694 /// By default, performs semantic analysis to build the new statement.
1695 /// Subclasses may override this routine to provide different behavior.
1696 OMPClause *RebuildOMPThreadLimitClause(Expr *ThreadLimit,
1697 SourceLocation StartLoc,
1698 SourceLocation LParenLoc,
1699 SourceLocation EndLoc) {
1700 return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc,
1701 LParenLoc, EndLoc);
1702 }
1703
Alexey Bataeva0569352015-12-01 10:17:31 +00001704 /// \brief Build a new OpenMP 'priority' clause.
1705 ///
1706 /// By default, performs semantic analysis to build the new statement.
1707 /// Subclasses may override this routine to provide different behavior.
1708 OMPClause *RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc,
1709 SourceLocation LParenLoc,
1710 SourceLocation EndLoc) {
1711 return getSema().ActOnOpenMPPriorityClause(Priority, StartLoc, LParenLoc,
1712 EndLoc);
1713 }
1714
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00001715 /// \brief Build a new OpenMP 'grainsize' clause.
1716 ///
1717 /// By default, performs semantic analysis to build the new statement.
1718 /// Subclasses may override this routine to provide different behavior.
1719 OMPClause *RebuildOMPGrainsizeClause(Expr *Grainsize, SourceLocation StartLoc,
1720 SourceLocation LParenLoc,
1721 SourceLocation EndLoc) {
1722 return getSema().ActOnOpenMPGrainsizeClause(Grainsize, StartLoc, LParenLoc,
1723 EndLoc);
1724 }
1725
Alexey Bataev382967a2015-12-08 12:06:20 +00001726 /// \brief Build a new OpenMP 'num_tasks' clause.
1727 ///
1728 /// By default, performs semantic analysis to build the new statement.
1729 /// Subclasses may override this routine to provide different behavior.
1730 OMPClause *RebuildOMPNumTasksClause(Expr *NumTasks, SourceLocation StartLoc,
1731 SourceLocation LParenLoc,
1732 SourceLocation EndLoc) {
1733 return getSema().ActOnOpenMPNumTasksClause(NumTasks, StartLoc, LParenLoc,
1734 EndLoc);
1735 }
1736
Alexey Bataev28c75412015-12-15 08:19:24 +00001737 /// \brief Build a new OpenMP 'hint' clause.
1738 ///
1739 /// By default, performs semantic analysis to build the new statement.
1740 /// Subclasses may override this routine to provide different behavior.
1741 OMPClause *RebuildOMPHintClause(Expr *Hint, SourceLocation StartLoc,
1742 SourceLocation LParenLoc,
1743 SourceLocation EndLoc) {
1744 return getSema().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc, EndLoc);
1745 }
1746
Carlo Bertollib4adf552016-01-15 18:50:31 +00001747 /// \brief Build a new OpenMP 'dist_schedule' clause.
1748 ///
1749 /// By default, performs semantic analysis to build the new OpenMP clause.
1750 /// Subclasses may override this routine to provide different behavior.
1751 OMPClause *
1752 RebuildOMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind,
1753 Expr *ChunkSize, SourceLocation StartLoc,
1754 SourceLocation LParenLoc, SourceLocation KindLoc,
1755 SourceLocation CommaLoc, SourceLocation EndLoc) {
1756 return getSema().ActOnOpenMPDistScheduleClause(
1757 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1758 }
1759
Samuel Antao661c0902016-05-26 17:39:58 +00001760 /// \brief Build a new OpenMP 'to' clause.
1761 ///
1762 /// By default, performs semantic analysis to build the new statement.
1763 /// Subclasses may override this routine to provide different behavior.
1764 OMPClause *RebuildOMPToClause(ArrayRef<Expr *> VarList,
1765 SourceLocation StartLoc,
1766 SourceLocation LParenLoc,
1767 SourceLocation EndLoc) {
1768 return getSema().ActOnOpenMPToClause(VarList, StartLoc, LParenLoc, EndLoc);
1769 }
1770
Samuel Antaoec172c62016-05-26 17:49:04 +00001771 /// \brief Build a new OpenMP 'from' clause.
1772 ///
1773 /// By default, performs semantic analysis to build the new statement.
1774 /// Subclasses may override this routine to provide different behavior.
1775 OMPClause *RebuildOMPFromClause(ArrayRef<Expr *> VarList,
1776 SourceLocation StartLoc,
1777 SourceLocation LParenLoc,
1778 SourceLocation EndLoc) {
1779 return getSema().ActOnOpenMPFromClause(VarList, StartLoc, LParenLoc,
1780 EndLoc);
1781 }
1782
James Dennett2a4d13c2012-06-15 07:13:21 +00001783 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001784 ///
1785 /// By default, performs semantic analysis to build the new statement.
1786 /// Subclasses may override this routine to provide different behavior.
1787 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1788 Expr *object) {
1789 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1790 }
1791
James Dennett2a4d13c2012-06-15 07:13:21 +00001792 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001793 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001794 /// By default, performs semantic analysis to build the new statement.
1795 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001796 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001797 Expr *Object, Stmt *Body) {
1798 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001799 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001800
James Dennett2a4d13c2012-06-15 07:13:21 +00001801 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001802 ///
1803 /// By default, performs semantic analysis to build the new statement.
1804 /// Subclasses may override this routine to provide different behavior.
1805 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1806 Stmt *Body) {
1807 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1808 }
John McCall53848232011-07-27 01:07:15 +00001809
Douglas Gregorf68a5082010-04-22 23:10:45 +00001810 /// \brief Build a new Objective-C fast enumeration statement.
1811 ///
1812 /// By default, performs semantic analysis to build the new statement.
1813 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001814 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001815 Stmt *Element,
1816 Expr *Collection,
1817 SourceLocation RParenLoc,
1818 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001819 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001820 Element,
John McCallb268a282010-08-23 23:25:46 +00001821 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001822 RParenLoc);
1823 if (ForEachStmt.isInvalid())
1824 return StmtError();
1825
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001826 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001827 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001828
Douglas Gregorebe10102009-08-20 07:17:43 +00001829 /// \brief Build a new C++ exception declaration.
1830 ///
1831 /// By default, performs semantic analysis to build the new decaration.
1832 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001833 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001834 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001835 SourceLocation StartLoc,
1836 SourceLocation IdLoc,
1837 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001838 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001839 StartLoc, IdLoc, Id);
1840 if (Var)
1841 getSema().CurContext->addDecl(Var);
1842 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001843 }
1844
1845 /// \brief Build a new C++ catch statement.
1846 ///
1847 /// By default, performs semantic analysis to build the new statement.
1848 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001849 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001850 VarDecl *ExceptionDecl,
1851 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001852 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1853 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001854 }
Mike Stump11289f42009-09-09 15:08:12 +00001855
Douglas Gregorebe10102009-08-20 07:17:43 +00001856 /// \brief Build a new C++ try statement.
1857 ///
1858 /// By default, performs semantic analysis to build the new statement.
1859 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001860 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1861 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001862 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001863 }
Mike Stump11289f42009-09-09 15:08:12 +00001864
Richard Smith02e85f32011-04-14 22:09:26 +00001865 /// \brief Build a new C++0x range-based for statement.
1866 ///
1867 /// By default, performs semantic analysis to build the new statement.
1868 /// Subclasses may override this routine to provide different behavior.
1869 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
Richard Smith9f690bd2015-10-27 06:02:45 +00001870 SourceLocation CoawaitLoc,
Richard Smith02e85f32011-04-14 22:09:26 +00001871 SourceLocation ColonLoc,
Richard Smith01694c32016-03-20 10:33:40 +00001872 Stmt *Range, Stmt *Begin, Stmt *End,
Richard Smith02e85f32011-04-14 22:09:26 +00001873 Expr *Cond, Expr *Inc,
1874 Stmt *LoopVar,
1875 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001876 // If we've just learned that the range is actually an Objective-C
1877 // collection, treat this as an Objective-C fast enumeration loop.
1878 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1879 if (RangeStmt->isSingleDecl()) {
1880 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001881 if (RangeVar->isInvalidDecl())
1882 return StmtError();
1883
Douglas Gregorf7106af2013-04-08 18:40:13 +00001884 Expr *RangeExpr = RangeVar->getInit();
1885 if (!RangeExpr->isTypeDependent() &&
1886 RangeExpr->getType()->isObjCObjectPointerType())
1887 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1888 RParenLoc);
1889 }
1890 }
1891 }
1892
Richard Smithcfd53b42015-10-22 06:13:50 +00001893 return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, ColonLoc,
Richard Smith01694c32016-03-20 10:33:40 +00001894 Range, Begin, End,
Richard Smitha05b3b52012-09-20 21:52:32 +00001895 Cond, Inc, LoopVar, RParenLoc,
1896 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001897 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001898
1899 /// \brief Build a new C++0x range-based for statement.
1900 ///
1901 /// By default, performs semantic analysis to build the new statement.
1902 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001903 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001904 bool IsIfExists,
1905 NestedNameSpecifierLoc QualifierLoc,
1906 DeclarationNameInfo NameInfo,
1907 Stmt *Nested) {
1908 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1909 QualifierLoc, NameInfo, Nested);
1910 }
1911
Richard Smith02e85f32011-04-14 22:09:26 +00001912 /// \brief Attach body to a C++0x range-based for statement.
1913 ///
1914 /// By default, performs semantic analysis to finish the new statement.
1915 /// Subclasses may override this routine to provide different behavior.
1916 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1917 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1918 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001919
David Majnemerfad8f482013-10-15 09:33:02 +00001920 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00001921 Stmt *TryBlock, Stmt *Handler) {
1922 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001923 }
1924
David Majnemerfad8f482013-10-15 09:33:02 +00001925 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001926 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001927 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001928 }
1929
David Majnemerfad8f482013-10-15 09:33:02 +00001930 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
Nico Weberd64657f2015-03-09 02:47:59 +00001931 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001932 }
1933
Alexey Bataevec474782014-10-09 08:45:04 +00001934 /// \brief Build a new predefined expression.
1935 ///
1936 /// By default, performs semantic analysis to build the new expression.
1937 /// Subclasses may override this routine to provide different behavior.
1938 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
1939 PredefinedExpr::IdentType IT) {
1940 return getSema().BuildPredefinedExpr(Loc, IT);
1941 }
1942
Douglas Gregora16548e2009-08-11 05:31:07 +00001943 /// \brief Build a new expression that references a declaration.
1944 ///
1945 /// 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 RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001948 LookupResult &R,
1949 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001950 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1951 }
1952
1953
1954 /// \brief Build a new expression that references a declaration.
1955 ///
1956 /// By default, performs semantic analysis to build the new expression.
1957 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001958 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001959 ValueDecl *VD,
1960 const DeclarationNameInfo &NameInfo,
1961 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001962 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001963 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001964
1965 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001966
1967 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001968 }
Mike Stump11289f42009-09-09 15:08:12 +00001969
Douglas Gregora16548e2009-08-11 05:31:07 +00001970 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001971 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001972 /// By default, performs semantic analysis to build the new expression.
1973 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001974 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001975 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001976 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001977 }
1978
Douglas Gregorad8a3362009-09-04 17:36:40 +00001979 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001980 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001981 /// By default, performs semantic analysis to build the new expression.
1982 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001983 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001984 SourceLocation OperatorLoc,
1985 bool isArrow,
1986 CXXScopeSpec &SS,
1987 TypeSourceInfo *ScopeType,
1988 SourceLocation CCLoc,
1989 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001990 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001991
Douglas Gregora16548e2009-08-11 05:31:07 +00001992 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001993 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001994 /// By default, performs semantic analysis to build the new expression.
1995 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001996 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001997 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001998 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001999 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002000 }
Mike Stump11289f42009-09-09 15:08:12 +00002001
Douglas Gregor882211c2010-04-28 22:16:22 +00002002 /// \brief Build a new builtin offsetof expression.
2003 ///
2004 /// By default, performs semantic analysis to build the new expression.
2005 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002006 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Craig Topperb5518242015-10-22 04:59:59 +00002007 TypeSourceInfo *Type,
2008 ArrayRef<Sema::OffsetOfComponent> Components,
2009 SourceLocation RParenLoc) {
Douglas Gregor882211c2010-04-28 22:16:22 +00002010 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
Craig Topperb5518242015-10-22 04:59:59 +00002011 RParenLoc);
Douglas Gregor882211c2010-04-28 22:16:22 +00002012 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002013
2014 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00002015 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00002016 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002017 /// By default, performs semantic analysis to build the new expression.
2018 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00002019 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
2020 SourceLocation OpLoc,
2021 UnaryExprOrTypeTrait ExprKind,
2022 SourceRange R) {
2023 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00002024 }
2025
Peter Collingbournee190dee2011-03-11 19:24:49 +00002026 /// \brief Build a new sizeof, alignof or vec step expression with an
2027 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00002028 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002029 /// By default, performs semantic analysis to build the new expression.
2030 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00002031 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
2032 UnaryExprOrTypeTrait ExprKind,
2033 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00002034 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00002035 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00002036 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002037 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002038
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002039 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002040 }
Mike Stump11289f42009-09-09 15:08:12 +00002041
Douglas Gregora16548e2009-08-11 05:31:07 +00002042 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00002043 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002044 /// By default, performs semantic analysis to build the new expression.
2045 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002046 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002047 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00002048 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002049 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002050 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00002051 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002052 RBracketLoc);
2053 }
2054
Alexey Bataev1a3320e2015-08-25 14:24:04 +00002055 /// \brief Build a new array section expression.
2056 ///
2057 /// By default, performs semantic analysis to build the new expression.
2058 /// Subclasses may override this routine to provide different behavior.
2059 ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc,
2060 Expr *LowerBound,
2061 SourceLocation ColonLoc, Expr *Length,
2062 SourceLocation RBracketLoc) {
2063 return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound,
2064 ColonLoc, Length, RBracketLoc);
2065 }
2066
Douglas Gregora16548e2009-08-11 05:31:07 +00002067 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00002068 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002069 /// By default, performs semantic analysis to build the new expression.
2070 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002071 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002072 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00002073 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00002074 Expr *ExecConfig = nullptr) {
2075 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002076 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00002077 }
2078
2079 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002080 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002081 /// By default, performs semantic analysis to build the new expression.
2082 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002083 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002084 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00002085 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002086 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002087 const DeclarationNameInfo &MemberNameInfo,
2088 ValueDecl *Member,
2089 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00002090 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00002091 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00002092 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
2093 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00002094 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00002095 // We have a reference to an unnamed field. This is always the
2096 // base of an anonymous struct/union member access, i.e. the
2097 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00002098 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00002099 assert(Member->getType()->isRecordType() &&
2100 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00002101
Richard Smithcab9a7d2011-10-26 19:06:56 +00002102 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002103 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00002104 QualifierLoc.getNestedNameSpecifier(),
2105 FoundDecl, Member);
2106 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002107 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002108 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00002109 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Aaron Ballmanf4cb2be2015-03-24 15:07:53 +00002110 MemberExpr *ME = new (getSema().Context)
2111 MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
2112 cast<FieldDecl>(Member)->getType(), VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002113 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00002114 }
Mike Stump11289f42009-09-09 15:08:12 +00002115
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002116 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00002117 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002118
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002119 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00002120 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00002121
John McCall16df1e52010-03-30 21:47:33 +00002122 // FIXME: this involves duplicating earlier analysis in a lot of
2123 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002124 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00002125 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00002126 R.resolveKind();
2127
John McCallb268a282010-08-23 23:25:46 +00002128 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002129 SS, TemplateKWLoc,
2130 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002131 R, ExplicitTemplateArgs,
2132 /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002133 }
Mike Stump11289f42009-09-09 15:08:12 +00002134
Douglas Gregora16548e2009-08-11 05:31:07 +00002135 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002136 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002137 /// By default, performs semantic analysis to build the new expression.
2138 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002139 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00002140 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00002141 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002142 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002143 }
2144
2145 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002146 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002147 /// By default, performs semantic analysis to build the new expression.
2148 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002149 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00002150 SourceLocation QuestionLoc,
2151 Expr *LHS,
2152 SourceLocation ColonLoc,
2153 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00002154 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
2155 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002156 }
2157
Douglas Gregora16548e2009-08-11 05:31:07 +00002158 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00002159 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002160 /// By default, performs semantic analysis to build the new expression.
2161 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002162 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00002163 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002164 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002165 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00002166 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002167 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002168 }
Mike Stump11289f42009-09-09 15:08:12 +00002169
Douglas Gregora16548e2009-08-11 05:31:07 +00002170 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00002171 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002172 /// By default, performs semantic analysis to build the new expression.
2173 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002174 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00002175 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002176 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002177 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00002178 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002179 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002180 }
Mike Stump11289f42009-09-09 15:08:12 +00002181
Douglas Gregora16548e2009-08-11 05:31:07 +00002182 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002183 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002184 /// By default, performs semantic analysis to build the new expression.
2185 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002186 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00002187 SourceLocation OpLoc,
2188 SourceLocation AccessorLoc,
2189 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00002190
John McCall10eae182009-11-30 22:42:35 +00002191 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002192 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00002193 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00002194 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002195 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002196 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002197 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002198 /* TemplateArgs */ nullptr,
2199 /*S*/ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002200 }
Mike Stump11289f42009-09-09 15:08:12 +00002201
Douglas Gregora16548e2009-08-11 05:31:07 +00002202 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00002203 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002204 /// By default, performs semantic analysis to build the new expression.
2205 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002206 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00002207 MultiExprArg Inits,
2208 SourceLocation RBraceLoc,
2209 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00002210 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002211 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00002212 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002213 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002214
Douglas Gregord3d93062009-11-09 17:16:50 +00002215 // Patch in the result type we were given, which may have been computed
2216 // when the initial InitListExpr was built.
2217 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
2218 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002219 return Result;
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 designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00002223 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002224 /// By default, performs semantic analysis to build the new expression.
2225 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002226 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00002227 MultiExprArg ArrayExprs,
2228 SourceLocation EqualOrColonLoc,
2229 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002230 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00002231 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00002232 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002233 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002234 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002235 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002236
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002237 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002238 }
Mike Stump11289f42009-09-09 15:08:12 +00002239
Douglas Gregora16548e2009-08-11 05:31:07 +00002240 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00002241 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002242 /// By default, builds the implicit value initialization without performing
2243 /// any semantic analysis. Subclasses may override this routine to provide
2244 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002245 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002246 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00002247 }
Mike Stump11289f42009-09-09 15:08:12 +00002248
Douglas Gregora16548e2009-08-11 05:31:07 +00002249 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00002250 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002251 /// By default, performs semantic analysis to build the new expression.
2252 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002253 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002254 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002255 SourceLocation RParenLoc) {
2256 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002257 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002258 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002259 }
2260
2261 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002262 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002263 /// By default, performs semantic analysis to build the new expression.
2264 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002265 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00002266 MultiExprArg SubExprs,
2267 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002268 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002269 }
Mike Stump11289f42009-09-09 15:08:12 +00002270
Douglas Gregora16548e2009-08-11 05:31:07 +00002271 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00002272 ///
2273 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002274 /// rather than attempting to map the label statement itself.
2275 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002276 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002277 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002278 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002279 }
Mike Stump11289f42009-09-09 15:08:12 +00002280
Douglas Gregora16548e2009-08-11 05:31:07 +00002281 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002282 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002283 /// By default, performs semantic analysis to build the new expression.
2284 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002285 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002286 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002287 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002288 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002289 }
Mike Stump11289f42009-09-09 15:08:12 +00002290
Douglas Gregora16548e2009-08-11 05:31:07 +00002291 /// \brief Build a new __builtin_choose_expr expression.
2292 ///
2293 /// By default, performs semantic analysis to build the new expression.
2294 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002295 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002296 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002297 SourceLocation RParenLoc) {
2298 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002299 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002300 RParenLoc);
2301 }
Mike Stump11289f42009-09-09 15:08:12 +00002302
Peter Collingbourne91147592011-04-15 00:35:48 +00002303 /// \brief Build a new generic selection expression.
2304 ///
2305 /// By default, performs semantic analysis to build the new expression.
2306 /// Subclasses may override this routine to provide different behavior.
2307 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2308 SourceLocation DefaultLoc,
2309 SourceLocation RParenLoc,
2310 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002311 ArrayRef<TypeSourceInfo *> Types,
2312 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002313 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002314 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002315 }
2316
Douglas Gregora16548e2009-08-11 05:31:07 +00002317 /// \brief Build a new overloaded operator call expression.
2318 ///
2319 /// By default, performs semantic analysis to build the new expression.
2320 /// The semantic analysis provides the behavior of template instantiation,
2321 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002322 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002323 /// argument-dependent lookup, etc. Subclasses may override this routine to
2324 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002325 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002326 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002327 Expr *Callee,
2328 Expr *First,
2329 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002330
2331 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002332 /// reinterpret_cast.
2333 ///
2334 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002335 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002336 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002337 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002338 Stmt::StmtClass Class,
2339 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002340 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002341 SourceLocation RAngleLoc,
2342 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002343 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002344 SourceLocation RParenLoc) {
2345 switch (Class) {
2346 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002347 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002348 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002349 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002350
2351 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002352 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002353 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002354 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002355
Douglas Gregora16548e2009-08-11 05:31:07 +00002356 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002357 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002358 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002359 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002360 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002361
Douglas Gregora16548e2009-08-11 05:31:07 +00002362 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002363 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002364 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002365 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002366
Douglas Gregora16548e2009-08-11 05:31:07 +00002367 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002368 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002369 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002370 }
Mike Stump11289f42009-09-09 15:08:12 +00002371
Douglas Gregora16548e2009-08-11 05:31:07 +00002372 /// \brief Build a new C++ static_cast expression.
2373 ///
2374 /// By default, performs semantic analysis to build the new expression.
2375 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002376 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002377 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002378 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002379 SourceLocation RAngleLoc,
2380 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002381 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002382 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002383 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002384 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002385 SourceRange(LAngleLoc, RAngleLoc),
2386 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002387 }
2388
2389 /// \brief Build a new C++ dynamic_cast expression.
2390 ///
2391 /// By default, performs semantic analysis to build the new expression.
2392 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002393 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002394 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002395 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002396 SourceLocation RAngleLoc,
2397 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002398 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002399 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002400 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002401 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002402 SourceRange(LAngleLoc, RAngleLoc),
2403 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002404 }
2405
2406 /// \brief Build a new C++ reinterpret_cast expression.
2407 ///
2408 /// By default, performs semantic analysis to build the new expression.
2409 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002410 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002411 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002412 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002413 SourceLocation RAngleLoc,
2414 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002415 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002416 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002417 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002418 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002419 SourceRange(LAngleLoc, RAngleLoc),
2420 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002421 }
2422
2423 /// \brief Build a new C++ const_cast expression.
2424 ///
2425 /// By default, performs semantic analysis to build the new expression.
2426 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002427 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002428 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002429 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002430 SourceLocation RAngleLoc,
2431 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002432 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002433 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002434 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002435 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002436 SourceRange(LAngleLoc, RAngleLoc),
2437 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002438 }
Mike Stump11289f42009-09-09 15:08:12 +00002439
Douglas Gregora16548e2009-08-11 05:31:07 +00002440 /// \brief Build a new C++ functional-style cast expression.
2441 ///
2442 /// By default, performs semantic analysis to build the new expression.
2443 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002444 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2445 SourceLocation LParenLoc,
2446 Expr *Sub,
2447 SourceLocation RParenLoc) {
2448 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002449 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002450 RParenLoc);
2451 }
Mike Stump11289f42009-09-09 15:08:12 +00002452
Douglas Gregora16548e2009-08-11 05:31:07 +00002453 /// \brief Build a new C++ typeid(type) expression.
2454 ///
2455 /// By default, performs semantic analysis to build the new expression.
2456 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002457 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002458 SourceLocation TypeidLoc,
2459 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002460 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002461 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002462 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002463 }
Mike Stump11289f42009-09-09 15:08:12 +00002464
Francois Pichet9f4f2072010-09-08 12:20:18 +00002465
Douglas Gregora16548e2009-08-11 05:31:07 +00002466 /// \brief Build a new C++ typeid(expr) expression.
2467 ///
2468 /// By default, performs semantic analysis to build the new expression.
2469 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002470 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002471 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002472 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002473 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002474 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002475 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002476 }
2477
Francois Pichet9f4f2072010-09-08 12:20:18 +00002478 /// \brief Build a new C++ __uuidof(type) expression.
2479 ///
2480 /// By default, performs semantic analysis to build the new expression.
2481 /// Subclasses may override this routine to provide different behavior.
2482 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2483 SourceLocation TypeidLoc,
2484 TypeSourceInfo *Operand,
2485 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002486 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002487 RParenLoc);
2488 }
2489
2490 /// \brief Build a new C++ __uuidof(expr) expression.
2491 ///
2492 /// By default, performs semantic analysis to build the new expression.
2493 /// Subclasses may override this routine to provide different behavior.
2494 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2495 SourceLocation TypeidLoc,
2496 Expr *Operand,
2497 SourceLocation RParenLoc) {
2498 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2499 RParenLoc);
2500 }
2501
Douglas Gregora16548e2009-08-11 05:31:07 +00002502 /// \brief Build a new C++ "this" expression.
2503 ///
2504 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002505 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002506 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002507 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002508 QualType ThisType,
2509 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002510 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002511 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002512 }
2513
2514 /// \brief Build a new C++ throw expression.
2515 ///
2516 /// By default, performs semantic analysis to build the new expression.
2517 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002518 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2519 bool IsThrownVariableInScope) {
2520 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002521 }
2522
2523 /// \brief Build a new C++ default-argument expression.
2524 ///
2525 /// By default, builds a new default-argument expression, which does not
2526 /// require any semantic analysis. Subclasses may override this routine to
2527 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002528 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002529 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002530 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002531 }
2532
Richard Smith852c9db2013-04-20 22:23:05 +00002533 /// \brief Build a new C++11 default-initialization expression.
2534 ///
2535 /// By default, builds a new default field initialization expression, which
2536 /// does not require any semantic analysis. Subclasses may override this
2537 /// routine to provide different behavior.
2538 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2539 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002540 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002541 }
2542
Douglas Gregora16548e2009-08-11 05:31:07 +00002543 /// \brief Build a new C++ zero-initialization expression.
2544 ///
2545 /// By default, performs semantic analysis to build the new expression.
2546 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002547 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2548 SourceLocation LParenLoc,
2549 SourceLocation RParenLoc) {
2550 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002551 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002552 }
Mike Stump11289f42009-09-09 15:08:12 +00002553
Douglas Gregora16548e2009-08-11 05:31:07 +00002554 /// \brief Build a new C++ "new" expression.
2555 ///
2556 /// By default, performs semantic analysis to build the new expression.
2557 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002558 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002559 bool UseGlobal,
2560 SourceLocation PlacementLParen,
2561 MultiExprArg PlacementArgs,
2562 SourceLocation PlacementRParen,
2563 SourceRange TypeIdParens,
2564 QualType AllocatedType,
2565 TypeSourceInfo *AllocatedTypeInfo,
2566 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002567 SourceRange DirectInitRange,
2568 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002569 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002570 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002571 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002572 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002573 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002574 AllocatedType,
2575 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002576 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002577 DirectInitRange,
2578 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002579 }
Mike Stump11289f42009-09-09 15:08:12 +00002580
Douglas Gregora16548e2009-08-11 05:31:07 +00002581 /// \brief Build a new C++ "delete" expression.
2582 ///
2583 /// By default, performs semantic analysis to build the new expression.
2584 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002585 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002586 bool IsGlobalDelete,
2587 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002588 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002589 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002590 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002591 }
Mike Stump11289f42009-09-09 15:08:12 +00002592
Douglas Gregor29c42f22012-02-24 07:38:34 +00002593 /// \brief Build a new type trait expression.
2594 ///
2595 /// By default, performs semantic analysis to build the new expression.
2596 /// Subclasses may override this routine to provide different behavior.
2597 ExprResult RebuildTypeTrait(TypeTrait Trait,
2598 SourceLocation StartLoc,
2599 ArrayRef<TypeSourceInfo *> Args,
2600 SourceLocation RParenLoc) {
2601 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2602 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002603
John Wiegley6242b6a2011-04-28 00:16:57 +00002604 /// \brief Build a new array type trait expression.
2605 ///
2606 /// By default, performs semantic analysis to build the new expression.
2607 /// Subclasses may override this routine to provide different behavior.
2608 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2609 SourceLocation StartLoc,
2610 TypeSourceInfo *TSInfo,
2611 Expr *DimExpr,
2612 SourceLocation RParenLoc) {
2613 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2614 }
2615
John Wiegleyf9f65842011-04-25 06:54:41 +00002616 /// \brief Build a new expression trait expression.
2617 ///
2618 /// By default, performs semantic analysis to build the new expression.
2619 /// Subclasses may override this routine to provide different behavior.
2620 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2621 SourceLocation StartLoc,
2622 Expr *Queried,
2623 SourceLocation RParenLoc) {
2624 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2625 }
2626
Mike Stump11289f42009-09-09 15:08:12 +00002627 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002628 /// expression.
2629 ///
2630 /// By default, performs semantic analysis to build the new expression.
2631 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002632 ExprResult RebuildDependentScopeDeclRefExpr(
2633 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002634 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002635 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002636 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002637 bool IsAddressOfOperand,
2638 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002639 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002640 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002641
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002642 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002643 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2644 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002645
Reid Kleckner32506ed2014-06-12 23:03:48 +00002646 return getSema().BuildQualifiedDeclarationNameExpr(
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002647 SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002648 }
2649
2650 /// \brief Build a new template-id expression.
2651 ///
2652 /// By default, performs semantic analysis to build the new expression.
2653 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002654 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002655 SourceLocation TemplateKWLoc,
2656 LookupResult &R,
2657 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002658 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002659 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2660 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002661 }
2662
2663 /// \brief Build a new object-construction expression.
2664 ///
2665 /// By default, performs semantic analysis to build the new expression.
2666 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002667 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002668 SourceLocation Loc,
2669 CXXConstructorDecl *Constructor,
2670 bool IsElidable,
2671 MultiExprArg Args,
2672 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002673 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002674 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002675 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002676 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002677 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002678 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002679 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002680 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002681 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002682
Richard Smithc83bf822016-06-10 00:58:19 +00002683 return getSema().BuildCXXConstructExpr(Loc, T, Constructor,
Richard Smithc2bebe92016-05-11 20:37:46 +00002684 IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002685 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002686 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002687 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002688 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002689 RequiresZeroInit, ConstructKind,
2690 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002691 }
2692
2693 /// \brief Build a new object-construction expression.
2694 ///
2695 /// By default, performs semantic analysis to build the new expression.
2696 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002697 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2698 SourceLocation LParenLoc,
2699 MultiExprArg Args,
2700 SourceLocation RParenLoc) {
2701 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002702 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002703 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002704 RParenLoc);
2705 }
2706
2707 /// \brief Build a new object-construction expression.
2708 ///
2709 /// By default, performs semantic analysis to build the new expression.
2710 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002711 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2712 SourceLocation LParenLoc,
2713 MultiExprArg Args,
2714 SourceLocation RParenLoc) {
2715 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002716 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002717 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002718 RParenLoc);
2719 }
Mike Stump11289f42009-09-09 15:08:12 +00002720
Douglas Gregora16548e2009-08-11 05:31:07 +00002721 /// \brief Build a new member reference expression.
2722 ///
2723 /// By default, performs semantic analysis to build the new expression.
2724 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002725 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002726 QualType BaseType,
2727 bool IsArrow,
2728 SourceLocation OperatorLoc,
2729 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002730 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002731 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002732 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002733 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002734 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002735 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002736
John McCallb268a282010-08-23 23:25:46 +00002737 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002738 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002739 SS, TemplateKWLoc,
2740 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002741 MemberNameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002742 TemplateArgs, /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002743 }
2744
John McCall10eae182009-11-30 22:42:35 +00002745 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002746 ///
2747 /// By default, performs semantic analysis to build the new expression.
2748 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002749 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2750 SourceLocation OperatorLoc,
2751 bool IsArrow,
2752 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002753 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002754 NamedDecl *FirstQualifierInScope,
2755 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002756 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002757 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002758 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002759
John McCallb268a282010-08-23 23:25:46 +00002760 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002761 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002762 SS, TemplateKWLoc,
2763 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002764 R, TemplateArgs, /*S*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00002765 }
Mike Stump11289f42009-09-09 15:08:12 +00002766
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002767 /// \brief Build a new noexcept expression.
2768 ///
2769 /// By default, performs semantic analysis to build the new expression.
2770 /// Subclasses may override this routine to provide different behavior.
2771 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2772 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2773 }
2774
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002775 /// \brief Build a new expression to compute the length of a parameter pack.
Richard Smithd784e682015-09-23 21:41:42 +00002776 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc,
2777 NamedDecl *Pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00002778 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002779 SourceLocation RParenLoc,
Richard Smithd784e682015-09-23 21:41:42 +00002780 Optional<unsigned> Length,
2781 ArrayRef<TemplateArgument> PartialArgs) {
2782 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
2783 RParenLoc, Length, PartialArgs);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002784 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002785
Patrick Beard0caa3942012-04-19 00:25:12 +00002786 /// \brief Build a new Objective-C boxed expression.
2787 ///
2788 /// By default, performs semantic analysis to build the new expression.
2789 /// Subclasses may override this routine to provide different behavior.
2790 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2791 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2792 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002793
Ted Kremeneke65b0862012-03-06 20:05:56 +00002794 /// \brief Build a new Objective-C array literal.
2795 ///
2796 /// By default, performs semantic analysis to build the new expression.
2797 /// Subclasses may override this routine to provide different behavior.
2798 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2799 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002800 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002801 MultiExprArg(Elements, NumElements));
2802 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002803
2804 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002805 Expr *Base, Expr *Key,
2806 ObjCMethodDecl *getterMethod,
2807 ObjCMethodDecl *setterMethod) {
2808 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2809 getterMethod, setterMethod);
2810 }
2811
2812 /// \brief Build a new Objective-C dictionary literal.
2813 ///
2814 /// By default, performs semantic analysis to build the new expression.
2815 /// Subclasses may override this routine to provide different behavior.
2816 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
Craig Topperd4336e02015-12-24 23:58:15 +00002817 MutableArrayRef<ObjCDictionaryElement> Elements) {
2818 return getSema().BuildObjCDictionaryLiteral(Range, Elements);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002819 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002820
James Dennett2a4d13c2012-06-15 07:13:21 +00002821 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002822 ///
2823 /// By default, performs semantic analysis to build the new expression.
2824 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002825 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002826 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002827 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002828 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002829 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002830
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002831 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002832 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002833 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002834 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002835 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002836 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002837 MultiExprArg Args,
2838 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002839 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2840 ReceiverTypeInfo->getType(),
2841 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002842 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002843 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002844 }
2845
2846 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002847 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002848 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002849 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002850 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002851 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002852 MultiExprArg Args,
2853 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002854 return SemaRef.BuildInstanceMessage(Receiver,
2855 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002856 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002857 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002858 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002859 }
2860
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002861 /// \brief Build a new Objective-C instance/class message to 'super'.
2862 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
2863 Selector Sel,
2864 ArrayRef<SourceLocation> SelectorLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002865 QualType SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002866 ObjCMethodDecl *Method,
2867 SourceLocation LBracLoc,
2868 MultiExprArg Args,
2869 SourceLocation RBracLoc) {
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002870 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002871 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002872 SuperLoc,
2873 Sel, Method, LBracLoc, SelectorLocs,
2874 RBracLoc, Args)
2875 : SemaRef.BuildClassMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002876 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002877 SuperLoc,
2878 Sel, Method, LBracLoc, SelectorLocs,
2879 RBracLoc, Args);
2880
2881
2882 }
2883
Douglas Gregord51d90d2010-04-26 20:11:03 +00002884 /// \brief Build a new Objective-C ivar reference expression.
2885 ///
2886 /// By default, performs semantic analysis to build the new expression.
2887 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002888 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002889 SourceLocation IvarLoc,
2890 bool IsArrow, bool IsFreeIvar) {
2891 // FIXME: We lose track of the IsFreeIvar bit.
2892 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002893 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2894 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002895 /*FIXME:*/IvarLoc, IsArrow,
2896 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002897 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002898 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002899 /*TemplateArgs=*/nullptr,
2900 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002901 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002902
2903 /// \brief Build a new Objective-C property reference expression.
2904 ///
2905 /// By default, performs semantic analysis to build the new expression.
2906 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002907 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002908 ObjCPropertyDecl *Property,
2909 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002910 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002911 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2912 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2913 /*FIXME:*/PropertyLoc,
2914 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002915 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002916 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002917 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002918 /*TemplateArgs=*/nullptr,
2919 /*S=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002920 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002921
John McCallb7bd14f2010-12-02 01:19:52 +00002922 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002923 ///
2924 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002925 /// Subclasses may override this routine to provide different behavior.
2926 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2927 ObjCMethodDecl *Getter,
2928 ObjCMethodDecl *Setter,
2929 SourceLocation PropertyLoc) {
2930 // Since these expressions can only be value-dependent, we do not
2931 // need to perform semantic analysis again.
2932 return Owned(
2933 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2934 VK_LValue, OK_ObjCProperty,
2935 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002936 }
2937
Douglas Gregord51d90d2010-04-26 20:11:03 +00002938 /// \brief Build a new Objective-C "isa" expression.
2939 ///
2940 /// By default, performs semantic analysis to build the new expression.
2941 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002942 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00002943 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00002944 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002945 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2946 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002947 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002948 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002949 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002950 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002951 /*TemplateArgs=*/nullptr,
2952 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002953 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002954
Douglas Gregora16548e2009-08-11 05:31:07 +00002955 /// \brief Build a new shuffle vector expression.
2956 ///
2957 /// By default, performs semantic analysis to build the new expression.
2958 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002959 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002960 MultiExprArg SubExprs,
2961 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002962 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002963 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002964 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2965 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2966 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002967 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002968
Douglas Gregora16548e2009-08-11 05:31:07 +00002969 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002970 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002971 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2972 SemaRef.Context.BuiltinFnTy,
2973 VK_RValue, BuiltinLoc);
2974 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2975 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002976 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00002977
2978 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002979 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00002980 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002981 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002982
Douglas Gregora16548e2009-08-11 05:31:07 +00002983 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002984 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002985 }
John McCall31f82722010-11-12 08:19:04 +00002986
Hal Finkelc4d7c822013-09-18 03:29:45 +00002987 /// \brief Build a new convert vector expression.
2988 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2989 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2990 SourceLocation RParenLoc) {
2991 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2992 BuiltinLoc, RParenLoc);
2993 }
2994
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002995 /// \brief Build a new template argument pack expansion.
2996 ///
2997 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002998 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002999 /// different behavior.
3000 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003001 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00003002 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003003 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00003004 case TemplateArgument::Expression: {
3005 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00003006 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
3007 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00003008 if (Result.isInvalid())
3009 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003010
Douglas Gregor98318c22011-01-03 21:37:45 +00003011 return TemplateArgumentLoc(Result.get(), Result.get());
3012 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003013
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003014 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003015 return TemplateArgumentLoc(TemplateArgument(
3016 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00003017 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00003018 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003019 Pattern.getTemplateNameLoc(),
3020 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003021
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003022 case TemplateArgument::Null:
3023 case TemplateArgument::Integral:
3024 case TemplateArgument::Declaration:
3025 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003026 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00003027 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003028 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00003029
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003030 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00003031 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003032 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003033 EllipsisLoc,
3034 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003035 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
3036 Expansion);
3037 break;
3038 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003039
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003040 return TemplateArgumentLoc();
3041 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003042
Douglas Gregor968f23a2011-01-03 19:31:53 +00003043 /// \brief Build a new expression pack expansion.
3044 ///
3045 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00003046 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00003047 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00003048 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00003049 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00003050 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003051 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003052
Richard Smith0f0af192014-11-08 05:07:16 +00003053 /// \brief Build a new C++1z fold-expression.
3054 ///
3055 /// By default, performs semantic analysis in order to build a new fold
3056 /// expression.
3057 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
3058 BinaryOperatorKind Operator,
3059 SourceLocation EllipsisLoc, Expr *RHS,
3060 SourceLocation RParenLoc) {
3061 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
3062 RHS, RParenLoc);
3063 }
3064
3065 /// \brief Build an empty C++1z fold-expression with the given operator.
3066 ///
3067 /// By default, produces the fallback value for the fold-expression, or
3068 /// produce an error if there is no fallback value.
3069 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
3070 BinaryOperatorKind Operator) {
3071 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
3072 }
3073
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003074 /// \brief Build a new atomic operation expression.
3075 ///
3076 /// By default, performs semantic analysis to build the new expression.
3077 /// Subclasses may override this routine to provide different behavior.
3078 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
3079 MultiExprArg SubExprs,
3080 QualType RetTy,
3081 AtomicExpr::AtomicOp Op,
3082 SourceLocation RParenLoc) {
3083 // Just create the expression; there is not any interesting semantic
3084 // analysis here because we can't actually build an AtomicExpr until
3085 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00003086 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003087 RParenLoc);
3088 }
3089
John McCall31f82722010-11-12 08:19:04 +00003090private:
Douglas Gregor14454802011-02-25 02:25:35 +00003091 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
3092 QualType ObjectType,
3093 NamedDecl *FirstQualifierInScope,
3094 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003095
3096 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3097 QualType ObjectType,
3098 NamedDecl *FirstQualifierInScope,
3099 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003100
3101 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
3102 NamedDecl *FirstQualifierInScope,
3103 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003104};
Douglas Gregora16548e2009-08-11 05:31:07 +00003105
Douglas Gregorebe10102009-08-20 07:17:43 +00003106template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003107StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003108 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003109 return S;
Mike Stump11289f42009-09-09 15:08:12 +00003110
Douglas Gregorebe10102009-08-20 07:17:43 +00003111 switch (S->getStmtClass()) {
3112 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00003113
Douglas Gregorebe10102009-08-20 07:17:43 +00003114 // Transform individual statement nodes
3115#define STMT(Node, Parent) \
3116 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00003117#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00003118#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00003119#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003120
Douglas Gregorebe10102009-08-20 07:17:43 +00003121 // Transform expressions by calling TransformExpr.
3122#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00003123#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00003124#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00003125#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00003126 {
John McCalldadc5752010-08-24 06:29:42 +00003127 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00003128 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003129 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003130
Richard Smith945f8d32013-01-14 22:39:08 +00003131 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00003132 }
Mike Stump11289f42009-09-09 15:08:12 +00003133 }
3134
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003135 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00003136}
Mike Stump11289f42009-09-09 15:08:12 +00003137
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00003138template<typename Derived>
3139OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
3140 if (!S)
3141 return S;
3142
3143 switch (S->getClauseKind()) {
3144 default: break;
3145 // Transform individual clause nodes
3146#define OPENMP_CLAUSE(Name, Class) \
3147 case OMPC_ ## Name : \
3148 return getDerived().Transform ## Class(cast<Class>(S));
3149#include "clang/Basic/OpenMPKinds.def"
3150 }
3151
3152 return S;
3153}
3154
Mike Stump11289f42009-09-09 15:08:12 +00003155
Douglas Gregore922c772009-08-04 22:27:00 +00003156template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003157ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003158 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003159 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00003160
3161 switch (E->getStmtClass()) {
3162 case Stmt::NoStmtClass: break;
3163#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00003164#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00003165#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00003166 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00003167#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003168 }
3169
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003170 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00003171}
3172
3173template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00003174ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00003175 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00003176 // Initializers are instantiated like expressions, except that various outer
3177 // layers are stripped.
3178 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003179 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00003180
3181 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
3182 Init = ExprTemp->getSubExpr();
3183
Richard Smithe6ca4752013-05-30 22:40:16 +00003184 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
3185 Init = MTE->GetTemporaryExpr();
3186
Richard Smithd59b8322012-12-19 01:39:02 +00003187 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
3188 Init = Binder->getSubExpr();
3189
3190 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
3191 Init = ICE->getSubExprAsWritten();
3192
Richard Smithcc1b96d2013-06-12 22:31:48 +00003193 if (CXXStdInitializerListExpr *ILE =
3194 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00003195 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00003196
Richard Smithc6abd962014-07-25 01:12:44 +00003197 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00003198 // InitListExprs. Other forms of copy-initialization will be a no-op if
3199 // the initializer is already the right type.
3200 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00003201 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00003202 return getDerived().TransformExpr(Init);
3203
3204 // Revert value-initialization back to empty parens.
3205 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
3206 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003207 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003208 Parens.getEnd());
3209 }
3210
3211 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3212 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003213 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003214 SourceLocation());
3215
3216 // Revert initialization by constructor back to a parenthesized or braced list
3217 // of expressions. Any other form of initializer can just be reused directly.
3218 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00003219 return getDerived().TransformExpr(Init);
3220
Richard Smithf8adcdc2014-07-17 05:12:35 +00003221 // If the initialization implicitly converted an initializer list to a
3222 // std::initializer_list object, unwrap the std::initializer_list too.
3223 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00003224 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00003225
Richard Smithd59b8322012-12-19 01:39:02 +00003226 SmallVector<Expr*, 8> NewArgs;
3227 bool ArgChanged = false;
3228 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00003229 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00003230 return ExprError();
3231
3232 // If this was list initialization, revert to list form.
3233 if (Construct->isListInitialization())
3234 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
3235 Construct->getLocEnd(),
3236 Construct->getType());
3237
Richard Smithd59b8322012-12-19 01:39:02 +00003238 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00003239 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00003240 if (Parens.isInvalid()) {
3241 // This was a variable declaration's initialization for which no initializer
3242 // was specified.
3243 assert(NewArgs.empty() &&
3244 "no parens or braces but have direct init with arguments?");
3245 return ExprEmpty();
3246 }
Richard Smithd59b8322012-12-19 01:39:02 +00003247 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3248 Parens.getEnd());
3249}
3250
3251template<typename Derived>
Craig Topper99d23532015-12-24 23:58:29 +00003252bool TreeTransform<Derived>::TransformExprs(Expr *const *Inputs,
Chad Rosier1dcde962012-08-08 18:46:20 +00003253 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003254 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003255 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003256 bool *ArgChanged) {
3257 for (unsigned I = 0; I != NumInputs; ++I) {
3258 // If requested, drop call arguments that need to be dropped.
3259 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3260 if (ArgChanged)
3261 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003262
Douglas Gregora3efea12011-01-03 19:04:46 +00003263 break;
3264 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003265
Douglas Gregor968f23a2011-01-03 19:31:53 +00003266 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3267 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00003268
Chris Lattner01cf8db2011-07-20 06:58:45 +00003269 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003270 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3271 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003272
Douglas Gregor968f23a2011-01-03 19:31:53 +00003273 // Determine whether the set of unexpanded parameter packs can and should
3274 // be expanded.
3275 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003276 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003277 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3278 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003279 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3280 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003281 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003282 Expand, RetainExpansion,
3283 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00003284 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003285
Douglas Gregor968f23a2011-01-03 19:31:53 +00003286 if (!Expand) {
3287 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003288 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00003289 // expansion.
3290 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3291 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3292 if (OutPattern.isInvalid())
3293 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003294
3295 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00003296 Expansion->getEllipsisLoc(),
3297 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003298 if (Out.isInvalid())
3299 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003300
Douglas Gregor968f23a2011-01-03 19:31:53 +00003301 if (ArgChanged)
3302 *ArgChanged = true;
3303 Outputs.push_back(Out.get());
3304 continue;
3305 }
John McCall542e7c62011-07-06 07:30:07 +00003306
3307 // Record right away that the argument was changed. This needs
3308 // to happen even if the array expands to nothing.
3309 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003310
Douglas Gregor968f23a2011-01-03 19:31:53 +00003311 // The transform has determined that we should perform an elementwise
3312 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003313 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00003314 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3315 ExprResult Out = getDerived().TransformExpr(Pattern);
3316 if (Out.isInvalid())
3317 return true;
3318
Richard Smith9467be42014-06-06 17:33:35 +00003319 // FIXME: Can this happen? We should not try to expand the pack
3320 // in this case.
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003321 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003322 Out = getDerived().RebuildPackExpansion(
3323 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003324 if (Out.isInvalid())
3325 return true;
3326 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003327
Douglas Gregor968f23a2011-01-03 19:31:53 +00003328 Outputs.push_back(Out.get());
3329 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003330
Richard Smith9467be42014-06-06 17:33:35 +00003331 // If we're supposed to retain a pack expansion, do so by temporarily
3332 // forgetting the partially-substituted parameter pack.
3333 if (RetainExpansion) {
3334 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3335
3336 ExprResult Out = getDerived().TransformExpr(Pattern);
3337 if (Out.isInvalid())
3338 return true;
3339
3340 Out = getDerived().RebuildPackExpansion(
3341 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3342 if (Out.isInvalid())
3343 return true;
3344
3345 Outputs.push_back(Out.get());
3346 }
3347
Douglas Gregor968f23a2011-01-03 19:31:53 +00003348 continue;
3349 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003350
Richard Smithd59b8322012-12-19 01:39:02 +00003351 ExprResult Result =
3352 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3353 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003354 if (Result.isInvalid())
3355 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003356
Douglas Gregora3efea12011-01-03 19:04:46 +00003357 if (Result.get() != Inputs[I] && ArgChanged)
3358 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003359
3360 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003361 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003362
Douglas Gregora3efea12011-01-03 19:04:46 +00003363 return false;
3364}
3365
Richard Smith03a4aa32016-06-23 19:02:52 +00003366template <typename Derived>
3367Sema::ConditionResult TreeTransform<Derived>::TransformCondition(
3368 SourceLocation Loc, VarDecl *Var, Expr *Expr, Sema::ConditionKind Kind) {
3369 if (Var) {
3370 VarDecl *ConditionVar = cast_or_null<VarDecl>(
3371 getDerived().TransformDefinition(Var->getLocation(), Var));
3372
3373 if (!ConditionVar)
3374 return Sema::ConditionError();
3375
3376 return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
3377 }
3378
3379 if (Expr) {
3380 ExprResult CondExpr = getDerived().TransformExpr(Expr);
3381
3382 if (CondExpr.isInvalid())
3383 return Sema::ConditionError();
3384
3385 return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind);
3386 }
3387
3388 return Sema::ConditionResult();
3389}
3390
Douglas Gregora3efea12011-01-03 19:04:46 +00003391template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003392NestedNameSpecifierLoc
3393TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3394 NestedNameSpecifierLoc NNS,
3395 QualType ObjectType,
3396 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003397 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003398 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003399 Qualifier = Qualifier.getPrefix())
3400 Qualifiers.push_back(Qualifier);
3401
3402 CXXScopeSpec SS;
3403 while (!Qualifiers.empty()) {
3404 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3405 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003406
Douglas Gregor14454802011-02-25 02:25:35 +00003407 switch (QNNS->getKind()) {
3408 case NestedNameSpecifier::Identifier:
Craig Topperc3ec1492014-05-26 06:22:03 +00003409 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
Douglas Gregor14454802011-02-25 02:25:35 +00003410 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003411 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003412 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003413 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00003414 FirstQualifierInScope, false))
3415 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003416
Douglas Gregor14454802011-02-25 02:25:35 +00003417 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003418
Douglas Gregor14454802011-02-25 02:25:35 +00003419 case NestedNameSpecifier::Namespace: {
3420 NamespaceDecl *NS
3421 = cast_or_null<NamespaceDecl>(
3422 getDerived().TransformDecl(
3423 Q.getLocalBeginLoc(),
3424 QNNS->getAsNamespace()));
3425 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3426 break;
3427 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003428
Douglas Gregor14454802011-02-25 02:25:35 +00003429 case NestedNameSpecifier::NamespaceAlias: {
3430 NamespaceAliasDecl *Alias
3431 = cast_or_null<NamespaceAliasDecl>(
3432 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3433 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003434 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003435 Q.getLocalEndLoc());
3436 break;
3437 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003438
Douglas Gregor14454802011-02-25 02:25:35 +00003439 case NestedNameSpecifier::Global:
3440 // There is no meaningful transformation that one could perform on the
3441 // global scope.
3442 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3443 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003444
Nikola Smiljanic67860242014-09-26 00:28:20 +00003445 case NestedNameSpecifier::Super: {
3446 CXXRecordDecl *RD =
3447 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3448 SourceLocation(), QNNS->getAsRecordDecl()));
3449 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3450 break;
3451 }
3452
Douglas Gregor14454802011-02-25 02:25:35 +00003453 case NestedNameSpecifier::TypeSpecWithTemplate:
3454 case NestedNameSpecifier::TypeSpec: {
3455 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3456 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003457
Douglas Gregor14454802011-02-25 02:25:35 +00003458 if (!TL)
3459 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003460
Douglas Gregor14454802011-02-25 02:25:35 +00003461 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003462 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003463 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003464 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003465 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003466 if (TL.getType()->isEnumeralType())
3467 SemaRef.Diag(TL.getBeginLoc(),
3468 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003469 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3470 Q.getLocalEndLoc());
3471 break;
3472 }
Richard Trieude756fb2011-05-07 01:36:37 +00003473 // If the nested-name-specifier is an invalid type def, don't emit an
3474 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003475 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3476 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003477 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003478 << TL.getType() << SS.getRange();
3479 }
Douglas Gregor14454802011-02-25 02:25:35 +00003480 return NestedNameSpecifierLoc();
3481 }
Douglas Gregore16af532011-02-28 18:50:33 +00003482 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003483
Douglas Gregore16af532011-02-28 18:50:33 +00003484 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003485 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003486 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003487 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003488
Douglas Gregor14454802011-02-25 02:25:35 +00003489 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003490 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003491 !getDerived().AlwaysRebuild())
3492 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003493
3494 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003495 // nested-name-specifier, do so.
3496 if (SS.location_size() == NNS.getDataLength() &&
3497 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3498 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3499
3500 // Allocate new nested-name-specifier location information.
3501 return SS.getWithLocInContext(SemaRef.Context);
3502}
3503
3504template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003505DeclarationNameInfo
3506TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003507::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003508 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003509 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003510 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003511
3512 switch (Name.getNameKind()) {
3513 case DeclarationName::Identifier:
3514 case DeclarationName::ObjCZeroArgSelector:
3515 case DeclarationName::ObjCOneArgSelector:
3516 case DeclarationName::ObjCMultiArgSelector:
3517 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003518 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003519 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003520 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003521
Douglas Gregorf816bd72009-09-03 22:13:48 +00003522 case DeclarationName::CXXConstructorName:
3523 case DeclarationName::CXXDestructorName:
3524 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003525 TypeSourceInfo *NewTInfo;
3526 CanQualType NewCanTy;
3527 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003528 NewTInfo = getDerived().TransformType(OldTInfo);
3529 if (!NewTInfo)
3530 return DeclarationNameInfo();
3531 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003532 }
3533 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003534 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003535 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003536 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003537 if (NewT.isNull())
3538 return DeclarationNameInfo();
3539 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3540 }
Mike Stump11289f42009-09-09 15:08:12 +00003541
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003542 DeclarationName NewName
3543 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3544 NewCanTy);
3545 DeclarationNameInfo NewNameInfo(NameInfo);
3546 NewNameInfo.setName(NewName);
3547 NewNameInfo.setNamedTypeInfo(NewTInfo);
3548 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003549 }
Mike Stump11289f42009-09-09 15:08:12 +00003550 }
3551
David Blaikie83d382b2011-09-23 05:06:16 +00003552 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003553}
3554
3555template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003556TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003557TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3558 TemplateName Name,
3559 SourceLocation NameLoc,
3560 QualType ObjectType,
3561 NamedDecl *FirstQualifierInScope) {
3562 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3563 TemplateDecl *Template = QTN->getTemplateDecl();
3564 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003565
Douglas Gregor9db53502011-03-02 18:07:45 +00003566 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003567 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003568 Template));
3569 if (!TransTemplate)
3570 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003571
Douglas Gregor9db53502011-03-02 18:07:45 +00003572 if (!getDerived().AlwaysRebuild() &&
3573 SS.getScopeRep() == QTN->getQualifier() &&
3574 TransTemplate == Template)
3575 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003576
Douglas Gregor9db53502011-03-02 18:07:45 +00003577 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3578 TransTemplate);
3579 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003580
Douglas Gregor9db53502011-03-02 18:07:45 +00003581 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3582 if (SS.getScopeRep()) {
3583 // These apply to the scope specifier, not the template.
3584 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003585 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003586 }
3587
Douglas Gregor9db53502011-03-02 18:07:45 +00003588 if (!getDerived().AlwaysRebuild() &&
3589 SS.getScopeRep() == DTN->getQualifier() &&
3590 ObjectType.isNull())
3591 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003592
Douglas Gregor9db53502011-03-02 18:07:45 +00003593 if (DTN->isIdentifier()) {
3594 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003595 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003596 NameLoc,
3597 ObjectType,
3598 FirstQualifierInScope);
3599 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003600
Douglas Gregor9db53502011-03-02 18:07:45 +00003601 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3602 ObjectType);
3603 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003604
Douglas Gregor9db53502011-03-02 18:07:45 +00003605 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3606 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003607 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003608 Template));
3609 if (!TransTemplate)
3610 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003611
Douglas Gregor9db53502011-03-02 18:07:45 +00003612 if (!getDerived().AlwaysRebuild() &&
3613 TransTemplate == Template)
3614 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003615
Douglas Gregor9db53502011-03-02 18:07:45 +00003616 return TemplateName(TransTemplate);
3617 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003618
Douglas Gregor9db53502011-03-02 18:07:45 +00003619 if (SubstTemplateTemplateParmPackStorage *SubstPack
3620 = Name.getAsSubstTemplateTemplateParmPack()) {
3621 TemplateTemplateParmDecl *TransParam
3622 = cast_or_null<TemplateTemplateParmDecl>(
3623 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3624 if (!TransParam)
3625 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003626
Douglas Gregor9db53502011-03-02 18:07:45 +00003627 if (!getDerived().AlwaysRebuild() &&
3628 TransParam == SubstPack->getParameterPack())
3629 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003630
3631 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003632 SubstPack->getArgumentPack());
3633 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003634
Douglas Gregor9db53502011-03-02 18:07:45 +00003635 // These should be getting filtered out before they reach the AST.
3636 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003637}
3638
3639template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003640void TreeTransform<Derived>::InventTemplateArgumentLoc(
3641 const TemplateArgument &Arg,
3642 TemplateArgumentLoc &Output) {
3643 SourceLocation Loc = getDerived().getBaseLocation();
3644 switch (Arg.getKind()) {
3645 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003646 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003647 break;
3648
3649 case TemplateArgument::Type:
3650 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003651 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003652
John McCall0ad16662009-10-29 08:12:44 +00003653 break;
3654
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003655 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003656 case TemplateArgument::TemplateExpansion: {
3657 NestedNameSpecifierLocBuilder Builder;
Manuel Klimek4c67fa72016-01-11 11:39:00 +00003658 TemplateName Template = Arg.getAsTemplateOrTemplatePattern();
Douglas Gregor9d802122011-03-02 17:09:35 +00003659 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3660 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3661 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3662 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003663
Douglas Gregor9d802122011-03-02 17:09:35 +00003664 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003665 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003666 Builder.getWithLocInContext(SemaRef.Context),
3667 Loc);
3668 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003669 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003670 Builder.getWithLocInContext(SemaRef.Context),
3671 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003672
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003673 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003674 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003675
John McCall0ad16662009-10-29 08:12:44 +00003676 case TemplateArgument::Expression:
3677 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3678 break;
3679
3680 case TemplateArgument::Declaration:
3681 case TemplateArgument::Integral:
3682 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003683 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003684 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003685 break;
3686 }
3687}
3688
3689template<typename Derived>
3690bool TreeTransform<Derived>::TransformTemplateArgument(
3691 const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +00003692 TemplateArgumentLoc &Output, bool Uneval) {
John McCall0ad16662009-10-29 08:12:44 +00003693 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003694 switch (Arg.getKind()) {
3695 case TemplateArgument::Null:
3696 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003697 case TemplateArgument::Pack:
3698 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003699 case TemplateArgument::NullPtr:
3700 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003701
Douglas Gregore922c772009-08-04 22:27:00 +00003702 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003703 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003704 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003705 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003706
3707 DI = getDerived().TransformType(DI);
3708 if (!DI) return true;
3709
3710 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3711 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003712 }
Mike Stump11289f42009-09-09 15:08:12 +00003713
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003714 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003715 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3716 if (QualifierLoc) {
3717 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3718 if (!QualifierLoc)
3719 return true;
3720 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003721
Douglas Gregordf846d12011-03-02 18:46:51 +00003722 CXXScopeSpec SS;
3723 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003724 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003725 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3726 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003727 if (Template.isNull())
3728 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003729
Douglas Gregor9d802122011-03-02 17:09:35 +00003730 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003731 Input.getTemplateNameLoc());
3732 return false;
3733 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003734
3735 case TemplateArgument::TemplateExpansion:
3736 llvm_unreachable("Caller should expand pack expansions");
3737
Douglas Gregore922c772009-08-04 22:27:00 +00003738 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003739 // Template argument expressions are constant expressions.
Richard Smithd784e682015-09-23 21:41:42 +00003740 EnterExpressionEvaluationContext Unevaluated(
3741 getSema(), Uneval ? Sema::Unevaluated : Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003742
John McCall0ad16662009-10-29 08:12:44 +00003743 Expr *InputExpr = Input.getSourceExpression();
3744 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3745
Chris Lattnercdb591a2011-04-25 20:37:58 +00003746 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003747 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003748 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003749 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003750 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003751 }
Douglas Gregore922c772009-08-04 22:27:00 +00003752 }
Mike Stump11289f42009-09-09 15:08:12 +00003753
Douglas Gregore922c772009-08-04 22:27:00 +00003754 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003755 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003756}
3757
Douglas Gregorfe921a72010-12-20 23:36:19 +00003758/// \brief Iterator adaptor that invents template argument location information
3759/// for each of the template arguments in its underlying iterator.
3760template<typename Derived, typename InputIterator>
3761class TemplateArgumentLocInventIterator {
3762 TreeTransform<Derived> &Self;
3763 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003764
Douglas Gregorfe921a72010-12-20 23:36:19 +00003765public:
3766 typedef TemplateArgumentLoc value_type;
3767 typedef TemplateArgumentLoc reference;
3768 typedef typename std::iterator_traits<InputIterator>::difference_type
3769 difference_type;
3770 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003771
Douglas Gregorfe921a72010-12-20 23:36:19 +00003772 class pointer {
3773 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003774
Douglas Gregorfe921a72010-12-20 23:36:19 +00003775 public:
3776 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003777
Douglas Gregorfe921a72010-12-20 23:36:19 +00003778 const TemplateArgumentLoc *operator->() const { return &Arg; }
3779 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003780
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00003781 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003782
Douglas Gregorfe921a72010-12-20 23:36:19 +00003783 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3784 InputIterator Iter)
3785 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003786
Douglas Gregorfe921a72010-12-20 23:36:19 +00003787 TemplateArgumentLocInventIterator &operator++() {
3788 ++Iter;
3789 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003790 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003791
Douglas Gregorfe921a72010-12-20 23:36:19 +00003792 TemplateArgumentLocInventIterator operator++(int) {
3793 TemplateArgumentLocInventIterator Old(*this);
3794 ++(*this);
3795 return Old;
3796 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003797
Douglas Gregorfe921a72010-12-20 23:36:19 +00003798 reference operator*() const {
3799 TemplateArgumentLoc Result;
3800 Self.InventTemplateArgumentLoc(*Iter, Result);
3801 return Result;
3802 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003803
Douglas Gregorfe921a72010-12-20 23:36:19 +00003804 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003805
Douglas Gregorfe921a72010-12-20 23:36:19 +00003806 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3807 const TemplateArgumentLocInventIterator &Y) {
3808 return X.Iter == Y.Iter;
3809 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003810
Douglas Gregorfe921a72010-12-20 23:36:19 +00003811 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3812 const TemplateArgumentLocInventIterator &Y) {
3813 return X.Iter != Y.Iter;
3814 }
3815};
Chad Rosier1dcde962012-08-08 18:46:20 +00003816
Douglas Gregor42cafa82010-12-20 17:42:22 +00003817template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003818template<typename InputIterator>
Richard Smithd784e682015-09-23 21:41:42 +00003819bool TreeTransform<Derived>::TransformTemplateArguments(
3820 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
3821 bool Uneval) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003822 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003823 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003824 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003825
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003826 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3827 // Unpack argument packs, which we translate them into separate
3828 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003829 // FIXME: We could do much better if we could guarantee that the
3830 // TemplateArgumentLocInfo for the pack expansion would be usable for
3831 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003832 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003833 TemplateArgument::pack_iterator>
3834 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003835 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003836 In.getArgument().pack_begin()),
3837 PackLocIterator(*this,
3838 In.getArgument().pack_end()),
Richard Smithd784e682015-09-23 21:41:42 +00003839 Outputs, Uneval))
Douglas Gregorfe921a72010-12-20 23:36:19 +00003840 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003841
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003842 continue;
3843 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003844
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003845 if (In.getArgument().isPackExpansion()) {
3846 // We have a pack expansion, for which we will be substituting into
3847 // the pattern.
3848 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003849 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003850 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003851 = getSema().getTemplateArgumentPackExpansionPattern(
3852 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003853
Chris Lattner01cf8db2011-07-20 06:58:45 +00003854 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003855 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3856 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003857
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003858 // Determine whether the set of unexpanded parameter packs can and should
3859 // be expanded.
3860 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003861 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003862 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003863 if (getDerived().TryExpandParameterPacks(Ellipsis,
3864 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003865 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003866 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003867 RetainExpansion,
3868 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003869 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003870
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003871 if (!Expand) {
3872 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003873 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003874 // expansion.
3875 TemplateArgumentLoc OutPattern;
3876 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Richard Smithd784e682015-09-23 21:41:42 +00003877 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003878 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003879
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003880 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3881 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003882 if (Out.getArgument().isNull())
3883 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003884
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003885 Outputs.addArgument(Out);
3886 continue;
3887 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003888
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003889 // The transform has determined that we should perform an elementwise
3890 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003891 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003892 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3893
Richard Smithd784e682015-09-23 21:41:42 +00003894 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003895 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003896
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003897 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003898 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3899 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003900 if (Out.getArgument().isNull())
3901 return true;
3902 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003903
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003904 Outputs.addArgument(Out);
3905 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003906
Douglas Gregor48d24112011-01-10 20:53:55 +00003907 // If we're supposed to retain a pack expansion, do so by temporarily
3908 // forgetting the partially-substituted parameter pack.
3909 if (RetainExpansion) {
3910 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003911
Richard Smithd784e682015-09-23 21:41:42 +00003912 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor48d24112011-01-10 20:53:55 +00003913 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003914
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003915 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3916 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003917 if (Out.getArgument().isNull())
3918 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003919
Douglas Gregor48d24112011-01-10 20:53:55 +00003920 Outputs.addArgument(Out);
3921 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003922
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003923 continue;
3924 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003925
3926 // The simple case:
Richard Smithd784e682015-09-23 21:41:42 +00003927 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003928 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003929
Douglas Gregor42cafa82010-12-20 17:42:22 +00003930 Outputs.addArgument(Out);
3931 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003932
Douglas Gregor42cafa82010-12-20 17:42:22 +00003933 return false;
3934
3935}
3936
Douglas Gregord6ff3322009-08-04 16:50:30 +00003937//===----------------------------------------------------------------------===//
3938// Type transformation
3939//===----------------------------------------------------------------------===//
3940
3941template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003942QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003943 if (getDerived().AlreadyTransformed(T))
3944 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003945
John McCall550e0c22009-10-21 00:40:46 +00003946 // Temporary workaround. All of these transformations should
3947 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003948 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3949 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003950
John McCall31f82722010-11-12 08:19:04 +00003951 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003952
John McCall550e0c22009-10-21 00:40:46 +00003953 if (!NewDI)
3954 return QualType();
3955
3956 return NewDI->getType();
3957}
3958
3959template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003960TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003961 // Refine the base location to the type's location.
3962 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3963 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003964 if (getDerived().AlreadyTransformed(DI->getType()))
3965 return DI;
3966
3967 TypeLocBuilder TLB;
3968
3969 TypeLoc TL = DI->getTypeLoc();
3970 TLB.reserve(TL.getFullDataSize());
3971
John McCall31f82722010-11-12 08:19:04 +00003972 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003973 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003974 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00003975
John McCallbcd03502009-12-07 02:54:59 +00003976 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003977}
3978
3979template<typename Derived>
3980QualType
John McCall31f82722010-11-12 08:19:04 +00003981TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003982 switch (T.getTypeLocClass()) {
3983#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003984#define TYPELOC(CLASS, PARENT) \
3985 case TypeLoc::CLASS: \
3986 return getDerived().Transform##CLASS##Type(TLB, \
3987 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003988#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003989 }
Mike Stump11289f42009-09-09 15:08:12 +00003990
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003991 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003992}
3993
3994/// FIXME: By default, this routine adds type qualifiers only to types
3995/// that can have qualifiers, and silently suppresses those qualifiers
3996/// that are not permitted (e.g., qualifiers on reference or function
3997/// types). This is the right thing for template instantiation, but
3998/// probably not for other clients.
3999template<typename Derived>
4000QualType
4001TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004002 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00004003 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00004004
John McCall31f82722010-11-12 08:19:04 +00004005 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00004006 if (Result.isNull())
4007 return QualType();
4008
4009 // Silently suppress qualifiers if the result type can't be qualified.
4010 // FIXME: this is the right thing for template instantiation, but
4011 // probably not for other clients.
4012 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00004013 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00004014
John McCall31168b02011-06-15 23:02:42 +00004015 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00004016 // resulting type.
4017 if (Quals.hasObjCLifetime()) {
4018 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
4019 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00004020 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004021 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00004022 // A lifetime qualifier applied to a substituted template parameter
4023 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00004024 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00004025 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00004026 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
4027 QualType Replacement = SubstTypeParam->getReplacementType();
4028 Qualifiers Qs = Replacement.getQualifiers();
4029 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00004030 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00004031 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
4032 Qs);
4033 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00004034 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00004035 Replacement);
4036 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00004037 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
4038 // 'auto' types behave the same way as template parameters.
4039 QualType Deduced = AutoTy->getDeducedType();
4040 Qualifiers Qs = Deduced.getQualifiers();
4041 Qs.removeObjCLifetime();
4042 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
4043 Qs);
Richard Smithe301ba22015-11-11 02:02:15 +00004044 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
Faisal Vali2b391ab2013-09-26 19:54:12 +00004045 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00004046 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00004047 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00004048 // Otherwise, complain about the addition of a qualifier to an
4049 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00004050 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00004051 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00004052 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00004053
Douglas Gregore46db902011-06-17 22:11:49 +00004054 Quals.removeObjCLifetime();
4055 }
4056 }
4057 }
John McCallcb0f89a2010-06-05 06:41:15 +00004058 if (!Quals.empty()) {
4059 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00004060 // BuildQualifiedType might not add qualifiers if they are invalid.
4061 if (Result.hasLocalQualifiers())
4062 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00004063 // No location information to preserve.
4064 }
John McCall550e0c22009-10-21 00:40:46 +00004065
4066 return Result;
4067}
4068
Douglas Gregor14454802011-02-25 02:25:35 +00004069template<typename Derived>
4070TypeLoc
4071TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
4072 QualType ObjectType,
4073 NamedDecl *UnqualLookup,
4074 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004075 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00004076 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00004077
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004078 TypeSourceInfo *TSI =
4079 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
4080 if (TSI)
4081 return TSI->getTypeLoc();
4082 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00004083}
4084
Douglas Gregor579c15f2011-03-02 18:32:08 +00004085template<typename Derived>
4086TypeSourceInfo *
4087TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4088 QualType ObjectType,
4089 NamedDecl *UnqualLookup,
4090 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004091 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00004092 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00004093
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004094 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
4095 UnqualLookup, SS);
4096}
4097
4098template <typename Derived>
4099TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
4100 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
4101 CXXScopeSpec &SS) {
4102 QualType T = TL.getType();
4103 assert(!getDerived().AlreadyTransformed(T));
4104
Douglas Gregor579c15f2011-03-02 18:32:08 +00004105 TypeLocBuilder TLB;
4106 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00004107
Douglas Gregor579c15f2011-03-02 18:32:08 +00004108 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004109 TemplateSpecializationTypeLoc SpecTL =
4110 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004111
Douglas Gregor579c15f2011-03-02 18:32:08 +00004112 TemplateName Template
4113 = getDerived().TransformTemplateName(SS,
4114 SpecTL.getTypePtr()->getTemplateName(),
4115 SpecTL.getTemplateNameLoc(),
4116 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00004117 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004118 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004119
4120 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004121 Template);
4122 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004123 DependentTemplateSpecializationTypeLoc SpecTL =
4124 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004125
Douglas Gregor579c15f2011-03-02 18:32:08 +00004126 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00004127 = getDerived().RebuildTemplateName(SS,
4128 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004129 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00004130 ObjectType, UnqualLookup);
4131 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004132 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004133
4134 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004135 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004136 Template,
4137 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00004138 } else {
4139 // Nothing special needs to be done for these.
4140 Result = getDerived().TransformType(TLB, TL);
4141 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004142
4143 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004144 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004145
Douglas Gregor579c15f2011-03-02 18:32:08 +00004146 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4147}
4148
John McCall550e0c22009-10-21 00:40:46 +00004149template <class TyLoc> static inline
4150QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
4151 TyLoc NewT = TLB.push<TyLoc>(T.getType());
4152 NewT.setNameLoc(T.getNameLoc());
4153 return T.getType();
4154}
4155
John McCall550e0c22009-10-21 00:40:46 +00004156template<typename Derived>
4157QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004158 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00004159 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
4160 NewT.setBuiltinLoc(T.getBuiltinLoc());
4161 if (T.needsExtraLocalData())
4162 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
4163 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004164}
Mike Stump11289f42009-09-09 15:08:12 +00004165
Douglas Gregord6ff3322009-08-04 16:50:30 +00004166template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004167QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004168 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00004169 // FIXME: recurse?
4170 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004171}
Mike Stump11289f42009-09-09 15:08:12 +00004172
Reid Kleckner0503a872013-12-05 01:23:43 +00004173template <typename Derived>
4174QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
4175 AdjustedTypeLoc TL) {
4176 // Adjustments applied during transformation are handled elsewhere.
4177 return getDerived().TransformType(TLB, TL.getOriginalLoc());
4178}
4179
Douglas Gregord6ff3322009-08-04 16:50:30 +00004180template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00004181QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
4182 DecayedTypeLoc TL) {
4183 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
4184 if (OriginalType.isNull())
4185 return QualType();
4186
4187 QualType Result = TL.getType();
4188 if (getDerived().AlwaysRebuild() ||
4189 OriginalType != TL.getOriginalLoc().getType())
4190 Result = SemaRef.Context.getDecayedType(OriginalType);
4191 TLB.push<DecayedTypeLoc>(Result);
4192 // Nothing to set for DecayedTypeLoc.
4193 return Result;
4194}
4195
4196template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004197QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004198 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004199 QualType PointeeType
4200 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004201 if (PointeeType.isNull())
4202 return QualType();
4203
4204 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00004205 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004206 // A dependent pointer type 'T *' has is being transformed such
4207 // that an Objective-C class type is being replaced for 'T'. The
4208 // resulting pointer type is an ObjCObjectPointerType, not a
4209 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00004210 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00004211
John McCall8b07ec22010-05-15 11:32:37 +00004212 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
4213 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004214 return Result;
4215 }
John McCall31f82722010-11-12 08:19:04 +00004216
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004217 if (getDerived().AlwaysRebuild() ||
4218 PointeeType != TL.getPointeeLoc().getType()) {
4219 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
4220 if (Result.isNull())
4221 return QualType();
4222 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004223
John McCall31168b02011-06-15 23:02:42 +00004224 // Objective-C ARC can add lifetime qualifiers to the type that we're
4225 // pointing to.
4226 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00004227
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004228 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
4229 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00004230 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004231}
Mike Stump11289f42009-09-09 15:08:12 +00004232
4233template<typename Derived>
4234QualType
John McCall550e0c22009-10-21 00:40:46 +00004235TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004236 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00004237 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00004238 = getDerived().TransformType(TLB, TL.getPointeeLoc());
4239 if (PointeeType.isNull())
4240 return QualType();
4241
4242 QualType Result = TL.getType();
4243 if (getDerived().AlwaysRebuild() ||
4244 PointeeType != TL.getPointeeLoc().getType()) {
4245 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00004246 TL.getSigilLoc());
4247 if (Result.isNull())
4248 return QualType();
4249 }
4250
Douglas Gregor049211a2010-04-22 16:50:51 +00004251 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00004252 NewT.setSigilLoc(TL.getSigilLoc());
4253 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004254}
4255
John McCall70dd5f62009-10-30 00:06:24 +00004256/// Transforms a reference type. Note that somewhat paradoxically we
4257/// don't care whether the type itself is an l-value type or an r-value
4258/// type; we only care if the type was *written* as an l-value type
4259/// or an r-value type.
4260template<typename Derived>
4261QualType
4262TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004263 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00004264 const ReferenceType *T = TL.getTypePtr();
4265
4266 // Note that this works with the pointee-as-written.
4267 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4268 if (PointeeType.isNull())
4269 return QualType();
4270
4271 QualType Result = TL.getType();
4272 if (getDerived().AlwaysRebuild() ||
4273 PointeeType != T->getPointeeTypeAsWritten()) {
4274 Result = getDerived().RebuildReferenceType(PointeeType,
4275 T->isSpelledAsLValue(),
4276 TL.getSigilLoc());
4277 if (Result.isNull())
4278 return QualType();
4279 }
4280
John McCall31168b02011-06-15 23:02:42 +00004281 // Objective-C ARC can add lifetime qualifiers to the type that we're
4282 // referring to.
4283 TLB.TypeWasModifiedSafely(
4284 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4285
John McCall70dd5f62009-10-30 00:06:24 +00004286 // r-value references can be rebuilt as l-value references.
4287 ReferenceTypeLoc NewTL;
4288 if (isa<LValueReferenceType>(Result))
4289 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4290 else
4291 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4292 NewTL.setSigilLoc(TL.getSigilLoc());
4293
4294 return Result;
4295}
4296
Mike Stump11289f42009-09-09 15:08:12 +00004297template<typename Derived>
4298QualType
John McCall550e0c22009-10-21 00:40:46 +00004299TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004300 LValueReferenceTypeLoc TL) {
4301 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004302}
4303
Mike Stump11289f42009-09-09 15:08:12 +00004304template<typename Derived>
4305QualType
John McCall550e0c22009-10-21 00:40:46 +00004306TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004307 RValueReferenceTypeLoc TL) {
4308 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004309}
Mike Stump11289f42009-09-09 15:08:12 +00004310
Douglas Gregord6ff3322009-08-04 16:50:30 +00004311template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004312QualType
John McCall550e0c22009-10-21 00:40:46 +00004313TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004314 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004315 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004316 if (PointeeType.isNull())
4317 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004318
Abramo Bagnara509357842011-03-05 14:42:21 +00004319 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004320 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00004321 if (OldClsTInfo) {
4322 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4323 if (!NewClsTInfo)
4324 return QualType();
4325 }
4326
4327 const MemberPointerType *T = TL.getTypePtr();
4328 QualType OldClsType = QualType(T->getClass(), 0);
4329 QualType NewClsType;
4330 if (NewClsTInfo)
4331 NewClsType = NewClsTInfo->getType();
4332 else {
4333 NewClsType = getDerived().TransformType(OldClsType);
4334 if (NewClsType.isNull())
4335 return QualType();
4336 }
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 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00004341 NewClsType != OldClsType) {
4342 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004343 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004344 if (Result.isNull())
4345 return QualType();
4346 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004347
Reid Kleckner0503a872013-12-05 01:23:43 +00004348 // If we had to adjust the pointee type when building a member pointer, make
4349 // sure to push TypeLoc info for it.
4350 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4351 if (MPT && PointeeType != MPT->getPointeeType()) {
4352 assert(isa<AdjustedType>(MPT->getPointeeType()));
4353 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4354 }
4355
John McCall550e0c22009-10-21 00:40:46 +00004356 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4357 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004358 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004359
4360 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004361}
4362
Mike Stump11289f42009-09-09 15:08:12 +00004363template<typename Derived>
4364QualType
John McCall550e0c22009-10-21 00:40:46 +00004365TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004366 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004367 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004368 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004369 if (ElementType.isNull())
4370 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004371
John McCall550e0c22009-10-21 00:40:46 +00004372 QualType Result = TL.getType();
4373 if (getDerived().AlwaysRebuild() ||
4374 ElementType != T->getElementType()) {
4375 Result = getDerived().RebuildConstantArrayType(ElementType,
4376 T->getSizeModifier(),
4377 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004378 T->getIndexTypeCVRQualifiers(),
4379 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004380 if (Result.isNull())
4381 return QualType();
4382 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004383
4384 // We might have either a ConstantArrayType or a VariableArrayType now:
4385 // a ConstantArrayType is allowed to have an element type which is a
4386 // VariableArrayType if the type is dependent. Fortunately, all array
4387 // types have the same 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());
Mike Stump11289f42009-09-09 15:08:12 +00004391
John McCall550e0c22009-10-21 00:40:46 +00004392 Expr *Size = TL.getSizeExpr();
4393 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004394 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4395 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004396 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4397 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004398 }
4399 NewTL.setSizeExpr(Size);
4400
4401 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004402}
Mike Stump11289f42009-09-09 15:08:12 +00004403
Douglas Gregord6ff3322009-08-04 16:50:30 +00004404template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004405QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004406 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004407 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004408 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004409 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004410 if (ElementType.isNull())
4411 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004412
John McCall550e0c22009-10-21 00:40:46 +00004413 QualType Result = TL.getType();
4414 if (getDerived().AlwaysRebuild() ||
4415 ElementType != T->getElementType()) {
4416 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004417 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004418 T->getIndexTypeCVRQualifiers(),
4419 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004420 if (Result.isNull())
4421 return QualType();
4422 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004423
John McCall550e0c22009-10-21 00:40:46 +00004424 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4425 NewTL.setLBracketLoc(TL.getLBracketLoc());
4426 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004427 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004428
4429 return Result;
4430}
4431
4432template<typename Derived>
4433QualType
4434TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004435 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004436 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004437 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4438 if (ElementType.isNull())
4439 return QualType();
4440
John McCalldadc5752010-08-24 06:29:42 +00004441 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00004442 = getDerived().TransformExpr(T->getSizeExpr());
4443 if (SizeResult.isInvalid())
4444 return QualType();
4445
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004446 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004447
4448 QualType Result = TL.getType();
4449 if (getDerived().AlwaysRebuild() ||
4450 ElementType != T->getElementType() ||
4451 Size != T->getSizeExpr()) {
4452 Result = getDerived().RebuildVariableArrayType(ElementType,
4453 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004454 Size,
John McCall550e0c22009-10-21 00:40:46 +00004455 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004456 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004457 if (Result.isNull())
4458 return QualType();
4459 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004460
Serge Pavlov774c6d02014-02-06 03:49:11 +00004461 // We might have constant size array now, but fortunately it has the same
4462 // location layout.
4463 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004464 NewTL.setLBracketLoc(TL.getLBracketLoc());
4465 NewTL.setRBracketLoc(TL.getRBracketLoc());
4466 NewTL.setSizeExpr(Size);
4467
4468 return Result;
4469}
4470
4471template<typename Derived>
4472QualType
4473TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004474 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004475 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004476 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4477 if (ElementType.isNull())
4478 return QualType();
4479
Richard Smith764d2fe2011-12-20 02:08:33 +00004480 // Array bounds are constant expressions.
4481 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4482 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004483
John McCall33ddac02011-01-19 10:06:00 +00004484 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4485 Expr *origSize = TL.getSizeExpr();
4486 if (!origSize) origSize = T->getSizeExpr();
4487
4488 ExprResult sizeResult
4489 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004490 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004491 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004492 return QualType();
4493
John McCall33ddac02011-01-19 10:06:00 +00004494 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004495
4496 QualType Result = TL.getType();
4497 if (getDerived().AlwaysRebuild() ||
4498 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004499 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004500 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4501 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004502 size,
John McCall550e0c22009-10-21 00:40:46 +00004503 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004504 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004505 if (Result.isNull())
4506 return QualType();
4507 }
John McCall550e0c22009-10-21 00:40:46 +00004508
4509 // We might have any sort of array type now, but fortunately they
4510 // all have the same location layout.
4511 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4512 NewTL.setLBracketLoc(TL.getLBracketLoc());
4513 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004514 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004515
4516 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004517}
Mike Stump11289f42009-09-09 15:08:12 +00004518
4519template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004520QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004521 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004522 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004523 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004524
4525 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004526 QualType ElementType = getDerived().TransformType(T->getElementType());
4527 if (ElementType.isNull())
4528 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004529
Richard Smith764d2fe2011-12-20 02:08:33 +00004530 // Vector sizes are constant expressions.
4531 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4532 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004533
John McCalldadc5752010-08-24 06:29:42 +00004534 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004535 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004536 if (Size.isInvalid())
4537 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004538
John McCall550e0c22009-10-21 00:40:46 +00004539 QualType Result = TL.getType();
4540 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004541 ElementType != T->getElementType() ||
4542 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004543 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004544 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004545 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004546 if (Result.isNull())
4547 return QualType();
4548 }
John McCall550e0c22009-10-21 00:40:46 +00004549
4550 // Result might be dependent or not.
4551 if (isa<DependentSizedExtVectorType>(Result)) {
4552 DependentSizedExtVectorTypeLoc NewTL
4553 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4554 NewTL.setNameLoc(TL.getNameLoc());
4555 } else {
4556 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4557 NewTL.setNameLoc(TL.getNameLoc());
4558 }
4559
4560 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004561}
Mike Stump11289f42009-09-09 15:08:12 +00004562
4563template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004564QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004565 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004566 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004567 QualType ElementType = getDerived().TransformType(T->getElementType());
4568 if (ElementType.isNull())
4569 return QualType();
4570
John McCall550e0c22009-10-21 00:40:46 +00004571 QualType Result = TL.getType();
4572 if (getDerived().AlwaysRebuild() ||
4573 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004574 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004575 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004576 if (Result.isNull())
4577 return QualType();
4578 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004579
John McCall550e0c22009-10-21 00:40:46 +00004580 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4581 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004582
John McCall550e0c22009-10-21 00:40:46 +00004583 return Result;
4584}
4585
4586template<typename Derived>
4587QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004588 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004589 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004590 QualType ElementType = getDerived().TransformType(T->getElementType());
4591 if (ElementType.isNull())
4592 return QualType();
4593
4594 QualType Result = TL.getType();
4595 if (getDerived().AlwaysRebuild() ||
4596 ElementType != T->getElementType()) {
4597 Result = getDerived().RebuildExtVectorType(ElementType,
4598 T->getNumElements(),
4599 /*FIXME*/ SourceLocation());
4600 if (Result.isNull())
4601 return QualType();
4602 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004603
John McCall550e0c22009-10-21 00:40:46 +00004604 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4605 NewTL.setNameLoc(TL.getNameLoc());
4606
4607 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004608}
Mike Stump11289f42009-09-09 15:08:12 +00004609
David Blaikie05785d12013-02-20 22:23:23 +00004610template <typename Derived>
4611ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4612 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4613 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004614 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004615 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004616
Douglas Gregor715e4612011-01-14 22:40:04 +00004617 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004618 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004619 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004620 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004621 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004622
Douglas Gregor715e4612011-01-14 22:40:04 +00004623 TypeLocBuilder TLB;
4624 TypeLoc NewTL = OldDI->getTypeLoc();
4625 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004626
4627 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004628 OldExpansionTL.getPatternLoc());
4629 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004630 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004631
4632 Result = RebuildPackExpansionType(Result,
4633 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004634 OldExpansionTL.getEllipsisLoc(),
4635 NumExpansions);
4636 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004637 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004638
Douglas Gregor715e4612011-01-14 22:40:04 +00004639 PackExpansionTypeLoc NewExpansionTL
4640 = TLB.push<PackExpansionTypeLoc>(Result);
4641 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4642 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4643 } else
4644 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004645 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004646 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004647
John McCall8fb0d9d2011-05-01 22:35:37 +00004648 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004649 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004650
4651 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4652 OldParm->getDeclContext(),
4653 OldParm->getInnerLocStart(),
4654 OldParm->getLocation(),
4655 OldParm->getIdentifier(),
4656 NewDI->getType(),
4657 NewDI,
4658 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004659 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004660 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4661 OldParm->getFunctionScopeIndex() + indexAdjustment);
4662 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004663}
4664
4665template<typename Derived>
4666bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004667 TransformFunctionTypeParams(SourceLocation Loc,
4668 ParmVarDecl **Params, unsigned NumParams,
4669 const QualType *ParamTypes,
John McCallc8e321d2016-03-01 02:09:25 +00004670 const FunctionProtoType::ExtParameterInfo *ParamInfos,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004671 SmallVectorImpl<QualType> &OutParamTypes,
John McCallc8e321d2016-03-01 02:09:25 +00004672 SmallVectorImpl<ParmVarDecl*> *PVars,
4673 Sema::ExtParameterInfoBuilder &PInfos) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004674 int indexAdjustment = 0;
4675
Douglas Gregordd472162011-01-07 00:20:55 +00004676 for (unsigned i = 0; i != NumParams; ++i) {
4677 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004678 assert(OldParm->getFunctionScopeIndex() == i);
4679
David Blaikie05785d12013-02-20 22:23:23 +00004680 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004681 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004682 if (OldParm->isParameterPack()) {
4683 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004684 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004685
Douglas Gregor5499af42011-01-05 23:12:31 +00004686 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004687 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004688 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004689 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4690 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004691 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4692
Douglas Gregor5499af42011-01-05 23:12:31 +00004693 // Determine whether we should expand the parameter packs.
4694 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004695 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004696 Optional<unsigned> OrigNumExpansions =
4697 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004698 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004699 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4700 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004701 Unexpanded,
4702 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004703 RetainExpansion,
4704 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004705 return true;
4706 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004707
Douglas Gregor5499af42011-01-05 23:12:31 +00004708 if (ShouldExpand) {
4709 // Expand the function parameter pack into multiple, separate
4710 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004711 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004712 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004713 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004714 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004715 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004716 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004717 OrigNumExpansions,
4718 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004719 if (!NewParm)
4720 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004721
John McCallc8e321d2016-03-01 02:09:25 +00004722 if (ParamInfos)
4723 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004724 OutParamTypes.push_back(NewParm->getType());
4725 if (PVars)
4726 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004727 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004728
4729 // If we're supposed to retain a pack expansion, do so by temporarily
4730 // forgetting the partially-substituted parameter pack.
4731 if (RetainExpansion) {
4732 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004733 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004734 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004735 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004736 OrigNumExpansions,
4737 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004738 if (!NewParm)
4739 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004740
John McCallc8e321d2016-03-01 02:09:25 +00004741 if (ParamInfos)
4742 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004743 OutParamTypes.push_back(NewParm->getType());
4744 if (PVars)
4745 PVars->push_back(NewParm);
4746 }
4747
John McCall8fb0d9d2011-05-01 22:35:37 +00004748 // The next parameter should have the same adjustment as the
4749 // last thing we pushed, but we post-incremented indexAdjustment
4750 // on every push. Also, if we push nothing, the adjustment should
4751 // go down by one.
4752 indexAdjustment--;
4753
Douglas Gregor5499af42011-01-05 23:12:31 +00004754 // We're done with the pack expansion.
4755 continue;
4756 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004757
4758 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004759 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004760 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4761 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004762 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004763 NumExpansions,
4764 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004765 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004766 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004767 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004768 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004769
John McCall58f10c32010-03-11 09:03:00 +00004770 if (!NewParm)
4771 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004772
John McCallc8e321d2016-03-01 02:09:25 +00004773 if (ParamInfos)
4774 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004775 OutParamTypes.push_back(NewParm->getType());
4776 if (PVars)
4777 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004778 continue;
4779 }
John McCall58f10c32010-03-11 09:03:00 +00004780
4781 // Deal with the possibility that we don't have a parameter
4782 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004783 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004784 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004785 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004786 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004787 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004788 = dyn_cast<PackExpansionType>(OldType)) {
4789 // We have a function parameter pack that may need to be expanded.
4790 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004791 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004792 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004793
Douglas Gregor5499af42011-01-05 23:12:31 +00004794 // Determine whether we should expand the parameter packs.
4795 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004796 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004797 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004798 Unexpanded,
4799 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004800 RetainExpansion,
4801 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004802 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004803 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004804
Douglas Gregor5499af42011-01-05 23:12:31 +00004805 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004806 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004807 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004808 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004809 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4810 QualType NewType = getDerived().TransformType(Pattern);
4811 if (NewType.isNull())
4812 return true;
John McCall58f10c32010-03-11 09:03:00 +00004813
John McCallc8e321d2016-03-01 02:09:25 +00004814 if (ParamInfos)
4815 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004816 OutParamTypes.push_back(NewType);
4817 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004818 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004819 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004820
Douglas Gregor5499af42011-01-05 23:12:31 +00004821 // We're done with the pack expansion.
4822 continue;
4823 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004824
Douglas Gregor48d24112011-01-10 20:53:55 +00004825 // If we're supposed to retain a pack expansion, do so by temporarily
4826 // forgetting the partially-substituted parameter pack.
4827 if (RetainExpansion) {
4828 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4829 QualType NewType = getDerived().TransformType(Pattern);
4830 if (NewType.isNull())
4831 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004832
John McCallc8e321d2016-03-01 02:09:25 +00004833 if (ParamInfos)
4834 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregor48d24112011-01-10 20:53:55 +00004835 OutParamTypes.push_back(NewType);
4836 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004837 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004838 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004839
Chad Rosier1dcde962012-08-08 18:46:20 +00004840 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004841 // expansion.
4842 OldType = Expansion->getPattern();
4843 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004844 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4845 NewType = getDerived().TransformType(OldType);
4846 } else {
4847 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004848 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004849
Douglas Gregor5499af42011-01-05 23:12:31 +00004850 if (NewType.isNull())
4851 return true;
4852
4853 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004854 NewType = getSema().Context.getPackExpansionType(NewType,
4855 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004856
John McCallc8e321d2016-03-01 02:09:25 +00004857 if (ParamInfos)
4858 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004859 OutParamTypes.push_back(NewType);
4860 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004861 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004862 }
4863
John McCall8fb0d9d2011-05-01 22:35:37 +00004864#ifndef NDEBUG
4865 if (PVars) {
4866 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4867 if (ParmVarDecl *parm = (*PVars)[i])
4868 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004869 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004870#endif
4871
4872 return false;
4873}
John McCall58f10c32010-03-11 09:03:00 +00004874
4875template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004876QualType
John McCall550e0c22009-10-21 00:40:46 +00004877TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004878 FunctionProtoTypeLoc TL) {
Richard Smith2e321552014-11-12 02:00:47 +00004879 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00004880 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00004881 return getDerived().TransformFunctionProtoType(
4882 TLB, TL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00004883 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
4884 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
4885 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00004886 });
Douglas Gregor3024f072012-04-16 07:05:22 +00004887}
4888
Richard Smith2e321552014-11-12 02:00:47 +00004889template<typename Derived> template<typename Fn>
4890QualType TreeTransform<Derived>::TransformFunctionProtoType(
4891 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
4892 unsigned ThisTypeQuals, Fn TransformExceptionSpec) {
John McCallc8e321d2016-03-01 02:09:25 +00004893
Douglas Gregor4afc2362010-08-31 00:26:14 +00004894 // Transform the parameters and return type.
4895 //
Richard Smithf623c962012-04-17 00:58:00 +00004896 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004897 // When the function has a trailing return type, we instantiate the
4898 // parameters before the return type, since the return type can then refer
4899 // to the parameters themselves (via decltype, sizeof, etc.).
4900 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004901 SmallVector<QualType, 4> ParamTypes;
4902 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallc8e321d2016-03-01 02:09:25 +00004903 Sema::ExtParameterInfoBuilder ExtParamInfos;
John McCall424cec92011-01-19 06:33:43 +00004904 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004905
Douglas Gregor7fb25412010-10-01 18:44:50 +00004906 QualType ResultType;
4907
Richard Smith1226c602012-08-14 22:51:13 +00004908 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004909 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004910 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
John McCallc8e321d2016-03-01 02:09:25 +00004911 TL.getTypePtr()->param_type_begin(),
4912 T->getExtParameterInfosOrNull(),
4913 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004914 return QualType();
4915
Douglas Gregor3024f072012-04-16 07:05:22 +00004916 {
4917 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004918 // If a declaration declares a member function or member function
4919 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004920 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004921 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004922 // declarator.
4923 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004924
Alp Toker42a16a62014-01-25 23:51:36 +00004925 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004926 if (ResultType.isNull())
4927 return QualType();
4928 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004929 }
4930 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004931 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004932 if (ResultType.isNull())
4933 return QualType();
4934
Alp Toker9cacbab2014-01-20 20:26:09 +00004935 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004936 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
John McCallc8e321d2016-03-01 02:09:25 +00004937 TL.getTypePtr()->param_type_begin(),
4938 T->getExtParameterInfosOrNull(),
4939 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004940 return QualType();
4941 }
4942
Richard Smith2e321552014-11-12 02:00:47 +00004943 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
4944
4945 bool EPIChanged = false;
4946 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
4947 return QualType();
4948
John McCallc8e321d2016-03-01 02:09:25 +00004949 // Handle extended parameter information.
4950 if (auto NewExtParamInfos =
4951 ExtParamInfos.getPointerOrNull(ParamTypes.size())) {
4952 if (!EPI.ExtParameterInfos ||
4953 llvm::makeArrayRef(EPI.ExtParameterInfos, TL.getNumParams())
4954 != llvm::makeArrayRef(NewExtParamInfos, ParamTypes.size())) {
4955 EPIChanged = true;
4956 }
4957 EPI.ExtParameterInfos = NewExtParamInfos;
4958 } else if (EPI.ExtParameterInfos) {
4959 EPIChanged = true;
4960 EPI.ExtParameterInfos = nullptr;
4961 }
Richard Smithf623c962012-04-17 00:58:00 +00004962
John McCall550e0c22009-10-21 00:40:46 +00004963 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004964 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Benjamin Kramere1c08b02015-08-18 08:10:39 +00004965 T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) {
Richard Smith2e321552014-11-12 02:00:47 +00004966 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
John McCall550e0c22009-10-21 00:40:46 +00004967 if (Result.isNull())
4968 return QualType();
4969 }
Mike Stump11289f42009-09-09 15:08:12 +00004970
John McCall550e0c22009-10-21 00:40:46 +00004971 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004972 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004973 NewTL.setLParenLoc(TL.getLParenLoc());
4974 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004975 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004976 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4977 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004978
4979 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004980}
Mike Stump11289f42009-09-09 15:08:12 +00004981
Douglas Gregord6ff3322009-08-04 16:50:30 +00004982template<typename Derived>
Richard Smith2e321552014-11-12 02:00:47 +00004983bool TreeTransform<Derived>::TransformExceptionSpec(
4984 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
4985 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
4986 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
4987
4988 // Instantiate a dynamic noexcept expression, if any.
4989 if (ESI.Type == EST_ComputedNoexcept) {
4990 EnterExpressionEvaluationContext Unevaluated(getSema(),
4991 Sema::ConstantEvaluated);
4992 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
4993 if (NoexceptExpr.isInvalid())
4994 return true;
4995
Richard Smith03a4aa32016-06-23 19:02:52 +00004996 // FIXME: This is bogus, a noexcept expression is not a condition.
4997 NoexceptExpr = getSema().CheckBooleanCondition(Loc, NoexceptExpr.get());
Richard Smith2e321552014-11-12 02:00:47 +00004998 if (NoexceptExpr.isInvalid())
4999 return true;
5000
5001 if (!NoexceptExpr.get()->isValueDependent()) {
5002 NoexceptExpr = getSema().VerifyIntegerConstantExpression(
5003 NoexceptExpr.get(), nullptr,
5004 diag::err_noexcept_needs_constant_expression,
5005 /*AllowFold*/false);
5006 if (NoexceptExpr.isInvalid())
5007 return true;
5008 }
5009
5010 if (ESI.NoexceptExpr != NoexceptExpr.get())
5011 Changed = true;
5012 ESI.NoexceptExpr = NoexceptExpr.get();
5013 }
5014
5015 if (ESI.Type != EST_Dynamic)
5016 return false;
5017
5018 // Instantiate a dynamic exception specification's type.
5019 for (QualType T : ESI.Exceptions) {
5020 if (const PackExpansionType *PackExpansion =
5021 T->getAs<PackExpansionType>()) {
5022 Changed = true;
5023
5024 // We have a pack expansion. Instantiate it.
5025 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5026 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5027 Unexpanded);
5028 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5029
5030 // Determine whether the set of unexpanded parameter packs can and
5031 // should
5032 // be expanded.
5033 bool Expand = false;
5034 bool RetainExpansion = false;
5035 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5036 // FIXME: Track the location of the ellipsis (and track source location
5037 // information for the types in the exception specification in general).
5038 if (getDerived().TryExpandParameterPacks(
5039 Loc, SourceRange(), Unexpanded, Expand,
5040 RetainExpansion, NumExpansions))
5041 return true;
5042
5043 if (!Expand) {
5044 // We can't expand this pack expansion into separate arguments yet;
5045 // just substitute into the pattern and create a new pack expansion
5046 // type.
5047 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5048 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5049 if (U.isNull())
5050 return true;
5051
5052 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
5053 Exceptions.push_back(U);
5054 continue;
5055 }
5056
5057 // Substitute into the pack expansion pattern for each slice of the
5058 // pack.
5059 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5060 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5061
5062 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5063 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5064 return true;
5065
5066 Exceptions.push_back(U);
5067 }
5068 } else {
5069 QualType U = getDerived().TransformType(T);
5070 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5071 return true;
5072 if (T != U)
5073 Changed = true;
5074
5075 Exceptions.push_back(U);
5076 }
5077 }
5078
5079 ESI.Exceptions = Exceptions;
5080 return false;
5081}
5082
5083template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00005084QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00005085 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005086 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005087 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00005088 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00005089 if (ResultType.isNull())
5090 return QualType();
5091
5092 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00005093 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00005094 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
5095
5096 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005097 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00005098 NewTL.setLParenLoc(TL.getLParenLoc());
5099 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005100 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00005101
5102 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005103}
Mike Stump11289f42009-09-09 15:08:12 +00005104
John McCallb96ec562009-12-04 22:46:56 +00005105template<typename Derived> QualType
5106TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005107 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005108 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005109 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00005110 if (!D)
5111 return QualType();
5112
5113 QualType Result = TL.getType();
5114 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
5115 Result = getDerived().RebuildUnresolvedUsingType(D);
5116 if (Result.isNull())
5117 return QualType();
5118 }
5119
5120 // We might get an arbitrary type spec type back. We should at
5121 // least always get a type spec type, though.
5122 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
5123 NewTL.setNameLoc(TL.getNameLoc());
5124
5125 return Result;
5126}
5127
Douglas Gregord6ff3322009-08-04 16:50:30 +00005128template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005129QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005130 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005131 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00005132 TypedefNameDecl *Typedef
5133 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5134 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005135 if (!Typedef)
5136 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005137
John McCall550e0c22009-10-21 00:40:46 +00005138 QualType Result = TL.getType();
5139 if (getDerived().AlwaysRebuild() ||
5140 Typedef != T->getDecl()) {
5141 Result = getDerived().RebuildTypedefType(Typedef);
5142 if (Result.isNull())
5143 return QualType();
5144 }
Mike Stump11289f42009-09-09 15:08:12 +00005145
John McCall550e0c22009-10-21 00:40:46 +00005146 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
5147 NewTL.setNameLoc(TL.getNameLoc());
5148
5149 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005150}
Mike Stump11289f42009-09-09 15:08:12 +00005151
Douglas Gregord6ff3322009-08-04 16:50:30 +00005152template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005153QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005154 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00005155 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00005156 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
5157 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00005158
John McCalldadc5752010-08-24 06:29:42 +00005159 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005160 if (E.isInvalid())
5161 return QualType();
5162
Eli Friedmane4f22df2012-02-29 04:03:55 +00005163 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
5164 if (E.isInvalid())
5165 return QualType();
5166
John McCall550e0c22009-10-21 00:40:46 +00005167 QualType Result = TL.getType();
5168 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00005169 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005170 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00005171 if (Result.isNull())
5172 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005173 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005174 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005175
John McCall550e0c22009-10-21 00:40:46 +00005176 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005177 NewTL.setTypeofLoc(TL.getTypeofLoc());
5178 NewTL.setLParenLoc(TL.getLParenLoc());
5179 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00005180
5181 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005182}
Mike Stump11289f42009-09-09 15:08:12 +00005183
5184template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005185QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005186 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00005187 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
5188 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
5189 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005190 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005191
John McCall550e0c22009-10-21 00:40:46 +00005192 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00005193 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
5194 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00005195 if (Result.isNull())
5196 return QualType();
5197 }
Mike Stump11289f42009-09-09 15:08:12 +00005198
John McCall550e0c22009-10-21 00:40:46 +00005199 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005200 NewTL.setTypeofLoc(TL.getTypeofLoc());
5201 NewTL.setLParenLoc(TL.getLParenLoc());
5202 NewTL.setRParenLoc(TL.getRParenLoc());
5203 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00005204
5205 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005206}
Mike Stump11289f42009-09-09 15:08:12 +00005207
5208template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005209QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005210 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005211 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00005212
Douglas Gregore922c772009-08-04 22:27:00 +00005213 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00005214 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
5215 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00005216
John McCalldadc5752010-08-24 06:29:42 +00005217 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005218 if (E.isInvalid())
5219 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005220
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005221 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00005222 if (E.isInvalid())
5223 return QualType();
5224
John McCall550e0c22009-10-21 00:40:46 +00005225 QualType Result = TL.getType();
5226 if (getDerived().AlwaysRebuild() ||
5227 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005228 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005229 if (Result.isNull())
5230 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005231 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005232 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005233
John McCall550e0c22009-10-21 00:40:46 +00005234 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
5235 NewTL.setNameLoc(TL.getNameLoc());
5236
5237 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005238}
5239
5240template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00005241QualType TreeTransform<Derived>::TransformUnaryTransformType(
5242 TypeLocBuilder &TLB,
5243 UnaryTransformTypeLoc TL) {
5244 QualType Result = TL.getType();
5245 if (Result->isDependentType()) {
5246 const UnaryTransformType *T = TL.getTypePtr();
5247 QualType NewBase =
5248 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
5249 Result = getDerived().RebuildUnaryTransformType(NewBase,
5250 T->getUTTKind(),
5251 TL.getKWLoc());
5252 if (Result.isNull())
5253 return QualType();
5254 }
5255
5256 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
5257 NewTL.setKWLoc(TL.getKWLoc());
5258 NewTL.setParensRange(TL.getParensRange());
5259 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
5260 return Result;
5261}
5262
5263template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00005264QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
5265 AutoTypeLoc TL) {
5266 const AutoType *T = TL.getTypePtr();
5267 QualType OldDeduced = T->getDeducedType();
5268 QualType NewDeduced;
5269 if (!OldDeduced.isNull()) {
5270 NewDeduced = getDerived().TransformType(OldDeduced);
5271 if (NewDeduced.isNull())
5272 return QualType();
5273 }
5274
5275 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00005276 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
5277 T->isDependentType()) {
Richard Smithe301ba22015-11-11 02:02:15 +00005278 Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword());
Richard Smith30482bc2011-02-20 03:19:35 +00005279 if (Result.isNull())
5280 return QualType();
5281 }
5282
5283 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5284 NewTL.setNameLoc(TL.getNameLoc());
5285
5286 return Result;
5287}
5288
5289template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005290QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005291 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005292 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005293 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005294 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5295 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005296 if (!Record)
5297 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005298
John McCall550e0c22009-10-21 00:40:46 +00005299 QualType Result = TL.getType();
5300 if (getDerived().AlwaysRebuild() ||
5301 Record != T->getDecl()) {
5302 Result = getDerived().RebuildRecordType(Record);
5303 if (Result.isNull())
5304 return QualType();
5305 }
Mike Stump11289f42009-09-09 15:08:12 +00005306
John McCall550e0c22009-10-21 00:40:46 +00005307 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5308 NewTL.setNameLoc(TL.getNameLoc());
5309
5310 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005311}
Mike Stump11289f42009-09-09 15:08:12 +00005312
5313template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005314QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005315 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005316 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005317 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005318 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5319 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005320 if (!Enum)
5321 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005322
John McCall550e0c22009-10-21 00:40:46 +00005323 QualType Result = TL.getType();
5324 if (getDerived().AlwaysRebuild() ||
5325 Enum != T->getDecl()) {
5326 Result = getDerived().RebuildEnumType(Enum);
5327 if (Result.isNull())
5328 return QualType();
5329 }
Mike Stump11289f42009-09-09 15:08:12 +00005330
John McCall550e0c22009-10-21 00:40:46 +00005331 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5332 NewTL.setNameLoc(TL.getNameLoc());
5333
5334 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005335}
John McCallfcc33b02009-09-05 00:15:47 +00005336
John McCalle78aac42010-03-10 03:28:59 +00005337template<typename Derived>
5338QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5339 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005340 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00005341 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5342 TL.getTypePtr()->getDecl());
5343 if (!D) return QualType();
5344
5345 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5346 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5347 return T;
5348}
5349
Douglas Gregord6ff3322009-08-04 16:50:30 +00005350template<typename Derived>
5351QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005352 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005353 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00005354 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005355}
5356
Mike Stump11289f42009-09-09 15:08:12 +00005357template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00005358QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005359 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005360 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005361 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005362
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005363 // Substitute into the replacement type, which itself might involve something
5364 // that needs to be transformed. This only tends to occur with default
5365 // template arguments of template template parameters.
5366 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5367 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5368 if (Replacement.isNull())
5369 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005370
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005371 // Always canonicalize the replacement type.
5372 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5373 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00005374 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005375 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00005376
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005377 // Propagate type-source information.
5378 SubstTemplateTypeParmTypeLoc NewTL
5379 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5380 NewTL.setNameLoc(TL.getNameLoc());
5381 return Result;
5382
John McCallcebee162009-10-18 09:09:24 +00005383}
5384
5385template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00005386QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5387 TypeLocBuilder &TLB,
5388 SubstTemplateTypeParmPackTypeLoc TL) {
5389 return TransformTypeSpecType(TLB, TL);
5390}
5391
5392template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00005393QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005394 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005395 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00005396 const TemplateSpecializationType *T = TL.getTypePtr();
5397
Douglas Gregordf846d12011-03-02 18:46:51 +00005398 // The nested-name-specifier never matters in a TemplateSpecializationType,
5399 // because we can't have a dependent nested-name-specifier anyway.
5400 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00005401 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00005402 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5403 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005404 if (Template.isNull())
5405 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005406
John McCall31f82722010-11-12 08:19:04 +00005407 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5408}
5409
Eli Friedman0dfb8892011-10-06 23:00:33 +00005410template<typename Derived>
5411QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5412 AtomicTypeLoc TL) {
5413 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5414 if (ValueType.isNull())
5415 return QualType();
5416
5417 QualType Result = TL.getType();
5418 if (getDerived().AlwaysRebuild() ||
5419 ValueType != TL.getValueLoc().getType()) {
5420 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5421 if (Result.isNull())
5422 return QualType();
5423 }
5424
5425 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5426 NewTL.setKWLoc(TL.getKWLoc());
5427 NewTL.setLParenLoc(TL.getLParenLoc());
5428 NewTL.setRParenLoc(TL.getRParenLoc());
5429
5430 return Result;
5431}
5432
Xiuli Pan9c14e282016-01-09 12:53:17 +00005433template <typename Derived>
5434QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB,
5435 PipeTypeLoc TL) {
5436 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5437 if (ValueType.isNull())
5438 return QualType();
5439
5440 QualType Result = TL.getType();
5441 if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
5442 Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc());
5443 if (Result.isNull())
5444 return QualType();
5445 }
5446
5447 PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
5448 NewTL.setKWLoc(TL.getKWLoc());
5449
5450 return Result;
5451}
5452
Chad Rosier1dcde962012-08-08 18:46:20 +00005453 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00005454 /// container that provides a \c getArgLoc() member function.
5455 ///
5456 /// This iterator is intended to be used with the iterator form of
5457 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5458 template<typename ArgLocContainer>
5459 class TemplateArgumentLocContainerIterator {
5460 ArgLocContainer *Container;
5461 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00005462
Douglas Gregorfe921a72010-12-20 23:36:19 +00005463 public:
5464 typedef TemplateArgumentLoc value_type;
5465 typedef TemplateArgumentLoc reference;
5466 typedef int difference_type;
5467 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00005468
Douglas Gregorfe921a72010-12-20 23:36:19 +00005469 class pointer {
5470 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00005471
Douglas Gregorfe921a72010-12-20 23:36:19 +00005472 public:
5473 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005474
Douglas Gregorfe921a72010-12-20 23:36:19 +00005475 const TemplateArgumentLoc *operator->() const {
5476 return &Arg;
5477 }
5478 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005479
5480
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00005481 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00005482
Douglas Gregorfe921a72010-12-20 23:36:19 +00005483 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5484 unsigned Index)
5485 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005486
Douglas Gregorfe921a72010-12-20 23:36:19 +00005487 TemplateArgumentLocContainerIterator &operator++() {
5488 ++Index;
5489 return *this;
5490 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005491
Douglas Gregorfe921a72010-12-20 23:36:19 +00005492 TemplateArgumentLocContainerIterator operator++(int) {
5493 TemplateArgumentLocContainerIterator Old(*this);
5494 ++(*this);
5495 return Old;
5496 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005497
Douglas Gregorfe921a72010-12-20 23:36:19 +00005498 TemplateArgumentLoc operator*() const {
5499 return Container->getArgLoc(Index);
5500 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005501
Douglas Gregorfe921a72010-12-20 23:36:19 +00005502 pointer operator->() const {
5503 return pointer(Container->getArgLoc(Index));
5504 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005505
Douglas Gregorfe921a72010-12-20 23:36:19 +00005506 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005507 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005508 return X.Container == Y.Container && X.Index == Y.Index;
5509 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005510
Douglas Gregorfe921a72010-12-20 23:36:19 +00005511 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005512 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005513 return !(X == Y);
5514 }
5515 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005516
5517
John McCall31f82722010-11-12 08:19:04 +00005518template <typename Derived>
5519QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5520 TypeLocBuilder &TLB,
5521 TemplateSpecializationTypeLoc TL,
5522 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005523 TemplateArgumentListInfo NewTemplateArgs;
5524 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5525 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005526 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5527 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005528 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005529 ArgIterator(TL, TL.getNumArgs()),
5530 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005531 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005532
John McCall0ad16662009-10-29 08:12:44 +00005533 // FIXME: maybe don't rebuild if all the template arguments are the same.
5534
5535 QualType Result =
5536 getDerived().RebuildTemplateSpecializationType(Template,
5537 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005538 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005539
5540 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005541 // Specializations of template template parameters are represented as
5542 // TemplateSpecializationTypes, and substitution of type alias templates
5543 // within a dependent context can transform them into
5544 // DependentTemplateSpecializationTypes.
5545 if (isa<DependentTemplateSpecializationType>(Result)) {
5546 DependentTemplateSpecializationTypeLoc NewTL
5547 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005548 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005549 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005550 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005551 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005552 NewTL.setLAngleLoc(TL.getLAngleLoc());
5553 NewTL.setRAngleLoc(TL.getRAngleLoc());
5554 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5555 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5556 return Result;
5557 }
5558
John McCall0ad16662009-10-29 08:12:44 +00005559 TemplateSpecializationTypeLoc NewTL
5560 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005561 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005562 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5563 NewTL.setLAngleLoc(TL.getLAngleLoc());
5564 NewTL.setRAngleLoc(TL.getRAngleLoc());
5565 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5566 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005567 }
Mike Stump11289f42009-09-09 15:08:12 +00005568
John McCall0ad16662009-10-29 08:12:44 +00005569 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005570}
Mike Stump11289f42009-09-09 15:08:12 +00005571
Douglas Gregor5a064722011-02-28 17:23:35 +00005572template <typename Derived>
5573QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5574 TypeLocBuilder &TLB,
5575 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005576 TemplateName Template,
5577 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005578 TemplateArgumentListInfo NewTemplateArgs;
5579 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5580 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5581 typedef TemplateArgumentLocContainerIterator<
5582 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005583 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005584 ArgIterator(TL, TL.getNumArgs()),
5585 NewTemplateArgs))
5586 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005587
Douglas Gregor5a064722011-02-28 17:23:35 +00005588 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005589
Douglas Gregor5a064722011-02-28 17:23:35 +00005590 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5591 QualType Result
5592 = getSema().Context.getDependentTemplateSpecializationType(
5593 TL.getTypePtr()->getKeyword(),
5594 DTN->getQualifier(),
5595 DTN->getIdentifier(),
5596 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005597
Douglas Gregor5a064722011-02-28 17:23:35 +00005598 DependentTemplateSpecializationTypeLoc NewTL
5599 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005600 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005601 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005602 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005603 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005604 NewTL.setLAngleLoc(TL.getLAngleLoc());
5605 NewTL.setRAngleLoc(TL.getRAngleLoc());
5606 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5607 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5608 return Result;
5609 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005610
5611 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005612 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005613 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005614 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005615
Douglas Gregor5a064722011-02-28 17:23:35 +00005616 if (!Result.isNull()) {
5617 /// FIXME: Wrap this in an elaborated-type-specifier?
5618 TemplateSpecializationTypeLoc NewTL
5619 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005620 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005621 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005622 NewTL.setLAngleLoc(TL.getLAngleLoc());
5623 NewTL.setRAngleLoc(TL.getRAngleLoc());
5624 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5625 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5626 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005627
Douglas Gregor5a064722011-02-28 17:23:35 +00005628 return Result;
5629}
5630
Mike Stump11289f42009-09-09 15:08:12 +00005631template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005632QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005633TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005634 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005635 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005636
Douglas Gregor844cb502011-03-01 18:12:44 +00005637 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005638 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005639 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005640 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005641 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5642 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005643 return QualType();
5644 }
Mike Stump11289f42009-09-09 15:08:12 +00005645
John McCall31f82722010-11-12 08:19:04 +00005646 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5647 if (NamedT.isNull())
5648 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005649
Richard Smith3f1b5d02011-05-05 21:57:07 +00005650 // C++0x [dcl.type.elab]p2:
5651 // If the identifier resolves to a typedef-name or the simple-template-id
5652 // resolves to an alias template specialization, the
5653 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005654 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5655 if (const TemplateSpecializationType *TST =
5656 NamedT->getAs<TemplateSpecializationType>()) {
5657 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00005658 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5659 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00005660 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5661 diag::err_tag_reference_non_tag) << 4;
5662 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5663 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005664 }
5665 }
5666
John McCall550e0c22009-10-21 00:40:46 +00005667 QualType Result = TL.getType();
5668 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005669 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005670 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005671 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005672 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005673 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005674 if (Result.isNull())
5675 return QualType();
5676 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005677
Abramo Bagnara6150c882010-05-11 21:36:43 +00005678 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005679 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005680 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005681 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005682}
Mike Stump11289f42009-09-09 15:08:12 +00005683
5684template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005685QualType TreeTransform<Derived>::TransformAttributedType(
5686 TypeLocBuilder &TLB,
5687 AttributedTypeLoc TL) {
5688 const AttributedType *oldType = TL.getTypePtr();
5689 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5690 if (modifiedType.isNull())
5691 return QualType();
5692
5693 QualType result = TL.getType();
5694
5695 // FIXME: dependent operand expressions?
5696 if (getDerived().AlwaysRebuild() ||
5697 modifiedType != oldType->getModifiedType()) {
5698 // TODO: this is really lame; we should really be rebuilding the
5699 // equivalent type from first principles.
5700 QualType equivalentType
5701 = getDerived().TransformType(oldType->getEquivalentType());
5702 if (equivalentType.isNull())
5703 return QualType();
Douglas Gregor261a89b2015-06-19 17:51:05 +00005704
5705 // Check whether we can add nullability; it is only represented as
5706 // type sugar, and therefore cannot be diagnosed in any other way.
5707 if (auto nullability = oldType->getImmediateNullability()) {
5708 if (!modifiedType->canHaveNullability()) {
5709 SemaRef.Diag(TL.getAttrNameLoc(), diag::err_nullability_nonpointer)
Douglas Gregoraea7afd2015-06-24 22:02:08 +00005710 << DiagNullabilityKind(*nullability, false) << modifiedType;
Douglas Gregor261a89b2015-06-19 17:51:05 +00005711 return QualType();
5712 }
5713 }
5714
John McCall81904512011-01-06 01:58:22 +00005715 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5716 modifiedType,
5717 equivalentType);
5718 }
5719
5720 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5721 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5722 if (TL.hasAttrOperand())
5723 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5724 if (TL.hasAttrExprOperand())
5725 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5726 else if (TL.hasAttrEnumOperand())
5727 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5728
5729 return result;
5730}
5731
5732template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005733QualType
5734TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5735 ParenTypeLoc TL) {
5736 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5737 if (Inner.isNull())
5738 return QualType();
5739
5740 QualType Result = TL.getType();
5741 if (getDerived().AlwaysRebuild() ||
5742 Inner != TL.getInnerLoc().getType()) {
5743 Result = getDerived().RebuildParenType(Inner);
5744 if (Result.isNull())
5745 return QualType();
5746 }
5747
5748 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5749 NewTL.setLParenLoc(TL.getLParenLoc());
5750 NewTL.setRParenLoc(TL.getRParenLoc());
5751 return Result;
5752}
5753
5754template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005755QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005756 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005757 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005758
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005759 NestedNameSpecifierLoc QualifierLoc
5760 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5761 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005762 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005763
John McCallc392f372010-06-11 00:33:02 +00005764 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005765 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005766 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005767 QualifierLoc,
5768 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005769 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005770 if (Result.isNull())
5771 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005772
Abramo Bagnarad7548482010-05-19 21:37:53 +00005773 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5774 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005775 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5776
Abramo Bagnarad7548482010-05-19 21:37:53 +00005777 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005778 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005779 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005780 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005781 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005782 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005783 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005784 NewTL.setNameLoc(TL.getNameLoc());
5785 }
John McCall550e0c22009-10-21 00:40:46 +00005786 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005787}
Mike Stump11289f42009-09-09 15:08:12 +00005788
Douglas Gregord6ff3322009-08-04 16:50:30 +00005789template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005790QualType TreeTransform<Derived>::
5791 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005792 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005793 NestedNameSpecifierLoc QualifierLoc;
5794 if (TL.getQualifierLoc()) {
5795 QualifierLoc
5796 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5797 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005798 return QualType();
5799 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005800
John McCall31f82722010-11-12 08:19:04 +00005801 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005802 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005803}
5804
5805template<typename Derived>
5806QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005807TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5808 DependentTemplateSpecializationTypeLoc TL,
5809 NestedNameSpecifierLoc QualifierLoc) {
5810 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005811
Douglas Gregora7a795b2011-03-01 20:11:18 +00005812 TemplateArgumentListInfo NewTemplateArgs;
5813 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5814 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005815
Douglas Gregora7a795b2011-03-01 20:11:18 +00005816 typedef TemplateArgumentLocContainerIterator<
5817 DependentTemplateSpecializationTypeLoc> ArgIterator;
5818 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5819 ArgIterator(TL, TL.getNumArgs()),
5820 NewTemplateArgs))
5821 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005822
Douglas Gregora7a795b2011-03-01 20:11:18 +00005823 QualType Result
5824 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5825 QualifierLoc,
5826 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005827 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005828 NewTemplateArgs);
5829 if (Result.isNull())
5830 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005831
Douglas Gregora7a795b2011-03-01 20:11:18 +00005832 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5833 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005834
Douglas Gregora7a795b2011-03-01 20:11:18 +00005835 // Copy information relevant to the template specialization.
5836 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005837 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005838 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005839 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005840 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5841 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005842 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005843 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005844
Douglas Gregora7a795b2011-03-01 20:11:18 +00005845 // Copy information relevant to the elaborated type.
5846 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005847 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005848 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005849 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5850 DependentTemplateSpecializationTypeLoc SpecTL
5851 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005852 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005853 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005854 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005855 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005856 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5857 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005858 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005859 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005860 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005861 TemplateSpecializationTypeLoc SpecTL
5862 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005863 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005864 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005865 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5866 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005867 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005868 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005869 }
5870 return Result;
5871}
5872
5873template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005874QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5875 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005876 QualType Pattern
5877 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005878 if (Pattern.isNull())
5879 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005880
5881 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005882 if (getDerived().AlwaysRebuild() ||
5883 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005884 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005885 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005886 TL.getEllipsisLoc(),
5887 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005888 if (Result.isNull())
5889 return QualType();
5890 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005891
Douglas Gregor822d0302011-01-12 17:07:58 +00005892 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5893 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5894 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005895}
5896
5897template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005898QualType
5899TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005900 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005901 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005902 TLB.pushFullCopy(TL);
5903 return TL.getType();
5904}
5905
5906template<typename Derived>
5907QualType
5908TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005909 ObjCObjectTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00005910 // Transform base type.
5911 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
5912 if (BaseType.isNull())
5913 return QualType();
5914
5915 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
5916
5917 // Transform type arguments.
5918 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
5919 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
5920 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
5921 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
5922 QualType TypeArg = TypeArgInfo->getType();
5923 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
5924 AnyChanged = true;
5925
5926 // We have a pack expansion. Instantiate it.
5927 const auto *PackExpansion = PackExpansionLoc.getType()
5928 ->castAs<PackExpansionType>();
5929 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5930 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5931 Unexpanded);
5932 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5933
5934 // Determine whether the set of unexpanded parameter packs can
5935 // and should be expanded.
5936 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
5937 bool Expand = false;
5938 bool RetainExpansion = false;
5939 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5940 if (getDerived().TryExpandParameterPacks(
5941 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
5942 Unexpanded, Expand, RetainExpansion, NumExpansions))
5943 return QualType();
5944
5945 if (!Expand) {
5946 // We can't expand this pack expansion into separate arguments yet;
5947 // just substitute into the pattern and create a new pack expansion
5948 // type.
5949 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5950
5951 TypeLocBuilder TypeArgBuilder;
5952 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
5953 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
5954 PatternLoc);
5955 if (NewPatternType.isNull())
5956 return QualType();
5957
5958 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
5959 NewPatternType, NumExpansions);
5960 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
5961 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
5962 NewTypeArgInfos.push_back(
5963 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
5964 continue;
5965 }
5966
5967 // Substitute into the pack expansion pattern for each slice of the
5968 // pack.
5969 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5970 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5971
5972 TypeLocBuilder TypeArgBuilder;
5973 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
5974
5975 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
5976 PatternLoc);
5977 if (NewTypeArg.isNull())
5978 return QualType();
5979
5980 NewTypeArgInfos.push_back(
5981 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
5982 }
5983
5984 continue;
5985 }
5986
5987 TypeLocBuilder TypeArgBuilder;
5988 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
5989 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
5990 if (NewTypeArg.isNull())
5991 return QualType();
5992
5993 // If nothing changed, just keep the old TypeSourceInfo.
5994 if (NewTypeArg == TypeArg) {
5995 NewTypeArgInfos.push_back(TypeArgInfo);
5996 continue;
5997 }
5998
5999 NewTypeArgInfos.push_back(
6000 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6001 AnyChanged = true;
6002 }
6003
6004 QualType Result = TL.getType();
6005 if (getDerived().AlwaysRebuild() || AnyChanged) {
6006 // Rebuild the type.
6007 Result = getDerived().RebuildObjCObjectType(
6008 BaseType,
6009 TL.getLocStart(),
6010 TL.getTypeArgsLAngleLoc(),
6011 NewTypeArgInfos,
6012 TL.getTypeArgsRAngleLoc(),
6013 TL.getProtocolLAngleLoc(),
6014 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
6015 TL.getNumProtocols()),
6016 TL.getProtocolLocs(),
6017 TL.getProtocolRAngleLoc());
6018
6019 if (Result.isNull())
6020 return QualType();
6021 }
6022
6023 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006024 NewT.setHasBaseTypeAsWritten(true);
6025 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
6026 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
6027 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
6028 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
6029 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
6030 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
6031 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
6032 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
6033 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006034}
Mike Stump11289f42009-09-09 15:08:12 +00006035
6036template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006037QualType
6038TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006039 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006040 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
6041 if (PointeeType.isNull())
6042 return QualType();
6043
6044 QualType Result = TL.getType();
6045 if (getDerived().AlwaysRebuild() ||
6046 PointeeType != TL.getPointeeLoc().getType()) {
6047 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
6048 TL.getStarLoc());
6049 if (Result.isNull())
6050 return QualType();
6051 }
6052
6053 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
6054 NewT.setStarLoc(TL.getStarLoc());
6055 return Result;
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00006056}
6057
Douglas Gregord6ff3322009-08-04 16:50:30 +00006058//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00006059// Statement transformation
6060//===----------------------------------------------------------------------===//
6061template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006062StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006063TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006064 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006065}
6066
6067template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006068StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006069TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
6070 return getDerived().TransformCompoundStmt(S, false);
6071}
6072
6073template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006074StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006075TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00006076 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00006077 Sema::CompoundScopeRAII CompoundScope(getSema());
6078
John McCall1ababa62010-08-27 19:56:05 +00006079 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00006080 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006081 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006082 for (auto *B : S->body()) {
6083 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00006084 if (Result.isInvalid()) {
6085 // Immediately fail if this was a DeclStmt, since it's very
6086 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006087 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00006088 return StmtError();
6089
6090 // Otherwise, just keep processing substatements and fail later.
6091 SubStmtInvalid = true;
6092 continue;
6093 }
Mike Stump11289f42009-09-09 15:08:12 +00006094
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006095 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006096 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006097 }
Mike Stump11289f42009-09-09 15:08:12 +00006098
John McCall1ababa62010-08-27 19:56:05 +00006099 if (SubStmtInvalid)
6100 return StmtError();
6101
Douglas Gregorebe10102009-08-20 07:17:43 +00006102 if (!getDerived().AlwaysRebuild() &&
6103 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006104 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006105
6106 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006107 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00006108 S->getRBracLoc(),
6109 IsStmtExpr);
6110}
Mike Stump11289f42009-09-09 15:08:12 +00006111
Douglas Gregorebe10102009-08-20 07:17:43 +00006112template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006113StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006114TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006115 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00006116 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00006117 EnterExpressionEvaluationContext Unevaluated(SemaRef,
6118 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006119
Eli Friedman06577382009-11-19 03:14:00 +00006120 // Transform the left-hand case value.
6121 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00006122 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00006123 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006124 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006125
Eli Friedman06577382009-11-19 03:14:00 +00006126 // Transform the right-hand case value (for the GNU case-range extension).
6127 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00006128 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00006129 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006130 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00006131 }
Mike Stump11289f42009-09-09 15:08:12 +00006132
Douglas Gregorebe10102009-08-20 07:17:43 +00006133 // Build the case statement.
6134 // Case statements are always rebuilt so that they will attached to their
6135 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006136 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00006137 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006138 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00006139 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006140 S->getColonLoc());
6141 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006142 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006143
Douglas Gregorebe10102009-08-20 07:17:43 +00006144 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00006145 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006146 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006147 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006148
Douglas Gregorebe10102009-08-20 07:17:43 +00006149 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00006150 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006151}
6152
6153template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006154StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006155TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006156 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00006157 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006158 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006159 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006160
Douglas Gregorebe10102009-08-20 07:17:43 +00006161 // Default statements are always rebuilt
6162 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006163 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006164}
Mike Stump11289f42009-09-09 15:08:12 +00006165
Douglas Gregorebe10102009-08-20 07:17:43 +00006166template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006167StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006168TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006169 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006170 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006171 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006172
Chris Lattnercab02a62011-02-17 20:34:02 +00006173 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
6174 S->getDecl());
6175 if (!LD)
6176 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00006177
6178
Douglas Gregorebe10102009-08-20 07:17:43 +00006179 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00006180 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006181 cast<LabelDecl>(LD), SourceLocation(),
6182 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006183}
Mike Stump11289f42009-09-09 15:08:12 +00006184
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006185template <typename Derived>
6186const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
6187 if (!R)
6188 return R;
6189
6190 switch (R->getKind()) {
6191// Transform attributes with a pragma spelling by calling TransformXXXAttr.
6192#define ATTR(X)
6193#define PRAGMA_SPELLING_ATTR(X) \
6194 case attr::X: \
6195 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
6196#include "clang/Basic/AttrList.inc"
6197 default:
6198 return R;
6199 }
6200}
6201
6202template <typename Derived>
6203StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
6204 bool AttrsChanged = false;
6205 SmallVector<const Attr *, 1> Attrs;
6206
6207 // Visit attributes and keep track if any are transformed.
6208 for (const auto *I : S->getAttrs()) {
6209 const Attr *R = getDerived().TransformAttr(I);
6210 AttrsChanged |= (I != R);
6211 Attrs.push_back(R);
6212 }
6213
Richard Smithc202b282012-04-14 00:33:13 +00006214 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6215 if (SubStmt.isInvalid())
6216 return StmtError();
6217
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006218 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
Richard Smithc202b282012-04-14 00:33:13 +00006219 return S;
6220
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006221 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00006222 SubStmt.get());
6223}
6224
6225template<typename Derived>
6226StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006227TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006228 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006229 Sema::ConditionResult Cond = getDerived().TransformCondition(
6230 S->getIfLoc(), S->getConditionVariable(), S->getCond(),
6231 Sema::ConditionKind::Boolean);
6232 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006233 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006234
Douglas Gregorebe10102009-08-20 07:17:43 +00006235 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00006236 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00006237 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006238 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006239
Douglas Gregorebe10102009-08-20 07:17:43 +00006240 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00006241 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00006242 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006243 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006244
Douglas Gregorebe10102009-08-20 07:17:43 +00006245 if (!getDerived().AlwaysRebuild() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006246 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006247 Then.get() == S->getThen() &&
6248 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006249 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006250
Richard Smith03a4aa32016-06-23 19:02:52 +00006251 return getDerived().RebuildIfStmt(S->getIfLoc(), Cond, Then.get(),
John McCallb268a282010-08-23 23:25:46 +00006252 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006253}
6254
6255template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006256StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006257TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006258 // Transform the condition.
Richard Smith03a4aa32016-06-23 19:02:52 +00006259 Sema::ConditionResult Cond = getDerived().TransformCondition(
6260 S->getSwitchLoc(), S->getConditionVariable(), S->getCond(),
6261 Sema::ConditionKind::Switch);
6262 if (Cond.isInvalid())
6263 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006264
Douglas Gregorebe10102009-08-20 07:17:43 +00006265 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006266 StmtResult Switch
Richard Smith03a4aa32016-06-23 19:02:52 +00006267 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond);
Douglas Gregorebe10102009-08-20 07:17:43 +00006268 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006269 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006270
Douglas Gregorebe10102009-08-20 07:17:43 +00006271 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006272 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006273 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006274 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006275
Douglas Gregorebe10102009-08-20 07:17:43 +00006276 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00006277 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
6278 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006279}
Mike Stump11289f42009-09-09 15:08:12 +00006280
Douglas Gregorebe10102009-08-20 07:17:43 +00006281template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006282StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006283TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006284 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006285 Sema::ConditionResult Cond = getDerived().TransformCondition(
6286 S->getWhileLoc(), S->getConditionVariable(), S->getCond(),
6287 Sema::ConditionKind::Boolean);
6288 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006289 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006290
Douglas Gregorebe10102009-08-20 07:17:43 +00006291 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006292 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006293 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006294 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006295
Douglas Gregorebe10102009-08-20 07:17:43 +00006296 if (!getDerived().AlwaysRebuild() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006297 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006298 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00006299 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00006300
Richard Smith03a4aa32016-06-23 19:02:52 +00006301 return getDerived().RebuildWhileStmt(S->getWhileLoc(), Cond, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006302}
Mike Stump11289f42009-09-09 15:08:12 +00006303
Douglas Gregorebe10102009-08-20 07:17:43 +00006304template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006305StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006306TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006307 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006308 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006309 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006310 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006311
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006312 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006313 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006314 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006315 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006316
Douglas Gregorebe10102009-08-20 07:17:43 +00006317 if (!getDerived().AlwaysRebuild() &&
6318 Cond.get() == S->getCond() &&
6319 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006320 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006321
John McCallb268a282010-08-23 23:25:46 +00006322 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
6323 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006324 S->getRParenLoc());
6325}
Mike Stump11289f42009-09-09 15:08:12 +00006326
Douglas Gregorebe10102009-08-20 07:17:43 +00006327template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006328StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006329TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006330 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00006331 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00006332 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006333 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006334
Alexey Bataeva636c7f2015-12-23 10:27:45 +00006335 // In OpenMP loop region loop control variable must be captured and be
6336 // private. Perform analysis of first part (if any).
6337 if (getSema().getLangOpts().OpenMP && Init.isUsable())
6338 getSema().ActOnOpenMPLoopInitialization(S->getForLoc(), Init.get());
6339
Douglas Gregorebe10102009-08-20 07:17:43 +00006340 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006341 Sema::ConditionResult Cond = getDerived().TransformCondition(
6342 S->getForLoc(), S->getConditionVariable(), S->getCond(),
6343 Sema::ConditionKind::Boolean);
6344 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006345 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006346
Douglas Gregorebe10102009-08-20 07:17:43 +00006347 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00006348 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006349 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006350 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006351
Richard Smith945f8d32013-01-14 22:39:08 +00006352 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00006353 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006354 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006355
Douglas Gregorebe10102009-08-20 07:17:43 +00006356 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006357 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006358 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006359 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006360
Douglas Gregorebe10102009-08-20 07:17:43 +00006361 if (!getDerived().AlwaysRebuild() &&
6362 Init.get() == S->getInit() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006363 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006364 Inc.get() == S->getInc() &&
6365 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006366 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006367
Douglas Gregorebe10102009-08-20 07:17:43 +00006368 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Richard Smith03a4aa32016-06-23 19:02:52 +00006369 Init.get(), Cond, FullInc,
6370 S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006371}
6372
6373template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006374StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006375TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006376 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6377 S->getLabel());
6378 if (!LD)
6379 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006380
Douglas Gregorebe10102009-08-20 07:17:43 +00006381 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00006382 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006383 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00006384}
6385
6386template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006387StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006388TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006389 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00006390 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006391 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006392 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00006393
Douglas Gregorebe10102009-08-20 07:17:43 +00006394 if (!getDerived().AlwaysRebuild() &&
6395 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006396 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006397
6398 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00006399 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006400}
6401
6402template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006403StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006404TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006405 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006406}
Mike Stump11289f42009-09-09 15:08:12 +00006407
Douglas Gregorebe10102009-08-20 07:17:43 +00006408template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006409StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006410TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006411 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006412}
Mike Stump11289f42009-09-09 15:08:12 +00006413
Douglas Gregorebe10102009-08-20 07:17:43 +00006414template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006415StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006416TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00006417 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6418 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00006419 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006420 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006421
Mike Stump11289f42009-09-09 15:08:12 +00006422 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00006423 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00006424 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006425}
Mike Stump11289f42009-09-09 15:08:12 +00006426
Douglas Gregorebe10102009-08-20 07:17:43 +00006427template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006428StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006429TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006430 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006431 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006432 for (auto *D : S->decls()) {
6433 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00006434 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00006435 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006436
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006437 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00006438 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00006439
Douglas Gregorebe10102009-08-20 07:17:43 +00006440 Decls.push_back(Transformed);
6441 }
Mike Stump11289f42009-09-09 15:08:12 +00006442
Douglas Gregorebe10102009-08-20 07:17:43 +00006443 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006444 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006445
Rafael Espindolaab417692013-07-09 12:05:01 +00006446 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006447}
Mike Stump11289f42009-09-09 15:08:12 +00006448
Douglas Gregorebe10102009-08-20 07:17:43 +00006449template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006450StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00006451TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006452
Benjamin Kramerf0623432012-08-23 22:51:59 +00006453 SmallVector<Expr*, 8> Constraints;
6454 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006455 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00006456
John McCalldadc5752010-08-24 06:29:42 +00006457 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006458 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006459
6460 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00006461
Anders Carlssonaaeef072010-01-24 05:50:09 +00006462 // Go through the outputs.
6463 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006464 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006465
Anders Carlssonaaeef072010-01-24 05:50:09 +00006466 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006467 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006468
Anders Carlssonaaeef072010-01-24 05:50:09 +00006469 // Transform the output expr.
6470 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006471 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006472 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006473 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006474
Anders Carlssonaaeef072010-01-24 05:50:09 +00006475 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006476
John McCallb268a282010-08-23 23:25:46 +00006477 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006478 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006479
Anders Carlssonaaeef072010-01-24 05:50:09 +00006480 // Go through the inputs.
6481 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006482 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006483
Anders Carlssonaaeef072010-01-24 05:50:09 +00006484 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006485 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006486
Anders Carlssonaaeef072010-01-24 05:50:09 +00006487 // Transform the input expr.
6488 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006489 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006490 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006491 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006492
Anders Carlssonaaeef072010-01-24 05:50:09 +00006493 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006494
John McCallb268a282010-08-23 23:25:46 +00006495 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006496 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006497
Anders Carlssonaaeef072010-01-24 05:50:09 +00006498 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006499 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006500
6501 // Go through the clobbers.
6502 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00006503 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00006504
6505 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006506 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00006507 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
6508 S->isVolatile(), S->getNumOutputs(),
6509 S->getNumInputs(), Names.data(),
6510 Constraints, Exprs, AsmString.get(),
6511 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006512}
6513
Chad Rosier32503022012-06-11 20:47:18 +00006514template<typename Derived>
6515StmtResult
6516TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00006517 ArrayRef<Token> AsmToks =
6518 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00006519
John McCallf413f5e2013-05-03 00:10:13 +00006520 bool HadError = false, HadChange = false;
6521
6522 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6523 SmallVector<Expr*, 8> TransformedExprs;
6524 TransformedExprs.reserve(SrcExprs.size());
6525 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6526 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
6527 if (!Result.isUsable()) {
6528 HadError = true;
6529 } else {
6530 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006531 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00006532 }
6533 }
6534
6535 if (HadError) return StmtError();
6536 if (!HadChange && !getDerived().AlwaysRebuild())
6537 return Owned(S);
6538
Chad Rosierb6f46c12012-08-15 16:53:30 +00006539 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00006540 AsmToks, S->getAsmString(),
6541 S->getNumOutputs(), S->getNumInputs(),
6542 S->getAllConstraints(), S->getClobbers(),
6543 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00006544}
Douglas Gregorebe10102009-08-20 07:17:43 +00006545
Richard Smith9f690bd2015-10-27 06:02:45 +00006546// C++ Coroutines TS
6547
6548template<typename Derived>
6549StmtResult
6550TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) {
6551 // The coroutine body should be re-formed by the caller if necessary.
6552 return getDerived().TransformStmt(S->getBody());
6553}
6554
6555template<typename Derived>
6556StmtResult
6557TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
6558 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
6559 /*NotCopyInit*/false);
6560 if (Result.isInvalid())
6561 return StmtError();
6562
6563 // Always rebuild; we don't know if this needs to be injected into a new
6564 // context or if the promise type has changed.
6565 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get());
6566}
6567
6568template<typename Derived>
6569ExprResult
6570TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) {
6571 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
6572 /*NotCopyInit*/false);
6573 if (Result.isInvalid())
6574 return ExprError();
6575
6576 // Always rebuild; we don't know if this needs to be injected into a new
6577 // context or if the promise type has changed.
6578 return getDerived().RebuildCoawaitExpr(E->getKeywordLoc(), Result.get());
6579}
6580
6581template<typename Derived>
6582ExprResult
6583TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) {
6584 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
6585 /*NotCopyInit*/false);
6586 if (Result.isInvalid())
6587 return ExprError();
6588
6589 // Always rebuild; we don't know if this needs to be injected into a new
6590 // context or if the promise type has changed.
6591 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
6592}
6593
6594// Objective-C Statements.
6595
Douglas Gregorebe10102009-08-20 07:17:43 +00006596template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006597StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006598TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006599 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00006600 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006601 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006602 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006603
Douglas Gregor96c79492010-04-23 22:50:49 +00006604 // Transform the @catch statements (if present).
6605 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006606 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00006607 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006608 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00006609 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006610 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00006611 if (Catch.get() != S->getCatchStmt(I))
6612 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006613 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006614 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006615
Douglas Gregor306de2f2010-04-22 23:59:56 +00006616 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00006617 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006618 if (S->getFinallyStmt()) {
6619 Finally = getDerived().TransformStmt(S->getFinallyStmt());
6620 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006621 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00006622 }
6623
6624 // If nothing changed, just retain this statement.
6625 if (!getDerived().AlwaysRebuild() &&
6626 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00006627 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00006628 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006629 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006630
Douglas Gregor306de2f2010-04-22 23:59:56 +00006631 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00006632 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006633 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006634}
Mike Stump11289f42009-09-09 15:08:12 +00006635
Douglas Gregorebe10102009-08-20 07:17:43 +00006636template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006637StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006638TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006639 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00006640 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006641 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006642 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006643 if (FromVar->getTypeSourceInfo()) {
6644 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
6645 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006646 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006647 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006648
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006649 QualType T;
6650 if (TSInfo)
6651 T = TSInfo->getType();
6652 else {
6653 T = getDerived().TransformType(FromVar->getType());
6654 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00006655 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006656 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006657
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006658 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6659 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00006660 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006661 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006662
John McCalldadc5752010-08-24 06:29:42 +00006663 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006664 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006665 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006666
6667 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006668 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006669 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006670}
Mike Stump11289f42009-09-09 15:08:12 +00006671
Douglas Gregorebe10102009-08-20 07:17:43 +00006672template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006673StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006674TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006675 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006676 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006677 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006678 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006679
Douglas Gregor306de2f2010-04-22 23:59:56 +00006680 // If nothing changed, just retain this statement.
6681 if (!getDerived().AlwaysRebuild() &&
6682 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006683 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006684
6685 // Build a new statement.
6686 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00006687 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006688}
Mike Stump11289f42009-09-09 15:08:12 +00006689
Douglas Gregorebe10102009-08-20 07:17:43 +00006690template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006691StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006692TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006693 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00006694 if (S->getThrowExpr()) {
6695 Operand = getDerived().TransformExpr(S->getThrowExpr());
6696 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006697 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00006698 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006699
Douglas Gregor2900c162010-04-22 21:44:01 +00006700 if (!getDerived().AlwaysRebuild() &&
6701 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006702 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006703
John McCallb268a282010-08-23 23:25:46 +00006704 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006705}
Mike Stump11289f42009-09-09 15:08:12 +00006706
Douglas Gregorebe10102009-08-20 07:17:43 +00006707template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006708StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006709TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006710 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00006711 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00006712 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00006713 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006714 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00006715 Object =
6716 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6717 Object.get());
6718 if (Object.isInvalid())
6719 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006720
Douglas Gregor6148de72010-04-22 22:01:21 +00006721 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006722 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00006723 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006724 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006725
Douglas Gregor6148de72010-04-22 22:01:21 +00006726 // If nothing change, just retain the current statement.
6727 if (!getDerived().AlwaysRebuild() &&
6728 Object.get() == S->getSynchExpr() &&
6729 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006730 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00006731
6732 // Build a new statement.
6733 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00006734 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006735}
6736
6737template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006738StmtResult
John McCall31168b02011-06-15 23:02:42 +00006739TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6740 ObjCAutoreleasePoolStmt *S) {
6741 // Transform the body.
6742 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6743 if (Body.isInvalid())
6744 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006745
John McCall31168b02011-06-15 23:02:42 +00006746 // If nothing changed, just retain this statement.
6747 if (!getDerived().AlwaysRebuild() &&
6748 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006749 return S;
John McCall31168b02011-06-15 23:02:42 +00006750
6751 // Build a new statement.
6752 return getDerived().RebuildObjCAutoreleasePoolStmt(
6753 S->getAtLoc(), Body.get());
6754}
6755
6756template<typename Derived>
6757StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006758TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006759 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006760 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006761 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006762 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006763 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006764
Douglas Gregorf68a5082010-04-22 23:10:45 +00006765 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006766 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006767 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006768 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006769
Douglas Gregorf68a5082010-04-22 23:10:45 +00006770 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006771 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006772 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006773 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006774
Douglas Gregorf68a5082010-04-22 23:10:45 +00006775 // If nothing changed, just retain this statement.
6776 if (!getDerived().AlwaysRebuild() &&
6777 Element.get() == S->getElement() &&
6778 Collection.get() == S->getCollection() &&
6779 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006780 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006781
Douglas Gregorf68a5082010-04-22 23:10:45 +00006782 // Build a new statement.
6783 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006784 Element.get(),
6785 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006786 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006787 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006788}
6789
David Majnemer5f7efef2013-10-15 09:50:08 +00006790template <typename Derived>
6791StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006792 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006793 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006794 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6795 TypeSourceInfo *T =
6796 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006797 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006798 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006799
David Majnemer5f7efef2013-10-15 09:50:08 +00006800 Var = getDerived().RebuildExceptionDecl(
6801 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6802 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006803 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006804 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006805 }
Mike Stump11289f42009-09-09 15:08:12 +00006806
Douglas Gregorebe10102009-08-20 07:17:43 +00006807 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006808 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006809 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006810 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006811
David Majnemer5f7efef2013-10-15 09:50:08 +00006812 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006813 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006814 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006815
David Majnemer5f7efef2013-10-15 09:50:08 +00006816 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006817}
Mike Stump11289f42009-09-09 15:08:12 +00006818
David Majnemer5f7efef2013-10-15 09:50:08 +00006819template <typename Derived>
6820StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006821 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006822 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006823 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006824 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006825
Douglas Gregorebe10102009-08-20 07:17:43 +00006826 // Transform the handlers.
6827 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006828 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006829 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006830 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006831 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006832 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006833
Douglas Gregorebe10102009-08-20 07:17:43 +00006834 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006835 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006836 }
Mike Stump11289f42009-09-09 15:08:12 +00006837
David Majnemer5f7efef2013-10-15 09:50:08 +00006838 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006839 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006840 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006841
John McCallb268a282010-08-23 23:25:46 +00006842 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006843 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006844}
Mike Stump11289f42009-09-09 15:08:12 +00006845
Richard Smith02e85f32011-04-14 22:09:26 +00006846template<typename Derived>
6847StmtResult
6848TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6849 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6850 if (Range.isInvalid())
6851 return StmtError();
6852
Richard Smith01694c32016-03-20 10:33:40 +00006853 StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
6854 if (Begin.isInvalid())
6855 return StmtError();
6856 StmtResult End = getDerived().TransformStmt(S->getEndStmt());
6857 if (End.isInvalid())
Richard Smith02e85f32011-04-14 22:09:26 +00006858 return StmtError();
6859
6860 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6861 if (Cond.isInvalid())
6862 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006863 if (Cond.get())
Richard Smith03a4aa32016-06-23 19:02:52 +00006864 Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get());
Eli Friedman87d32802012-01-31 22:45:40 +00006865 if (Cond.isInvalid())
6866 return StmtError();
6867 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006868 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006869
6870 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6871 if (Inc.isInvalid())
6872 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006873 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006874 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006875
6876 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6877 if (LoopVar.isInvalid())
6878 return StmtError();
6879
6880 StmtResult NewStmt = S;
6881 if (getDerived().AlwaysRebuild() ||
6882 Range.get() != S->getRangeStmt() ||
Richard Smith01694c32016-03-20 10:33:40 +00006883 Begin.get() != S->getBeginStmt() ||
6884 End.get() != S->getEndStmt() ||
Richard Smith02e85f32011-04-14 22:09:26 +00006885 Cond.get() != S->getCond() ||
6886 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006887 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006888 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00006889 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00006890 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00006891 Begin.get(), End.get(),
6892 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00006893 Inc.get(), LoopVar.get(),
6894 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006895 if (NewStmt.isInvalid())
6896 return StmtError();
6897 }
Richard Smith02e85f32011-04-14 22:09:26 +00006898
6899 StmtResult Body = getDerived().TransformStmt(S->getBody());
6900 if (Body.isInvalid())
6901 return StmtError();
6902
6903 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6904 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006905 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006906 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00006907 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00006908 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00006909 Begin.get(), End.get(),
6910 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00006911 Inc.get(), LoopVar.get(),
6912 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006913 if (NewStmt.isInvalid())
6914 return StmtError();
6915 }
Richard Smith02e85f32011-04-14 22:09:26 +00006916
6917 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006918 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00006919
6920 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6921}
6922
John Wiegley1c0675e2011-04-28 01:08:34 +00006923template<typename Derived>
6924StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006925TreeTransform<Derived>::TransformMSDependentExistsStmt(
6926 MSDependentExistsStmt *S) {
6927 // Transform the nested-name-specifier, if any.
6928 NestedNameSpecifierLoc QualifierLoc;
6929 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006930 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006931 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6932 if (!QualifierLoc)
6933 return StmtError();
6934 }
6935
6936 // Transform the declaration name.
6937 DeclarationNameInfo NameInfo = S->getNameInfo();
6938 if (NameInfo.getName()) {
6939 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6940 if (!NameInfo.getName())
6941 return StmtError();
6942 }
6943
6944 // Check whether anything changed.
6945 if (!getDerived().AlwaysRebuild() &&
6946 QualifierLoc == S->getQualifierLoc() &&
6947 NameInfo.getName() == S->getNameInfo().getName())
6948 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006949
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006950 // Determine whether this name exists, if we can.
6951 CXXScopeSpec SS;
6952 SS.Adopt(QualifierLoc);
6953 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00006954 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006955 case Sema::IER_Exists:
6956 if (S->isIfExists())
6957 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006958
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006959 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6960
6961 case Sema::IER_DoesNotExist:
6962 if (S->isIfNotExists())
6963 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006964
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006965 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006966
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006967 case Sema::IER_Dependent:
6968 Dependent = true;
6969 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006970
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006971 case Sema::IER_Error:
6972 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006973 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006974
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006975 // We need to continue with the instantiation, so do so now.
6976 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6977 if (SubStmt.isInvalid())
6978 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006979
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006980 // If we have resolved the name, just transform to the substatement.
6981 if (!Dependent)
6982 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006983
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006984 // The name is still dependent, so build a dependent expression again.
6985 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6986 S->isIfExists(),
6987 QualifierLoc,
6988 NameInfo,
6989 SubStmt.get());
6990}
6991
6992template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006993ExprResult
6994TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6995 NestedNameSpecifierLoc QualifierLoc;
6996 if (E->getQualifierLoc()) {
6997 QualifierLoc
6998 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6999 if (!QualifierLoc)
7000 return ExprError();
7001 }
7002
7003 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
7004 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
7005 if (!PD)
7006 return ExprError();
7007
7008 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
7009 if (Base.isInvalid())
7010 return ExprError();
7011
7012 return new (SemaRef.getASTContext())
7013 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
7014 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
7015 QualifierLoc, E->getMemberLoc());
7016}
7017
David Majnemerfad8f482013-10-15 09:33:02 +00007018template <typename Derived>
Alexey Bataevf7630272015-11-25 12:01:00 +00007019ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr(
7020 MSPropertySubscriptExpr *E) {
7021 auto BaseRes = getDerived().TransformExpr(E->getBase());
7022 if (BaseRes.isInvalid())
7023 return ExprError();
7024 auto IdxRes = getDerived().TransformExpr(E->getIdx());
7025 if (IdxRes.isInvalid())
7026 return ExprError();
7027
7028 if (!getDerived().AlwaysRebuild() &&
7029 BaseRes.get() == E->getBase() &&
7030 IdxRes.get() == E->getIdx())
7031 return E;
7032
7033 return getDerived().RebuildArraySubscriptExpr(
7034 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
7035}
7036
7037template <typename Derived>
David Majnemerfad8f482013-10-15 09:33:02 +00007038StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007039 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007040 if (TryBlock.isInvalid())
7041 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007042
7043 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00007044 if (Handler.isInvalid())
7045 return StmtError();
7046
David Majnemerfad8f482013-10-15 09:33:02 +00007047 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
7048 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007049 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00007050
Warren Huntf6be4cb2014-07-25 20:52:51 +00007051 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
7052 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007053}
7054
David Majnemerfad8f482013-10-15 09:33:02 +00007055template <typename Derived>
7056StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007057 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007058 if (Block.isInvalid())
7059 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007060
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007061 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007062}
7063
David Majnemerfad8f482013-10-15 09:33:02 +00007064template <typename Derived>
7065StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00007066 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00007067 if (FilterExpr.isInvalid())
7068 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007069
David Majnemer7e755502013-10-15 09:30:14 +00007070 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007071 if (Block.isInvalid())
7072 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007073
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007074 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
7075 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007076}
7077
David Majnemerfad8f482013-10-15 09:33:02 +00007078template <typename Derived>
7079StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
7080 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00007081 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
7082 else
7083 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
7084}
7085
Nico Weber9b982072014-07-07 00:12:30 +00007086template<typename Derived>
7087StmtResult
7088TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
7089 return S;
7090}
7091
Alexander Musman64d33f12014-06-04 07:53:32 +00007092//===----------------------------------------------------------------------===//
7093// OpenMP directive transformation
7094//===----------------------------------------------------------------------===//
7095template <typename Derived>
7096StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
7097 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007098
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007099 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00007100 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007101 ArrayRef<OMPClause *> Clauses = D->clauses();
7102 TClauses.reserve(Clauses.size());
7103 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
7104 I != E; ++I) {
7105 if (*I) {
Alexey Bataevaac108a2015-06-23 04:51:00 +00007106 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007107 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevaac108a2015-06-23 04:51:00 +00007108 getDerived().getSema().EndOpenMPClause();
Alexey Bataevc5e02582014-06-16 07:08:35 +00007109 if (Clause)
7110 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00007111 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00007112 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007113 }
7114 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007115 StmtResult AssociatedStmt;
Alexey Bataeveb482352015-12-18 05:05:56 +00007116 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00007117 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
7118 /*CurScope=*/nullptr);
7119 StmtResult Body;
7120 {
7121 Sema::CompoundScopeRAII CompoundScope(getSema());
7122 Body = getDerived().TransformStmt(
7123 cast<CapturedStmt>(D->getAssociatedStmt())->getCapturedStmt());
7124 }
7125 AssociatedStmt =
7126 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
Alexey Bataev68446b72014-07-18 07:47:19 +00007127 if (AssociatedStmt.isInvalid()) {
7128 return StmtError();
7129 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00007130 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007131 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007132 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00007133 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007134
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007135 // Transform directive name for 'omp critical' directive.
7136 DeclarationNameInfo DirName;
7137 if (D->getDirectiveKind() == OMPD_critical) {
7138 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
7139 DirName = getDerived().TransformDeclarationNameInfo(DirName);
7140 }
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007141 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
7142 if (D->getDirectiveKind() == OMPD_cancellation_point) {
7143 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
Alexey Bataev80909872015-07-02 11:25:17 +00007144 } else if (D->getDirectiveKind() == OMPD_cancel) {
7145 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007146 }
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007147
Alexander Musman64d33f12014-06-04 07:53:32 +00007148 return getDerived().RebuildOMPExecutableDirective(
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007149 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
7150 AssociatedStmt.get(), D->getLocStart(), D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007151}
7152
Alexander Musman64d33f12014-06-04 07:53:32 +00007153template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007154StmtResult
7155TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
7156 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007157 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
7158 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007159 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7160 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7161 return Res;
7162}
7163
Alexander Musman64d33f12014-06-04 07:53:32 +00007164template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007165StmtResult
7166TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
7167 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007168 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
7169 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007170 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7171 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007172 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007173}
7174
Alexey Bataevf29276e2014-06-18 04:14:57 +00007175template <typename Derived>
7176StmtResult
7177TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
7178 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007179 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
7180 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00007181 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7182 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7183 return Res;
7184}
7185
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007186template <typename Derived>
7187StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00007188TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
7189 DeclarationNameInfo DirName;
7190 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
7191 D->getLocStart());
7192 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7193 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7194 return Res;
7195}
7196
7197template <typename Derived>
7198StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007199TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
7200 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007201 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
7202 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007203 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7204 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7205 return Res;
7206}
7207
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007208template <typename Derived>
7209StmtResult
7210TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
7211 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007212 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
7213 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007214 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7215 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7216 return Res;
7217}
7218
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007219template <typename Derived>
7220StmtResult
7221TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
7222 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007223 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
7224 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007225 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7226 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7227 return Res;
7228}
7229
Alexey Bataev4acb8592014-07-07 13:01:15 +00007230template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00007231StmtResult
7232TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
7233 DeclarationNameInfo DirName;
7234 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
7235 D->getLocStart());
7236 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7237 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7238 return Res;
7239}
7240
7241template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007242StmtResult
7243TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
7244 getDerived().getSema().StartOpenMPDSABlock(
7245 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
7246 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7247 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7248 return Res;
7249}
7250
7251template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00007252StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
7253 OMPParallelForDirective *D) {
7254 DeclarationNameInfo DirName;
7255 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
7256 nullptr, D->getLocStart());
7257 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7258 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7259 return Res;
7260}
7261
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007262template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00007263StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
7264 OMPParallelForSimdDirective *D) {
7265 DeclarationNameInfo DirName;
7266 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
7267 nullptr, D->getLocStart());
7268 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7269 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7270 return Res;
7271}
7272
7273template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007274StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
7275 OMPParallelSectionsDirective *D) {
7276 DeclarationNameInfo DirName;
7277 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
7278 nullptr, D->getLocStart());
7279 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7280 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7281 return Res;
7282}
7283
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00007284template <typename Derived>
7285StmtResult
7286TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
7287 DeclarationNameInfo DirName;
7288 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
7289 D->getLocStart());
7290 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7291 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7292 return Res;
7293}
7294
Alexey Bataev68446b72014-07-18 07:47:19 +00007295template <typename Derived>
7296StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
7297 OMPTaskyieldDirective *D) {
7298 DeclarationNameInfo DirName;
7299 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
7300 D->getLocStart());
7301 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7302 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7303 return Res;
7304}
7305
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00007306template <typename Derived>
7307StmtResult
7308TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
7309 DeclarationNameInfo DirName;
7310 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
7311 D->getLocStart());
7312 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7313 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7314 return Res;
7315}
7316
Alexey Bataev2df347a2014-07-18 10:17:07 +00007317template <typename Derived>
7318StmtResult
7319TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
7320 DeclarationNameInfo DirName;
7321 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
7322 D->getLocStart());
7323 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7324 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7325 return Res;
7326}
7327
Alexey Bataev6125da92014-07-21 11:26:11 +00007328template <typename Derived>
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00007329StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
7330 OMPTaskgroupDirective *D) {
7331 DeclarationNameInfo DirName;
7332 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
7333 D->getLocStart());
7334 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7335 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7336 return Res;
7337}
7338
7339template <typename Derived>
Alexey Bataev6125da92014-07-21 11:26:11 +00007340StmtResult
7341TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
7342 DeclarationNameInfo DirName;
7343 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
7344 D->getLocStart());
7345 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7346 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7347 return Res;
7348}
7349
Alexey Bataev9fb6e642014-07-22 06:45:04 +00007350template <typename Derived>
7351StmtResult
7352TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
7353 DeclarationNameInfo DirName;
7354 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
7355 D->getLocStart());
7356 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7357 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7358 return Res;
7359}
7360
Alexey Bataev0162e452014-07-22 10:10:35 +00007361template <typename Derived>
7362StmtResult
7363TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
7364 DeclarationNameInfo DirName;
7365 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
7366 D->getLocStart());
7367 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7368 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7369 return Res;
7370}
7371
Alexey Bataev0bd520b2014-09-19 08:19:49 +00007372template <typename Derived>
7373StmtResult
7374TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
7375 DeclarationNameInfo DirName;
7376 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
7377 D->getLocStart());
7378 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7379 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7380 return Res;
7381}
7382
Alexey Bataev13314bf2014-10-09 04:18:56 +00007383template <typename Derived>
Michael Wong65f367f2015-07-21 13:44:28 +00007384StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
7385 OMPTargetDataDirective *D) {
7386 DeclarationNameInfo DirName;
7387 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
7388 D->getLocStart());
7389 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7390 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7391 return Res;
7392}
7393
7394template <typename Derived>
Samuel Antaodf67fc42016-01-19 19:15:56 +00007395StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective(
7396 OMPTargetEnterDataDirective *D) {
7397 DeclarationNameInfo DirName;
7398 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_enter_data, DirName,
7399 nullptr, D->getLocStart());
7400 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7401 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7402 return Res;
7403}
7404
7405template <typename Derived>
Samuel Antao72590762016-01-19 20:04:50 +00007406StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective(
7407 OMPTargetExitDataDirective *D) {
7408 DeclarationNameInfo DirName;
7409 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_exit_data, DirName,
7410 nullptr, D->getLocStart());
7411 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7412 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7413 return Res;
7414}
7415
7416template <typename Derived>
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +00007417StmtResult TreeTransform<Derived>::TransformOMPTargetParallelDirective(
7418 OMPTargetParallelDirective *D) {
7419 DeclarationNameInfo DirName;
7420 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel, DirName,
7421 nullptr, D->getLocStart());
7422 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7423 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7424 return Res;
7425}
7426
7427template <typename Derived>
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +00007428StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForDirective(
7429 OMPTargetParallelForDirective *D) {
7430 DeclarationNameInfo DirName;
7431 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for, DirName,
7432 nullptr, D->getLocStart());
7433 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7434 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7435 return Res;
7436}
7437
7438template <typename Derived>
Samuel Antao686c70c2016-05-26 17:30:50 +00007439StmtResult TreeTransform<Derived>::TransformOMPTargetUpdateDirective(
7440 OMPTargetUpdateDirective *D) {
7441 DeclarationNameInfo DirName;
7442 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_update, DirName,
7443 nullptr, D->getLocStart());
7444 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7445 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7446 return Res;
7447}
7448
7449template <typename Derived>
Alexey Bataev13314bf2014-10-09 04:18:56 +00007450StmtResult
7451TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
7452 DeclarationNameInfo DirName;
7453 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
7454 D->getLocStart());
7455 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7456 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7457 return Res;
7458}
7459
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007460template <typename Derived>
7461StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
7462 OMPCancellationPointDirective *D) {
7463 DeclarationNameInfo DirName;
7464 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
7465 nullptr, D->getLocStart());
7466 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7467 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7468 return Res;
7469}
7470
Alexey Bataev80909872015-07-02 11:25:17 +00007471template <typename Derived>
7472StmtResult
7473TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
7474 DeclarationNameInfo DirName;
7475 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
7476 D->getLocStart());
7477 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7478 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7479 return Res;
7480}
7481
Alexey Bataev49f6e782015-12-01 04:18:41 +00007482template <typename Derived>
7483StmtResult
7484TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
7485 DeclarationNameInfo DirName;
7486 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr,
7487 D->getLocStart());
7488 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7489 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7490 return Res;
7491}
7492
Alexey Bataev0a6ed842015-12-03 09:40:15 +00007493template <typename Derived>
7494StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective(
7495 OMPTaskLoopSimdDirective *D) {
7496 DeclarationNameInfo DirName;
7497 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop_simd, DirName,
7498 nullptr, D->getLocStart());
7499 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7500 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7501 return Res;
7502}
7503
Carlo Bertolli6200a3d2015-12-14 14:51:25 +00007504template <typename Derived>
7505StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective(
7506 OMPDistributeDirective *D) {
7507 DeclarationNameInfo DirName;
7508 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr,
7509 D->getLocStart());
7510 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7511 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7512 return Res;
7513}
7514
Alexander Musman64d33f12014-06-04 07:53:32 +00007515//===----------------------------------------------------------------------===//
7516// OpenMP clause transformation
7517//===----------------------------------------------------------------------===//
7518template <typename Derived>
7519OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00007520 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7521 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007522 return nullptr;
Alexey Bataev6b8046a2015-09-03 07:23:48 +00007523 return getDerived().RebuildOMPIfClause(
7524 C->getNameModifier(), Cond.get(), C->getLocStart(), C->getLParenLoc(),
7525 C->getNameModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007526}
7527
Alexander Musman64d33f12014-06-04 07:53:32 +00007528template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00007529OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
7530 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7531 if (Cond.isInvalid())
7532 return nullptr;
7533 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
7534 C->getLParenLoc(), C->getLocEnd());
7535}
7536
7537template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007538OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00007539TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
7540 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
7541 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007542 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00007543 return getDerived().RebuildOMPNumThreadsClause(
7544 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00007545}
7546
Alexey Bataev62c87d22014-03-21 04:51:18 +00007547template <typename Derived>
7548OMPClause *
7549TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
7550 ExprResult E = getDerived().TransformExpr(C->getSafelen());
7551 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007552 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00007553 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007554 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00007555}
7556
Alexander Musman8bd31e62014-05-27 15:12:19 +00007557template <typename Derived>
7558OMPClause *
Alexey Bataev66b15b52015-08-21 11:14:16 +00007559TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
7560 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
7561 if (E.isInvalid())
7562 return nullptr;
7563 return getDerived().RebuildOMPSimdlenClause(
7564 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7565}
7566
7567template <typename Derived>
7568OMPClause *
Alexander Musman8bd31e62014-05-27 15:12:19 +00007569TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
7570 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
7571 if (E.isInvalid())
Hans Wennborg59dbe862015-09-29 20:56:43 +00007572 return nullptr;
Alexander Musman8bd31e62014-05-27 15:12:19 +00007573 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007574 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00007575}
7576
Alexander Musman64d33f12014-06-04 07:53:32 +00007577template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00007578OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007579TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007580 return getDerived().RebuildOMPDefaultClause(
7581 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
7582 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007583}
7584
Alexander Musman64d33f12014-06-04 07:53:32 +00007585template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007586OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007587TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007588 return getDerived().RebuildOMPProcBindClause(
7589 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
7590 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007591}
7592
Alexander Musman64d33f12014-06-04 07:53:32 +00007593template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007594OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00007595TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
7596 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
7597 if (E.isInvalid())
7598 return nullptr;
7599 return getDerived().RebuildOMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00007600 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
Alexey Bataev56dafe82014-06-20 07:16:17 +00007601 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
Alexey Bataev6402bca2015-12-28 07:25:51 +00007602 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
Alexey Bataev56dafe82014-06-20 07:16:17 +00007603 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
7604}
7605
7606template <typename Derived>
7607OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007608TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
Alexey Bataev10e775f2015-07-30 11:36:16 +00007609 ExprResult E;
7610 if (auto *Num = C->getNumForLoops()) {
7611 E = getDerived().TransformExpr(Num);
7612 if (E.isInvalid())
7613 return nullptr;
7614 }
7615 return getDerived().RebuildOMPOrderedClause(C->getLocStart(), C->getLocEnd(),
7616 C->getLParenLoc(), E.get());
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007617}
7618
7619template <typename Derived>
7620OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00007621TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
7622 // No need to rebuild this clause, no template-dependent parameters.
7623 return C;
7624}
7625
7626template <typename Derived>
7627OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00007628TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
7629 // No need to rebuild this clause, no template-dependent parameters.
7630 return C;
7631}
7632
7633template <typename Derived>
7634OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007635TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
7636 // No need to rebuild this clause, no template-dependent parameters.
7637 return C;
7638}
7639
7640template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00007641OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
7642 // No need to rebuild this clause, no template-dependent parameters.
7643 return C;
7644}
7645
7646template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00007647OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
7648 // No need to rebuild this clause, no template-dependent parameters.
7649 return C;
7650}
7651
7652template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007653OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00007654TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
7655 // No need to rebuild this clause, no template-dependent parameters.
7656 return C;
7657}
7658
7659template <typename Derived>
7660OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00007661TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
7662 // No need to rebuild this clause, no template-dependent parameters.
7663 return C;
7664}
7665
7666template <typename Derived>
7667OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00007668TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
7669 // No need to rebuild this clause, no template-dependent parameters.
7670 return C;
7671}
7672
7673template <typename Derived>
7674OMPClause *
Alexey Bataev346265e2015-09-25 10:37:12 +00007675TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
7676 // No need to rebuild this clause, no template-dependent parameters.
7677 return C;
7678}
7679
7680template <typename Derived>
Alexey Bataevd14d1e62015-09-28 06:39:35 +00007681OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
7682 // No need to rebuild this clause, no template-dependent parameters.
7683 return C;
7684}
7685
7686template <typename Derived>
Alexey Bataev346265e2015-09-25 10:37:12 +00007687OMPClause *
Alexey Bataevb825de12015-12-07 10:51:44 +00007688TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
7689 // No need to rebuild this clause, no template-dependent parameters.
7690 return C;
7691}
7692
7693template <typename Derived>
7694OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007695TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007696 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007697 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007698 for (auto *VE : C->varlists()) {
7699 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007700 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007701 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007702 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007703 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007704 return getDerived().RebuildOMPPrivateClause(
7705 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007706}
7707
Alexander Musman64d33f12014-06-04 07:53:32 +00007708template <typename Derived>
7709OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
7710 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007711 llvm::SmallVector<Expr *, 16> Vars;
7712 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007713 for (auto *VE : C->varlists()) {
7714 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007715 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007716 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007717 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007718 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007719 return getDerived().RebuildOMPFirstprivateClause(
7720 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007721}
7722
Alexander Musman64d33f12014-06-04 07:53:32 +00007723template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007724OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00007725TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
7726 llvm::SmallVector<Expr *, 16> Vars;
7727 Vars.reserve(C->varlist_size());
7728 for (auto *VE : C->varlists()) {
7729 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7730 if (EVar.isInvalid())
7731 return nullptr;
7732 Vars.push_back(EVar.get());
7733 }
7734 return getDerived().RebuildOMPLastprivateClause(
7735 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7736}
7737
7738template <typename Derived>
7739OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00007740TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
7741 llvm::SmallVector<Expr *, 16> Vars;
7742 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007743 for (auto *VE : C->varlists()) {
7744 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00007745 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007746 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007747 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007748 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007749 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
7750 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007751}
7752
Alexander Musman64d33f12014-06-04 07:53:32 +00007753template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007754OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00007755TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
7756 llvm::SmallVector<Expr *, 16> Vars;
7757 Vars.reserve(C->varlist_size());
7758 for (auto *VE : C->varlists()) {
7759 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7760 if (EVar.isInvalid())
7761 return nullptr;
7762 Vars.push_back(EVar.get());
7763 }
7764 CXXScopeSpec ReductionIdScopeSpec;
7765 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
7766
7767 DeclarationNameInfo NameInfo = C->getNameInfo();
7768 if (NameInfo.getName()) {
7769 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7770 if (!NameInfo.getName())
7771 return nullptr;
7772 }
Alexey Bataeva839ddd2016-03-17 10:19:46 +00007773 // Build a list of all UDR decls with the same names ranged by the Scopes.
7774 // The Scope boundary is a duplication of the previous decl.
7775 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
7776 for (auto *E : C->reduction_ops()) {
7777 // Transform all the decls.
7778 if (E) {
7779 auto *ULE = cast<UnresolvedLookupExpr>(E);
7780 UnresolvedSet<8> Decls;
7781 for (auto *D : ULE->decls()) {
7782 NamedDecl *InstD =
7783 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
7784 Decls.addDecl(InstD, InstD->getAccess());
7785 }
7786 UnresolvedReductions.push_back(
7787 UnresolvedLookupExpr::Create(
7788 SemaRef.Context, /*NamingClass=*/nullptr,
7789 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context),
7790 NameInfo, /*ADL=*/true, ULE->isOverloaded(),
7791 Decls.begin(), Decls.end()));
7792 } else
7793 UnresolvedReductions.push_back(nullptr);
7794 }
Alexey Bataevc5e02582014-06-16 07:08:35 +00007795 return getDerived().RebuildOMPReductionClause(
7796 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
Alexey Bataeva839ddd2016-03-17 10:19:46 +00007797 C->getLocEnd(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00007798}
7799
7800template <typename Derived>
7801OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00007802TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
7803 llvm::SmallVector<Expr *, 16> Vars;
7804 Vars.reserve(C->varlist_size());
7805 for (auto *VE : C->varlists()) {
7806 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7807 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007808 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007809 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00007810 }
7811 ExprResult Step = getDerived().TransformExpr(C->getStep());
7812 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007813 return nullptr;
Alexey Bataev182227b2015-08-20 10:54:39 +00007814 return getDerived().RebuildOMPLinearClause(
7815 Vars, Step.get(), C->getLocStart(), C->getLParenLoc(), C->getModifier(),
7816 C->getModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00007817}
7818
Alexander Musman64d33f12014-06-04 07:53:32 +00007819template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00007820OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007821TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
7822 llvm::SmallVector<Expr *, 16> Vars;
7823 Vars.reserve(C->varlist_size());
7824 for (auto *VE : C->varlists()) {
7825 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7826 if (EVar.isInvalid())
7827 return nullptr;
7828 Vars.push_back(EVar.get());
7829 }
7830 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
7831 if (Alignment.isInvalid())
7832 return nullptr;
7833 return getDerived().RebuildOMPAlignedClause(
7834 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
7835 C->getColonLoc(), C->getLocEnd());
7836}
7837
Alexander Musman64d33f12014-06-04 07:53:32 +00007838template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007839OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007840TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
7841 llvm::SmallVector<Expr *, 16> Vars;
7842 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007843 for (auto *VE : C->varlists()) {
7844 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007845 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007846 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007847 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007848 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007849 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
7850 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007851}
7852
Alexey Bataevbae9a792014-06-27 10:37:06 +00007853template <typename Derived>
7854OMPClause *
7855TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
7856 llvm::SmallVector<Expr *, 16> Vars;
7857 Vars.reserve(C->varlist_size());
7858 for (auto *VE : C->varlists()) {
7859 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7860 if (EVar.isInvalid())
7861 return nullptr;
7862 Vars.push_back(EVar.get());
7863 }
7864 return getDerived().RebuildOMPCopyprivateClause(
7865 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7866}
7867
Alexey Bataev6125da92014-07-21 11:26:11 +00007868template <typename Derived>
7869OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
7870 llvm::SmallVector<Expr *, 16> Vars;
7871 Vars.reserve(C->varlist_size());
7872 for (auto *VE : C->varlists()) {
7873 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7874 if (EVar.isInvalid())
7875 return nullptr;
7876 Vars.push_back(EVar.get());
7877 }
7878 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
7879 C->getLParenLoc(), C->getLocEnd());
7880}
7881
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00007882template <typename Derived>
7883OMPClause *
7884TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
7885 llvm::SmallVector<Expr *, 16> Vars;
7886 Vars.reserve(C->varlist_size());
7887 for (auto *VE : C->varlists()) {
7888 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7889 if (EVar.isInvalid())
7890 return nullptr;
7891 Vars.push_back(EVar.get());
7892 }
7893 return getDerived().RebuildOMPDependClause(
7894 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
7895 C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7896}
7897
Michael Wonge710d542015-08-07 16:16:36 +00007898template <typename Derived>
7899OMPClause *
7900TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
7901 ExprResult E = getDerived().TransformExpr(C->getDevice());
7902 if (E.isInvalid())
7903 return nullptr;
7904 return getDerived().RebuildOMPDeviceClause(
7905 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7906}
7907
Kelvin Li0bff7af2015-11-23 05:32:03 +00007908template <typename Derived>
7909OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
7910 llvm::SmallVector<Expr *, 16> Vars;
7911 Vars.reserve(C->varlist_size());
7912 for (auto *VE : C->varlists()) {
7913 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7914 if (EVar.isInvalid())
7915 return nullptr;
7916 Vars.push_back(EVar.get());
7917 }
7918 return getDerived().RebuildOMPMapClause(
Samuel Antao23abd722016-01-19 20:40:49 +00007919 C->getMapTypeModifier(), C->getMapType(), C->isImplicitMapType(),
7920 C->getMapLoc(), C->getColonLoc(), Vars, C->getLocStart(),
7921 C->getLParenLoc(), C->getLocEnd());
Kelvin Li0bff7af2015-11-23 05:32:03 +00007922}
7923
Kelvin Li099bb8c2015-11-24 20:50:12 +00007924template <typename Derived>
7925OMPClause *
7926TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
7927 ExprResult E = getDerived().TransformExpr(C->getNumTeams());
7928 if (E.isInvalid())
7929 return nullptr;
7930 return getDerived().RebuildOMPNumTeamsClause(
7931 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7932}
7933
Kelvin Lia15fb1a2015-11-27 18:47:36 +00007934template <typename Derived>
7935OMPClause *
7936TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
7937 ExprResult E = getDerived().TransformExpr(C->getThreadLimit());
7938 if (E.isInvalid())
7939 return nullptr;
7940 return getDerived().RebuildOMPThreadLimitClause(
7941 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7942}
7943
Alexey Bataeva0569352015-12-01 10:17:31 +00007944template <typename Derived>
7945OMPClause *
7946TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
7947 ExprResult E = getDerived().TransformExpr(C->getPriority());
7948 if (E.isInvalid())
7949 return nullptr;
7950 return getDerived().RebuildOMPPriorityClause(
7951 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7952}
7953
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00007954template <typename Derived>
7955OMPClause *
7956TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
7957 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
7958 if (E.isInvalid())
7959 return nullptr;
7960 return getDerived().RebuildOMPGrainsizeClause(
7961 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7962}
7963
Alexey Bataev382967a2015-12-08 12:06:20 +00007964template <typename Derived>
7965OMPClause *
7966TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
7967 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
7968 if (E.isInvalid())
7969 return nullptr;
7970 return getDerived().RebuildOMPNumTasksClause(
7971 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7972}
7973
Alexey Bataev28c75412015-12-15 08:19:24 +00007974template <typename Derived>
7975OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) {
7976 ExprResult E = getDerived().TransformExpr(C->getHint());
7977 if (E.isInvalid())
7978 return nullptr;
7979 return getDerived().RebuildOMPHintClause(E.get(), C->getLocStart(),
7980 C->getLParenLoc(), C->getLocEnd());
7981}
7982
Carlo Bertollib4adf552016-01-15 18:50:31 +00007983template <typename Derived>
7984OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause(
7985 OMPDistScheduleClause *C) {
7986 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
7987 if (E.isInvalid())
7988 return nullptr;
7989 return getDerived().RebuildOMPDistScheduleClause(
7990 C->getDistScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
7991 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
7992}
7993
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +00007994template <typename Derived>
7995OMPClause *
7996TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) {
7997 return C;
7998}
7999
Samuel Antao661c0902016-05-26 17:39:58 +00008000template <typename Derived>
8001OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) {
8002 llvm::SmallVector<Expr *, 16> Vars;
8003 Vars.reserve(C->varlist_size());
8004 for (auto *VE : C->varlists()) {
8005 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8006 if (EVar.isInvalid())
8007 return 0;
8008 Vars.push_back(EVar.get());
8009 }
8010 return getDerived().RebuildOMPToClause(Vars, C->getLocStart(),
8011 C->getLParenLoc(), C->getLocEnd());
8012}
8013
Samuel Antaoec172c62016-05-26 17:49:04 +00008014template <typename Derived>
8015OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) {
8016 llvm::SmallVector<Expr *, 16> Vars;
8017 Vars.reserve(C->varlist_size());
8018 for (auto *VE : C->varlists()) {
8019 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8020 if (EVar.isInvalid())
8021 return 0;
8022 Vars.push_back(EVar.get());
8023 }
8024 return getDerived().RebuildOMPFromClause(Vars, C->getLocStart(),
8025 C->getLParenLoc(), C->getLocEnd());
8026}
8027
Douglas Gregorebe10102009-08-20 07:17:43 +00008028//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00008029// Expression transformation
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>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00008034 if (!E->isTypeDependent())
8035 return E;
8036
8037 return getDerived().RebuildPredefinedExpr(E->getLocation(),
8038 E->getIdentType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008039}
Mike Stump11289f42009-09-09 15:08:12 +00008040
8041template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008042ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008043TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00008044 NestedNameSpecifierLoc QualifierLoc;
8045 if (E->getQualifierLoc()) {
8046 QualifierLoc
8047 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8048 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008049 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008050 }
John McCallce546572009-12-08 09:08:17 +00008051
8052 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008053 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8054 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008055 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00008056 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008057
John McCall815039a2010-08-17 21:27:17 +00008058 DeclarationNameInfo NameInfo = E->getNameInfo();
8059 if (NameInfo.getName()) {
8060 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8061 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008062 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00008063 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008064
8065 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00008066 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008067 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008068 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00008069 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00008070
8071 // Mark it referenced in the new context regardless.
8072 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00008073 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00008074
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008075 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008076 }
John McCallce546572009-12-08 09:08:17 +00008077
Craig Topperc3ec1492014-05-26 06:22:03 +00008078 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00008079 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00008080 TemplateArgs = &TransArgs;
8081 TransArgs.setLAngleLoc(E->getLAngleLoc());
8082 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008083 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8084 E->getNumTemplateArgs(),
8085 TransArgs))
8086 return ExprError();
John McCallce546572009-12-08 09:08:17 +00008087 }
8088
Chad Rosier1dcde962012-08-08 18:46:20 +00008089 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00008090 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00008091}
Mike Stump11289f42009-09-09 15:08:12 +00008092
Douglas Gregora16548e2009-08-11 05:31:07 +00008093template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008094ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008095TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008096 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008097}
Mike Stump11289f42009-09-09 15:08:12 +00008098
Douglas Gregora16548e2009-08-11 05:31:07 +00008099template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008100ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008101TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008102 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008103}
Mike Stump11289f42009-09-09 15:08:12 +00008104
Douglas Gregora16548e2009-08-11 05:31:07 +00008105template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008106ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008107TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008108 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008109}
Mike Stump11289f42009-09-09 15:08:12 +00008110
Douglas Gregora16548e2009-08-11 05:31:07 +00008111template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008112ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008113TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008114 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008115}
Mike Stump11289f42009-09-09 15:08:12 +00008116
Douglas Gregora16548e2009-08-11 05:31:07 +00008117template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008118ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008119TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008120 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008121}
8122
8123template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008124ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00008125TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00008126 if (FunctionDecl *FD = E->getDirectCallee())
8127 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00008128 return SemaRef.MaybeBindToTemporary(E);
8129}
8130
8131template<typename Derived>
8132ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00008133TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
8134 ExprResult ControllingExpr =
8135 getDerived().TransformExpr(E->getControllingExpr());
8136 if (ControllingExpr.isInvalid())
8137 return ExprError();
8138
Chris Lattner01cf8db2011-07-20 06:58:45 +00008139 SmallVector<Expr *, 4> AssocExprs;
8140 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00008141 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
8142 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
8143 if (TS) {
8144 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
8145 if (!AssocType)
8146 return ExprError();
8147 AssocTypes.push_back(AssocType);
8148 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00008149 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00008150 }
8151
8152 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
8153 if (AssocExpr.isInvalid())
8154 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008155 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00008156 }
8157
8158 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
8159 E->getDefaultLoc(),
8160 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008161 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00008162 AssocTypes,
8163 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00008164}
8165
8166template<typename Derived>
8167ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008168TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008169 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008170 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008171 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008172
Douglas Gregora16548e2009-08-11 05:31:07 +00008173 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008174 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008175
John McCallb268a282010-08-23 23:25:46 +00008176 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008177 E->getRParen());
8178}
8179
Richard Smithdb2630f2012-10-21 03:28:35 +00008180/// \brief The operand of a unary address-of operator has special rules: it's
8181/// allowed to refer to a non-static member of a class even if there's no 'this'
8182/// object available.
8183template<typename Derived>
8184ExprResult
8185TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
8186 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00008187 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00008188 else
8189 return getDerived().TransformExpr(E);
8190}
8191
Mike Stump11289f42009-09-09 15:08:12 +00008192template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008193ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008194TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00008195 ExprResult SubExpr;
8196 if (E->getOpcode() == UO_AddrOf)
8197 SubExpr = TransformAddressOfOperand(E->getSubExpr());
8198 else
8199 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008200 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008201 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008202
Douglas Gregora16548e2009-08-11 05:31:07 +00008203 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008204 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008205
Douglas Gregora16548e2009-08-11 05:31:07 +00008206 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
8207 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008208 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008209}
Mike Stump11289f42009-09-09 15:08:12 +00008210
Douglas Gregora16548e2009-08-11 05:31:07 +00008211template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008212ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00008213TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
8214 // Transform the type.
8215 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
8216 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00008217 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008218
Douglas Gregor882211c2010-04-28 22:16:22 +00008219 // Transform all of the components into components similar to what the
8220 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00008221 // FIXME: It would be slightly more efficient in the non-dependent case to
8222 // just map FieldDecls, rather than requiring the rebuilder to look for
8223 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00008224 // template code that we don't care.
8225 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00008226 typedef Sema::OffsetOfComponent Component;
Chris Lattner01cf8db2011-07-20 06:58:45 +00008227 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00008228 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
James Y Knight7281c352015-12-29 22:31:18 +00008229 const OffsetOfNode &ON = E->getComponent(I);
Douglas Gregor882211c2010-04-28 22:16:22 +00008230 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00008231 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00008232 Comp.LocStart = ON.getSourceRange().getBegin();
8233 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00008234 switch (ON.getKind()) {
James Y Knight7281c352015-12-29 22:31:18 +00008235 case OffsetOfNode::Array: {
Douglas Gregor882211c2010-04-28 22:16:22 +00008236 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00008237 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00008238 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008239 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008240
Douglas Gregor882211c2010-04-28 22:16:22 +00008241 ExprChanged = ExprChanged || Index.get() != FromIndex;
8242 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00008243 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00008244 break;
8245 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008246
James Y Knight7281c352015-12-29 22:31:18 +00008247 case OffsetOfNode::Field:
8248 case OffsetOfNode::Identifier:
Douglas Gregor882211c2010-04-28 22:16:22 +00008249 Comp.isBrackets = false;
8250 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00008251 if (!Comp.U.IdentInfo)
8252 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008253
Douglas Gregor882211c2010-04-28 22:16:22 +00008254 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00008255
James Y Knight7281c352015-12-29 22:31:18 +00008256 case OffsetOfNode::Base:
Douglas Gregord1702062010-04-29 00:18:15 +00008257 // Will be recomputed during the rebuild.
8258 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00008259 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008260
Douglas Gregor882211c2010-04-28 22:16:22 +00008261 Components.push_back(Comp);
8262 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008263
Douglas Gregor882211c2010-04-28 22:16:22 +00008264 // If nothing changed, retain the existing expression.
8265 if (!getDerived().AlwaysRebuild() &&
8266 Type == E->getTypeSourceInfo() &&
8267 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008268 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00008269
Douglas Gregor882211c2010-04-28 22:16:22 +00008270 // Build a new offsetof expression.
8271 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
Craig Topperb5518242015-10-22 04:59:59 +00008272 Components, E->getRParenLoc());
Douglas Gregor882211c2010-04-28 22:16:22 +00008273}
8274
8275template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008276ExprResult
John McCall8d69a212010-11-15 23:31:06 +00008277TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
Hubert Tong2cded442015-09-01 22:50:31 +00008278 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
John McCall8d69a212010-11-15 23:31:06 +00008279 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008280 return E;
John McCall8d69a212010-11-15 23:31:06 +00008281}
8282
8283template<typename Derived>
8284ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00008285TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
8286 return E;
8287}
8288
8289template<typename Derived>
8290ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00008291TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00008292 // Rebuild the syntactic form. The original syntactic form has
8293 // opaque-value expressions in it, so strip those away and rebuild
8294 // the result. This is a really awful way of doing this, but the
8295 // better solution (rebuilding the semantic expressions and
8296 // rebinding OVEs as necessary) doesn't work; we'd need
8297 // TreeTransform to not strip away implicit conversions.
8298 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
8299 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00008300 if (result.isInvalid()) return ExprError();
8301
8302 // If that gives us a pseudo-object result back, the pseudo-object
8303 // expression must have been an lvalue-to-rvalue conversion which we
8304 // should reapply.
8305 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008306 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00008307
8308 return result;
8309}
8310
8311template<typename Derived>
8312ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00008313TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
8314 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008315 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00008316 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00008317
John McCallbcd03502009-12-07 02:54:59 +00008318 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00008319 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008320 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008321
John McCall4c98fd82009-11-04 07:28:41 +00008322 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008323 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008324
Peter Collingbournee190dee2011-03-11 19:24:49 +00008325 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
8326 E->getKind(),
8327 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008328 }
Mike Stump11289f42009-09-09 15:08:12 +00008329
Eli Friedmane4f22df2012-02-29 04:03:55 +00008330 // C++0x [expr.sizeof]p1:
8331 // The operand is either an expression, which is an unevaluated operand
8332 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00008333 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8334 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008335
Reid Kleckner32506ed2014-06-12 23:03:48 +00008336 // Try to recover if we have something like sizeof(T::X) where X is a type.
8337 // Notably, there must be *exactly* one set of parens if X is a type.
8338 TypeSourceInfo *RecoveryTSI = nullptr;
8339 ExprResult SubExpr;
8340 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
8341 if (auto *DRE =
8342 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
8343 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
8344 PE, DRE, false, &RecoveryTSI);
8345 else
8346 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
8347
8348 if (RecoveryTSI) {
8349 return getDerived().RebuildUnaryExprOrTypeTrait(
8350 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
8351 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00008352 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008353
Eli Friedmane4f22df2012-02-29 04:03:55 +00008354 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008355 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008356
Peter Collingbournee190dee2011-03-11 19:24:49 +00008357 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
8358 E->getOperatorLoc(),
8359 E->getKind(),
8360 E->getSourceRange());
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>::TransformArraySubscriptExpr(ArraySubscriptExpr *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
8374
Douglas Gregora16548e2009-08-11 05:31:07 +00008375 if (!getDerived().AlwaysRebuild() &&
8376 LHS.get() == E->getLHS() &&
8377 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008378 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008379
John McCallb268a282010-08-23 23:25:46 +00008380 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008381 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008382 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008383 E->getRBracketLoc());
8384}
Mike Stump11289f42009-09-09 15:08:12 +00008385
Alexey Bataev1a3320e2015-08-25 14:24:04 +00008386template <typename Derived>
8387ExprResult
8388TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
8389 ExprResult Base = getDerived().TransformExpr(E->getBase());
8390 if (Base.isInvalid())
8391 return ExprError();
8392
8393 ExprResult LowerBound;
8394 if (E->getLowerBound()) {
8395 LowerBound = getDerived().TransformExpr(E->getLowerBound());
8396 if (LowerBound.isInvalid())
8397 return ExprError();
8398 }
8399
8400 ExprResult Length;
8401 if (E->getLength()) {
8402 Length = getDerived().TransformExpr(E->getLength());
8403 if (Length.isInvalid())
8404 return ExprError();
8405 }
8406
8407 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
8408 LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
8409 return E;
8410
8411 return getDerived().RebuildOMPArraySectionExpr(
8412 Base.get(), E->getBase()->getLocEnd(), LowerBound.get(), E->getColonLoc(),
8413 Length.get(), E->getRBracketLoc());
8414}
8415
Mike Stump11289f42009-09-09 15:08:12 +00008416template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008417ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008418TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008419 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00008420 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00008421 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008422 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008423
8424 // Transform arguments.
8425 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008426 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008427 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008428 &ArgChanged))
8429 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008430
Douglas Gregora16548e2009-08-11 05:31:07 +00008431 if (!getDerived().AlwaysRebuild() &&
8432 Callee.get() == E->getCallee() &&
8433 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00008434 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00008435
Douglas Gregora16548e2009-08-11 05:31:07 +00008436 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00008437 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00008438 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00008439 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008440 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008441 E->getRParenLoc());
8442}
Mike Stump11289f42009-09-09 15:08:12 +00008443
8444template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008445ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008446TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008447 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008448 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008449 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008450
Douglas Gregorea972d32011-02-28 21:54:11 +00008451 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00008452 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00008453 QualifierLoc
8454 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00008455
Douglas Gregorea972d32011-02-28 21:54:11 +00008456 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008457 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00008458 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00008459 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008460
Eli Friedman2cfcef62009-12-04 06:40:45 +00008461 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008462 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
8463 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008464 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00008465 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008466
John McCall16df1e52010-03-30 21:47:33 +00008467 NamedDecl *FoundDecl = E->getFoundDecl();
8468 if (FoundDecl == E->getMemberDecl()) {
8469 FoundDecl = Member;
8470 } else {
8471 FoundDecl = cast_or_null<NamedDecl>(
8472 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
8473 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00008474 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00008475 }
8476
Douglas Gregora16548e2009-08-11 05:31:07 +00008477 if (!getDerived().AlwaysRebuild() &&
8478 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00008479 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008480 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00008481 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00008482 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008483
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008484 // Mark it referenced in the new context regardless.
8485 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00008486 SemaRef.MarkMemberReferenced(E);
8487
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008488 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008489 }
Douglas Gregora16548e2009-08-11 05:31:07 +00008490
John McCall6b51f282009-11-23 01:53:49 +00008491 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00008492 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00008493 TransArgs.setLAngleLoc(E->getLAngleLoc());
8494 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008495 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8496 E->getNumTemplateArgs(),
8497 TransArgs))
8498 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008499 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008500
Douglas Gregora16548e2009-08-11 05:31:07 +00008501 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00008502 SourceLocation FakeOperatorLoc =
8503 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00008504
John McCall38836f02010-01-15 08:34:02 +00008505 // FIXME: to do this check properly, we will need to preserve the
8506 // first-qualifier-in-scope here, just in case we had a dependent
8507 // base (and therefore couldn't do the check) and a
8508 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00008509 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00008510
John McCallb268a282010-08-23 23:25:46 +00008511 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008512 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00008513 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008514 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008515 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008516 Member,
John McCall16df1e52010-03-30 21:47:33 +00008517 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00008518 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00008519 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00008520 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00008521}
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>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008526 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008527 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008528 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008529
John McCalldadc5752010-08-24 06:29:42 +00008530 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008531 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008532 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008533
Douglas Gregora16548e2009-08-11 05:31:07 +00008534 if (!getDerived().AlwaysRebuild() &&
8535 LHS.get() == E->getLHS() &&
8536 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008537 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008538
Lang Hames5de91cc2012-10-02 04:45:10 +00008539 Sema::FPContractStateRAII FPContractState(getSema());
8540 getSema().FPFeatures.fp_contract = E->isFPContractable();
8541
Douglas Gregora16548e2009-08-11 05:31:07 +00008542 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008543 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008544}
8545
Mike Stump11289f42009-09-09 15:08:12 +00008546template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008547ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008548TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00008549 CompoundAssignOperator *E) {
8550 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008551}
Mike Stump11289f42009-09-09 15:08:12 +00008552
Douglas Gregora16548e2009-08-11 05:31:07 +00008553template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00008554ExprResult TreeTransform<Derived>::
8555TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
8556 // Just rebuild the common and RHS expressions and see whether we
8557 // get any changes.
8558
8559 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
8560 if (commonExpr.isInvalid())
8561 return ExprError();
8562
8563 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
8564 if (rhs.isInvalid())
8565 return ExprError();
8566
8567 if (!getDerived().AlwaysRebuild() &&
8568 commonExpr.get() == e->getCommon() &&
8569 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008570 return e;
John McCallc07a0c72011-02-17 10:25:35 +00008571
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008572 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00008573 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008574 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00008575 e->getColonLoc(),
8576 rhs.get());
8577}
8578
8579template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008580ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008581TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008582 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008583 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008584 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008585
John McCalldadc5752010-08-24 06:29:42 +00008586 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008587 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008588 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008589
John McCalldadc5752010-08-24 06:29:42 +00008590 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008591 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008592 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008593
Douglas Gregora16548e2009-08-11 05:31:07 +00008594 if (!getDerived().AlwaysRebuild() &&
8595 Cond.get() == E->getCond() &&
8596 LHS.get() == E->getLHS() &&
8597 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008598 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008599
John McCallb268a282010-08-23 23:25:46 +00008600 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008601 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00008602 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008603 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008604 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008605}
Mike Stump11289f42009-09-09 15:08:12 +00008606
8607template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008608ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008609TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00008610 // Implicit casts are eliminated during transformation, since they
8611 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00008612 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008613}
Mike Stump11289f42009-09-09 15:08:12 +00008614
Douglas Gregora16548e2009-08-11 05:31:07 +00008615template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008616ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008617TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008618 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8619 if (!Type)
8620 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008621
John McCalldadc5752010-08-24 06:29:42 +00008622 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008623 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008624 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008625 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008626
Douglas Gregora16548e2009-08-11 05:31:07 +00008627 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008628 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008629 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008630 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008631
John McCall97513962010-01-15 18:39:57 +00008632 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008633 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00008634 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008635 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008636}
Mike Stump11289f42009-09-09 15:08:12 +00008637
Douglas Gregora16548e2009-08-11 05:31:07 +00008638template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008639ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008640TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00008641 TypeSourceInfo *OldT = E->getTypeSourceInfo();
8642 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
8643 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008644 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008645
John McCalldadc5752010-08-24 06:29:42 +00008646 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00008647 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008648 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008649
Douglas Gregora16548e2009-08-11 05:31:07 +00008650 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00008651 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008652 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008653 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008654
John McCall5d7aa7f2010-01-19 22:33:45 +00008655 // Note: the expression type doesn't necessarily match the
8656 // type-as-written, but that's okay, because it should always be
8657 // derivable from the initializer.
8658
John McCalle15bbff2010-01-18 19:35:47 +00008659 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00008660 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00008661 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008662}
Mike Stump11289f42009-09-09 15:08:12 +00008663
Douglas Gregora16548e2009-08-11 05:31:07 +00008664template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008665ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008666TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008667 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008668 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008669 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008670
Douglas Gregora16548e2009-08-11 05:31:07 +00008671 if (!getDerived().AlwaysRebuild() &&
8672 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008673 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008674
Douglas Gregora16548e2009-08-11 05:31:07 +00008675 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00008676 SourceLocation FakeOperatorLoc =
8677 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00008678 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008679 E->getAccessorLoc(),
8680 E->getAccessor());
8681}
Mike Stump11289f42009-09-09 15:08:12 +00008682
Douglas Gregora16548e2009-08-11 05:31:07 +00008683template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008684ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008685TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Richard Smith520449d2015-02-05 06:15:50 +00008686 if (InitListExpr *Syntactic = E->getSyntacticForm())
8687 E = Syntactic;
8688
Douglas Gregora16548e2009-08-11 05:31:07 +00008689 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00008690
Benjamin Kramerf0623432012-08-23 22:51:59 +00008691 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00008692 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00008693 Inits, &InitChanged))
8694 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008695
Richard Smith520449d2015-02-05 06:15:50 +00008696 if (!getDerived().AlwaysRebuild() && !InitChanged) {
8697 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
8698 // in some cases. We can't reuse it in general, because the syntactic and
8699 // semantic forms are linked, and we can't know that semantic form will
8700 // match even if the syntactic form does.
8701 }
Mike Stump11289f42009-09-09 15:08:12 +00008702
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008703 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00008704 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008705}
Mike Stump11289f42009-09-09 15:08:12 +00008706
Douglas Gregora16548e2009-08-11 05:31:07 +00008707template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008708ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008709TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008710 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00008711
Douglas Gregorebe10102009-08-20 07:17:43 +00008712 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00008713 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008714 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008715 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008716
Douglas Gregorebe10102009-08-20 07:17:43 +00008717 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008718 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00008719 bool ExprChanged = false;
David Majnemerf7e36092016-06-23 00:15:04 +00008720 for (const DesignatedInitExpr::Designator &D : E->designators()) {
8721 if (D.isFieldDesignator()) {
8722 Desig.AddDesignator(Designator::getField(D.getFieldName(),
8723 D.getDotLoc(),
8724 D.getFieldLoc()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008725 continue;
8726 }
Mike Stump11289f42009-09-09 15:08:12 +00008727
David Majnemerf7e36092016-06-23 00:15:04 +00008728 if (D.isArrayDesignator()) {
8729 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008730 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008731 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008732
David Majnemerf7e36092016-06-23 00:15:04 +00008733 Desig.AddDesignator(
8734 Designator::getArray(Index.get(), D.getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008735
David Majnemerf7e36092016-06-23 00:15:04 +00008736 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008737 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008738 continue;
8739 }
Mike Stump11289f42009-09-09 15:08:12 +00008740
David Majnemerf7e36092016-06-23 00:15:04 +00008741 assert(D.isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00008742 ExprResult Start
David Majnemerf7e36092016-06-23 00:15:04 +00008743 = getDerived().TransformExpr(E->getArrayRangeStart(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008744 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008745 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008746
David Majnemerf7e36092016-06-23 00:15:04 +00008747 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008748 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008749 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008750
8751 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008752 End.get(),
David Majnemerf7e36092016-06-23 00:15:04 +00008753 D.getLBracketLoc(),
8754 D.getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008755
David Majnemerf7e36092016-06-23 00:15:04 +00008756 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
8757 End.get() != E->getArrayRangeEnd(D);
Mike Stump11289f42009-09-09 15:08:12 +00008758
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008759 ArrayExprs.push_back(Start.get());
8760 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008761 }
Mike Stump11289f42009-09-09 15:08:12 +00008762
Douglas Gregora16548e2009-08-11 05:31:07 +00008763 if (!getDerived().AlwaysRebuild() &&
8764 Init.get() == E->getInit() &&
8765 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008766 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008767
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008768 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008769 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008770 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008771}
Mike Stump11289f42009-09-09 15:08:12 +00008772
Yunzhong Gaocb779302015-06-10 00:27:52 +00008773// Seems that if TransformInitListExpr() only works on the syntactic form of an
8774// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
8775template<typename Derived>
8776ExprResult
8777TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
8778 DesignatedInitUpdateExpr *E) {
8779 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
8780 "initializer");
8781 return ExprError();
8782}
8783
8784template<typename Derived>
8785ExprResult
8786TreeTransform<Derived>::TransformNoInitExpr(
8787 NoInitExpr *E) {
8788 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
8789 return ExprError();
8790}
8791
Douglas Gregora16548e2009-08-11 05:31:07 +00008792template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008793ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008794TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008795 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00008796 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00008797
Douglas Gregor3da3c062009-10-28 00:29:27 +00008798 // FIXME: Will we ever have proper type location here? Will we actually
8799 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00008800 QualType T = getDerived().TransformType(E->getType());
8801 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008802 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008803
Douglas Gregora16548e2009-08-11 05:31:07 +00008804 if (!getDerived().AlwaysRebuild() &&
8805 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008806 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008807
Douglas Gregora16548e2009-08-11 05:31:07 +00008808 return getDerived().RebuildImplicitValueInitExpr(T);
8809}
Mike Stump11289f42009-09-09 15:08:12 +00008810
Douglas Gregora16548e2009-08-11 05:31:07 +00008811template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008812ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008813TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00008814 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
8815 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008816 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008817
John McCalldadc5752010-08-24 06:29:42 +00008818 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008819 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008820 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008821
Douglas Gregora16548e2009-08-11 05:31:07 +00008822 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00008823 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008824 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008825 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008826
John McCallb268a282010-08-23 23:25:46 +00008827 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00008828 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008829}
8830
8831template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008832ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008833TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008834 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008835 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00008836 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
8837 &ArgumentChanged))
8838 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008839
Douglas Gregora16548e2009-08-11 05:31:07 +00008840 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008841 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00008842 E->getRParenLoc());
8843}
Mike Stump11289f42009-09-09 15:08:12 +00008844
Douglas Gregora16548e2009-08-11 05:31:07 +00008845/// \brief Transform an address-of-label expression.
8846///
8847/// By default, the transformation of an address-of-label expression always
8848/// rebuilds the expression, so that the label identifier can be resolved to
8849/// the corresponding label statement by semantic analysis.
8850template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008851ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008852TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00008853 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
8854 E->getLabel());
8855 if (!LD)
8856 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008857
Douglas Gregora16548e2009-08-11 05:31:07 +00008858 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00008859 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00008860}
Mike Stump11289f42009-09-09 15:08:12 +00008861
8862template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00008863ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008864TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00008865 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00008866 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00008867 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00008868 if (SubStmt.isInvalid()) {
8869 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00008870 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00008871 }
Mike Stump11289f42009-09-09 15:08:12 +00008872
Douglas Gregora16548e2009-08-11 05:31:07 +00008873 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00008874 SubStmt.get() == E->getSubStmt()) {
8875 // Calling this an 'error' is unintuitive, but it does the right thing.
8876 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008877 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00008878 }
Mike Stump11289f42009-09-09 15:08:12 +00008879
8880 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008881 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008882 E->getRParenLoc());
8883}
Mike Stump11289f42009-09-09 15:08:12 +00008884
Douglas Gregora16548e2009-08-11 05:31:07 +00008885template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008886ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008887TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008888 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008889 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008890 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008891
John McCalldadc5752010-08-24 06:29:42 +00008892 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008893 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008894 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008895
John McCalldadc5752010-08-24 06:29:42 +00008896 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008897 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008898 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008899
Douglas Gregora16548e2009-08-11 05:31:07 +00008900 if (!getDerived().AlwaysRebuild() &&
8901 Cond.get() == E->getCond() &&
8902 LHS.get() == E->getLHS() &&
8903 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008904 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008905
Douglas Gregora16548e2009-08-11 05:31:07 +00008906 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00008907 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008908 E->getRParenLoc());
8909}
Mike Stump11289f42009-09-09 15:08:12 +00008910
Douglas Gregora16548e2009-08-11 05:31:07 +00008911template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008912ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008913TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008914 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008915}
8916
8917template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008918ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008919TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008920 switch (E->getOperator()) {
8921 case OO_New:
8922 case OO_Delete:
8923 case OO_Array_New:
8924 case OO_Array_Delete:
8925 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00008926
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008927 case OO_Call: {
8928 // This is a call to an object's operator().
8929 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
8930
8931 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00008932 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008933 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008934 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008935
8936 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00008937 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
8938 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008939
8940 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008941 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008942 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00008943 Args))
8944 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008945
John McCallb268a282010-08-23 23:25:46 +00008946 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008947 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008948 E->getLocEnd());
8949 }
8950
8951#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
8952 case OO_##Name:
8953#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
8954#include "clang/Basic/OperatorKinds.def"
8955 case OO_Subscript:
8956 // Handled below.
8957 break;
8958
8959 case OO_Conditional:
8960 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008961
8962 case OO_None:
8963 case NUM_OVERLOADED_OPERATORS:
8964 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008965 }
8966
John McCalldadc5752010-08-24 06:29:42 +00008967 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00008968 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008969 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008970
Richard Smithdb2630f2012-10-21 03:28:35 +00008971 ExprResult First;
8972 if (E->getOperator() == OO_Amp)
8973 First = getDerived().TransformAddressOfOperand(E->getArg(0));
8974 else
8975 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00008976 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008977 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008978
John McCalldadc5752010-08-24 06:29:42 +00008979 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00008980 if (E->getNumArgs() == 2) {
8981 Second = getDerived().TransformExpr(E->getArg(1));
8982 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008983 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008984 }
Mike Stump11289f42009-09-09 15:08:12 +00008985
Douglas Gregora16548e2009-08-11 05:31:07 +00008986 if (!getDerived().AlwaysRebuild() &&
8987 Callee.get() == E->getCallee() &&
8988 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00008989 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008990 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00008991
Lang Hames5de91cc2012-10-02 04:45:10 +00008992 Sema::FPContractStateRAII FPContractState(getSema());
8993 getSema().FPFeatures.fp_contract = E->isFPContractable();
8994
Douglas Gregora16548e2009-08-11 05:31:07 +00008995 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
8996 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00008997 Callee.get(),
8998 First.get(),
8999 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009000}
Mike Stump11289f42009-09-09 15:08:12 +00009001
Douglas Gregora16548e2009-08-11 05:31:07 +00009002template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009003ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009004TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
9005 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009006}
Mike Stump11289f42009-09-09 15:08:12 +00009007
Douglas Gregora16548e2009-08-11 05:31:07 +00009008template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009009ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00009010TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
9011 // Transform the callee.
9012 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
9013 if (Callee.isInvalid())
9014 return ExprError();
9015
9016 // Transform exec config.
9017 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
9018 if (EC.isInvalid())
9019 return ExprError();
9020
9021 // Transform arguments.
9022 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009023 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009024 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00009025 &ArgChanged))
9026 return ExprError();
9027
9028 if (!getDerived().AlwaysRebuild() &&
9029 Callee.get() == E->getCallee() &&
9030 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009031 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00009032
9033 // FIXME: Wrong source location information for the '('.
9034 SourceLocation FakeLParenLoc
9035 = ((Expr *)Callee.get())->getSourceRange().getBegin();
9036 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009037 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00009038 E->getRParenLoc(), EC.get());
9039}
9040
9041template<typename Derived>
9042ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009043TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009044 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9045 if (!Type)
9046 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009047
John McCalldadc5752010-08-24 06:29:42 +00009048 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009049 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009050 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009051 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009052
Douglas Gregora16548e2009-08-11 05:31:07 +00009053 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009054 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009055 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009056 return E;
Nico Weberc153d242014-07-28 00:02:09 +00009057 return getDerived().RebuildCXXNamedCastExpr(
9058 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
9059 Type, E->getAngleBrackets().getEnd(),
9060 // FIXME. this should be '(' location
9061 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009062}
Mike Stump11289f42009-09-09 15:08:12 +00009063
Douglas Gregora16548e2009-08-11 05:31:07 +00009064template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009065ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009066TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
9067 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009068}
Mike Stump11289f42009-09-09 15:08:12 +00009069
9070template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009071ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009072TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
9073 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00009074}
9075
Douglas Gregora16548e2009-08-11 05:31:07 +00009076template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009077ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009078TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009079 CXXReinterpretCastExpr *E) {
9080 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009081}
Mike Stump11289f42009-09-09 15:08:12 +00009082
Douglas Gregora16548e2009-08-11 05:31:07 +00009083template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009084ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009085TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
9086 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009087}
Mike Stump11289f42009-09-09 15:08:12 +00009088
Douglas Gregora16548e2009-08-11 05:31:07 +00009089template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009090ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009091TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009092 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009093 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9094 if (!Type)
9095 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009096
John McCalldadc5752010-08-24 06:29:42 +00009097 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009098 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009099 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009100 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009101
Douglas Gregora16548e2009-08-11 05:31:07 +00009102 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009103 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009104 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009105 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009106
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009107 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00009108 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009109 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009110 E->getRParenLoc());
9111}
Mike Stump11289f42009-09-09 15:08:12 +00009112
Douglas Gregora16548e2009-08-11 05:31:07 +00009113template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009114ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009115TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009116 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00009117 TypeSourceInfo *TInfo
9118 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9119 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009120 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009121
Douglas Gregora16548e2009-08-11 05:31:07 +00009122 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00009123 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009124 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009125
Douglas Gregor9da64192010-04-26 22:37:10 +00009126 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9127 E->getLocStart(),
9128 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009129 E->getLocEnd());
9130 }
Mike Stump11289f42009-09-09 15:08:12 +00009131
Eli Friedman456f0182012-01-20 01:26:23 +00009132 // We don't know whether the subexpression is potentially evaluated until
9133 // after we perform semantic analysis. We speculatively assume it is
9134 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00009135 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00009136 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
9137 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00009138
John McCalldadc5752010-08-24 06:29:42 +00009139 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00009140 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009141 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009142
Douglas Gregora16548e2009-08-11 05:31:07 +00009143 if (!getDerived().AlwaysRebuild() &&
9144 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009145 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009146
Douglas Gregor9da64192010-04-26 22:37:10 +00009147 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9148 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00009149 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009150 E->getLocEnd());
9151}
9152
9153template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009154ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00009155TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
9156 if (E->isTypeOperand()) {
9157 TypeSourceInfo *TInfo
9158 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9159 if (!TInfo)
9160 return ExprError();
9161
9162 if (!getDerived().AlwaysRebuild() &&
9163 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009164 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00009165
Douglas Gregor69735112011-03-06 17:40:41 +00009166 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00009167 E->getLocStart(),
9168 TInfo,
9169 E->getLocEnd());
9170 }
9171
Francois Pichet9f4f2072010-09-08 12:20:18 +00009172 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9173
9174 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
9175 if (SubExpr.isInvalid())
9176 return ExprError();
9177
9178 if (!getDerived().AlwaysRebuild() &&
9179 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009180 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00009181
9182 return getDerived().RebuildCXXUuidofExpr(E->getType(),
9183 E->getLocStart(),
9184 SubExpr.get(),
9185 E->getLocEnd());
9186}
9187
9188template<typename Derived>
9189ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009190TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009191 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009192}
Mike Stump11289f42009-09-09 15:08:12 +00009193
Douglas Gregora16548e2009-08-11 05:31:07 +00009194template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009195ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009196TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009197 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009198 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009199}
Mike Stump11289f42009-09-09 15:08:12 +00009200
Douglas Gregora16548e2009-08-11 05:31:07 +00009201template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009202ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009203TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00009204 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00009205
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009206 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
9207 // Make sure that we capture 'this'.
9208 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009209 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009210 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009211
Douglas Gregorb15af892010-01-07 23:12:05 +00009212 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00009213}
Mike Stump11289f42009-09-09 15:08:12 +00009214
Douglas Gregora16548e2009-08-11 05:31:07 +00009215template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009216ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009217TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009218 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009219 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009220 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009221
Douglas Gregora16548e2009-08-11 05:31:07 +00009222 if (!getDerived().AlwaysRebuild() &&
9223 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009224 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009225
Douglas Gregor53e191ed2011-07-06 22:04:06 +00009226 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
9227 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00009228}
Mike Stump11289f42009-09-09 15:08:12 +00009229
Douglas Gregora16548e2009-08-11 05:31:07 +00009230template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009231ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009232TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00009233 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009234 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
9235 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009236 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00009237 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009238
Chandler Carruth794da4c2010-02-08 06:42:49 +00009239 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009240 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009241 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009242
Douglas Gregor033f6752009-12-23 23:03:06 +00009243 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00009244}
Mike Stump11289f42009-09-09 15:08:12 +00009245
Douglas Gregora16548e2009-08-11 05:31:07 +00009246template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009247ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00009248TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
9249 FieldDecl *Field
9250 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
9251 E->getField()));
9252 if (!Field)
9253 return ExprError();
9254
9255 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009256 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00009257
9258 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
9259}
9260
9261template<typename Derived>
9262ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00009263TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
9264 CXXScalarValueInitExpr *E) {
9265 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9266 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009267 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009268
Douglas Gregora16548e2009-08-11 05:31:07 +00009269 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009270 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009271 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009272
Chad Rosier1dcde962012-08-08 18:46:20 +00009273 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00009274 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00009275 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009276}
Mike Stump11289f42009-09-09 15:08:12 +00009277
Douglas Gregora16548e2009-08-11 05:31:07 +00009278template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009279ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009280TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009281 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00009282 TypeSourceInfo *AllocTypeInfo
9283 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
9284 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009285 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009286
Douglas Gregora16548e2009-08-11 05:31:07 +00009287 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00009288 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00009289 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009290 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009291
Douglas Gregora16548e2009-08-11 05:31:07 +00009292 // Transform the placement arguments (if any).
9293 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009294 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00009295 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00009296 E->getNumPlacementArgs(), true,
9297 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00009298 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009299
Sebastian Redl6047f072012-02-16 12:22:20 +00009300 // Transform the initializer (if any).
9301 Expr *OldInit = E->getInitializer();
9302 ExprResult NewInit;
9303 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +00009304 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +00009305 if (NewInit.isInvalid())
9306 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009307
Sebastian Redl6047f072012-02-16 12:22:20 +00009308 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00009309 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009310 if (E->getOperatorNew()) {
9311 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009312 getDerived().TransformDecl(E->getLocStart(),
9313 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009314 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00009315 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009316 }
9317
Craig Topperc3ec1492014-05-26 06:22:03 +00009318 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009319 if (E->getOperatorDelete()) {
9320 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009321 getDerived().TransformDecl(E->getLocStart(),
9322 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009323 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00009324 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009325 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009326
Douglas Gregora16548e2009-08-11 05:31:07 +00009327 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00009328 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009329 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00009330 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00009331 OperatorNew == E->getOperatorNew() &&
9332 OperatorDelete == E->getOperatorDelete() &&
9333 !ArgumentChanged) {
9334 // Mark any declarations we need as referenced.
9335 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00009336 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009337 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00009338 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009339 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00009340
Sebastian Redl6047f072012-02-16 12:22:20 +00009341 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00009342 QualType ElementType
9343 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
9344 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
9345 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
9346 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00009347 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00009348 }
9349 }
9350 }
Sebastian Redl6047f072012-02-16 12:22:20 +00009351
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009352 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009353 }
Mike Stump11289f42009-09-09 15:08:12 +00009354
Douglas Gregor0744ef62010-09-07 21:49:58 +00009355 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009356 if (!ArraySize.get()) {
9357 // If no array size was specified, but the new expression was
9358 // instantiated with an array type (e.g., "new T" where T is
9359 // instantiated with "int[4]"), extract the outer bound from the
9360 // array type as our array size. We do this with constant and
9361 // dependently-sized array types.
9362 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
9363 if (!ArrayT) {
9364 // Do nothing
9365 } else if (const ConstantArrayType *ConsArrayT
9366 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009367 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
9368 SemaRef.Context.getSizeType(),
9369 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009370 AllocType = ConsArrayT->getElementType();
9371 } else if (const DependentSizedArrayType *DepArrayT
9372 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
9373 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009374 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009375 AllocType = DepArrayT->getElementType();
9376 }
9377 }
9378 }
Sebastian Redl6047f072012-02-16 12:22:20 +00009379
Douglas Gregora16548e2009-08-11 05:31:07 +00009380 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
9381 E->isGlobalNew(),
9382 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009383 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009384 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00009385 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009386 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00009387 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00009388 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00009389 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009390 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009391}
Mike Stump11289f42009-09-09 15:08:12 +00009392
Douglas Gregora16548e2009-08-11 05:31:07 +00009393template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009394ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009395TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009396 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00009397 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009398 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009399
Douglas Gregord2d9da02010-02-26 00:38:10 +00009400 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00009401 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009402 if (E->getOperatorDelete()) {
9403 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009404 getDerived().TransformDecl(E->getLocStart(),
9405 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009406 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00009407 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009408 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009409
Douglas Gregora16548e2009-08-11 05:31:07 +00009410 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00009411 Operand.get() == E->getArgument() &&
9412 OperatorDelete == E->getOperatorDelete()) {
9413 // Mark any declarations we need as referenced.
9414 // FIXME: instantiation-specific.
9415 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009416 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00009417
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00009418 if (!E->getArgument()->isTypeDependent()) {
9419 QualType Destroyed = SemaRef.Context.getBaseElementType(
9420 E->getDestroyedType());
9421 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
9422 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00009423 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00009424 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00009425 }
9426 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009427
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009428 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009429 }
Mike Stump11289f42009-09-09 15:08:12 +00009430
Douglas Gregora16548e2009-08-11 05:31:07 +00009431 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
9432 E->isGlobalDelete(),
9433 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00009434 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009435}
Mike Stump11289f42009-09-09 15:08:12 +00009436
Douglas Gregora16548e2009-08-11 05:31:07 +00009437template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009438ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00009439TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009440 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009441 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00009442 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009443 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009444
John McCallba7bf592010-08-24 05:47:05 +00009445 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00009446 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00009447 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009448 E->getOperatorLoc(),
9449 E->isArrow()? tok::arrow : tok::period,
9450 ObjectTypePtr,
9451 MayBePseudoDestructor);
9452 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009453 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009454
John McCallba7bf592010-08-24 05:47:05 +00009455 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00009456 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
9457 if (QualifierLoc) {
9458 QualifierLoc
9459 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
9460 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00009461 return ExprError();
9462 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00009463 CXXScopeSpec SS;
9464 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00009465
Douglas Gregor678f90d2010-02-25 01:56:36 +00009466 PseudoDestructorTypeStorage Destroyed;
9467 if (E->getDestroyedTypeInfo()) {
9468 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00009469 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009470 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00009471 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009472 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00009473 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00009474 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00009475 // We aren't likely to be able to resolve the identifier down to a type
9476 // now anyway, so just retain the identifier.
9477 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
9478 E->getDestroyedTypeLoc());
9479 } else {
9480 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00009481 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009482 *E->getDestroyedTypeIdentifier(),
9483 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009484 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009485 SS, ObjectTypePtr,
9486 false);
9487 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009488 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009489
Douglas Gregor678f90d2010-02-25 01:56:36 +00009490 Destroyed
9491 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
9492 E->getDestroyedTypeLoc());
9493 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009494
Craig Topperc3ec1492014-05-26 06:22:03 +00009495 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009496 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00009497 CXXScopeSpec EmptySS;
9498 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00009499 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009500 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009501 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00009502 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009503
John McCallb268a282010-08-23 23:25:46 +00009504 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00009505 E->getOperatorLoc(),
9506 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00009507 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009508 ScopeTypeInfo,
9509 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009510 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009511 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00009512}
Mike Stump11289f42009-09-09 15:08:12 +00009513
Douglas Gregorad8a3362009-09-04 17:36:40 +00009514template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009515ExprResult
John McCalld14a8642009-11-21 08:51:07 +00009516TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009517 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00009518 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
9519 Sema::LookupOrdinaryName);
9520
9521 // Transform all the decls.
9522 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
9523 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009524 NamedDecl *InstD = static_cast<NamedDecl*>(
9525 getDerived().TransformDecl(Old->getNameLoc(),
9526 *I));
John McCall84d87672009-12-10 09:41:52 +00009527 if (!InstD) {
9528 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9529 // This can happen because of dependent hiding.
9530 if (isa<UsingShadowDecl>(*I))
9531 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00009532 else {
9533 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009534 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009535 }
John McCall84d87672009-12-10 09:41:52 +00009536 }
John McCalle66edc12009-11-24 19:00:30 +00009537
9538 // Expand using declarations.
9539 if (isa<UsingDecl>(InstD)) {
9540 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009541 for (auto *I : UD->shadows())
9542 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00009543 continue;
9544 }
9545
9546 R.addDecl(InstD);
9547 }
9548
9549 // Resolve a kind, but don't do any further analysis. If it's
9550 // ambiguous, the callee needs to deal with it.
9551 R.resolveKind();
9552
9553 // Rebuild the nested-name qualifier, if present.
9554 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00009555 if (Old->getQualifierLoc()) {
9556 NestedNameSpecifierLoc QualifierLoc
9557 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9558 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009559 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009560
Douglas Gregor0da1d432011-02-28 20:01:57 +00009561 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00009562 }
9563
Douglas Gregor9262f472010-04-27 18:19:34 +00009564 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00009565 CXXRecordDecl *NamingClass
9566 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
9567 Old->getNameLoc(),
9568 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00009569 if (!NamingClass) {
9570 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009571 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009572 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009573
Douglas Gregorda7be082010-04-27 16:10:10 +00009574 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00009575 }
9576
Abramo Bagnara7945c982012-01-27 09:46:47 +00009577 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9578
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009579 // If we have neither explicit template arguments, nor the template keyword,
Reid Kleckner744e3e72015-10-20 21:04:13 +00009580 // it's a normal declaration name or member reference.
9581 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
9582 NamedDecl *D = R.getAsSingle<NamedDecl>();
9583 // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
9584 // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
9585 // give a good diagnostic.
9586 if (D && D->isCXXInstanceMember()) {
9587 return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R,
9588 /*TemplateArgs=*/nullptr,
9589 /*Scope=*/nullptr);
9590 }
9591
John McCalle66edc12009-11-24 19:00:30 +00009592 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
Reid Kleckner744e3e72015-10-20 21:04:13 +00009593 }
John McCalle66edc12009-11-24 19:00:30 +00009594
9595 // If we have template arguments, rebuild them, then rebuild the
9596 // templateid expression.
9597 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00009598 if (Old->hasExplicitTemplateArgs() &&
9599 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00009600 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00009601 TransArgs)) {
9602 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00009603 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009604 }
John McCalle66edc12009-11-24 19:00:30 +00009605
Abramo Bagnara7945c982012-01-27 09:46:47 +00009606 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009607 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00009608}
Mike Stump11289f42009-09-09 15:08:12 +00009609
Douglas Gregora16548e2009-08-11 05:31:07 +00009610template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009611ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00009612TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
9613 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009614 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009615 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
9616 TypeSourceInfo *From = E->getArg(I);
9617 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00009618 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00009619 TypeLocBuilder TLB;
9620 TLB.reserve(FromTL.getFullDataSize());
9621 QualType To = getDerived().TransformType(TLB, FromTL);
9622 if (To.isNull())
9623 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009624
Douglas Gregor29c42f22012-02-24 07:38:34 +00009625 if (To == From->getType())
9626 Args.push_back(From);
9627 else {
9628 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9629 ArgChanged = true;
9630 }
9631 continue;
9632 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009633
Douglas Gregor29c42f22012-02-24 07:38:34 +00009634 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009635
Douglas Gregor29c42f22012-02-24 07:38:34 +00009636 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00009637 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00009638 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
9639 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9640 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00009641
Douglas Gregor29c42f22012-02-24 07:38:34 +00009642 // Determine whether the set of unexpanded parameter packs can and should
9643 // be expanded.
9644 bool Expand = true;
9645 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009646 Optional<unsigned> OrigNumExpansions =
9647 ExpansionTL.getTypePtr()->getNumExpansions();
9648 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009649 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
9650 PatternTL.getSourceRange(),
9651 Unexpanded,
9652 Expand, RetainExpansion,
9653 NumExpansions))
9654 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009655
Douglas Gregor29c42f22012-02-24 07:38:34 +00009656 if (!Expand) {
9657 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009658 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00009659 // expansion.
9660 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00009661
Douglas Gregor29c42f22012-02-24 07:38:34 +00009662 TypeLocBuilder TLB;
9663 TLB.reserve(From->getTypeLoc().getFullDataSize());
9664
9665 QualType To = getDerived().TransformType(TLB, PatternTL);
9666 if (To.isNull())
9667 return ExprError();
9668
Chad Rosier1dcde962012-08-08 18:46:20 +00009669 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009670 PatternTL.getSourceRange(),
9671 ExpansionTL.getEllipsisLoc(),
9672 NumExpansions);
9673 if (To.isNull())
9674 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009675
Douglas Gregor29c42f22012-02-24 07:38:34 +00009676 PackExpansionTypeLoc ToExpansionTL
9677 = TLB.push<PackExpansionTypeLoc>(To);
9678 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9679 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9680 continue;
9681 }
9682
9683 // Expand the pack expansion by substituting for each argument in the
9684 // pack(s).
9685 for (unsigned I = 0; I != *NumExpansions; ++I) {
9686 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
9687 TypeLocBuilder TLB;
9688 TLB.reserve(PatternTL.getFullDataSize());
9689 QualType To = getDerived().TransformType(TLB, PatternTL);
9690 if (To.isNull())
9691 return ExprError();
9692
Eli Friedman5e05c4a2013-07-19 21:49:32 +00009693 if (To->containsUnexpandedParameterPack()) {
9694 To = getDerived().RebuildPackExpansionType(To,
9695 PatternTL.getSourceRange(),
9696 ExpansionTL.getEllipsisLoc(),
9697 NumExpansions);
9698 if (To.isNull())
9699 return ExprError();
9700
9701 PackExpansionTypeLoc ToExpansionTL
9702 = TLB.push<PackExpansionTypeLoc>(To);
9703 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9704 }
9705
Douglas Gregor29c42f22012-02-24 07:38:34 +00009706 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9707 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009708
Douglas Gregor29c42f22012-02-24 07:38:34 +00009709 if (!RetainExpansion)
9710 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009711
Douglas Gregor29c42f22012-02-24 07:38:34 +00009712 // If we're supposed to retain a pack expansion, do so by temporarily
9713 // forgetting the partially-substituted parameter pack.
9714 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
9715
9716 TypeLocBuilder TLB;
9717 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00009718
Douglas Gregor29c42f22012-02-24 07:38:34 +00009719 QualType To = getDerived().TransformType(TLB, PatternTL);
9720 if (To.isNull())
9721 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009722
9723 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009724 PatternTL.getSourceRange(),
9725 ExpansionTL.getEllipsisLoc(),
9726 NumExpansions);
9727 if (To.isNull())
9728 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009729
Douglas Gregor29c42f22012-02-24 07:38:34 +00009730 PackExpansionTypeLoc ToExpansionTL
9731 = TLB.push<PackExpansionTypeLoc>(To);
9732 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9733 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9734 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009735
Douglas Gregor29c42f22012-02-24 07:38:34 +00009736 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009737 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009738
9739 return getDerived().RebuildTypeTrait(E->getTrait(),
9740 E->getLocStart(),
9741 Args,
9742 E->getLocEnd());
9743}
9744
9745template<typename Derived>
9746ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00009747TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
9748 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
9749 if (!T)
9750 return ExprError();
9751
9752 if (!getDerived().AlwaysRebuild() &&
9753 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009754 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009755
9756 ExprResult SubExpr;
9757 {
9758 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9759 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
9760 if (SubExpr.isInvalid())
9761 return ExprError();
9762
9763 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009764 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009765 }
9766
9767 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
9768 E->getLocStart(),
9769 T,
9770 SubExpr.get(),
9771 E->getLocEnd());
9772}
9773
9774template<typename Derived>
9775ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00009776TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
9777 ExprResult SubExpr;
9778 {
9779 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9780 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
9781 if (SubExpr.isInvalid())
9782 return ExprError();
9783
9784 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009785 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +00009786 }
9787
9788 return getDerived().RebuildExpressionTrait(
9789 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
9790}
9791
Reid Kleckner32506ed2014-06-12 23:03:48 +00009792template <typename Derived>
9793ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
9794 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
9795 TypeSourceInfo **RecoveryTSI) {
9796 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
9797 DRE, AddrTaken, RecoveryTSI);
9798
9799 // Propagate both errors and recovered types, which return ExprEmpty.
9800 if (!NewDRE.isUsable())
9801 return NewDRE;
9802
9803 // We got an expr, wrap it up in parens.
9804 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
9805 return PE;
9806 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
9807 PE->getRParen());
9808}
9809
9810template <typename Derived>
9811ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9812 DependentScopeDeclRefExpr *E) {
9813 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
9814 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00009815}
9816
9817template<typename Derived>
9818ExprResult
9819TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9820 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +00009821 bool IsAddressOfOperand,
9822 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00009823 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009824 NestedNameSpecifierLoc QualifierLoc
9825 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9826 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009827 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00009828 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00009829
John McCall31f82722010-11-12 08:19:04 +00009830 // TODO: If this is a conversion-function-id, verify that the
9831 // destination type name (if present) resolves the same way after
9832 // instantiation as it did in the local scope.
9833
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009834 DeclarationNameInfo NameInfo
9835 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
9836 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009837 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009838
John McCalle66edc12009-11-24 19:00:30 +00009839 if (!E->hasExplicitTemplateArgs()) {
9840 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009841 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009842 // Note: it is sufficient to compare the Name component of NameInfo:
9843 // if name has not changed, DNLoc has not changed either.
9844 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009845 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009846
Reid Kleckner32506ed2014-06-12 23:03:48 +00009847 return getDerived().RebuildDependentScopeDeclRefExpr(
9848 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
9849 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +00009850 }
John McCall6b51f282009-11-23 01:53:49 +00009851
9852 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009853 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9854 E->getNumTemplateArgs(),
9855 TransArgs))
9856 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009857
Reid Kleckner32506ed2014-06-12 23:03:48 +00009858 return getDerived().RebuildDependentScopeDeclRefExpr(
9859 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
9860 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00009861}
9862
9863template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009864ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009865TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00009866 // CXXConstructExprs other than for list-initialization and
9867 // CXXTemporaryObjectExpr are always implicit, so when we have
9868 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00009869 if ((E->getNumArgs() == 1 ||
9870 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00009871 (!getDerived().DropCallArgument(E->getArg(0))) &&
9872 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00009873 return getDerived().TransformExpr(E->getArg(0));
9874
Douglas Gregora16548e2009-08-11 05:31:07 +00009875 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
9876
9877 QualType T = getDerived().TransformType(E->getType());
9878 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00009879 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009880
9881 CXXConstructorDecl *Constructor
9882 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009883 getDerived().TransformDecl(E->getLocStart(),
9884 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009885 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009886 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009887
Douglas Gregora16548e2009-08-11 05:31:07 +00009888 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009889 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009890 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009891 &ArgumentChanged))
9892 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009893
Douglas Gregora16548e2009-08-11 05:31:07 +00009894 if (!getDerived().AlwaysRebuild() &&
9895 T == E->getType() &&
9896 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00009897 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00009898 // Mark the constructor as referenced.
9899 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009900 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009901 return E;
Douglas Gregorde550352010-02-26 00:01:57 +00009902 }
Mike Stump11289f42009-09-09 15:08:12 +00009903
Douglas Gregordb121ba2009-12-14 16:27:04 +00009904 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
Richard Smithc83bf822016-06-10 00:58:19 +00009905 Constructor,
Richard Smithc2bebe92016-05-11 20:37:46 +00009906 E->isElidable(), Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00009907 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00009908 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +00009909 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00009910 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00009911 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00009912 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009913}
Mike Stump11289f42009-09-09 15:08:12 +00009914
Douglas Gregora16548e2009-08-11 05:31:07 +00009915/// \brief Transform a C++ temporary-binding expression.
9916///
Douglas Gregor363b1512009-12-24 18:51:59 +00009917/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
9918/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009919template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009920ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009921TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009922 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009923}
Mike Stump11289f42009-09-09 15:08:12 +00009924
John McCall5d413782010-12-06 08:20:24 +00009925/// \brief Transform a C++ expression that contains cleanups that should
9926/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00009927///
John McCall5d413782010-12-06 08:20:24 +00009928/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00009929/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009930template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009931ExprResult
John McCall5d413782010-12-06 08:20:24 +00009932TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009933 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009934}
Mike Stump11289f42009-09-09 15:08:12 +00009935
Douglas Gregora16548e2009-08-11 05:31:07 +00009936template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009937ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009938TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00009939 CXXTemporaryObjectExpr *E) {
9940 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9941 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009942 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009943
Douglas Gregora16548e2009-08-11 05:31:07 +00009944 CXXConstructorDecl *Constructor
9945 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00009946 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009947 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009948 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009949 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009950
Douglas Gregora16548e2009-08-11 05:31:07 +00009951 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009952 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00009953 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009954 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009955 &ArgumentChanged))
9956 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009957
Douglas Gregora16548e2009-08-11 05:31:07 +00009958 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009959 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009960 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009961 !ArgumentChanged) {
9962 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009963 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00009964 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009965 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009966
Richard Smithd59b8322012-12-19 01:39:02 +00009967 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00009968 return getDerived().RebuildCXXTemporaryObjectExpr(T,
9969 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009970 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009971 E->getLocEnd());
9972}
Mike Stump11289f42009-09-09 15:08:12 +00009973
Douglas Gregora16548e2009-08-11 05:31:07 +00009974template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009975ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00009976TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +00009977 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009978 // lambda body, because they are not semantically within that scope.
Richard Smithc38498f2015-04-27 21:27:54 +00009979 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009980 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
9981 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
Richard Smithc38498f2015-04-27 21:27:54 +00009982 E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009983 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +00009984 CEnd = E->capture_end();
9985 C != CEnd; ++C) {
James Dennettdd2ffea22015-05-07 18:48:18 +00009986 if (!E->isInitCapture(C))
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009987 continue;
Richard Smith01014ce2014-11-20 23:53:14 +00009988 EnterExpressionEvaluationContext EEEC(getSema(),
9989 Sema::PotentiallyEvaluated);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009990 ExprResult NewExprInitResult = getDerived().TransformInitializer(
9991 C->getCapturedVar()->getInit(),
9992 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith01014ce2014-11-20 23:53:14 +00009993
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009994 if (NewExprInitResult.isInvalid())
9995 return ExprError();
9996 Expr *NewExprInit = NewExprInitResult.get();
Richard Smith01014ce2014-11-20 23:53:14 +00009997
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009998 VarDecl *OldVD = C->getCapturedVar();
Richard Smith01014ce2014-11-20 23:53:14 +00009999 QualType NewInitCaptureType =
Richard Smith42b10572015-11-11 01:36:17 +000010000 getSema().buildLambdaInitCaptureInitialization(
10001 C->getLocation(), OldVD->getType()->isReferenceType(),
10002 OldVD->getIdentifier(),
10003 C->getCapturedVar()->getInitStyle() != VarDecl::CInit, NewExprInit);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010004 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010005 InitCaptureExprsAndTypes[C - E->capture_begin()] =
10006 std::make_pair(NewExprInitResult, NewInitCaptureType);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010007 }
10008
Faisal Vali2cba1332013-10-23 06:44:28 +000010009 // Transform the template parameters, and add them to the current
10010 // instantiation scope. The null case is handled correctly.
Richard Smithc38498f2015-04-27 21:27:54 +000010011 auto TPL = getDerived().TransformTemplateParameterList(
Faisal Vali2cba1332013-10-23 06:44:28 +000010012 E->getTemplateParameterList());
10013
Richard Smith01014ce2014-11-20 23:53:14 +000010014 // Transform the type of the original lambda's call operator.
10015 // The transformation MUST be done in the CurrentInstantiationScope since
10016 // it introduces a mapping of the original to the newly created
10017 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +000010018 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +000010019 {
10020 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
10021 FunctionProtoTypeLoc OldCallOpFPTL =
10022 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +000010023
10024 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +000010025 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +000010026 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +000010027 QualType NewCallOpType = TransformFunctionProtoType(
10028 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +000010029 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
10030 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
10031 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +000010032 });
Reid Kleckneraac43c62014-12-15 21:07:16 +000010033 if (NewCallOpType.isNull())
10034 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +000010035 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
10036 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +000010037 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010038
Richard Smithc38498f2015-04-27 21:27:54 +000010039 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
10040 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
10041 LSI->GLTemplateParameterList = TPL;
10042
Eli Friedmand564afb2012-09-19 01:18:11 +000010043 // Create the local class that will describe the lambda.
10044 CXXRecordDecl *Class
10045 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +000010046 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +000010047 /*KnownDependent=*/false,
10048 E->getCaptureDefault());
Eli Friedmand564afb2012-09-19 01:18:11 +000010049 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
10050
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010051 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +000010052 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
10053 Class, E->getIntroducerRange(), NewCallOpTSI,
10054 E->getCallOperator()->getLocEnd(),
Faisal Valia734ab92016-03-26 16:11:37 +000010055 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams(),
10056 E->getCallOperator()->isConstexpr());
10057
Faisal Vali2cba1332013-10-23 06:44:28 +000010058 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +000010059
Faisal Vali2cba1332013-10-23 06:44:28 +000010060 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
Richard Smithc38498f2015-04-27 21:27:54 +000010061 getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
Richard Smithba71c082013-05-16 06:20:58 +000010062
Douglas Gregorb4328232012-02-14 00:00:48 +000010063 // Introduce the context of the call operator.
Richard Smithc38498f2015-04-27 21:27:54 +000010064 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
Richard Smith7ff2bcb2014-01-24 01:54:52 +000010065 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +000010066
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010067 // Enter the scope of the lambda.
Richard Smithc38498f2015-04-27 21:27:54 +000010068 getSema().buildLambdaScope(LSI, NewCallOperator,
10069 E->getIntroducerRange(),
10070 E->getCaptureDefault(),
10071 E->getCaptureDefaultLoc(),
10072 E->hasExplicitParameters(),
10073 E->hasExplicitResultType(),
10074 E->isMutable());
10075
10076 bool Invalid = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010077
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010078 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010079 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010080 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010081 CEnd = E->capture_end();
10082 C != CEnd; ++C) {
10083 // When we hit the first implicit capture, tell Sema that we've finished
10084 // the list of explicit captures.
10085 if (!FinishedExplicitCaptures && C->isImplicit()) {
10086 getSema().finishLambdaExplicitCaptures(LSI);
10087 FinishedExplicitCaptures = true;
10088 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010089
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010090 // Capturing 'this' is trivial.
10091 if (C->capturesThis()) {
Faisal Validc6b5962016-03-21 09:25:37 +000010092 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
10093 /*BuildAndDiagnose*/ true, nullptr,
10094 C->getCaptureKind() == LCK_StarThis);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010095 continue;
10096 }
Alexey Bataev39c81e22014-08-28 04:28:19 +000010097 // Captured expression will be recaptured during captured variables
10098 // rebuilding.
10099 if (C->capturesVLAType())
10100 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +000010101
Richard Smithba71c082013-05-16 06:20:58 +000010102 // Rebuild init-captures, including the implied field declaration.
James Dennettdd2ffea22015-05-07 18:48:18 +000010103 if (E->isInitCapture(C)) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010104 InitCaptureInfoTy InitExprTypePair =
10105 InitCaptureExprsAndTypes[C - E->capture_begin()];
10106 ExprResult Init = InitExprTypePair.first;
10107 QualType InitQualType = InitExprTypePair.second;
10108 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +000010109 Invalid = true;
10110 continue;
10111 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000010112 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010113 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
Richard Smith42b10572015-11-11 01:36:17 +000010114 OldVD->getLocation(), InitExprTypePair.second, OldVD->getIdentifier(),
10115 OldVD->getInitStyle(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +000010116 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +000010117 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010118 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +000010119 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010120 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000010121 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +000010122 continue;
10123 }
10124
10125 assert(C->capturesVariable() && "unexpected kind of lambda capture");
10126
Douglas Gregor3e308b12012-02-14 19:27:52 +000010127 // Determine the capture kind for Sema.
10128 Sema::TryCaptureKind Kind
10129 = C->isImplicit()? Sema::TryCapture_Implicit
10130 : C->getCaptureKind() == LCK_ByCopy
10131 ? Sema::TryCapture_ExplicitByVal
10132 : Sema::TryCapture_ExplicitByRef;
10133 SourceLocation EllipsisLoc;
10134 if (C->isPackExpansion()) {
10135 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
10136 bool ShouldExpand = false;
10137 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010138 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +000010139 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
10140 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000010141 Unexpanded,
10142 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +000010143 NumExpansions)) {
10144 Invalid = true;
10145 continue;
10146 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010147
Douglas Gregor3e308b12012-02-14 19:27:52 +000010148 if (ShouldExpand) {
10149 // The transform has determined that we should perform an expansion;
10150 // transform and capture each of the arguments.
10151 // expansion of the pattern. Do so.
10152 VarDecl *Pack = C->getCapturedVar();
10153 for (unsigned I = 0; I != *NumExpansions; ++I) {
10154 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10155 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000010156 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000010157 Pack));
10158 if (!CapturedVar) {
10159 Invalid = true;
10160 continue;
10161 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010162
Douglas Gregor3e308b12012-02-14 19:27:52 +000010163 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +000010164 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
10165 }
Richard Smith9467be42014-06-06 17:33:35 +000010166
10167 // FIXME: Retain a pack expansion if RetainExpansion is true.
10168
Douglas Gregor3e308b12012-02-14 19:27:52 +000010169 continue;
10170 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010171
Douglas Gregor3e308b12012-02-14 19:27:52 +000010172 EllipsisLoc = C->getEllipsisLoc();
10173 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010174
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010175 // Transform the captured variable.
10176 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000010177 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010178 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +000010179 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010180 Invalid = true;
10181 continue;
10182 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010183
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010184 // Capture the transformed variable.
Meador Inge4f9dee72015-06-26 00:09:55 +000010185 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
10186 EllipsisLoc);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010187 }
10188 if (!FinishedExplicitCaptures)
10189 getSema().finishLambdaExplicitCaptures(LSI);
10190
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010191 // Enter a new evaluation context to insulate the lambda from any
10192 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +000010193 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010194
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010195 // Instantiate the body of the lambda expression.
Richard Smithc38498f2015-04-27 21:27:54 +000010196 StmtResult Body =
10197 Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
10198
10199 // ActOnLambda* will pop the function scope for us.
10200 FuncScopeCleanup.disable();
10201
Douglas Gregorb4328232012-02-14 00:00:48 +000010202 if (Body.isInvalid()) {
Richard Smithc38498f2015-04-27 21:27:54 +000010203 SavedContext.pop();
Craig Topperc3ec1492014-05-26 06:22:03 +000010204 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +000010205 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +000010206 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +000010207 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +000010208
Richard Smithc38498f2015-04-27 21:27:54 +000010209 // Copy the LSI before ActOnFinishFunctionBody removes it.
10210 // FIXME: This is dumb. Store the lambda information somewhere that outlives
10211 // the call operator.
10212 auto LSICopy = *LSI;
10213 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
10214 /*IsInstantiation*/ true);
10215 SavedContext.pop();
10216
10217 return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(),
10218 &LSICopy);
Douglas Gregore31e6062012-02-07 10:09:13 +000010219}
10220
10221template<typename Derived>
10222ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010223TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010224 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +000010225 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10226 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010227 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010228
Douglas Gregora16548e2009-08-11 05:31:07 +000010229 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010230 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000010231 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +000010232 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010233 &ArgumentChanged))
10234 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010235
Douglas Gregora16548e2009-08-11 05:31:07 +000010236 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010237 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010238 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010239 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010240
Douglas Gregora16548e2009-08-11 05:31:07 +000010241 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +000010242 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +000010243 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010244 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +000010245 E->getRParenLoc());
10246}
Mike Stump11289f42009-09-09 15:08:12 +000010247
Douglas Gregora16548e2009-08-11 05:31:07 +000010248template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010249ExprResult
John McCall8cd78132009-11-19 22:55:06 +000010250TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010251 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010252 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000010253 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000010254 Expr *OldBase;
10255 QualType BaseType;
10256 QualType ObjectType;
10257 if (!E->isImplicitAccess()) {
10258 OldBase = E->getBase();
10259 Base = getDerived().TransformExpr(OldBase);
10260 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010261 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010262
John McCall2d74de92009-12-01 22:10:20 +000010263 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +000010264 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +000010265 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +000010266 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010267 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010268 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +000010269 ObjectTy,
10270 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +000010271 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010272 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +000010273
John McCallba7bf592010-08-24 05:47:05 +000010274 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +000010275 BaseType = ((Expr*) Base.get())->getType();
10276 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +000010277 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +000010278 BaseType = getDerived().TransformType(E->getBaseType());
10279 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
10280 }
Mike Stump11289f42009-09-09 15:08:12 +000010281
Douglas Gregora5cb6da2009-10-20 05:58:46 +000010282 // Transform the first part of the nested-name-specifier that qualifies
10283 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +000010284 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +000010285 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +000010286 E->getFirstQualifierFoundInScope(),
10287 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +000010288
Douglas Gregore16af532011-02-28 18:50:33 +000010289 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010290 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +000010291 QualifierLoc
10292 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
10293 ObjectType,
10294 FirstQualifierInScope);
10295 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010296 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010297 }
Mike Stump11289f42009-09-09 15:08:12 +000010298
Abramo Bagnara7945c982012-01-27 09:46:47 +000010299 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
10300
John McCall31f82722010-11-12 08:19:04 +000010301 // TODO: If this is a conversion-function-id, verify that the
10302 // destination type name (if present) resolves the same way after
10303 // instantiation as it did in the local scope.
10304
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010305 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +000010306 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010307 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000010308 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010309
John McCall2d74de92009-12-01 22:10:20 +000010310 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +000010311 // This is a reference to a member without an explicitly-specified
10312 // template argument list. Optimize for this common case.
10313 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +000010314 Base.get() == OldBase &&
10315 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +000010316 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010317 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +000010318 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010319 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010320
John McCallb268a282010-08-23 23:25:46 +000010321 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010322 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +000010323 E->isArrow(),
10324 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000010325 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010326 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +000010327 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010328 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000010329 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +000010330 }
10331
John McCall6b51f282009-11-23 01:53:49 +000010332 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010333 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
10334 E->getNumTemplateArgs(),
10335 TransArgs))
10336 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010337
John McCallb268a282010-08-23 23:25:46 +000010338 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010339 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +000010340 E->isArrow(),
10341 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000010342 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010343 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +000010344 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010345 NameInfo,
John McCall10eae182009-11-30 22:42:35 +000010346 &TransArgs);
10347}
10348
10349template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010350ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010351TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +000010352 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000010353 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000010354 QualType BaseType;
10355 if (!Old->isImplicitAccess()) {
10356 Base = getDerived().TransformExpr(Old->getBase());
10357 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010358 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010359 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +000010360 Old->isArrow());
10361 if (Base.isInvalid())
10362 return ExprError();
10363 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +000010364 } else {
10365 BaseType = getDerived().TransformType(Old->getBaseType());
10366 }
John McCall10eae182009-11-30 22:42:35 +000010367
Douglas Gregor0da1d432011-02-28 20:01:57 +000010368 NestedNameSpecifierLoc QualifierLoc;
10369 if (Old->getQualifierLoc()) {
10370 QualifierLoc
10371 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
10372 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010373 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000010374 }
10375
Abramo Bagnara7945c982012-01-27 09:46:47 +000010376 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
10377
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010378 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +000010379 Sema::LookupOrdinaryName);
10380
10381 // Transform all the decls.
10382 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
10383 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010384 NamedDecl *InstD = static_cast<NamedDecl*>(
10385 getDerived().TransformDecl(Old->getMemberLoc(),
10386 *I));
John McCall84d87672009-12-10 09:41:52 +000010387 if (!InstD) {
10388 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
10389 // This can happen because of dependent hiding.
10390 if (isa<UsingShadowDecl>(*I))
10391 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +000010392 else {
10393 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +000010394 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +000010395 }
John McCall84d87672009-12-10 09:41:52 +000010396 }
John McCall10eae182009-11-30 22:42:35 +000010397
10398 // Expand using declarations.
10399 if (isa<UsingDecl>(InstD)) {
10400 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +000010401 for (auto *I : UD->shadows())
10402 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +000010403 continue;
10404 }
10405
10406 R.addDecl(InstD);
10407 }
10408
10409 R.resolveKind();
10410
Douglas Gregor9262f472010-04-27 18:19:34 +000010411 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +000010412 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +000010413 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +000010414 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +000010415 Old->getMemberLoc(),
10416 Old->getNamingClass()));
10417 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +000010418 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010419
Douglas Gregorda7be082010-04-27 16:10:10 +000010420 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +000010421 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010422
John McCall10eae182009-11-30 22:42:35 +000010423 TemplateArgumentListInfo TransArgs;
10424 if (Old->hasExplicitTemplateArgs()) {
10425 TransArgs.setLAngleLoc(Old->getLAngleLoc());
10426 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010427 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
10428 Old->getNumTemplateArgs(),
10429 TransArgs))
10430 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000010431 }
John McCall38836f02010-01-15 08:34:02 +000010432
10433 // FIXME: to do this check properly, we will need to preserve the
10434 // first-qualifier-in-scope here, just in case we had a dependent
10435 // base (and therefore couldn't do the check) and a
10436 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +000010437 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +000010438
John McCallb268a282010-08-23 23:25:46 +000010439 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010440 BaseType,
John McCall10eae182009-11-30 22:42:35 +000010441 Old->getOperatorLoc(),
10442 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +000010443 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010444 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +000010445 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +000010446 R,
10447 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +000010448 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +000010449}
10450
10451template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010452ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010453TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +000010454 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010455 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
10456 if (SubExpr.isInvalid())
10457 return ExprError();
10458
10459 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010460 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010461
10462 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
10463}
10464
10465template<typename Derived>
10466ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010467TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010468 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
10469 if (Pattern.isInvalid())
10470 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010471
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010472 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010473 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010474
Douglas Gregorb8840002011-01-14 21:20:45 +000010475 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
10476 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010477}
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010478
10479template<typename Derived>
10480ExprResult
10481TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
10482 // If E is not value-dependent, then nothing will change when we transform it.
10483 // Note: This is an instantiation-centric view.
10484 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010485 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010486
Richard Smithd784e682015-09-23 21:41:42 +000010487 EnterExpressionEvaluationContext Unevaluated(getSema(), Sema::Unevaluated);
Chad Rosier1dcde962012-08-08 18:46:20 +000010488
Richard Smithd784e682015-09-23 21:41:42 +000010489 ArrayRef<TemplateArgument> PackArgs;
10490 TemplateArgument ArgStorage;
Chad Rosier1dcde962012-08-08 18:46:20 +000010491
Richard Smithd784e682015-09-23 21:41:42 +000010492 // Find the argument list to transform.
10493 if (E->isPartiallySubstituted()) {
10494 PackArgs = E->getPartialArguments();
10495 } else if (E->isValueDependent()) {
10496 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
10497 bool ShouldExpand = false;
10498 bool RetainExpansion = false;
10499 Optional<unsigned> NumExpansions;
10500 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
10501 Unexpanded,
10502 ShouldExpand, RetainExpansion,
10503 NumExpansions))
10504 return ExprError();
10505
10506 // If we need to expand the pack, build a template argument from it and
10507 // expand that.
10508 if (ShouldExpand) {
10509 auto *Pack = E->getPack();
10510 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
10511 ArgStorage = getSema().Context.getPackExpansionType(
10512 getSema().Context.getTypeDeclType(TTPD), None);
10513 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
10514 ArgStorage = TemplateArgument(TemplateName(TTPD), None);
10515 } else {
10516 auto *VD = cast<ValueDecl>(Pack);
10517 ExprResult DRE = getSema().BuildDeclRefExpr(VD, VD->getType(),
10518 VK_RValue, E->getPackLoc());
10519 if (DRE.isInvalid())
10520 return ExprError();
10521 ArgStorage = new (getSema().Context) PackExpansionExpr(
10522 getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
10523 }
10524 PackArgs = ArgStorage;
10525 }
10526 }
10527
10528 // If we're not expanding the pack, just transform the decl.
10529 if (!PackArgs.size()) {
10530 auto *Pack = cast_or_null<NamedDecl>(
10531 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010532 if (!Pack)
10533 return ExprError();
Richard Smithd784e682015-09-23 21:41:42 +000010534 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
10535 E->getPackLoc(),
10536 E->getRParenLoc(), None, None);
10537 }
10538
10539 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
10540 E->getPackLoc());
10541 {
10542 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
10543 typedef TemplateArgumentLocInventIterator<
10544 Derived, const TemplateArgument*> PackLocIterator;
10545 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
10546 PackLocIterator(*this, PackArgs.end()),
10547 TransformedPackArgs, /*Uneval*/true))
10548 return ExprError();
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010549 }
10550
Richard Smithd784e682015-09-23 21:41:42 +000010551 SmallVector<TemplateArgument, 8> Args;
10552 bool PartialSubstitution = false;
10553 for (auto &Loc : TransformedPackArgs.arguments()) {
10554 Args.push_back(Loc.getArgument());
10555 if (Loc.getArgument().isPackExpansion())
10556 PartialSubstitution = true;
10557 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010558
Richard Smithd784e682015-09-23 21:41:42 +000010559 if (PartialSubstitution)
10560 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
10561 E->getPackLoc(),
10562 E->getRParenLoc(), None, Args);
10563
10564 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
Chad Rosier1dcde962012-08-08 18:46:20 +000010565 E->getPackLoc(), E->getRParenLoc(),
Richard Smithd784e682015-09-23 21:41:42 +000010566 Args.size(), None);
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010567}
10568
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010569template<typename Derived>
10570ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010571TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
10572 SubstNonTypeTemplateParmPackExpr *E) {
10573 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010574 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010575}
10576
10577template<typename Derived>
10578ExprResult
John McCall7c454bb2011-07-15 05:09:51 +000010579TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
10580 SubstNonTypeTemplateParmExpr *E) {
10581 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010582 return E;
John McCall7c454bb2011-07-15 05:09:51 +000010583}
10584
10585template<typename Derived>
10586ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +000010587TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
10588 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010589 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +000010590}
10591
10592template<typename Derived>
10593ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +000010594TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
10595 MaterializeTemporaryExpr *E) {
10596 return getDerived().TransformExpr(E->GetTemporaryExpr());
10597}
Chad Rosier1dcde962012-08-08 18:46:20 +000010598
Douglas Gregorfe314812011-06-21 17:03:29 +000010599template<typename Derived>
10600ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +000010601TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
10602 Expr *Pattern = E->getPattern();
10603
10604 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10605 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
10606 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10607
10608 // Determine whether the set of unexpanded parameter packs can and should
10609 // be expanded.
10610 bool Expand = true;
10611 bool RetainExpansion = false;
10612 Optional<unsigned> NumExpansions;
10613 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
10614 Pattern->getSourceRange(),
10615 Unexpanded,
10616 Expand, RetainExpansion,
10617 NumExpansions))
10618 return true;
10619
10620 if (!Expand) {
10621 // Do not expand any packs here, just transform and rebuild a fold
10622 // expression.
10623 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10624
10625 ExprResult LHS =
10626 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
10627 if (LHS.isInvalid())
10628 return true;
10629
10630 ExprResult RHS =
10631 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
10632 if (RHS.isInvalid())
10633 return true;
10634
10635 if (!getDerived().AlwaysRebuild() &&
10636 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
10637 return E;
10638
10639 return getDerived().RebuildCXXFoldExpr(
10640 E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
10641 RHS.get(), E->getLocEnd());
10642 }
10643
10644 // The transform has determined that we should perform an elementwise
10645 // expansion of the pattern. Do so.
10646 ExprResult Result = getDerived().TransformExpr(E->getInit());
10647 if (Result.isInvalid())
10648 return true;
10649 bool LeftFold = E->isLeftFold();
10650
10651 // If we're retaining an expansion for a right fold, it is the innermost
10652 // component and takes the init (if any).
10653 if (!LeftFold && RetainExpansion) {
10654 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10655
10656 ExprResult Out = getDerived().TransformExpr(Pattern);
10657 if (Out.isInvalid())
10658 return true;
10659
10660 Result = getDerived().RebuildCXXFoldExpr(
10661 E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
10662 Result.get(), E->getLocEnd());
10663 if (Result.isInvalid())
10664 return true;
10665 }
10666
10667 for (unsigned I = 0; I != *NumExpansions; ++I) {
10668 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
10669 getSema(), LeftFold ? I : *NumExpansions - I - 1);
10670 ExprResult Out = getDerived().TransformExpr(Pattern);
10671 if (Out.isInvalid())
10672 return true;
10673
10674 if (Out.get()->containsUnexpandedParameterPack()) {
10675 // We still have a pack; retain a pack expansion for this slice.
10676 Result = getDerived().RebuildCXXFoldExpr(
10677 E->getLocStart(),
10678 LeftFold ? Result.get() : Out.get(),
10679 E->getOperator(), E->getEllipsisLoc(),
10680 LeftFold ? Out.get() : Result.get(),
10681 E->getLocEnd());
10682 } else if (Result.isUsable()) {
10683 // We've got down to a single element; build a binary operator.
10684 Result = getDerived().RebuildBinaryOperator(
10685 E->getEllipsisLoc(), E->getOperator(),
10686 LeftFold ? Result.get() : Out.get(),
10687 LeftFold ? Out.get() : Result.get());
10688 } else
10689 Result = Out;
10690
10691 if (Result.isInvalid())
10692 return true;
10693 }
10694
10695 // If we're retaining an expansion for a left fold, it is the outermost
10696 // component and takes the complete expansion so far as its init (if any).
10697 if (LeftFold && RetainExpansion) {
10698 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10699
10700 ExprResult Out = getDerived().TransformExpr(Pattern);
10701 if (Out.isInvalid())
10702 return true;
10703
10704 Result = getDerived().RebuildCXXFoldExpr(
10705 E->getLocStart(), Result.get(),
10706 E->getOperator(), E->getEllipsisLoc(),
10707 Out.get(), E->getLocEnd());
10708 if (Result.isInvalid())
10709 return true;
10710 }
10711
10712 // If we had no init and an empty pack, and we're not retaining an expansion,
10713 // then produce a fallback value or error.
10714 if (Result.isUnset())
10715 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
10716 E->getOperator());
10717
10718 return Result;
10719}
10720
10721template<typename Derived>
10722ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +000010723TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
10724 CXXStdInitializerListExpr *E) {
10725 return getDerived().TransformExpr(E->getSubExpr());
10726}
10727
10728template<typename Derived>
10729ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010730TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010731 return SemaRef.MaybeBindToTemporary(E);
10732}
10733
10734template<typename Derived>
10735ExprResult
10736TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010737 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010738}
10739
10740template<typename Derived>
10741ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +000010742TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
10743 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
10744 if (SubExpr.isInvalid())
10745 return ExprError();
10746
10747 if (!getDerived().AlwaysRebuild() &&
10748 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010749 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +000010750
10751 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +000010752}
10753
10754template<typename Derived>
10755ExprResult
10756TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
10757 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010758 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010759 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010760 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000010761 /*IsCall=*/false, Elements, &ArgChanged))
10762 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010763
Ted Kremeneke65b0862012-03-06 20:05:56 +000010764 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10765 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000010766
Ted Kremeneke65b0862012-03-06 20:05:56 +000010767 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
10768 Elements.data(),
10769 Elements.size());
10770}
10771
10772template<typename Derived>
10773ExprResult
10774TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +000010775 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010776 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010777 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010778 bool ArgChanged = false;
10779 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
10780 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +000010781
Ted Kremeneke65b0862012-03-06 20:05:56 +000010782 if (OrigElement.isPackExpansion()) {
10783 // This key/value element is a pack expansion.
10784 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10785 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
10786 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
10787 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10788
10789 // Determine whether the set of unexpanded parameter packs can
10790 // and should be expanded.
10791 bool Expand = true;
10792 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010793 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
10794 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010795 SourceRange PatternRange(OrigElement.Key->getLocStart(),
10796 OrigElement.Value->getLocEnd());
10797 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
10798 PatternRange,
10799 Unexpanded,
10800 Expand, RetainExpansion,
10801 NumExpansions))
10802 return ExprError();
10803
10804 if (!Expand) {
10805 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000010806 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +000010807 // expansion.
10808 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10809 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10810 if (Key.isInvalid())
10811 return ExprError();
10812
10813 if (Key.get() != OrigElement.Key)
10814 ArgChanged = true;
10815
10816 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10817 if (Value.isInvalid())
10818 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010819
Ted Kremeneke65b0862012-03-06 20:05:56 +000010820 if (Value.get() != OrigElement.Value)
10821 ArgChanged = true;
10822
Chad Rosier1dcde962012-08-08 18:46:20 +000010823 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010824 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
10825 };
10826 Elements.push_back(Expansion);
10827 continue;
10828 }
10829
10830 // Record right away that the argument was changed. This needs
10831 // to happen even if the array expands to nothing.
10832 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010833
Ted Kremeneke65b0862012-03-06 20:05:56 +000010834 // The transform has determined that we should perform an elementwise
10835 // expansion of the pattern. Do so.
10836 for (unsigned I = 0; I != *NumExpansions; ++I) {
10837 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10838 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10839 if (Key.isInvalid())
10840 return ExprError();
10841
10842 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10843 if (Value.isInvalid())
10844 return ExprError();
10845
Chad Rosier1dcde962012-08-08 18:46:20 +000010846 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010847 Key.get(), Value.get(), SourceLocation(), NumExpansions
10848 };
10849
10850 // If any unexpanded parameter packs remain, we still have a
10851 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +000010852 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +000010853 if (Key.get()->containsUnexpandedParameterPack() ||
10854 Value.get()->containsUnexpandedParameterPack())
10855 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +000010856
Ted Kremeneke65b0862012-03-06 20:05:56 +000010857 Elements.push_back(Element);
10858 }
10859
Richard Smith9467be42014-06-06 17:33:35 +000010860 // FIXME: Retain a pack expansion if RetainExpansion is true.
10861
Ted Kremeneke65b0862012-03-06 20:05:56 +000010862 // We've finished with this pack expansion.
10863 continue;
10864 }
10865
10866 // Transform and check key.
10867 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10868 if (Key.isInvalid())
10869 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010870
Ted Kremeneke65b0862012-03-06 20:05:56 +000010871 if (Key.get() != OrigElement.Key)
10872 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010873
Ted Kremeneke65b0862012-03-06 20:05:56 +000010874 // Transform and check value.
10875 ExprResult Value
10876 = getDerived().TransformExpr(OrigElement.Value);
10877 if (Value.isInvalid())
10878 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010879
Ted Kremeneke65b0862012-03-06 20:05:56 +000010880 if (Value.get() != OrigElement.Value)
10881 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010882
10883 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +000010884 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +000010885 };
10886 Elements.push_back(Element);
10887 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010888
Ted Kremeneke65b0862012-03-06 20:05:56 +000010889 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10890 return SemaRef.MaybeBindToTemporary(E);
10891
10892 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
Craig Topperd4336e02015-12-24 23:58:15 +000010893 Elements);
Douglas Gregora16548e2009-08-11 05:31:07 +000010894}
10895
Mike Stump11289f42009-09-09 15:08:12 +000010896template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010897ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010898TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +000010899 TypeSourceInfo *EncodedTypeInfo
10900 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
10901 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010902 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010903
Douglas Gregora16548e2009-08-11 05:31:07 +000010904 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +000010905 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010906 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010907
10908 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +000010909 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000010910 E->getRParenLoc());
10911}
Mike Stump11289f42009-09-09 15:08:12 +000010912
Douglas Gregora16548e2009-08-11 05:31:07 +000010913template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +000010914ExprResult TreeTransform<Derived>::
10915TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +000010916 // This is a kind of implicit conversion, and it needs to get dropped
10917 // and recomputed for the same general reasons that ImplicitCastExprs
10918 // do, as well a more specific one: this expression is only valid when
10919 // it appears *immediately* as an argument expression.
10920 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +000010921}
10922
10923template<typename Derived>
10924ExprResult TreeTransform<Derived>::
10925TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +000010926 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +000010927 = getDerived().TransformType(E->getTypeInfoAsWritten());
10928 if (!TSInfo)
10929 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010930
John McCall31168b02011-06-15 23:02:42 +000010931 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +000010932 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +000010933 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010934
John McCall31168b02011-06-15 23:02:42 +000010935 if (!getDerived().AlwaysRebuild() &&
10936 TSInfo == E->getTypeInfoAsWritten() &&
10937 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010938 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010939
John McCall31168b02011-06-15 23:02:42 +000010940 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000010941 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000010942 Result.get());
10943}
10944
10945template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010946ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010947TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010948 // Transform arguments.
10949 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010950 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000010951 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010952 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010953 &ArgChanged))
10954 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010955
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010956 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
10957 // Class message: transform the receiver type.
10958 TypeSourceInfo *ReceiverTypeInfo
10959 = getDerived().TransformType(E->getClassReceiverTypeInfo());
10960 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010961 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010962
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010963 // If nothing changed, just retain the existing message send.
10964 if (!getDerived().AlwaysRebuild() &&
10965 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010966 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010967
10968 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010969 SmallVector<SourceLocation, 16> SelLocs;
10970 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010971 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
10972 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010973 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010974 E->getMethodDecl(),
10975 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010976 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010977 E->getRightLoc());
10978 }
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000010979 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
10980 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
10981 // Build a new class message send to 'super'.
10982 SmallVector<SourceLocation, 16> SelLocs;
10983 E->getSelectorLocs(SelLocs);
10984 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
10985 E->getSelector(),
10986 SelLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +000010987 E->getReceiverType(),
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000010988 E->getMethodDecl(),
10989 E->getLeftLoc(),
10990 Args,
10991 E->getRightLoc());
10992 }
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010993
10994 // Instance message: transform the receiver
10995 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
10996 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000010997 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010998 = getDerived().TransformExpr(E->getInstanceReceiver());
10999 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011000 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011001
11002 // If nothing changed, just retain the existing message send.
11003 if (!getDerived().AlwaysRebuild() &&
11004 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011005 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000011006
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011007 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011008 SmallVector<SourceLocation, 16> SelLocs;
11009 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000011010 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011011 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011012 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011013 E->getMethodDecl(),
11014 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011015 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011016 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000011017}
11018
Mike Stump11289f42009-09-09 15:08:12 +000011019template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011020ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011021TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011022 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011023}
11024
Mike Stump11289f42009-09-09 15:08:12 +000011025template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011026ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011027TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011028 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011029}
11030
Mike Stump11289f42009-09-09 15:08:12 +000011031template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011032ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011033TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000011034 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011035 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000011036 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011037 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000011038
11039 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000011040
Douglas Gregord51d90d2010-04-26 20:11:03 +000011041 // If nothing changed, just retain the existing expression.
11042 if (!getDerived().AlwaysRebuild() &&
11043 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011044 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011045
John McCallb268a282010-08-23 23:25:46 +000011046 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000011047 E->getLocation(),
11048 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000011049}
11050
Mike Stump11289f42009-09-09 15:08:12 +000011051template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011052ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011053TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000011054 // 'super' and types never change. Property never changes. Just
11055 // retain the existing expression.
11056 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011057 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011058
Douglas Gregor9faee212010-04-26 20:47:02 +000011059 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011060 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000011061 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011062 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011063
Douglas Gregor9faee212010-04-26 20:47:02 +000011064 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000011065
Douglas Gregor9faee212010-04-26 20:47:02 +000011066 // If nothing changed, just retain the existing expression.
11067 if (!getDerived().AlwaysRebuild() &&
11068 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011069 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011070
John McCallb7bd14f2010-12-02 01:19:52 +000011071 if (E->isExplicitProperty())
11072 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
11073 E->getExplicitProperty(),
11074 E->getLocation());
11075
11076 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000011077 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000011078 E->getImplicitPropertyGetter(),
11079 E->getImplicitPropertySetter(),
11080 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000011081}
11082
Mike Stump11289f42009-09-09 15:08:12 +000011083template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011084ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000011085TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
11086 // Transform the base expression.
11087 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
11088 if (Base.isInvalid())
11089 return ExprError();
11090
11091 // Transform the key expression.
11092 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
11093 if (Key.isInvalid())
11094 return ExprError();
11095
11096 // If nothing changed, just retain the existing expression.
11097 if (!getDerived().AlwaysRebuild() &&
11098 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011099 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011100
Chad Rosier1dcde962012-08-08 18:46:20 +000011101 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000011102 Base.get(), Key.get(),
11103 E->getAtIndexMethodDecl(),
11104 E->setAtIndexMethodDecl());
11105}
11106
11107template<typename Derived>
11108ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011109TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000011110 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011111 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000011112 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011113 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011114
Douglas Gregord51d90d2010-04-26 20:11:03 +000011115 // If nothing changed, just retain the existing expression.
11116 if (!getDerived().AlwaysRebuild() &&
11117 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011118 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011119
John McCallb268a282010-08-23 23:25:46 +000011120 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000011121 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000011122 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000011123}
11124
Mike Stump11289f42009-09-09 15:08:12 +000011125template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011126ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011127TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011128 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011129 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000011130 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000011131 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000011132 SubExprs, &ArgumentChanged))
11133 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011134
Douglas Gregora16548e2009-08-11 05:31:07 +000011135 if (!getDerived().AlwaysRebuild() &&
11136 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011137 return E;
Mike Stump11289f42009-09-09 15:08:12 +000011138
Douglas Gregora16548e2009-08-11 05:31:07 +000011139 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011140 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000011141 E->getRParenLoc());
11142}
11143
Mike Stump11289f42009-09-09 15:08:12 +000011144template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011145ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000011146TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
11147 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
11148 if (SrcExpr.isInvalid())
11149 return ExprError();
11150
11151 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
11152 if (!Type)
11153 return ExprError();
11154
11155 if (!getDerived().AlwaysRebuild() &&
11156 Type == E->getTypeSourceInfo() &&
11157 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011158 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000011159
11160 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
11161 SrcExpr.get(), Type,
11162 E->getRParenLoc());
11163}
11164
11165template<typename Derived>
11166ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011167TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000011168 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000011169
Craig Topperc3ec1492014-05-26 06:22:03 +000011170 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000011171 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
11172
11173 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000011174 blockScope->TheDecl->setBlockMissingReturnType(
11175 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000011176
Chris Lattner01cf8db2011-07-20 06:58:45 +000011177 SmallVector<ParmVarDecl*, 4> params;
11178 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000011179
John McCallc8e321d2016-03-01 02:09:25 +000011180 const FunctionProtoType *exprFunctionType = E->getFunctionType();
11181
Fariborz Jahanian1babe772010-07-09 18:44:02 +000011182 // Parameter substitution.
John McCallc8e321d2016-03-01 02:09:25 +000011183 Sema::ExtParameterInfoBuilder extParamInfos;
John McCall490112f2011-02-04 18:33:18 +000011184 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
11185 oldBlock->param_begin(),
11186 oldBlock->param_size(),
John McCallc8e321d2016-03-01 02:09:25 +000011187 nullptr,
11188 exprFunctionType->getExtParameterInfosOrNull(),
11189 paramTypes, &params,
11190 extParamInfos)) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011191 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011192 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011193 }
John McCall490112f2011-02-04 18:33:18 +000011194
Eli Friedman34b49062012-01-26 03:00:14 +000011195 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000011196 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000011197
John McCallc8e321d2016-03-01 02:09:25 +000011198 auto epi = exprFunctionType->getExtProtoInfo();
11199 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
11200
Jordan Rose5c382722013-03-08 21:51:21 +000011201 QualType functionType =
John McCallc8e321d2016-03-01 02:09:25 +000011202 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
John McCall490112f2011-02-04 18:33:18 +000011203 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000011204
11205 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000011206 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000011207 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000011208
11209 if (!oldBlock->blockMissingReturnType()) {
11210 blockScope->HasImplicitReturnType = false;
11211 blockScope->ReturnType = exprResultType;
11212 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011213
John McCall3882ace2011-01-05 12:14:39 +000011214 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000011215 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011216 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011217 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000011218 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011219 }
John McCall3882ace2011-01-05 12:14:39 +000011220
John McCall490112f2011-02-04 18:33:18 +000011221#ifndef NDEBUG
11222 // In builds with assertions, make sure that we captured everything we
11223 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011224 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000011225 for (const auto &I : oldBlock->captures()) {
11226 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000011227
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011228 // Ignore parameter packs.
11229 if (isa<ParmVarDecl>(oldCapture) &&
11230 cast<ParmVarDecl>(oldCapture)->isParameterPack())
11231 continue;
John McCall490112f2011-02-04 18:33:18 +000011232
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011233 VarDecl *newCapture =
11234 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
11235 oldCapture));
11236 assert(blockScope->CaptureMap.count(newCapture));
11237 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000011238 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000011239 }
11240#endif
11241
11242 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000011243 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000011244}
11245
Mike Stump11289f42009-09-09 15:08:12 +000011246template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011247ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000011248TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000011249 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000011250}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000011251
11252template<typename Derived>
11253ExprResult
11254TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011255 QualType RetTy = getDerived().TransformType(E->getType());
11256 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011257 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011258 SubExprs.reserve(E->getNumSubExprs());
11259 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
11260 SubExprs, &ArgumentChanged))
11261 return ExprError();
11262
11263 if (!getDerived().AlwaysRebuild() &&
11264 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011265 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011266
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011267 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011268 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000011269}
Chad Rosier1dcde962012-08-08 18:46:20 +000011270
Douglas Gregora16548e2009-08-11 05:31:07 +000011271//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000011272// Type reconstruction
11273//===----------------------------------------------------------------------===//
11274
Mike Stump11289f42009-09-09 15:08:12 +000011275template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000011276QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
11277 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000011278 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011279 getDerived().getBaseEntity());
11280}
11281
Mike Stump11289f42009-09-09 15:08:12 +000011282template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000011283QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
11284 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000011285 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011286 getDerived().getBaseEntity());
11287}
11288
Mike Stump11289f42009-09-09 15:08:12 +000011289template<typename Derived>
11290QualType
John McCall70dd5f62009-10-30 00:06:24 +000011291TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
11292 bool WrittenAsLValue,
11293 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000011294 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000011295 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011296}
11297
11298template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011299QualType
John McCall70dd5f62009-10-30 00:06:24 +000011300TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
11301 QualType ClassType,
11302 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000011303 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
11304 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011305}
11306
11307template<typename Derived>
Douglas Gregor9bda6cf2015-07-07 03:58:14 +000011308QualType TreeTransform<Derived>::RebuildObjCObjectType(
11309 QualType BaseType,
11310 SourceLocation Loc,
11311 SourceLocation TypeArgsLAngleLoc,
11312 ArrayRef<TypeSourceInfo *> TypeArgs,
11313 SourceLocation TypeArgsRAngleLoc,
11314 SourceLocation ProtocolLAngleLoc,
11315 ArrayRef<ObjCProtocolDecl *> Protocols,
11316 ArrayRef<SourceLocation> ProtocolLocs,
11317 SourceLocation ProtocolRAngleLoc) {
11318 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
11319 TypeArgs, TypeArgsRAngleLoc,
11320 ProtocolLAngleLoc, Protocols, ProtocolLocs,
11321 ProtocolRAngleLoc,
11322 /*FailOnError=*/true);
11323}
11324
11325template<typename Derived>
11326QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
11327 QualType PointeeType,
11328 SourceLocation Star) {
11329 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
11330}
11331
11332template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011333QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000011334TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
11335 ArrayType::ArraySizeModifier SizeMod,
11336 const llvm::APInt *Size,
11337 Expr *SizeExpr,
11338 unsigned IndexTypeQuals,
11339 SourceRange BracketsRange) {
11340 if (SizeExpr || !Size)
11341 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
11342 IndexTypeQuals, BracketsRange,
11343 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000011344
11345 QualType Types[] = {
11346 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
11347 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
11348 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000011349 };
Craig Toppere5ce8312013-07-15 03:38:40 +000011350 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011351 QualType SizeType;
11352 for (unsigned I = 0; I != NumTypes; ++I)
11353 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
11354 SizeType = Types[I];
11355 break;
11356 }
Mike Stump11289f42009-09-09 15:08:12 +000011357
Eli Friedman9562f392012-01-25 23:20:27 +000011358 // Note that we can return a VariableArrayType here in the case where
11359 // the element type was a dependent VariableArrayType.
11360 IntegerLiteral *ArraySize
11361 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
11362 /*FIXME*/BracketsRange.getBegin());
11363 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011364 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000011365 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011366}
Mike Stump11289f42009-09-09 15:08:12 +000011367
Douglas Gregord6ff3322009-08-04 16:50:30 +000011368template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011369QualType
11370TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011371 ArrayType::ArraySizeModifier SizeMod,
11372 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000011373 unsigned IndexTypeQuals,
11374 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011375 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000011376 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011377}
11378
11379template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011380QualType
Mike Stump11289f42009-09-09 15:08:12 +000011381TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011382 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000011383 unsigned IndexTypeQuals,
11384 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011385 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000011386 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011387}
Mike Stump11289f42009-09-09 15:08:12 +000011388
Douglas Gregord6ff3322009-08-04 16:50:30 +000011389template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011390QualType
11391TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011392 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000011393 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011394 unsigned IndexTypeQuals,
11395 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011396 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000011397 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011398 IndexTypeQuals, BracketsRange);
11399}
11400
11401template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011402QualType
11403TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011404 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000011405 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011406 unsigned IndexTypeQuals,
11407 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011408 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000011409 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011410 IndexTypeQuals, BracketsRange);
11411}
11412
11413template<typename Derived>
11414QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +000011415 unsigned NumElements,
11416 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000011417 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000011418 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011419}
Mike Stump11289f42009-09-09 15:08:12 +000011420
Douglas Gregord6ff3322009-08-04 16:50:30 +000011421template<typename Derived>
11422QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
11423 unsigned NumElements,
11424 SourceLocation AttributeLoc) {
11425 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
11426 NumElements, true);
11427 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000011428 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
11429 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000011430 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011431}
Mike Stump11289f42009-09-09 15:08:12 +000011432
Douglas Gregord6ff3322009-08-04 16:50:30 +000011433template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011434QualType
11435TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000011436 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011437 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000011438 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011439}
Mike Stump11289f42009-09-09 15:08:12 +000011440
Douglas Gregord6ff3322009-08-04 16:50:30 +000011441template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000011442QualType TreeTransform<Derived>::RebuildFunctionProtoType(
11443 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000011444 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000011445 const FunctionProtoType::ExtProtoInfo &EPI) {
11446 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011447 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000011448 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000011449 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011450}
Mike Stump11289f42009-09-09 15:08:12 +000011451
Douglas Gregord6ff3322009-08-04 16:50:30 +000011452template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000011453QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
11454 return SemaRef.Context.getFunctionNoProtoType(T);
11455}
11456
11457template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +000011458QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
11459 assert(D && "no decl found");
11460 if (D->isInvalidDecl()) return QualType();
11461
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011462 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000011463 TypeDecl *Ty;
11464 if (isa<UsingDecl>(D)) {
11465 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000011466 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000011467 "UnresolvedUsingTypenameDecl transformed to non-typename using");
11468
11469 // A valid resolved using typename decl points to exactly one type decl.
11470 assert(++Using->shadow_begin() == Using->shadow_end());
11471 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000011472
John McCallb96ec562009-12-04 22:46:56 +000011473 } else {
11474 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
11475 "UnresolvedUsingTypenameDecl transformed to non-using decl");
11476 Ty = cast<UnresolvedUsingTypenameDecl>(D);
11477 }
11478
11479 return SemaRef.Context.getTypeDeclType(Ty);
11480}
11481
11482template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000011483QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
11484 SourceLocation Loc) {
11485 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011486}
11487
11488template<typename Derived>
11489QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
11490 return SemaRef.Context.getTypeOfType(Underlying);
11491}
11492
11493template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000011494QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
11495 SourceLocation Loc) {
11496 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011497}
11498
11499template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000011500QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
11501 UnaryTransformType::UTTKind UKind,
11502 SourceLocation Loc) {
11503 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
11504}
11505
11506template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000011507QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000011508 TemplateName Template,
11509 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000011510 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000011511 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011512}
Mike Stump11289f42009-09-09 15:08:12 +000011513
Douglas Gregor1135c352009-08-06 05:28:30 +000011514template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000011515QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
11516 SourceLocation KWLoc) {
11517 return SemaRef.BuildAtomicType(ValueType, KWLoc);
11518}
11519
11520template<typename Derived>
Xiuli Pan9c14e282016-01-09 12:53:17 +000011521QualType TreeTransform<Derived>::RebuildPipeType(QualType ValueType,
11522 SourceLocation KWLoc) {
11523 return SemaRef.BuildPipeType(ValueType, KWLoc);
11524}
11525
11526template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011527TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011528TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000011529 bool TemplateKW,
11530 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000011531 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000011532 Template);
11533}
11534
11535template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011536TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011537TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
11538 const IdentifierInfo &Name,
11539 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000011540 QualType ObjectType,
11541 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +000011542 UnqualifiedId TemplateName;
11543 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000011544 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000011545 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000011546 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011547 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000011548 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000011549 /*EnteringContext=*/false,
11550 Template);
John McCall31f82722010-11-12 08:19:04 +000011551 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000011552}
Mike Stump11289f42009-09-09 15:08:12 +000011553
Douglas Gregora16548e2009-08-11 05:31:07 +000011554template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000011555TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011556TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000011557 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000011558 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000011559 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000011560 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000011561 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000011562 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000011563 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000011564 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000011565 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000011566 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011567 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000011568 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000011569 /*EnteringContext=*/false,
11570 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000011571 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000011572}
Chad Rosier1dcde962012-08-08 18:46:20 +000011573
Douglas Gregor71395fa2009-11-04 00:56:37 +000011574template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011575ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000011576TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
11577 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000011578 Expr *OrigCallee,
11579 Expr *First,
11580 Expr *Second) {
11581 Expr *Callee = OrigCallee->IgnoreParenCasts();
11582 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000011583
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000011584 if (First->getObjectKind() == OK_ObjCProperty) {
11585 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
11586 if (BinaryOperator::isAssignmentOp(Opc))
11587 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
11588 First, Second);
11589 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
11590 if (Result.isInvalid())
11591 return ExprError();
11592 First = Result.get();
11593 }
11594
11595 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
11596 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
11597 if (Result.isInvalid())
11598 return ExprError();
11599 Second = Result.get();
11600 }
11601
Douglas Gregora16548e2009-08-11 05:31:07 +000011602 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000011603 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000011604 if (!First->getType()->isOverloadableType() &&
11605 !Second->getType()->isOverloadableType())
11606 return getSema().CreateBuiltinArraySubscriptExpr(First,
11607 Callee->getLocStart(),
11608 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000011609 } else if (Op == OO_Arrow) {
11610 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000011611 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
11612 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000011613 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011614 // The argument is not of overloadable type, so try to create a
11615 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000011616 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011617 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000011618
John McCallb268a282010-08-23 23:25:46 +000011619 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011620 }
11621 } else {
John McCallb268a282010-08-23 23:25:46 +000011622 if (!First->getType()->isOverloadableType() &&
11623 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011624 // Neither of the arguments is an overloadable type, so try to
11625 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000011626 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011627 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000011628 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000011629 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011630 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011631
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011632 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011633 }
11634 }
Mike Stump11289f42009-09-09 15:08:12 +000011635
11636 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000011637 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000011638 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000011639
John McCallb268a282010-08-23 23:25:46 +000011640 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000011641 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000011642 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000011643 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000011644 // If we've resolved this to a particular non-member function, just call
11645 // that function. If we resolved it to a member function,
11646 // CreateOverloaded* will find that function for us.
11647 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
11648 if (!isa<CXXMethodDecl>(ND))
11649 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000011650 }
Mike Stump11289f42009-09-09 15:08:12 +000011651
Douglas Gregora16548e2009-08-11 05:31:07 +000011652 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000011653 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000011654 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000011655
Douglas Gregora16548e2009-08-11 05:31:07 +000011656 // Create the overloaded operator invocation for unary operators.
11657 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000011658 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011659 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000011660 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011661 }
Mike Stump11289f42009-09-09 15:08:12 +000011662
Douglas Gregore9d62932011-07-15 16:25:15 +000011663 if (Op == OO_Subscript) {
11664 SourceLocation LBrace;
11665 SourceLocation RBrace;
11666
11667 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000011668 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000011669 LBrace = SourceLocation::getFromRawEncoding(
11670 NameLoc.CXXOperatorName.BeginOpNameLoc);
11671 RBrace = SourceLocation::getFromRawEncoding(
11672 NameLoc.CXXOperatorName.EndOpNameLoc);
11673 } else {
11674 LBrace = Callee->getLocStart();
11675 RBrace = OpLoc;
11676 }
11677
11678 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
11679 First, Second);
11680 }
Sebastian Redladba46e2009-10-29 20:17:01 +000011681
Douglas Gregora16548e2009-08-11 05:31:07 +000011682 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000011683 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011684 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000011685 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
11686 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011687 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011688
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011689 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011690}
Mike Stump11289f42009-09-09 15:08:12 +000011691
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011692template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000011693ExprResult
John McCallb268a282010-08-23 23:25:46 +000011694TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011695 SourceLocation OperatorLoc,
11696 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000011697 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011698 TypeSourceInfo *ScopeType,
11699 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000011700 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000011701 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000011702 QualType BaseType = Base->getType();
11703 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011704 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000011705 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000011706 !BaseType->getAs<PointerType>()->getPointeeType()
11707 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011708 // This pseudo-destructor expression is still a pseudo-destructor.
David Majnemerced8bdf2015-02-25 17:36:15 +000011709 return SemaRef.BuildPseudoDestructorExpr(
11710 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
11711 CCLoc, TildeLoc, Destroyed);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011712 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011713
Douglas Gregor678f90d2010-02-25 01:56:36 +000011714 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011715 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
11716 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
11717 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
11718 NameInfo.setNamedTypeInfo(DestroyedType);
11719
Richard Smith8e4a3862012-05-15 06:15:11 +000011720 // The scope type is now known to be a valid nested name specifier
11721 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000011722 if (ScopeType) {
11723 if (!ScopeType->getType()->getAs<TagType>()) {
11724 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
11725 diag::err_expected_class_or_namespace)
11726 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
11727 return ExprError();
11728 }
11729 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
11730 CCLoc);
11731 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011732
Abramo Bagnara7945c982012-01-27 09:46:47 +000011733 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000011734 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011735 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011736 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000011737 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011738 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +000011739 /*TemplateArgs*/ nullptr,
11740 /*S*/nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011741}
11742
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000011743template<typename Derived>
11744StmtResult
11745TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000011746 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000011747 CapturedDecl *CD = S->getCapturedDecl();
11748 unsigned NumParams = CD->getNumParams();
11749 unsigned ContextParamPos = CD->getContextParamPosition();
11750 SmallVector<Sema::CapturedParamNameType, 4> Params;
11751 for (unsigned I = 0; I < NumParams; ++I) {
11752 if (I != ContextParamPos) {
11753 Params.push_back(
11754 std::make_pair(
11755 CD->getParam(I)->getName(),
11756 getDerived().TransformType(CD->getParam(I)->getType())));
11757 } else {
11758 Params.push_back(std::make_pair(StringRef(), QualType()));
11759 }
11760 }
Craig Topperc3ec1492014-05-26 06:22:03 +000011761 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000011762 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000011763 StmtResult Body;
11764 {
11765 Sema::CompoundScopeRAII CompoundScope(getSema());
11766 Body = getDerived().TransformStmt(S->getCapturedStmt());
11767 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000011768
11769 if (Body.isInvalid()) {
11770 getSema().ActOnCapturedRegionError();
11771 return StmtError();
11772 }
11773
Nikola Smiljanic01a75982014-05-29 10:55:11 +000011774 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000011775}
11776
Douglas Gregord6ff3322009-08-04 16:50:30 +000011777} // end namespace clang
11778
Hans Wennborg59dbe862015-09-29 20:56:43 +000011779#endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H