blob: bba90191019c715559a0f8256fec578a254f486b [file] [log] [blame]
Chris Lattnercab02a62011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnercab02a62011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00008//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
Chris Lattnercab02a62011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000014#ifndef LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
Douglas Gregord6ff3322009-08-04 16:50:30 +000016
Chandler Carruth3a022472012-12-04 09:13:33 +000017#include "TypeLocBuilder.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000018#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000019#include "clang/AST/DeclObjC.h"
Richard Smith3f1b5d02011-05-05 21:57:07 +000020#include "clang/AST/DeclTemplate.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000021#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000022#include "clang/AST/ExprCXX.h"
23#include "clang/AST/ExprObjC.h"
Alexey Bataev1a3320e2015-08-25 14:24:04 +000024#include "clang/AST/ExprOpenMP.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000025#include "clang/AST/Stmt.h"
26#include "clang/AST/StmtCXX.h"
27#include "clang/AST/StmtObjC.h"
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000028#include "clang/AST/StmtOpenMP.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000029#include "clang/Sema/Designator.h"
30#include "clang/Sema/Lookup.h"
31#include "clang/Sema/Ownership.h"
32#include "clang/Sema/ParsedTemplate.h"
33#include "clang/Sema/ScopeInfo.h"
34#include "clang/Sema/SemaDiagnostic.h"
35#include "clang/Sema/SemaInternal.h"
David Blaikieb9c168a2011-09-22 02:34:54 +000036#include "llvm/ADT/ArrayRef.h"
John McCall550e0c22009-10-21 00:40:46 +000037#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000038#include <algorithm>
39
40namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000041using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000042
Douglas Gregord6ff3322009-08-04 16:50:30 +000043/// \brief A semantic tree transformation that allows one to transform one
44/// abstract syntax tree into another.
45///
Mike Stump11289f42009-09-09 15:08:12 +000046/// A new tree transformation is defined by creating a new subclass \c X of
47/// \c TreeTransform<X> and then overriding certain operations to provide
48/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000049/// instantiation is implemented as a tree transformation where the
50/// transformation of TemplateTypeParmType nodes involves substituting the
51/// template arguments for their corresponding template parameters; a similar
52/// transformation is performed for non-type template parameters and
53/// template template parameters.
54///
55/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000056/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000057/// override any of the transformation or rebuild operators by providing an
58/// operation with the same signature as the default implementation. The
59/// overridding function should not be virtual.
60///
61/// Semantic tree transformations are split into two stages, either of which
62/// can be replaced by a subclass. The "transform" step transforms an AST node
63/// or the parts of an AST node using the various transformation functions,
64/// then passes the pieces on to the "rebuild" step, which constructs a new AST
65/// node of the appropriate kind from the pieces. The default transformation
66/// routines recursively transform the operands to composite AST nodes (e.g.,
67/// the pointee type of a PointerType node) and, if any of those operand nodes
68/// were changed by the transformation, invokes the rebuild operation to create
69/// a new AST node.
70///
Mike Stump11289f42009-09-09 15:08:12 +000071/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000072/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregorfd35cde2011-03-02 18:50:38 +000073/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000074/// TransformTemplateName(), or TransformTemplateArgument() with entirely
75/// new implementations.
76///
77/// For more fine-grained transformations, subclasses can replace any of the
78/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000079/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000080/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000081/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000082/// parameters. Additionally, subclasses can override the \c RebuildXXX
83/// functions to control how AST nodes are rebuilt when their operands change.
84/// By default, \c TreeTransform will invoke semantic analysis to rebuild
85/// AST nodes. However, certain other tree transformations (e.g, cloning) may
86/// be able to use more efficient rebuild steps.
87///
88/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000089/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000090/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
91/// operands have not changed (\c AlwaysRebuild()), and customize the
92/// default locations and entity names used for type-checking
93/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000094template<typename Derived>
95class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000096 /// \brief Private RAII object that helps us forget and then re-remember
97 /// the template argument corresponding to a partially-substituted parameter
98 /// pack.
99 class ForgetPartiallySubstitutedPackRAII {
100 Derived &Self;
101 TemplateArgument Old;
Chad Rosier1dcde962012-08-08 18:46:20 +0000102
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000103 public:
104 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
105 Old = Self.ForgetPartiallySubstitutedPack();
106 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000107
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000108 ~ForgetPartiallySubstitutedPackRAII() {
109 Self.RememberPartiallySubstitutedPack(Old);
110 }
111 };
Chad Rosier1dcde962012-08-08 18:46:20 +0000112
Douglas Gregord6ff3322009-08-04 16:50:30 +0000113protected:
114 Sema &SemaRef;
Chad Rosier1dcde962012-08-08 18:46:20 +0000115
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000116 /// \brief The set of local declarations that have been transformed, for
117 /// cases where we are forced to build new declarations within the transformer
118 /// rather than in the subclass (e.g., lambda closure types).
119 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
Chad Rosier1dcde962012-08-08 18:46:20 +0000120
Mike Stump11289f42009-09-09 15:08:12 +0000121public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000122 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000123 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000124
Douglas Gregord6ff3322009-08-04 16:50:30 +0000125 /// \brief Retrieves a reference to the derived class.
126 Derived &getDerived() { return static_cast<Derived&>(*this); }
127
128 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000129 const Derived &getDerived() const {
130 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000131 }
132
John McCalldadc5752010-08-24 06:29:42 +0000133 static inline ExprResult Owned(Expr *E) { return E; }
134 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000135
Douglas Gregord6ff3322009-08-04 16:50:30 +0000136 /// \brief Retrieves a reference to the semantic analysis object used for
137 /// this tree transform.
138 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000139
Douglas Gregord6ff3322009-08-04 16:50:30 +0000140 /// \brief Whether the transformation should always rebuild AST nodes, even
141 /// if none of the children have changed.
142 ///
143 /// Subclasses may override this function to specify when the transformation
144 /// should rebuild all AST nodes.
Richard Smith2aa81a72013-11-07 20:07:17 +0000145 ///
146 /// We must always rebuild all AST nodes when performing variadic template
147 /// pack expansion, in order to avoid violating the AST invariant that each
148 /// statement node appears at most once in its containing declaration.
149 bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; }
Mike Stump11289f42009-09-09 15:08:12 +0000150
Douglas Gregord6ff3322009-08-04 16:50:30 +0000151 /// \brief Returns the location of the entity being transformed, if that
152 /// information was not available elsewhere in the AST.
153 ///
Mike Stump11289f42009-09-09 15:08:12 +0000154 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000155 /// provide an alternative implementation that provides better location
156 /// information.
157 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000158
Douglas Gregord6ff3322009-08-04 16:50:30 +0000159 /// \brief Returns the name of the entity being transformed, if that
160 /// information was not available elsewhere in the AST.
161 ///
162 /// By default, returns an empty name. Subclasses can provide an alternative
163 /// implementation with a more precise name.
164 DeclarationName getBaseEntity() { return DeclarationName(); }
165
Douglas Gregora16548e2009-08-11 05:31:07 +0000166 /// \brief Sets the "base" location and entity when that
167 /// information is known based on another transformation.
168 ///
169 /// By default, the source location and entity are ignored. Subclasses can
170 /// override this function to provide a customized implementation.
171 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000172
Douglas Gregora16548e2009-08-11 05:31:07 +0000173 /// \brief RAII object that temporarily sets the base location and entity
174 /// used for reporting diagnostics in types.
175 class TemporaryBase {
176 TreeTransform &Self;
177 SourceLocation OldLocation;
178 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000179
Douglas Gregora16548e2009-08-11 05:31:07 +0000180 public:
181 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000182 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000183 OldLocation = Self.getDerived().getBaseLocation();
184 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier1dcde962012-08-08 18:46:20 +0000185
Douglas Gregora518d5b2011-01-25 17:51:48 +0000186 if (Location.isValid())
187 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000188 }
Mike Stump11289f42009-09-09 15:08:12 +0000189
Douglas Gregora16548e2009-08-11 05:31:07 +0000190 ~TemporaryBase() {
191 Self.getDerived().setBase(OldLocation, OldEntity);
192 }
193 };
Mike Stump11289f42009-09-09 15:08:12 +0000194
195 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000196 /// transformed.
197 ///
198 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000199 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000200 /// not change. For example, template instantiation need not traverse
201 /// non-dependent types.
202 bool AlreadyTransformed(QualType T) {
203 return T.isNull();
204 }
205
Douglas Gregord196a582009-12-14 19:27:10 +0000206 /// \brief Determine whether the given call argument should be dropped, e.g.,
207 /// because it is a default argument.
208 ///
209 /// Subclasses can provide an alternative implementation of this routine to
210 /// determine which kinds of call arguments get dropped. By default,
211 /// CXXDefaultArgument nodes are dropped (prior to transformation).
212 bool DropCallArgument(Expr *E) {
213 return E->isDefaultArgument();
214 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000215
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000216 /// \brief Determine whether we should expand a pack expansion with the
217 /// given set of parameter packs into separate arguments by repeatedly
218 /// transforming the pattern.
219 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000220 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000221 /// Subclasses can override this routine to provide different behavior.
222 ///
223 /// \param EllipsisLoc The location of the ellipsis that identifies the
224 /// pack expansion.
225 ///
226 /// \param PatternRange The source range that covers the entire pattern of
227 /// the pack expansion.
228 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000229 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000230 /// pattern.
231 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000232 /// \param ShouldExpand Will be set to \c true if the transformer should
233 /// expand the corresponding pack expansions into separate arguments. When
234 /// set, \c NumExpansions must also be set.
235 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000236 /// \param RetainExpansion Whether the caller should add an unexpanded
237 /// pack expansion after all of the expanded arguments. This is used
238 /// when extending explicitly-specified template argument packs per
239 /// C++0x [temp.arg.explicit]p9.
240 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000241 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000242 /// the expanded form of the corresponding pack expansion. This is both an
243 /// input and an output parameter, which can be set by the caller if the
244 /// number of expansions is known a priori (e.g., due to a prior substitution)
245 /// and will be set by the callee when the number of expansions is known.
246 /// The callee must set this value when \c ShouldExpand is \c true; it may
247 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000248 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000249 /// \returns true if an error occurred (e.g., because the parameter packs
250 /// are to be instantiated with arguments of different lengths), false
251 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000252 /// must be set.
253 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
254 SourceRange PatternRange,
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000255 ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000256 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000257 bool &RetainExpansion,
David Blaikie05785d12013-02-20 22:23:23 +0000258 Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000259 ShouldExpand = false;
260 return false;
261 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000262
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000263 /// \brief "Forget" about the partially-substituted pack template argument,
264 /// when performing an instantiation that must preserve the parameter pack
265 /// use.
266 ///
267 /// This routine is meant to be overridden by the template instantiator.
268 TemplateArgument ForgetPartiallySubstitutedPack() {
269 return TemplateArgument();
270 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000271
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000272 /// \brief "Remember" the partially-substituted pack template argument
273 /// after performing an instantiation that must preserve the parameter pack
274 /// use.
275 ///
276 /// This routine is meant to be overridden by the template instantiator.
277 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000278
Douglas Gregorf3010112011-01-07 16:43:16 +0000279 /// \brief Note to the derived class when a function parameter pack is
280 /// being expanded.
281 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000282
Douglas Gregord6ff3322009-08-04 16:50:30 +0000283 /// \brief Transforms the given type into another type.
284 ///
John McCall550e0c22009-10-21 00:40:46 +0000285 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000286 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000287 /// function. This is expensive, but we don't mind, because
288 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000289 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000290 ///
291 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000292 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000293
John McCall550e0c22009-10-21 00:40:46 +0000294 /// \brief Transforms the given type-with-location into a new
295 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000296 ///
John McCall550e0c22009-10-21 00:40:46 +0000297 /// By default, this routine transforms a type by delegating to the
298 /// appropriate TransformXXXType to build a new type. Subclasses
299 /// may override this function (to take over all type
300 /// transformations) or some set of the TransformXXXType functions
301 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000302 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000303
304 /// \brief Transform the given type-with-location into a new
305 /// type, collecting location information in the given builder
306 /// as necessary.
307 ///
John McCall31f82722010-11-12 08:19:04 +0000308 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000309
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000310 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000311 ///
Mike Stump11289f42009-09-09 15:08:12 +0000312 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000313 /// appropriate TransformXXXStmt function to transform a specific kind of
314 /// statement or the TransformExpr() function to transform an expression.
315 /// Subclasses may override this function to transform statements using some
316 /// other mechanism.
317 ///
318 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000319 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000320
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000321 /// \brief Transform the given statement.
322 ///
323 /// By default, this routine transforms a statement by delegating to the
324 /// appropriate TransformOMPXXXClause function to transform a specific kind
325 /// of clause. Subclasses may override this function to transform statements
326 /// using some other mechanism.
327 ///
328 /// \returns the transformed OpenMP clause.
329 OMPClause *TransformOMPClause(OMPClause *S);
330
Tyler Nowickic724a83e2014-10-12 20:46:07 +0000331 /// \brief Transform the given attribute.
332 ///
333 /// By default, this routine transforms a statement by delegating to the
334 /// appropriate TransformXXXAttr function to transform a specific kind
335 /// of attribute. Subclasses may override this function to transform
336 /// attributed statements using some other mechanism.
337 ///
338 /// \returns the transformed attribute
339 const Attr *TransformAttr(const Attr *S);
340
341/// \brief Transform the specified attribute.
342///
343/// Subclasses should override the transformation of attributes with a pragma
344/// spelling to transform expressions stored within the attribute.
345///
346/// \returns the transformed attribute.
347#define ATTR(X)
348#define PRAGMA_SPELLING_ATTR(X) \
349 const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; }
350#include "clang/Basic/AttrList.inc"
351
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000352 /// \brief Transform the given expression.
353 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000354 /// By default, this routine transforms an expression by delegating to the
355 /// appropriate TransformXXXExpr function to build a new expression.
356 /// Subclasses may override this function to transform expressions using some
357 /// other mechanism.
358 ///
359 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000360 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000361
Richard Smithd59b8322012-12-19 01:39:02 +0000362 /// \brief Transform the given initializer.
363 ///
364 /// By default, this routine transforms an initializer by stripping off the
365 /// semantic nodes added by initialization, then passing the result to
366 /// TransformExpr or TransformExprs.
367 ///
368 /// \returns the transformed initializer.
Richard Smithc6abd962014-07-25 01:12:44 +0000369 ExprResult TransformInitializer(Expr *Init, bool NotCopyInit);
Richard Smithd59b8322012-12-19 01:39:02 +0000370
Douglas Gregora3efea12011-01-03 19:04:46 +0000371 /// \brief Transform the given list of expressions.
372 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000373 /// This routine transforms a list of expressions by invoking
374 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregora3efea12011-01-03 19:04:46 +0000375 /// support for variadic templates by expanding any pack expansions (if the
376 /// derived class permits such expansion) along the way. When pack expansions
377 /// are present, the number of outputs may not equal the number of inputs.
378 ///
379 /// \param Inputs The set of expressions to be transformed.
380 ///
381 /// \param NumInputs The number of expressions in \c Inputs.
382 ///
383 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier1dcde962012-08-08 18:46:20 +0000384 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregora3efea12011-01-03 19:04:46 +0000385 /// be.
386 ///
387 /// \param Outputs The transformed input expressions will be added to this
388 /// vector.
389 ///
390 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
391 /// due to transformation.
392 ///
393 /// \returns true if an error occurred, false otherwise.
Craig Topper99d23532015-12-24 23:58:29 +0000394 bool TransformExprs(Expr *const *Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000395 SmallVectorImpl<Expr *> &Outputs,
Craig Topperc3ec1492014-05-26 06:22:03 +0000396 bool *ArgChanged = nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000397
Douglas Gregord6ff3322009-08-04 16:50:30 +0000398 /// \brief Transform the given declaration, which is referenced from a type
399 /// or expression.
400 ///
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000401 /// By default, acts as the identity function on declarations, unless the
402 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregor1135c352009-08-06 05:28:30 +0000403 /// may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000404 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000405 llvm::DenseMap<Decl *, Decl *>::iterator Known
406 = TransformedLocalDecls.find(D);
407 if (Known != TransformedLocalDecls.end())
408 return Known->second;
Chad Rosier1dcde962012-08-08 18:46:20 +0000409
410 return D;
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000411 }
Douglas Gregorebe10102009-08-20 07:17:43 +0000412
Chad Rosier1dcde962012-08-08 18:46:20 +0000413 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000414 /// place them on the new declaration.
415 ///
416 /// By default, this operation does nothing. Subclasses may override this
417 /// behavior to transform attributes.
418 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000419
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000420 /// \brief Note that a local declaration has been transformed by this
421 /// transformer.
422 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000423 /// Local declarations are typically transformed via a call to
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000424 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
425 /// the transformer itself has to transform the declarations. This routine
426 /// can be overridden by a subclass that keeps track of such mappings.
427 void transformedLocalDecl(Decl *Old, Decl *New) {
428 TransformedLocalDecls[Old] = New;
429 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000430
Douglas Gregorebe10102009-08-20 07:17:43 +0000431 /// \brief Transform the definition of the given declaration.
432 ///
Mike Stump11289f42009-09-09 15:08:12 +0000433 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000434 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000435 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
436 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000437 }
Mike Stump11289f42009-09-09 15:08:12 +0000438
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000439 /// \brief Transform the given declaration, which was the first part of a
440 /// nested-name-specifier in a member access expression.
441 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000442 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000443 /// identifier in a nested-name-specifier of a member access expression, e.g.,
444 /// the \c T in \c x->T::member
445 ///
446 /// By default, invokes TransformDecl() to transform the declaration.
447 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000448 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
449 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000450 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000451
Douglas Gregor14454802011-02-25 02:25:35 +0000452 /// \brief Transform the given nested-name-specifier with source-location
453 /// information.
454 ///
455 /// By default, transforms all of the types and declarations within the
456 /// nested-name-specifier. Subclasses may override this function to provide
457 /// alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000458 NestedNameSpecifierLoc
459 TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
460 QualType ObjectType = QualType(),
461 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor14454802011-02-25 02:25:35 +0000462
Douglas Gregorf816bd72009-09-03 22:13:48 +0000463 /// \brief Transform the given declaration name.
464 ///
465 /// By default, transforms the types of conversion function, constructor,
466 /// and destructor names and then (if needed) rebuilds the declaration name.
467 /// Identifiers and selectors are returned unmodified. Sublcasses may
468 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000469 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000470 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000471
Douglas Gregord6ff3322009-08-04 16:50:30 +0000472 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000473 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000474 /// \param SS The nested-name-specifier that qualifies the template
475 /// name. This nested-name-specifier must already have been transformed.
476 ///
477 /// \param Name The template name to transform.
478 ///
479 /// \param NameLoc The source location of the template name.
480 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000481 /// \param ObjectType If we're translating a template name within a member
Douglas Gregor9db53502011-03-02 18:07:45 +0000482 /// access expression, this is the type of the object whose member template
483 /// is being referenced.
484 ///
485 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
486 /// also refers to a name within the current (lexical) scope, this is the
487 /// declaration it refers to.
488 ///
489 /// By default, transforms the template name by transforming the declarations
490 /// and nested-name-specifiers that occur within the template name.
491 /// Subclasses may override this function to provide alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000492 TemplateName
493 TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
494 SourceLocation NameLoc,
495 QualType ObjectType = QualType(),
496 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor9db53502011-03-02 18:07:45 +0000497
Douglas Gregord6ff3322009-08-04 16:50:30 +0000498 /// \brief Transform the given template argument.
499 ///
Mike Stump11289f42009-09-09 15:08:12 +0000500 /// By default, this operation transforms the type, expression, or
501 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000502 /// new template argument from the transformed result. Subclasses may
503 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000504 ///
505 /// Returns true if there was an error.
506 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +0000507 TemplateArgumentLoc &Output,
508 bool Uneval = false);
John McCall0ad16662009-10-29 08:12:44 +0000509
Douglas Gregor62e06f22010-12-20 17:31:10 +0000510 /// \brief Transform the given set of template arguments.
511 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000512 /// By default, this operation transforms all of the template arguments
Douglas Gregor62e06f22010-12-20 17:31:10 +0000513 /// in the input set using \c TransformTemplateArgument(), and appends
514 /// the transformed arguments to the output list.
515 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000516 /// Note that this overload of \c TransformTemplateArguments() is merely
517 /// a convenience function. Subclasses that wish to override this behavior
518 /// should override the iterator-based member template version.
519 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000520 /// \param Inputs The set of template arguments to be transformed.
521 ///
522 /// \param NumInputs The number of template arguments in \p Inputs.
523 ///
524 /// \param Outputs The set of transformed template arguments output by this
525 /// routine.
526 ///
527 /// Returns true if an error occurred.
528 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
529 unsigned NumInputs,
Richard Smithd784e682015-09-23 21:41:42 +0000530 TemplateArgumentListInfo &Outputs,
531 bool Uneval = false) {
532 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs,
533 Uneval);
Douglas Gregorfe921a72010-12-20 23:36:19 +0000534 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000535
536 /// \brief Transform the given set of template arguments.
537 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000538 /// By default, this operation transforms all of the template arguments
Douglas Gregor42cafa82010-12-20 17:42:22 +0000539 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier1dcde962012-08-08 18:46:20 +0000540 /// the transformed arguments to the output list.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000541 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000542 /// \param First An iterator to the first template argument.
543 ///
544 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000545 ///
546 /// \param Outputs The set of transformed template arguments output by this
547 /// routine.
548 ///
549 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000550 template<typename InputIterator>
551 bool TransformTemplateArguments(InputIterator First,
552 InputIterator Last,
Richard Smithd784e682015-09-23 21:41:42 +0000553 TemplateArgumentListInfo &Outputs,
554 bool Uneval = false);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000555
John McCall0ad16662009-10-29 08:12:44 +0000556 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
557 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
558 TemplateArgumentLoc &ArgLoc);
559
John McCallbcd03502009-12-07 02:54:59 +0000560 /// \brief Fakes up a TypeSourceInfo for a type.
561 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
562 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000563 getDerived().getBaseLocation());
564 }
Mike Stump11289f42009-09-09 15:08:12 +0000565
John McCall550e0c22009-10-21 00:40:46 +0000566#define ABSTRACT_TYPELOC(CLASS, PARENT)
567#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000568 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000569#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000570
Richard Smith2e321552014-11-12 02:00:47 +0000571 template<typename Fn>
Douglas Gregor3024f072012-04-16 07:05:22 +0000572 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
573 FunctionProtoTypeLoc TL,
574 CXXRecordDecl *ThisContext,
Richard Smith2e321552014-11-12 02:00:47 +0000575 unsigned ThisTypeQuals,
576 Fn TransformExceptionSpec);
577
578 bool TransformExceptionSpec(SourceLocation Loc,
579 FunctionProtoType::ExceptionSpecInfo &ESI,
580 SmallVectorImpl<QualType> &Exceptions,
581 bool &Changed);
Douglas Gregor3024f072012-04-16 07:05:22 +0000582
David Majnemerfad8f482013-10-15 09:33:02 +0000583 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000584
Chad Rosier1dcde962012-08-08 18:46:20 +0000585 QualType
John McCall31f82722010-11-12 08:19:04 +0000586 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
587 TemplateSpecializationTypeLoc TL,
588 TemplateName Template);
589
Chad Rosier1dcde962012-08-08 18:46:20 +0000590 QualType
John McCall31f82722010-11-12 08:19:04 +0000591 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
592 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000593 TemplateName Template,
594 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000595
Nico Weberc153d242014-07-28 00:02:09 +0000596 QualType TransformDependentTemplateSpecializationType(
597 TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL,
598 NestedNameSpecifierLoc QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000599
John McCall58f10c32010-03-11 09:03:00 +0000600 /// \brief Transforms the parameters of a function type into the
601 /// given vectors.
602 ///
603 /// The result vectors should be kept in sync; null entries in the
604 /// variables vector are acceptable.
605 ///
606 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000607 bool TransformFunctionTypeParams(SourceLocation Loc,
608 ParmVarDecl **Params, unsigned NumParams,
609 const QualType *ParamTypes,
John McCallc8e321d2016-03-01 02:09:25 +0000610 const FunctionProtoType::ExtParameterInfo *ParamInfos,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000611 SmallVectorImpl<QualType> &PTypes,
John McCallc8e321d2016-03-01 02:09:25 +0000612 SmallVectorImpl<ParmVarDecl*> *PVars,
613 Sema::ExtParameterInfoBuilder &PInfos);
John McCall58f10c32010-03-11 09:03:00 +0000614
615 /// \brief Transforms a single function-type parameter. Return null
616 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000617 ///
618 /// \param indexAdjustment - A number to add to the parameter's
619 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000620 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000621 int indexAdjustment,
David Blaikie05785d12013-02-20 22:23:23 +0000622 Optional<unsigned> NumExpansions,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +0000623 bool ExpectParameterPack);
John McCall58f10c32010-03-11 09:03:00 +0000624
John McCall31f82722010-11-12 08:19:04 +0000625 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000626
John McCalldadc5752010-08-24 06:29:42 +0000627 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
628 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Richard Smith2589b9802012-07-25 03:56:55 +0000629
Faisal Vali2cba1332013-10-23 06:44:28 +0000630 TemplateParameterList *TransformTemplateParameterList(
631 TemplateParameterList *TPL) {
632 return TPL;
633 }
634
Richard Smithdb2630f2012-10-21 03:28:35 +0000635 ExprResult TransformAddressOfOperand(Expr *E);
Reid Kleckner32506ed2014-06-12 23:03:48 +0000636
Richard Smithdb2630f2012-10-21 03:28:35 +0000637 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +0000638 bool IsAddressOfOperand,
639 TypeSourceInfo **RecoveryTSI);
640
641 ExprResult TransformParenDependentScopeDeclRefExpr(
642 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
643 TypeSourceInfo **RecoveryTSI);
644
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000645 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000646
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000647// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
648// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000649#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000650 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000651 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000652#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000653 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000654 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000655#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000656#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000657
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000658#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000659 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000660 OMPClause *Transform ## Class(Class *S);
661#include "clang/Basic/OpenMPKinds.def"
662
Douglas Gregord6ff3322009-08-04 16:50:30 +0000663 /// \brief Build a new pointer type given its pointee type.
664 ///
665 /// By default, performs semantic analysis when building the pointer type.
666 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000667 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000668
669 /// \brief Build a new block pointer type given its pointee type.
670 ///
Mike Stump11289f42009-09-09 15:08:12 +0000671 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000672 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000673 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000674
John McCall70dd5f62009-10-30 00:06:24 +0000675 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000676 ///
John McCall70dd5f62009-10-30 00:06:24 +0000677 /// By default, performs semantic analysis when building the
678 /// reference type. Subclasses may override this routine to provide
679 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000680 ///
John McCall70dd5f62009-10-30 00:06:24 +0000681 /// \param LValue whether the type was written with an lvalue sigil
682 /// or an rvalue sigil.
683 QualType RebuildReferenceType(QualType ReferentType,
684 bool LValue,
685 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000686
Douglas Gregord6ff3322009-08-04 16:50:30 +0000687 /// \brief Build a new member pointer type given the pointee type and the
688 /// class type it refers into.
689 ///
690 /// By default, performs semantic analysis when building the member pointer
691 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000692 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
693 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000694
Douglas Gregor9bda6cf2015-07-07 03:58:14 +0000695 /// \brief Build an Objective-C object type.
696 ///
697 /// By default, performs semantic analysis when building the object type.
698 /// Subclasses may override this routine to provide different behavior.
699 QualType RebuildObjCObjectType(QualType BaseType,
700 SourceLocation Loc,
701 SourceLocation TypeArgsLAngleLoc,
702 ArrayRef<TypeSourceInfo *> TypeArgs,
703 SourceLocation TypeArgsRAngleLoc,
704 SourceLocation ProtocolLAngleLoc,
705 ArrayRef<ObjCProtocolDecl *> Protocols,
706 ArrayRef<SourceLocation> ProtocolLocs,
707 SourceLocation ProtocolRAngleLoc);
708
709 /// \brief Build a new Objective-C object pointer type given the pointee type.
710 ///
711 /// By default, directly builds the pointer type, with no additional semantic
712 /// analysis.
713 QualType RebuildObjCObjectPointerType(QualType PointeeType,
714 SourceLocation Star);
715
Douglas Gregord6ff3322009-08-04 16:50:30 +0000716 /// \brief Build a new array type given the element type, size
717 /// modifier, size of the array (if known), size expression, and index type
718 /// qualifiers.
719 ///
720 /// By default, performs semantic analysis when building the array type.
721 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000722 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000723 QualType RebuildArrayType(QualType ElementType,
724 ArrayType::ArraySizeModifier SizeMod,
725 const llvm::APInt *Size,
726 Expr *SizeExpr,
727 unsigned IndexTypeQuals,
728 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000729
Douglas Gregord6ff3322009-08-04 16:50:30 +0000730 /// \brief Build a new constant array type given the element type, size
731 /// modifier, (known) size of the array, and index type qualifiers.
732 ///
733 /// By default, performs semantic analysis when building the array type.
734 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000735 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000736 ArrayType::ArraySizeModifier SizeMod,
737 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000738 unsigned IndexTypeQuals,
739 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000740
Douglas Gregord6ff3322009-08-04 16:50:30 +0000741 /// \brief Build a new incomplete array type given the element type, size
742 /// modifier, and index type qualifiers.
743 ///
744 /// By default, performs semantic analysis when building the array type.
745 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000746 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000747 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000748 unsigned IndexTypeQuals,
749 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000750
Mike Stump11289f42009-09-09 15:08:12 +0000751 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000752 /// size modifier, size expression, and index type qualifiers.
753 ///
754 /// By default, performs semantic analysis when building the array type.
755 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000756 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000757 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000758 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000759 unsigned IndexTypeQuals,
760 SourceRange BracketsRange);
761
Mike Stump11289f42009-09-09 15:08:12 +0000762 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000763 /// size modifier, size expression, and index type qualifiers.
764 ///
765 /// By default, performs semantic analysis when building the array type.
766 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000767 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000768 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000769 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000770 unsigned IndexTypeQuals,
771 SourceRange BracketsRange);
772
773 /// \brief Build a new vector type given the element type and
774 /// number of elements.
775 ///
776 /// By default, performs semantic analysis when building the vector type.
777 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000778 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000779 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000780
Douglas Gregord6ff3322009-08-04 16:50:30 +0000781 /// \brief Build a new extended 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.
786 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
787 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000788
789 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000790 /// given the element type and 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.
Mike Stump11289f42009-09-09 15:08:12 +0000794 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000795 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000796 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000797
Douglas Gregord6ff3322009-08-04 16:50:30 +0000798 /// \brief Build a new function type.
799 ///
800 /// By default, performs semantic analysis when building the function type.
801 /// Subclasses may override this routine to provide different behavior.
802 QualType RebuildFunctionProtoType(QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +0000803 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000804 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000805
John McCall550e0c22009-10-21 00:40:46 +0000806 /// \brief Build a new unprototyped function type.
807 QualType RebuildFunctionNoProtoType(QualType ResultType);
808
John McCallb96ec562009-12-04 22:46:56 +0000809 /// \brief Rebuild an unresolved typename type, given the decl that
810 /// the UnresolvedUsingTypenameDecl was transformed to.
811 QualType RebuildUnresolvedUsingType(Decl *D);
812
Douglas Gregord6ff3322009-08-04 16:50:30 +0000813 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000814 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000815 return SemaRef.Context.getTypeDeclType(Typedef);
816 }
817
818 /// \brief Build a new class/struct/union type.
819 QualType RebuildRecordType(RecordDecl *Record) {
820 return SemaRef.Context.getTypeDeclType(Record);
821 }
822
823 /// \brief Build a new Enum type.
824 QualType RebuildEnumType(EnumDecl *Enum) {
825 return SemaRef.Context.getTypeDeclType(Enum);
826 }
John McCallfcc33b02009-09-05 00:15:47 +0000827
Mike Stump11289f42009-09-09 15:08:12 +0000828 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000829 ///
830 /// By default, performs semantic analysis when building the typeof type.
831 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000832 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000833
Mike Stump11289f42009-09-09 15:08:12 +0000834 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000835 ///
836 /// By default, builds a new TypeOfType with the given underlying type.
837 QualType RebuildTypeOfType(QualType Underlying);
838
Alexis Hunte852b102011-05-24 22:41:36 +0000839 /// \brief Build a new unary transform type.
840 QualType RebuildUnaryTransformType(QualType BaseType,
841 UnaryTransformType::UTTKind UKind,
842 SourceLocation Loc);
843
Richard Smith74aeef52013-04-26 16:15:35 +0000844 /// \brief Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000845 ///
846 /// By default, performs semantic analysis when building the decltype type.
847 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000848 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000849
Richard Smith74aeef52013-04-26 16:15:35 +0000850 /// \brief Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000851 ///
852 /// By default, builds a new AutoType with the given deduced type.
Richard Smithe301ba22015-11-11 02:02:15 +0000853 QualType RebuildAutoType(QualType Deduced, AutoTypeKeyword Keyword) {
Richard Smith27d807c2013-04-30 13:56:41 +0000854 // Note, IsDependent is always false here: we implicitly convert an 'auto'
855 // which has been deduced to a dependent type into an undeduced 'auto', so
856 // that we'll retry deduction after the transformation.
Richard Smithe301ba22015-11-11 02:02:15 +0000857 return SemaRef.Context.getAutoType(Deduced, Keyword,
Faisal Vali2b391ab2013-09-26 19:54:12 +0000858 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000859 }
860
Douglas Gregord6ff3322009-08-04 16:50:30 +0000861 /// \brief Build a new template specialization type.
862 ///
863 /// By default, performs semantic analysis when building the template
864 /// specialization type. Subclasses may override this routine to provide
865 /// different behavior.
866 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000867 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000868 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000869
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000870 /// \brief Build a new parenthesized type.
871 ///
872 /// By default, builds a new ParenType type from the inner type.
873 /// Subclasses may override this routine to provide different behavior.
874 QualType RebuildParenType(QualType InnerType) {
875 return SemaRef.Context.getParenType(InnerType);
876 }
877
Douglas Gregord6ff3322009-08-04 16:50:30 +0000878 /// \brief Build a new qualified name type.
879 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000880 /// By default, builds a new ElaboratedType type from the keyword,
881 /// the nested-name-specifier and the named type.
882 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000883 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
884 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000885 NestedNameSpecifierLoc QualifierLoc,
886 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000887 return SemaRef.Context.getElaboratedType(Keyword,
888 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000889 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000890 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000891
892 /// \brief Build a new typename type that refers to a template-id.
893 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000894 /// By default, builds a new DependentNameType type from the
895 /// nested-name-specifier and the given type. Subclasses may override
896 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000897 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000898 ElaboratedTypeKeyword Keyword,
899 NestedNameSpecifierLoc QualifierLoc,
900 const IdentifierInfo *Name,
901 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000902 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000903 // Rebuild the template name.
904 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000905 CXXScopeSpec SS;
906 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +0000907 TemplateName InstName
Craig Topperc3ec1492014-05-26 06:22:03 +0000908 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(),
909 nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000910
Douglas Gregora7a795b2011-03-01 20:11:18 +0000911 if (InstName.isNull())
912 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000913
Douglas Gregora7a795b2011-03-01 20:11:18 +0000914 // If it's still dependent, make a dependent specialization.
915 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000916 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
917 QualifierLoc.getNestedNameSpecifier(),
918 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000919 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000920
Douglas Gregora7a795b2011-03-01 20:11:18 +0000921 // Otherwise, make an elaborated type wrapping a non-dependent
922 // specialization.
923 QualType T =
924 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
925 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000926
Craig Topperc3ec1492014-05-26 06:22:03 +0000927 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
Douglas Gregora7a795b2011-03-01 20:11:18 +0000928 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +0000929
930 return SemaRef.Context.getElaboratedType(Keyword,
931 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +0000932 T);
933 }
934
Douglas Gregord6ff3322009-08-04 16:50:30 +0000935 /// \brief Build a new typename type that refers to an identifier.
936 ///
937 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000938 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000939 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000940 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000941 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000942 NestedNameSpecifierLoc QualifierLoc,
943 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000944 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000945 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000946 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000947
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000948 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000949 // If the name is still dependent, just build a new dependent name type.
950 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +0000951 return SemaRef.Context.getDependentNameType(Keyword,
952 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000953 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000954 }
955
Abramo Bagnara6150c882010-05-11 21:36:43 +0000956 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000957 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000958 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000959
960 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
961
Abramo Bagnarad7548482010-05-19 21:37:53 +0000962 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000963 // into a non-dependent elaborated-type-specifier. Find the tag we're
964 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000965 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000966 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
967 if (!DC)
968 return QualType();
969
John McCallbf8c5192010-05-27 06:40:31 +0000970 if (SemaRef.RequireCompleteDeclContext(SS, DC))
971 return QualType();
972
Craig Topperc3ec1492014-05-26 06:22:03 +0000973 TagDecl *Tag = nullptr;
Douglas Gregore677daf2010-03-31 22:19:08 +0000974 SemaRef.LookupQualifiedName(Result, DC);
975 switch (Result.getResultKind()) {
976 case LookupResult::NotFound:
977 case LookupResult::NotFoundInCurrentInstantiation:
978 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000979
Douglas Gregore677daf2010-03-31 22:19:08 +0000980 case LookupResult::Found:
981 Tag = Result.getAsSingle<TagDecl>();
982 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000983
Douglas Gregore677daf2010-03-31 22:19:08 +0000984 case LookupResult::FoundOverloaded:
985 case LookupResult::FoundUnresolvedValue:
986 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +0000987
Douglas Gregore677daf2010-03-31 22:19:08 +0000988 case LookupResult::Ambiguous:
989 // Let the LookupResult structure handle ambiguities.
990 return QualType();
991 }
992
993 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000994 // Check where the name exists but isn't a tag type and use that to emit
995 // better diagnostics.
996 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
997 SemaRef.LookupQualifiedName(Result, DC);
998 switch (Result.getResultKind()) {
999 case LookupResult::Found:
1000 case LookupResult::FoundOverloaded:
1001 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +00001002 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky0c438082011-01-24 19:01:04 +00001003 unsigned Kind = 0;
1004 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smithdda56e42011-04-15 14:24:37 +00001005 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
1006 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky0c438082011-01-24 19:01:04 +00001007 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
1008 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1009 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +00001010 }
Nick Lewycky0c438082011-01-24 19:01:04 +00001011 default:
Nick Lewycky0c438082011-01-24 19:01:04 +00001012 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +00001013 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +00001014 break;
1015 }
Douglas Gregore677daf2010-03-31 22:19:08 +00001016 return QualType();
1017 }
Abramo Bagnara6150c882010-05-11 21:36:43 +00001018
Richard Trieucaa33d32011-06-10 03:11:26 +00001019 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
Justin Bognerc6ecb7c2015-07-10 23:05:47 +00001020 IdLoc, Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +00001021 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +00001022 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1023 return QualType();
1024 }
1025
1026 // Build the elaborated-type-specifier type.
1027 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +00001028 return SemaRef.Context.getElaboratedType(Keyword,
1029 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001030 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00001031 }
Mike Stump11289f42009-09-09 15:08:12 +00001032
Douglas Gregor822d0302011-01-12 17:07:58 +00001033 /// \brief Build a new pack expansion type.
1034 ///
1035 /// By default, builds a new PackExpansionType type from the given pattern.
1036 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001037 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00001038 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001039 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00001040 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001041 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1042 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +00001043 }
1044
Eli Friedman0dfb8892011-10-06 23:00:33 +00001045 /// \brief Build a new atomic type given its value type.
1046 ///
1047 /// By default, performs semantic analysis when building the atomic type.
1048 /// Subclasses may override this routine to provide different behavior.
1049 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1050
Xiuli Pan9c14e282016-01-09 12:53:17 +00001051 /// \brief Build a new pipe type given its value type.
1052 QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc);
1053
Douglas Gregor71dc5092009-08-06 06:41:21 +00001054 /// \brief Build a new template name given a nested name specifier, a flag
1055 /// indicating whether the "template" keyword was provided, and the template
1056 /// that the template name refers to.
1057 ///
1058 /// By default, builds the new template name directly. Subclasses may override
1059 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001060 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001061 bool TemplateKW,
1062 TemplateDecl *Template);
1063
Douglas Gregor71dc5092009-08-06 06:41:21 +00001064 /// \brief Build a new template name given a nested name specifier and the
1065 /// name that is referred to as a template.
1066 ///
1067 /// By default, performs semantic analysis to determine whether the name can
1068 /// be resolved to a specific template, then builds the appropriate kind of
1069 /// template name. Subclasses may override this routine to provide different
1070 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001071 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1072 const IdentifierInfo &Name,
1073 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00001074 QualType ObjectType,
1075 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001076
Douglas Gregor71395fa2009-11-04 00:56:37 +00001077 /// \brief Build a new template name given a nested name specifier and the
1078 /// overloaded operator name that is referred to as a template.
1079 ///
1080 /// By default, performs semantic analysis to determine whether the name can
1081 /// be resolved to a specific template, then builds the appropriate kind of
1082 /// template name. Subclasses may override this routine to provide different
1083 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001084 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001085 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00001086 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001087 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +00001088
1089 /// \brief Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001090 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001091 ///
1092 /// By default, performs semantic analysis to determine whether the name can
1093 /// be resolved to a specific template, then builds the appropriate kind of
1094 /// template name. Subclasses may override this routine to provide different
1095 /// behavior.
1096 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1097 const TemplateArgument &ArgPack) {
1098 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1099 }
1100
Douglas Gregorebe10102009-08-20 07:17:43 +00001101 /// \brief Build a new compound statement.
1102 ///
1103 /// By default, performs semantic analysis to build the new statement.
1104 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001105 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001106 MultiStmtArg Statements,
1107 SourceLocation RBraceLoc,
1108 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001109 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001110 IsStmtExpr);
1111 }
1112
1113 /// \brief Build a new case statement.
1114 ///
1115 /// By default, performs semantic analysis to build the new statement.
1116 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001117 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001118 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001119 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001120 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001121 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001122 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001123 ColonLoc);
1124 }
Mike Stump11289f42009-09-09 15:08:12 +00001125
Douglas Gregorebe10102009-08-20 07:17:43 +00001126 /// \brief Attach the body to a new case statement.
1127 ///
1128 /// By default, performs semantic analysis to build the new statement.
1129 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001130 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001131 getSema().ActOnCaseStmtBody(S, Body);
1132 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001133 }
Mike Stump11289f42009-09-09 15:08:12 +00001134
Douglas Gregorebe10102009-08-20 07:17:43 +00001135 /// \brief Build a new default statement.
1136 ///
1137 /// By default, performs semantic analysis to build the new statement.
1138 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001139 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001140 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001141 Stmt *SubStmt) {
1142 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Craig Topperc3ec1492014-05-26 06:22:03 +00001143 /*CurScope=*/nullptr);
Douglas Gregorebe10102009-08-20 07:17:43 +00001144 }
Mike Stump11289f42009-09-09 15:08:12 +00001145
Douglas Gregorebe10102009-08-20 07:17:43 +00001146 /// \brief Build a new label statement.
1147 ///
1148 /// By default, performs semantic analysis to build the new statement.
1149 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001150 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1151 SourceLocation ColonLoc, Stmt *SubStmt) {
1152 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001153 }
Mike Stump11289f42009-09-09 15:08:12 +00001154
Richard Smithc202b282012-04-14 00:33:13 +00001155 /// \brief Build a new label statement.
1156 ///
1157 /// By default, performs semantic analysis to build the new statement.
1158 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001159 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1160 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001161 Stmt *SubStmt) {
1162 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1163 }
1164
Douglas Gregorebe10102009-08-20 07:17:43 +00001165 /// \brief Build a new "if" statement.
1166 ///
1167 /// By default, performs semantic analysis to build the new statement.
1168 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001169 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier1dcde962012-08-08 18:46:20 +00001170 VarDecl *CondVar, Stmt *Then,
Chris Lattnercab02a62011-02-17 20:34:02 +00001171 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001172 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001173 }
Mike Stump11289f42009-09-09 15:08:12 +00001174
Douglas Gregorebe10102009-08-20 07:17:43 +00001175 /// \brief Start building a new switch statement.
1176 ///
1177 /// By default, performs semantic analysis to build the new statement.
1178 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001179 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001180 Expr *Cond, VarDecl *CondVar) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001181 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001182 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001183 }
Mike Stump11289f42009-09-09 15:08:12 +00001184
Douglas Gregorebe10102009-08-20 07:17:43 +00001185 /// \brief Attach the body to the switch statement.
1186 ///
1187 /// By default, performs semantic analysis to build the new statement.
1188 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001189 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001190 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001191 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001192 }
1193
1194 /// \brief Build a new while statement.
1195 ///
1196 /// By default, performs semantic analysis to build the new statement.
1197 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001198 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1199 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001200 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001201 }
Mike Stump11289f42009-09-09 15:08:12 +00001202
Douglas Gregorebe10102009-08-20 07:17:43 +00001203 /// \brief Build a new do-while statement.
1204 ///
1205 /// By default, performs semantic analysis to build the new statement.
1206 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001207 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001208 SourceLocation WhileLoc, SourceLocation LParenLoc,
1209 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001210 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1211 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001212 }
1213
1214 /// \brief Build a new for statement.
1215 ///
1216 /// By default, performs semantic analysis to build the new statement.
1217 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001218 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier1dcde962012-08-08 18:46:20 +00001219 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001220 VarDecl *CondVar, Sema::FullExprArg Inc,
1221 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001222 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001223 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001224 }
Mike Stump11289f42009-09-09 15:08:12 +00001225
Douglas Gregorebe10102009-08-20 07:17:43 +00001226 /// \brief Build a new goto statement.
1227 ///
1228 /// By default, performs semantic analysis to build the new statement.
1229 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001230 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1231 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001232 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001233 }
1234
1235 /// \brief Build a new indirect goto statement.
1236 ///
1237 /// By default, performs semantic analysis to build the new statement.
1238 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001239 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001240 SourceLocation StarLoc,
1241 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001242 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001243 }
Mike Stump11289f42009-09-09 15:08:12 +00001244
Douglas Gregorebe10102009-08-20 07:17:43 +00001245 /// \brief Build a new return statement.
1246 ///
1247 /// By default, performs semantic analysis to build the new statement.
1248 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001249 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001250 return getSema().BuildReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001251 }
Mike Stump11289f42009-09-09 15:08:12 +00001252
Douglas Gregorebe10102009-08-20 07:17:43 +00001253 /// \brief Build a new declaration statement.
1254 ///
1255 /// By default, performs semantic analysis to build the new statement.
1256 /// Subclasses may override this routine to provide different behavior.
Craig Toppere3d2ecbe2014-06-28 23:22:33 +00001257 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
Rafael Espindolaab417692013-07-09 12:05:01 +00001258 SourceLocation StartLoc, SourceLocation EndLoc) {
1259 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001260 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001261 }
Mike Stump11289f42009-09-09 15:08:12 +00001262
Anders Carlssonaaeef072010-01-24 05:50:09 +00001263 /// \brief Build a new inline asm statement.
1264 ///
1265 /// By default, performs semantic analysis to build the new statement.
1266 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001267 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1268 bool IsVolatile, unsigned NumOutputs,
1269 unsigned NumInputs, IdentifierInfo **Names,
1270 MultiExprArg Constraints, MultiExprArg Exprs,
1271 Expr *AsmString, MultiExprArg Clobbers,
1272 SourceLocation RParenLoc) {
1273 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1274 NumInputs, Names, Constraints, Exprs,
1275 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001276 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001277
Chad Rosier32503022012-06-11 20:47:18 +00001278 /// \brief Build a new MS style inline asm statement.
1279 ///
1280 /// By default, performs semantic analysis to build the new statement.
1281 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001282 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001283 ArrayRef<Token> AsmToks,
1284 StringRef AsmString,
1285 unsigned NumOutputs, unsigned NumInputs,
1286 ArrayRef<StringRef> Constraints,
1287 ArrayRef<StringRef> Clobbers,
1288 ArrayRef<Expr*> Exprs,
1289 SourceLocation EndLoc) {
1290 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1291 NumOutputs, NumInputs,
1292 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001293 }
1294
Richard Smith9f690bd2015-10-27 06:02:45 +00001295 /// \brief Build a new co_return statement.
1296 ///
1297 /// By default, performs semantic analysis to build the new statement.
1298 /// Subclasses may override this routine to provide different behavior.
1299 StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result) {
1300 return getSema().BuildCoreturnStmt(CoreturnLoc, Result);
1301 }
1302
1303 /// \brief Build a new co_await expression.
1304 ///
1305 /// By default, performs semantic analysis to build the new expression.
1306 /// Subclasses may override this routine to provide different behavior.
1307 ExprResult RebuildCoawaitExpr(SourceLocation CoawaitLoc, Expr *Result) {
1308 return getSema().BuildCoawaitExpr(CoawaitLoc, Result);
1309 }
1310
1311 /// \brief Build a new co_yield expression.
1312 ///
1313 /// By default, performs semantic analysis to build the new expression.
1314 /// Subclasses may override this routine to provide different behavior.
1315 ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result) {
1316 return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1317 }
1318
James Dennett2a4d13c2012-06-15 07:13:21 +00001319 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001320 ///
1321 /// By default, performs semantic analysis to build the new statement.
1322 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001323 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001324 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001325 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001326 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001327 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001328 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001329 }
1330
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001331 /// \brief Rebuild an Objective-C exception declaration.
1332 ///
1333 /// By default, performs semantic analysis to build the new declaration.
1334 /// Subclasses may override this routine to provide different behavior.
1335 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1336 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001337 return getSema().BuildObjCExceptionDecl(TInfo, T,
1338 ExceptionDecl->getInnerLocStart(),
1339 ExceptionDecl->getLocation(),
1340 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001341 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001342
James Dennett2a4d13c2012-06-15 07:13:21 +00001343 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001344 ///
1345 /// By default, performs semantic analysis to build the new statement.
1346 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001347 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001348 SourceLocation RParenLoc,
1349 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001350 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001351 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001352 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001353 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001354
James Dennett2a4d13c2012-06-15 07:13:21 +00001355 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001356 ///
1357 /// By default, performs semantic analysis to build the new statement.
1358 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001359 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001360 Stmt *Body) {
1361 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001362 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001363
James Dennett2a4d13c2012-06-15 07:13:21 +00001364 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001365 ///
1366 /// By default, performs semantic analysis to build the new statement.
1367 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001368 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001369 Expr *Operand) {
1370 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001371 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001372
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001373 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001374 ///
1375 /// By default, performs semantic analysis to build the new statement.
1376 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001377 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001378 DeclarationNameInfo DirName,
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001379 OpenMPDirectiveKind CancelRegion,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001380 ArrayRef<OMPClause *> Clauses,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001381 Stmt *AStmt, SourceLocation StartLoc,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001382 SourceLocation EndLoc) {
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001383 return getSema().ActOnOpenMPExecutableDirective(
1384 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001385 }
1386
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001387 /// \brief Build a new OpenMP 'if' clause.
1388 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001389 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001390 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001391 OMPClause *RebuildOMPIfClause(OpenMPDirectiveKind NameModifier,
1392 Expr *Condition, SourceLocation StartLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001393 SourceLocation LParenLoc,
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001394 SourceLocation NameModifierLoc,
1395 SourceLocation ColonLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001396 SourceLocation EndLoc) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001397 return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc,
1398 LParenLoc, NameModifierLoc, ColonLoc,
1399 EndLoc);
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001400 }
1401
Alexey Bataev3778b602014-07-17 07:32:53 +00001402 /// \brief Build a new OpenMP 'final' clause.
1403 ///
1404 /// By default, performs semantic analysis to build the new OpenMP clause.
1405 /// Subclasses may override this routine to provide different behavior.
1406 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1407 SourceLocation LParenLoc,
1408 SourceLocation EndLoc) {
1409 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1410 EndLoc);
1411 }
1412
Alexey Bataev568a8332014-03-06 06:15:19 +00001413 /// \brief Build a new OpenMP 'num_threads' clause.
1414 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001415 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001416 /// Subclasses may override this routine to provide different behavior.
1417 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1418 SourceLocation StartLoc,
1419 SourceLocation LParenLoc,
1420 SourceLocation EndLoc) {
1421 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1422 LParenLoc, EndLoc);
1423 }
1424
Alexey Bataev62c87d22014-03-21 04:51:18 +00001425 /// \brief Build a new OpenMP 'safelen' clause.
1426 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001427 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001428 /// Subclasses may override this routine to provide different behavior.
1429 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1430 SourceLocation LParenLoc,
1431 SourceLocation EndLoc) {
1432 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1433 }
1434
Alexey Bataev66b15b52015-08-21 11:14:16 +00001435 /// \brief Build a new OpenMP 'simdlen' clause.
1436 ///
1437 /// By default, performs semantic analysis to build the new OpenMP clause.
1438 /// Subclasses may override this routine to provide different behavior.
1439 OMPClause *RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc,
1440 SourceLocation LParenLoc,
1441 SourceLocation EndLoc) {
1442 return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc);
1443 }
1444
Alexander Musman8bd31e62014-05-27 15:12:19 +00001445 /// \brief Build a new OpenMP 'collapse' clause.
1446 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001447 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001448 /// Subclasses may override this routine to provide different behavior.
1449 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1450 SourceLocation LParenLoc,
1451 SourceLocation EndLoc) {
1452 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1453 EndLoc);
1454 }
1455
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001456 /// \brief Build a new OpenMP 'default' clause.
1457 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001458 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001459 /// Subclasses may override this routine to provide different behavior.
1460 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1461 SourceLocation KindKwLoc,
1462 SourceLocation StartLoc,
1463 SourceLocation LParenLoc,
1464 SourceLocation EndLoc) {
1465 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1466 StartLoc, LParenLoc, EndLoc);
1467 }
1468
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001469 /// \brief Build a new OpenMP 'proc_bind' clause.
1470 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001471 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001472 /// Subclasses may override this routine to provide different behavior.
1473 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1474 SourceLocation KindKwLoc,
1475 SourceLocation StartLoc,
1476 SourceLocation LParenLoc,
1477 SourceLocation EndLoc) {
1478 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1479 StartLoc, LParenLoc, EndLoc);
1480 }
1481
Alexey Bataev56dafe82014-06-20 07:16:17 +00001482 /// \brief Build a new OpenMP 'schedule' clause.
1483 ///
1484 /// By default, performs semantic analysis to build the new OpenMP clause.
1485 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6402bca2015-12-28 07:25:51 +00001486 OMPClause *RebuildOMPScheduleClause(
1487 OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2,
1488 OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1489 SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1490 SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
Alexey Bataev56dafe82014-06-20 07:16:17 +00001491 return getSema().ActOnOpenMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00001492 M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1493 CommaLoc, EndLoc);
Alexey Bataev56dafe82014-06-20 07:16:17 +00001494 }
1495
Alexey Bataev10e775f2015-07-30 11:36:16 +00001496 /// \brief Build a new OpenMP 'ordered' clause.
1497 ///
1498 /// By default, performs semantic analysis to build the new OpenMP clause.
1499 /// Subclasses may override this routine to provide different behavior.
1500 OMPClause *RebuildOMPOrderedClause(SourceLocation StartLoc,
1501 SourceLocation EndLoc,
1502 SourceLocation LParenLoc, Expr *Num) {
1503 return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num);
1504 }
1505
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001506 /// \brief Build a new OpenMP 'private' clause.
1507 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001508 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001509 /// Subclasses may override this routine to provide different behavior.
1510 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1511 SourceLocation StartLoc,
1512 SourceLocation LParenLoc,
1513 SourceLocation EndLoc) {
1514 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1515 EndLoc);
1516 }
1517
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001518 /// \brief Build a new OpenMP 'firstprivate' clause.
1519 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001520 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001521 /// Subclasses may override this routine to provide different behavior.
1522 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1523 SourceLocation StartLoc,
1524 SourceLocation LParenLoc,
1525 SourceLocation EndLoc) {
1526 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1527 EndLoc);
1528 }
1529
Alexander Musman1bb328c2014-06-04 13:06:39 +00001530 /// \brief Build a new OpenMP 'lastprivate' clause.
1531 ///
1532 /// By default, performs semantic analysis to build the new OpenMP clause.
1533 /// Subclasses may override this routine to provide different behavior.
1534 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1535 SourceLocation StartLoc,
1536 SourceLocation LParenLoc,
1537 SourceLocation EndLoc) {
1538 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1539 EndLoc);
1540 }
1541
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001542 /// \brief Build a new OpenMP 'shared' clause.
1543 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001544 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001545 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001546 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1547 SourceLocation StartLoc,
1548 SourceLocation LParenLoc,
1549 SourceLocation EndLoc) {
1550 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1551 EndLoc);
1552 }
1553
Alexey Bataevc5e02582014-06-16 07:08:35 +00001554 /// \brief Build a new OpenMP 'reduction' clause.
1555 ///
1556 /// By default, performs semantic analysis to build the new statement.
1557 /// Subclasses may override this routine to provide different behavior.
1558 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1559 SourceLocation StartLoc,
1560 SourceLocation LParenLoc,
1561 SourceLocation ColonLoc,
1562 SourceLocation EndLoc,
1563 CXXScopeSpec &ReductionIdScopeSpec,
Alexey Bataeva839ddd2016-03-17 10:19:46 +00001564 const DeclarationNameInfo &ReductionId,
1565 ArrayRef<Expr *> UnresolvedReductions) {
Alexey Bataevc5e02582014-06-16 07:08:35 +00001566 return getSema().ActOnOpenMPReductionClause(
1567 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
Alexey Bataeva839ddd2016-03-17 10:19:46 +00001568 ReductionId, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00001569 }
1570
Alexander Musman8dba6642014-04-22 13:09:42 +00001571 /// \brief Build a new OpenMP 'linear' clause.
1572 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001573 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001574 /// Subclasses may override this routine to provide different behavior.
1575 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1576 SourceLocation StartLoc,
1577 SourceLocation LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001578 OpenMPLinearClauseKind Modifier,
1579 SourceLocation ModifierLoc,
Alexander Musman8dba6642014-04-22 13:09:42 +00001580 SourceLocation ColonLoc,
1581 SourceLocation EndLoc) {
1582 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001583 Modifier, ModifierLoc, ColonLoc,
1584 EndLoc);
Alexander Musman8dba6642014-04-22 13:09:42 +00001585 }
1586
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001587 /// \brief Build a new OpenMP 'aligned' clause.
1588 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001589 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001590 /// Subclasses may override this routine to provide different behavior.
1591 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1592 SourceLocation StartLoc,
1593 SourceLocation LParenLoc,
1594 SourceLocation ColonLoc,
1595 SourceLocation EndLoc) {
1596 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1597 LParenLoc, ColonLoc, EndLoc);
1598 }
1599
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001600 /// \brief Build a new OpenMP 'copyin' clause.
1601 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001602 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001603 /// Subclasses may override this routine to provide different behavior.
1604 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1605 SourceLocation StartLoc,
1606 SourceLocation LParenLoc,
1607 SourceLocation EndLoc) {
1608 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1609 EndLoc);
1610 }
1611
Alexey Bataevbae9a792014-06-27 10:37:06 +00001612 /// \brief Build a new OpenMP 'copyprivate' clause.
1613 ///
1614 /// By default, performs semantic analysis to build the new OpenMP clause.
1615 /// Subclasses may override this routine to provide different behavior.
1616 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1617 SourceLocation StartLoc,
1618 SourceLocation LParenLoc,
1619 SourceLocation EndLoc) {
1620 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1621 EndLoc);
1622 }
1623
Alexey Bataev6125da92014-07-21 11:26:11 +00001624 /// \brief Build a new OpenMP 'flush' pseudo clause.
1625 ///
1626 /// By default, performs semantic analysis to build the new OpenMP clause.
1627 /// Subclasses may override this routine to provide different behavior.
1628 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1629 SourceLocation StartLoc,
1630 SourceLocation LParenLoc,
1631 SourceLocation EndLoc) {
1632 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1633 EndLoc);
1634 }
1635
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001636 /// \brief Build a new OpenMP 'depend' pseudo clause.
1637 ///
1638 /// By default, performs semantic analysis to build the new OpenMP clause.
1639 /// Subclasses may override this routine to provide different behavior.
1640 OMPClause *
1641 RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
1642 SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1643 SourceLocation StartLoc, SourceLocation LParenLoc,
1644 SourceLocation EndLoc) {
1645 return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList,
1646 StartLoc, LParenLoc, EndLoc);
1647 }
1648
Michael Wonge710d542015-08-07 16:16:36 +00001649 /// \brief Build a new OpenMP 'device' clause.
1650 ///
1651 /// By default, performs semantic analysis to build the new statement.
1652 /// Subclasses may override this routine to provide different behavior.
1653 OMPClause *RebuildOMPDeviceClause(Expr *Device, SourceLocation StartLoc,
1654 SourceLocation LParenLoc,
1655 SourceLocation EndLoc) {
Kelvin Li099bb8c2015-11-24 20:50:12 +00001656 return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc,
Michael Wonge710d542015-08-07 16:16:36 +00001657 EndLoc);
1658 }
1659
Kelvin Li0bff7af2015-11-23 05:32:03 +00001660 /// \brief Build a new OpenMP 'map' clause.
1661 ///
1662 /// By default, performs semantic analysis to build the new OpenMP clause.
1663 /// Subclasses may override this routine to provide different behavior.
Samuel Antao23abd722016-01-19 20:40:49 +00001664 OMPClause *
1665 RebuildOMPMapClause(OpenMPMapClauseKind MapTypeModifier,
1666 OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
1667 SourceLocation MapLoc, SourceLocation ColonLoc,
1668 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1669 SourceLocation LParenLoc, SourceLocation EndLoc) {
1670 return getSema().ActOnOpenMPMapClause(MapTypeModifier, MapType,
1671 IsMapTypeImplicit, MapLoc, ColonLoc,
1672 VarList, StartLoc, LParenLoc, EndLoc);
Kelvin Li0bff7af2015-11-23 05:32:03 +00001673 }
1674
Kelvin Li099bb8c2015-11-24 20:50:12 +00001675 /// \brief Build a new OpenMP 'num_teams' clause.
1676 ///
1677 /// By default, performs semantic analysis to build the new statement.
1678 /// Subclasses may override this routine to provide different behavior.
1679 OMPClause *RebuildOMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc,
1680 SourceLocation LParenLoc,
1681 SourceLocation EndLoc) {
1682 return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc,
1683 EndLoc);
1684 }
1685
Kelvin Lia15fb1a2015-11-27 18:47:36 +00001686 /// \brief Build a new OpenMP 'thread_limit' clause.
1687 ///
1688 /// By default, performs semantic analysis to build the new statement.
1689 /// Subclasses may override this routine to provide different behavior.
1690 OMPClause *RebuildOMPThreadLimitClause(Expr *ThreadLimit,
1691 SourceLocation StartLoc,
1692 SourceLocation LParenLoc,
1693 SourceLocation EndLoc) {
1694 return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc,
1695 LParenLoc, EndLoc);
1696 }
1697
Alexey Bataeva0569352015-12-01 10:17:31 +00001698 /// \brief Build a new OpenMP 'priority' clause.
1699 ///
1700 /// By default, performs semantic analysis to build the new statement.
1701 /// Subclasses may override this routine to provide different behavior.
1702 OMPClause *RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc,
1703 SourceLocation LParenLoc,
1704 SourceLocation EndLoc) {
1705 return getSema().ActOnOpenMPPriorityClause(Priority, StartLoc, LParenLoc,
1706 EndLoc);
1707 }
1708
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00001709 /// \brief Build a new OpenMP 'grainsize' clause.
1710 ///
1711 /// By default, performs semantic analysis to build the new statement.
1712 /// Subclasses may override this routine to provide different behavior.
1713 OMPClause *RebuildOMPGrainsizeClause(Expr *Grainsize, SourceLocation StartLoc,
1714 SourceLocation LParenLoc,
1715 SourceLocation EndLoc) {
1716 return getSema().ActOnOpenMPGrainsizeClause(Grainsize, StartLoc, LParenLoc,
1717 EndLoc);
1718 }
1719
Alexey Bataev382967a2015-12-08 12:06:20 +00001720 /// \brief Build a new OpenMP 'num_tasks' clause.
1721 ///
1722 /// By default, performs semantic analysis to build the new statement.
1723 /// Subclasses may override this routine to provide different behavior.
1724 OMPClause *RebuildOMPNumTasksClause(Expr *NumTasks, SourceLocation StartLoc,
1725 SourceLocation LParenLoc,
1726 SourceLocation EndLoc) {
1727 return getSema().ActOnOpenMPNumTasksClause(NumTasks, StartLoc, LParenLoc,
1728 EndLoc);
1729 }
1730
Alexey Bataev28c75412015-12-15 08:19:24 +00001731 /// \brief Build a new OpenMP 'hint' clause.
1732 ///
1733 /// By default, performs semantic analysis to build the new statement.
1734 /// Subclasses may override this routine to provide different behavior.
1735 OMPClause *RebuildOMPHintClause(Expr *Hint, SourceLocation StartLoc,
1736 SourceLocation LParenLoc,
1737 SourceLocation EndLoc) {
1738 return getSema().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc, EndLoc);
1739 }
1740
Carlo Bertollib4adf552016-01-15 18:50:31 +00001741 /// \brief Build a new OpenMP 'dist_schedule' clause.
1742 ///
1743 /// By default, performs semantic analysis to build the new OpenMP clause.
1744 /// Subclasses may override this routine to provide different behavior.
1745 OMPClause *
1746 RebuildOMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind,
1747 Expr *ChunkSize, SourceLocation StartLoc,
1748 SourceLocation LParenLoc, SourceLocation KindLoc,
1749 SourceLocation CommaLoc, SourceLocation EndLoc) {
1750 return getSema().ActOnOpenMPDistScheduleClause(
1751 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1752 }
1753
Samuel Antao661c0902016-05-26 17:39:58 +00001754 /// \brief Build a new OpenMP 'to' clause.
1755 ///
1756 /// By default, performs semantic analysis to build the new statement.
1757 /// Subclasses may override this routine to provide different behavior.
1758 OMPClause *RebuildOMPToClause(ArrayRef<Expr *> VarList,
1759 SourceLocation StartLoc,
1760 SourceLocation LParenLoc,
1761 SourceLocation EndLoc) {
1762 return getSema().ActOnOpenMPToClause(VarList, StartLoc, LParenLoc, EndLoc);
1763 }
1764
Samuel Antaoec172c62016-05-26 17:49:04 +00001765 /// \brief Build a new OpenMP 'from' clause.
1766 ///
1767 /// By default, performs semantic analysis to build the new statement.
1768 /// Subclasses may override this routine to provide different behavior.
1769 OMPClause *RebuildOMPFromClause(ArrayRef<Expr *> VarList,
1770 SourceLocation StartLoc,
1771 SourceLocation LParenLoc,
1772 SourceLocation EndLoc) {
1773 return getSema().ActOnOpenMPFromClause(VarList, StartLoc, LParenLoc,
1774 EndLoc);
1775 }
1776
James Dennett2a4d13c2012-06-15 07:13:21 +00001777 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001778 ///
1779 /// By default, performs semantic analysis to build the new statement.
1780 /// Subclasses may override this routine to provide different behavior.
1781 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1782 Expr *object) {
1783 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1784 }
1785
James Dennett2a4d13c2012-06-15 07:13:21 +00001786 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001787 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001788 /// By default, performs semantic analysis to build the new statement.
1789 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001790 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001791 Expr *Object, Stmt *Body) {
1792 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001793 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001794
James Dennett2a4d13c2012-06-15 07:13:21 +00001795 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001796 ///
1797 /// By default, performs semantic analysis to build the new statement.
1798 /// Subclasses may override this routine to provide different behavior.
1799 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1800 Stmt *Body) {
1801 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1802 }
John McCall53848232011-07-27 01:07:15 +00001803
Douglas Gregorf68a5082010-04-22 23:10:45 +00001804 /// \brief Build a new Objective-C fast enumeration statement.
1805 ///
1806 /// By default, performs semantic analysis to build the new statement.
1807 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001808 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001809 Stmt *Element,
1810 Expr *Collection,
1811 SourceLocation RParenLoc,
1812 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001813 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001814 Element,
John McCallb268a282010-08-23 23:25:46 +00001815 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001816 RParenLoc);
1817 if (ForEachStmt.isInvalid())
1818 return StmtError();
1819
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001820 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001821 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001822
Douglas Gregorebe10102009-08-20 07:17:43 +00001823 /// \brief Build a new C++ exception declaration.
1824 ///
1825 /// By default, performs semantic analysis to build the new decaration.
1826 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001827 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001828 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001829 SourceLocation StartLoc,
1830 SourceLocation IdLoc,
1831 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001832 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001833 StartLoc, IdLoc, Id);
1834 if (Var)
1835 getSema().CurContext->addDecl(Var);
1836 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001837 }
1838
1839 /// \brief Build a new C++ catch statement.
1840 ///
1841 /// By default, performs semantic analysis to build the new statement.
1842 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001843 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001844 VarDecl *ExceptionDecl,
1845 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001846 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1847 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001848 }
Mike Stump11289f42009-09-09 15:08:12 +00001849
Douglas Gregorebe10102009-08-20 07:17:43 +00001850 /// \brief Build a new C++ try statement.
1851 ///
1852 /// By default, performs semantic analysis to build the new statement.
1853 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001854 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1855 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001856 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001857 }
Mike Stump11289f42009-09-09 15:08:12 +00001858
Richard Smith02e85f32011-04-14 22:09:26 +00001859 /// \brief Build a new C++0x range-based for statement.
1860 ///
1861 /// By default, performs semantic analysis to build the new statement.
1862 /// Subclasses may override this routine to provide different behavior.
1863 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
Richard Smith9f690bd2015-10-27 06:02:45 +00001864 SourceLocation CoawaitLoc,
Richard Smith02e85f32011-04-14 22:09:26 +00001865 SourceLocation ColonLoc,
Richard Smith01694c32016-03-20 10:33:40 +00001866 Stmt *Range, Stmt *Begin, Stmt *End,
Richard Smith02e85f32011-04-14 22:09:26 +00001867 Expr *Cond, Expr *Inc,
1868 Stmt *LoopVar,
1869 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001870 // If we've just learned that the range is actually an Objective-C
1871 // collection, treat this as an Objective-C fast enumeration loop.
1872 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1873 if (RangeStmt->isSingleDecl()) {
1874 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001875 if (RangeVar->isInvalidDecl())
1876 return StmtError();
1877
Douglas Gregorf7106af2013-04-08 18:40:13 +00001878 Expr *RangeExpr = RangeVar->getInit();
1879 if (!RangeExpr->isTypeDependent() &&
1880 RangeExpr->getType()->isObjCObjectPointerType())
1881 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1882 RParenLoc);
1883 }
1884 }
1885 }
1886
Richard Smithcfd53b42015-10-22 06:13:50 +00001887 return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, ColonLoc,
Richard Smith01694c32016-03-20 10:33:40 +00001888 Range, Begin, End,
Richard Smitha05b3b52012-09-20 21:52:32 +00001889 Cond, Inc, LoopVar, RParenLoc,
1890 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001891 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001892
1893 /// \brief Build a new C++0x range-based for statement.
1894 ///
1895 /// By default, performs semantic analysis to build the new statement.
1896 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001897 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001898 bool IsIfExists,
1899 NestedNameSpecifierLoc QualifierLoc,
1900 DeclarationNameInfo NameInfo,
1901 Stmt *Nested) {
1902 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1903 QualifierLoc, NameInfo, Nested);
1904 }
1905
Richard Smith02e85f32011-04-14 22:09:26 +00001906 /// \brief Attach body to a C++0x range-based for statement.
1907 ///
1908 /// By default, performs semantic analysis to finish the new statement.
1909 /// Subclasses may override this routine to provide different behavior.
1910 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1911 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1912 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001913
David Majnemerfad8f482013-10-15 09:33:02 +00001914 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00001915 Stmt *TryBlock, Stmt *Handler) {
1916 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001917 }
1918
David Majnemerfad8f482013-10-15 09:33:02 +00001919 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001920 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001921 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001922 }
1923
David Majnemerfad8f482013-10-15 09:33:02 +00001924 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
Nico Weberd64657f2015-03-09 02:47:59 +00001925 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001926 }
1927
Alexey Bataevec474782014-10-09 08:45:04 +00001928 /// \brief Build a new predefined expression.
1929 ///
1930 /// By default, performs semantic analysis to build the new expression.
1931 /// Subclasses may override this routine to provide different behavior.
1932 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
1933 PredefinedExpr::IdentType IT) {
1934 return getSema().BuildPredefinedExpr(Loc, IT);
1935 }
1936
Douglas Gregora16548e2009-08-11 05:31:07 +00001937 /// \brief Build a new expression that references a declaration.
1938 ///
1939 /// By default, performs semantic analysis to build the new expression.
1940 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001941 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001942 LookupResult &R,
1943 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001944 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1945 }
1946
1947
1948 /// \brief Build a new expression that references a declaration.
1949 ///
1950 /// By default, performs semantic analysis to build the new expression.
1951 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001952 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001953 ValueDecl *VD,
1954 const DeclarationNameInfo &NameInfo,
1955 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001956 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001957 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001958
1959 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001960
1961 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001962 }
Mike Stump11289f42009-09-09 15:08:12 +00001963
Douglas Gregora16548e2009-08-11 05:31:07 +00001964 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001965 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001966 /// By default, performs semantic analysis to build the new expression.
1967 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001968 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001969 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001970 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001971 }
1972
Douglas Gregorad8a3362009-09-04 17:36:40 +00001973 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001974 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001975 /// By default, performs semantic analysis to build the new expression.
1976 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001977 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001978 SourceLocation OperatorLoc,
1979 bool isArrow,
1980 CXXScopeSpec &SS,
1981 TypeSourceInfo *ScopeType,
1982 SourceLocation CCLoc,
1983 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001984 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001985
Douglas Gregora16548e2009-08-11 05:31:07 +00001986 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001987 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001988 /// By default, performs semantic analysis to build the new expression.
1989 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001990 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001991 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001992 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001993 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001994 }
Mike Stump11289f42009-09-09 15:08:12 +00001995
Douglas Gregor882211c2010-04-28 22:16:22 +00001996 /// \brief Build a new builtin offsetof expression.
1997 ///
1998 /// By default, performs semantic analysis to build the new expression.
1999 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002000 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Craig Topperb5518242015-10-22 04:59:59 +00002001 TypeSourceInfo *Type,
2002 ArrayRef<Sema::OffsetOfComponent> Components,
2003 SourceLocation RParenLoc) {
Douglas Gregor882211c2010-04-28 22:16:22 +00002004 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
Craig Topperb5518242015-10-22 04:59:59 +00002005 RParenLoc);
Douglas Gregor882211c2010-04-28 22:16:22 +00002006 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002007
2008 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00002009 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00002010 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002011 /// By default, performs semantic analysis to build the new expression.
2012 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00002013 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
2014 SourceLocation OpLoc,
2015 UnaryExprOrTypeTrait ExprKind,
2016 SourceRange R) {
2017 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00002018 }
2019
Peter Collingbournee190dee2011-03-11 19:24:49 +00002020 /// \brief Build a new sizeof, alignof or vec step expression with an
2021 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00002022 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002023 /// By default, performs semantic analysis to build the new expression.
2024 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00002025 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
2026 UnaryExprOrTypeTrait ExprKind,
2027 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00002028 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00002029 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00002030 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002031 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002032
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002033 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002034 }
Mike Stump11289f42009-09-09 15:08:12 +00002035
Douglas Gregora16548e2009-08-11 05:31:07 +00002036 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00002037 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002038 /// By default, performs semantic analysis to build the new expression.
2039 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002040 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002041 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00002042 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002043 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002044 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00002045 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002046 RBracketLoc);
2047 }
2048
Alexey Bataev1a3320e2015-08-25 14:24:04 +00002049 /// \brief Build a new array section expression.
2050 ///
2051 /// By default, performs semantic analysis to build the new expression.
2052 /// Subclasses may override this routine to provide different behavior.
2053 ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc,
2054 Expr *LowerBound,
2055 SourceLocation ColonLoc, Expr *Length,
2056 SourceLocation RBracketLoc) {
2057 return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound,
2058 ColonLoc, Length, RBracketLoc);
2059 }
2060
Douglas Gregora16548e2009-08-11 05:31:07 +00002061 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00002062 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002063 /// By default, performs semantic analysis to build the new expression.
2064 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002065 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002066 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00002067 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00002068 Expr *ExecConfig = nullptr) {
2069 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002070 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00002071 }
2072
2073 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002074 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002075 /// By default, performs semantic analysis to build the new expression.
2076 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002077 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002078 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00002079 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002080 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002081 const DeclarationNameInfo &MemberNameInfo,
2082 ValueDecl *Member,
2083 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00002084 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00002085 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00002086 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
2087 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00002088 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00002089 // We have a reference to an unnamed field. This is always the
2090 // base of an anonymous struct/union member access, i.e. the
2091 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00002092 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00002093 assert(Member->getType()->isRecordType() &&
2094 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00002095
Richard Smithcab9a7d2011-10-26 19:06:56 +00002096 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002097 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00002098 QualifierLoc.getNestedNameSpecifier(),
2099 FoundDecl, Member);
2100 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002101 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002102 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00002103 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Aaron Ballmanf4cb2be2015-03-24 15:07:53 +00002104 MemberExpr *ME = new (getSema().Context)
2105 MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
2106 cast<FieldDecl>(Member)->getType(), VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002107 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00002108 }
Mike Stump11289f42009-09-09 15:08:12 +00002109
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002110 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00002111 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002112
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002113 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00002114 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00002115
John McCall16df1e52010-03-30 21:47:33 +00002116 // FIXME: this involves duplicating earlier analysis in a lot of
2117 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002118 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00002119 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00002120 R.resolveKind();
2121
John McCallb268a282010-08-23 23:25:46 +00002122 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002123 SS, TemplateKWLoc,
2124 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002125 R, ExplicitTemplateArgs,
2126 /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002127 }
Mike Stump11289f42009-09-09 15:08:12 +00002128
Douglas Gregora16548e2009-08-11 05:31:07 +00002129 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002130 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002131 /// By default, performs semantic analysis to build the new expression.
2132 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002133 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00002134 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00002135 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002136 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002137 }
2138
2139 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002140 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002141 /// By default, performs semantic analysis to build the new expression.
2142 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002143 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00002144 SourceLocation QuestionLoc,
2145 Expr *LHS,
2146 SourceLocation ColonLoc,
2147 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00002148 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
2149 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002150 }
2151
Douglas Gregora16548e2009-08-11 05:31:07 +00002152 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00002153 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002154 /// By default, performs semantic analysis to build the new expression.
2155 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002156 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00002157 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002158 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002159 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00002160 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002161 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002162 }
Mike Stump11289f42009-09-09 15:08:12 +00002163
Douglas Gregora16548e2009-08-11 05:31:07 +00002164 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00002165 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002166 /// By default, performs semantic analysis to build the new expression.
2167 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002168 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00002169 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002170 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002171 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00002172 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002173 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002174 }
Mike Stump11289f42009-09-09 15:08:12 +00002175
Douglas Gregora16548e2009-08-11 05:31:07 +00002176 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002177 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002178 /// By default, performs semantic analysis to build the new expression.
2179 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002180 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00002181 SourceLocation OpLoc,
2182 SourceLocation AccessorLoc,
2183 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00002184
John McCall10eae182009-11-30 22:42:35 +00002185 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002186 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00002187 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00002188 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002189 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002190 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002191 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002192 /* TemplateArgs */ nullptr,
2193 /*S*/ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002194 }
Mike Stump11289f42009-09-09 15:08:12 +00002195
Douglas Gregora16548e2009-08-11 05:31:07 +00002196 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00002197 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002198 /// By default, performs semantic analysis to build the new expression.
2199 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002200 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00002201 MultiExprArg Inits,
2202 SourceLocation RBraceLoc,
2203 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00002204 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002205 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00002206 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002207 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002208
Douglas Gregord3d93062009-11-09 17:16:50 +00002209 // Patch in the result type we were given, which may have been computed
2210 // when the initial InitListExpr was built.
2211 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
2212 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002213 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002214 }
Mike Stump11289f42009-09-09 15:08:12 +00002215
Douglas Gregora16548e2009-08-11 05:31:07 +00002216 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00002217 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002218 /// By default, performs semantic analysis to build the new expression.
2219 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002220 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00002221 MultiExprArg ArrayExprs,
2222 SourceLocation EqualOrColonLoc,
2223 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002224 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00002225 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00002226 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002227 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002228 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002229 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002230
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002231 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002232 }
Mike Stump11289f42009-09-09 15:08:12 +00002233
Douglas Gregora16548e2009-08-11 05:31:07 +00002234 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00002235 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002236 /// By default, builds the implicit value initialization without performing
2237 /// any semantic analysis. Subclasses may override this routine to provide
2238 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002239 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002240 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00002241 }
Mike Stump11289f42009-09-09 15:08:12 +00002242
Douglas Gregora16548e2009-08-11 05:31:07 +00002243 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00002244 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002245 /// By default, performs semantic analysis to build the new expression.
2246 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002247 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002248 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002249 SourceLocation RParenLoc) {
2250 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002251 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002252 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002253 }
2254
2255 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002256 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002257 /// By default, performs semantic analysis to build the new expression.
2258 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002259 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00002260 MultiExprArg SubExprs,
2261 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002262 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002263 }
Mike Stump11289f42009-09-09 15:08:12 +00002264
Douglas Gregora16548e2009-08-11 05:31:07 +00002265 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00002266 ///
2267 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002268 /// rather than attempting to map the label statement itself.
2269 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002270 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002271 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002272 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002273 }
Mike Stump11289f42009-09-09 15:08:12 +00002274
Douglas Gregora16548e2009-08-11 05:31:07 +00002275 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002276 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002277 /// By default, performs semantic analysis to build the new expression.
2278 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002279 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002280 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002281 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002282 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002283 }
Mike Stump11289f42009-09-09 15:08:12 +00002284
Douglas Gregora16548e2009-08-11 05:31:07 +00002285 /// \brief Build a new __builtin_choose_expr expression.
2286 ///
2287 /// By default, performs semantic analysis to build the new expression.
2288 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002289 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002290 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002291 SourceLocation RParenLoc) {
2292 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002293 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002294 RParenLoc);
2295 }
Mike Stump11289f42009-09-09 15:08:12 +00002296
Peter Collingbourne91147592011-04-15 00:35:48 +00002297 /// \brief Build a new generic selection expression.
2298 ///
2299 /// By default, performs semantic analysis to build the new expression.
2300 /// Subclasses may override this routine to provide different behavior.
2301 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2302 SourceLocation DefaultLoc,
2303 SourceLocation RParenLoc,
2304 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002305 ArrayRef<TypeSourceInfo *> Types,
2306 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002307 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002308 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002309 }
2310
Douglas Gregora16548e2009-08-11 05:31:07 +00002311 /// \brief Build a new overloaded operator call expression.
2312 ///
2313 /// By default, performs semantic analysis to build the new expression.
2314 /// The semantic analysis provides the behavior of template instantiation,
2315 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002316 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002317 /// argument-dependent lookup, etc. Subclasses may override this routine to
2318 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002319 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002320 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002321 Expr *Callee,
2322 Expr *First,
2323 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002324
2325 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002326 /// reinterpret_cast.
2327 ///
2328 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002329 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002330 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002331 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002332 Stmt::StmtClass Class,
2333 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002334 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002335 SourceLocation RAngleLoc,
2336 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002337 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002338 SourceLocation RParenLoc) {
2339 switch (Class) {
2340 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002341 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002342 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002343 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002344
2345 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002346 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002347 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002348 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002349
Douglas Gregora16548e2009-08-11 05:31:07 +00002350 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002351 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002352 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002353 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002354 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002355
Douglas Gregora16548e2009-08-11 05:31:07 +00002356 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002357 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002358 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002359 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002360
Douglas Gregora16548e2009-08-11 05:31:07 +00002361 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002362 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002363 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002364 }
Mike Stump11289f42009-09-09 15:08:12 +00002365
Douglas Gregora16548e2009-08-11 05:31:07 +00002366 /// \brief Build a new C++ static_cast expression.
2367 ///
2368 /// By default, performs semantic analysis to build the new expression.
2369 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002370 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002371 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002372 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002373 SourceLocation RAngleLoc,
2374 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002375 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002376 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002377 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002378 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002379 SourceRange(LAngleLoc, RAngleLoc),
2380 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002381 }
2382
2383 /// \brief Build a new C++ dynamic_cast expression.
2384 ///
2385 /// By default, performs semantic analysis to build the new expression.
2386 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002387 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002388 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002389 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002390 SourceLocation RAngleLoc,
2391 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002392 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002393 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002394 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002395 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002396 SourceRange(LAngleLoc, RAngleLoc),
2397 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002398 }
2399
2400 /// \brief Build a new C++ reinterpret_cast expression.
2401 ///
2402 /// By default, performs semantic analysis to build the new expression.
2403 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002404 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002405 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002406 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002407 SourceLocation RAngleLoc,
2408 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002409 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002410 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002411 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002412 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002413 SourceRange(LAngleLoc, RAngleLoc),
2414 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002415 }
2416
2417 /// \brief Build a new C++ const_cast expression.
2418 ///
2419 /// By default, performs semantic analysis to build the new expression.
2420 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002421 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002422 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002423 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002424 SourceLocation RAngleLoc,
2425 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002426 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002427 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002428 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002429 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002430 SourceRange(LAngleLoc, RAngleLoc),
2431 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002432 }
Mike Stump11289f42009-09-09 15:08:12 +00002433
Douglas Gregora16548e2009-08-11 05:31:07 +00002434 /// \brief Build a new C++ functional-style cast expression.
2435 ///
2436 /// By default, performs semantic analysis to build the new expression.
2437 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002438 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2439 SourceLocation LParenLoc,
2440 Expr *Sub,
2441 SourceLocation RParenLoc) {
2442 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002443 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002444 RParenLoc);
2445 }
Mike Stump11289f42009-09-09 15:08:12 +00002446
Douglas Gregora16548e2009-08-11 05:31:07 +00002447 /// \brief Build a new C++ typeid(type) expression.
2448 ///
2449 /// By default, performs semantic analysis to build the new expression.
2450 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002451 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002452 SourceLocation TypeidLoc,
2453 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002454 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002455 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002456 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002457 }
Mike Stump11289f42009-09-09 15:08:12 +00002458
Francois Pichet9f4f2072010-09-08 12:20:18 +00002459
Douglas Gregora16548e2009-08-11 05:31:07 +00002460 /// \brief Build a new C++ typeid(expr) expression.
2461 ///
2462 /// By default, performs semantic analysis to build the new expression.
2463 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002464 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002465 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002466 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002467 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002468 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002469 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002470 }
2471
Francois Pichet9f4f2072010-09-08 12:20:18 +00002472 /// \brief Build a new C++ __uuidof(type) expression.
2473 ///
2474 /// By default, performs semantic analysis to build the new expression.
2475 /// Subclasses may override this routine to provide different behavior.
2476 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2477 SourceLocation TypeidLoc,
2478 TypeSourceInfo *Operand,
2479 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002480 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002481 RParenLoc);
2482 }
2483
2484 /// \brief Build a new C++ __uuidof(expr) expression.
2485 ///
2486 /// By default, performs semantic analysis to build the new expression.
2487 /// Subclasses may override this routine to provide different behavior.
2488 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2489 SourceLocation TypeidLoc,
2490 Expr *Operand,
2491 SourceLocation RParenLoc) {
2492 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2493 RParenLoc);
2494 }
2495
Douglas Gregora16548e2009-08-11 05:31:07 +00002496 /// \brief Build a new C++ "this" expression.
2497 ///
2498 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002499 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002500 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002501 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002502 QualType ThisType,
2503 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002504 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002505 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002506 }
2507
2508 /// \brief Build a new C++ throw expression.
2509 ///
2510 /// By default, performs semantic analysis to build the new expression.
2511 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002512 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2513 bool IsThrownVariableInScope) {
2514 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002515 }
2516
2517 /// \brief Build a new C++ default-argument expression.
2518 ///
2519 /// By default, builds a new default-argument expression, which does not
2520 /// require any semantic analysis. Subclasses may override this routine to
2521 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002522 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002523 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002524 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002525 }
2526
Richard Smith852c9db2013-04-20 22:23:05 +00002527 /// \brief Build a new C++11 default-initialization expression.
2528 ///
2529 /// By default, builds a new default field initialization expression, which
2530 /// does not require any semantic analysis. Subclasses may override this
2531 /// routine to provide different behavior.
2532 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2533 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002534 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002535 }
2536
Douglas Gregora16548e2009-08-11 05:31:07 +00002537 /// \brief Build a new C++ zero-initialization expression.
2538 ///
2539 /// By default, performs semantic analysis to build the new expression.
2540 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002541 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2542 SourceLocation LParenLoc,
2543 SourceLocation RParenLoc) {
2544 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002545 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002546 }
Mike Stump11289f42009-09-09 15:08:12 +00002547
Douglas Gregora16548e2009-08-11 05:31:07 +00002548 /// \brief Build a new C++ "new" expression.
2549 ///
2550 /// By default, performs semantic analysis to build the new expression.
2551 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002552 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002553 bool UseGlobal,
2554 SourceLocation PlacementLParen,
2555 MultiExprArg PlacementArgs,
2556 SourceLocation PlacementRParen,
2557 SourceRange TypeIdParens,
2558 QualType AllocatedType,
2559 TypeSourceInfo *AllocatedTypeInfo,
2560 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002561 SourceRange DirectInitRange,
2562 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002563 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002564 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002565 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002566 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002567 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002568 AllocatedType,
2569 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002570 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002571 DirectInitRange,
2572 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002573 }
Mike Stump11289f42009-09-09 15:08:12 +00002574
Douglas Gregora16548e2009-08-11 05:31:07 +00002575 /// \brief Build a new C++ "delete" expression.
2576 ///
2577 /// By default, performs semantic analysis to build the new expression.
2578 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002579 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002580 bool IsGlobalDelete,
2581 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002582 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002583 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002584 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002585 }
Mike Stump11289f42009-09-09 15:08:12 +00002586
Douglas Gregor29c42f22012-02-24 07:38:34 +00002587 /// \brief Build a new type trait expression.
2588 ///
2589 /// By default, performs semantic analysis to build the new expression.
2590 /// Subclasses may override this routine to provide different behavior.
2591 ExprResult RebuildTypeTrait(TypeTrait Trait,
2592 SourceLocation StartLoc,
2593 ArrayRef<TypeSourceInfo *> Args,
2594 SourceLocation RParenLoc) {
2595 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2596 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002597
John Wiegley6242b6a2011-04-28 00:16:57 +00002598 /// \brief Build a new array type trait expression.
2599 ///
2600 /// By default, performs semantic analysis to build the new expression.
2601 /// Subclasses may override this routine to provide different behavior.
2602 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2603 SourceLocation StartLoc,
2604 TypeSourceInfo *TSInfo,
2605 Expr *DimExpr,
2606 SourceLocation RParenLoc) {
2607 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2608 }
2609
John Wiegleyf9f65842011-04-25 06:54:41 +00002610 /// \brief Build a new expression trait expression.
2611 ///
2612 /// By default, performs semantic analysis to build the new expression.
2613 /// Subclasses may override this routine to provide different behavior.
2614 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2615 SourceLocation StartLoc,
2616 Expr *Queried,
2617 SourceLocation RParenLoc) {
2618 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2619 }
2620
Mike Stump11289f42009-09-09 15:08:12 +00002621 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002622 /// expression.
2623 ///
2624 /// By default, performs semantic analysis to build the new expression.
2625 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002626 ExprResult RebuildDependentScopeDeclRefExpr(
2627 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002628 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002629 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002630 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002631 bool IsAddressOfOperand,
2632 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002633 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002634 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002635
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002636 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002637 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2638 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002639
Reid Kleckner32506ed2014-06-12 23:03:48 +00002640 return getSema().BuildQualifiedDeclarationNameExpr(
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002641 SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002642 }
2643
2644 /// \brief Build a new template-id expression.
2645 ///
2646 /// By default, performs semantic analysis to build the new expression.
2647 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002648 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002649 SourceLocation TemplateKWLoc,
2650 LookupResult &R,
2651 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002652 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002653 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2654 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002655 }
2656
2657 /// \brief Build a new object-construction expression.
2658 ///
2659 /// By default, performs semantic analysis to build the new expression.
2660 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002661 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002662 SourceLocation Loc,
2663 CXXConstructorDecl *Constructor,
2664 bool IsElidable,
2665 MultiExprArg Args,
2666 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002667 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002668 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002669 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002670 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002671 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002672 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002673 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002674 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002675 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002676
Richard Smithc83bf822016-06-10 00:58:19 +00002677 return getSema().BuildCXXConstructExpr(Loc, T, Constructor,
Richard Smithc2bebe92016-05-11 20:37:46 +00002678 IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002679 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002680 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002681 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002682 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002683 RequiresZeroInit, ConstructKind,
2684 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002685 }
2686
2687 /// \brief Build a new object-construction expression.
2688 ///
2689 /// By default, performs semantic analysis to build the new expression.
2690 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002691 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2692 SourceLocation LParenLoc,
2693 MultiExprArg Args,
2694 SourceLocation RParenLoc) {
2695 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002696 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002697 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002698 RParenLoc);
2699 }
2700
2701 /// \brief Build a new object-construction expression.
2702 ///
2703 /// By default, performs semantic analysis to build the new expression.
2704 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002705 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2706 SourceLocation LParenLoc,
2707 MultiExprArg Args,
2708 SourceLocation RParenLoc) {
2709 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002710 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002711 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002712 RParenLoc);
2713 }
Mike Stump11289f42009-09-09 15:08:12 +00002714
Douglas Gregora16548e2009-08-11 05:31:07 +00002715 /// \brief Build a new member reference expression.
2716 ///
2717 /// By default, performs semantic analysis to build the new expression.
2718 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002719 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002720 QualType BaseType,
2721 bool IsArrow,
2722 SourceLocation OperatorLoc,
2723 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002724 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002725 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002726 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002727 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002728 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002729 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002730
John McCallb268a282010-08-23 23:25:46 +00002731 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002732 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002733 SS, TemplateKWLoc,
2734 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002735 MemberNameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002736 TemplateArgs, /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002737 }
2738
John McCall10eae182009-11-30 22:42:35 +00002739 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002740 ///
2741 /// By default, performs semantic analysis to build the new expression.
2742 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002743 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2744 SourceLocation OperatorLoc,
2745 bool IsArrow,
2746 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002747 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002748 NamedDecl *FirstQualifierInScope,
2749 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002750 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002751 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002752 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002753
John McCallb268a282010-08-23 23:25:46 +00002754 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002755 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002756 SS, TemplateKWLoc,
2757 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002758 R, TemplateArgs, /*S*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00002759 }
Mike Stump11289f42009-09-09 15:08:12 +00002760
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002761 /// \brief Build a new noexcept expression.
2762 ///
2763 /// By default, performs semantic analysis to build the new expression.
2764 /// Subclasses may override this routine to provide different behavior.
2765 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2766 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2767 }
2768
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002769 /// \brief Build a new expression to compute the length of a parameter pack.
Richard Smithd784e682015-09-23 21:41:42 +00002770 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc,
2771 NamedDecl *Pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00002772 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002773 SourceLocation RParenLoc,
Richard Smithd784e682015-09-23 21:41:42 +00002774 Optional<unsigned> Length,
2775 ArrayRef<TemplateArgument> PartialArgs) {
2776 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
2777 RParenLoc, Length, PartialArgs);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002778 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002779
Patrick Beard0caa3942012-04-19 00:25:12 +00002780 /// \brief Build a new Objective-C boxed expression.
2781 ///
2782 /// By default, performs semantic analysis to build the new expression.
2783 /// Subclasses may override this routine to provide different behavior.
2784 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2785 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2786 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002787
Ted Kremeneke65b0862012-03-06 20:05:56 +00002788 /// \brief Build a new Objective-C array literal.
2789 ///
2790 /// By default, performs semantic analysis to build the new expression.
2791 /// Subclasses may override this routine to provide different behavior.
2792 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2793 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002794 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002795 MultiExprArg(Elements, NumElements));
2796 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002797
2798 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002799 Expr *Base, Expr *Key,
2800 ObjCMethodDecl *getterMethod,
2801 ObjCMethodDecl *setterMethod) {
2802 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2803 getterMethod, setterMethod);
2804 }
2805
2806 /// \brief Build a new Objective-C dictionary literal.
2807 ///
2808 /// By default, performs semantic analysis to build the new expression.
2809 /// Subclasses may override this routine to provide different behavior.
2810 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
Craig Topperd4336e02015-12-24 23:58:15 +00002811 MutableArrayRef<ObjCDictionaryElement> Elements) {
2812 return getSema().BuildObjCDictionaryLiteral(Range, Elements);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002813 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002814
James Dennett2a4d13c2012-06-15 07:13:21 +00002815 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002816 ///
2817 /// By default, performs semantic analysis to build the new expression.
2818 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002819 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002820 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002821 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002822 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002823 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002824
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002825 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002826 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002827 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002828 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002829 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002830 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002831 MultiExprArg Args,
2832 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002833 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2834 ReceiverTypeInfo->getType(),
2835 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002836 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002837 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002838 }
2839
2840 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002841 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002842 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002843 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002844 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002845 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002846 MultiExprArg Args,
2847 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002848 return SemaRef.BuildInstanceMessage(Receiver,
2849 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002850 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002851 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002852 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002853 }
2854
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002855 /// \brief Build a new Objective-C instance/class message to 'super'.
2856 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
2857 Selector Sel,
2858 ArrayRef<SourceLocation> SelectorLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002859 QualType SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002860 ObjCMethodDecl *Method,
2861 SourceLocation LBracLoc,
2862 MultiExprArg Args,
2863 SourceLocation RBracLoc) {
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002864 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002865 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002866 SuperLoc,
2867 Sel, Method, LBracLoc, SelectorLocs,
2868 RBracLoc, Args)
2869 : SemaRef.BuildClassMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002870 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002871 SuperLoc,
2872 Sel, Method, LBracLoc, SelectorLocs,
2873 RBracLoc, Args);
2874
2875
2876 }
2877
Douglas Gregord51d90d2010-04-26 20:11:03 +00002878 /// \brief Build a new Objective-C ivar reference expression.
2879 ///
2880 /// By default, performs semantic analysis to build the new expression.
2881 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002882 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002883 SourceLocation IvarLoc,
2884 bool IsArrow, bool IsFreeIvar) {
2885 // FIXME: We lose track of the IsFreeIvar bit.
2886 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002887 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2888 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002889 /*FIXME:*/IvarLoc, IsArrow,
2890 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002891 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002892 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002893 /*TemplateArgs=*/nullptr,
2894 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002895 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002896
2897 /// \brief Build a new Objective-C property reference expression.
2898 ///
2899 /// By default, performs semantic analysis to build the new expression.
2900 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002901 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002902 ObjCPropertyDecl *Property,
2903 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002904 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002905 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2906 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2907 /*FIXME:*/PropertyLoc,
2908 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002909 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002910 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002911 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002912 /*TemplateArgs=*/nullptr,
2913 /*S=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002914 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002915
John McCallb7bd14f2010-12-02 01:19:52 +00002916 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002917 ///
2918 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002919 /// Subclasses may override this routine to provide different behavior.
2920 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2921 ObjCMethodDecl *Getter,
2922 ObjCMethodDecl *Setter,
2923 SourceLocation PropertyLoc) {
2924 // Since these expressions can only be value-dependent, we do not
2925 // need to perform semantic analysis again.
2926 return Owned(
2927 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2928 VK_LValue, OK_ObjCProperty,
2929 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002930 }
2931
Douglas Gregord51d90d2010-04-26 20:11:03 +00002932 /// \brief Build a new Objective-C "isa" expression.
2933 ///
2934 /// By default, performs semantic analysis to build the new expression.
2935 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002936 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00002937 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00002938 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002939 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2940 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002941 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002942 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002943 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002944 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002945 /*TemplateArgs=*/nullptr,
2946 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002947 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002948
Douglas Gregora16548e2009-08-11 05:31:07 +00002949 /// \brief Build a new shuffle vector expression.
2950 ///
2951 /// By default, performs semantic analysis to build the new expression.
2952 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002953 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002954 MultiExprArg SubExprs,
2955 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002956 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002957 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002958 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2959 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2960 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002961 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002962
Douglas Gregora16548e2009-08-11 05:31:07 +00002963 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002964 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002965 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2966 SemaRef.Context.BuiltinFnTy,
2967 VK_RValue, BuiltinLoc);
2968 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2969 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002970 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00002971
2972 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002973 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00002974 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002975 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002976
Douglas Gregora16548e2009-08-11 05:31:07 +00002977 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002978 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002979 }
John McCall31f82722010-11-12 08:19:04 +00002980
Hal Finkelc4d7c822013-09-18 03:29:45 +00002981 /// \brief Build a new convert vector expression.
2982 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2983 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2984 SourceLocation RParenLoc) {
2985 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2986 BuiltinLoc, RParenLoc);
2987 }
2988
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002989 /// \brief Build a new template argument pack expansion.
2990 ///
2991 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002992 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002993 /// different behavior.
2994 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002995 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002996 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002997 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002998 case TemplateArgument::Expression: {
2999 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00003000 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
3001 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00003002 if (Result.isInvalid())
3003 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003004
Douglas Gregor98318c22011-01-03 21:37:45 +00003005 return TemplateArgumentLoc(Result.get(), Result.get());
3006 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003007
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003008 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003009 return TemplateArgumentLoc(TemplateArgument(
3010 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00003011 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00003012 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003013 Pattern.getTemplateNameLoc(),
3014 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003015
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003016 case TemplateArgument::Null:
3017 case TemplateArgument::Integral:
3018 case TemplateArgument::Declaration:
3019 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003020 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00003021 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003022 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00003023
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003024 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00003025 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003026 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003027 EllipsisLoc,
3028 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003029 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
3030 Expansion);
3031 break;
3032 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003033
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003034 return TemplateArgumentLoc();
3035 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003036
Douglas Gregor968f23a2011-01-03 19:31:53 +00003037 /// \brief Build a new expression pack expansion.
3038 ///
3039 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00003040 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00003041 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00003042 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00003043 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00003044 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003045 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003046
Richard Smith0f0af192014-11-08 05:07:16 +00003047 /// \brief Build a new C++1z fold-expression.
3048 ///
3049 /// By default, performs semantic analysis in order to build a new fold
3050 /// expression.
3051 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
3052 BinaryOperatorKind Operator,
3053 SourceLocation EllipsisLoc, Expr *RHS,
3054 SourceLocation RParenLoc) {
3055 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
3056 RHS, RParenLoc);
3057 }
3058
3059 /// \brief Build an empty C++1z fold-expression with the given operator.
3060 ///
3061 /// By default, produces the fallback value for the fold-expression, or
3062 /// produce an error if there is no fallback value.
3063 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
3064 BinaryOperatorKind Operator) {
3065 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
3066 }
3067
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003068 /// \brief Build a new atomic operation expression.
3069 ///
3070 /// By default, performs semantic analysis to build the new expression.
3071 /// Subclasses may override this routine to provide different behavior.
3072 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
3073 MultiExprArg SubExprs,
3074 QualType RetTy,
3075 AtomicExpr::AtomicOp Op,
3076 SourceLocation RParenLoc) {
3077 // Just create the expression; there is not any interesting semantic
3078 // analysis here because we can't actually build an AtomicExpr until
3079 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00003080 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003081 RParenLoc);
3082 }
3083
John McCall31f82722010-11-12 08:19:04 +00003084private:
Douglas Gregor14454802011-02-25 02:25:35 +00003085 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
3086 QualType ObjectType,
3087 NamedDecl *FirstQualifierInScope,
3088 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003089
3090 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3091 QualType ObjectType,
3092 NamedDecl *FirstQualifierInScope,
3093 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003094
3095 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
3096 NamedDecl *FirstQualifierInScope,
3097 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003098};
Douglas Gregora16548e2009-08-11 05:31:07 +00003099
Douglas Gregorebe10102009-08-20 07:17:43 +00003100template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003101StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003102 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003103 return S;
Mike Stump11289f42009-09-09 15:08:12 +00003104
Douglas Gregorebe10102009-08-20 07:17:43 +00003105 switch (S->getStmtClass()) {
3106 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00003107
Douglas Gregorebe10102009-08-20 07:17:43 +00003108 // Transform individual statement nodes
3109#define STMT(Node, Parent) \
3110 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00003111#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00003112#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00003113#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003114
Douglas Gregorebe10102009-08-20 07:17:43 +00003115 // Transform expressions by calling TransformExpr.
3116#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00003117#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00003118#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00003119#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00003120 {
John McCalldadc5752010-08-24 06:29:42 +00003121 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00003122 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003123 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003124
Richard Smith945f8d32013-01-14 22:39:08 +00003125 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00003126 }
Mike Stump11289f42009-09-09 15:08:12 +00003127 }
3128
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003129 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00003130}
Mike Stump11289f42009-09-09 15:08:12 +00003131
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00003132template<typename Derived>
3133OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
3134 if (!S)
3135 return S;
3136
3137 switch (S->getClauseKind()) {
3138 default: break;
3139 // Transform individual clause nodes
3140#define OPENMP_CLAUSE(Name, Class) \
3141 case OMPC_ ## Name : \
3142 return getDerived().Transform ## Class(cast<Class>(S));
3143#include "clang/Basic/OpenMPKinds.def"
3144 }
3145
3146 return S;
3147}
3148
Mike Stump11289f42009-09-09 15:08:12 +00003149
Douglas Gregore922c772009-08-04 22:27:00 +00003150template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003151ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003152 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003153 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00003154
3155 switch (E->getStmtClass()) {
3156 case Stmt::NoStmtClass: break;
3157#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00003158#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00003159#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00003160 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00003161#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003162 }
3163
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003164 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00003165}
3166
3167template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00003168ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00003169 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00003170 // Initializers are instantiated like expressions, except that various outer
3171 // layers are stripped.
3172 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003173 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00003174
3175 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
3176 Init = ExprTemp->getSubExpr();
3177
Richard Smithe6ca4752013-05-30 22:40:16 +00003178 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
3179 Init = MTE->GetTemporaryExpr();
3180
Richard Smithd59b8322012-12-19 01:39:02 +00003181 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
3182 Init = Binder->getSubExpr();
3183
3184 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
3185 Init = ICE->getSubExprAsWritten();
3186
Richard Smithcc1b96d2013-06-12 22:31:48 +00003187 if (CXXStdInitializerListExpr *ILE =
3188 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00003189 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00003190
Richard Smithc6abd962014-07-25 01:12:44 +00003191 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00003192 // InitListExprs. Other forms of copy-initialization will be a no-op if
3193 // the initializer is already the right type.
3194 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00003195 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00003196 return getDerived().TransformExpr(Init);
3197
3198 // Revert value-initialization back to empty parens.
3199 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
3200 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003201 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003202 Parens.getEnd());
3203 }
3204
3205 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3206 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003207 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003208 SourceLocation());
3209
3210 // Revert initialization by constructor back to a parenthesized or braced list
3211 // of expressions. Any other form of initializer can just be reused directly.
3212 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00003213 return getDerived().TransformExpr(Init);
3214
Richard Smithf8adcdc2014-07-17 05:12:35 +00003215 // If the initialization implicitly converted an initializer list to a
3216 // std::initializer_list object, unwrap the std::initializer_list too.
3217 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00003218 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00003219
Richard Smithd59b8322012-12-19 01:39:02 +00003220 SmallVector<Expr*, 8> NewArgs;
3221 bool ArgChanged = false;
3222 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00003223 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00003224 return ExprError();
3225
3226 // If this was list initialization, revert to list form.
3227 if (Construct->isListInitialization())
3228 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
3229 Construct->getLocEnd(),
3230 Construct->getType());
3231
Richard Smithd59b8322012-12-19 01:39:02 +00003232 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00003233 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00003234 if (Parens.isInvalid()) {
3235 // This was a variable declaration's initialization for which no initializer
3236 // was specified.
3237 assert(NewArgs.empty() &&
3238 "no parens or braces but have direct init with arguments?");
3239 return ExprEmpty();
3240 }
Richard Smithd59b8322012-12-19 01:39:02 +00003241 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3242 Parens.getEnd());
3243}
3244
3245template<typename Derived>
Craig Topper99d23532015-12-24 23:58:29 +00003246bool TreeTransform<Derived>::TransformExprs(Expr *const *Inputs,
Chad Rosier1dcde962012-08-08 18:46:20 +00003247 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003248 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003249 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003250 bool *ArgChanged) {
3251 for (unsigned I = 0; I != NumInputs; ++I) {
3252 // If requested, drop call arguments that need to be dropped.
3253 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3254 if (ArgChanged)
3255 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003256
Douglas Gregora3efea12011-01-03 19:04:46 +00003257 break;
3258 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003259
Douglas Gregor968f23a2011-01-03 19:31:53 +00003260 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3261 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00003262
Chris Lattner01cf8db2011-07-20 06:58:45 +00003263 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003264 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3265 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003266
Douglas Gregor968f23a2011-01-03 19:31:53 +00003267 // Determine whether the set of unexpanded parameter packs can and should
3268 // be expanded.
3269 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003270 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003271 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3272 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003273 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3274 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003275 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003276 Expand, RetainExpansion,
3277 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00003278 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003279
Douglas Gregor968f23a2011-01-03 19:31:53 +00003280 if (!Expand) {
3281 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003282 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00003283 // expansion.
3284 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3285 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3286 if (OutPattern.isInvalid())
3287 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003288
3289 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00003290 Expansion->getEllipsisLoc(),
3291 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003292 if (Out.isInvalid())
3293 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003294
Douglas Gregor968f23a2011-01-03 19:31:53 +00003295 if (ArgChanged)
3296 *ArgChanged = true;
3297 Outputs.push_back(Out.get());
3298 continue;
3299 }
John McCall542e7c62011-07-06 07:30:07 +00003300
3301 // Record right away that the argument was changed. This needs
3302 // to happen even if the array expands to nothing.
3303 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003304
Douglas Gregor968f23a2011-01-03 19:31:53 +00003305 // The transform has determined that we should perform an elementwise
3306 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003307 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00003308 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3309 ExprResult Out = getDerived().TransformExpr(Pattern);
3310 if (Out.isInvalid())
3311 return true;
3312
Richard Smith9467be42014-06-06 17:33:35 +00003313 // FIXME: Can this happen? We should not try to expand the pack
3314 // in this case.
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003315 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003316 Out = getDerived().RebuildPackExpansion(
3317 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003318 if (Out.isInvalid())
3319 return true;
3320 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003321
Douglas Gregor968f23a2011-01-03 19:31:53 +00003322 Outputs.push_back(Out.get());
3323 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003324
Richard Smith9467be42014-06-06 17:33:35 +00003325 // If we're supposed to retain a pack expansion, do so by temporarily
3326 // forgetting the partially-substituted parameter pack.
3327 if (RetainExpansion) {
3328 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3329
3330 ExprResult Out = getDerived().TransformExpr(Pattern);
3331 if (Out.isInvalid())
3332 return true;
3333
3334 Out = getDerived().RebuildPackExpansion(
3335 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3336 if (Out.isInvalid())
3337 return true;
3338
3339 Outputs.push_back(Out.get());
3340 }
3341
Douglas Gregor968f23a2011-01-03 19:31:53 +00003342 continue;
3343 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003344
Richard Smithd59b8322012-12-19 01:39:02 +00003345 ExprResult Result =
3346 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3347 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003348 if (Result.isInvalid())
3349 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003350
Douglas Gregora3efea12011-01-03 19:04:46 +00003351 if (Result.get() != Inputs[I] && ArgChanged)
3352 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003353
3354 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003355 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003356
Douglas Gregora3efea12011-01-03 19:04:46 +00003357 return false;
3358}
3359
3360template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003361NestedNameSpecifierLoc
3362TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3363 NestedNameSpecifierLoc NNS,
3364 QualType ObjectType,
3365 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003366 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003367 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003368 Qualifier = Qualifier.getPrefix())
3369 Qualifiers.push_back(Qualifier);
3370
3371 CXXScopeSpec SS;
3372 while (!Qualifiers.empty()) {
3373 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3374 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003375
Douglas Gregor14454802011-02-25 02:25:35 +00003376 switch (QNNS->getKind()) {
3377 case NestedNameSpecifier::Identifier:
Craig Topperc3ec1492014-05-26 06:22:03 +00003378 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
Douglas Gregor14454802011-02-25 02:25:35 +00003379 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003380 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003381 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003382 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00003383 FirstQualifierInScope, false))
3384 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003385
Douglas Gregor14454802011-02-25 02:25:35 +00003386 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003387
Douglas Gregor14454802011-02-25 02:25:35 +00003388 case NestedNameSpecifier::Namespace: {
3389 NamespaceDecl *NS
3390 = cast_or_null<NamespaceDecl>(
3391 getDerived().TransformDecl(
3392 Q.getLocalBeginLoc(),
3393 QNNS->getAsNamespace()));
3394 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3395 break;
3396 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003397
Douglas Gregor14454802011-02-25 02:25:35 +00003398 case NestedNameSpecifier::NamespaceAlias: {
3399 NamespaceAliasDecl *Alias
3400 = cast_or_null<NamespaceAliasDecl>(
3401 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3402 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003403 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003404 Q.getLocalEndLoc());
3405 break;
3406 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003407
Douglas Gregor14454802011-02-25 02:25:35 +00003408 case NestedNameSpecifier::Global:
3409 // There is no meaningful transformation that one could perform on the
3410 // global scope.
3411 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3412 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003413
Nikola Smiljanic67860242014-09-26 00:28:20 +00003414 case NestedNameSpecifier::Super: {
3415 CXXRecordDecl *RD =
3416 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3417 SourceLocation(), QNNS->getAsRecordDecl()));
3418 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3419 break;
3420 }
3421
Douglas Gregor14454802011-02-25 02:25:35 +00003422 case NestedNameSpecifier::TypeSpecWithTemplate:
3423 case NestedNameSpecifier::TypeSpec: {
3424 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3425 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003426
Douglas Gregor14454802011-02-25 02:25:35 +00003427 if (!TL)
3428 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003429
Douglas Gregor14454802011-02-25 02:25:35 +00003430 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003431 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003432 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003433 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003434 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003435 if (TL.getType()->isEnumeralType())
3436 SemaRef.Diag(TL.getBeginLoc(),
3437 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003438 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3439 Q.getLocalEndLoc());
3440 break;
3441 }
Richard Trieude756fb2011-05-07 01:36:37 +00003442 // If the nested-name-specifier is an invalid type def, don't emit an
3443 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003444 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3445 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003446 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003447 << TL.getType() << SS.getRange();
3448 }
Douglas Gregor14454802011-02-25 02:25:35 +00003449 return NestedNameSpecifierLoc();
3450 }
Douglas Gregore16af532011-02-28 18:50:33 +00003451 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003452
Douglas Gregore16af532011-02-28 18:50:33 +00003453 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003454 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003455 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003456 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003457
Douglas Gregor14454802011-02-25 02:25:35 +00003458 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003459 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003460 !getDerived().AlwaysRebuild())
3461 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003462
3463 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003464 // nested-name-specifier, do so.
3465 if (SS.location_size() == NNS.getDataLength() &&
3466 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3467 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3468
3469 // Allocate new nested-name-specifier location information.
3470 return SS.getWithLocInContext(SemaRef.Context);
3471}
3472
3473template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003474DeclarationNameInfo
3475TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003476::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003477 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003478 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003479 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003480
3481 switch (Name.getNameKind()) {
3482 case DeclarationName::Identifier:
3483 case DeclarationName::ObjCZeroArgSelector:
3484 case DeclarationName::ObjCOneArgSelector:
3485 case DeclarationName::ObjCMultiArgSelector:
3486 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003487 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003488 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003489 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003490
Douglas Gregorf816bd72009-09-03 22:13:48 +00003491 case DeclarationName::CXXConstructorName:
3492 case DeclarationName::CXXDestructorName:
3493 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003494 TypeSourceInfo *NewTInfo;
3495 CanQualType NewCanTy;
3496 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003497 NewTInfo = getDerived().TransformType(OldTInfo);
3498 if (!NewTInfo)
3499 return DeclarationNameInfo();
3500 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003501 }
3502 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003503 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003504 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003505 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003506 if (NewT.isNull())
3507 return DeclarationNameInfo();
3508 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3509 }
Mike Stump11289f42009-09-09 15:08:12 +00003510
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003511 DeclarationName NewName
3512 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3513 NewCanTy);
3514 DeclarationNameInfo NewNameInfo(NameInfo);
3515 NewNameInfo.setName(NewName);
3516 NewNameInfo.setNamedTypeInfo(NewTInfo);
3517 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003518 }
Mike Stump11289f42009-09-09 15:08:12 +00003519 }
3520
David Blaikie83d382b2011-09-23 05:06:16 +00003521 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003522}
3523
3524template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003525TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003526TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3527 TemplateName Name,
3528 SourceLocation NameLoc,
3529 QualType ObjectType,
3530 NamedDecl *FirstQualifierInScope) {
3531 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3532 TemplateDecl *Template = QTN->getTemplateDecl();
3533 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003534
Douglas Gregor9db53502011-03-02 18:07:45 +00003535 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003536 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003537 Template));
3538 if (!TransTemplate)
3539 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003540
Douglas Gregor9db53502011-03-02 18:07:45 +00003541 if (!getDerived().AlwaysRebuild() &&
3542 SS.getScopeRep() == QTN->getQualifier() &&
3543 TransTemplate == Template)
3544 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003545
Douglas Gregor9db53502011-03-02 18:07:45 +00003546 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3547 TransTemplate);
3548 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003549
Douglas Gregor9db53502011-03-02 18:07:45 +00003550 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3551 if (SS.getScopeRep()) {
3552 // These apply to the scope specifier, not the template.
3553 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003554 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003555 }
3556
Douglas Gregor9db53502011-03-02 18:07:45 +00003557 if (!getDerived().AlwaysRebuild() &&
3558 SS.getScopeRep() == DTN->getQualifier() &&
3559 ObjectType.isNull())
3560 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003561
Douglas Gregor9db53502011-03-02 18:07:45 +00003562 if (DTN->isIdentifier()) {
3563 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003564 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003565 NameLoc,
3566 ObjectType,
3567 FirstQualifierInScope);
3568 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003569
Douglas Gregor9db53502011-03-02 18:07:45 +00003570 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3571 ObjectType);
3572 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003573
Douglas Gregor9db53502011-03-02 18:07:45 +00003574 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3575 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003576 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003577 Template));
3578 if (!TransTemplate)
3579 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003580
Douglas Gregor9db53502011-03-02 18:07:45 +00003581 if (!getDerived().AlwaysRebuild() &&
3582 TransTemplate == Template)
3583 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003584
Douglas Gregor9db53502011-03-02 18:07:45 +00003585 return TemplateName(TransTemplate);
3586 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003587
Douglas Gregor9db53502011-03-02 18:07:45 +00003588 if (SubstTemplateTemplateParmPackStorage *SubstPack
3589 = Name.getAsSubstTemplateTemplateParmPack()) {
3590 TemplateTemplateParmDecl *TransParam
3591 = cast_or_null<TemplateTemplateParmDecl>(
3592 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3593 if (!TransParam)
3594 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003595
Douglas Gregor9db53502011-03-02 18:07:45 +00003596 if (!getDerived().AlwaysRebuild() &&
3597 TransParam == SubstPack->getParameterPack())
3598 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003599
3600 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003601 SubstPack->getArgumentPack());
3602 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003603
Douglas Gregor9db53502011-03-02 18:07:45 +00003604 // These should be getting filtered out before they reach the AST.
3605 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003606}
3607
3608template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003609void TreeTransform<Derived>::InventTemplateArgumentLoc(
3610 const TemplateArgument &Arg,
3611 TemplateArgumentLoc &Output) {
3612 SourceLocation Loc = getDerived().getBaseLocation();
3613 switch (Arg.getKind()) {
3614 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003615 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003616 break;
3617
3618 case TemplateArgument::Type:
3619 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003620 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003621
John McCall0ad16662009-10-29 08:12:44 +00003622 break;
3623
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003624 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003625 case TemplateArgument::TemplateExpansion: {
3626 NestedNameSpecifierLocBuilder Builder;
Manuel Klimek4c67fa72016-01-11 11:39:00 +00003627 TemplateName Template = Arg.getAsTemplateOrTemplatePattern();
Douglas Gregor9d802122011-03-02 17:09:35 +00003628 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3629 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3630 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3631 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003632
Douglas Gregor9d802122011-03-02 17:09:35 +00003633 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003634 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003635 Builder.getWithLocInContext(SemaRef.Context),
3636 Loc);
3637 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003638 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003639 Builder.getWithLocInContext(SemaRef.Context),
3640 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003641
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003642 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003643 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003644
John McCall0ad16662009-10-29 08:12:44 +00003645 case TemplateArgument::Expression:
3646 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3647 break;
3648
3649 case TemplateArgument::Declaration:
3650 case TemplateArgument::Integral:
3651 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003652 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003653 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003654 break;
3655 }
3656}
3657
3658template<typename Derived>
3659bool TreeTransform<Derived>::TransformTemplateArgument(
3660 const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +00003661 TemplateArgumentLoc &Output, bool Uneval) {
John McCall0ad16662009-10-29 08:12:44 +00003662 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003663 switch (Arg.getKind()) {
3664 case TemplateArgument::Null:
3665 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003666 case TemplateArgument::Pack:
3667 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003668 case TemplateArgument::NullPtr:
3669 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003670
Douglas Gregore922c772009-08-04 22:27:00 +00003671 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003672 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003673 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003674 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003675
3676 DI = getDerived().TransformType(DI);
3677 if (!DI) return true;
3678
3679 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3680 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003681 }
Mike Stump11289f42009-09-09 15:08:12 +00003682
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003683 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003684 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3685 if (QualifierLoc) {
3686 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3687 if (!QualifierLoc)
3688 return true;
3689 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003690
Douglas Gregordf846d12011-03-02 18:46:51 +00003691 CXXScopeSpec SS;
3692 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003693 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003694 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3695 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003696 if (Template.isNull())
3697 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003698
Douglas Gregor9d802122011-03-02 17:09:35 +00003699 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003700 Input.getTemplateNameLoc());
3701 return false;
3702 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003703
3704 case TemplateArgument::TemplateExpansion:
3705 llvm_unreachable("Caller should expand pack expansions");
3706
Douglas Gregore922c772009-08-04 22:27:00 +00003707 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003708 // Template argument expressions are constant expressions.
Richard Smithd784e682015-09-23 21:41:42 +00003709 EnterExpressionEvaluationContext Unevaluated(
3710 getSema(), Uneval ? Sema::Unevaluated : Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003711
John McCall0ad16662009-10-29 08:12:44 +00003712 Expr *InputExpr = Input.getSourceExpression();
3713 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3714
Chris Lattnercdb591a2011-04-25 20:37:58 +00003715 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003716 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003717 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003718 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003719 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003720 }
Douglas Gregore922c772009-08-04 22:27:00 +00003721 }
Mike Stump11289f42009-09-09 15:08:12 +00003722
Douglas Gregore922c772009-08-04 22:27:00 +00003723 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003724 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003725}
3726
Douglas Gregorfe921a72010-12-20 23:36:19 +00003727/// \brief Iterator adaptor that invents template argument location information
3728/// for each of the template arguments in its underlying iterator.
3729template<typename Derived, typename InputIterator>
3730class TemplateArgumentLocInventIterator {
3731 TreeTransform<Derived> &Self;
3732 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003733
Douglas Gregorfe921a72010-12-20 23:36:19 +00003734public:
3735 typedef TemplateArgumentLoc value_type;
3736 typedef TemplateArgumentLoc reference;
3737 typedef typename std::iterator_traits<InputIterator>::difference_type
3738 difference_type;
3739 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003740
Douglas Gregorfe921a72010-12-20 23:36:19 +00003741 class pointer {
3742 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003743
Douglas Gregorfe921a72010-12-20 23:36:19 +00003744 public:
3745 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003746
Douglas Gregorfe921a72010-12-20 23:36:19 +00003747 const TemplateArgumentLoc *operator->() const { return &Arg; }
3748 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003749
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00003750 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003751
Douglas Gregorfe921a72010-12-20 23:36:19 +00003752 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3753 InputIterator Iter)
3754 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003755
Douglas Gregorfe921a72010-12-20 23:36:19 +00003756 TemplateArgumentLocInventIterator &operator++() {
3757 ++Iter;
3758 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003759 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003760
Douglas Gregorfe921a72010-12-20 23:36:19 +00003761 TemplateArgumentLocInventIterator operator++(int) {
3762 TemplateArgumentLocInventIterator Old(*this);
3763 ++(*this);
3764 return Old;
3765 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003766
Douglas Gregorfe921a72010-12-20 23:36:19 +00003767 reference operator*() const {
3768 TemplateArgumentLoc Result;
3769 Self.InventTemplateArgumentLoc(*Iter, Result);
3770 return Result;
3771 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003772
Douglas Gregorfe921a72010-12-20 23:36:19 +00003773 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003774
Douglas Gregorfe921a72010-12-20 23:36:19 +00003775 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3776 const TemplateArgumentLocInventIterator &Y) {
3777 return X.Iter == Y.Iter;
3778 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003779
Douglas Gregorfe921a72010-12-20 23:36:19 +00003780 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3781 const TemplateArgumentLocInventIterator &Y) {
3782 return X.Iter != Y.Iter;
3783 }
3784};
Chad Rosier1dcde962012-08-08 18:46:20 +00003785
Douglas Gregor42cafa82010-12-20 17:42:22 +00003786template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003787template<typename InputIterator>
Richard Smithd784e682015-09-23 21:41:42 +00003788bool TreeTransform<Derived>::TransformTemplateArguments(
3789 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
3790 bool Uneval) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003791 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003792 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003793 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003794
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003795 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3796 // Unpack argument packs, which we translate them into separate
3797 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003798 // FIXME: We could do much better if we could guarantee that the
3799 // TemplateArgumentLocInfo for the pack expansion would be usable for
3800 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003801 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003802 TemplateArgument::pack_iterator>
3803 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003804 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003805 In.getArgument().pack_begin()),
3806 PackLocIterator(*this,
3807 In.getArgument().pack_end()),
Richard Smithd784e682015-09-23 21:41:42 +00003808 Outputs, Uneval))
Douglas Gregorfe921a72010-12-20 23:36:19 +00003809 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003810
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003811 continue;
3812 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003813
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003814 if (In.getArgument().isPackExpansion()) {
3815 // We have a pack expansion, for which we will be substituting into
3816 // the pattern.
3817 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003818 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003819 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003820 = getSema().getTemplateArgumentPackExpansionPattern(
3821 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003822
Chris Lattner01cf8db2011-07-20 06:58:45 +00003823 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003824 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3825 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003826
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003827 // Determine whether the set of unexpanded parameter packs can and should
3828 // be expanded.
3829 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003830 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003831 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003832 if (getDerived().TryExpandParameterPacks(Ellipsis,
3833 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003834 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003835 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003836 RetainExpansion,
3837 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003838 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003839
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003840 if (!Expand) {
3841 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003842 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003843 // expansion.
3844 TemplateArgumentLoc OutPattern;
3845 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Richard Smithd784e682015-09-23 21:41:42 +00003846 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003847 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003848
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003849 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3850 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003851 if (Out.getArgument().isNull())
3852 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003853
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003854 Outputs.addArgument(Out);
3855 continue;
3856 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003857
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003858 // The transform has determined that we should perform an elementwise
3859 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003860 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003861 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3862
Richard Smithd784e682015-09-23 21:41:42 +00003863 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003864 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003865
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003866 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003867 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3868 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003869 if (Out.getArgument().isNull())
3870 return true;
3871 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003872
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003873 Outputs.addArgument(Out);
3874 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003875
Douglas Gregor48d24112011-01-10 20:53:55 +00003876 // If we're supposed to retain a pack expansion, do so by temporarily
3877 // forgetting the partially-substituted parameter pack.
3878 if (RetainExpansion) {
3879 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003880
Richard Smithd784e682015-09-23 21:41:42 +00003881 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor48d24112011-01-10 20:53:55 +00003882 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003883
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003884 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3885 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003886 if (Out.getArgument().isNull())
3887 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003888
Douglas Gregor48d24112011-01-10 20:53:55 +00003889 Outputs.addArgument(Out);
3890 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003891
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003892 continue;
3893 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003894
3895 // The simple case:
Richard Smithd784e682015-09-23 21:41:42 +00003896 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003897 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003898
Douglas Gregor42cafa82010-12-20 17:42:22 +00003899 Outputs.addArgument(Out);
3900 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003901
Douglas Gregor42cafa82010-12-20 17:42:22 +00003902 return false;
3903
3904}
3905
Douglas Gregord6ff3322009-08-04 16:50:30 +00003906//===----------------------------------------------------------------------===//
3907// Type transformation
3908//===----------------------------------------------------------------------===//
3909
3910template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003911QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003912 if (getDerived().AlreadyTransformed(T))
3913 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003914
John McCall550e0c22009-10-21 00:40:46 +00003915 // Temporary workaround. All of these transformations should
3916 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003917 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3918 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003919
John McCall31f82722010-11-12 08:19:04 +00003920 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003921
John McCall550e0c22009-10-21 00:40:46 +00003922 if (!NewDI)
3923 return QualType();
3924
3925 return NewDI->getType();
3926}
3927
3928template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003929TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003930 // Refine the base location to the type's location.
3931 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3932 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003933 if (getDerived().AlreadyTransformed(DI->getType()))
3934 return DI;
3935
3936 TypeLocBuilder TLB;
3937
3938 TypeLoc TL = DI->getTypeLoc();
3939 TLB.reserve(TL.getFullDataSize());
3940
John McCall31f82722010-11-12 08:19:04 +00003941 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003942 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003943 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00003944
John McCallbcd03502009-12-07 02:54:59 +00003945 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003946}
3947
3948template<typename Derived>
3949QualType
John McCall31f82722010-11-12 08:19:04 +00003950TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003951 switch (T.getTypeLocClass()) {
3952#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003953#define TYPELOC(CLASS, PARENT) \
3954 case TypeLoc::CLASS: \
3955 return getDerived().Transform##CLASS##Type(TLB, \
3956 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003957#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003958 }
Mike Stump11289f42009-09-09 15:08:12 +00003959
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003960 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003961}
3962
3963/// FIXME: By default, this routine adds type qualifiers only to types
3964/// that can have qualifiers, and silently suppresses those qualifiers
3965/// that are not permitted (e.g., qualifiers on reference or function
3966/// types). This is the right thing for template instantiation, but
3967/// probably not for other clients.
3968template<typename Derived>
3969QualType
3970TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003971 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003972 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003973
John McCall31f82722010-11-12 08:19:04 +00003974 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003975 if (Result.isNull())
3976 return QualType();
3977
3978 // Silently suppress qualifiers if the result type can't be qualified.
3979 // FIXME: this is the right thing for template instantiation, but
3980 // probably not for other clients.
3981 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003982 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003983
John McCall31168b02011-06-15 23:02:42 +00003984 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003985 // resulting type.
3986 if (Quals.hasObjCLifetime()) {
3987 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3988 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003989 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003990 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003991 // A lifetime qualifier applied to a substituted template parameter
3992 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003993 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003994 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003995 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3996 QualType Replacement = SubstTypeParam->getReplacementType();
3997 Qualifiers Qs = Replacement.getQualifiers();
3998 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003999 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00004000 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
4001 Qs);
4002 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00004003 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00004004 Replacement);
4005 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00004006 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
4007 // 'auto' types behave the same way as template parameters.
4008 QualType Deduced = AutoTy->getDeducedType();
4009 Qualifiers Qs = Deduced.getQualifiers();
4010 Qs.removeObjCLifetime();
4011 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
4012 Qs);
Richard Smithe301ba22015-11-11 02:02:15 +00004013 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
Faisal Vali2b391ab2013-09-26 19:54:12 +00004014 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00004015 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00004016 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00004017 // Otherwise, complain about the addition of a qualifier to an
4018 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00004019 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00004020 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00004021 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00004022
Douglas Gregore46db902011-06-17 22:11:49 +00004023 Quals.removeObjCLifetime();
4024 }
4025 }
4026 }
John McCallcb0f89a2010-06-05 06:41:15 +00004027 if (!Quals.empty()) {
4028 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00004029 // BuildQualifiedType might not add qualifiers if they are invalid.
4030 if (Result.hasLocalQualifiers())
4031 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00004032 // No location information to preserve.
4033 }
John McCall550e0c22009-10-21 00:40:46 +00004034
4035 return Result;
4036}
4037
Douglas Gregor14454802011-02-25 02:25:35 +00004038template<typename Derived>
4039TypeLoc
4040TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
4041 QualType ObjectType,
4042 NamedDecl *UnqualLookup,
4043 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004044 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00004045 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00004046
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004047 TypeSourceInfo *TSI =
4048 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
4049 if (TSI)
4050 return TSI->getTypeLoc();
4051 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00004052}
4053
Douglas Gregor579c15f2011-03-02 18:32:08 +00004054template<typename Derived>
4055TypeSourceInfo *
4056TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4057 QualType ObjectType,
4058 NamedDecl *UnqualLookup,
4059 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004060 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00004061 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00004062
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004063 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
4064 UnqualLookup, SS);
4065}
4066
4067template <typename Derived>
4068TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
4069 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
4070 CXXScopeSpec &SS) {
4071 QualType T = TL.getType();
4072 assert(!getDerived().AlreadyTransformed(T));
4073
Douglas Gregor579c15f2011-03-02 18:32:08 +00004074 TypeLocBuilder TLB;
4075 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00004076
Douglas Gregor579c15f2011-03-02 18:32:08 +00004077 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004078 TemplateSpecializationTypeLoc SpecTL =
4079 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004080
Douglas Gregor579c15f2011-03-02 18:32:08 +00004081 TemplateName Template
4082 = getDerived().TransformTemplateName(SS,
4083 SpecTL.getTypePtr()->getTemplateName(),
4084 SpecTL.getTemplateNameLoc(),
4085 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00004086 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004087 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004088
4089 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004090 Template);
4091 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004092 DependentTemplateSpecializationTypeLoc SpecTL =
4093 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004094
Douglas Gregor579c15f2011-03-02 18:32:08 +00004095 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00004096 = getDerived().RebuildTemplateName(SS,
4097 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004098 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00004099 ObjectType, UnqualLookup);
4100 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004101 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004102
4103 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004104 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004105 Template,
4106 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00004107 } else {
4108 // Nothing special needs to be done for these.
4109 Result = getDerived().TransformType(TLB, TL);
4110 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004111
4112 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004113 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004114
Douglas Gregor579c15f2011-03-02 18:32:08 +00004115 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4116}
4117
John McCall550e0c22009-10-21 00:40:46 +00004118template <class TyLoc> static inline
4119QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
4120 TyLoc NewT = TLB.push<TyLoc>(T.getType());
4121 NewT.setNameLoc(T.getNameLoc());
4122 return T.getType();
4123}
4124
John McCall550e0c22009-10-21 00:40:46 +00004125template<typename Derived>
4126QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004127 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00004128 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
4129 NewT.setBuiltinLoc(T.getBuiltinLoc());
4130 if (T.needsExtraLocalData())
4131 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
4132 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004133}
Mike Stump11289f42009-09-09 15:08:12 +00004134
Douglas Gregord6ff3322009-08-04 16:50:30 +00004135template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004136QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004137 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00004138 // FIXME: recurse?
4139 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004140}
Mike Stump11289f42009-09-09 15:08:12 +00004141
Reid Kleckner0503a872013-12-05 01:23:43 +00004142template <typename Derived>
4143QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
4144 AdjustedTypeLoc TL) {
4145 // Adjustments applied during transformation are handled elsewhere.
4146 return getDerived().TransformType(TLB, TL.getOriginalLoc());
4147}
4148
Douglas Gregord6ff3322009-08-04 16:50:30 +00004149template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00004150QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
4151 DecayedTypeLoc TL) {
4152 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
4153 if (OriginalType.isNull())
4154 return QualType();
4155
4156 QualType Result = TL.getType();
4157 if (getDerived().AlwaysRebuild() ||
4158 OriginalType != TL.getOriginalLoc().getType())
4159 Result = SemaRef.Context.getDecayedType(OriginalType);
4160 TLB.push<DecayedTypeLoc>(Result);
4161 // Nothing to set for DecayedTypeLoc.
4162 return Result;
4163}
4164
4165template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004166QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004167 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004168 QualType PointeeType
4169 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004170 if (PointeeType.isNull())
4171 return QualType();
4172
4173 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00004174 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004175 // A dependent pointer type 'T *' has is being transformed such
4176 // that an Objective-C class type is being replaced for 'T'. The
4177 // resulting pointer type is an ObjCObjectPointerType, not a
4178 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00004179 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00004180
John McCall8b07ec22010-05-15 11:32:37 +00004181 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
4182 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004183 return Result;
4184 }
John McCall31f82722010-11-12 08:19:04 +00004185
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004186 if (getDerived().AlwaysRebuild() ||
4187 PointeeType != TL.getPointeeLoc().getType()) {
4188 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
4189 if (Result.isNull())
4190 return QualType();
4191 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004192
John McCall31168b02011-06-15 23:02:42 +00004193 // Objective-C ARC can add lifetime qualifiers to the type that we're
4194 // pointing to.
4195 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00004196
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004197 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
4198 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00004199 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004200}
Mike Stump11289f42009-09-09 15:08:12 +00004201
4202template<typename Derived>
4203QualType
John McCall550e0c22009-10-21 00:40:46 +00004204TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004205 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00004206 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00004207 = getDerived().TransformType(TLB, TL.getPointeeLoc());
4208 if (PointeeType.isNull())
4209 return QualType();
4210
4211 QualType Result = TL.getType();
4212 if (getDerived().AlwaysRebuild() ||
4213 PointeeType != TL.getPointeeLoc().getType()) {
4214 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00004215 TL.getSigilLoc());
4216 if (Result.isNull())
4217 return QualType();
4218 }
4219
Douglas Gregor049211a2010-04-22 16:50:51 +00004220 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00004221 NewT.setSigilLoc(TL.getSigilLoc());
4222 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004223}
4224
John McCall70dd5f62009-10-30 00:06:24 +00004225/// Transforms a reference type. Note that somewhat paradoxically we
4226/// don't care whether the type itself is an l-value type or an r-value
4227/// type; we only care if the type was *written* as an l-value type
4228/// or an r-value type.
4229template<typename Derived>
4230QualType
4231TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004232 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00004233 const ReferenceType *T = TL.getTypePtr();
4234
4235 // Note that this works with the pointee-as-written.
4236 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4237 if (PointeeType.isNull())
4238 return QualType();
4239
4240 QualType Result = TL.getType();
4241 if (getDerived().AlwaysRebuild() ||
4242 PointeeType != T->getPointeeTypeAsWritten()) {
4243 Result = getDerived().RebuildReferenceType(PointeeType,
4244 T->isSpelledAsLValue(),
4245 TL.getSigilLoc());
4246 if (Result.isNull())
4247 return QualType();
4248 }
4249
John McCall31168b02011-06-15 23:02:42 +00004250 // Objective-C ARC can add lifetime qualifiers to the type that we're
4251 // referring to.
4252 TLB.TypeWasModifiedSafely(
4253 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4254
John McCall70dd5f62009-10-30 00:06:24 +00004255 // r-value references can be rebuilt as l-value references.
4256 ReferenceTypeLoc NewTL;
4257 if (isa<LValueReferenceType>(Result))
4258 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4259 else
4260 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4261 NewTL.setSigilLoc(TL.getSigilLoc());
4262
4263 return Result;
4264}
4265
Mike Stump11289f42009-09-09 15:08:12 +00004266template<typename Derived>
4267QualType
John McCall550e0c22009-10-21 00:40:46 +00004268TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004269 LValueReferenceTypeLoc TL) {
4270 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004271}
4272
Mike Stump11289f42009-09-09 15:08:12 +00004273template<typename Derived>
4274QualType
John McCall550e0c22009-10-21 00:40:46 +00004275TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004276 RValueReferenceTypeLoc TL) {
4277 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004278}
Mike Stump11289f42009-09-09 15:08:12 +00004279
Douglas Gregord6ff3322009-08-04 16:50:30 +00004280template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004281QualType
John McCall550e0c22009-10-21 00:40:46 +00004282TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004283 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004284 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004285 if (PointeeType.isNull())
4286 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004287
Abramo Bagnara509357842011-03-05 14:42:21 +00004288 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004289 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00004290 if (OldClsTInfo) {
4291 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4292 if (!NewClsTInfo)
4293 return QualType();
4294 }
4295
4296 const MemberPointerType *T = TL.getTypePtr();
4297 QualType OldClsType = QualType(T->getClass(), 0);
4298 QualType NewClsType;
4299 if (NewClsTInfo)
4300 NewClsType = NewClsTInfo->getType();
4301 else {
4302 NewClsType = getDerived().TransformType(OldClsType);
4303 if (NewClsType.isNull())
4304 return QualType();
4305 }
Mike Stump11289f42009-09-09 15:08:12 +00004306
John McCall550e0c22009-10-21 00:40:46 +00004307 QualType Result = TL.getType();
4308 if (getDerived().AlwaysRebuild() ||
4309 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00004310 NewClsType != OldClsType) {
4311 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004312 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004313 if (Result.isNull())
4314 return QualType();
4315 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004316
Reid Kleckner0503a872013-12-05 01:23:43 +00004317 // If we had to adjust the pointee type when building a member pointer, make
4318 // sure to push TypeLoc info for it.
4319 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4320 if (MPT && PointeeType != MPT->getPointeeType()) {
4321 assert(isa<AdjustedType>(MPT->getPointeeType()));
4322 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4323 }
4324
John McCall550e0c22009-10-21 00:40:46 +00004325 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4326 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004327 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004328
4329 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004330}
4331
Mike Stump11289f42009-09-09 15:08:12 +00004332template<typename Derived>
4333QualType
John McCall550e0c22009-10-21 00:40:46 +00004334TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004335 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004336 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004337 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004338 if (ElementType.isNull())
4339 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004340
John McCall550e0c22009-10-21 00:40:46 +00004341 QualType Result = TL.getType();
4342 if (getDerived().AlwaysRebuild() ||
4343 ElementType != T->getElementType()) {
4344 Result = getDerived().RebuildConstantArrayType(ElementType,
4345 T->getSizeModifier(),
4346 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004347 T->getIndexTypeCVRQualifiers(),
4348 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004349 if (Result.isNull())
4350 return QualType();
4351 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004352
4353 // We might have either a ConstantArrayType or a VariableArrayType now:
4354 // a ConstantArrayType is allowed to have an element type which is a
4355 // VariableArrayType if the type is dependent. Fortunately, all array
4356 // types have the same location layout.
4357 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004358 NewTL.setLBracketLoc(TL.getLBracketLoc());
4359 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004360
John McCall550e0c22009-10-21 00:40:46 +00004361 Expr *Size = TL.getSizeExpr();
4362 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004363 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4364 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004365 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4366 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004367 }
4368 NewTL.setSizeExpr(Size);
4369
4370 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004371}
Mike Stump11289f42009-09-09 15:08:12 +00004372
Douglas Gregord6ff3322009-08-04 16:50:30 +00004373template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004374QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004375 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004376 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004377 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004378 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004379 if (ElementType.isNull())
4380 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004381
John McCall550e0c22009-10-21 00:40:46 +00004382 QualType Result = TL.getType();
4383 if (getDerived().AlwaysRebuild() ||
4384 ElementType != T->getElementType()) {
4385 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004386 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004387 T->getIndexTypeCVRQualifiers(),
4388 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004389 if (Result.isNull())
4390 return QualType();
4391 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004392
John McCall550e0c22009-10-21 00:40:46 +00004393 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4394 NewTL.setLBracketLoc(TL.getLBracketLoc());
4395 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004396 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004397
4398 return Result;
4399}
4400
4401template<typename Derived>
4402QualType
4403TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004404 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004405 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004406 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4407 if (ElementType.isNull())
4408 return QualType();
4409
John McCalldadc5752010-08-24 06:29:42 +00004410 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00004411 = getDerived().TransformExpr(T->getSizeExpr());
4412 if (SizeResult.isInvalid())
4413 return QualType();
4414
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004415 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004416
4417 QualType Result = TL.getType();
4418 if (getDerived().AlwaysRebuild() ||
4419 ElementType != T->getElementType() ||
4420 Size != T->getSizeExpr()) {
4421 Result = getDerived().RebuildVariableArrayType(ElementType,
4422 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004423 Size,
John McCall550e0c22009-10-21 00:40:46 +00004424 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004425 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004426 if (Result.isNull())
4427 return QualType();
4428 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004429
Serge Pavlov774c6d02014-02-06 03:49:11 +00004430 // We might have constant size array now, but fortunately it has the same
4431 // location layout.
4432 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004433 NewTL.setLBracketLoc(TL.getLBracketLoc());
4434 NewTL.setRBracketLoc(TL.getRBracketLoc());
4435 NewTL.setSizeExpr(Size);
4436
4437 return Result;
4438}
4439
4440template<typename Derived>
4441QualType
4442TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004443 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004444 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004445 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4446 if (ElementType.isNull())
4447 return QualType();
4448
Richard Smith764d2fe2011-12-20 02:08:33 +00004449 // Array bounds are constant expressions.
4450 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4451 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004452
John McCall33ddac02011-01-19 10:06:00 +00004453 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4454 Expr *origSize = TL.getSizeExpr();
4455 if (!origSize) origSize = T->getSizeExpr();
4456
4457 ExprResult sizeResult
4458 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004459 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004460 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004461 return QualType();
4462
John McCall33ddac02011-01-19 10:06:00 +00004463 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004464
4465 QualType Result = TL.getType();
4466 if (getDerived().AlwaysRebuild() ||
4467 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004468 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004469 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4470 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004471 size,
John McCall550e0c22009-10-21 00:40:46 +00004472 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004473 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004474 if (Result.isNull())
4475 return QualType();
4476 }
John McCall550e0c22009-10-21 00:40:46 +00004477
4478 // We might have any sort of array type now, but fortunately they
4479 // all have the same location layout.
4480 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4481 NewTL.setLBracketLoc(TL.getLBracketLoc());
4482 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004483 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004484
4485 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004486}
Mike Stump11289f42009-09-09 15:08:12 +00004487
4488template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004489QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004490 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004491 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004492 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004493
4494 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004495 QualType ElementType = getDerived().TransformType(T->getElementType());
4496 if (ElementType.isNull())
4497 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004498
Richard Smith764d2fe2011-12-20 02:08:33 +00004499 // Vector sizes are constant expressions.
4500 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4501 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004502
John McCalldadc5752010-08-24 06:29:42 +00004503 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004504 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004505 if (Size.isInvalid())
4506 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004507
John McCall550e0c22009-10-21 00:40:46 +00004508 QualType Result = TL.getType();
4509 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004510 ElementType != T->getElementType() ||
4511 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004512 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004513 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004514 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004515 if (Result.isNull())
4516 return QualType();
4517 }
John McCall550e0c22009-10-21 00:40:46 +00004518
4519 // Result might be dependent or not.
4520 if (isa<DependentSizedExtVectorType>(Result)) {
4521 DependentSizedExtVectorTypeLoc NewTL
4522 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4523 NewTL.setNameLoc(TL.getNameLoc());
4524 } else {
4525 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4526 NewTL.setNameLoc(TL.getNameLoc());
4527 }
4528
4529 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004530}
Mike Stump11289f42009-09-09 15:08:12 +00004531
4532template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004533QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004534 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004535 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004536 QualType ElementType = getDerived().TransformType(T->getElementType());
4537 if (ElementType.isNull())
4538 return QualType();
4539
John McCall550e0c22009-10-21 00:40:46 +00004540 QualType Result = TL.getType();
4541 if (getDerived().AlwaysRebuild() ||
4542 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004543 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004544 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004545 if (Result.isNull())
4546 return QualType();
4547 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004548
John McCall550e0c22009-10-21 00:40:46 +00004549 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4550 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004551
John McCall550e0c22009-10-21 00:40:46 +00004552 return Result;
4553}
4554
4555template<typename Derived>
4556QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004557 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004558 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004559 QualType ElementType = getDerived().TransformType(T->getElementType());
4560 if (ElementType.isNull())
4561 return QualType();
4562
4563 QualType Result = TL.getType();
4564 if (getDerived().AlwaysRebuild() ||
4565 ElementType != T->getElementType()) {
4566 Result = getDerived().RebuildExtVectorType(ElementType,
4567 T->getNumElements(),
4568 /*FIXME*/ SourceLocation());
4569 if (Result.isNull())
4570 return QualType();
4571 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004572
John McCall550e0c22009-10-21 00:40:46 +00004573 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4574 NewTL.setNameLoc(TL.getNameLoc());
4575
4576 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004577}
Mike Stump11289f42009-09-09 15:08:12 +00004578
David Blaikie05785d12013-02-20 22:23:23 +00004579template <typename Derived>
4580ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4581 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4582 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004583 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004584 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004585
Douglas Gregor715e4612011-01-14 22:40:04 +00004586 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004587 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004588 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004589 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004590 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004591
Douglas Gregor715e4612011-01-14 22:40:04 +00004592 TypeLocBuilder TLB;
4593 TypeLoc NewTL = OldDI->getTypeLoc();
4594 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004595
4596 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004597 OldExpansionTL.getPatternLoc());
4598 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004599 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004600
4601 Result = RebuildPackExpansionType(Result,
4602 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004603 OldExpansionTL.getEllipsisLoc(),
4604 NumExpansions);
4605 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004606 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004607
Douglas Gregor715e4612011-01-14 22:40:04 +00004608 PackExpansionTypeLoc NewExpansionTL
4609 = TLB.push<PackExpansionTypeLoc>(Result);
4610 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4611 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4612 } else
4613 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004614 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004615 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004616
John McCall8fb0d9d2011-05-01 22:35:37 +00004617 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004618 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004619
4620 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4621 OldParm->getDeclContext(),
4622 OldParm->getInnerLocStart(),
4623 OldParm->getLocation(),
4624 OldParm->getIdentifier(),
4625 NewDI->getType(),
4626 NewDI,
4627 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004628 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004629 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4630 OldParm->getFunctionScopeIndex() + indexAdjustment);
4631 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004632}
4633
4634template<typename Derived>
4635bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004636 TransformFunctionTypeParams(SourceLocation Loc,
4637 ParmVarDecl **Params, unsigned NumParams,
4638 const QualType *ParamTypes,
John McCallc8e321d2016-03-01 02:09:25 +00004639 const FunctionProtoType::ExtParameterInfo *ParamInfos,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004640 SmallVectorImpl<QualType> &OutParamTypes,
John McCallc8e321d2016-03-01 02:09:25 +00004641 SmallVectorImpl<ParmVarDecl*> *PVars,
4642 Sema::ExtParameterInfoBuilder &PInfos) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004643 int indexAdjustment = 0;
4644
Douglas Gregordd472162011-01-07 00:20:55 +00004645 for (unsigned i = 0; i != NumParams; ++i) {
4646 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004647 assert(OldParm->getFunctionScopeIndex() == i);
4648
David Blaikie05785d12013-02-20 22:23:23 +00004649 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004650 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004651 if (OldParm->isParameterPack()) {
4652 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004653 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004654
Douglas Gregor5499af42011-01-05 23:12:31 +00004655 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004656 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004657 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004658 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4659 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004660 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4661
Douglas Gregor5499af42011-01-05 23:12:31 +00004662 // Determine whether we should expand the parameter packs.
4663 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004664 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004665 Optional<unsigned> OrigNumExpansions =
4666 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004667 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004668 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4669 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004670 Unexpanded,
4671 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004672 RetainExpansion,
4673 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004674 return true;
4675 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004676
Douglas Gregor5499af42011-01-05 23:12:31 +00004677 if (ShouldExpand) {
4678 // Expand the function parameter pack into multiple, separate
4679 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004680 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004681 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004682 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004683 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004684 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004685 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004686 OrigNumExpansions,
4687 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004688 if (!NewParm)
4689 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004690
John McCallc8e321d2016-03-01 02:09:25 +00004691 if (ParamInfos)
4692 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004693 OutParamTypes.push_back(NewParm->getType());
4694 if (PVars)
4695 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004696 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004697
4698 // If we're supposed to retain a pack expansion, do so by temporarily
4699 // forgetting the partially-substituted parameter pack.
4700 if (RetainExpansion) {
4701 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004702 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004703 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004704 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004705 OrigNumExpansions,
4706 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004707 if (!NewParm)
4708 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004709
John McCallc8e321d2016-03-01 02:09:25 +00004710 if (ParamInfos)
4711 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004712 OutParamTypes.push_back(NewParm->getType());
4713 if (PVars)
4714 PVars->push_back(NewParm);
4715 }
4716
John McCall8fb0d9d2011-05-01 22:35:37 +00004717 // The next parameter should have the same adjustment as the
4718 // last thing we pushed, but we post-incremented indexAdjustment
4719 // on every push. Also, if we push nothing, the adjustment should
4720 // go down by one.
4721 indexAdjustment--;
4722
Douglas Gregor5499af42011-01-05 23:12:31 +00004723 // We're done with the pack expansion.
4724 continue;
4725 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004726
4727 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004728 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004729 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4730 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004731 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004732 NumExpansions,
4733 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004734 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004735 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004736 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004737 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004738
John McCall58f10c32010-03-11 09:03:00 +00004739 if (!NewParm)
4740 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004741
John McCallc8e321d2016-03-01 02:09:25 +00004742 if (ParamInfos)
4743 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004744 OutParamTypes.push_back(NewParm->getType());
4745 if (PVars)
4746 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004747 continue;
4748 }
John McCall58f10c32010-03-11 09:03:00 +00004749
4750 // Deal with the possibility that we don't have a parameter
4751 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004752 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004753 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004754 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004755 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004756 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004757 = dyn_cast<PackExpansionType>(OldType)) {
4758 // We have a function parameter pack that may need to be expanded.
4759 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004760 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004761 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004762
Douglas Gregor5499af42011-01-05 23:12:31 +00004763 // Determine whether we should expand the parameter packs.
4764 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004765 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004766 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004767 Unexpanded,
4768 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004769 RetainExpansion,
4770 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004771 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004772 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004773
Douglas Gregor5499af42011-01-05 23:12:31 +00004774 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004775 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004776 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004777 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004778 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4779 QualType NewType = getDerived().TransformType(Pattern);
4780 if (NewType.isNull())
4781 return true;
John McCall58f10c32010-03-11 09:03:00 +00004782
John McCallc8e321d2016-03-01 02:09:25 +00004783 if (ParamInfos)
4784 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004785 OutParamTypes.push_back(NewType);
4786 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004787 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004788 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004789
Douglas Gregor5499af42011-01-05 23:12:31 +00004790 // We're done with the pack expansion.
4791 continue;
4792 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004793
Douglas Gregor48d24112011-01-10 20:53:55 +00004794 // If we're supposed to retain a pack expansion, do so by temporarily
4795 // forgetting the partially-substituted parameter pack.
4796 if (RetainExpansion) {
4797 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4798 QualType NewType = getDerived().TransformType(Pattern);
4799 if (NewType.isNull())
4800 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004801
John McCallc8e321d2016-03-01 02:09:25 +00004802 if (ParamInfos)
4803 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregor48d24112011-01-10 20:53:55 +00004804 OutParamTypes.push_back(NewType);
4805 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004806 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004807 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004808
Chad Rosier1dcde962012-08-08 18:46:20 +00004809 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004810 // expansion.
4811 OldType = Expansion->getPattern();
4812 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004813 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4814 NewType = getDerived().TransformType(OldType);
4815 } else {
4816 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004817 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004818
Douglas Gregor5499af42011-01-05 23:12:31 +00004819 if (NewType.isNull())
4820 return true;
4821
4822 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004823 NewType = getSema().Context.getPackExpansionType(NewType,
4824 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004825
John McCallc8e321d2016-03-01 02:09:25 +00004826 if (ParamInfos)
4827 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004828 OutParamTypes.push_back(NewType);
4829 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004830 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004831 }
4832
John McCall8fb0d9d2011-05-01 22:35:37 +00004833#ifndef NDEBUG
4834 if (PVars) {
4835 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4836 if (ParmVarDecl *parm = (*PVars)[i])
4837 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004838 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004839#endif
4840
4841 return false;
4842}
John McCall58f10c32010-03-11 09:03:00 +00004843
4844template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004845QualType
John McCall550e0c22009-10-21 00:40:46 +00004846TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004847 FunctionProtoTypeLoc TL) {
Richard Smith2e321552014-11-12 02:00:47 +00004848 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00004849 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00004850 return getDerived().TransformFunctionProtoType(
4851 TLB, TL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00004852 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
4853 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
4854 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00004855 });
Douglas Gregor3024f072012-04-16 07:05:22 +00004856}
4857
Richard Smith2e321552014-11-12 02:00:47 +00004858template<typename Derived> template<typename Fn>
4859QualType TreeTransform<Derived>::TransformFunctionProtoType(
4860 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
4861 unsigned ThisTypeQuals, Fn TransformExceptionSpec) {
John McCallc8e321d2016-03-01 02:09:25 +00004862
Douglas Gregor4afc2362010-08-31 00:26:14 +00004863 // Transform the parameters and return type.
4864 //
Richard Smithf623c962012-04-17 00:58:00 +00004865 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004866 // When the function has a trailing return type, we instantiate the
4867 // parameters before the return type, since the return type can then refer
4868 // to the parameters themselves (via decltype, sizeof, etc.).
4869 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004870 SmallVector<QualType, 4> ParamTypes;
4871 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallc8e321d2016-03-01 02:09:25 +00004872 Sema::ExtParameterInfoBuilder ExtParamInfos;
John McCall424cec92011-01-19 06:33:43 +00004873 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004874
Douglas Gregor7fb25412010-10-01 18:44:50 +00004875 QualType ResultType;
4876
Richard Smith1226c602012-08-14 22:51:13 +00004877 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004878 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004879 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
John McCallc8e321d2016-03-01 02:09:25 +00004880 TL.getTypePtr()->param_type_begin(),
4881 T->getExtParameterInfosOrNull(),
4882 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004883 return QualType();
4884
Douglas Gregor3024f072012-04-16 07:05:22 +00004885 {
4886 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004887 // If a declaration declares a member function or member function
4888 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004889 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004890 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004891 // declarator.
4892 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004893
Alp Toker42a16a62014-01-25 23:51:36 +00004894 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004895 if (ResultType.isNull())
4896 return QualType();
4897 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004898 }
4899 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004900 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004901 if (ResultType.isNull())
4902 return QualType();
4903
Alp Toker9cacbab2014-01-20 20:26:09 +00004904 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004905 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
John McCallc8e321d2016-03-01 02:09:25 +00004906 TL.getTypePtr()->param_type_begin(),
4907 T->getExtParameterInfosOrNull(),
4908 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004909 return QualType();
4910 }
4911
Richard Smith2e321552014-11-12 02:00:47 +00004912 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
4913
4914 bool EPIChanged = false;
4915 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
4916 return QualType();
4917
John McCallc8e321d2016-03-01 02:09:25 +00004918 // Handle extended parameter information.
4919 if (auto NewExtParamInfos =
4920 ExtParamInfos.getPointerOrNull(ParamTypes.size())) {
4921 if (!EPI.ExtParameterInfos ||
4922 llvm::makeArrayRef(EPI.ExtParameterInfos, TL.getNumParams())
4923 != llvm::makeArrayRef(NewExtParamInfos, ParamTypes.size())) {
4924 EPIChanged = true;
4925 }
4926 EPI.ExtParameterInfos = NewExtParamInfos;
4927 } else if (EPI.ExtParameterInfos) {
4928 EPIChanged = true;
4929 EPI.ExtParameterInfos = nullptr;
4930 }
Richard Smithf623c962012-04-17 00:58:00 +00004931
John McCall550e0c22009-10-21 00:40:46 +00004932 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004933 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Benjamin Kramere1c08b02015-08-18 08:10:39 +00004934 T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) {
Richard Smith2e321552014-11-12 02:00:47 +00004935 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
John McCall550e0c22009-10-21 00:40:46 +00004936 if (Result.isNull())
4937 return QualType();
4938 }
Mike Stump11289f42009-09-09 15:08:12 +00004939
John McCall550e0c22009-10-21 00:40:46 +00004940 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004941 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004942 NewTL.setLParenLoc(TL.getLParenLoc());
4943 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004944 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004945 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4946 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004947
4948 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004949}
Mike Stump11289f42009-09-09 15:08:12 +00004950
Douglas Gregord6ff3322009-08-04 16:50:30 +00004951template<typename Derived>
Richard Smith2e321552014-11-12 02:00:47 +00004952bool TreeTransform<Derived>::TransformExceptionSpec(
4953 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
4954 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
4955 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
4956
4957 // Instantiate a dynamic noexcept expression, if any.
4958 if (ESI.Type == EST_ComputedNoexcept) {
4959 EnterExpressionEvaluationContext Unevaluated(getSema(),
4960 Sema::ConstantEvaluated);
4961 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
4962 if (NoexceptExpr.isInvalid())
4963 return true;
4964
4965 NoexceptExpr = getSema().CheckBooleanCondition(
4966 NoexceptExpr.get(), NoexceptExpr.get()->getLocStart());
4967 if (NoexceptExpr.isInvalid())
4968 return true;
4969
4970 if (!NoexceptExpr.get()->isValueDependent()) {
4971 NoexceptExpr = getSema().VerifyIntegerConstantExpression(
4972 NoexceptExpr.get(), nullptr,
4973 diag::err_noexcept_needs_constant_expression,
4974 /*AllowFold*/false);
4975 if (NoexceptExpr.isInvalid())
4976 return true;
4977 }
4978
4979 if (ESI.NoexceptExpr != NoexceptExpr.get())
4980 Changed = true;
4981 ESI.NoexceptExpr = NoexceptExpr.get();
4982 }
4983
4984 if (ESI.Type != EST_Dynamic)
4985 return false;
4986
4987 // Instantiate a dynamic exception specification's type.
4988 for (QualType T : ESI.Exceptions) {
4989 if (const PackExpansionType *PackExpansion =
4990 T->getAs<PackExpansionType>()) {
4991 Changed = true;
4992
4993 // We have a pack expansion. Instantiate it.
4994 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
4995 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
4996 Unexpanded);
4997 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4998
4999 // Determine whether the set of unexpanded parameter packs can and
5000 // should
5001 // be expanded.
5002 bool Expand = false;
5003 bool RetainExpansion = false;
5004 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5005 // FIXME: Track the location of the ellipsis (and track source location
5006 // information for the types in the exception specification in general).
5007 if (getDerived().TryExpandParameterPacks(
5008 Loc, SourceRange(), Unexpanded, Expand,
5009 RetainExpansion, NumExpansions))
5010 return true;
5011
5012 if (!Expand) {
5013 // We can't expand this pack expansion into separate arguments yet;
5014 // just substitute into the pattern and create a new pack expansion
5015 // type.
5016 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5017 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5018 if (U.isNull())
5019 return true;
5020
5021 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
5022 Exceptions.push_back(U);
5023 continue;
5024 }
5025
5026 // Substitute into the pack expansion pattern for each slice of the
5027 // pack.
5028 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5029 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5030
5031 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5032 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5033 return true;
5034
5035 Exceptions.push_back(U);
5036 }
5037 } else {
5038 QualType U = getDerived().TransformType(T);
5039 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5040 return true;
5041 if (T != U)
5042 Changed = true;
5043
5044 Exceptions.push_back(U);
5045 }
5046 }
5047
5048 ESI.Exceptions = Exceptions;
5049 return false;
5050}
5051
5052template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00005053QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00005054 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005055 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005056 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00005057 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00005058 if (ResultType.isNull())
5059 return QualType();
5060
5061 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00005062 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00005063 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
5064
5065 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005066 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00005067 NewTL.setLParenLoc(TL.getLParenLoc());
5068 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005069 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00005070
5071 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005072}
Mike Stump11289f42009-09-09 15:08:12 +00005073
John McCallb96ec562009-12-04 22:46:56 +00005074template<typename Derived> QualType
5075TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005076 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005077 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005078 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00005079 if (!D)
5080 return QualType();
5081
5082 QualType Result = TL.getType();
5083 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
5084 Result = getDerived().RebuildUnresolvedUsingType(D);
5085 if (Result.isNull())
5086 return QualType();
5087 }
5088
5089 // We might get an arbitrary type spec type back. We should at
5090 // least always get a type spec type, though.
5091 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
5092 NewTL.setNameLoc(TL.getNameLoc());
5093
5094 return Result;
5095}
5096
Douglas Gregord6ff3322009-08-04 16:50:30 +00005097template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005098QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005099 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005100 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00005101 TypedefNameDecl *Typedef
5102 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5103 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005104 if (!Typedef)
5105 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005106
John McCall550e0c22009-10-21 00:40:46 +00005107 QualType Result = TL.getType();
5108 if (getDerived().AlwaysRebuild() ||
5109 Typedef != T->getDecl()) {
5110 Result = getDerived().RebuildTypedefType(Typedef);
5111 if (Result.isNull())
5112 return QualType();
5113 }
Mike Stump11289f42009-09-09 15:08:12 +00005114
John McCall550e0c22009-10-21 00:40:46 +00005115 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
5116 NewTL.setNameLoc(TL.getNameLoc());
5117
5118 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005119}
Mike Stump11289f42009-09-09 15:08:12 +00005120
Douglas Gregord6ff3322009-08-04 16:50:30 +00005121template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005122QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005123 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00005124 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00005125 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
5126 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00005127
John McCalldadc5752010-08-24 06:29:42 +00005128 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005129 if (E.isInvalid())
5130 return QualType();
5131
Eli Friedmane4f22df2012-02-29 04:03:55 +00005132 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
5133 if (E.isInvalid())
5134 return QualType();
5135
John McCall550e0c22009-10-21 00:40:46 +00005136 QualType Result = TL.getType();
5137 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00005138 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005139 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00005140 if (Result.isNull())
5141 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005142 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005143 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005144
John McCall550e0c22009-10-21 00:40:46 +00005145 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005146 NewTL.setTypeofLoc(TL.getTypeofLoc());
5147 NewTL.setLParenLoc(TL.getLParenLoc());
5148 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00005149
5150 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005151}
Mike Stump11289f42009-09-09 15:08:12 +00005152
5153template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005154QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005155 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00005156 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
5157 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
5158 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005159 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005160
John McCall550e0c22009-10-21 00:40:46 +00005161 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00005162 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
5163 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00005164 if (Result.isNull())
5165 return QualType();
5166 }
Mike Stump11289f42009-09-09 15:08:12 +00005167
John McCall550e0c22009-10-21 00:40:46 +00005168 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005169 NewTL.setTypeofLoc(TL.getTypeofLoc());
5170 NewTL.setLParenLoc(TL.getLParenLoc());
5171 NewTL.setRParenLoc(TL.getRParenLoc());
5172 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00005173
5174 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005175}
Mike Stump11289f42009-09-09 15:08:12 +00005176
5177template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005178QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005179 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005180 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00005181
Douglas Gregore922c772009-08-04 22:27:00 +00005182 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00005183 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
5184 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00005185
John McCalldadc5752010-08-24 06:29:42 +00005186 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005187 if (E.isInvalid())
5188 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005189
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005190 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00005191 if (E.isInvalid())
5192 return QualType();
5193
John McCall550e0c22009-10-21 00:40:46 +00005194 QualType Result = TL.getType();
5195 if (getDerived().AlwaysRebuild() ||
5196 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005197 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005198 if (Result.isNull())
5199 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005200 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005201 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005202
John McCall550e0c22009-10-21 00:40:46 +00005203 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
5204 NewTL.setNameLoc(TL.getNameLoc());
5205
5206 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005207}
5208
5209template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00005210QualType TreeTransform<Derived>::TransformUnaryTransformType(
5211 TypeLocBuilder &TLB,
5212 UnaryTransformTypeLoc TL) {
5213 QualType Result = TL.getType();
5214 if (Result->isDependentType()) {
5215 const UnaryTransformType *T = TL.getTypePtr();
5216 QualType NewBase =
5217 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
5218 Result = getDerived().RebuildUnaryTransformType(NewBase,
5219 T->getUTTKind(),
5220 TL.getKWLoc());
5221 if (Result.isNull())
5222 return QualType();
5223 }
5224
5225 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
5226 NewTL.setKWLoc(TL.getKWLoc());
5227 NewTL.setParensRange(TL.getParensRange());
5228 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
5229 return Result;
5230}
5231
5232template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00005233QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
5234 AutoTypeLoc TL) {
5235 const AutoType *T = TL.getTypePtr();
5236 QualType OldDeduced = T->getDeducedType();
5237 QualType NewDeduced;
5238 if (!OldDeduced.isNull()) {
5239 NewDeduced = getDerived().TransformType(OldDeduced);
5240 if (NewDeduced.isNull())
5241 return QualType();
5242 }
5243
5244 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00005245 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
5246 T->isDependentType()) {
Richard Smithe301ba22015-11-11 02:02:15 +00005247 Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword());
Richard Smith30482bc2011-02-20 03:19:35 +00005248 if (Result.isNull())
5249 return QualType();
5250 }
5251
5252 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5253 NewTL.setNameLoc(TL.getNameLoc());
5254
5255 return Result;
5256}
5257
5258template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005259QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005260 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005261 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005262 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005263 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5264 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005265 if (!Record)
5266 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005267
John McCall550e0c22009-10-21 00:40:46 +00005268 QualType Result = TL.getType();
5269 if (getDerived().AlwaysRebuild() ||
5270 Record != T->getDecl()) {
5271 Result = getDerived().RebuildRecordType(Record);
5272 if (Result.isNull())
5273 return QualType();
5274 }
Mike Stump11289f42009-09-09 15:08:12 +00005275
John McCall550e0c22009-10-21 00:40:46 +00005276 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5277 NewTL.setNameLoc(TL.getNameLoc());
5278
5279 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005280}
Mike Stump11289f42009-09-09 15:08:12 +00005281
5282template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005283QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005284 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005285 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005286 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005287 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5288 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005289 if (!Enum)
5290 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005291
John McCall550e0c22009-10-21 00:40:46 +00005292 QualType Result = TL.getType();
5293 if (getDerived().AlwaysRebuild() ||
5294 Enum != T->getDecl()) {
5295 Result = getDerived().RebuildEnumType(Enum);
5296 if (Result.isNull())
5297 return QualType();
5298 }
Mike Stump11289f42009-09-09 15:08:12 +00005299
John McCall550e0c22009-10-21 00:40:46 +00005300 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5301 NewTL.setNameLoc(TL.getNameLoc());
5302
5303 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005304}
John McCallfcc33b02009-09-05 00:15:47 +00005305
John McCalle78aac42010-03-10 03:28:59 +00005306template<typename Derived>
5307QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5308 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005309 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00005310 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5311 TL.getTypePtr()->getDecl());
5312 if (!D) return QualType();
5313
5314 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5315 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5316 return T;
5317}
5318
Douglas Gregord6ff3322009-08-04 16:50:30 +00005319template<typename Derived>
5320QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005321 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005322 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00005323 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005324}
5325
Mike Stump11289f42009-09-09 15:08:12 +00005326template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00005327QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005328 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005329 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005330 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005331
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005332 // Substitute into the replacement type, which itself might involve something
5333 // that needs to be transformed. This only tends to occur with default
5334 // template arguments of template template parameters.
5335 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5336 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5337 if (Replacement.isNull())
5338 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005339
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005340 // Always canonicalize the replacement type.
5341 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5342 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00005343 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005344 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00005345
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005346 // Propagate type-source information.
5347 SubstTemplateTypeParmTypeLoc NewTL
5348 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5349 NewTL.setNameLoc(TL.getNameLoc());
5350 return Result;
5351
John McCallcebee162009-10-18 09:09:24 +00005352}
5353
5354template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00005355QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5356 TypeLocBuilder &TLB,
5357 SubstTemplateTypeParmPackTypeLoc TL) {
5358 return TransformTypeSpecType(TLB, TL);
5359}
5360
5361template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00005362QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005363 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005364 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00005365 const TemplateSpecializationType *T = TL.getTypePtr();
5366
Douglas Gregordf846d12011-03-02 18:46:51 +00005367 // The nested-name-specifier never matters in a TemplateSpecializationType,
5368 // because we can't have a dependent nested-name-specifier anyway.
5369 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00005370 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00005371 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5372 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005373 if (Template.isNull())
5374 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005375
John McCall31f82722010-11-12 08:19:04 +00005376 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5377}
5378
Eli Friedman0dfb8892011-10-06 23:00:33 +00005379template<typename Derived>
5380QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5381 AtomicTypeLoc TL) {
5382 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5383 if (ValueType.isNull())
5384 return QualType();
5385
5386 QualType Result = TL.getType();
5387 if (getDerived().AlwaysRebuild() ||
5388 ValueType != TL.getValueLoc().getType()) {
5389 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5390 if (Result.isNull())
5391 return QualType();
5392 }
5393
5394 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5395 NewTL.setKWLoc(TL.getKWLoc());
5396 NewTL.setLParenLoc(TL.getLParenLoc());
5397 NewTL.setRParenLoc(TL.getRParenLoc());
5398
5399 return Result;
5400}
5401
Xiuli Pan9c14e282016-01-09 12:53:17 +00005402template <typename Derived>
5403QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB,
5404 PipeTypeLoc TL) {
5405 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5406 if (ValueType.isNull())
5407 return QualType();
5408
5409 QualType Result = TL.getType();
5410 if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
5411 Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc());
5412 if (Result.isNull())
5413 return QualType();
5414 }
5415
5416 PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
5417 NewTL.setKWLoc(TL.getKWLoc());
5418
5419 return Result;
5420}
5421
Chad Rosier1dcde962012-08-08 18:46:20 +00005422 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00005423 /// container that provides a \c getArgLoc() member function.
5424 ///
5425 /// This iterator is intended to be used with the iterator form of
5426 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5427 template<typename ArgLocContainer>
5428 class TemplateArgumentLocContainerIterator {
5429 ArgLocContainer *Container;
5430 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00005431
Douglas Gregorfe921a72010-12-20 23:36:19 +00005432 public:
5433 typedef TemplateArgumentLoc value_type;
5434 typedef TemplateArgumentLoc reference;
5435 typedef int difference_type;
5436 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00005437
Douglas Gregorfe921a72010-12-20 23:36:19 +00005438 class pointer {
5439 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00005440
Douglas Gregorfe921a72010-12-20 23:36:19 +00005441 public:
5442 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005443
Douglas Gregorfe921a72010-12-20 23:36:19 +00005444 const TemplateArgumentLoc *operator->() const {
5445 return &Arg;
5446 }
5447 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005448
5449
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00005450 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00005451
Douglas Gregorfe921a72010-12-20 23:36:19 +00005452 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5453 unsigned Index)
5454 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005455
Douglas Gregorfe921a72010-12-20 23:36:19 +00005456 TemplateArgumentLocContainerIterator &operator++() {
5457 ++Index;
5458 return *this;
5459 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005460
Douglas Gregorfe921a72010-12-20 23:36:19 +00005461 TemplateArgumentLocContainerIterator operator++(int) {
5462 TemplateArgumentLocContainerIterator Old(*this);
5463 ++(*this);
5464 return Old;
5465 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005466
Douglas Gregorfe921a72010-12-20 23:36:19 +00005467 TemplateArgumentLoc operator*() const {
5468 return Container->getArgLoc(Index);
5469 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005470
Douglas Gregorfe921a72010-12-20 23:36:19 +00005471 pointer operator->() const {
5472 return pointer(Container->getArgLoc(Index));
5473 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005474
Douglas Gregorfe921a72010-12-20 23:36:19 +00005475 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005476 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005477 return X.Container == Y.Container && X.Index == Y.Index;
5478 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005479
Douglas Gregorfe921a72010-12-20 23:36:19 +00005480 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005481 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005482 return !(X == Y);
5483 }
5484 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005485
5486
John McCall31f82722010-11-12 08:19:04 +00005487template <typename Derived>
5488QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5489 TypeLocBuilder &TLB,
5490 TemplateSpecializationTypeLoc TL,
5491 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005492 TemplateArgumentListInfo NewTemplateArgs;
5493 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5494 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005495 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5496 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005497 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005498 ArgIterator(TL, TL.getNumArgs()),
5499 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005500 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005501
John McCall0ad16662009-10-29 08:12:44 +00005502 // FIXME: maybe don't rebuild if all the template arguments are the same.
5503
5504 QualType Result =
5505 getDerived().RebuildTemplateSpecializationType(Template,
5506 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005507 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005508
5509 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005510 // Specializations of template template parameters are represented as
5511 // TemplateSpecializationTypes, and substitution of type alias templates
5512 // within a dependent context can transform them into
5513 // DependentTemplateSpecializationTypes.
5514 if (isa<DependentTemplateSpecializationType>(Result)) {
5515 DependentTemplateSpecializationTypeLoc NewTL
5516 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005517 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005518 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005519 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005520 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005521 NewTL.setLAngleLoc(TL.getLAngleLoc());
5522 NewTL.setRAngleLoc(TL.getRAngleLoc());
5523 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5524 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5525 return Result;
5526 }
5527
John McCall0ad16662009-10-29 08:12:44 +00005528 TemplateSpecializationTypeLoc NewTL
5529 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005530 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005531 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5532 NewTL.setLAngleLoc(TL.getLAngleLoc());
5533 NewTL.setRAngleLoc(TL.getRAngleLoc());
5534 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5535 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005536 }
Mike Stump11289f42009-09-09 15:08:12 +00005537
John McCall0ad16662009-10-29 08:12:44 +00005538 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005539}
Mike Stump11289f42009-09-09 15:08:12 +00005540
Douglas Gregor5a064722011-02-28 17:23:35 +00005541template <typename Derived>
5542QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5543 TypeLocBuilder &TLB,
5544 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005545 TemplateName Template,
5546 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005547 TemplateArgumentListInfo NewTemplateArgs;
5548 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5549 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5550 typedef TemplateArgumentLocContainerIterator<
5551 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005552 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005553 ArgIterator(TL, TL.getNumArgs()),
5554 NewTemplateArgs))
5555 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005556
Douglas Gregor5a064722011-02-28 17:23:35 +00005557 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005558
Douglas Gregor5a064722011-02-28 17:23:35 +00005559 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5560 QualType Result
5561 = getSema().Context.getDependentTemplateSpecializationType(
5562 TL.getTypePtr()->getKeyword(),
5563 DTN->getQualifier(),
5564 DTN->getIdentifier(),
5565 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005566
Douglas Gregor5a064722011-02-28 17:23:35 +00005567 DependentTemplateSpecializationTypeLoc NewTL
5568 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005569 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005570 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005571 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005572 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005573 NewTL.setLAngleLoc(TL.getLAngleLoc());
5574 NewTL.setRAngleLoc(TL.getRAngleLoc());
5575 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5576 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5577 return Result;
5578 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005579
5580 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005581 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005582 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005583 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005584
Douglas Gregor5a064722011-02-28 17:23:35 +00005585 if (!Result.isNull()) {
5586 /// FIXME: Wrap this in an elaborated-type-specifier?
5587 TemplateSpecializationTypeLoc NewTL
5588 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005589 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005590 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005591 NewTL.setLAngleLoc(TL.getLAngleLoc());
5592 NewTL.setRAngleLoc(TL.getRAngleLoc());
5593 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5594 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5595 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005596
Douglas Gregor5a064722011-02-28 17:23:35 +00005597 return Result;
5598}
5599
Mike Stump11289f42009-09-09 15:08:12 +00005600template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005601QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005602TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005603 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005604 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005605
Douglas Gregor844cb502011-03-01 18:12:44 +00005606 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005607 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005608 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005609 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005610 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5611 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005612 return QualType();
5613 }
Mike Stump11289f42009-09-09 15:08:12 +00005614
John McCall31f82722010-11-12 08:19:04 +00005615 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5616 if (NamedT.isNull())
5617 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005618
Richard Smith3f1b5d02011-05-05 21:57:07 +00005619 // C++0x [dcl.type.elab]p2:
5620 // If the identifier resolves to a typedef-name or the simple-template-id
5621 // resolves to an alias template specialization, the
5622 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005623 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5624 if (const TemplateSpecializationType *TST =
5625 NamedT->getAs<TemplateSpecializationType>()) {
5626 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00005627 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5628 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00005629 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5630 diag::err_tag_reference_non_tag) << 4;
5631 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5632 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005633 }
5634 }
5635
John McCall550e0c22009-10-21 00:40:46 +00005636 QualType Result = TL.getType();
5637 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005638 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005639 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005640 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005641 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005642 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005643 if (Result.isNull())
5644 return QualType();
5645 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005646
Abramo Bagnara6150c882010-05-11 21:36:43 +00005647 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005648 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005649 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005650 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005651}
Mike Stump11289f42009-09-09 15:08:12 +00005652
5653template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005654QualType TreeTransform<Derived>::TransformAttributedType(
5655 TypeLocBuilder &TLB,
5656 AttributedTypeLoc TL) {
5657 const AttributedType *oldType = TL.getTypePtr();
5658 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5659 if (modifiedType.isNull())
5660 return QualType();
5661
5662 QualType result = TL.getType();
5663
5664 // FIXME: dependent operand expressions?
5665 if (getDerived().AlwaysRebuild() ||
5666 modifiedType != oldType->getModifiedType()) {
5667 // TODO: this is really lame; we should really be rebuilding the
5668 // equivalent type from first principles.
5669 QualType equivalentType
5670 = getDerived().TransformType(oldType->getEquivalentType());
5671 if (equivalentType.isNull())
5672 return QualType();
Douglas Gregor261a89b2015-06-19 17:51:05 +00005673
5674 // Check whether we can add nullability; it is only represented as
5675 // type sugar, and therefore cannot be diagnosed in any other way.
5676 if (auto nullability = oldType->getImmediateNullability()) {
5677 if (!modifiedType->canHaveNullability()) {
5678 SemaRef.Diag(TL.getAttrNameLoc(), diag::err_nullability_nonpointer)
Douglas Gregoraea7afd2015-06-24 22:02:08 +00005679 << DiagNullabilityKind(*nullability, false) << modifiedType;
Douglas Gregor261a89b2015-06-19 17:51:05 +00005680 return QualType();
5681 }
5682 }
5683
John McCall81904512011-01-06 01:58:22 +00005684 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5685 modifiedType,
5686 equivalentType);
5687 }
5688
5689 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5690 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5691 if (TL.hasAttrOperand())
5692 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5693 if (TL.hasAttrExprOperand())
5694 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5695 else if (TL.hasAttrEnumOperand())
5696 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5697
5698 return result;
5699}
5700
5701template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005702QualType
5703TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5704 ParenTypeLoc TL) {
5705 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5706 if (Inner.isNull())
5707 return QualType();
5708
5709 QualType Result = TL.getType();
5710 if (getDerived().AlwaysRebuild() ||
5711 Inner != TL.getInnerLoc().getType()) {
5712 Result = getDerived().RebuildParenType(Inner);
5713 if (Result.isNull())
5714 return QualType();
5715 }
5716
5717 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5718 NewTL.setLParenLoc(TL.getLParenLoc());
5719 NewTL.setRParenLoc(TL.getRParenLoc());
5720 return Result;
5721}
5722
5723template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005724QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005725 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005726 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005727
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005728 NestedNameSpecifierLoc QualifierLoc
5729 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5730 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005731 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005732
John McCallc392f372010-06-11 00:33:02 +00005733 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005734 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005735 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005736 QualifierLoc,
5737 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005738 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005739 if (Result.isNull())
5740 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005741
Abramo Bagnarad7548482010-05-19 21:37:53 +00005742 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5743 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005744 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5745
Abramo Bagnarad7548482010-05-19 21:37:53 +00005746 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005747 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005748 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005749 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005750 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005751 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005752 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005753 NewTL.setNameLoc(TL.getNameLoc());
5754 }
John McCall550e0c22009-10-21 00:40:46 +00005755 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005756}
Mike Stump11289f42009-09-09 15:08:12 +00005757
Douglas Gregord6ff3322009-08-04 16:50:30 +00005758template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005759QualType TreeTransform<Derived>::
5760 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005761 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005762 NestedNameSpecifierLoc QualifierLoc;
5763 if (TL.getQualifierLoc()) {
5764 QualifierLoc
5765 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5766 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005767 return QualType();
5768 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005769
John McCall31f82722010-11-12 08:19:04 +00005770 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005771 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005772}
5773
5774template<typename Derived>
5775QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005776TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5777 DependentTemplateSpecializationTypeLoc TL,
5778 NestedNameSpecifierLoc QualifierLoc) {
5779 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005780
Douglas Gregora7a795b2011-03-01 20:11:18 +00005781 TemplateArgumentListInfo NewTemplateArgs;
5782 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5783 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005784
Douglas Gregora7a795b2011-03-01 20:11:18 +00005785 typedef TemplateArgumentLocContainerIterator<
5786 DependentTemplateSpecializationTypeLoc> ArgIterator;
5787 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5788 ArgIterator(TL, TL.getNumArgs()),
5789 NewTemplateArgs))
5790 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005791
Douglas Gregora7a795b2011-03-01 20:11:18 +00005792 QualType Result
5793 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5794 QualifierLoc,
5795 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005796 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005797 NewTemplateArgs);
5798 if (Result.isNull())
5799 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005800
Douglas Gregora7a795b2011-03-01 20:11:18 +00005801 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5802 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005803
Douglas Gregora7a795b2011-03-01 20:11:18 +00005804 // Copy information relevant to the template specialization.
5805 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005806 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005807 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005808 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005809 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5810 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005811 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005812 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005813
Douglas Gregora7a795b2011-03-01 20:11:18 +00005814 // Copy information relevant to the elaborated type.
5815 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005816 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005817 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005818 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5819 DependentTemplateSpecializationTypeLoc SpecTL
5820 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005821 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005822 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005823 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005824 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005825 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5826 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005827 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005828 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005829 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005830 TemplateSpecializationTypeLoc SpecTL
5831 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005832 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005833 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005834 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5835 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005836 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005837 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005838 }
5839 return Result;
5840}
5841
5842template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005843QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5844 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005845 QualType Pattern
5846 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005847 if (Pattern.isNull())
5848 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005849
5850 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005851 if (getDerived().AlwaysRebuild() ||
5852 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005853 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005854 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005855 TL.getEllipsisLoc(),
5856 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005857 if (Result.isNull())
5858 return QualType();
5859 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005860
Douglas Gregor822d0302011-01-12 17:07:58 +00005861 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5862 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5863 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005864}
5865
5866template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005867QualType
5868TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005869 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005870 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005871 TLB.pushFullCopy(TL);
5872 return TL.getType();
5873}
5874
5875template<typename Derived>
5876QualType
5877TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005878 ObjCObjectTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00005879 // Transform base type.
5880 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
5881 if (BaseType.isNull())
5882 return QualType();
5883
5884 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
5885
5886 // Transform type arguments.
5887 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
5888 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
5889 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
5890 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
5891 QualType TypeArg = TypeArgInfo->getType();
5892 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
5893 AnyChanged = true;
5894
5895 // We have a pack expansion. Instantiate it.
5896 const auto *PackExpansion = PackExpansionLoc.getType()
5897 ->castAs<PackExpansionType>();
5898 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5899 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5900 Unexpanded);
5901 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5902
5903 // Determine whether the set of unexpanded parameter packs can
5904 // and should be expanded.
5905 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
5906 bool Expand = false;
5907 bool RetainExpansion = false;
5908 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5909 if (getDerived().TryExpandParameterPacks(
5910 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
5911 Unexpanded, Expand, RetainExpansion, NumExpansions))
5912 return QualType();
5913
5914 if (!Expand) {
5915 // We can't expand this pack expansion into separate arguments yet;
5916 // just substitute into the pattern and create a new pack expansion
5917 // type.
5918 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5919
5920 TypeLocBuilder TypeArgBuilder;
5921 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
5922 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
5923 PatternLoc);
5924 if (NewPatternType.isNull())
5925 return QualType();
5926
5927 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
5928 NewPatternType, NumExpansions);
5929 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
5930 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
5931 NewTypeArgInfos.push_back(
5932 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
5933 continue;
5934 }
5935
5936 // Substitute into the pack expansion pattern for each slice of the
5937 // pack.
5938 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5939 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5940
5941 TypeLocBuilder TypeArgBuilder;
5942 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
5943
5944 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
5945 PatternLoc);
5946 if (NewTypeArg.isNull())
5947 return QualType();
5948
5949 NewTypeArgInfos.push_back(
5950 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
5951 }
5952
5953 continue;
5954 }
5955
5956 TypeLocBuilder TypeArgBuilder;
5957 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
5958 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
5959 if (NewTypeArg.isNull())
5960 return QualType();
5961
5962 // If nothing changed, just keep the old TypeSourceInfo.
5963 if (NewTypeArg == TypeArg) {
5964 NewTypeArgInfos.push_back(TypeArgInfo);
5965 continue;
5966 }
5967
5968 NewTypeArgInfos.push_back(
5969 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
5970 AnyChanged = true;
5971 }
5972
5973 QualType Result = TL.getType();
5974 if (getDerived().AlwaysRebuild() || AnyChanged) {
5975 // Rebuild the type.
5976 Result = getDerived().RebuildObjCObjectType(
5977 BaseType,
5978 TL.getLocStart(),
5979 TL.getTypeArgsLAngleLoc(),
5980 NewTypeArgInfos,
5981 TL.getTypeArgsRAngleLoc(),
5982 TL.getProtocolLAngleLoc(),
5983 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
5984 TL.getNumProtocols()),
5985 TL.getProtocolLocs(),
5986 TL.getProtocolRAngleLoc());
5987
5988 if (Result.isNull())
5989 return QualType();
5990 }
5991
5992 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00005993 NewT.setHasBaseTypeAsWritten(true);
5994 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
5995 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
5996 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
5997 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
5998 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
5999 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
6000 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
6001 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
6002 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006003}
Mike Stump11289f42009-09-09 15:08:12 +00006004
6005template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006006QualType
6007TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006008 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006009 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
6010 if (PointeeType.isNull())
6011 return QualType();
6012
6013 QualType Result = TL.getType();
6014 if (getDerived().AlwaysRebuild() ||
6015 PointeeType != TL.getPointeeLoc().getType()) {
6016 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
6017 TL.getStarLoc());
6018 if (Result.isNull())
6019 return QualType();
6020 }
6021
6022 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
6023 NewT.setStarLoc(TL.getStarLoc());
6024 return Result;
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00006025}
6026
Douglas Gregord6ff3322009-08-04 16:50:30 +00006027//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00006028// Statement transformation
6029//===----------------------------------------------------------------------===//
6030template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006031StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006032TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006033 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006034}
6035
6036template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006037StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006038TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
6039 return getDerived().TransformCompoundStmt(S, false);
6040}
6041
6042template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006043StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006044TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00006045 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00006046 Sema::CompoundScopeRAII CompoundScope(getSema());
6047
John McCall1ababa62010-08-27 19:56:05 +00006048 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00006049 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006050 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006051 for (auto *B : S->body()) {
6052 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00006053 if (Result.isInvalid()) {
6054 // Immediately fail if this was a DeclStmt, since it's very
6055 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006056 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00006057 return StmtError();
6058
6059 // Otherwise, just keep processing substatements and fail later.
6060 SubStmtInvalid = true;
6061 continue;
6062 }
Mike Stump11289f42009-09-09 15:08:12 +00006063
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006064 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006065 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006066 }
Mike Stump11289f42009-09-09 15:08:12 +00006067
John McCall1ababa62010-08-27 19:56:05 +00006068 if (SubStmtInvalid)
6069 return StmtError();
6070
Douglas Gregorebe10102009-08-20 07:17:43 +00006071 if (!getDerived().AlwaysRebuild() &&
6072 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006073 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006074
6075 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006076 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00006077 S->getRBracLoc(),
6078 IsStmtExpr);
6079}
Mike Stump11289f42009-09-09 15:08:12 +00006080
Douglas Gregorebe10102009-08-20 07:17:43 +00006081template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006082StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006083TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006084 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00006085 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00006086 EnterExpressionEvaluationContext Unevaluated(SemaRef,
6087 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006088
Eli Friedman06577382009-11-19 03:14:00 +00006089 // Transform the left-hand case value.
6090 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00006091 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00006092 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006093 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006094
Eli Friedman06577382009-11-19 03:14:00 +00006095 // Transform the right-hand case value (for the GNU case-range extension).
6096 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00006097 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00006098 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006099 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00006100 }
Mike Stump11289f42009-09-09 15:08:12 +00006101
Douglas Gregorebe10102009-08-20 07:17:43 +00006102 // Build the case statement.
6103 // Case statements are always rebuilt so that they will attached to their
6104 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006105 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00006106 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006107 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00006108 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006109 S->getColonLoc());
6110 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006111 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006112
Douglas Gregorebe10102009-08-20 07:17:43 +00006113 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00006114 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006115 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006116 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006117
Douglas Gregorebe10102009-08-20 07:17:43 +00006118 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00006119 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006120}
6121
6122template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006123StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006124TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006125 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00006126 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006127 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006128 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006129
Douglas Gregorebe10102009-08-20 07:17:43 +00006130 // Default statements are always rebuilt
6131 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006132 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006133}
Mike Stump11289f42009-09-09 15:08:12 +00006134
Douglas Gregorebe10102009-08-20 07:17:43 +00006135template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006136StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006137TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006138 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006139 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006140 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006141
Chris Lattnercab02a62011-02-17 20:34:02 +00006142 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
6143 S->getDecl());
6144 if (!LD)
6145 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00006146
6147
Douglas Gregorebe10102009-08-20 07:17:43 +00006148 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00006149 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006150 cast<LabelDecl>(LD), SourceLocation(),
6151 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006152}
Mike Stump11289f42009-09-09 15:08:12 +00006153
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006154template <typename Derived>
6155const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
6156 if (!R)
6157 return R;
6158
6159 switch (R->getKind()) {
6160// Transform attributes with a pragma spelling by calling TransformXXXAttr.
6161#define ATTR(X)
6162#define PRAGMA_SPELLING_ATTR(X) \
6163 case attr::X: \
6164 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
6165#include "clang/Basic/AttrList.inc"
6166 default:
6167 return R;
6168 }
6169}
6170
6171template <typename Derived>
6172StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
6173 bool AttrsChanged = false;
6174 SmallVector<const Attr *, 1> Attrs;
6175
6176 // Visit attributes and keep track if any are transformed.
6177 for (const auto *I : S->getAttrs()) {
6178 const Attr *R = getDerived().TransformAttr(I);
6179 AttrsChanged |= (I != R);
6180 Attrs.push_back(R);
6181 }
6182
Richard Smithc202b282012-04-14 00:33:13 +00006183 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6184 if (SubStmt.isInvalid())
6185 return StmtError();
6186
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006187 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
Richard Smithc202b282012-04-14 00:33:13 +00006188 return S;
6189
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006190 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00006191 SubStmt.get());
6192}
6193
6194template<typename Derived>
6195StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006196TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006197 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006198 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006199 VarDecl *ConditionVar = nullptr;
Douglas Gregor633caca2009-11-23 23:44:04 +00006200 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006201 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00006202 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006203 getDerived().TransformDefinition(
6204 S->getConditionVariable()->getLocation(),
6205 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00006206 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006207 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006208 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00006209 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006210
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006211 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006212 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006213
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006214 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00006215 if (S->getCond()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006216 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00006217 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00006218 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006219 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006220
John McCallb268a282010-08-23 23:25:46 +00006221 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006222 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006223 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006224
Richard Trieu43b4c822016-01-06 21:11:18 +00006225 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get(), S->getIfLoc()));
John McCallb268a282010-08-23 23:25:46 +00006226 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006227 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006228
Douglas Gregorebe10102009-08-20 07:17:43 +00006229 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00006230 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00006231 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006232 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006233
Douglas Gregorebe10102009-08-20 07:17:43 +00006234 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00006235 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00006236 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006237 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006238
Douglas Gregorebe10102009-08-20 07:17:43 +00006239 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00006240 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006241 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006242 Then.get() == S->getThen() &&
6243 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006244 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006245
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006246 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00006247 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00006248 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006249}
6250
6251template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006252StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006253TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006254 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00006255 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006256 VarDecl *ConditionVar = nullptr;
Douglas Gregordcf19622009-11-24 17:07:59 +00006257 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006258 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00006259 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006260 getDerived().TransformDefinition(
6261 S->getConditionVariable()->getLocation(),
6262 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00006263 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006264 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006265 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00006266 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006267
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006268 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006269 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006270 }
Mike Stump11289f42009-09-09 15:08:12 +00006271
Douglas Gregorebe10102009-08-20 07:17:43 +00006272 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006273 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00006274 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00006275 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00006276 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006277 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006278
Douglas Gregorebe10102009-08-20 07:17:43 +00006279 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006280 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006281 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006282 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006283
Douglas Gregorebe10102009-08-20 07:17:43 +00006284 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00006285 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
6286 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006287}
Mike Stump11289f42009-09-09 15:08:12 +00006288
Douglas Gregorebe10102009-08-20 07:17:43 +00006289template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006290StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006291TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006292 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006293 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006294 VarDecl *ConditionVar = nullptr;
Douglas Gregor680f8612009-11-24 21:15:44 +00006295 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006296 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00006297 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006298 getDerived().TransformDefinition(
6299 S->getConditionVariable()->getLocation(),
6300 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00006301 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006302 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006303 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00006304 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006305
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006306 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006307 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006308
6309 if (S->getCond()) {
6310 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00006311 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
6312 S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00006313 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00006314 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006315 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00006316 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00006317 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006318 }
Mike Stump11289f42009-09-09 15:08:12 +00006319
Richard Trieu43b4c822016-01-06 21:11:18 +00006320 Sema::FullExprArg FullCond(
6321 getSema().MakeFullExpr(Cond.get(), S->getWhileLoc()));
John McCallb268a282010-08-23 23:25:46 +00006322 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006323 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006324
Douglas Gregorebe10102009-08-20 07:17:43 +00006325 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006326 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006327 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006328 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006329
Douglas Gregorebe10102009-08-20 07:17:43 +00006330 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00006331 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006332 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006333 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00006334 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00006335
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006336 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00006337 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006338}
Mike Stump11289f42009-09-09 15:08:12 +00006339
Douglas Gregorebe10102009-08-20 07:17:43 +00006340template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006341StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006342TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006343 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006344 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006345 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006346 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006347
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006348 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006349 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006350 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006351 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006352
Douglas Gregorebe10102009-08-20 07:17:43 +00006353 if (!getDerived().AlwaysRebuild() &&
6354 Cond.get() == S->getCond() &&
6355 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006356 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006357
John McCallb268a282010-08-23 23:25:46 +00006358 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
6359 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006360 S->getRParenLoc());
6361}
Mike Stump11289f42009-09-09 15:08:12 +00006362
Douglas Gregorebe10102009-08-20 07:17:43 +00006363template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006364StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006365TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006366 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00006367 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00006368 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006369 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006370
Alexey Bataeva636c7f2015-12-23 10:27:45 +00006371 // In OpenMP loop region loop control variable must be captured and be
6372 // private. Perform analysis of first part (if any).
6373 if (getSema().getLangOpts().OpenMP && Init.isUsable())
6374 getSema().ActOnOpenMPLoopInitialization(S->getForLoc(), Init.get());
6375
Douglas Gregorebe10102009-08-20 07:17:43 +00006376 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006377 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006378 VarDecl *ConditionVar = nullptr;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006379 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006380 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006381 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006382 getDerived().TransformDefinition(
6383 S->getConditionVariable()->getLocation(),
6384 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006385 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006386 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006387 } else {
6388 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006389
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006390 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006391 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006392
6393 if (S->getCond()) {
6394 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00006395 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
6396 S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00006397 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00006398 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006399 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006400
John McCallb268a282010-08-23 23:25:46 +00006401 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006402 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006403 }
Mike Stump11289f42009-09-09 15:08:12 +00006404
Richard Trieu43b4c822016-01-06 21:11:18 +00006405 Sema::FullExprArg FullCond(
6406 getSema().MakeFullExpr(Cond.get(), S->getForLoc()));
John McCallb268a282010-08-23 23:25:46 +00006407 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006408 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006409
Douglas Gregorebe10102009-08-20 07:17:43 +00006410 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00006411 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006412 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006413 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006414
Richard Smith945f8d32013-01-14 22:39:08 +00006415 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00006416 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006417 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006418
Douglas Gregorebe10102009-08-20 07:17:43 +00006419 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006420 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006421 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006422 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006423
Douglas Gregorebe10102009-08-20 07:17:43 +00006424 if (!getDerived().AlwaysRebuild() &&
6425 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00006426 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006427 Inc.get() == S->getInc() &&
6428 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006429 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006430
Douglas Gregorebe10102009-08-20 07:17:43 +00006431 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006432 Init.get(), FullCond, ConditionVar,
6433 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006434}
6435
6436template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006437StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006438TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006439 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6440 S->getLabel());
6441 if (!LD)
6442 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006443
Douglas Gregorebe10102009-08-20 07:17:43 +00006444 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00006445 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006446 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00006447}
6448
6449template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006450StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006451TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006452 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00006453 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006454 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006455 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00006456
Douglas Gregorebe10102009-08-20 07:17:43 +00006457 if (!getDerived().AlwaysRebuild() &&
6458 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006459 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006460
6461 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00006462 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006463}
6464
6465template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006466StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006467TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006468 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006469}
Mike Stump11289f42009-09-09 15:08:12 +00006470
Douglas Gregorebe10102009-08-20 07:17:43 +00006471template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006472StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006473TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006474 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006475}
Mike Stump11289f42009-09-09 15:08:12 +00006476
Douglas Gregorebe10102009-08-20 07:17:43 +00006477template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006478StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006479TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00006480 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6481 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00006482 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006483 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006484
Mike Stump11289f42009-09-09 15:08:12 +00006485 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00006486 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00006487 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006488}
Mike Stump11289f42009-09-09 15:08:12 +00006489
Douglas Gregorebe10102009-08-20 07:17:43 +00006490template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006491StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006492TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006493 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006494 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006495 for (auto *D : S->decls()) {
6496 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00006497 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00006498 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006499
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006500 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00006501 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00006502
Douglas Gregorebe10102009-08-20 07:17:43 +00006503 Decls.push_back(Transformed);
6504 }
Mike Stump11289f42009-09-09 15:08:12 +00006505
Douglas Gregorebe10102009-08-20 07:17:43 +00006506 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006507 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006508
Rafael Espindolaab417692013-07-09 12:05:01 +00006509 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006510}
Mike Stump11289f42009-09-09 15:08:12 +00006511
Douglas Gregorebe10102009-08-20 07:17:43 +00006512template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006513StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00006514TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006515
Benjamin Kramerf0623432012-08-23 22:51:59 +00006516 SmallVector<Expr*, 8> Constraints;
6517 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006518 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00006519
John McCalldadc5752010-08-24 06:29:42 +00006520 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006521 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006522
6523 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00006524
Anders Carlssonaaeef072010-01-24 05:50:09 +00006525 // Go through the outputs.
6526 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006527 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006528
Anders Carlssonaaeef072010-01-24 05:50:09 +00006529 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006530 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006531
Anders Carlssonaaeef072010-01-24 05:50:09 +00006532 // Transform the output expr.
6533 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006534 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006535 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006536 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006537
Anders Carlssonaaeef072010-01-24 05:50:09 +00006538 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006539
John McCallb268a282010-08-23 23:25:46 +00006540 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006541 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006542
Anders Carlssonaaeef072010-01-24 05:50:09 +00006543 // Go through the inputs.
6544 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006545 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006546
Anders Carlssonaaeef072010-01-24 05:50:09 +00006547 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006548 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006549
Anders Carlssonaaeef072010-01-24 05:50:09 +00006550 // Transform the input expr.
6551 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006552 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006553 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006554 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006555
Anders Carlssonaaeef072010-01-24 05:50:09 +00006556 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006557
John McCallb268a282010-08-23 23:25:46 +00006558 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006559 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006560
Anders Carlssonaaeef072010-01-24 05:50:09 +00006561 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006562 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006563
6564 // Go through the clobbers.
6565 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00006566 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00006567
6568 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006569 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00006570 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
6571 S->isVolatile(), S->getNumOutputs(),
6572 S->getNumInputs(), Names.data(),
6573 Constraints, Exprs, AsmString.get(),
6574 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006575}
6576
Chad Rosier32503022012-06-11 20:47:18 +00006577template<typename Derived>
6578StmtResult
6579TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00006580 ArrayRef<Token> AsmToks =
6581 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00006582
John McCallf413f5e2013-05-03 00:10:13 +00006583 bool HadError = false, HadChange = false;
6584
6585 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6586 SmallVector<Expr*, 8> TransformedExprs;
6587 TransformedExprs.reserve(SrcExprs.size());
6588 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6589 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
6590 if (!Result.isUsable()) {
6591 HadError = true;
6592 } else {
6593 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006594 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00006595 }
6596 }
6597
6598 if (HadError) return StmtError();
6599 if (!HadChange && !getDerived().AlwaysRebuild())
6600 return Owned(S);
6601
Chad Rosierb6f46c12012-08-15 16:53:30 +00006602 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00006603 AsmToks, S->getAsmString(),
6604 S->getNumOutputs(), S->getNumInputs(),
6605 S->getAllConstraints(), S->getClobbers(),
6606 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00006607}
Douglas Gregorebe10102009-08-20 07:17:43 +00006608
Richard Smith9f690bd2015-10-27 06:02:45 +00006609// C++ Coroutines TS
6610
6611template<typename Derived>
6612StmtResult
6613TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) {
6614 // The coroutine body should be re-formed by the caller if necessary.
6615 return getDerived().TransformStmt(S->getBody());
6616}
6617
6618template<typename Derived>
6619StmtResult
6620TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
6621 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
6622 /*NotCopyInit*/false);
6623 if (Result.isInvalid())
6624 return StmtError();
6625
6626 // Always rebuild; we don't know if this needs to be injected into a new
6627 // context or if the promise type has changed.
6628 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get());
6629}
6630
6631template<typename Derived>
6632ExprResult
6633TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) {
6634 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
6635 /*NotCopyInit*/false);
6636 if (Result.isInvalid())
6637 return ExprError();
6638
6639 // Always rebuild; we don't know if this needs to be injected into a new
6640 // context or if the promise type has changed.
6641 return getDerived().RebuildCoawaitExpr(E->getKeywordLoc(), Result.get());
6642}
6643
6644template<typename Derived>
6645ExprResult
6646TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) {
6647 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
6648 /*NotCopyInit*/false);
6649 if (Result.isInvalid())
6650 return ExprError();
6651
6652 // Always rebuild; we don't know if this needs to be injected into a new
6653 // context or if the promise type has changed.
6654 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
6655}
6656
6657// Objective-C Statements.
6658
Douglas Gregorebe10102009-08-20 07:17:43 +00006659template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006660StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006661TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006662 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00006663 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006664 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006665 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006666
Douglas Gregor96c79492010-04-23 22:50:49 +00006667 // Transform the @catch statements (if present).
6668 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006669 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00006670 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006671 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00006672 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006673 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00006674 if (Catch.get() != S->getCatchStmt(I))
6675 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006676 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006677 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006678
Douglas Gregor306de2f2010-04-22 23:59:56 +00006679 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00006680 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006681 if (S->getFinallyStmt()) {
6682 Finally = getDerived().TransformStmt(S->getFinallyStmt());
6683 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006684 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00006685 }
6686
6687 // If nothing changed, just retain this statement.
6688 if (!getDerived().AlwaysRebuild() &&
6689 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00006690 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00006691 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006692 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006693
Douglas Gregor306de2f2010-04-22 23:59:56 +00006694 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00006695 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006696 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006697}
Mike Stump11289f42009-09-09 15:08:12 +00006698
Douglas Gregorebe10102009-08-20 07:17:43 +00006699template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006700StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006701TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006702 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00006703 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006704 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006705 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006706 if (FromVar->getTypeSourceInfo()) {
6707 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
6708 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006709 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006710 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006711
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006712 QualType T;
6713 if (TSInfo)
6714 T = TSInfo->getType();
6715 else {
6716 T = getDerived().TransformType(FromVar->getType());
6717 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00006718 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006719 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006720
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006721 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6722 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00006723 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006724 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006725
John McCalldadc5752010-08-24 06:29:42 +00006726 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006727 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006728 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006729
6730 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006731 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006732 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006733}
Mike Stump11289f42009-09-09 15:08:12 +00006734
Douglas Gregorebe10102009-08-20 07:17:43 +00006735template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006736StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006737TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006738 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006739 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006740 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006741 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006742
Douglas Gregor306de2f2010-04-22 23:59:56 +00006743 // If nothing changed, just retain this statement.
6744 if (!getDerived().AlwaysRebuild() &&
6745 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006746 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006747
6748 // Build a new statement.
6749 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00006750 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006751}
Mike Stump11289f42009-09-09 15:08:12 +00006752
Douglas Gregorebe10102009-08-20 07:17:43 +00006753template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006754StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006755TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006756 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00006757 if (S->getThrowExpr()) {
6758 Operand = getDerived().TransformExpr(S->getThrowExpr());
6759 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006760 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00006761 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006762
Douglas Gregor2900c162010-04-22 21:44:01 +00006763 if (!getDerived().AlwaysRebuild() &&
6764 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006765 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006766
John McCallb268a282010-08-23 23:25:46 +00006767 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006768}
Mike Stump11289f42009-09-09 15:08:12 +00006769
Douglas Gregorebe10102009-08-20 07:17:43 +00006770template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006771StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006772TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006773 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00006774 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00006775 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00006776 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006777 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00006778 Object =
6779 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6780 Object.get());
6781 if (Object.isInvalid())
6782 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006783
Douglas Gregor6148de72010-04-22 22:01:21 +00006784 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006785 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00006786 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006787 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006788
Douglas Gregor6148de72010-04-22 22:01:21 +00006789 // If nothing change, just retain the current statement.
6790 if (!getDerived().AlwaysRebuild() &&
6791 Object.get() == S->getSynchExpr() &&
6792 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006793 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00006794
6795 // Build a new statement.
6796 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00006797 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006798}
6799
6800template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006801StmtResult
John McCall31168b02011-06-15 23:02:42 +00006802TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6803 ObjCAutoreleasePoolStmt *S) {
6804 // Transform the body.
6805 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6806 if (Body.isInvalid())
6807 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006808
John McCall31168b02011-06-15 23:02:42 +00006809 // If nothing changed, just retain this statement.
6810 if (!getDerived().AlwaysRebuild() &&
6811 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006812 return S;
John McCall31168b02011-06-15 23:02:42 +00006813
6814 // Build a new statement.
6815 return getDerived().RebuildObjCAutoreleasePoolStmt(
6816 S->getAtLoc(), Body.get());
6817}
6818
6819template<typename Derived>
6820StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006821TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006822 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006823 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006824 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006825 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006826 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006827
Douglas Gregorf68a5082010-04-22 23:10:45 +00006828 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006829 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006830 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006831 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006832
Douglas Gregorf68a5082010-04-22 23:10:45 +00006833 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006834 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006835 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006836 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006837
Douglas Gregorf68a5082010-04-22 23:10:45 +00006838 // If nothing changed, just retain this statement.
6839 if (!getDerived().AlwaysRebuild() &&
6840 Element.get() == S->getElement() &&
6841 Collection.get() == S->getCollection() &&
6842 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006843 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006844
Douglas Gregorf68a5082010-04-22 23:10:45 +00006845 // Build a new statement.
6846 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006847 Element.get(),
6848 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006849 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006850 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006851}
6852
David Majnemer5f7efef2013-10-15 09:50:08 +00006853template <typename Derived>
6854StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006855 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006856 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006857 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6858 TypeSourceInfo *T =
6859 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006860 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006861 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006862
David Majnemer5f7efef2013-10-15 09:50:08 +00006863 Var = getDerived().RebuildExceptionDecl(
6864 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6865 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006866 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006867 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006868 }
Mike Stump11289f42009-09-09 15:08:12 +00006869
Douglas Gregorebe10102009-08-20 07:17:43 +00006870 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006871 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006872 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006873 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006874
David Majnemer5f7efef2013-10-15 09:50:08 +00006875 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006876 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006877 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006878
David Majnemer5f7efef2013-10-15 09:50:08 +00006879 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006880}
Mike Stump11289f42009-09-09 15:08:12 +00006881
David Majnemer5f7efef2013-10-15 09:50:08 +00006882template <typename Derived>
6883StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006884 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006885 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006886 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006887 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006888
Douglas Gregorebe10102009-08-20 07:17:43 +00006889 // Transform the handlers.
6890 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006891 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006892 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006893 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006894 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006895 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006896
Douglas Gregorebe10102009-08-20 07:17:43 +00006897 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006898 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006899 }
Mike Stump11289f42009-09-09 15:08:12 +00006900
David Majnemer5f7efef2013-10-15 09:50:08 +00006901 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006902 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006903 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006904
John McCallb268a282010-08-23 23:25:46 +00006905 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006906 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006907}
Mike Stump11289f42009-09-09 15:08:12 +00006908
Richard Smith02e85f32011-04-14 22:09:26 +00006909template<typename Derived>
6910StmtResult
6911TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6912 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6913 if (Range.isInvalid())
6914 return StmtError();
6915
Richard Smith01694c32016-03-20 10:33:40 +00006916 StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
6917 if (Begin.isInvalid())
6918 return StmtError();
6919 StmtResult End = getDerived().TransformStmt(S->getEndStmt());
6920 if (End.isInvalid())
Richard Smith02e85f32011-04-14 22:09:26 +00006921 return StmtError();
6922
6923 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6924 if (Cond.isInvalid())
6925 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006926 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006927 Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc());
Eli Friedman87d32802012-01-31 22:45:40 +00006928 if (Cond.isInvalid())
6929 return StmtError();
6930 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006931 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006932
6933 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6934 if (Inc.isInvalid())
6935 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006936 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006937 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006938
6939 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6940 if (LoopVar.isInvalid())
6941 return StmtError();
6942
6943 StmtResult NewStmt = S;
6944 if (getDerived().AlwaysRebuild() ||
6945 Range.get() != S->getRangeStmt() ||
Richard Smith01694c32016-03-20 10:33:40 +00006946 Begin.get() != S->getBeginStmt() ||
6947 End.get() != S->getEndStmt() ||
Richard Smith02e85f32011-04-14 22:09:26 +00006948 Cond.get() != S->getCond() ||
6949 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006950 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006951 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00006952 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00006953 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00006954 Begin.get(), End.get(),
6955 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00006956 Inc.get(), LoopVar.get(),
6957 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006958 if (NewStmt.isInvalid())
6959 return StmtError();
6960 }
Richard Smith02e85f32011-04-14 22:09:26 +00006961
6962 StmtResult Body = getDerived().TransformStmt(S->getBody());
6963 if (Body.isInvalid())
6964 return StmtError();
6965
6966 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6967 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006968 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006969 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00006970 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00006971 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00006972 Begin.get(), End.get(),
6973 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00006974 Inc.get(), LoopVar.get(),
6975 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006976 if (NewStmt.isInvalid())
6977 return StmtError();
6978 }
Richard Smith02e85f32011-04-14 22:09:26 +00006979
6980 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006981 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00006982
6983 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6984}
6985
John Wiegley1c0675e2011-04-28 01:08:34 +00006986template<typename Derived>
6987StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006988TreeTransform<Derived>::TransformMSDependentExistsStmt(
6989 MSDependentExistsStmt *S) {
6990 // Transform the nested-name-specifier, if any.
6991 NestedNameSpecifierLoc QualifierLoc;
6992 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006993 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006994 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6995 if (!QualifierLoc)
6996 return StmtError();
6997 }
6998
6999 // Transform the declaration name.
7000 DeclarationNameInfo NameInfo = S->getNameInfo();
7001 if (NameInfo.getName()) {
7002 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7003 if (!NameInfo.getName())
7004 return StmtError();
7005 }
7006
7007 // Check whether anything changed.
7008 if (!getDerived().AlwaysRebuild() &&
7009 QualifierLoc == S->getQualifierLoc() &&
7010 NameInfo.getName() == S->getNameInfo().getName())
7011 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007012
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007013 // Determine whether this name exists, if we can.
7014 CXXScopeSpec SS;
7015 SS.Adopt(QualifierLoc);
7016 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00007017 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007018 case Sema::IER_Exists:
7019 if (S->isIfExists())
7020 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007021
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007022 return new (getSema().Context) NullStmt(S->getKeywordLoc());
7023
7024 case Sema::IER_DoesNotExist:
7025 if (S->isIfNotExists())
7026 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007027
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007028 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00007029
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007030 case Sema::IER_Dependent:
7031 Dependent = true;
7032 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007033
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00007034 case Sema::IER_Error:
7035 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007036 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007037
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007038 // We need to continue with the instantiation, so do so now.
7039 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
7040 if (SubStmt.isInvalid())
7041 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007042
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007043 // If we have resolved the name, just transform to the substatement.
7044 if (!Dependent)
7045 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00007046
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007047 // The name is still dependent, so build a dependent expression again.
7048 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
7049 S->isIfExists(),
7050 QualifierLoc,
7051 NameInfo,
7052 SubStmt.get());
7053}
7054
7055template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00007056ExprResult
7057TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
7058 NestedNameSpecifierLoc QualifierLoc;
7059 if (E->getQualifierLoc()) {
7060 QualifierLoc
7061 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7062 if (!QualifierLoc)
7063 return ExprError();
7064 }
7065
7066 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
7067 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
7068 if (!PD)
7069 return ExprError();
7070
7071 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
7072 if (Base.isInvalid())
7073 return ExprError();
7074
7075 return new (SemaRef.getASTContext())
7076 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
7077 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
7078 QualifierLoc, E->getMemberLoc());
7079}
7080
David Majnemerfad8f482013-10-15 09:33:02 +00007081template <typename Derived>
Alexey Bataevf7630272015-11-25 12:01:00 +00007082ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr(
7083 MSPropertySubscriptExpr *E) {
7084 auto BaseRes = getDerived().TransformExpr(E->getBase());
7085 if (BaseRes.isInvalid())
7086 return ExprError();
7087 auto IdxRes = getDerived().TransformExpr(E->getIdx());
7088 if (IdxRes.isInvalid())
7089 return ExprError();
7090
7091 if (!getDerived().AlwaysRebuild() &&
7092 BaseRes.get() == E->getBase() &&
7093 IdxRes.get() == E->getIdx())
7094 return E;
7095
7096 return getDerived().RebuildArraySubscriptExpr(
7097 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
7098}
7099
7100template <typename Derived>
David Majnemerfad8f482013-10-15 09:33:02 +00007101StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007102 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007103 if (TryBlock.isInvalid())
7104 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007105
7106 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00007107 if (Handler.isInvalid())
7108 return StmtError();
7109
David Majnemerfad8f482013-10-15 09:33:02 +00007110 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
7111 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007112 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00007113
Warren Huntf6be4cb2014-07-25 20:52:51 +00007114 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
7115 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007116}
7117
David Majnemerfad8f482013-10-15 09:33:02 +00007118template <typename Derived>
7119StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007120 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007121 if (Block.isInvalid())
7122 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007123
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007124 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007125}
7126
David Majnemerfad8f482013-10-15 09:33:02 +00007127template <typename Derived>
7128StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00007129 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00007130 if (FilterExpr.isInvalid())
7131 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007132
David Majnemer7e755502013-10-15 09:30:14 +00007133 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007134 if (Block.isInvalid())
7135 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007136
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007137 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
7138 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007139}
7140
David Majnemerfad8f482013-10-15 09:33:02 +00007141template <typename Derived>
7142StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
7143 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00007144 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
7145 else
7146 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
7147}
7148
Nico Weber9b982072014-07-07 00:12:30 +00007149template<typename Derived>
7150StmtResult
7151TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
7152 return S;
7153}
7154
Alexander Musman64d33f12014-06-04 07:53:32 +00007155//===----------------------------------------------------------------------===//
7156// OpenMP directive transformation
7157//===----------------------------------------------------------------------===//
7158template <typename Derived>
7159StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
7160 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007161
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007162 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00007163 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007164 ArrayRef<OMPClause *> Clauses = D->clauses();
7165 TClauses.reserve(Clauses.size());
7166 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
7167 I != E; ++I) {
7168 if (*I) {
Alexey Bataevaac108a2015-06-23 04:51:00 +00007169 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007170 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevaac108a2015-06-23 04:51:00 +00007171 getDerived().getSema().EndOpenMPClause();
Alexey Bataevc5e02582014-06-16 07:08:35 +00007172 if (Clause)
7173 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00007174 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00007175 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007176 }
7177 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007178 StmtResult AssociatedStmt;
Alexey Bataeveb482352015-12-18 05:05:56 +00007179 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00007180 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
7181 /*CurScope=*/nullptr);
7182 StmtResult Body;
7183 {
7184 Sema::CompoundScopeRAII CompoundScope(getSema());
7185 Body = getDerived().TransformStmt(
7186 cast<CapturedStmt>(D->getAssociatedStmt())->getCapturedStmt());
7187 }
7188 AssociatedStmt =
7189 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
Alexey Bataev68446b72014-07-18 07:47:19 +00007190 if (AssociatedStmt.isInvalid()) {
7191 return StmtError();
7192 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00007193 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007194 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007195 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00007196 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007197
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007198 // Transform directive name for 'omp critical' directive.
7199 DeclarationNameInfo DirName;
7200 if (D->getDirectiveKind() == OMPD_critical) {
7201 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
7202 DirName = getDerived().TransformDeclarationNameInfo(DirName);
7203 }
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007204 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
7205 if (D->getDirectiveKind() == OMPD_cancellation_point) {
7206 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
Alexey Bataev80909872015-07-02 11:25:17 +00007207 } else if (D->getDirectiveKind() == OMPD_cancel) {
7208 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007209 }
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007210
Alexander Musman64d33f12014-06-04 07:53:32 +00007211 return getDerived().RebuildOMPExecutableDirective(
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007212 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
7213 AssociatedStmt.get(), D->getLocStart(), D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007214}
7215
Alexander Musman64d33f12014-06-04 07:53:32 +00007216template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007217StmtResult
7218TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
7219 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007220 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
7221 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007222 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7223 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7224 return Res;
7225}
7226
Alexander Musman64d33f12014-06-04 07:53:32 +00007227template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007228StmtResult
7229TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
7230 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007231 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
7232 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007233 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7234 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007235 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007236}
7237
Alexey Bataevf29276e2014-06-18 04:14:57 +00007238template <typename Derived>
7239StmtResult
7240TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
7241 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007242 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
7243 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00007244 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7245 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7246 return Res;
7247}
7248
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007249template <typename Derived>
7250StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00007251TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
7252 DeclarationNameInfo DirName;
7253 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
7254 D->getLocStart());
7255 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7256 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7257 return Res;
7258}
7259
7260template <typename Derived>
7261StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007262TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
7263 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007264 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
7265 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007266 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7267 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7268 return Res;
7269}
7270
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007271template <typename Derived>
7272StmtResult
7273TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
7274 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007275 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
7276 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007277 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7278 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7279 return Res;
7280}
7281
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007282template <typename Derived>
7283StmtResult
7284TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
7285 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007286 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
7287 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007288 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7289 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7290 return Res;
7291}
7292
Alexey Bataev4acb8592014-07-07 13:01:15 +00007293template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00007294StmtResult
7295TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
7296 DeclarationNameInfo DirName;
7297 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
7298 D->getLocStart());
7299 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7300 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7301 return Res;
7302}
7303
7304template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007305StmtResult
7306TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
7307 getDerived().getSema().StartOpenMPDSABlock(
7308 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
7309 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7310 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7311 return Res;
7312}
7313
7314template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00007315StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
7316 OMPParallelForDirective *D) {
7317 DeclarationNameInfo DirName;
7318 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
7319 nullptr, D->getLocStart());
7320 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7321 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7322 return Res;
7323}
7324
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007325template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00007326StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
7327 OMPParallelForSimdDirective *D) {
7328 DeclarationNameInfo DirName;
7329 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
7330 nullptr, D->getLocStart());
7331 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7332 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7333 return Res;
7334}
7335
7336template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007337StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
7338 OMPParallelSectionsDirective *D) {
7339 DeclarationNameInfo DirName;
7340 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
7341 nullptr, D->getLocStart());
7342 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7343 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7344 return Res;
7345}
7346
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00007347template <typename Derived>
7348StmtResult
7349TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
7350 DeclarationNameInfo DirName;
7351 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
7352 D->getLocStart());
7353 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7354 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7355 return Res;
7356}
7357
Alexey Bataev68446b72014-07-18 07:47:19 +00007358template <typename Derived>
7359StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
7360 OMPTaskyieldDirective *D) {
7361 DeclarationNameInfo DirName;
7362 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
7363 D->getLocStart());
7364 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7365 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7366 return Res;
7367}
7368
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00007369template <typename Derived>
7370StmtResult
7371TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
7372 DeclarationNameInfo DirName;
7373 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
7374 D->getLocStart());
7375 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7376 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7377 return Res;
7378}
7379
Alexey Bataev2df347a2014-07-18 10:17:07 +00007380template <typename Derived>
7381StmtResult
7382TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
7383 DeclarationNameInfo DirName;
7384 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
7385 D->getLocStart());
7386 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7387 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7388 return Res;
7389}
7390
Alexey Bataev6125da92014-07-21 11:26:11 +00007391template <typename Derived>
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00007392StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
7393 OMPTaskgroupDirective *D) {
7394 DeclarationNameInfo DirName;
7395 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
7396 D->getLocStart());
7397 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7398 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7399 return Res;
7400}
7401
7402template <typename Derived>
Alexey Bataev6125da92014-07-21 11:26:11 +00007403StmtResult
7404TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
7405 DeclarationNameInfo DirName;
7406 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
7407 D->getLocStart());
7408 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7409 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7410 return Res;
7411}
7412
Alexey Bataev9fb6e642014-07-22 06:45:04 +00007413template <typename Derived>
7414StmtResult
7415TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
7416 DeclarationNameInfo DirName;
7417 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
7418 D->getLocStart());
7419 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7420 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7421 return Res;
7422}
7423
Alexey Bataev0162e452014-07-22 10:10:35 +00007424template <typename Derived>
7425StmtResult
7426TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
7427 DeclarationNameInfo DirName;
7428 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
7429 D->getLocStart());
7430 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7431 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7432 return Res;
7433}
7434
Alexey Bataev0bd520b2014-09-19 08:19:49 +00007435template <typename Derived>
7436StmtResult
7437TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
7438 DeclarationNameInfo DirName;
7439 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
7440 D->getLocStart());
7441 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7442 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7443 return Res;
7444}
7445
Alexey Bataev13314bf2014-10-09 04:18:56 +00007446template <typename Derived>
Michael Wong65f367f2015-07-21 13:44:28 +00007447StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
7448 OMPTargetDataDirective *D) {
7449 DeclarationNameInfo DirName;
7450 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
7451 D->getLocStart());
7452 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7453 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7454 return Res;
7455}
7456
7457template <typename Derived>
Samuel Antaodf67fc42016-01-19 19:15:56 +00007458StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective(
7459 OMPTargetEnterDataDirective *D) {
7460 DeclarationNameInfo DirName;
7461 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_enter_data, DirName,
7462 nullptr, D->getLocStart());
7463 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7464 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7465 return Res;
7466}
7467
7468template <typename Derived>
Samuel Antao72590762016-01-19 20:04:50 +00007469StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective(
7470 OMPTargetExitDataDirective *D) {
7471 DeclarationNameInfo DirName;
7472 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_exit_data, DirName,
7473 nullptr, D->getLocStart());
7474 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7475 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7476 return Res;
7477}
7478
7479template <typename Derived>
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +00007480StmtResult TreeTransform<Derived>::TransformOMPTargetParallelDirective(
7481 OMPTargetParallelDirective *D) {
7482 DeclarationNameInfo DirName;
7483 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel, DirName,
7484 nullptr, D->getLocStart());
7485 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7486 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7487 return Res;
7488}
7489
7490template <typename Derived>
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +00007491StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForDirective(
7492 OMPTargetParallelForDirective *D) {
7493 DeclarationNameInfo DirName;
7494 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for, DirName,
7495 nullptr, D->getLocStart());
7496 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7497 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7498 return Res;
7499}
7500
7501template <typename Derived>
Samuel Antao686c70c2016-05-26 17:30:50 +00007502StmtResult TreeTransform<Derived>::TransformOMPTargetUpdateDirective(
7503 OMPTargetUpdateDirective *D) {
7504 DeclarationNameInfo DirName;
7505 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_update, DirName,
7506 nullptr, D->getLocStart());
7507 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7508 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7509 return Res;
7510}
7511
7512template <typename Derived>
Alexey Bataev13314bf2014-10-09 04:18:56 +00007513StmtResult
7514TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
7515 DeclarationNameInfo DirName;
7516 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
7517 D->getLocStart());
7518 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7519 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7520 return Res;
7521}
7522
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007523template <typename Derived>
7524StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
7525 OMPCancellationPointDirective *D) {
7526 DeclarationNameInfo DirName;
7527 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
7528 nullptr, D->getLocStart());
7529 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7530 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7531 return Res;
7532}
7533
Alexey Bataev80909872015-07-02 11:25:17 +00007534template <typename Derived>
7535StmtResult
7536TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
7537 DeclarationNameInfo DirName;
7538 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
7539 D->getLocStart());
7540 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7541 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7542 return Res;
7543}
7544
Alexey Bataev49f6e782015-12-01 04:18:41 +00007545template <typename Derived>
7546StmtResult
7547TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
7548 DeclarationNameInfo DirName;
7549 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr,
7550 D->getLocStart());
7551 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7552 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7553 return Res;
7554}
7555
Alexey Bataev0a6ed842015-12-03 09:40:15 +00007556template <typename Derived>
7557StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective(
7558 OMPTaskLoopSimdDirective *D) {
7559 DeclarationNameInfo DirName;
7560 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop_simd, DirName,
7561 nullptr, D->getLocStart());
7562 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7563 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7564 return Res;
7565}
7566
Carlo Bertolli6200a3d2015-12-14 14:51:25 +00007567template <typename Derived>
7568StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective(
7569 OMPDistributeDirective *D) {
7570 DeclarationNameInfo DirName;
7571 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr,
7572 D->getLocStart());
7573 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7574 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7575 return Res;
7576}
7577
Alexander Musman64d33f12014-06-04 07:53:32 +00007578//===----------------------------------------------------------------------===//
7579// OpenMP clause transformation
7580//===----------------------------------------------------------------------===//
7581template <typename Derived>
7582OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00007583 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7584 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007585 return nullptr;
Alexey Bataev6b8046a2015-09-03 07:23:48 +00007586 return getDerived().RebuildOMPIfClause(
7587 C->getNameModifier(), Cond.get(), C->getLocStart(), C->getLParenLoc(),
7588 C->getNameModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007589}
7590
Alexander Musman64d33f12014-06-04 07:53:32 +00007591template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00007592OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
7593 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7594 if (Cond.isInvalid())
7595 return nullptr;
7596 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
7597 C->getLParenLoc(), C->getLocEnd());
7598}
7599
7600template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007601OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00007602TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
7603 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
7604 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007605 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00007606 return getDerived().RebuildOMPNumThreadsClause(
7607 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00007608}
7609
Alexey Bataev62c87d22014-03-21 04:51:18 +00007610template <typename Derived>
7611OMPClause *
7612TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
7613 ExprResult E = getDerived().TransformExpr(C->getSafelen());
7614 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007615 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00007616 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007617 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00007618}
7619
Alexander Musman8bd31e62014-05-27 15:12:19 +00007620template <typename Derived>
7621OMPClause *
Alexey Bataev66b15b52015-08-21 11:14:16 +00007622TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
7623 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
7624 if (E.isInvalid())
7625 return nullptr;
7626 return getDerived().RebuildOMPSimdlenClause(
7627 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7628}
7629
7630template <typename Derived>
7631OMPClause *
Alexander Musman8bd31e62014-05-27 15:12:19 +00007632TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
7633 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
7634 if (E.isInvalid())
Hans Wennborg59dbe862015-09-29 20:56:43 +00007635 return nullptr;
Alexander Musman8bd31e62014-05-27 15:12:19 +00007636 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007637 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00007638}
7639
Alexander Musman64d33f12014-06-04 07:53:32 +00007640template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00007641OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007642TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007643 return getDerived().RebuildOMPDefaultClause(
7644 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
7645 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007646}
7647
Alexander Musman64d33f12014-06-04 07:53:32 +00007648template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007649OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007650TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007651 return getDerived().RebuildOMPProcBindClause(
7652 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
7653 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007654}
7655
Alexander Musman64d33f12014-06-04 07:53:32 +00007656template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007657OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00007658TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
7659 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
7660 if (E.isInvalid())
7661 return nullptr;
7662 return getDerived().RebuildOMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00007663 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
Alexey Bataev56dafe82014-06-20 07:16:17 +00007664 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
Alexey Bataev6402bca2015-12-28 07:25:51 +00007665 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
Alexey Bataev56dafe82014-06-20 07:16:17 +00007666 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
7667}
7668
7669template <typename Derived>
7670OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007671TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
Alexey Bataev10e775f2015-07-30 11:36:16 +00007672 ExprResult E;
7673 if (auto *Num = C->getNumForLoops()) {
7674 E = getDerived().TransformExpr(Num);
7675 if (E.isInvalid())
7676 return nullptr;
7677 }
7678 return getDerived().RebuildOMPOrderedClause(C->getLocStart(), C->getLocEnd(),
7679 C->getLParenLoc(), E.get());
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007680}
7681
7682template <typename Derived>
7683OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00007684TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
7685 // No need to rebuild this clause, no template-dependent parameters.
7686 return C;
7687}
7688
7689template <typename Derived>
7690OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00007691TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
7692 // No need to rebuild this clause, no template-dependent parameters.
7693 return C;
7694}
7695
7696template <typename Derived>
7697OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007698TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
7699 // No need to rebuild this clause, no template-dependent parameters.
7700 return C;
7701}
7702
7703template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00007704OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
7705 // No need to rebuild this clause, no template-dependent parameters.
7706 return C;
7707}
7708
7709template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00007710OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
7711 // No need to rebuild this clause, no template-dependent parameters.
7712 return C;
7713}
7714
7715template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007716OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00007717TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
7718 // No need to rebuild this clause, no template-dependent parameters.
7719 return C;
7720}
7721
7722template <typename Derived>
7723OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00007724TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
7725 // No need to rebuild this clause, no template-dependent parameters.
7726 return C;
7727}
7728
7729template <typename Derived>
7730OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00007731TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
7732 // No need to rebuild this clause, no template-dependent parameters.
7733 return C;
7734}
7735
7736template <typename Derived>
7737OMPClause *
Alexey Bataev346265e2015-09-25 10:37:12 +00007738TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
7739 // No need to rebuild this clause, no template-dependent parameters.
7740 return C;
7741}
7742
7743template <typename Derived>
Alexey Bataevd14d1e62015-09-28 06:39:35 +00007744OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
7745 // No need to rebuild this clause, no template-dependent parameters.
7746 return C;
7747}
7748
7749template <typename Derived>
Alexey Bataev346265e2015-09-25 10:37:12 +00007750OMPClause *
Alexey Bataevb825de12015-12-07 10:51:44 +00007751TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
7752 // No need to rebuild this clause, no template-dependent parameters.
7753 return C;
7754}
7755
7756template <typename Derived>
7757OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007758TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007759 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007760 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007761 for (auto *VE : C->varlists()) {
7762 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007763 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007764 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007765 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007766 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007767 return getDerived().RebuildOMPPrivateClause(
7768 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007769}
7770
Alexander Musman64d33f12014-06-04 07:53:32 +00007771template <typename Derived>
7772OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
7773 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007774 llvm::SmallVector<Expr *, 16> Vars;
7775 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007776 for (auto *VE : C->varlists()) {
7777 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007778 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007779 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007780 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007781 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007782 return getDerived().RebuildOMPFirstprivateClause(
7783 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007784}
7785
Alexander Musman64d33f12014-06-04 07:53:32 +00007786template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007787OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00007788TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
7789 llvm::SmallVector<Expr *, 16> Vars;
7790 Vars.reserve(C->varlist_size());
7791 for (auto *VE : C->varlists()) {
7792 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7793 if (EVar.isInvalid())
7794 return nullptr;
7795 Vars.push_back(EVar.get());
7796 }
7797 return getDerived().RebuildOMPLastprivateClause(
7798 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7799}
7800
7801template <typename Derived>
7802OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00007803TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
7804 llvm::SmallVector<Expr *, 16> Vars;
7805 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007806 for (auto *VE : C->varlists()) {
7807 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00007808 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007809 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007810 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007811 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007812 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
7813 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007814}
7815
Alexander Musman64d33f12014-06-04 07:53:32 +00007816template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007817OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00007818TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
7819 llvm::SmallVector<Expr *, 16> Vars;
7820 Vars.reserve(C->varlist_size());
7821 for (auto *VE : C->varlists()) {
7822 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7823 if (EVar.isInvalid())
7824 return nullptr;
7825 Vars.push_back(EVar.get());
7826 }
7827 CXXScopeSpec ReductionIdScopeSpec;
7828 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
7829
7830 DeclarationNameInfo NameInfo = C->getNameInfo();
7831 if (NameInfo.getName()) {
7832 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7833 if (!NameInfo.getName())
7834 return nullptr;
7835 }
Alexey Bataeva839ddd2016-03-17 10:19:46 +00007836 // Build a list of all UDR decls with the same names ranged by the Scopes.
7837 // The Scope boundary is a duplication of the previous decl.
7838 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
7839 for (auto *E : C->reduction_ops()) {
7840 // Transform all the decls.
7841 if (E) {
7842 auto *ULE = cast<UnresolvedLookupExpr>(E);
7843 UnresolvedSet<8> Decls;
7844 for (auto *D : ULE->decls()) {
7845 NamedDecl *InstD =
7846 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
7847 Decls.addDecl(InstD, InstD->getAccess());
7848 }
7849 UnresolvedReductions.push_back(
7850 UnresolvedLookupExpr::Create(
7851 SemaRef.Context, /*NamingClass=*/nullptr,
7852 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context),
7853 NameInfo, /*ADL=*/true, ULE->isOverloaded(),
7854 Decls.begin(), Decls.end()));
7855 } else
7856 UnresolvedReductions.push_back(nullptr);
7857 }
Alexey Bataevc5e02582014-06-16 07:08:35 +00007858 return getDerived().RebuildOMPReductionClause(
7859 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
Alexey Bataeva839ddd2016-03-17 10:19:46 +00007860 C->getLocEnd(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00007861}
7862
7863template <typename Derived>
7864OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00007865TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
7866 llvm::SmallVector<Expr *, 16> Vars;
7867 Vars.reserve(C->varlist_size());
7868 for (auto *VE : C->varlists()) {
7869 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7870 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007871 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007872 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00007873 }
7874 ExprResult Step = getDerived().TransformExpr(C->getStep());
7875 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007876 return nullptr;
Alexey Bataev182227b2015-08-20 10:54:39 +00007877 return getDerived().RebuildOMPLinearClause(
7878 Vars, Step.get(), C->getLocStart(), C->getLParenLoc(), C->getModifier(),
7879 C->getModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00007880}
7881
Alexander Musman64d33f12014-06-04 07:53:32 +00007882template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00007883OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007884TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *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 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
7894 if (Alignment.isInvalid())
7895 return nullptr;
7896 return getDerived().RebuildOMPAlignedClause(
7897 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
7898 C->getColonLoc(), C->getLocEnd());
7899}
7900
Alexander Musman64d33f12014-06-04 07:53:32 +00007901template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007902OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007903TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
7904 llvm::SmallVector<Expr *, 16> Vars;
7905 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007906 for (auto *VE : C->varlists()) {
7907 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007908 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007909 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007910 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007911 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007912 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
7913 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007914}
7915
Alexey Bataevbae9a792014-06-27 10:37:06 +00007916template <typename Derived>
7917OMPClause *
7918TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
7919 llvm::SmallVector<Expr *, 16> Vars;
7920 Vars.reserve(C->varlist_size());
7921 for (auto *VE : C->varlists()) {
7922 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7923 if (EVar.isInvalid())
7924 return nullptr;
7925 Vars.push_back(EVar.get());
7926 }
7927 return getDerived().RebuildOMPCopyprivateClause(
7928 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7929}
7930
Alexey Bataev6125da92014-07-21 11:26:11 +00007931template <typename Derived>
7932OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
7933 llvm::SmallVector<Expr *, 16> Vars;
7934 Vars.reserve(C->varlist_size());
7935 for (auto *VE : C->varlists()) {
7936 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7937 if (EVar.isInvalid())
7938 return nullptr;
7939 Vars.push_back(EVar.get());
7940 }
7941 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
7942 C->getLParenLoc(), C->getLocEnd());
7943}
7944
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00007945template <typename Derived>
7946OMPClause *
7947TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
7948 llvm::SmallVector<Expr *, 16> Vars;
7949 Vars.reserve(C->varlist_size());
7950 for (auto *VE : C->varlists()) {
7951 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7952 if (EVar.isInvalid())
7953 return nullptr;
7954 Vars.push_back(EVar.get());
7955 }
7956 return getDerived().RebuildOMPDependClause(
7957 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
7958 C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7959}
7960
Michael Wonge710d542015-08-07 16:16:36 +00007961template <typename Derived>
7962OMPClause *
7963TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
7964 ExprResult E = getDerived().TransformExpr(C->getDevice());
7965 if (E.isInvalid())
7966 return nullptr;
7967 return getDerived().RebuildOMPDeviceClause(
7968 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7969}
7970
Kelvin Li0bff7af2015-11-23 05:32:03 +00007971template <typename Derived>
7972OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
7973 llvm::SmallVector<Expr *, 16> Vars;
7974 Vars.reserve(C->varlist_size());
7975 for (auto *VE : C->varlists()) {
7976 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7977 if (EVar.isInvalid())
7978 return nullptr;
7979 Vars.push_back(EVar.get());
7980 }
7981 return getDerived().RebuildOMPMapClause(
Samuel Antao23abd722016-01-19 20:40:49 +00007982 C->getMapTypeModifier(), C->getMapType(), C->isImplicitMapType(),
7983 C->getMapLoc(), C->getColonLoc(), Vars, C->getLocStart(),
7984 C->getLParenLoc(), C->getLocEnd());
Kelvin Li0bff7af2015-11-23 05:32:03 +00007985}
7986
Kelvin Li099bb8c2015-11-24 20:50:12 +00007987template <typename Derived>
7988OMPClause *
7989TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
7990 ExprResult E = getDerived().TransformExpr(C->getNumTeams());
7991 if (E.isInvalid())
7992 return nullptr;
7993 return getDerived().RebuildOMPNumTeamsClause(
7994 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7995}
7996
Kelvin Lia15fb1a2015-11-27 18:47:36 +00007997template <typename Derived>
7998OMPClause *
7999TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
8000 ExprResult E = getDerived().TransformExpr(C->getThreadLimit());
8001 if (E.isInvalid())
8002 return nullptr;
8003 return getDerived().RebuildOMPThreadLimitClause(
8004 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8005}
8006
Alexey Bataeva0569352015-12-01 10:17:31 +00008007template <typename Derived>
8008OMPClause *
8009TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
8010 ExprResult E = getDerived().TransformExpr(C->getPriority());
8011 if (E.isInvalid())
8012 return nullptr;
8013 return getDerived().RebuildOMPPriorityClause(
8014 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8015}
8016
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00008017template <typename Derived>
8018OMPClause *
8019TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
8020 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
8021 if (E.isInvalid())
8022 return nullptr;
8023 return getDerived().RebuildOMPGrainsizeClause(
8024 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8025}
8026
Alexey Bataev382967a2015-12-08 12:06:20 +00008027template <typename Derived>
8028OMPClause *
8029TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
8030 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
8031 if (E.isInvalid())
8032 return nullptr;
8033 return getDerived().RebuildOMPNumTasksClause(
8034 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8035}
8036
Alexey Bataev28c75412015-12-15 08:19:24 +00008037template <typename Derived>
8038OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) {
8039 ExprResult E = getDerived().TransformExpr(C->getHint());
8040 if (E.isInvalid())
8041 return nullptr;
8042 return getDerived().RebuildOMPHintClause(E.get(), C->getLocStart(),
8043 C->getLParenLoc(), C->getLocEnd());
8044}
8045
Carlo Bertollib4adf552016-01-15 18:50:31 +00008046template <typename Derived>
8047OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause(
8048 OMPDistScheduleClause *C) {
8049 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
8050 if (E.isInvalid())
8051 return nullptr;
8052 return getDerived().RebuildOMPDistScheduleClause(
8053 C->getDistScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
8054 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
8055}
8056
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +00008057template <typename Derived>
8058OMPClause *
8059TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) {
8060 return C;
8061}
8062
Samuel Antao661c0902016-05-26 17:39:58 +00008063template <typename Derived>
8064OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) {
8065 llvm::SmallVector<Expr *, 16> Vars;
8066 Vars.reserve(C->varlist_size());
8067 for (auto *VE : C->varlists()) {
8068 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8069 if (EVar.isInvalid())
8070 return 0;
8071 Vars.push_back(EVar.get());
8072 }
8073 return getDerived().RebuildOMPToClause(Vars, C->getLocStart(),
8074 C->getLParenLoc(), C->getLocEnd());
8075}
8076
Samuel Antaoec172c62016-05-26 17:49:04 +00008077template <typename Derived>
8078OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) {
8079 llvm::SmallVector<Expr *, 16> Vars;
8080 Vars.reserve(C->varlist_size());
8081 for (auto *VE : C->varlists()) {
8082 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8083 if (EVar.isInvalid())
8084 return 0;
8085 Vars.push_back(EVar.get());
8086 }
8087 return getDerived().RebuildOMPFromClause(Vars, C->getLocStart(),
8088 C->getLParenLoc(), C->getLocEnd());
8089}
8090
Douglas Gregorebe10102009-08-20 07:17:43 +00008091//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00008092// Expression transformation
8093//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00008094template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008095ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008096TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00008097 if (!E->isTypeDependent())
8098 return E;
8099
8100 return getDerived().RebuildPredefinedExpr(E->getLocation(),
8101 E->getIdentType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008102}
Mike Stump11289f42009-09-09 15:08:12 +00008103
8104template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008105ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008106TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00008107 NestedNameSpecifierLoc QualifierLoc;
8108 if (E->getQualifierLoc()) {
8109 QualifierLoc
8110 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8111 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008112 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008113 }
John McCallce546572009-12-08 09:08:17 +00008114
8115 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008116 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8117 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008118 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00008119 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008120
John McCall815039a2010-08-17 21:27:17 +00008121 DeclarationNameInfo NameInfo = E->getNameInfo();
8122 if (NameInfo.getName()) {
8123 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8124 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008125 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00008126 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008127
8128 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00008129 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008130 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008131 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00008132 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00008133
8134 // Mark it referenced in the new context regardless.
8135 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00008136 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00008137
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008138 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008139 }
John McCallce546572009-12-08 09:08:17 +00008140
Craig Topperc3ec1492014-05-26 06:22:03 +00008141 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00008142 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00008143 TemplateArgs = &TransArgs;
8144 TransArgs.setLAngleLoc(E->getLAngleLoc());
8145 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008146 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8147 E->getNumTemplateArgs(),
8148 TransArgs))
8149 return ExprError();
John McCallce546572009-12-08 09:08:17 +00008150 }
8151
Chad Rosier1dcde962012-08-08 18:46:20 +00008152 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00008153 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00008154}
Mike Stump11289f42009-09-09 15:08:12 +00008155
Douglas Gregora16548e2009-08-11 05:31:07 +00008156template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008157ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008158TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008159 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008160}
Mike Stump11289f42009-09-09 15:08:12 +00008161
Douglas Gregora16548e2009-08-11 05:31:07 +00008162template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008163ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008164TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008165 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008166}
Mike Stump11289f42009-09-09 15:08:12 +00008167
Douglas Gregora16548e2009-08-11 05:31:07 +00008168template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008169ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008170TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008171 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008172}
Mike Stump11289f42009-09-09 15:08:12 +00008173
Douglas Gregora16548e2009-08-11 05:31:07 +00008174template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008175ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008176TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008177 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008178}
Mike Stump11289f42009-09-09 15:08:12 +00008179
Douglas Gregora16548e2009-08-11 05:31:07 +00008180template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008181ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008182TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008183 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008184}
8185
8186template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008187ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00008188TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00008189 if (FunctionDecl *FD = E->getDirectCallee())
8190 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00008191 return SemaRef.MaybeBindToTemporary(E);
8192}
8193
8194template<typename Derived>
8195ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00008196TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
8197 ExprResult ControllingExpr =
8198 getDerived().TransformExpr(E->getControllingExpr());
8199 if (ControllingExpr.isInvalid())
8200 return ExprError();
8201
Chris Lattner01cf8db2011-07-20 06:58:45 +00008202 SmallVector<Expr *, 4> AssocExprs;
8203 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00008204 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
8205 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
8206 if (TS) {
8207 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
8208 if (!AssocType)
8209 return ExprError();
8210 AssocTypes.push_back(AssocType);
8211 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00008212 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00008213 }
8214
8215 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
8216 if (AssocExpr.isInvalid())
8217 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008218 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00008219 }
8220
8221 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
8222 E->getDefaultLoc(),
8223 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008224 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00008225 AssocTypes,
8226 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00008227}
8228
8229template<typename Derived>
8230ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008231TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008232 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008233 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008234 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008235
Douglas Gregora16548e2009-08-11 05:31:07 +00008236 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008237 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008238
John McCallb268a282010-08-23 23:25:46 +00008239 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008240 E->getRParen());
8241}
8242
Richard Smithdb2630f2012-10-21 03:28:35 +00008243/// \brief The operand of a unary address-of operator has special rules: it's
8244/// allowed to refer to a non-static member of a class even if there's no 'this'
8245/// object available.
8246template<typename Derived>
8247ExprResult
8248TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
8249 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00008250 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00008251 else
8252 return getDerived().TransformExpr(E);
8253}
8254
Mike Stump11289f42009-09-09 15:08:12 +00008255template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008256ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008257TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00008258 ExprResult SubExpr;
8259 if (E->getOpcode() == UO_AddrOf)
8260 SubExpr = TransformAddressOfOperand(E->getSubExpr());
8261 else
8262 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008263 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008264 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008265
Douglas Gregora16548e2009-08-11 05:31:07 +00008266 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008267 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008268
Douglas Gregora16548e2009-08-11 05:31:07 +00008269 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
8270 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008271 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008272}
Mike Stump11289f42009-09-09 15:08:12 +00008273
Douglas Gregora16548e2009-08-11 05:31:07 +00008274template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008275ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00008276TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
8277 // Transform the type.
8278 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
8279 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00008280 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008281
Douglas Gregor882211c2010-04-28 22:16:22 +00008282 // Transform all of the components into components similar to what the
8283 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00008284 // FIXME: It would be slightly more efficient in the non-dependent case to
8285 // just map FieldDecls, rather than requiring the rebuilder to look for
8286 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00008287 // template code that we don't care.
8288 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00008289 typedef Sema::OffsetOfComponent Component;
Chris Lattner01cf8db2011-07-20 06:58:45 +00008290 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00008291 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
James Y Knight7281c352015-12-29 22:31:18 +00008292 const OffsetOfNode &ON = E->getComponent(I);
Douglas Gregor882211c2010-04-28 22:16:22 +00008293 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00008294 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00008295 Comp.LocStart = ON.getSourceRange().getBegin();
8296 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00008297 switch (ON.getKind()) {
James Y Knight7281c352015-12-29 22:31:18 +00008298 case OffsetOfNode::Array: {
Douglas Gregor882211c2010-04-28 22:16:22 +00008299 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00008300 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00008301 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008302 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008303
Douglas Gregor882211c2010-04-28 22:16:22 +00008304 ExprChanged = ExprChanged || Index.get() != FromIndex;
8305 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00008306 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00008307 break;
8308 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008309
James Y Knight7281c352015-12-29 22:31:18 +00008310 case OffsetOfNode::Field:
8311 case OffsetOfNode::Identifier:
Douglas Gregor882211c2010-04-28 22:16:22 +00008312 Comp.isBrackets = false;
8313 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00008314 if (!Comp.U.IdentInfo)
8315 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008316
Douglas Gregor882211c2010-04-28 22:16:22 +00008317 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00008318
James Y Knight7281c352015-12-29 22:31:18 +00008319 case OffsetOfNode::Base:
Douglas Gregord1702062010-04-29 00:18:15 +00008320 // Will be recomputed during the rebuild.
8321 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00008322 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008323
Douglas Gregor882211c2010-04-28 22:16:22 +00008324 Components.push_back(Comp);
8325 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008326
Douglas Gregor882211c2010-04-28 22:16:22 +00008327 // If nothing changed, retain the existing expression.
8328 if (!getDerived().AlwaysRebuild() &&
8329 Type == E->getTypeSourceInfo() &&
8330 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008331 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00008332
Douglas Gregor882211c2010-04-28 22:16:22 +00008333 // Build a new offsetof expression.
8334 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
Craig Topperb5518242015-10-22 04:59:59 +00008335 Components, E->getRParenLoc());
Douglas Gregor882211c2010-04-28 22:16:22 +00008336}
8337
8338template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008339ExprResult
John McCall8d69a212010-11-15 23:31:06 +00008340TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
Hubert Tong2cded442015-09-01 22:50:31 +00008341 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
John McCall8d69a212010-11-15 23:31:06 +00008342 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008343 return E;
John McCall8d69a212010-11-15 23:31:06 +00008344}
8345
8346template<typename Derived>
8347ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00008348TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
8349 return E;
8350}
8351
8352template<typename Derived>
8353ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00008354TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00008355 // Rebuild the syntactic form. The original syntactic form has
8356 // opaque-value expressions in it, so strip those away and rebuild
8357 // the result. This is a really awful way of doing this, but the
8358 // better solution (rebuilding the semantic expressions and
8359 // rebinding OVEs as necessary) doesn't work; we'd need
8360 // TreeTransform to not strip away implicit conversions.
8361 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
8362 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00008363 if (result.isInvalid()) return ExprError();
8364
8365 // If that gives us a pseudo-object result back, the pseudo-object
8366 // expression must have been an lvalue-to-rvalue conversion which we
8367 // should reapply.
8368 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008369 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00008370
8371 return result;
8372}
8373
8374template<typename Derived>
8375ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00008376TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
8377 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008378 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00008379 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00008380
John McCallbcd03502009-12-07 02:54:59 +00008381 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00008382 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008383 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008384
John McCall4c98fd82009-11-04 07:28:41 +00008385 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008386 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008387
Peter Collingbournee190dee2011-03-11 19:24:49 +00008388 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
8389 E->getKind(),
8390 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008391 }
Mike Stump11289f42009-09-09 15:08:12 +00008392
Eli Friedmane4f22df2012-02-29 04:03:55 +00008393 // C++0x [expr.sizeof]p1:
8394 // The operand is either an expression, which is an unevaluated operand
8395 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00008396 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8397 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008398
Reid Kleckner32506ed2014-06-12 23:03:48 +00008399 // Try to recover if we have something like sizeof(T::X) where X is a type.
8400 // Notably, there must be *exactly* one set of parens if X is a type.
8401 TypeSourceInfo *RecoveryTSI = nullptr;
8402 ExprResult SubExpr;
8403 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
8404 if (auto *DRE =
8405 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
8406 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
8407 PE, DRE, false, &RecoveryTSI);
8408 else
8409 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
8410
8411 if (RecoveryTSI) {
8412 return getDerived().RebuildUnaryExprOrTypeTrait(
8413 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
8414 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00008415 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008416
Eli Friedmane4f22df2012-02-29 04:03:55 +00008417 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008418 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008419
Peter Collingbournee190dee2011-03-11 19:24:49 +00008420 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
8421 E->getOperatorLoc(),
8422 E->getKind(),
8423 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008424}
Mike Stump11289f42009-09-09 15:08:12 +00008425
Douglas Gregora16548e2009-08-11 05:31:07 +00008426template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008427ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008428TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008429 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008430 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008431 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008432
John McCalldadc5752010-08-24 06:29:42 +00008433 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008434 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008435 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008436
8437
Douglas Gregora16548e2009-08-11 05:31:07 +00008438 if (!getDerived().AlwaysRebuild() &&
8439 LHS.get() == E->getLHS() &&
8440 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008441 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008442
John McCallb268a282010-08-23 23:25:46 +00008443 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008444 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008445 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008446 E->getRBracketLoc());
8447}
Mike Stump11289f42009-09-09 15:08:12 +00008448
Alexey Bataev1a3320e2015-08-25 14:24:04 +00008449template <typename Derived>
8450ExprResult
8451TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
8452 ExprResult Base = getDerived().TransformExpr(E->getBase());
8453 if (Base.isInvalid())
8454 return ExprError();
8455
8456 ExprResult LowerBound;
8457 if (E->getLowerBound()) {
8458 LowerBound = getDerived().TransformExpr(E->getLowerBound());
8459 if (LowerBound.isInvalid())
8460 return ExprError();
8461 }
8462
8463 ExprResult Length;
8464 if (E->getLength()) {
8465 Length = getDerived().TransformExpr(E->getLength());
8466 if (Length.isInvalid())
8467 return ExprError();
8468 }
8469
8470 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
8471 LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
8472 return E;
8473
8474 return getDerived().RebuildOMPArraySectionExpr(
8475 Base.get(), E->getBase()->getLocEnd(), LowerBound.get(), E->getColonLoc(),
8476 Length.get(), E->getRBracketLoc());
8477}
8478
Mike Stump11289f42009-09-09 15:08:12 +00008479template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008480ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008481TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008482 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00008483 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00008484 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008485 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008486
8487 // Transform arguments.
8488 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008489 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008490 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008491 &ArgChanged))
8492 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008493
Douglas Gregora16548e2009-08-11 05:31:07 +00008494 if (!getDerived().AlwaysRebuild() &&
8495 Callee.get() == E->getCallee() &&
8496 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00008497 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00008498
Douglas Gregora16548e2009-08-11 05:31:07 +00008499 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00008500 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00008501 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00008502 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008503 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008504 E->getRParenLoc());
8505}
Mike Stump11289f42009-09-09 15:08:12 +00008506
8507template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008508ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008509TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008510 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008511 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008512 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008513
Douglas Gregorea972d32011-02-28 21:54:11 +00008514 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00008515 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00008516 QualifierLoc
8517 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00008518
Douglas Gregorea972d32011-02-28 21:54:11 +00008519 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008520 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00008521 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00008522 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008523
Eli Friedman2cfcef62009-12-04 06:40:45 +00008524 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008525 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
8526 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008527 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00008528 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008529
John McCall16df1e52010-03-30 21:47:33 +00008530 NamedDecl *FoundDecl = E->getFoundDecl();
8531 if (FoundDecl == E->getMemberDecl()) {
8532 FoundDecl = Member;
8533 } else {
8534 FoundDecl = cast_or_null<NamedDecl>(
8535 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
8536 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00008537 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00008538 }
8539
Douglas Gregora16548e2009-08-11 05:31:07 +00008540 if (!getDerived().AlwaysRebuild() &&
8541 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00008542 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008543 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00008544 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00008545 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008546
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008547 // Mark it referenced in the new context regardless.
8548 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00008549 SemaRef.MarkMemberReferenced(E);
8550
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008551 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008552 }
Douglas Gregora16548e2009-08-11 05:31:07 +00008553
John McCall6b51f282009-11-23 01:53:49 +00008554 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00008555 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00008556 TransArgs.setLAngleLoc(E->getLAngleLoc());
8557 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008558 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8559 E->getNumTemplateArgs(),
8560 TransArgs))
8561 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008562 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008563
Douglas Gregora16548e2009-08-11 05:31:07 +00008564 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00008565 SourceLocation FakeOperatorLoc =
8566 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00008567
John McCall38836f02010-01-15 08:34:02 +00008568 // FIXME: to do this check properly, we will need to preserve the
8569 // first-qualifier-in-scope here, just in case we had a dependent
8570 // base (and therefore couldn't do the check) and a
8571 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00008572 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00008573
John McCallb268a282010-08-23 23:25:46 +00008574 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008575 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00008576 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008577 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008578 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008579 Member,
John McCall16df1e52010-03-30 21:47:33 +00008580 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00008581 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00008582 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00008583 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00008584}
Mike Stump11289f42009-09-09 15:08:12 +00008585
Douglas Gregora16548e2009-08-11 05:31:07 +00008586template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008587ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008588TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008589 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008590 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008591 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008592
John McCalldadc5752010-08-24 06:29:42 +00008593 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008594 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008595 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008596
Douglas Gregora16548e2009-08-11 05:31:07 +00008597 if (!getDerived().AlwaysRebuild() &&
8598 LHS.get() == E->getLHS() &&
8599 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008600 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008601
Lang Hames5de91cc2012-10-02 04:45:10 +00008602 Sema::FPContractStateRAII FPContractState(getSema());
8603 getSema().FPFeatures.fp_contract = E->isFPContractable();
8604
Douglas Gregora16548e2009-08-11 05:31:07 +00008605 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008606 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008607}
8608
Mike Stump11289f42009-09-09 15:08:12 +00008609template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008610ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008611TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00008612 CompoundAssignOperator *E) {
8613 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008614}
Mike Stump11289f42009-09-09 15:08:12 +00008615
Douglas Gregora16548e2009-08-11 05:31:07 +00008616template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00008617ExprResult TreeTransform<Derived>::
8618TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
8619 // Just rebuild the common and RHS expressions and see whether we
8620 // get any changes.
8621
8622 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
8623 if (commonExpr.isInvalid())
8624 return ExprError();
8625
8626 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
8627 if (rhs.isInvalid())
8628 return ExprError();
8629
8630 if (!getDerived().AlwaysRebuild() &&
8631 commonExpr.get() == e->getCommon() &&
8632 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008633 return e;
John McCallc07a0c72011-02-17 10:25:35 +00008634
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008635 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00008636 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008637 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00008638 e->getColonLoc(),
8639 rhs.get());
8640}
8641
8642template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008643ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008644TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008645 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008646 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008647 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008648
John McCalldadc5752010-08-24 06:29:42 +00008649 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008650 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008651 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008652
John McCalldadc5752010-08-24 06:29:42 +00008653 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008654 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008655 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008656
Douglas Gregora16548e2009-08-11 05:31:07 +00008657 if (!getDerived().AlwaysRebuild() &&
8658 Cond.get() == E->getCond() &&
8659 LHS.get() == E->getLHS() &&
8660 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008661 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008662
John McCallb268a282010-08-23 23:25:46 +00008663 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008664 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00008665 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008666 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008667 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008668}
Mike Stump11289f42009-09-09 15:08:12 +00008669
8670template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008671ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008672TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00008673 // Implicit casts are eliminated during transformation, since they
8674 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00008675 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008676}
Mike Stump11289f42009-09-09 15:08:12 +00008677
Douglas Gregora16548e2009-08-11 05:31:07 +00008678template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008679ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008680TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008681 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8682 if (!Type)
8683 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008684
John McCalldadc5752010-08-24 06:29:42 +00008685 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008686 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008687 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008688 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008689
Douglas Gregora16548e2009-08-11 05:31:07 +00008690 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008691 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008692 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008693 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008694
John McCall97513962010-01-15 18:39:57 +00008695 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008696 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00008697 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008698 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008699}
Mike Stump11289f42009-09-09 15:08:12 +00008700
Douglas Gregora16548e2009-08-11 05:31:07 +00008701template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008702ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008703TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00008704 TypeSourceInfo *OldT = E->getTypeSourceInfo();
8705 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
8706 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008707 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008708
John McCalldadc5752010-08-24 06:29:42 +00008709 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00008710 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008711 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008712
Douglas Gregora16548e2009-08-11 05:31:07 +00008713 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00008714 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008715 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008716 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008717
John McCall5d7aa7f2010-01-19 22:33:45 +00008718 // Note: the expression type doesn't necessarily match the
8719 // type-as-written, but that's okay, because it should always be
8720 // derivable from the initializer.
8721
John McCalle15bbff2010-01-18 19:35:47 +00008722 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00008723 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00008724 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008725}
Mike Stump11289f42009-09-09 15:08:12 +00008726
Douglas Gregora16548e2009-08-11 05:31:07 +00008727template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008728ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008729TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008730 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008731 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008732 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008733
Douglas Gregora16548e2009-08-11 05:31:07 +00008734 if (!getDerived().AlwaysRebuild() &&
8735 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008736 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008737
Douglas Gregora16548e2009-08-11 05:31:07 +00008738 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00008739 SourceLocation FakeOperatorLoc =
8740 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00008741 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008742 E->getAccessorLoc(),
8743 E->getAccessor());
8744}
Mike Stump11289f42009-09-09 15:08:12 +00008745
Douglas Gregora16548e2009-08-11 05:31:07 +00008746template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008747ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008748TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Richard Smith520449d2015-02-05 06:15:50 +00008749 if (InitListExpr *Syntactic = E->getSyntacticForm())
8750 E = Syntactic;
8751
Douglas Gregora16548e2009-08-11 05:31:07 +00008752 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00008753
Benjamin Kramerf0623432012-08-23 22:51:59 +00008754 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00008755 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00008756 Inits, &InitChanged))
8757 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008758
Richard Smith520449d2015-02-05 06:15:50 +00008759 if (!getDerived().AlwaysRebuild() && !InitChanged) {
8760 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
8761 // in some cases. We can't reuse it in general, because the syntactic and
8762 // semantic forms are linked, and we can't know that semantic form will
8763 // match even if the syntactic form does.
8764 }
Mike Stump11289f42009-09-09 15:08:12 +00008765
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008766 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00008767 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008768}
Mike Stump11289f42009-09-09 15:08:12 +00008769
Douglas Gregora16548e2009-08-11 05:31:07 +00008770template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008771ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008772TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008773 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00008774
Douglas Gregorebe10102009-08-20 07:17:43 +00008775 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00008776 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008777 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008778 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008779
Douglas Gregorebe10102009-08-20 07:17:43 +00008780 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008781 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00008782 bool ExprChanged = false;
8783 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
8784 DEnd = E->designators_end();
8785 D != DEnd; ++D) {
8786 if (D->isFieldDesignator()) {
8787 Desig.AddDesignator(Designator::getField(D->getFieldName(),
8788 D->getDotLoc(),
8789 D->getFieldLoc()));
8790 continue;
8791 }
Mike Stump11289f42009-09-09 15:08:12 +00008792
Douglas Gregora16548e2009-08-11 05:31:07 +00008793 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00008794 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008795 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008796 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008797
8798 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008799 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008800
Douglas Gregora16548e2009-08-11 05:31:07 +00008801 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008802 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008803 continue;
8804 }
Mike Stump11289f42009-09-09 15:08:12 +00008805
Douglas Gregora16548e2009-08-11 05:31:07 +00008806 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00008807 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00008808 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
8809 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008810 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008811
John McCalldadc5752010-08-24 06:29:42 +00008812 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008813 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008814 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008815
8816 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008817 End.get(),
8818 D->getLBracketLoc(),
8819 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008820
Douglas Gregora16548e2009-08-11 05:31:07 +00008821 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
8822 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00008823
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008824 ArrayExprs.push_back(Start.get());
8825 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008826 }
Mike Stump11289f42009-09-09 15:08:12 +00008827
Douglas Gregora16548e2009-08-11 05:31:07 +00008828 if (!getDerived().AlwaysRebuild() &&
8829 Init.get() == E->getInit() &&
8830 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008831 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008832
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008833 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008834 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008835 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008836}
Mike Stump11289f42009-09-09 15:08:12 +00008837
Yunzhong Gaocb779302015-06-10 00:27:52 +00008838// Seems that if TransformInitListExpr() only works on the syntactic form of an
8839// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
8840template<typename Derived>
8841ExprResult
8842TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
8843 DesignatedInitUpdateExpr *E) {
8844 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
8845 "initializer");
8846 return ExprError();
8847}
8848
8849template<typename Derived>
8850ExprResult
8851TreeTransform<Derived>::TransformNoInitExpr(
8852 NoInitExpr *E) {
8853 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
8854 return ExprError();
8855}
8856
Douglas Gregora16548e2009-08-11 05:31:07 +00008857template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008858ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008859TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008860 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00008861 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00008862
Douglas Gregor3da3c062009-10-28 00:29:27 +00008863 // FIXME: Will we ever have proper type location here? Will we actually
8864 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00008865 QualType T = getDerived().TransformType(E->getType());
8866 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008867 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008868
Douglas Gregora16548e2009-08-11 05:31:07 +00008869 if (!getDerived().AlwaysRebuild() &&
8870 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008871 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008872
Douglas Gregora16548e2009-08-11 05:31:07 +00008873 return getDerived().RebuildImplicitValueInitExpr(T);
8874}
Mike Stump11289f42009-09-09 15:08:12 +00008875
Douglas Gregora16548e2009-08-11 05:31:07 +00008876template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008877ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008878TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00008879 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
8880 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008881 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008882
John McCalldadc5752010-08-24 06:29:42 +00008883 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008884 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008885 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008886
Douglas Gregora16548e2009-08-11 05:31:07 +00008887 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00008888 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008889 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008890 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008891
John McCallb268a282010-08-23 23:25:46 +00008892 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00008893 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008894}
8895
8896template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008897ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008898TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008899 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008900 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00008901 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
8902 &ArgumentChanged))
8903 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008904
Douglas Gregora16548e2009-08-11 05:31:07 +00008905 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008906 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00008907 E->getRParenLoc());
8908}
Mike Stump11289f42009-09-09 15:08:12 +00008909
Douglas Gregora16548e2009-08-11 05:31:07 +00008910/// \brief Transform an address-of-label expression.
8911///
8912/// By default, the transformation of an address-of-label expression always
8913/// rebuilds the expression, so that the label identifier can be resolved to
8914/// the corresponding label statement by semantic analysis.
8915template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008916ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008917TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00008918 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
8919 E->getLabel());
8920 if (!LD)
8921 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008922
Douglas Gregora16548e2009-08-11 05:31:07 +00008923 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00008924 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00008925}
Mike Stump11289f42009-09-09 15:08:12 +00008926
8927template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00008928ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008929TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00008930 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00008931 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00008932 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00008933 if (SubStmt.isInvalid()) {
8934 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00008935 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00008936 }
Mike Stump11289f42009-09-09 15:08:12 +00008937
Douglas Gregora16548e2009-08-11 05:31:07 +00008938 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00008939 SubStmt.get() == E->getSubStmt()) {
8940 // Calling this an 'error' is unintuitive, but it does the right thing.
8941 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008942 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00008943 }
Mike Stump11289f42009-09-09 15:08:12 +00008944
8945 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008946 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008947 E->getRParenLoc());
8948}
Mike Stump11289f42009-09-09 15:08:12 +00008949
Douglas Gregora16548e2009-08-11 05:31:07 +00008950template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008951ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008952TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008953 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008954 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008955 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008956
John McCalldadc5752010-08-24 06:29:42 +00008957 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008958 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008959 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008960
John McCalldadc5752010-08-24 06:29:42 +00008961 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008962 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008963 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008964
Douglas Gregora16548e2009-08-11 05:31:07 +00008965 if (!getDerived().AlwaysRebuild() &&
8966 Cond.get() == E->getCond() &&
8967 LHS.get() == E->getLHS() &&
8968 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008969 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008970
Douglas Gregora16548e2009-08-11 05:31:07 +00008971 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00008972 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008973 E->getRParenLoc());
8974}
Mike Stump11289f42009-09-09 15:08:12 +00008975
Douglas Gregora16548e2009-08-11 05:31:07 +00008976template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008977ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008978TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008979 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008980}
8981
8982template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008983ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008984TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008985 switch (E->getOperator()) {
8986 case OO_New:
8987 case OO_Delete:
8988 case OO_Array_New:
8989 case OO_Array_Delete:
8990 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00008991
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008992 case OO_Call: {
8993 // This is a call to an object's operator().
8994 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
8995
8996 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00008997 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008998 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008999 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009000
9001 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00009002 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
9003 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009004
9005 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00009006 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009007 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00009008 Args))
9009 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009010
John McCallb268a282010-08-23 23:25:46 +00009011 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009012 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009013 E->getLocEnd());
9014 }
9015
9016#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
9017 case OO_##Name:
9018#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
9019#include "clang/Basic/OperatorKinds.def"
9020 case OO_Subscript:
9021 // Handled below.
9022 break;
9023
9024 case OO_Conditional:
9025 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009026
9027 case OO_None:
9028 case NUM_OVERLOADED_OPERATORS:
9029 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009030 }
9031
John McCalldadc5752010-08-24 06:29:42 +00009032 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00009033 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009034 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009035
Richard Smithdb2630f2012-10-21 03:28:35 +00009036 ExprResult First;
9037 if (E->getOperator() == OO_Amp)
9038 First = getDerived().TransformAddressOfOperand(E->getArg(0));
9039 else
9040 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00009041 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009042 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009043
John McCalldadc5752010-08-24 06:29:42 +00009044 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00009045 if (E->getNumArgs() == 2) {
9046 Second = getDerived().TransformExpr(E->getArg(1));
9047 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009048 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009049 }
Mike Stump11289f42009-09-09 15:08:12 +00009050
Douglas Gregora16548e2009-08-11 05:31:07 +00009051 if (!getDerived().AlwaysRebuild() &&
9052 Callee.get() == E->getCallee() &&
9053 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00009054 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009055 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00009056
Lang Hames5de91cc2012-10-02 04:45:10 +00009057 Sema::FPContractStateRAII FPContractState(getSema());
9058 getSema().FPFeatures.fp_contract = E->isFPContractable();
9059
Douglas Gregora16548e2009-08-11 05:31:07 +00009060 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
9061 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00009062 Callee.get(),
9063 First.get(),
9064 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009065}
Mike Stump11289f42009-09-09 15:08:12 +00009066
Douglas Gregora16548e2009-08-11 05:31:07 +00009067template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009068ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009069TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
9070 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009071}
Mike Stump11289f42009-09-09 15:08:12 +00009072
Douglas Gregora16548e2009-08-11 05:31:07 +00009073template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009074ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00009075TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
9076 // Transform the callee.
9077 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
9078 if (Callee.isInvalid())
9079 return ExprError();
9080
9081 // Transform exec config.
9082 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
9083 if (EC.isInvalid())
9084 return ExprError();
9085
9086 // Transform arguments.
9087 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009088 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009089 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00009090 &ArgChanged))
9091 return ExprError();
9092
9093 if (!getDerived().AlwaysRebuild() &&
9094 Callee.get() == E->getCallee() &&
9095 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009096 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00009097
9098 // FIXME: Wrong source location information for the '('.
9099 SourceLocation FakeLParenLoc
9100 = ((Expr *)Callee.get())->getSourceRange().getBegin();
9101 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009102 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00009103 E->getRParenLoc(), EC.get());
9104}
9105
9106template<typename Derived>
9107ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009108TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009109 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9110 if (!Type)
9111 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009112
John McCalldadc5752010-08-24 06:29:42 +00009113 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009114 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009115 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009116 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009117
Douglas Gregora16548e2009-08-11 05:31:07 +00009118 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009119 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009120 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009121 return E;
Nico Weberc153d242014-07-28 00:02:09 +00009122 return getDerived().RebuildCXXNamedCastExpr(
9123 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
9124 Type, E->getAngleBrackets().getEnd(),
9125 // FIXME. this should be '(' location
9126 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009127}
Mike Stump11289f42009-09-09 15:08:12 +00009128
Douglas Gregora16548e2009-08-11 05:31:07 +00009129template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009130ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009131TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
9132 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009133}
Mike Stump11289f42009-09-09 15:08:12 +00009134
9135template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009136ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009137TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
9138 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00009139}
9140
Douglas Gregora16548e2009-08-11 05:31:07 +00009141template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009142ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009143TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009144 CXXReinterpretCastExpr *E) {
9145 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009146}
Mike Stump11289f42009-09-09 15:08:12 +00009147
Douglas Gregora16548e2009-08-11 05:31:07 +00009148template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009149ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009150TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
9151 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009152}
Mike Stump11289f42009-09-09 15:08:12 +00009153
Douglas Gregora16548e2009-08-11 05:31:07 +00009154template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009155ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009156TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009157 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009158 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9159 if (!Type)
9160 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009161
John McCalldadc5752010-08-24 06:29:42 +00009162 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009163 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009164 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009165 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009166
Douglas Gregora16548e2009-08-11 05:31:07 +00009167 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009168 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009169 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009170 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009171
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009172 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00009173 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009174 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009175 E->getRParenLoc());
9176}
Mike Stump11289f42009-09-09 15:08:12 +00009177
Douglas Gregora16548e2009-08-11 05:31:07 +00009178template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009179ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009180TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009181 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00009182 TypeSourceInfo *TInfo
9183 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9184 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009185 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009186
Douglas Gregora16548e2009-08-11 05:31:07 +00009187 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00009188 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009189 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009190
Douglas Gregor9da64192010-04-26 22:37:10 +00009191 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9192 E->getLocStart(),
9193 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009194 E->getLocEnd());
9195 }
Mike Stump11289f42009-09-09 15:08:12 +00009196
Eli Friedman456f0182012-01-20 01:26:23 +00009197 // We don't know whether the subexpression is potentially evaluated until
9198 // after we perform semantic analysis. We speculatively assume it is
9199 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00009200 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00009201 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
9202 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00009203
John McCalldadc5752010-08-24 06:29:42 +00009204 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00009205 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009206 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009207
Douglas Gregora16548e2009-08-11 05:31:07 +00009208 if (!getDerived().AlwaysRebuild() &&
9209 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009210 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009211
Douglas Gregor9da64192010-04-26 22:37:10 +00009212 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9213 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00009214 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009215 E->getLocEnd());
9216}
9217
9218template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009219ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00009220TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
9221 if (E->isTypeOperand()) {
9222 TypeSourceInfo *TInfo
9223 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9224 if (!TInfo)
9225 return ExprError();
9226
9227 if (!getDerived().AlwaysRebuild() &&
9228 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009229 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00009230
Douglas Gregor69735112011-03-06 17:40:41 +00009231 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00009232 E->getLocStart(),
9233 TInfo,
9234 E->getLocEnd());
9235 }
9236
Francois Pichet9f4f2072010-09-08 12:20:18 +00009237 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9238
9239 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
9240 if (SubExpr.isInvalid())
9241 return ExprError();
9242
9243 if (!getDerived().AlwaysRebuild() &&
9244 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009245 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00009246
9247 return getDerived().RebuildCXXUuidofExpr(E->getType(),
9248 E->getLocStart(),
9249 SubExpr.get(),
9250 E->getLocEnd());
9251}
9252
9253template<typename Derived>
9254ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009255TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009256 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009257}
Mike Stump11289f42009-09-09 15:08:12 +00009258
Douglas Gregora16548e2009-08-11 05:31:07 +00009259template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009260ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009261TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009262 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009263 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009264}
Mike Stump11289f42009-09-09 15:08:12 +00009265
Douglas Gregora16548e2009-08-11 05:31:07 +00009266template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009267ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009268TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00009269 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00009270
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009271 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
9272 // Make sure that we capture 'this'.
9273 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009274 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009275 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009276
Douglas Gregorb15af892010-01-07 23:12:05 +00009277 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00009278}
Mike Stump11289f42009-09-09 15:08:12 +00009279
Douglas Gregora16548e2009-08-11 05:31:07 +00009280template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009281ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009282TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009283 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009284 if (SubExpr.isInvalid())
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 if (!getDerived().AlwaysRebuild() &&
9288 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009289 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009290
Douglas Gregor53e191ed2011-07-06 22:04:06 +00009291 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
9292 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00009293}
Mike Stump11289f42009-09-09 15:08:12 +00009294
Douglas Gregora16548e2009-08-11 05:31:07 +00009295template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009296ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009297TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00009298 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009299 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
9300 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009301 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00009302 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009303
Chandler Carruth794da4c2010-02-08 06:42:49 +00009304 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009305 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009306 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009307
Douglas Gregor033f6752009-12-23 23:03:06 +00009308 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00009309}
Mike Stump11289f42009-09-09 15:08:12 +00009310
Douglas Gregora16548e2009-08-11 05:31:07 +00009311template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009312ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00009313TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
9314 FieldDecl *Field
9315 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
9316 E->getField()));
9317 if (!Field)
9318 return ExprError();
9319
9320 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009321 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00009322
9323 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
9324}
9325
9326template<typename Derived>
9327ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00009328TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
9329 CXXScalarValueInitExpr *E) {
9330 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9331 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009332 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009333
Douglas Gregora16548e2009-08-11 05:31:07 +00009334 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009335 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009336 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009337
Chad Rosier1dcde962012-08-08 18:46:20 +00009338 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00009339 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00009340 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009341}
Mike Stump11289f42009-09-09 15:08:12 +00009342
Douglas Gregora16548e2009-08-11 05:31:07 +00009343template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009344ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009345TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009346 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00009347 TypeSourceInfo *AllocTypeInfo
9348 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
9349 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009350 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009351
Douglas Gregora16548e2009-08-11 05:31:07 +00009352 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00009353 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00009354 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009355 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009356
Douglas Gregora16548e2009-08-11 05:31:07 +00009357 // Transform the placement arguments (if any).
9358 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009359 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00009360 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00009361 E->getNumPlacementArgs(), true,
9362 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00009363 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009364
Sebastian Redl6047f072012-02-16 12:22:20 +00009365 // Transform the initializer (if any).
9366 Expr *OldInit = E->getInitializer();
9367 ExprResult NewInit;
9368 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +00009369 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +00009370 if (NewInit.isInvalid())
9371 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009372
Sebastian Redl6047f072012-02-16 12:22:20 +00009373 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00009374 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009375 if (E->getOperatorNew()) {
9376 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009377 getDerived().TransformDecl(E->getLocStart(),
9378 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009379 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00009380 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009381 }
9382
Craig Topperc3ec1492014-05-26 06:22:03 +00009383 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009384 if (E->getOperatorDelete()) {
9385 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009386 getDerived().TransformDecl(E->getLocStart(),
9387 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009388 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00009389 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009390 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009391
Douglas Gregora16548e2009-08-11 05:31:07 +00009392 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00009393 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009394 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00009395 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00009396 OperatorNew == E->getOperatorNew() &&
9397 OperatorDelete == E->getOperatorDelete() &&
9398 !ArgumentChanged) {
9399 // Mark any declarations we need as referenced.
9400 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00009401 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009402 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00009403 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009404 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00009405
Sebastian Redl6047f072012-02-16 12:22:20 +00009406 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00009407 QualType ElementType
9408 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
9409 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
9410 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
9411 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00009412 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00009413 }
9414 }
9415 }
Sebastian Redl6047f072012-02-16 12:22:20 +00009416
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009417 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009418 }
Mike Stump11289f42009-09-09 15:08:12 +00009419
Douglas Gregor0744ef62010-09-07 21:49:58 +00009420 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009421 if (!ArraySize.get()) {
9422 // If no array size was specified, but the new expression was
9423 // instantiated with an array type (e.g., "new T" where T is
9424 // instantiated with "int[4]"), extract the outer bound from the
9425 // array type as our array size. We do this with constant and
9426 // dependently-sized array types.
9427 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
9428 if (!ArrayT) {
9429 // Do nothing
9430 } else if (const ConstantArrayType *ConsArrayT
9431 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009432 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
9433 SemaRef.Context.getSizeType(),
9434 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009435 AllocType = ConsArrayT->getElementType();
9436 } else if (const DependentSizedArrayType *DepArrayT
9437 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
9438 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009439 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009440 AllocType = DepArrayT->getElementType();
9441 }
9442 }
9443 }
Sebastian Redl6047f072012-02-16 12:22:20 +00009444
Douglas Gregora16548e2009-08-11 05:31:07 +00009445 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
9446 E->isGlobalNew(),
9447 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009448 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009449 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00009450 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009451 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00009452 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00009453 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00009454 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009455 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009456}
Mike Stump11289f42009-09-09 15:08:12 +00009457
Douglas Gregora16548e2009-08-11 05:31:07 +00009458template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009459ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009460TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009461 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00009462 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009463 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009464
Douglas Gregord2d9da02010-02-26 00:38:10 +00009465 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00009466 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009467 if (E->getOperatorDelete()) {
9468 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009469 getDerived().TransformDecl(E->getLocStart(),
9470 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009471 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00009472 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009473 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009474
Douglas Gregora16548e2009-08-11 05:31:07 +00009475 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00009476 Operand.get() == E->getArgument() &&
9477 OperatorDelete == E->getOperatorDelete()) {
9478 // Mark any declarations we need as referenced.
9479 // FIXME: instantiation-specific.
9480 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009481 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00009482
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00009483 if (!E->getArgument()->isTypeDependent()) {
9484 QualType Destroyed = SemaRef.Context.getBaseElementType(
9485 E->getDestroyedType());
9486 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
9487 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00009488 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00009489 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00009490 }
9491 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009492
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009493 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009494 }
Mike Stump11289f42009-09-09 15:08:12 +00009495
Douglas Gregora16548e2009-08-11 05:31:07 +00009496 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
9497 E->isGlobalDelete(),
9498 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00009499 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009500}
Mike Stump11289f42009-09-09 15:08:12 +00009501
Douglas Gregora16548e2009-08-11 05:31:07 +00009502template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009503ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00009504TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009505 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009506 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00009507 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009508 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009509
John McCallba7bf592010-08-24 05:47:05 +00009510 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00009511 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00009512 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009513 E->getOperatorLoc(),
9514 E->isArrow()? tok::arrow : tok::period,
9515 ObjectTypePtr,
9516 MayBePseudoDestructor);
9517 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009518 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009519
John McCallba7bf592010-08-24 05:47:05 +00009520 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00009521 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
9522 if (QualifierLoc) {
9523 QualifierLoc
9524 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
9525 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00009526 return ExprError();
9527 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00009528 CXXScopeSpec SS;
9529 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00009530
Douglas Gregor678f90d2010-02-25 01:56:36 +00009531 PseudoDestructorTypeStorage Destroyed;
9532 if (E->getDestroyedTypeInfo()) {
9533 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00009534 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009535 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00009536 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009537 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00009538 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00009539 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00009540 // We aren't likely to be able to resolve the identifier down to a type
9541 // now anyway, so just retain the identifier.
9542 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
9543 E->getDestroyedTypeLoc());
9544 } else {
9545 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00009546 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009547 *E->getDestroyedTypeIdentifier(),
9548 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009549 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009550 SS, ObjectTypePtr,
9551 false);
9552 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009553 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009554
Douglas Gregor678f90d2010-02-25 01:56:36 +00009555 Destroyed
9556 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
9557 E->getDestroyedTypeLoc());
9558 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009559
Craig Topperc3ec1492014-05-26 06:22:03 +00009560 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009561 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00009562 CXXScopeSpec EmptySS;
9563 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00009564 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009565 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009566 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00009567 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009568
John McCallb268a282010-08-23 23:25:46 +00009569 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00009570 E->getOperatorLoc(),
9571 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00009572 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009573 ScopeTypeInfo,
9574 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009575 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009576 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00009577}
Mike Stump11289f42009-09-09 15:08:12 +00009578
Douglas Gregorad8a3362009-09-04 17:36:40 +00009579template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009580ExprResult
John McCalld14a8642009-11-21 08:51:07 +00009581TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009582 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00009583 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
9584 Sema::LookupOrdinaryName);
9585
9586 // Transform all the decls.
9587 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
9588 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009589 NamedDecl *InstD = static_cast<NamedDecl*>(
9590 getDerived().TransformDecl(Old->getNameLoc(),
9591 *I));
John McCall84d87672009-12-10 09:41:52 +00009592 if (!InstD) {
9593 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9594 // This can happen because of dependent hiding.
9595 if (isa<UsingShadowDecl>(*I))
9596 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00009597 else {
9598 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009599 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009600 }
John McCall84d87672009-12-10 09:41:52 +00009601 }
John McCalle66edc12009-11-24 19:00:30 +00009602
9603 // Expand using declarations.
9604 if (isa<UsingDecl>(InstD)) {
9605 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009606 for (auto *I : UD->shadows())
9607 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00009608 continue;
9609 }
9610
9611 R.addDecl(InstD);
9612 }
9613
9614 // Resolve a kind, but don't do any further analysis. If it's
9615 // ambiguous, the callee needs to deal with it.
9616 R.resolveKind();
9617
9618 // Rebuild the nested-name qualifier, if present.
9619 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00009620 if (Old->getQualifierLoc()) {
9621 NestedNameSpecifierLoc QualifierLoc
9622 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9623 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009624 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009625
Douglas Gregor0da1d432011-02-28 20:01:57 +00009626 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00009627 }
9628
Douglas Gregor9262f472010-04-27 18:19:34 +00009629 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00009630 CXXRecordDecl *NamingClass
9631 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
9632 Old->getNameLoc(),
9633 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00009634 if (!NamingClass) {
9635 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009636 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009637 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009638
Douglas Gregorda7be082010-04-27 16:10:10 +00009639 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00009640 }
9641
Abramo Bagnara7945c982012-01-27 09:46:47 +00009642 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9643
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009644 // If we have neither explicit template arguments, nor the template keyword,
Reid Kleckner744e3e72015-10-20 21:04:13 +00009645 // it's a normal declaration name or member reference.
9646 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
9647 NamedDecl *D = R.getAsSingle<NamedDecl>();
9648 // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
9649 // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
9650 // give a good diagnostic.
9651 if (D && D->isCXXInstanceMember()) {
9652 return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R,
9653 /*TemplateArgs=*/nullptr,
9654 /*Scope=*/nullptr);
9655 }
9656
John McCalle66edc12009-11-24 19:00:30 +00009657 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
Reid Kleckner744e3e72015-10-20 21:04:13 +00009658 }
John McCalle66edc12009-11-24 19:00:30 +00009659
9660 // If we have template arguments, rebuild them, then rebuild the
9661 // templateid expression.
9662 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00009663 if (Old->hasExplicitTemplateArgs() &&
9664 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00009665 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00009666 TransArgs)) {
9667 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00009668 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009669 }
John McCalle66edc12009-11-24 19:00:30 +00009670
Abramo Bagnara7945c982012-01-27 09:46:47 +00009671 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009672 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00009673}
Mike Stump11289f42009-09-09 15:08:12 +00009674
Douglas Gregora16548e2009-08-11 05:31:07 +00009675template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009676ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00009677TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
9678 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009679 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009680 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
9681 TypeSourceInfo *From = E->getArg(I);
9682 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00009683 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00009684 TypeLocBuilder TLB;
9685 TLB.reserve(FromTL.getFullDataSize());
9686 QualType To = getDerived().TransformType(TLB, FromTL);
9687 if (To.isNull())
9688 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009689
Douglas Gregor29c42f22012-02-24 07:38:34 +00009690 if (To == From->getType())
9691 Args.push_back(From);
9692 else {
9693 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9694 ArgChanged = true;
9695 }
9696 continue;
9697 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009698
Douglas Gregor29c42f22012-02-24 07:38:34 +00009699 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009700
Douglas Gregor29c42f22012-02-24 07:38:34 +00009701 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00009702 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00009703 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
9704 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9705 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00009706
Douglas Gregor29c42f22012-02-24 07:38:34 +00009707 // Determine whether the set of unexpanded parameter packs can and should
9708 // be expanded.
9709 bool Expand = true;
9710 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009711 Optional<unsigned> OrigNumExpansions =
9712 ExpansionTL.getTypePtr()->getNumExpansions();
9713 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009714 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
9715 PatternTL.getSourceRange(),
9716 Unexpanded,
9717 Expand, RetainExpansion,
9718 NumExpansions))
9719 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009720
Douglas Gregor29c42f22012-02-24 07:38:34 +00009721 if (!Expand) {
9722 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009723 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00009724 // expansion.
9725 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00009726
Douglas Gregor29c42f22012-02-24 07:38:34 +00009727 TypeLocBuilder TLB;
9728 TLB.reserve(From->getTypeLoc().getFullDataSize());
9729
9730 QualType To = getDerived().TransformType(TLB, PatternTL);
9731 if (To.isNull())
9732 return ExprError();
9733
Chad Rosier1dcde962012-08-08 18:46:20 +00009734 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009735 PatternTL.getSourceRange(),
9736 ExpansionTL.getEllipsisLoc(),
9737 NumExpansions);
9738 if (To.isNull())
9739 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009740
Douglas Gregor29c42f22012-02-24 07:38:34 +00009741 PackExpansionTypeLoc ToExpansionTL
9742 = TLB.push<PackExpansionTypeLoc>(To);
9743 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9744 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9745 continue;
9746 }
9747
9748 // Expand the pack expansion by substituting for each argument in the
9749 // pack(s).
9750 for (unsigned I = 0; I != *NumExpansions; ++I) {
9751 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
9752 TypeLocBuilder TLB;
9753 TLB.reserve(PatternTL.getFullDataSize());
9754 QualType To = getDerived().TransformType(TLB, PatternTL);
9755 if (To.isNull())
9756 return ExprError();
9757
Eli Friedman5e05c4a2013-07-19 21:49:32 +00009758 if (To->containsUnexpandedParameterPack()) {
9759 To = getDerived().RebuildPackExpansionType(To,
9760 PatternTL.getSourceRange(),
9761 ExpansionTL.getEllipsisLoc(),
9762 NumExpansions);
9763 if (To.isNull())
9764 return ExprError();
9765
9766 PackExpansionTypeLoc ToExpansionTL
9767 = TLB.push<PackExpansionTypeLoc>(To);
9768 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9769 }
9770
Douglas Gregor29c42f22012-02-24 07:38:34 +00009771 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9772 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009773
Douglas Gregor29c42f22012-02-24 07:38:34 +00009774 if (!RetainExpansion)
9775 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009776
Douglas Gregor29c42f22012-02-24 07:38:34 +00009777 // If we're supposed to retain a pack expansion, do so by temporarily
9778 // forgetting the partially-substituted parameter pack.
9779 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
9780
9781 TypeLocBuilder TLB;
9782 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00009783
Douglas Gregor29c42f22012-02-24 07:38:34 +00009784 QualType To = getDerived().TransformType(TLB, PatternTL);
9785 if (To.isNull())
9786 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009787
9788 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009789 PatternTL.getSourceRange(),
9790 ExpansionTL.getEllipsisLoc(),
9791 NumExpansions);
9792 if (To.isNull())
9793 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009794
Douglas Gregor29c42f22012-02-24 07:38:34 +00009795 PackExpansionTypeLoc ToExpansionTL
9796 = TLB.push<PackExpansionTypeLoc>(To);
9797 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9798 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9799 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009800
Douglas Gregor29c42f22012-02-24 07:38:34 +00009801 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009802 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009803
9804 return getDerived().RebuildTypeTrait(E->getTrait(),
9805 E->getLocStart(),
9806 Args,
9807 E->getLocEnd());
9808}
9809
9810template<typename Derived>
9811ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00009812TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
9813 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
9814 if (!T)
9815 return ExprError();
9816
9817 if (!getDerived().AlwaysRebuild() &&
9818 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009819 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009820
9821 ExprResult SubExpr;
9822 {
9823 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9824 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
9825 if (SubExpr.isInvalid())
9826 return ExprError();
9827
9828 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009829 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009830 }
9831
9832 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
9833 E->getLocStart(),
9834 T,
9835 SubExpr.get(),
9836 E->getLocEnd());
9837}
9838
9839template<typename Derived>
9840ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00009841TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
9842 ExprResult SubExpr;
9843 {
9844 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9845 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
9846 if (SubExpr.isInvalid())
9847 return ExprError();
9848
9849 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009850 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +00009851 }
9852
9853 return getDerived().RebuildExpressionTrait(
9854 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
9855}
9856
Reid Kleckner32506ed2014-06-12 23:03:48 +00009857template <typename Derived>
9858ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
9859 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
9860 TypeSourceInfo **RecoveryTSI) {
9861 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
9862 DRE, AddrTaken, RecoveryTSI);
9863
9864 // Propagate both errors and recovered types, which return ExprEmpty.
9865 if (!NewDRE.isUsable())
9866 return NewDRE;
9867
9868 // We got an expr, wrap it up in parens.
9869 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
9870 return PE;
9871 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
9872 PE->getRParen());
9873}
9874
9875template <typename Derived>
9876ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9877 DependentScopeDeclRefExpr *E) {
9878 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
9879 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00009880}
9881
9882template<typename Derived>
9883ExprResult
9884TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9885 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +00009886 bool IsAddressOfOperand,
9887 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00009888 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009889 NestedNameSpecifierLoc QualifierLoc
9890 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9891 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009892 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00009893 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00009894
John McCall31f82722010-11-12 08:19:04 +00009895 // TODO: If this is a conversion-function-id, verify that the
9896 // destination type name (if present) resolves the same way after
9897 // instantiation as it did in the local scope.
9898
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009899 DeclarationNameInfo NameInfo
9900 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
9901 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009902 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009903
John McCalle66edc12009-11-24 19:00:30 +00009904 if (!E->hasExplicitTemplateArgs()) {
9905 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009906 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009907 // Note: it is sufficient to compare the Name component of NameInfo:
9908 // if name has not changed, DNLoc has not changed either.
9909 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009910 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009911
Reid Kleckner32506ed2014-06-12 23:03:48 +00009912 return getDerived().RebuildDependentScopeDeclRefExpr(
9913 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
9914 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +00009915 }
John McCall6b51f282009-11-23 01:53:49 +00009916
9917 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009918 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9919 E->getNumTemplateArgs(),
9920 TransArgs))
9921 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009922
Reid Kleckner32506ed2014-06-12 23:03:48 +00009923 return getDerived().RebuildDependentScopeDeclRefExpr(
9924 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
9925 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00009926}
9927
9928template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009929ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009930TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00009931 // CXXConstructExprs other than for list-initialization and
9932 // CXXTemporaryObjectExpr are always implicit, so when we have
9933 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00009934 if ((E->getNumArgs() == 1 ||
9935 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00009936 (!getDerived().DropCallArgument(E->getArg(0))) &&
9937 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00009938 return getDerived().TransformExpr(E->getArg(0));
9939
Douglas Gregora16548e2009-08-11 05:31:07 +00009940 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
9941
9942 QualType T = getDerived().TransformType(E->getType());
9943 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00009944 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009945
9946 CXXConstructorDecl *Constructor
9947 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009948 getDerived().TransformDecl(E->getLocStart(),
9949 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009950 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009951 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009952
Douglas Gregora16548e2009-08-11 05:31:07 +00009953 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009954 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009955 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009956 &ArgumentChanged))
9957 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009958
Douglas Gregora16548e2009-08-11 05:31:07 +00009959 if (!getDerived().AlwaysRebuild() &&
9960 T == E->getType() &&
9961 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00009962 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00009963 // Mark the constructor as referenced.
9964 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009965 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009966 return E;
Douglas Gregorde550352010-02-26 00:01:57 +00009967 }
Mike Stump11289f42009-09-09 15:08:12 +00009968
Douglas Gregordb121ba2009-12-14 16:27:04 +00009969 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
Richard Smithc83bf822016-06-10 00:58:19 +00009970 Constructor,
Richard Smithc2bebe92016-05-11 20:37:46 +00009971 E->isElidable(), Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00009972 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00009973 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +00009974 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00009975 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00009976 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00009977 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009978}
Mike Stump11289f42009-09-09 15:08:12 +00009979
Douglas Gregora16548e2009-08-11 05:31:07 +00009980/// \brief Transform a C++ temporary-binding expression.
9981///
Douglas Gregor363b1512009-12-24 18:51:59 +00009982/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
9983/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009984template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009985ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009986TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009987 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009988}
Mike Stump11289f42009-09-09 15:08:12 +00009989
John McCall5d413782010-12-06 08:20:24 +00009990/// \brief Transform a C++ expression that contains cleanups that should
9991/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00009992///
John McCall5d413782010-12-06 08:20:24 +00009993/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00009994/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009995template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009996ExprResult
John McCall5d413782010-12-06 08:20:24 +00009997TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009998 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009999}
Mike Stump11289f42009-09-09 15:08:12 +000010000
Douglas Gregora16548e2009-08-11 05:31:07 +000010001template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010002ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010003TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +000010004 CXXTemporaryObjectExpr *E) {
10005 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10006 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010007 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010008
Douglas Gregora16548e2009-08-11 05:31:07 +000010009 CXXConstructorDecl *Constructor
10010 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +000010011 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010012 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +000010013 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +000010014 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010015
Douglas Gregora16548e2009-08-11 05:31:07 +000010016 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010017 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +000010018 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010019 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010020 &ArgumentChanged))
10021 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010022
Douglas Gregora16548e2009-08-11 05:31:07 +000010023 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010024 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010025 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000010026 !ArgumentChanged) {
10027 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +000010028 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +000010029 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000010030 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010031
Richard Smithd59b8322012-12-19 01:39:02 +000010032 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +000010033 return getDerived().RebuildCXXTemporaryObjectExpr(T,
10034 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010035 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +000010036 E->getLocEnd());
10037}
Mike Stump11289f42009-09-09 15:08:12 +000010038
Douglas Gregora16548e2009-08-11 05:31:07 +000010039template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010040ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +000010041TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +000010042 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010043 // lambda body, because they are not semantically within that scope.
Richard Smithc38498f2015-04-27 21:27:54 +000010044 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010045 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
10046 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
Richard Smithc38498f2015-04-27 21:27:54 +000010047 E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010048 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +000010049 CEnd = E->capture_end();
10050 C != CEnd; ++C) {
James Dennettdd2ffea22015-05-07 18:48:18 +000010051 if (!E->isInitCapture(C))
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010052 continue;
Richard Smith01014ce2014-11-20 23:53:14 +000010053 EnterExpressionEvaluationContext EEEC(getSema(),
10054 Sema::PotentiallyEvaluated);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010055 ExprResult NewExprInitResult = getDerived().TransformInitializer(
10056 C->getCapturedVar()->getInit(),
10057 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith01014ce2014-11-20 23:53:14 +000010058
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010059 if (NewExprInitResult.isInvalid())
10060 return ExprError();
10061 Expr *NewExprInit = NewExprInitResult.get();
Richard Smith01014ce2014-11-20 23:53:14 +000010062
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010063 VarDecl *OldVD = C->getCapturedVar();
Richard Smith01014ce2014-11-20 23:53:14 +000010064 QualType NewInitCaptureType =
Richard Smith42b10572015-11-11 01:36:17 +000010065 getSema().buildLambdaInitCaptureInitialization(
10066 C->getLocation(), OldVD->getType()->isReferenceType(),
10067 OldVD->getIdentifier(),
10068 C->getCapturedVar()->getInitStyle() != VarDecl::CInit, NewExprInit);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010069 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010070 InitCaptureExprsAndTypes[C - E->capture_begin()] =
10071 std::make_pair(NewExprInitResult, NewInitCaptureType);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010072 }
10073
Faisal Vali2cba1332013-10-23 06:44:28 +000010074 // Transform the template parameters, and add them to the current
10075 // instantiation scope. The null case is handled correctly.
Richard Smithc38498f2015-04-27 21:27:54 +000010076 auto TPL = getDerived().TransformTemplateParameterList(
Faisal Vali2cba1332013-10-23 06:44:28 +000010077 E->getTemplateParameterList());
10078
Richard Smith01014ce2014-11-20 23:53:14 +000010079 // Transform the type of the original lambda's call operator.
10080 // The transformation MUST be done in the CurrentInstantiationScope since
10081 // it introduces a mapping of the original to the newly created
10082 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +000010083 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +000010084 {
10085 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
10086 FunctionProtoTypeLoc OldCallOpFPTL =
10087 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +000010088
10089 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +000010090 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +000010091 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +000010092 QualType NewCallOpType = TransformFunctionProtoType(
10093 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +000010094 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
10095 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
10096 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +000010097 });
Reid Kleckneraac43c62014-12-15 21:07:16 +000010098 if (NewCallOpType.isNull())
10099 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +000010100 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
10101 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +000010102 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010103
Richard Smithc38498f2015-04-27 21:27:54 +000010104 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
10105 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
10106 LSI->GLTemplateParameterList = TPL;
10107
Eli Friedmand564afb2012-09-19 01:18:11 +000010108 // Create the local class that will describe the lambda.
10109 CXXRecordDecl *Class
10110 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +000010111 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +000010112 /*KnownDependent=*/false,
10113 E->getCaptureDefault());
Eli Friedmand564afb2012-09-19 01:18:11 +000010114 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
10115
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010116 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +000010117 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
10118 Class, E->getIntroducerRange(), NewCallOpTSI,
10119 E->getCallOperator()->getLocEnd(),
Faisal Valia734ab92016-03-26 16:11:37 +000010120 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams(),
10121 E->getCallOperator()->isConstexpr());
10122
Faisal Vali2cba1332013-10-23 06:44:28 +000010123 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +000010124
Faisal Vali2cba1332013-10-23 06:44:28 +000010125 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
Richard Smithc38498f2015-04-27 21:27:54 +000010126 getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
Richard Smithba71c082013-05-16 06:20:58 +000010127
Douglas Gregorb4328232012-02-14 00:00:48 +000010128 // Introduce the context of the call operator.
Richard Smithc38498f2015-04-27 21:27:54 +000010129 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
Richard Smith7ff2bcb2014-01-24 01:54:52 +000010130 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +000010131
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010132 // Enter the scope of the lambda.
Richard Smithc38498f2015-04-27 21:27:54 +000010133 getSema().buildLambdaScope(LSI, NewCallOperator,
10134 E->getIntroducerRange(),
10135 E->getCaptureDefault(),
10136 E->getCaptureDefaultLoc(),
10137 E->hasExplicitParameters(),
10138 E->hasExplicitResultType(),
10139 E->isMutable());
10140
10141 bool Invalid = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010142
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010143 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010144 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010145 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010146 CEnd = E->capture_end();
10147 C != CEnd; ++C) {
10148 // When we hit the first implicit capture, tell Sema that we've finished
10149 // the list of explicit captures.
10150 if (!FinishedExplicitCaptures && C->isImplicit()) {
10151 getSema().finishLambdaExplicitCaptures(LSI);
10152 FinishedExplicitCaptures = true;
10153 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010154
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010155 // Capturing 'this' is trivial.
10156 if (C->capturesThis()) {
Faisal Validc6b5962016-03-21 09:25:37 +000010157 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
10158 /*BuildAndDiagnose*/ true, nullptr,
10159 C->getCaptureKind() == LCK_StarThis);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010160 continue;
10161 }
Alexey Bataev39c81e22014-08-28 04:28:19 +000010162 // Captured expression will be recaptured during captured variables
10163 // rebuilding.
10164 if (C->capturesVLAType())
10165 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +000010166
Richard Smithba71c082013-05-16 06:20:58 +000010167 // Rebuild init-captures, including the implied field declaration.
James Dennettdd2ffea22015-05-07 18:48:18 +000010168 if (E->isInitCapture(C)) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010169 InitCaptureInfoTy InitExprTypePair =
10170 InitCaptureExprsAndTypes[C - E->capture_begin()];
10171 ExprResult Init = InitExprTypePair.first;
10172 QualType InitQualType = InitExprTypePair.second;
10173 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +000010174 Invalid = true;
10175 continue;
10176 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000010177 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010178 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
Richard Smith42b10572015-11-11 01:36:17 +000010179 OldVD->getLocation(), InitExprTypePair.second, OldVD->getIdentifier(),
10180 OldVD->getInitStyle(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +000010181 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +000010182 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010183 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +000010184 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010185 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000010186 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +000010187 continue;
10188 }
10189
10190 assert(C->capturesVariable() && "unexpected kind of lambda capture");
10191
Douglas Gregor3e308b12012-02-14 19:27:52 +000010192 // Determine the capture kind for Sema.
10193 Sema::TryCaptureKind Kind
10194 = C->isImplicit()? Sema::TryCapture_Implicit
10195 : C->getCaptureKind() == LCK_ByCopy
10196 ? Sema::TryCapture_ExplicitByVal
10197 : Sema::TryCapture_ExplicitByRef;
10198 SourceLocation EllipsisLoc;
10199 if (C->isPackExpansion()) {
10200 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
10201 bool ShouldExpand = false;
10202 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010203 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +000010204 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
10205 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000010206 Unexpanded,
10207 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +000010208 NumExpansions)) {
10209 Invalid = true;
10210 continue;
10211 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010212
Douglas Gregor3e308b12012-02-14 19:27:52 +000010213 if (ShouldExpand) {
10214 // The transform has determined that we should perform an expansion;
10215 // transform and capture each of the arguments.
10216 // expansion of the pattern. Do so.
10217 VarDecl *Pack = C->getCapturedVar();
10218 for (unsigned I = 0; I != *NumExpansions; ++I) {
10219 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10220 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000010221 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000010222 Pack));
10223 if (!CapturedVar) {
10224 Invalid = true;
10225 continue;
10226 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010227
Douglas Gregor3e308b12012-02-14 19:27:52 +000010228 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +000010229 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
10230 }
Richard Smith9467be42014-06-06 17:33:35 +000010231
10232 // FIXME: Retain a pack expansion if RetainExpansion is true.
10233
Douglas Gregor3e308b12012-02-14 19:27:52 +000010234 continue;
10235 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010236
Douglas Gregor3e308b12012-02-14 19:27:52 +000010237 EllipsisLoc = C->getEllipsisLoc();
10238 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010239
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010240 // Transform the captured variable.
10241 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000010242 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010243 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +000010244 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010245 Invalid = true;
10246 continue;
10247 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010248
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010249 // Capture the transformed variable.
Meador Inge4f9dee72015-06-26 00:09:55 +000010250 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
10251 EllipsisLoc);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010252 }
10253 if (!FinishedExplicitCaptures)
10254 getSema().finishLambdaExplicitCaptures(LSI);
10255
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010256 // Enter a new evaluation context to insulate the lambda from any
10257 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +000010258 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010259
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010260 // Instantiate the body of the lambda expression.
Richard Smithc38498f2015-04-27 21:27:54 +000010261 StmtResult Body =
10262 Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
10263
10264 // ActOnLambda* will pop the function scope for us.
10265 FuncScopeCleanup.disable();
10266
Douglas Gregorb4328232012-02-14 00:00:48 +000010267 if (Body.isInvalid()) {
Richard Smithc38498f2015-04-27 21:27:54 +000010268 SavedContext.pop();
Craig Topperc3ec1492014-05-26 06:22:03 +000010269 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +000010270 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +000010271 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +000010272 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +000010273
Richard Smithc38498f2015-04-27 21:27:54 +000010274 // Copy the LSI before ActOnFinishFunctionBody removes it.
10275 // FIXME: This is dumb. Store the lambda information somewhere that outlives
10276 // the call operator.
10277 auto LSICopy = *LSI;
10278 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
10279 /*IsInstantiation*/ true);
10280 SavedContext.pop();
10281
10282 return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(),
10283 &LSICopy);
Douglas Gregore31e6062012-02-07 10:09:13 +000010284}
10285
10286template<typename Derived>
10287ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010288TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010289 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +000010290 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10291 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010292 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010293
Douglas Gregora16548e2009-08-11 05:31:07 +000010294 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010295 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000010296 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +000010297 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010298 &ArgumentChanged))
10299 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010300
Douglas Gregora16548e2009-08-11 05:31:07 +000010301 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010302 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010303 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010304 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010305
Douglas Gregora16548e2009-08-11 05:31:07 +000010306 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +000010307 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +000010308 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010309 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +000010310 E->getRParenLoc());
10311}
Mike Stump11289f42009-09-09 15:08:12 +000010312
Douglas Gregora16548e2009-08-11 05:31:07 +000010313template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010314ExprResult
John McCall8cd78132009-11-19 22:55:06 +000010315TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010316 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010317 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000010318 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000010319 Expr *OldBase;
10320 QualType BaseType;
10321 QualType ObjectType;
10322 if (!E->isImplicitAccess()) {
10323 OldBase = E->getBase();
10324 Base = getDerived().TransformExpr(OldBase);
10325 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010326 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010327
John McCall2d74de92009-12-01 22:10:20 +000010328 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +000010329 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +000010330 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +000010331 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010332 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010333 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +000010334 ObjectTy,
10335 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +000010336 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010337 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +000010338
John McCallba7bf592010-08-24 05:47:05 +000010339 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +000010340 BaseType = ((Expr*) Base.get())->getType();
10341 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +000010342 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +000010343 BaseType = getDerived().TransformType(E->getBaseType());
10344 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
10345 }
Mike Stump11289f42009-09-09 15:08:12 +000010346
Douglas Gregora5cb6da2009-10-20 05:58:46 +000010347 // Transform the first part of the nested-name-specifier that qualifies
10348 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +000010349 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +000010350 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +000010351 E->getFirstQualifierFoundInScope(),
10352 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +000010353
Douglas Gregore16af532011-02-28 18:50:33 +000010354 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010355 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +000010356 QualifierLoc
10357 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
10358 ObjectType,
10359 FirstQualifierInScope);
10360 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010361 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010362 }
Mike Stump11289f42009-09-09 15:08:12 +000010363
Abramo Bagnara7945c982012-01-27 09:46:47 +000010364 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
10365
John McCall31f82722010-11-12 08:19:04 +000010366 // TODO: If this is a conversion-function-id, verify that the
10367 // destination type name (if present) resolves the same way after
10368 // instantiation as it did in the local scope.
10369
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010370 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +000010371 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010372 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000010373 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010374
John McCall2d74de92009-12-01 22:10:20 +000010375 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +000010376 // This is a reference to a member without an explicitly-specified
10377 // template argument list. Optimize for this common case.
10378 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +000010379 Base.get() == OldBase &&
10380 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +000010381 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010382 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +000010383 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010384 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010385
John McCallb268a282010-08-23 23:25:46 +000010386 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010387 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +000010388 E->isArrow(),
10389 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000010390 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010391 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +000010392 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010393 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000010394 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +000010395 }
10396
John McCall6b51f282009-11-23 01:53:49 +000010397 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010398 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
10399 E->getNumTemplateArgs(),
10400 TransArgs))
10401 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010402
John McCallb268a282010-08-23 23:25:46 +000010403 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010404 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +000010405 E->isArrow(),
10406 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000010407 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010408 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +000010409 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010410 NameInfo,
John McCall10eae182009-11-30 22:42:35 +000010411 &TransArgs);
10412}
10413
10414template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010415ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010416TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +000010417 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000010418 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000010419 QualType BaseType;
10420 if (!Old->isImplicitAccess()) {
10421 Base = getDerived().TransformExpr(Old->getBase());
10422 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010423 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010424 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +000010425 Old->isArrow());
10426 if (Base.isInvalid())
10427 return ExprError();
10428 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +000010429 } else {
10430 BaseType = getDerived().TransformType(Old->getBaseType());
10431 }
John McCall10eae182009-11-30 22:42:35 +000010432
Douglas Gregor0da1d432011-02-28 20:01:57 +000010433 NestedNameSpecifierLoc QualifierLoc;
10434 if (Old->getQualifierLoc()) {
10435 QualifierLoc
10436 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
10437 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010438 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000010439 }
10440
Abramo Bagnara7945c982012-01-27 09:46:47 +000010441 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
10442
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010443 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +000010444 Sema::LookupOrdinaryName);
10445
10446 // Transform all the decls.
10447 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
10448 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010449 NamedDecl *InstD = static_cast<NamedDecl*>(
10450 getDerived().TransformDecl(Old->getMemberLoc(),
10451 *I));
John McCall84d87672009-12-10 09:41:52 +000010452 if (!InstD) {
10453 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
10454 // This can happen because of dependent hiding.
10455 if (isa<UsingShadowDecl>(*I))
10456 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +000010457 else {
10458 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +000010459 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +000010460 }
John McCall84d87672009-12-10 09:41:52 +000010461 }
John McCall10eae182009-11-30 22:42:35 +000010462
10463 // Expand using declarations.
10464 if (isa<UsingDecl>(InstD)) {
10465 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +000010466 for (auto *I : UD->shadows())
10467 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +000010468 continue;
10469 }
10470
10471 R.addDecl(InstD);
10472 }
10473
10474 R.resolveKind();
10475
Douglas Gregor9262f472010-04-27 18:19:34 +000010476 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +000010477 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +000010478 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +000010479 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +000010480 Old->getMemberLoc(),
10481 Old->getNamingClass()));
10482 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +000010483 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010484
Douglas Gregorda7be082010-04-27 16:10:10 +000010485 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +000010486 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010487
John McCall10eae182009-11-30 22:42:35 +000010488 TemplateArgumentListInfo TransArgs;
10489 if (Old->hasExplicitTemplateArgs()) {
10490 TransArgs.setLAngleLoc(Old->getLAngleLoc());
10491 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010492 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
10493 Old->getNumTemplateArgs(),
10494 TransArgs))
10495 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000010496 }
John McCall38836f02010-01-15 08:34:02 +000010497
10498 // FIXME: to do this check properly, we will need to preserve the
10499 // first-qualifier-in-scope here, just in case we had a dependent
10500 // base (and therefore couldn't do the check) and a
10501 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +000010502 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +000010503
John McCallb268a282010-08-23 23:25:46 +000010504 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010505 BaseType,
John McCall10eae182009-11-30 22:42:35 +000010506 Old->getOperatorLoc(),
10507 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +000010508 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010509 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +000010510 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +000010511 R,
10512 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +000010513 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +000010514}
10515
10516template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010517ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010518TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +000010519 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010520 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
10521 if (SubExpr.isInvalid())
10522 return ExprError();
10523
10524 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010525 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010526
10527 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
10528}
10529
10530template<typename Derived>
10531ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010532TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010533 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
10534 if (Pattern.isInvalid())
10535 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010536
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010537 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010538 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010539
Douglas Gregorb8840002011-01-14 21:20:45 +000010540 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
10541 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010542}
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010543
10544template<typename Derived>
10545ExprResult
10546TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
10547 // If E is not value-dependent, then nothing will change when we transform it.
10548 // Note: This is an instantiation-centric view.
10549 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010550 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010551
Richard Smithd784e682015-09-23 21:41:42 +000010552 EnterExpressionEvaluationContext Unevaluated(getSema(), Sema::Unevaluated);
Chad Rosier1dcde962012-08-08 18:46:20 +000010553
Richard Smithd784e682015-09-23 21:41:42 +000010554 ArrayRef<TemplateArgument> PackArgs;
10555 TemplateArgument ArgStorage;
Chad Rosier1dcde962012-08-08 18:46:20 +000010556
Richard Smithd784e682015-09-23 21:41:42 +000010557 // Find the argument list to transform.
10558 if (E->isPartiallySubstituted()) {
10559 PackArgs = E->getPartialArguments();
10560 } else if (E->isValueDependent()) {
10561 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
10562 bool ShouldExpand = false;
10563 bool RetainExpansion = false;
10564 Optional<unsigned> NumExpansions;
10565 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
10566 Unexpanded,
10567 ShouldExpand, RetainExpansion,
10568 NumExpansions))
10569 return ExprError();
10570
10571 // If we need to expand the pack, build a template argument from it and
10572 // expand that.
10573 if (ShouldExpand) {
10574 auto *Pack = E->getPack();
10575 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
10576 ArgStorage = getSema().Context.getPackExpansionType(
10577 getSema().Context.getTypeDeclType(TTPD), None);
10578 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
10579 ArgStorage = TemplateArgument(TemplateName(TTPD), None);
10580 } else {
10581 auto *VD = cast<ValueDecl>(Pack);
10582 ExprResult DRE = getSema().BuildDeclRefExpr(VD, VD->getType(),
10583 VK_RValue, E->getPackLoc());
10584 if (DRE.isInvalid())
10585 return ExprError();
10586 ArgStorage = new (getSema().Context) PackExpansionExpr(
10587 getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
10588 }
10589 PackArgs = ArgStorage;
10590 }
10591 }
10592
10593 // If we're not expanding the pack, just transform the decl.
10594 if (!PackArgs.size()) {
10595 auto *Pack = cast_or_null<NamedDecl>(
10596 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010597 if (!Pack)
10598 return ExprError();
Richard Smithd784e682015-09-23 21:41:42 +000010599 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
10600 E->getPackLoc(),
10601 E->getRParenLoc(), None, None);
10602 }
10603
10604 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
10605 E->getPackLoc());
10606 {
10607 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
10608 typedef TemplateArgumentLocInventIterator<
10609 Derived, const TemplateArgument*> PackLocIterator;
10610 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
10611 PackLocIterator(*this, PackArgs.end()),
10612 TransformedPackArgs, /*Uneval*/true))
10613 return ExprError();
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010614 }
10615
Richard Smithd784e682015-09-23 21:41:42 +000010616 SmallVector<TemplateArgument, 8> Args;
10617 bool PartialSubstitution = false;
10618 for (auto &Loc : TransformedPackArgs.arguments()) {
10619 Args.push_back(Loc.getArgument());
10620 if (Loc.getArgument().isPackExpansion())
10621 PartialSubstitution = true;
10622 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010623
Richard Smithd784e682015-09-23 21:41:42 +000010624 if (PartialSubstitution)
10625 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
10626 E->getPackLoc(),
10627 E->getRParenLoc(), None, Args);
10628
10629 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
Chad Rosier1dcde962012-08-08 18:46:20 +000010630 E->getPackLoc(), E->getRParenLoc(),
Richard Smithd784e682015-09-23 21:41:42 +000010631 Args.size(), None);
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010632}
10633
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010634template<typename Derived>
10635ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010636TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
10637 SubstNonTypeTemplateParmPackExpr *E) {
10638 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010639 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010640}
10641
10642template<typename Derived>
10643ExprResult
John McCall7c454bb2011-07-15 05:09:51 +000010644TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
10645 SubstNonTypeTemplateParmExpr *E) {
10646 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010647 return E;
John McCall7c454bb2011-07-15 05:09:51 +000010648}
10649
10650template<typename Derived>
10651ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +000010652TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
10653 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010654 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +000010655}
10656
10657template<typename Derived>
10658ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +000010659TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
10660 MaterializeTemporaryExpr *E) {
10661 return getDerived().TransformExpr(E->GetTemporaryExpr());
10662}
Chad Rosier1dcde962012-08-08 18:46:20 +000010663
Douglas Gregorfe314812011-06-21 17:03:29 +000010664template<typename Derived>
10665ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +000010666TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
10667 Expr *Pattern = E->getPattern();
10668
10669 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10670 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
10671 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10672
10673 // Determine whether the set of unexpanded parameter packs can and should
10674 // be expanded.
10675 bool Expand = true;
10676 bool RetainExpansion = false;
10677 Optional<unsigned> NumExpansions;
10678 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
10679 Pattern->getSourceRange(),
10680 Unexpanded,
10681 Expand, RetainExpansion,
10682 NumExpansions))
10683 return true;
10684
10685 if (!Expand) {
10686 // Do not expand any packs here, just transform and rebuild a fold
10687 // expression.
10688 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10689
10690 ExprResult LHS =
10691 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
10692 if (LHS.isInvalid())
10693 return true;
10694
10695 ExprResult RHS =
10696 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
10697 if (RHS.isInvalid())
10698 return true;
10699
10700 if (!getDerived().AlwaysRebuild() &&
10701 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
10702 return E;
10703
10704 return getDerived().RebuildCXXFoldExpr(
10705 E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
10706 RHS.get(), E->getLocEnd());
10707 }
10708
10709 // The transform has determined that we should perform an elementwise
10710 // expansion of the pattern. Do so.
10711 ExprResult Result = getDerived().TransformExpr(E->getInit());
10712 if (Result.isInvalid())
10713 return true;
10714 bool LeftFold = E->isLeftFold();
10715
10716 // If we're retaining an expansion for a right fold, it is the innermost
10717 // component and takes the init (if any).
10718 if (!LeftFold && RetainExpansion) {
10719 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10720
10721 ExprResult Out = getDerived().TransformExpr(Pattern);
10722 if (Out.isInvalid())
10723 return true;
10724
10725 Result = getDerived().RebuildCXXFoldExpr(
10726 E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
10727 Result.get(), E->getLocEnd());
10728 if (Result.isInvalid())
10729 return true;
10730 }
10731
10732 for (unsigned I = 0; I != *NumExpansions; ++I) {
10733 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
10734 getSema(), LeftFold ? I : *NumExpansions - I - 1);
10735 ExprResult Out = getDerived().TransformExpr(Pattern);
10736 if (Out.isInvalid())
10737 return true;
10738
10739 if (Out.get()->containsUnexpandedParameterPack()) {
10740 // We still have a pack; retain a pack expansion for this slice.
10741 Result = getDerived().RebuildCXXFoldExpr(
10742 E->getLocStart(),
10743 LeftFold ? Result.get() : Out.get(),
10744 E->getOperator(), E->getEllipsisLoc(),
10745 LeftFold ? Out.get() : Result.get(),
10746 E->getLocEnd());
10747 } else if (Result.isUsable()) {
10748 // We've got down to a single element; build a binary operator.
10749 Result = getDerived().RebuildBinaryOperator(
10750 E->getEllipsisLoc(), E->getOperator(),
10751 LeftFold ? Result.get() : Out.get(),
10752 LeftFold ? Out.get() : Result.get());
10753 } else
10754 Result = Out;
10755
10756 if (Result.isInvalid())
10757 return true;
10758 }
10759
10760 // If we're retaining an expansion for a left fold, it is the outermost
10761 // component and takes the complete expansion so far as its init (if any).
10762 if (LeftFold && RetainExpansion) {
10763 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10764
10765 ExprResult Out = getDerived().TransformExpr(Pattern);
10766 if (Out.isInvalid())
10767 return true;
10768
10769 Result = getDerived().RebuildCXXFoldExpr(
10770 E->getLocStart(), Result.get(),
10771 E->getOperator(), E->getEllipsisLoc(),
10772 Out.get(), E->getLocEnd());
10773 if (Result.isInvalid())
10774 return true;
10775 }
10776
10777 // If we had no init and an empty pack, and we're not retaining an expansion,
10778 // then produce a fallback value or error.
10779 if (Result.isUnset())
10780 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
10781 E->getOperator());
10782
10783 return Result;
10784}
10785
10786template<typename Derived>
10787ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +000010788TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
10789 CXXStdInitializerListExpr *E) {
10790 return getDerived().TransformExpr(E->getSubExpr());
10791}
10792
10793template<typename Derived>
10794ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010795TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010796 return SemaRef.MaybeBindToTemporary(E);
10797}
10798
10799template<typename Derived>
10800ExprResult
10801TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010802 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010803}
10804
10805template<typename Derived>
10806ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +000010807TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
10808 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
10809 if (SubExpr.isInvalid())
10810 return ExprError();
10811
10812 if (!getDerived().AlwaysRebuild() &&
10813 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010814 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +000010815
10816 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +000010817}
10818
10819template<typename Derived>
10820ExprResult
10821TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
10822 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010823 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010824 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010825 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000010826 /*IsCall=*/false, Elements, &ArgChanged))
10827 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010828
Ted Kremeneke65b0862012-03-06 20:05:56 +000010829 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10830 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000010831
Ted Kremeneke65b0862012-03-06 20:05:56 +000010832 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
10833 Elements.data(),
10834 Elements.size());
10835}
10836
10837template<typename Derived>
10838ExprResult
10839TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +000010840 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010841 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010842 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010843 bool ArgChanged = false;
10844 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
10845 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +000010846
Ted Kremeneke65b0862012-03-06 20:05:56 +000010847 if (OrigElement.isPackExpansion()) {
10848 // This key/value element is a pack expansion.
10849 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10850 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
10851 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
10852 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10853
10854 // Determine whether the set of unexpanded parameter packs can
10855 // and should be expanded.
10856 bool Expand = true;
10857 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010858 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
10859 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010860 SourceRange PatternRange(OrigElement.Key->getLocStart(),
10861 OrigElement.Value->getLocEnd());
10862 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
10863 PatternRange,
10864 Unexpanded,
10865 Expand, RetainExpansion,
10866 NumExpansions))
10867 return ExprError();
10868
10869 if (!Expand) {
10870 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000010871 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +000010872 // expansion.
10873 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10874 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10875 if (Key.isInvalid())
10876 return ExprError();
10877
10878 if (Key.get() != OrigElement.Key)
10879 ArgChanged = true;
10880
10881 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10882 if (Value.isInvalid())
10883 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010884
Ted Kremeneke65b0862012-03-06 20:05:56 +000010885 if (Value.get() != OrigElement.Value)
10886 ArgChanged = true;
10887
Chad Rosier1dcde962012-08-08 18:46:20 +000010888 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010889 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
10890 };
10891 Elements.push_back(Expansion);
10892 continue;
10893 }
10894
10895 // Record right away that the argument was changed. This needs
10896 // to happen even if the array expands to nothing.
10897 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010898
Ted Kremeneke65b0862012-03-06 20:05:56 +000010899 // The transform has determined that we should perform an elementwise
10900 // expansion of the pattern. Do so.
10901 for (unsigned I = 0; I != *NumExpansions; ++I) {
10902 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10903 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10904 if (Key.isInvalid())
10905 return ExprError();
10906
10907 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10908 if (Value.isInvalid())
10909 return ExprError();
10910
Chad Rosier1dcde962012-08-08 18:46:20 +000010911 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010912 Key.get(), Value.get(), SourceLocation(), NumExpansions
10913 };
10914
10915 // If any unexpanded parameter packs remain, we still have a
10916 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +000010917 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +000010918 if (Key.get()->containsUnexpandedParameterPack() ||
10919 Value.get()->containsUnexpandedParameterPack())
10920 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +000010921
Ted Kremeneke65b0862012-03-06 20:05:56 +000010922 Elements.push_back(Element);
10923 }
10924
Richard Smith9467be42014-06-06 17:33:35 +000010925 // FIXME: Retain a pack expansion if RetainExpansion is true.
10926
Ted Kremeneke65b0862012-03-06 20:05:56 +000010927 // We've finished with this pack expansion.
10928 continue;
10929 }
10930
10931 // Transform and check key.
10932 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10933 if (Key.isInvalid())
10934 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010935
Ted Kremeneke65b0862012-03-06 20:05:56 +000010936 if (Key.get() != OrigElement.Key)
10937 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010938
Ted Kremeneke65b0862012-03-06 20:05:56 +000010939 // Transform and check value.
10940 ExprResult Value
10941 = getDerived().TransformExpr(OrigElement.Value);
10942 if (Value.isInvalid())
10943 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010944
Ted Kremeneke65b0862012-03-06 20:05:56 +000010945 if (Value.get() != OrigElement.Value)
10946 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010947
10948 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +000010949 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +000010950 };
10951 Elements.push_back(Element);
10952 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010953
Ted Kremeneke65b0862012-03-06 20:05:56 +000010954 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10955 return SemaRef.MaybeBindToTemporary(E);
10956
10957 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
Craig Topperd4336e02015-12-24 23:58:15 +000010958 Elements);
Douglas Gregora16548e2009-08-11 05:31:07 +000010959}
10960
Mike Stump11289f42009-09-09 15:08:12 +000010961template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010962ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010963TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +000010964 TypeSourceInfo *EncodedTypeInfo
10965 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
10966 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010967 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010968
Douglas Gregora16548e2009-08-11 05:31:07 +000010969 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +000010970 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010971 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010972
10973 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +000010974 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000010975 E->getRParenLoc());
10976}
Mike Stump11289f42009-09-09 15:08:12 +000010977
Douglas Gregora16548e2009-08-11 05:31:07 +000010978template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +000010979ExprResult TreeTransform<Derived>::
10980TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +000010981 // This is a kind of implicit conversion, and it needs to get dropped
10982 // and recomputed for the same general reasons that ImplicitCastExprs
10983 // do, as well a more specific one: this expression is only valid when
10984 // it appears *immediately* as an argument expression.
10985 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +000010986}
10987
10988template<typename Derived>
10989ExprResult TreeTransform<Derived>::
10990TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +000010991 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +000010992 = getDerived().TransformType(E->getTypeInfoAsWritten());
10993 if (!TSInfo)
10994 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010995
John McCall31168b02011-06-15 23:02:42 +000010996 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +000010997 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +000010998 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010999
John McCall31168b02011-06-15 23:02:42 +000011000 if (!getDerived().AlwaysRebuild() &&
11001 TSInfo == E->getTypeInfoAsWritten() &&
11002 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011003 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011004
John McCall31168b02011-06-15 23:02:42 +000011005 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000011006 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000011007 Result.get());
11008}
11009
11010template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011011ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011012TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011013 // Transform arguments.
11014 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011015 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000011016 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000011017 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000011018 &ArgChanged))
11019 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011020
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011021 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
11022 // Class message: transform the receiver type.
11023 TypeSourceInfo *ReceiverTypeInfo
11024 = getDerived().TransformType(E->getClassReceiverTypeInfo());
11025 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000011026 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011027
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011028 // If nothing changed, just retain the existing message send.
11029 if (!getDerived().AlwaysRebuild() &&
11030 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011031 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011032
11033 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011034 SmallVector<SourceLocation, 16> SelLocs;
11035 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011036 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
11037 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011038 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011039 E->getMethodDecl(),
11040 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011041 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011042 E->getRightLoc());
11043 }
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011044 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
11045 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
11046 // Build a new class message send to 'super'.
11047 SmallVector<SourceLocation, 16> SelLocs;
11048 E->getSelectorLocs(SelLocs);
11049 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
11050 E->getSelector(),
11051 SelLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +000011052 E->getReceiverType(),
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011053 E->getMethodDecl(),
11054 E->getLeftLoc(),
11055 Args,
11056 E->getRightLoc());
11057 }
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011058
11059 // Instance message: transform the receiver
11060 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
11061 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000011062 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011063 = getDerived().TransformExpr(E->getInstanceReceiver());
11064 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011065 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011066
11067 // If nothing changed, just retain the existing message send.
11068 if (!getDerived().AlwaysRebuild() &&
11069 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011070 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000011071
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011072 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011073 SmallVector<SourceLocation, 16> SelLocs;
11074 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000011075 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011076 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011077 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011078 E->getMethodDecl(),
11079 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011080 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011081 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000011082}
11083
Mike Stump11289f42009-09-09 15:08:12 +000011084template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011085ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011086TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011087 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011088}
11089
Mike Stump11289f42009-09-09 15:08:12 +000011090template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011091ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011092TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011093 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011094}
11095
Mike Stump11289f42009-09-09 15:08:12 +000011096template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011097ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011098TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000011099 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011100 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000011101 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011102 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000011103
11104 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000011105
Douglas Gregord51d90d2010-04-26 20:11:03 +000011106 // If nothing changed, just retain the existing expression.
11107 if (!getDerived().AlwaysRebuild() &&
11108 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011109 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011110
John McCallb268a282010-08-23 23:25:46 +000011111 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000011112 E->getLocation(),
11113 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000011114}
11115
Mike Stump11289f42009-09-09 15:08:12 +000011116template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011117ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011118TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000011119 // 'super' and types never change. Property never changes. Just
11120 // retain the existing expression.
11121 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011122 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011123
Douglas Gregor9faee212010-04-26 20:47:02 +000011124 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011125 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000011126 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011127 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011128
Douglas Gregor9faee212010-04-26 20:47:02 +000011129 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000011130
Douglas Gregor9faee212010-04-26 20:47:02 +000011131 // If nothing changed, just retain the existing expression.
11132 if (!getDerived().AlwaysRebuild() &&
11133 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011134 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011135
John McCallb7bd14f2010-12-02 01:19:52 +000011136 if (E->isExplicitProperty())
11137 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
11138 E->getExplicitProperty(),
11139 E->getLocation());
11140
11141 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000011142 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000011143 E->getImplicitPropertyGetter(),
11144 E->getImplicitPropertySetter(),
11145 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000011146}
11147
Mike Stump11289f42009-09-09 15:08:12 +000011148template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011149ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000011150TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
11151 // Transform the base expression.
11152 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
11153 if (Base.isInvalid())
11154 return ExprError();
11155
11156 // Transform the key expression.
11157 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
11158 if (Key.isInvalid())
11159 return ExprError();
11160
11161 // If nothing changed, just retain the existing expression.
11162 if (!getDerived().AlwaysRebuild() &&
11163 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011164 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011165
Chad Rosier1dcde962012-08-08 18:46:20 +000011166 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000011167 Base.get(), Key.get(),
11168 E->getAtIndexMethodDecl(),
11169 E->setAtIndexMethodDecl());
11170}
11171
11172template<typename Derived>
11173ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011174TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000011175 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011176 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000011177 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011178 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011179
Douglas Gregord51d90d2010-04-26 20:11:03 +000011180 // If nothing changed, just retain the existing expression.
11181 if (!getDerived().AlwaysRebuild() &&
11182 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011183 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011184
John McCallb268a282010-08-23 23:25:46 +000011185 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000011186 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000011187 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000011188}
11189
Mike Stump11289f42009-09-09 15:08:12 +000011190template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011191ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011192TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011193 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011194 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000011195 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000011196 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000011197 SubExprs, &ArgumentChanged))
11198 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011199
Douglas Gregora16548e2009-08-11 05:31:07 +000011200 if (!getDerived().AlwaysRebuild() &&
11201 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011202 return E;
Mike Stump11289f42009-09-09 15:08:12 +000011203
Douglas Gregora16548e2009-08-11 05:31:07 +000011204 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011205 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000011206 E->getRParenLoc());
11207}
11208
Mike Stump11289f42009-09-09 15:08:12 +000011209template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011210ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000011211TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
11212 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
11213 if (SrcExpr.isInvalid())
11214 return ExprError();
11215
11216 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
11217 if (!Type)
11218 return ExprError();
11219
11220 if (!getDerived().AlwaysRebuild() &&
11221 Type == E->getTypeSourceInfo() &&
11222 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011223 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000011224
11225 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
11226 SrcExpr.get(), Type,
11227 E->getRParenLoc());
11228}
11229
11230template<typename Derived>
11231ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011232TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000011233 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000011234
Craig Topperc3ec1492014-05-26 06:22:03 +000011235 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000011236 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
11237
11238 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000011239 blockScope->TheDecl->setBlockMissingReturnType(
11240 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000011241
Chris Lattner01cf8db2011-07-20 06:58:45 +000011242 SmallVector<ParmVarDecl*, 4> params;
11243 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000011244
John McCallc8e321d2016-03-01 02:09:25 +000011245 const FunctionProtoType *exprFunctionType = E->getFunctionType();
11246
Fariborz Jahanian1babe772010-07-09 18:44:02 +000011247 // Parameter substitution.
John McCallc8e321d2016-03-01 02:09:25 +000011248 Sema::ExtParameterInfoBuilder extParamInfos;
John McCall490112f2011-02-04 18:33:18 +000011249 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
11250 oldBlock->param_begin(),
11251 oldBlock->param_size(),
John McCallc8e321d2016-03-01 02:09:25 +000011252 nullptr,
11253 exprFunctionType->getExtParameterInfosOrNull(),
11254 paramTypes, &params,
11255 extParamInfos)) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011256 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011257 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011258 }
John McCall490112f2011-02-04 18:33:18 +000011259
Eli Friedman34b49062012-01-26 03:00:14 +000011260 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000011261 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000011262
John McCallc8e321d2016-03-01 02:09:25 +000011263 auto epi = exprFunctionType->getExtProtoInfo();
11264 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
11265
Jordan Rose5c382722013-03-08 21:51:21 +000011266 QualType functionType =
John McCallc8e321d2016-03-01 02:09:25 +000011267 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
John McCall490112f2011-02-04 18:33:18 +000011268 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000011269
11270 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000011271 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000011272 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000011273
11274 if (!oldBlock->blockMissingReturnType()) {
11275 blockScope->HasImplicitReturnType = false;
11276 blockScope->ReturnType = exprResultType;
11277 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011278
John McCall3882ace2011-01-05 12:14:39 +000011279 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000011280 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011281 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011282 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000011283 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011284 }
John McCall3882ace2011-01-05 12:14:39 +000011285
John McCall490112f2011-02-04 18:33:18 +000011286#ifndef NDEBUG
11287 // In builds with assertions, make sure that we captured everything we
11288 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011289 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000011290 for (const auto &I : oldBlock->captures()) {
11291 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000011292
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011293 // Ignore parameter packs.
11294 if (isa<ParmVarDecl>(oldCapture) &&
11295 cast<ParmVarDecl>(oldCapture)->isParameterPack())
11296 continue;
John McCall490112f2011-02-04 18:33:18 +000011297
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011298 VarDecl *newCapture =
11299 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
11300 oldCapture));
11301 assert(blockScope->CaptureMap.count(newCapture));
11302 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000011303 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000011304 }
11305#endif
11306
11307 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000011308 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000011309}
11310
Mike Stump11289f42009-09-09 15:08:12 +000011311template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011312ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000011313TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000011314 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000011315}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000011316
11317template<typename Derived>
11318ExprResult
11319TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011320 QualType RetTy = getDerived().TransformType(E->getType());
11321 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011322 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011323 SubExprs.reserve(E->getNumSubExprs());
11324 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
11325 SubExprs, &ArgumentChanged))
11326 return ExprError();
11327
11328 if (!getDerived().AlwaysRebuild() &&
11329 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011330 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011331
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011332 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011333 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000011334}
Chad Rosier1dcde962012-08-08 18:46:20 +000011335
Douglas Gregora16548e2009-08-11 05:31:07 +000011336//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000011337// Type reconstruction
11338//===----------------------------------------------------------------------===//
11339
Mike Stump11289f42009-09-09 15:08:12 +000011340template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000011341QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
11342 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000011343 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011344 getDerived().getBaseEntity());
11345}
11346
Mike Stump11289f42009-09-09 15:08:12 +000011347template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000011348QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
11349 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000011350 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011351 getDerived().getBaseEntity());
11352}
11353
Mike Stump11289f42009-09-09 15:08:12 +000011354template<typename Derived>
11355QualType
John McCall70dd5f62009-10-30 00:06:24 +000011356TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
11357 bool WrittenAsLValue,
11358 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000011359 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000011360 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011361}
11362
11363template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011364QualType
John McCall70dd5f62009-10-30 00:06:24 +000011365TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
11366 QualType ClassType,
11367 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000011368 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
11369 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011370}
11371
11372template<typename Derived>
Douglas Gregor9bda6cf2015-07-07 03:58:14 +000011373QualType TreeTransform<Derived>::RebuildObjCObjectType(
11374 QualType BaseType,
11375 SourceLocation Loc,
11376 SourceLocation TypeArgsLAngleLoc,
11377 ArrayRef<TypeSourceInfo *> TypeArgs,
11378 SourceLocation TypeArgsRAngleLoc,
11379 SourceLocation ProtocolLAngleLoc,
11380 ArrayRef<ObjCProtocolDecl *> Protocols,
11381 ArrayRef<SourceLocation> ProtocolLocs,
11382 SourceLocation ProtocolRAngleLoc) {
11383 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
11384 TypeArgs, TypeArgsRAngleLoc,
11385 ProtocolLAngleLoc, Protocols, ProtocolLocs,
11386 ProtocolRAngleLoc,
11387 /*FailOnError=*/true);
11388}
11389
11390template<typename Derived>
11391QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
11392 QualType PointeeType,
11393 SourceLocation Star) {
11394 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
11395}
11396
11397template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011398QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000011399TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
11400 ArrayType::ArraySizeModifier SizeMod,
11401 const llvm::APInt *Size,
11402 Expr *SizeExpr,
11403 unsigned IndexTypeQuals,
11404 SourceRange BracketsRange) {
11405 if (SizeExpr || !Size)
11406 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
11407 IndexTypeQuals, BracketsRange,
11408 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000011409
11410 QualType Types[] = {
11411 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
11412 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
11413 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000011414 };
Craig Toppere5ce8312013-07-15 03:38:40 +000011415 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011416 QualType SizeType;
11417 for (unsigned I = 0; I != NumTypes; ++I)
11418 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
11419 SizeType = Types[I];
11420 break;
11421 }
Mike Stump11289f42009-09-09 15:08:12 +000011422
Eli Friedman9562f392012-01-25 23:20:27 +000011423 // Note that we can return a VariableArrayType here in the case where
11424 // the element type was a dependent VariableArrayType.
11425 IntegerLiteral *ArraySize
11426 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
11427 /*FIXME*/BracketsRange.getBegin());
11428 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011429 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000011430 getDerived().getBaseEntity());
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>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011436 ArrayType::ArraySizeModifier SizeMod,
11437 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000011438 unsigned IndexTypeQuals,
11439 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011440 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000011441 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011442}
11443
11444template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011445QualType
Mike Stump11289f42009-09-09 15:08:12 +000011446TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011447 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000011448 unsigned IndexTypeQuals,
11449 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011450 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000011451 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011452}
Mike Stump11289f42009-09-09 15:08:12 +000011453
Douglas Gregord6ff3322009-08-04 16:50:30 +000011454template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011455QualType
11456TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011457 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000011458 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011459 unsigned IndexTypeQuals,
11460 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011461 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000011462 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011463 IndexTypeQuals, BracketsRange);
11464}
11465
11466template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011467QualType
11468TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011469 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000011470 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011471 unsigned IndexTypeQuals,
11472 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011473 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000011474 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011475 IndexTypeQuals, BracketsRange);
11476}
11477
11478template<typename Derived>
11479QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +000011480 unsigned NumElements,
11481 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000011482 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000011483 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011484}
Mike Stump11289f42009-09-09 15:08:12 +000011485
Douglas Gregord6ff3322009-08-04 16:50:30 +000011486template<typename Derived>
11487QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
11488 unsigned NumElements,
11489 SourceLocation AttributeLoc) {
11490 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
11491 NumElements, true);
11492 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000011493 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
11494 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000011495 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011496}
Mike Stump11289f42009-09-09 15:08:12 +000011497
Douglas Gregord6ff3322009-08-04 16:50:30 +000011498template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011499QualType
11500TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000011501 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011502 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000011503 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011504}
Mike Stump11289f42009-09-09 15:08:12 +000011505
Douglas Gregord6ff3322009-08-04 16:50:30 +000011506template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000011507QualType TreeTransform<Derived>::RebuildFunctionProtoType(
11508 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000011509 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000011510 const FunctionProtoType::ExtProtoInfo &EPI) {
11511 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011512 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000011513 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000011514 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011515}
Mike Stump11289f42009-09-09 15:08:12 +000011516
Douglas Gregord6ff3322009-08-04 16:50:30 +000011517template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000011518QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
11519 return SemaRef.Context.getFunctionNoProtoType(T);
11520}
11521
11522template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +000011523QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
11524 assert(D && "no decl found");
11525 if (D->isInvalidDecl()) return QualType();
11526
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011527 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000011528 TypeDecl *Ty;
11529 if (isa<UsingDecl>(D)) {
11530 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000011531 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000011532 "UnresolvedUsingTypenameDecl transformed to non-typename using");
11533
11534 // A valid resolved using typename decl points to exactly one type decl.
11535 assert(++Using->shadow_begin() == Using->shadow_end());
11536 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000011537
John McCallb96ec562009-12-04 22:46:56 +000011538 } else {
11539 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
11540 "UnresolvedUsingTypenameDecl transformed to non-using decl");
11541 Ty = cast<UnresolvedUsingTypenameDecl>(D);
11542 }
11543
11544 return SemaRef.Context.getTypeDeclType(Ty);
11545}
11546
11547template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000011548QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
11549 SourceLocation Loc) {
11550 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011551}
11552
11553template<typename Derived>
11554QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
11555 return SemaRef.Context.getTypeOfType(Underlying);
11556}
11557
11558template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000011559QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
11560 SourceLocation Loc) {
11561 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011562}
11563
11564template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000011565QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
11566 UnaryTransformType::UTTKind UKind,
11567 SourceLocation Loc) {
11568 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
11569}
11570
11571template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000011572QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000011573 TemplateName Template,
11574 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000011575 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000011576 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011577}
Mike Stump11289f42009-09-09 15:08:12 +000011578
Douglas Gregor1135c352009-08-06 05:28:30 +000011579template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000011580QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
11581 SourceLocation KWLoc) {
11582 return SemaRef.BuildAtomicType(ValueType, KWLoc);
11583}
11584
11585template<typename Derived>
Xiuli Pan9c14e282016-01-09 12:53:17 +000011586QualType TreeTransform<Derived>::RebuildPipeType(QualType ValueType,
11587 SourceLocation KWLoc) {
11588 return SemaRef.BuildPipeType(ValueType, KWLoc);
11589}
11590
11591template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011592TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011593TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000011594 bool TemplateKW,
11595 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000011596 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000011597 Template);
11598}
11599
11600template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011601TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011602TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
11603 const IdentifierInfo &Name,
11604 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000011605 QualType ObjectType,
11606 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +000011607 UnqualifiedId TemplateName;
11608 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000011609 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000011610 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000011611 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011612 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000011613 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000011614 /*EnteringContext=*/false,
11615 Template);
John McCall31f82722010-11-12 08:19:04 +000011616 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000011617}
Mike Stump11289f42009-09-09 15:08:12 +000011618
Douglas Gregora16548e2009-08-11 05:31:07 +000011619template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000011620TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011621TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000011622 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000011623 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000011624 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000011625 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000011626 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000011627 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000011628 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000011629 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000011630 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000011631 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011632 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000011633 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000011634 /*EnteringContext=*/false,
11635 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000011636 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000011637}
Chad Rosier1dcde962012-08-08 18:46:20 +000011638
Douglas Gregor71395fa2009-11-04 00:56:37 +000011639template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011640ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000011641TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
11642 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000011643 Expr *OrigCallee,
11644 Expr *First,
11645 Expr *Second) {
11646 Expr *Callee = OrigCallee->IgnoreParenCasts();
11647 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000011648
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000011649 if (First->getObjectKind() == OK_ObjCProperty) {
11650 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
11651 if (BinaryOperator::isAssignmentOp(Opc))
11652 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
11653 First, Second);
11654 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
11655 if (Result.isInvalid())
11656 return ExprError();
11657 First = Result.get();
11658 }
11659
11660 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
11661 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
11662 if (Result.isInvalid())
11663 return ExprError();
11664 Second = Result.get();
11665 }
11666
Douglas Gregora16548e2009-08-11 05:31:07 +000011667 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000011668 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000011669 if (!First->getType()->isOverloadableType() &&
11670 !Second->getType()->isOverloadableType())
11671 return getSema().CreateBuiltinArraySubscriptExpr(First,
11672 Callee->getLocStart(),
11673 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000011674 } else if (Op == OO_Arrow) {
11675 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000011676 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
11677 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000011678 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011679 // The argument is not of overloadable type, so try to create a
11680 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000011681 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011682 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000011683
John McCallb268a282010-08-23 23:25:46 +000011684 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011685 }
11686 } else {
John McCallb268a282010-08-23 23:25:46 +000011687 if (!First->getType()->isOverloadableType() &&
11688 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011689 // Neither of the arguments is an overloadable type, so try to
11690 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000011691 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011692 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000011693 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000011694 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011695 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011696
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011697 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011698 }
11699 }
Mike Stump11289f42009-09-09 15:08:12 +000011700
11701 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000011702 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000011703 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000011704
John McCallb268a282010-08-23 23:25:46 +000011705 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000011706 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000011707 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000011708 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000011709 // If we've resolved this to a particular non-member function, just call
11710 // that function. If we resolved it to a member function,
11711 // CreateOverloaded* will find that function for us.
11712 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
11713 if (!isa<CXXMethodDecl>(ND))
11714 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000011715 }
Mike Stump11289f42009-09-09 15:08:12 +000011716
Douglas Gregora16548e2009-08-11 05:31:07 +000011717 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000011718 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000011719 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000011720
Douglas Gregora16548e2009-08-11 05:31:07 +000011721 // Create the overloaded operator invocation for unary operators.
11722 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000011723 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011724 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000011725 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011726 }
Mike Stump11289f42009-09-09 15:08:12 +000011727
Douglas Gregore9d62932011-07-15 16:25:15 +000011728 if (Op == OO_Subscript) {
11729 SourceLocation LBrace;
11730 SourceLocation RBrace;
11731
11732 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000011733 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000011734 LBrace = SourceLocation::getFromRawEncoding(
11735 NameLoc.CXXOperatorName.BeginOpNameLoc);
11736 RBrace = SourceLocation::getFromRawEncoding(
11737 NameLoc.CXXOperatorName.EndOpNameLoc);
11738 } else {
11739 LBrace = Callee->getLocStart();
11740 RBrace = OpLoc;
11741 }
11742
11743 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
11744 First, Second);
11745 }
Sebastian Redladba46e2009-10-29 20:17:01 +000011746
Douglas Gregora16548e2009-08-11 05:31:07 +000011747 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000011748 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011749 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000011750 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
11751 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011752 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011753
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011754 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011755}
Mike Stump11289f42009-09-09 15:08:12 +000011756
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011757template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000011758ExprResult
John McCallb268a282010-08-23 23:25:46 +000011759TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011760 SourceLocation OperatorLoc,
11761 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000011762 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011763 TypeSourceInfo *ScopeType,
11764 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000011765 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000011766 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000011767 QualType BaseType = Base->getType();
11768 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011769 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000011770 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000011771 !BaseType->getAs<PointerType>()->getPointeeType()
11772 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011773 // This pseudo-destructor expression is still a pseudo-destructor.
David Majnemerced8bdf2015-02-25 17:36:15 +000011774 return SemaRef.BuildPseudoDestructorExpr(
11775 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
11776 CCLoc, TildeLoc, Destroyed);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011777 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011778
Douglas Gregor678f90d2010-02-25 01:56:36 +000011779 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011780 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
11781 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
11782 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
11783 NameInfo.setNamedTypeInfo(DestroyedType);
11784
Richard Smith8e4a3862012-05-15 06:15:11 +000011785 // The scope type is now known to be a valid nested name specifier
11786 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000011787 if (ScopeType) {
11788 if (!ScopeType->getType()->getAs<TagType>()) {
11789 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
11790 diag::err_expected_class_or_namespace)
11791 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
11792 return ExprError();
11793 }
11794 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
11795 CCLoc);
11796 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011797
Abramo Bagnara7945c982012-01-27 09:46:47 +000011798 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000011799 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011800 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011801 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000011802 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011803 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +000011804 /*TemplateArgs*/ nullptr,
11805 /*S*/nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011806}
11807
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000011808template<typename Derived>
11809StmtResult
11810TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000011811 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000011812 CapturedDecl *CD = S->getCapturedDecl();
11813 unsigned NumParams = CD->getNumParams();
11814 unsigned ContextParamPos = CD->getContextParamPosition();
11815 SmallVector<Sema::CapturedParamNameType, 4> Params;
11816 for (unsigned I = 0; I < NumParams; ++I) {
11817 if (I != ContextParamPos) {
11818 Params.push_back(
11819 std::make_pair(
11820 CD->getParam(I)->getName(),
11821 getDerived().TransformType(CD->getParam(I)->getType())));
11822 } else {
11823 Params.push_back(std::make_pair(StringRef(), QualType()));
11824 }
11825 }
Craig Topperc3ec1492014-05-26 06:22:03 +000011826 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000011827 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000011828 StmtResult Body;
11829 {
11830 Sema::CompoundScopeRAII CompoundScope(getSema());
11831 Body = getDerived().TransformStmt(S->getCapturedStmt());
11832 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000011833
11834 if (Body.isInvalid()) {
11835 getSema().ActOnCapturedRegionError();
11836 return StmtError();
11837 }
11838
Nikola Smiljanic01a75982014-05-29 10:55:11 +000011839 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000011840}
11841
Douglas Gregord6ff3322009-08-04 16:50:30 +000011842} // end namespace clang
11843
Hans Wennborg59dbe862015-09-29 20:56:43 +000011844#endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H