blob: 7ed52ebb12aa5cf322949fab892e3f0d03f986dd [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
James Dennett2a4d13c2012-06-15 07:13:21 +00001754 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001755 ///
1756 /// By default, performs semantic analysis to build the new statement.
1757 /// Subclasses may override this routine to provide different behavior.
1758 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1759 Expr *object) {
1760 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1761 }
1762
James Dennett2a4d13c2012-06-15 07:13:21 +00001763 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001764 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001765 /// By default, performs semantic analysis to build the new statement.
1766 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001767 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001768 Expr *Object, Stmt *Body) {
1769 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001770 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001771
James Dennett2a4d13c2012-06-15 07:13:21 +00001772 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001773 ///
1774 /// By default, performs semantic analysis to build the new statement.
1775 /// Subclasses may override this routine to provide different behavior.
1776 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1777 Stmt *Body) {
1778 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1779 }
John McCall53848232011-07-27 01:07:15 +00001780
Douglas Gregorf68a5082010-04-22 23:10:45 +00001781 /// \brief Build a new Objective-C fast enumeration statement.
1782 ///
1783 /// By default, performs semantic analysis to build the new statement.
1784 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001785 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001786 Stmt *Element,
1787 Expr *Collection,
1788 SourceLocation RParenLoc,
1789 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001790 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001791 Element,
John McCallb268a282010-08-23 23:25:46 +00001792 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001793 RParenLoc);
1794 if (ForEachStmt.isInvalid())
1795 return StmtError();
1796
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001797 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001798 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001799
Douglas Gregorebe10102009-08-20 07:17:43 +00001800 /// \brief Build a new C++ exception declaration.
1801 ///
1802 /// By default, performs semantic analysis to build the new decaration.
1803 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001804 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001805 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001806 SourceLocation StartLoc,
1807 SourceLocation IdLoc,
1808 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001809 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001810 StartLoc, IdLoc, Id);
1811 if (Var)
1812 getSema().CurContext->addDecl(Var);
1813 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001814 }
1815
1816 /// \brief Build a new C++ catch statement.
1817 ///
1818 /// By default, performs semantic analysis to build the new statement.
1819 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001820 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001821 VarDecl *ExceptionDecl,
1822 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001823 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1824 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001825 }
Mike Stump11289f42009-09-09 15:08:12 +00001826
Douglas Gregorebe10102009-08-20 07:17:43 +00001827 /// \brief Build a new C++ try statement.
1828 ///
1829 /// By default, performs semantic analysis to build the new statement.
1830 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001831 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1832 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001833 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001834 }
Mike Stump11289f42009-09-09 15:08:12 +00001835
Richard Smith02e85f32011-04-14 22:09:26 +00001836 /// \brief Build a new C++0x range-based for statement.
1837 ///
1838 /// By default, performs semantic analysis to build the new statement.
1839 /// Subclasses may override this routine to provide different behavior.
1840 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
Richard Smith9f690bd2015-10-27 06:02:45 +00001841 SourceLocation CoawaitLoc,
Richard Smith02e85f32011-04-14 22:09:26 +00001842 SourceLocation ColonLoc,
Richard Smith01694c32016-03-20 10:33:40 +00001843 Stmt *Range, Stmt *Begin, Stmt *End,
Richard Smith02e85f32011-04-14 22:09:26 +00001844 Expr *Cond, Expr *Inc,
1845 Stmt *LoopVar,
1846 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001847 // If we've just learned that the range is actually an Objective-C
1848 // collection, treat this as an Objective-C fast enumeration loop.
1849 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1850 if (RangeStmt->isSingleDecl()) {
1851 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001852 if (RangeVar->isInvalidDecl())
1853 return StmtError();
1854
Douglas Gregorf7106af2013-04-08 18:40:13 +00001855 Expr *RangeExpr = RangeVar->getInit();
1856 if (!RangeExpr->isTypeDependent() &&
1857 RangeExpr->getType()->isObjCObjectPointerType())
1858 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1859 RParenLoc);
1860 }
1861 }
1862 }
1863
Richard Smithcfd53b42015-10-22 06:13:50 +00001864 return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, ColonLoc,
Richard Smith01694c32016-03-20 10:33:40 +00001865 Range, Begin, End,
Richard Smitha05b3b52012-09-20 21:52:32 +00001866 Cond, Inc, LoopVar, RParenLoc,
1867 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001868 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001869
1870 /// \brief Build a new C++0x range-based for statement.
1871 ///
1872 /// By default, performs semantic analysis to build the new statement.
1873 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001874 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001875 bool IsIfExists,
1876 NestedNameSpecifierLoc QualifierLoc,
1877 DeclarationNameInfo NameInfo,
1878 Stmt *Nested) {
1879 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1880 QualifierLoc, NameInfo, Nested);
1881 }
1882
Richard Smith02e85f32011-04-14 22:09:26 +00001883 /// \brief Attach body to a C++0x range-based for statement.
1884 ///
1885 /// By default, performs semantic analysis to finish the new statement.
1886 /// Subclasses may override this routine to provide different behavior.
1887 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1888 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1889 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001890
David Majnemerfad8f482013-10-15 09:33:02 +00001891 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00001892 Stmt *TryBlock, Stmt *Handler) {
1893 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001894 }
1895
David Majnemerfad8f482013-10-15 09:33:02 +00001896 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001897 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001898 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001899 }
1900
David Majnemerfad8f482013-10-15 09:33:02 +00001901 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
Nico Weberd64657f2015-03-09 02:47:59 +00001902 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001903 }
1904
Alexey Bataevec474782014-10-09 08:45:04 +00001905 /// \brief Build a new predefined expression.
1906 ///
1907 /// By default, performs semantic analysis to build the new expression.
1908 /// Subclasses may override this routine to provide different behavior.
1909 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
1910 PredefinedExpr::IdentType IT) {
1911 return getSema().BuildPredefinedExpr(Loc, IT);
1912 }
1913
Douglas Gregora16548e2009-08-11 05:31:07 +00001914 /// \brief Build a new expression that references a declaration.
1915 ///
1916 /// By default, performs semantic analysis to build the new expression.
1917 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001918 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001919 LookupResult &R,
1920 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001921 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1922 }
1923
1924
1925 /// \brief Build a new expression that references a declaration.
1926 ///
1927 /// By default, performs semantic analysis to build the new expression.
1928 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001929 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001930 ValueDecl *VD,
1931 const DeclarationNameInfo &NameInfo,
1932 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001933 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001934 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001935
1936 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001937
1938 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001939 }
Mike Stump11289f42009-09-09 15:08:12 +00001940
Douglas Gregora16548e2009-08-11 05:31:07 +00001941 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001942 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001943 /// By default, performs semantic analysis to build the new expression.
1944 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001945 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001946 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001947 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001948 }
1949
Douglas Gregorad8a3362009-09-04 17:36:40 +00001950 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001951 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001952 /// By default, performs semantic analysis to build the new expression.
1953 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001954 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001955 SourceLocation OperatorLoc,
1956 bool isArrow,
1957 CXXScopeSpec &SS,
1958 TypeSourceInfo *ScopeType,
1959 SourceLocation CCLoc,
1960 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001961 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001962
Douglas Gregora16548e2009-08-11 05:31:07 +00001963 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001964 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001965 /// By default, performs semantic analysis to build the new expression.
1966 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001967 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001968 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001969 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001970 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001971 }
Mike Stump11289f42009-09-09 15:08:12 +00001972
Douglas Gregor882211c2010-04-28 22:16:22 +00001973 /// \brief Build a new builtin offsetof expression.
1974 ///
1975 /// 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 RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Craig Topperb5518242015-10-22 04:59:59 +00001978 TypeSourceInfo *Type,
1979 ArrayRef<Sema::OffsetOfComponent> Components,
1980 SourceLocation RParenLoc) {
Douglas Gregor882211c2010-04-28 22:16:22 +00001981 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
Craig Topperb5518242015-10-22 04:59:59 +00001982 RParenLoc);
Douglas Gregor882211c2010-04-28 22:16:22 +00001983 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001984
1985 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001986 /// type argument.
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.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001990 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1991 SourceLocation OpLoc,
1992 UnaryExprOrTypeTrait ExprKind,
1993 SourceRange R) {
1994 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001995 }
1996
Peter Collingbournee190dee2011-03-11 19:24:49 +00001997 /// \brief Build a new sizeof, alignof or vec step expression with an
1998 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001999 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002000 /// By default, performs semantic analysis to build the new expression.
2001 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00002002 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
2003 UnaryExprOrTypeTrait ExprKind,
2004 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00002005 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00002006 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00002007 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002008 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002009
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002010 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002011 }
Mike Stump11289f42009-09-09 15:08:12 +00002012
Douglas Gregora16548e2009-08-11 05:31:07 +00002013 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00002014 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002015 /// By default, performs semantic analysis to build the new expression.
2016 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002017 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002018 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00002019 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002020 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002021 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00002022 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002023 RBracketLoc);
2024 }
2025
Alexey Bataev1a3320e2015-08-25 14:24:04 +00002026 /// \brief Build a new array section expression.
2027 ///
2028 /// By default, performs semantic analysis to build the new expression.
2029 /// Subclasses may override this routine to provide different behavior.
2030 ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc,
2031 Expr *LowerBound,
2032 SourceLocation ColonLoc, Expr *Length,
2033 SourceLocation RBracketLoc) {
2034 return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound,
2035 ColonLoc, Length, RBracketLoc);
2036 }
2037
Douglas Gregora16548e2009-08-11 05:31:07 +00002038 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00002039 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002040 /// By default, performs semantic analysis to build the new expression.
2041 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002042 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002043 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00002044 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00002045 Expr *ExecConfig = nullptr) {
2046 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002047 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00002048 }
2049
2050 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002051 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002052 /// By default, performs semantic analysis to build the new expression.
2053 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002054 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002055 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00002056 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002057 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002058 const DeclarationNameInfo &MemberNameInfo,
2059 ValueDecl *Member,
2060 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00002061 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00002062 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00002063 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
2064 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00002065 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00002066 // We have a reference to an unnamed field. This is always the
2067 // base of an anonymous struct/union member access, i.e. the
2068 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00002069 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00002070 assert(Member->getType()->isRecordType() &&
2071 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00002072
Richard Smithcab9a7d2011-10-26 19:06:56 +00002073 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002074 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00002075 QualifierLoc.getNestedNameSpecifier(),
2076 FoundDecl, Member);
2077 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002078 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002079 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00002080 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Aaron Ballmanf4cb2be2015-03-24 15:07:53 +00002081 MemberExpr *ME = new (getSema().Context)
2082 MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
2083 cast<FieldDecl>(Member)->getType(), VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002084 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00002085 }
Mike Stump11289f42009-09-09 15:08:12 +00002086
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002087 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00002088 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002089
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002090 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00002091 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00002092
John McCall16df1e52010-03-30 21:47:33 +00002093 // FIXME: this involves duplicating earlier analysis in a lot of
2094 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002095 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00002096 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00002097 R.resolveKind();
2098
John McCallb268a282010-08-23 23:25:46 +00002099 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002100 SS, TemplateKWLoc,
2101 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002102 R, ExplicitTemplateArgs,
2103 /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002104 }
Mike Stump11289f42009-09-09 15:08:12 +00002105
Douglas Gregora16548e2009-08-11 05:31:07 +00002106 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002107 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002108 /// By default, performs semantic analysis to build the new expression.
2109 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002110 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00002111 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00002112 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002113 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002114 }
2115
2116 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002117 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002118 /// By default, performs semantic analysis to build the new expression.
2119 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002120 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00002121 SourceLocation QuestionLoc,
2122 Expr *LHS,
2123 SourceLocation ColonLoc,
2124 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00002125 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
2126 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002127 }
2128
Douglas Gregora16548e2009-08-11 05:31:07 +00002129 /// \brief Build a new C-style cast 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 RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00002134 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002135 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002136 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00002137 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002138 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002139 }
Mike Stump11289f42009-09-09 15:08:12 +00002140
Douglas Gregora16548e2009-08-11 05:31:07 +00002141 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00002142 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002143 /// By default, performs semantic analysis to build the new expression.
2144 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002145 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00002146 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002147 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002148 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00002149 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002150 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002151 }
Mike Stump11289f42009-09-09 15:08:12 +00002152
Douglas Gregora16548e2009-08-11 05:31:07 +00002153 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002154 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002155 /// By default, performs semantic analysis to build the new expression.
2156 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002157 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00002158 SourceLocation OpLoc,
2159 SourceLocation AccessorLoc,
2160 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00002161
John McCall10eae182009-11-30 22:42:35 +00002162 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002163 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00002164 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00002165 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002166 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002167 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002168 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002169 /* TemplateArgs */ nullptr,
2170 /*S*/ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002171 }
Mike Stump11289f42009-09-09 15:08:12 +00002172
Douglas Gregora16548e2009-08-11 05:31:07 +00002173 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00002174 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002175 /// By default, performs semantic analysis to build the new expression.
2176 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002177 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00002178 MultiExprArg Inits,
2179 SourceLocation RBraceLoc,
2180 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00002181 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002182 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00002183 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002184 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002185
Douglas Gregord3d93062009-11-09 17:16:50 +00002186 // Patch in the result type we were given, which may have been computed
2187 // when the initial InitListExpr was built.
2188 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
2189 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002190 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002191 }
Mike Stump11289f42009-09-09 15:08:12 +00002192
Douglas Gregora16548e2009-08-11 05:31:07 +00002193 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00002194 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002195 /// By default, performs semantic analysis to build the new expression.
2196 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002197 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00002198 MultiExprArg ArrayExprs,
2199 SourceLocation EqualOrColonLoc,
2200 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002201 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00002202 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00002203 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002204 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002205 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002206 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002207
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002208 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002209 }
Mike Stump11289f42009-09-09 15:08:12 +00002210
Douglas Gregora16548e2009-08-11 05:31:07 +00002211 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00002212 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002213 /// By default, builds the implicit value initialization without performing
2214 /// any semantic analysis. Subclasses may override this routine to provide
2215 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002216 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002217 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00002218 }
Mike Stump11289f42009-09-09 15:08:12 +00002219
Douglas Gregora16548e2009-08-11 05:31:07 +00002220 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00002221 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002222 /// By default, performs semantic analysis to build the new expression.
2223 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002224 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002225 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002226 SourceLocation RParenLoc) {
2227 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002228 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002229 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002230 }
2231
2232 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002233 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002234 /// By default, performs semantic analysis to build the new expression.
2235 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002236 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00002237 MultiExprArg SubExprs,
2238 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002239 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002240 }
Mike Stump11289f42009-09-09 15:08:12 +00002241
Douglas Gregora16548e2009-08-11 05:31:07 +00002242 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00002243 ///
2244 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002245 /// rather than attempting to map the label statement itself.
2246 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002247 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002248 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002249 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002250 }
Mike Stump11289f42009-09-09 15:08:12 +00002251
Douglas Gregora16548e2009-08-11 05:31:07 +00002252 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002253 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002254 /// By default, performs semantic analysis to build the new expression.
2255 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002256 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002257 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002258 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002259 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002260 }
Mike Stump11289f42009-09-09 15:08:12 +00002261
Douglas Gregora16548e2009-08-11 05:31:07 +00002262 /// \brief Build a new __builtin_choose_expr expression.
2263 ///
2264 /// By default, performs semantic analysis to build the new expression.
2265 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002266 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002267 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002268 SourceLocation RParenLoc) {
2269 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002270 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002271 RParenLoc);
2272 }
Mike Stump11289f42009-09-09 15:08:12 +00002273
Peter Collingbourne91147592011-04-15 00:35:48 +00002274 /// \brief Build a new generic selection expression.
2275 ///
2276 /// By default, performs semantic analysis to build the new expression.
2277 /// Subclasses may override this routine to provide different behavior.
2278 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2279 SourceLocation DefaultLoc,
2280 SourceLocation RParenLoc,
2281 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002282 ArrayRef<TypeSourceInfo *> Types,
2283 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002284 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002285 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002286 }
2287
Douglas Gregora16548e2009-08-11 05:31:07 +00002288 /// \brief Build a new overloaded operator call expression.
2289 ///
2290 /// By default, performs semantic analysis to build the new expression.
2291 /// The semantic analysis provides the behavior of template instantiation,
2292 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002293 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002294 /// argument-dependent lookup, etc. Subclasses may override this routine to
2295 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002296 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002297 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002298 Expr *Callee,
2299 Expr *First,
2300 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002301
2302 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002303 /// reinterpret_cast.
2304 ///
2305 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002306 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002307 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002308 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002309 Stmt::StmtClass Class,
2310 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002311 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002312 SourceLocation RAngleLoc,
2313 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002314 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002315 SourceLocation RParenLoc) {
2316 switch (Class) {
2317 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002318 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002319 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002320 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002321
2322 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002323 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002324 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002325 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002326
Douglas Gregora16548e2009-08-11 05:31:07 +00002327 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002328 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002329 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002330 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002331 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002332
Douglas Gregora16548e2009-08-11 05:31:07 +00002333 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002334 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002335 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002336 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002337
Douglas Gregora16548e2009-08-11 05:31:07 +00002338 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002339 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002340 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002341 }
Mike Stump11289f42009-09-09 15:08:12 +00002342
Douglas Gregora16548e2009-08-11 05:31:07 +00002343 /// \brief Build a new C++ static_cast expression.
2344 ///
2345 /// By default, performs semantic analysis to build the new expression.
2346 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002347 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002348 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002349 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002350 SourceLocation RAngleLoc,
2351 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002352 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002353 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002354 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002355 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002356 SourceRange(LAngleLoc, RAngleLoc),
2357 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002358 }
2359
2360 /// \brief Build a new C++ dynamic_cast expression.
2361 ///
2362 /// By default, performs semantic analysis to build the new expression.
2363 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002364 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002365 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002366 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002367 SourceLocation RAngleLoc,
2368 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002369 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002370 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002371 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002372 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002373 SourceRange(LAngleLoc, RAngleLoc),
2374 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002375 }
2376
2377 /// \brief Build a new C++ reinterpret_cast expression.
2378 ///
2379 /// By default, performs semantic analysis to build the new expression.
2380 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002381 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002382 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002383 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002384 SourceLocation RAngleLoc,
2385 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002386 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002387 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002388 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002389 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002390 SourceRange(LAngleLoc, RAngleLoc),
2391 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002392 }
2393
2394 /// \brief Build a new C++ const_cast expression.
2395 ///
2396 /// By default, performs semantic analysis to build the new expression.
2397 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002398 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002399 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002400 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002401 SourceLocation RAngleLoc,
2402 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002403 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002404 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002405 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002406 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002407 SourceRange(LAngleLoc, RAngleLoc),
2408 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002409 }
Mike Stump11289f42009-09-09 15:08:12 +00002410
Douglas Gregora16548e2009-08-11 05:31:07 +00002411 /// \brief Build a new C++ functional-style cast expression.
2412 ///
2413 /// By default, performs semantic analysis to build the new expression.
2414 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002415 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2416 SourceLocation LParenLoc,
2417 Expr *Sub,
2418 SourceLocation RParenLoc) {
2419 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002420 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002421 RParenLoc);
2422 }
Mike Stump11289f42009-09-09 15:08:12 +00002423
Douglas Gregora16548e2009-08-11 05:31:07 +00002424 /// \brief Build a new C++ typeid(type) expression.
2425 ///
2426 /// By default, performs semantic analysis to build the new expression.
2427 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002428 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002429 SourceLocation TypeidLoc,
2430 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002431 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002432 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002433 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002434 }
Mike Stump11289f42009-09-09 15:08:12 +00002435
Francois Pichet9f4f2072010-09-08 12:20:18 +00002436
Douglas Gregora16548e2009-08-11 05:31:07 +00002437 /// \brief Build a new C++ typeid(expr) expression.
2438 ///
2439 /// By default, performs semantic analysis to build the new expression.
2440 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002441 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002442 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002443 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002444 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002445 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002446 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002447 }
2448
Francois Pichet9f4f2072010-09-08 12:20:18 +00002449 /// \brief Build a new C++ __uuidof(type) expression.
2450 ///
2451 /// By default, performs semantic analysis to build the new expression.
2452 /// Subclasses may override this routine to provide different behavior.
2453 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2454 SourceLocation TypeidLoc,
2455 TypeSourceInfo *Operand,
2456 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002457 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002458 RParenLoc);
2459 }
2460
2461 /// \brief Build a new C++ __uuidof(expr) expression.
2462 ///
2463 /// By default, performs semantic analysis to build the new expression.
2464 /// Subclasses may override this routine to provide different behavior.
2465 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2466 SourceLocation TypeidLoc,
2467 Expr *Operand,
2468 SourceLocation RParenLoc) {
2469 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2470 RParenLoc);
2471 }
2472
Douglas Gregora16548e2009-08-11 05:31:07 +00002473 /// \brief Build a new C++ "this" expression.
2474 ///
2475 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002476 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002477 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002478 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002479 QualType ThisType,
2480 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002481 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002482 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002483 }
2484
2485 /// \brief Build a new C++ throw expression.
2486 ///
2487 /// By default, performs semantic analysis to build the new expression.
2488 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002489 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2490 bool IsThrownVariableInScope) {
2491 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002492 }
2493
2494 /// \brief Build a new C++ default-argument expression.
2495 ///
2496 /// By default, builds a new default-argument expression, which does not
2497 /// require any semantic analysis. Subclasses may override this routine to
2498 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002499 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002500 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002501 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002502 }
2503
Richard Smith852c9db2013-04-20 22:23:05 +00002504 /// \brief Build a new C++11 default-initialization expression.
2505 ///
2506 /// By default, builds a new default field initialization expression, which
2507 /// does not require any semantic analysis. Subclasses may override this
2508 /// routine to provide different behavior.
2509 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2510 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002511 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002512 }
2513
Douglas Gregora16548e2009-08-11 05:31:07 +00002514 /// \brief Build a new C++ zero-initialization expression.
2515 ///
2516 /// By default, performs semantic analysis to build the new expression.
2517 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002518 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2519 SourceLocation LParenLoc,
2520 SourceLocation RParenLoc) {
2521 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002522 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002523 }
Mike Stump11289f42009-09-09 15:08:12 +00002524
Douglas Gregora16548e2009-08-11 05:31:07 +00002525 /// \brief Build a new C++ "new" expression.
2526 ///
2527 /// By default, performs semantic analysis to build the new expression.
2528 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002529 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002530 bool UseGlobal,
2531 SourceLocation PlacementLParen,
2532 MultiExprArg PlacementArgs,
2533 SourceLocation PlacementRParen,
2534 SourceRange TypeIdParens,
2535 QualType AllocatedType,
2536 TypeSourceInfo *AllocatedTypeInfo,
2537 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002538 SourceRange DirectInitRange,
2539 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002540 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002541 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002542 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002543 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002544 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002545 AllocatedType,
2546 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002547 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002548 DirectInitRange,
2549 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002550 }
Mike Stump11289f42009-09-09 15:08:12 +00002551
Douglas Gregora16548e2009-08-11 05:31:07 +00002552 /// \brief Build a new C++ "delete" expression.
2553 ///
2554 /// By default, performs semantic analysis to build the new expression.
2555 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002556 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002557 bool IsGlobalDelete,
2558 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002559 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002560 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002561 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002562 }
Mike Stump11289f42009-09-09 15:08:12 +00002563
Douglas Gregor29c42f22012-02-24 07:38:34 +00002564 /// \brief Build a new type trait expression.
2565 ///
2566 /// By default, performs semantic analysis to build the new expression.
2567 /// Subclasses may override this routine to provide different behavior.
2568 ExprResult RebuildTypeTrait(TypeTrait Trait,
2569 SourceLocation StartLoc,
2570 ArrayRef<TypeSourceInfo *> Args,
2571 SourceLocation RParenLoc) {
2572 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2573 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002574
John Wiegley6242b6a2011-04-28 00:16:57 +00002575 /// \brief Build a new array type trait expression.
2576 ///
2577 /// By default, performs semantic analysis to build the new expression.
2578 /// Subclasses may override this routine to provide different behavior.
2579 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2580 SourceLocation StartLoc,
2581 TypeSourceInfo *TSInfo,
2582 Expr *DimExpr,
2583 SourceLocation RParenLoc) {
2584 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2585 }
2586
John Wiegleyf9f65842011-04-25 06:54:41 +00002587 /// \brief Build a new expression 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 RebuildExpressionTrait(ExpressionTrait Trait,
2592 SourceLocation StartLoc,
2593 Expr *Queried,
2594 SourceLocation RParenLoc) {
2595 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2596 }
2597
Mike Stump11289f42009-09-09 15:08:12 +00002598 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002599 /// expression.
2600 ///
2601 /// By default, performs semantic analysis to build the new expression.
2602 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002603 ExprResult RebuildDependentScopeDeclRefExpr(
2604 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002605 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002606 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002607 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002608 bool IsAddressOfOperand,
2609 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002610 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002611 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002612
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002613 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002614 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2615 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002616
Reid Kleckner32506ed2014-06-12 23:03:48 +00002617 return getSema().BuildQualifiedDeclarationNameExpr(
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002618 SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002619 }
2620
2621 /// \brief Build a new template-id expression.
2622 ///
2623 /// By default, performs semantic analysis to build the new expression.
2624 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002625 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002626 SourceLocation TemplateKWLoc,
2627 LookupResult &R,
2628 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002629 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002630 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2631 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002632 }
2633
2634 /// \brief Build a new object-construction expression.
2635 ///
2636 /// By default, performs semantic analysis to build the new expression.
2637 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002638 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002639 SourceLocation Loc,
2640 CXXConstructorDecl *Constructor,
2641 bool IsElidable,
2642 MultiExprArg Args,
2643 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002644 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002645 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002646 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002647 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002648 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002649 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002650 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002651 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002652 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002653
Douglas Gregordb121ba2009-12-14 16:27:04 +00002654 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002655 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002656 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002657 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002658 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002659 RequiresZeroInit, ConstructKind,
2660 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002661 }
2662
2663 /// \brief Build a new object-construction expression.
2664 ///
2665 /// By default, performs semantic analysis to build the new expression.
2666 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002667 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2668 SourceLocation LParenLoc,
2669 MultiExprArg Args,
2670 SourceLocation RParenLoc) {
2671 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002672 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002673 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002674 RParenLoc);
2675 }
2676
2677 /// \brief Build a new object-construction expression.
2678 ///
2679 /// By default, performs semantic analysis to build the new expression.
2680 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002681 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2682 SourceLocation LParenLoc,
2683 MultiExprArg Args,
2684 SourceLocation RParenLoc) {
2685 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002686 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002687 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002688 RParenLoc);
2689 }
Mike Stump11289f42009-09-09 15:08:12 +00002690
Douglas Gregora16548e2009-08-11 05:31:07 +00002691 /// \brief Build a new member reference expression.
2692 ///
2693 /// By default, performs semantic analysis to build the new expression.
2694 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002695 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002696 QualType BaseType,
2697 bool IsArrow,
2698 SourceLocation OperatorLoc,
2699 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002700 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002701 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002702 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002703 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002704 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002705 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002706
John McCallb268a282010-08-23 23:25:46 +00002707 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002708 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002709 SS, TemplateKWLoc,
2710 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002711 MemberNameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002712 TemplateArgs, /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002713 }
2714
John McCall10eae182009-11-30 22:42:35 +00002715 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002716 ///
2717 /// By default, performs semantic analysis to build the new expression.
2718 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002719 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2720 SourceLocation OperatorLoc,
2721 bool IsArrow,
2722 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002723 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002724 NamedDecl *FirstQualifierInScope,
2725 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002726 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002727 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002728 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002729
John McCallb268a282010-08-23 23:25:46 +00002730 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002731 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002732 SS, TemplateKWLoc,
2733 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002734 R, TemplateArgs, /*S*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00002735 }
Mike Stump11289f42009-09-09 15:08:12 +00002736
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002737 /// \brief Build a new noexcept expression.
2738 ///
2739 /// By default, performs semantic analysis to build the new expression.
2740 /// Subclasses may override this routine to provide different behavior.
2741 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2742 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2743 }
2744
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002745 /// \brief Build a new expression to compute the length of a parameter pack.
Richard Smithd784e682015-09-23 21:41:42 +00002746 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc,
2747 NamedDecl *Pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00002748 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002749 SourceLocation RParenLoc,
Richard Smithd784e682015-09-23 21:41:42 +00002750 Optional<unsigned> Length,
2751 ArrayRef<TemplateArgument> PartialArgs) {
2752 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
2753 RParenLoc, Length, PartialArgs);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002754 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002755
Patrick Beard0caa3942012-04-19 00:25:12 +00002756 /// \brief Build a new Objective-C boxed expression.
2757 ///
2758 /// By default, performs semantic analysis to build the new expression.
2759 /// Subclasses may override this routine to provide different behavior.
2760 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2761 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2762 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002763
Ted Kremeneke65b0862012-03-06 20:05:56 +00002764 /// \brief Build a new Objective-C array literal.
2765 ///
2766 /// By default, performs semantic analysis to build the new expression.
2767 /// Subclasses may override this routine to provide different behavior.
2768 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2769 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002770 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002771 MultiExprArg(Elements, NumElements));
2772 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002773
2774 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002775 Expr *Base, Expr *Key,
2776 ObjCMethodDecl *getterMethod,
2777 ObjCMethodDecl *setterMethod) {
2778 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2779 getterMethod, setterMethod);
2780 }
2781
2782 /// \brief Build a new Objective-C dictionary literal.
2783 ///
2784 /// By default, performs semantic analysis to build the new expression.
2785 /// Subclasses may override this routine to provide different behavior.
2786 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
Craig Topperd4336e02015-12-24 23:58:15 +00002787 MutableArrayRef<ObjCDictionaryElement> Elements) {
2788 return getSema().BuildObjCDictionaryLiteral(Range, Elements);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002789 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002790
James Dennett2a4d13c2012-06-15 07:13:21 +00002791 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002792 ///
2793 /// By default, performs semantic analysis to build the new expression.
2794 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002795 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002796 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002797 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002798 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002799 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002800
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002801 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002802 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002803 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002804 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002805 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002806 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002807 MultiExprArg Args,
2808 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002809 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2810 ReceiverTypeInfo->getType(),
2811 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002812 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002813 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002814 }
2815
2816 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002817 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002818 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002819 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002820 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002821 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002822 MultiExprArg Args,
2823 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002824 return SemaRef.BuildInstanceMessage(Receiver,
2825 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002826 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002827 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002828 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002829 }
2830
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002831 /// \brief Build a new Objective-C instance/class message to 'super'.
2832 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
2833 Selector Sel,
2834 ArrayRef<SourceLocation> SelectorLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002835 QualType SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002836 ObjCMethodDecl *Method,
2837 SourceLocation LBracLoc,
2838 MultiExprArg Args,
2839 SourceLocation RBracLoc) {
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002840 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002841 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002842 SuperLoc,
2843 Sel, Method, LBracLoc, SelectorLocs,
2844 RBracLoc, Args)
2845 : SemaRef.BuildClassMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002846 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002847 SuperLoc,
2848 Sel, Method, LBracLoc, SelectorLocs,
2849 RBracLoc, Args);
2850
2851
2852 }
2853
Douglas Gregord51d90d2010-04-26 20:11:03 +00002854 /// \brief Build a new Objective-C ivar reference expression.
2855 ///
2856 /// By default, performs semantic analysis to build the new expression.
2857 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002858 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002859 SourceLocation IvarLoc,
2860 bool IsArrow, bool IsFreeIvar) {
2861 // FIXME: We lose track of the IsFreeIvar bit.
2862 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002863 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2864 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002865 /*FIXME:*/IvarLoc, IsArrow,
2866 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002867 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002868 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002869 /*TemplateArgs=*/nullptr,
2870 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002871 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002872
2873 /// \brief Build a new Objective-C property reference expression.
2874 ///
2875 /// By default, performs semantic analysis to build the new expression.
2876 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002877 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002878 ObjCPropertyDecl *Property,
2879 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002880 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002881 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2882 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2883 /*FIXME:*/PropertyLoc,
2884 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002885 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002886 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002887 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002888 /*TemplateArgs=*/nullptr,
2889 /*S=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002890 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002891
John McCallb7bd14f2010-12-02 01:19:52 +00002892 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002893 ///
2894 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002895 /// Subclasses may override this routine to provide different behavior.
2896 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2897 ObjCMethodDecl *Getter,
2898 ObjCMethodDecl *Setter,
2899 SourceLocation PropertyLoc) {
2900 // Since these expressions can only be value-dependent, we do not
2901 // need to perform semantic analysis again.
2902 return Owned(
2903 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2904 VK_LValue, OK_ObjCProperty,
2905 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002906 }
2907
Douglas Gregord51d90d2010-04-26 20:11:03 +00002908 /// \brief Build a new Objective-C "isa" expression.
2909 ///
2910 /// By default, performs semantic analysis to build the new expression.
2911 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002912 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00002913 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00002914 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002915 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2916 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002917 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002918 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002919 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002920 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002921 /*TemplateArgs=*/nullptr,
2922 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002923 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002924
Douglas Gregora16548e2009-08-11 05:31:07 +00002925 /// \brief Build a new shuffle vector expression.
2926 ///
2927 /// By default, performs semantic analysis to build the new expression.
2928 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002929 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002930 MultiExprArg SubExprs,
2931 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002932 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002933 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002934 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2935 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2936 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002937 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002938
Douglas Gregora16548e2009-08-11 05:31:07 +00002939 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002940 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002941 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2942 SemaRef.Context.BuiltinFnTy,
2943 VK_RValue, BuiltinLoc);
2944 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2945 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002946 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00002947
2948 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002949 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00002950 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002951 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002952
Douglas Gregora16548e2009-08-11 05:31:07 +00002953 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002954 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002955 }
John McCall31f82722010-11-12 08:19:04 +00002956
Hal Finkelc4d7c822013-09-18 03:29:45 +00002957 /// \brief Build a new convert vector expression.
2958 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2959 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2960 SourceLocation RParenLoc) {
2961 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2962 BuiltinLoc, RParenLoc);
2963 }
2964
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002965 /// \brief Build a new template argument pack expansion.
2966 ///
2967 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002968 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002969 /// different behavior.
2970 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002971 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002972 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002973 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002974 case TemplateArgument::Expression: {
2975 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002976 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2977 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002978 if (Result.isInvalid())
2979 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002980
Douglas Gregor98318c22011-01-03 21:37:45 +00002981 return TemplateArgumentLoc(Result.get(), Result.get());
2982 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002983
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002984 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002985 return TemplateArgumentLoc(TemplateArgument(
2986 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002987 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002988 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002989 Pattern.getTemplateNameLoc(),
2990 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002991
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002992 case TemplateArgument::Null:
2993 case TemplateArgument::Integral:
2994 case TemplateArgument::Declaration:
2995 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002996 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002997 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002998 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002999
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003000 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00003001 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003002 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003003 EllipsisLoc,
3004 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003005 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
3006 Expansion);
3007 break;
3008 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003009
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003010 return TemplateArgumentLoc();
3011 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003012
Douglas Gregor968f23a2011-01-03 19:31:53 +00003013 /// \brief Build a new expression pack expansion.
3014 ///
3015 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00003016 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00003017 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00003018 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00003019 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00003020 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003021 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003022
Richard Smith0f0af192014-11-08 05:07:16 +00003023 /// \brief Build a new C++1z fold-expression.
3024 ///
3025 /// By default, performs semantic analysis in order to build a new fold
3026 /// expression.
3027 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
3028 BinaryOperatorKind Operator,
3029 SourceLocation EllipsisLoc, Expr *RHS,
3030 SourceLocation RParenLoc) {
3031 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
3032 RHS, RParenLoc);
3033 }
3034
3035 /// \brief Build an empty C++1z fold-expression with the given operator.
3036 ///
3037 /// By default, produces the fallback value for the fold-expression, or
3038 /// produce an error if there is no fallback value.
3039 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
3040 BinaryOperatorKind Operator) {
3041 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
3042 }
3043
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003044 /// \brief Build a new atomic operation expression.
3045 ///
3046 /// By default, performs semantic analysis to build the new expression.
3047 /// Subclasses may override this routine to provide different behavior.
3048 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
3049 MultiExprArg SubExprs,
3050 QualType RetTy,
3051 AtomicExpr::AtomicOp Op,
3052 SourceLocation RParenLoc) {
3053 // Just create the expression; there is not any interesting semantic
3054 // analysis here because we can't actually build an AtomicExpr until
3055 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00003056 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003057 RParenLoc);
3058 }
3059
John McCall31f82722010-11-12 08:19:04 +00003060private:
Douglas Gregor14454802011-02-25 02:25:35 +00003061 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
3062 QualType ObjectType,
3063 NamedDecl *FirstQualifierInScope,
3064 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003065
3066 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3067 QualType ObjectType,
3068 NamedDecl *FirstQualifierInScope,
3069 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003070
3071 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
3072 NamedDecl *FirstQualifierInScope,
3073 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003074};
Douglas Gregora16548e2009-08-11 05:31:07 +00003075
Douglas Gregorebe10102009-08-20 07:17:43 +00003076template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003077StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003078 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003079 return S;
Mike Stump11289f42009-09-09 15:08:12 +00003080
Douglas Gregorebe10102009-08-20 07:17:43 +00003081 switch (S->getStmtClass()) {
3082 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00003083
Douglas Gregorebe10102009-08-20 07:17:43 +00003084 // Transform individual statement nodes
3085#define STMT(Node, Parent) \
3086 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00003087#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00003088#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00003089#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003090
Douglas Gregorebe10102009-08-20 07:17:43 +00003091 // Transform expressions by calling TransformExpr.
3092#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00003093#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00003094#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00003095#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00003096 {
John McCalldadc5752010-08-24 06:29:42 +00003097 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00003098 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003099 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003100
Richard Smith945f8d32013-01-14 22:39:08 +00003101 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00003102 }
Mike Stump11289f42009-09-09 15:08:12 +00003103 }
3104
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003105 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00003106}
Mike Stump11289f42009-09-09 15:08:12 +00003107
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00003108template<typename Derived>
3109OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
3110 if (!S)
3111 return S;
3112
3113 switch (S->getClauseKind()) {
3114 default: break;
3115 // Transform individual clause nodes
3116#define OPENMP_CLAUSE(Name, Class) \
3117 case OMPC_ ## Name : \
3118 return getDerived().Transform ## Class(cast<Class>(S));
3119#include "clang/Basic/OpenMPKinds.def"
3120 }
3121
3122 return S;
3123}
3124
Mike Stump11289f42009-09-09 15:08:12 +00003125
Douglas Gregore922c772009-08-04 22:27:00 +00003126template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003127ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003128 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003129 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00003130
3131 switch (E->getStmtClass()) {
3132 case Stmt::NoStmtClass: break;
3133#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00003134#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00003135#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00003136 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00003137#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003138 }
3139
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003140 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00003141}
3142
3143template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00003144ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00003145 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00003146 // Initializers are instantiated like expressions, except that various outer
3147 // layers are stripped.
3148 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003149 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00003150
3151 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
3152 Init = ExprTemp->getSubExpr();
3153
Richard Smithe6ca4752013-05-30 22:40:16 +00003154 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
3155 Init = MTE->GetTemporaryExpr();
3156
Richard Smithd59b8322012-12-19 01:39:02 +00003157 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
3158 Init = Binder->getSubExpr();
3159
3160 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
3161 Init = ICE->getSubExprAsWritten();
3162
Richard Smithcc1b96d2013-06-12 22:31:48 +00003163 if (CXXStdInitializerListExpr *ILE =
3164 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00003165 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00003166
Richard Smithc6abd962014-07-25 01:12:44 +00003167 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00003168 // InitListExprs. Other forms of copy-initialization will be a no-op if
3169 // the initializer is already the right type.
3170 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00003171 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00003172 return getDerived().TransformExpr(Init);
3173
3174 // Revert value-initialization back to empty parens.
3175 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
3176 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003177 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003178 Parens.getEnd());
3179 }
3180
3181 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3182 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003183 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003184 SourceLocation());
3185
3186 // Revert initialization by constructor back to a parenthesized or braced list
3187 // of expressions. Any other form of initializer can just be reused directly.
3188 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00003189 return getDerived().TransformExpr(Init);
3190
Richard Smithf8adcdc2014-07-17 05:12:35 +00003191 // If the initialization implicitly converted an initializer list to a
3192 // std::initializer_list object, unwrap the std::initializer_list too.
3193 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00003194 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00003195
Richard Smithd59b8322012-12-19 01:39:02 +00003196 SmallVector<Expr*, 8> NewArgs;
3197 bool ArgChanged = false;
3198 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00003199 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00003200 return ExprError();
3201
3202 // If this was list initialization, revert to list form.
3203 if (Construct->isListInitialization())
3204 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
3205 Construct->getLocEnd(),
3206 Construct->getType());
3207
Richard Smithd59b8322012-12-19 01:39:02 +00003208 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00003209 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00003210 if (Parens.isInvalid()) {
3211 // This was a variable declaration's initialization for which no initializer
3212 // was specified.
3213 assert(NewArgs.empty() &&
3214 "no parens or braces but have direct init with arguments?");
3215 return ExprEmpty();
3216 }
Richard Smithd59b8322012-12-19 01:39:02 +00003217 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3218 Parens.getEnd());
3219}
3220
3221template<typename Derived>
Craig Topper99d23532015-12-24 23:58:29 +00003222bool TreeTransform<Derived>::TransformExprs(Expr *const *Inputs,
Chad Rosier1dcde962012-08-08 18:46:20 +00003223 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003224 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003225 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003226 bool *ArgChanged) {
3227 for (unsigned I = 0; I != NumInputs; ++I) {
3228 // If requested, drop call arguments that need to be dropped.
3229 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3230 if (ArgChanged)
3231 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003232
Douglas Gregora3efea12011-01-03 19:04:46 +00003233 break;
3234 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003235
Douglas Gregor968f23a2011-01-03 19:31:53 +00003236 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3237 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00003238
Chris Lattner01cf8db2011-07-20 06:58:45 +00003239 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003240 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3241 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003242
Douglas Gregor968f23a2011-01-03 19:31:53 +00003243 // Determine whether the set of unexpanded parameter packs can and should
3244 // be expanded.
3245 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003246 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003247 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3248 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003249 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3250 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003251 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003252 Expand, RetainExpansion,
3253 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00003254 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003255
Douglas Gregor968f23a2011-01-03 19:31:53 +00003256 if (!Expand) {
3257 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003258 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00003259 // expansion.
3260 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3261 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3262 if (OutPattern.isInvalid())
3263 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003264
3265 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00003266 Expansion->getEllipsisLoc(),
3267 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003268 if (Out.isInvalid())
3269 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003270
Douglas Gregor968f23a2011-01-03 19:31:53 +00003271 if (ArgChanged)
3272 *ArgChanged = true;
3273 Outputs.push_back(Out.get());
3274 continue;
3275 }
John McCall542e7c62011-07-06 07:30:07 +00003276
3277 // Record right away that the argument was changed. This needs
3278 // to happen even if the array expands to nothing.
3279 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003280
Douglas Gregor968f23a2011-01-03 19:31:53 +00003281 // The transform has determined that we should perform an elementwise
3282 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003283 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00003284 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3285 ExprResult Out = getDerived().TransformExpr(Pattern);
3286 if (Out.isInvalid())
3287 return true;
3288
Richard Smith9467be42014-06-06 17:33:35 +00003289 // FIXME: Can this happen? We should not try to expand the pack
3290 // in this case.
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003291 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003292 Out = getDerived().RebuildPackExpansion(
3293 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003294 if (Out.isInvalid())
3295 return true;
3296 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003297
Douglas Gregor968f23a2011-01-03 19:31:53 +00003298 Outputs.push_back(Out.get());
3299 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003300
Richard Smith9467be42014-06-06 17:33:35 +00003301 // If we're supposed to retain a pack expansion, do so by temporarily
3302 // forgetting the partially-substituted parameter pack.
3303 if (RetainExpansion) {
3304 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3305
3306 ExprResult Out = getDerived().TransformExpr(Pattern);
3307 if (Out.isInvalid())
3308 return true;
3309
3310 Out = getDerived().RebuildPackExpansion(
3311 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3312 if (Out.isInvalid())
3313 return true;
3314
3315 Outputs.push_back(Out.get());
3316 }
3317
Douglas Gregor968f23a2011-01-03 19:31:53 +00003318 continue;
3319 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003320
Richard Smithd59b8322012-12-19 01:39:02 +00003321 ExprResult Result =
3322 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3323 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003324 if (Result.isInvalid())
3325 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003326
Douglas Gregora3efea12011-01-03 19:04:46 +00003327 if (Result.get() != Inputs[I] && ArgChanged)
3328 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003329
3330 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003331 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003332
Douglas Gregora3efea12011-01-03 19:04:46 +00003333 return false;
3334}
3335
3336template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003337NestedNameSpecifierLoc
3338TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3339 NestedNameSpecifierLoc NNS,
3340 QualType ObjectType,
3341 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003342 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003343 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003344 Qualifier = Qualifier.getPrefix())
3345 Qualifiers.push_back(Qualifier);
3346
3347 CXXScopeSpec SS;
3348 while (!Qualifiers.empty()) {
3349 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3350 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003351
Douglas Gregor14454802011-02-25 02:25:35 +00003352 switch (QNNS->getKind()) {
3353 case NestedNameSpecifier::Identifier:
Craig Topperc3ec1492014-05-26 06:22:03 +00003354 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
Douglas Gregor14454802011-02-25 02:25:35 +00003355 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003356 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003357 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003358 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00003359 FirstQualifierInScope, false))
3360 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003361
Douglas Gregor14454802011-02-25 02:25:35 +00003362 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003363
Douglas Gregor14454802011-02-25 02:25:35 +00003364 case NestedNameSpecifier::Namespace: {
3365 NamespaceDecl *NS
3366 = cast_or_null<NamespaceDecl>(
3367 getDerived().TransformDecl(
3368 Q.getLocalBeginLoc(),
3369 QNNS->getAsNamespace()));
3370 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3371 break;
3372 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003373
Douglas Gregor14454802011-02-25 02:25:35 +00003374 case NestedNameSpecifier::NamespaceAlias: {
3375 NamespaceAliasDecl *Alias
3376 = cast_or_null<NamespaceAliasDecl>(
3377 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3378 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003379 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003380 Q.getLocalEndLoc());
3381 break;
3382 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003383
Douglas Gregor14454802011-02-25 02:25:35 +00003384 case NestedNameSpecifier::Global:
3385 // There is no meaningful transformation that one could perform on the
3386 // global scope.
3387 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3388 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003389
Nikola Smiljanic67860242014-09-26 00:28:20 +00003390 case NestedNameSpecifier::Super: {
3391 CXXRecordDecl *RD =
3392 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3393 SourceLocation(), QNNS->getAsRecordDecl()));
3394 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3395 break;
3396 }
3397
Douglas Gregor14454802011-02-25 02:25:35 +00003398 case NestedNameSpecifier::TypeSpecWithTemplate:
3399 case NestedNameSpecifier::TypeSpec: {
3400 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3401 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003402
Douglas Gregor14454802011-02-25 02:25:35 +00003403 if (!TL)
3404 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003405
Douglas Gregor14454802011-02-25 02:25:35 +00003406 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003407 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003408 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003409 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003410 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003411 if (TL.getType()->isEnumeralType())
3412 SemaRef.Diag(TL.getBeginLoc(),
3413 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003414 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3415 Q.getLocalEndLoc());
3416 break;
3417 }
Richard Trieude756fb2011-05-07 01:36:37 +00003418 // If the nested-name-specifier is an invalid type def, don't emit an
3419 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003420 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3421 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003422 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003423 << TL.getType() << SS.getRange();
3424 }
Douglas Gregor14454802011-02-25 02:25:35 +00003425 return NestedNameSpecifierLoc();
3426 }
Douglas Gregore16af532011-02-28 18:50:33 +00003427 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003428
Douglas Gregore16af532011-02-28 18:50:33 +00003429 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003430 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003431 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003432 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003433
Douglas Gregor14454802011-02-25 02:25:35 +00003434 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003435 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003436 !getDerived().AlwaysRebuild())
3437 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003438
3439 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003440 // nested-name-specifier, do so.
3441 if (SS.location_size() == NNS.getDataLength() &&
3442 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3443 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3444
3445 // Allocate new nested-name-specifier location information.
3446 return SS.getWithLocInContext(SemaRef.Context);
3447}
3448
3449template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003450DeclarationNameInfo
3451TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003452::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003453 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003454 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003455 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003456
3457 switch (Name.getNameKind()) {
3458 case DeclarationName::Identifier:
3459 case DeclarationName::ObjCZeroArgSelector:
3460 case DeclarationName::ObjCOneArgSelector:
3461 case DeclarationName::ObjCMultiArgSelector:
3462 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003463 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003464 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003465 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003466
Douglas Gregorf816bd72009-09-03 22:13:48 +00003467 case DeclarationName::CXXConstructorName:
3468 case DeclarationName::CXXDestructorName:
3469 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003470 TypeSourceInfo *NewTInfo;
3471 CanQualType NewCanTy;
3472 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003473 NewTInfo = getDerived().TransformType(OldTInfo);
3474 if (!NewTInfo)
3475 return DeclarationNameInfo();
3476 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003477 }
3478 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003479 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003480 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003481 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003482 if (NewT.isNull())
3483 return DeclarationNameInfo();
3484 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3485 }
Mike Stump11289f42009-09-09 15:08:12 +00003486
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003487 DeclarationName NewName
3488 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3489 NewCanTy);
3490 DeclarationNameInfo NewNameInfo(NameInfo);
3491 NewNameInfo.setName(NewName);
3492 NewNameInfo.setNamedTypeInfo(NewTInfo);
3493 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003494 }
Mike Stump11289f42009-09-09 15:08:12 +00003495 }
3496
David Blaikie83d382b2011-09-23 05:06:16 +00003497 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003498}
3499
3500template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003501TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003502TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3503 TemplateName Name,
3504 SourceLocation NameLoc,
3505 QualType ObjectType,
3506 NamedDecl *FirstQualifierInScope) {
3507 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3508 TemplateDecl *Template = QTN->getTemplateDecl();
3509 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003510
Douglas Gregor9db53502011-03-02 18:07:45 +00003511 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003512 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003513 Template));
3514 if (!TransTemplate)
3515 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003516
Douglas Gregor9db53502011-03-02 18:07:45 +00003517 if (!getDerived().AlwaysRebuild() &&
3518 SS.getScopeRep() == QTN->getQualifier() &&
3519 TransTemplate == Template)
3520 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003521
Douglas Gregor9db53502011-03-02 18:07:45 +00003522 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3523 TransTemplate);
3524 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003525
Douglas Gregor9db53502011-03-02 18:07:45 +00003526 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3527 if (SS.getScopeRep()) {
3528 // These apply to the scope specifier, not the template.
3529 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003530 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003531 }
3532
Douglas Gregor9db53502011-03-02 18:07:45 +00003533 if (!getDerived().AlwaysRebuild() &&
3534 SS.getScopeRep() == DTN->getQualifier() &&
3535 ObjectType.isNull())
3536 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003537
Douglas Gregor9db53502011-03-02 18:07:45 +00003538 if (DTN->isIdentifier()) {
3539 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003540 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003541 NameLoc,
3542 ObjectType,
3543 FirstQualifierInScope);
3544 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003545
Douglas Gregor9db53502011-03-02 18:07:45 +00003546 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3547 ObjectType);
3548 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003549
Douglas Gregor9db53502011-03-02 18:07:45 +00003550 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3551 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003552 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003553 Template));
3554 if (!TransTemplate)
3555 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003556
Douglas Gregor9db53502011-03-02 18:07:45 +00003557 if (!getDerived().AlwaysRebuild() &&
3558 TransTemplate == Template)
3559 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003560
Douglas Gregor9db53502011-03-02 18:07:45 +00003561 return TemplateName(TransTemplate);
3562 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003563
Douglas Gregor9db53502011-03-02 18:07:45 +00003564 if (SubstTemplateTemplateParmPackStorage *SubstPack
3565 = Name.getAsSubstTemplateTemplateParmPack()) {
3566 TemplateTemplateParmDecl *TransParam
3567 = cast_or_null<TemplateTemplateParmDecl>(
3568 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3569 if (!TransParam)
3570 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003571
Douglas Gregor9db53502011-03-02 18:07:45 +00003572 if (!getDerived().AlwaysRebuild() &&
3573 TransParam == SubstPack->getParameterPack())
3574 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003575
3576 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003577 SubstPack->getArgumentPack());
3578 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003579
Douglas Gregor9db53502011-03-02 18:07:45 +00003580 // These should be getting filtered out before they reach the AST.
3581 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003582}
3583
3584template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003585void TreeTransform<Derived>::InventTemplateArgumentLoc(
3586 const TemplateArgument &Arg,
3587 TemplateArgumentLoc &Output) {
3588 SourceLocation Loc = getDerived().getBaseLocation();
3589 switch (Arg.getKind()) {
3590 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003591 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003592 break;
3593
3594 case TemplateArgument::Type:
3595 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003596 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003597
John McCall0ad16662009-10-29 08:12:44 +00003598 break;
3599
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003600 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003601 case TemplateArgument::TemplateExpansion: {
3602 NestedNameSpecifierLocBuilder Builder;
Manuel Klimek4c67fa72016-01-11 11:39:00 +00003603 TemplateName Template = Arg.getAsTemplateOrTemplatePattern();
Douglas Gregor9d802122011-03-02 17:09:35 +00003604 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3605 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3606 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3607 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003608
Douglas Gregor9d802122011-03-02 17:09:35 +00003609 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003610 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003611 Builder.getWithLocInContext(SemaRef.Context),
3612 Loc);
3613 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003614 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003615 Builder.getWithLocInContext(SemaRef.Context),
3616 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003617
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003618 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003619 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003620
John McCall0ad16662009-10-29 08:12:44 +00003621 case TemplateArgument::Expression:
3622 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3623 break;
3624
3625 case TemplateArgument::Declaration:
3626 case TemplateArgument::Integral:
3627 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003628 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003629 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003630 break;
3631 }
3632}
3633
3634template<typename Derived>
3635bool TreeTransform<Derived>::TransformTemplateArgument(
3636 const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +00003637 TemplateArgumentLoc &Output, bool Uneval) {
John McCall0ad16662009-10-29 08:12:44 +00003638 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003639 switch (Arg.getKind()) {
3640 case TemplateArgument::Null:
3641 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003642 case TemplateArgument::Pack:
3643 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003644 case TemplateArgument::NullPtr:
3645 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003646
Douglas Gregore922c772009-08-04 22:27:00 +00003647 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003648 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003649 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003650 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003651
3652 DI = getDerived().TransformType(DI);
3653 if (!DI) return true;
3654
3655 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3656 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003657 }
Mike Stump11289f42009-09-09 15:08:12 +00003658
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003659 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003660 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3661 if (QualifierLoc) {
3662 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3663 if (!QualifierLoc)
3664 return true;
3665 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003666
Douglas Gregordf846d12011-03-02 18:46:51 +00003667 CXXScopeSpec SS;
3668 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003669 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003670 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3671 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003672 if (Template.isNull())
3673 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003674
Douglas Gregor9d802122011-03-02 17:09:35 +00003675 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003676 Input.getTemplateNameLoc());
3677 return false;
3678 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003679
3680 case TemplateArgument::TemplateExpansion:
3681 llvm_unreachable("Caller should expand pack expansions");
3682
Douglas Gregore922c772009-08-04 22:27:00 +00003683 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003684 // Template argument expressions are constant expressions.
Richard Smithd784e682015-09-23 21:41:42 +00003685 EnterExpressionEvaluationContext Unevaluated(
3686 getSema(), Uneval ? Sema::Unevaluated : Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003687
John McCall0ad16662009-10-29 08:12:44 +00003688 Expr *InputExpr = Input.getSourceExpression();
3689 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3690
Chris Lattnercdb591a2011-04-25 20:37:58 +00003691 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003692 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003693 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003694 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003695 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003696 }
Douglas Gregore922c772009-08-04 22:27:00 +00003697 }
Mike Stump11289f42009-09-09 15:08:12 +00003698
Douglas Gregore922c772009-08-04 22:27:00 +00003699 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003700 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003701}
3702
Douglas Gregorfe921a72010-12-20 23:36:19 +00003703/// \brief Iterator adaptor that invents template argument location information
3704/// for each of the template arguments in its underlying iterator.
3705template<typename Derived, typename InputIterator>
3706class TemplateArgumentLocInventIterator {
3707 TreeTransform<Derived> &Self;
3708 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003709
Douglas Gregorfe921a72010-12-20 23:36:19 +00003710public:
3711 typedef TemplateArgumentLoc value_type;
3712 typedef TemplateArgumentLoc reference;
3713 typedef typename std::iterator_traits<InputIterator>::difference_type
3714 difference_type;
3715 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003716
Douglas Gregorfe921a72010-12-20 23:36:19 +00003717 class pointer {
3718 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003719
Douglas Gregorfe921a72010-12-20 23:36:19 +00003720 public:
3721 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003722
Douglas Gregorfe921a72010-12-20 23:36:19 +00003723 const TemplateArgumentLoc *operator->() const { return &Arg; }
3724 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003725
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00003726 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003727
Douglas Gregorfe921a72010-12-20 23:36:19 +00003728 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3729 InputIterator Iter)
3730 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003731
Douglas Gregorfe921a72010-12-20 23:36:19 +00003732 TemplateArgumentLocInventIterator &operator++() {
3733 ++Iter;
3734 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003735 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003736
Douglas Gregorfe921a72010-12-20 23:36:19 +00003737 TemplateArgumentLocInventIterator operator++(int) {
3738 TemplateArgumentLocInventIterator Old(*this);
3739 ++(*this);
3740 return Old;
3741 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003742
Douglas Gregorfe921a72010-12-20 23:36:19 +00003743 reference operator*() const {
3744 TemplateArgumentLoc Result;
3745 Self.InventTemplateArgumentLoc(*Iter, Result);
3746 return Result;
3747 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003748
Douglas Gregorfe921a72010-12-20 23:36:19 +00003749 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003750
Douglas Gregorfe921a72010-12-20 23:36:19 +00003751 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3752 const TemplateArgumentLocInventIterator &Y) {
3753 return X.Iter == Y.Iter;
3754 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003755
Douglas Gregorfe921a72010-12-20 23:36:19 +00003756 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3757 const TemplateArgumentLocInventIterator &Y) {
3758 return X.Iter != Y.Iter;
3759 }
3760};
Chad Rosier1dcde962012-08-08 18:46:20 +00003761
Douglas Gregor42cafa82010-12-20 17:42:22 +00003762template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003763template<typename InputIterator>
Richard Smithd784e682015-09-23 21:41:42 +00003764bool TreeTransform<Derived>::TransformTemplateArguments(
3765 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
3766 bool Uneval) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003767 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003768 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003769 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003770
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003771 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3772 // Unpack argument packs, which we translate them into separate
3773 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003774 // FIXME: We could do much better if we could guarantee that the
3775 // TemplateArgumentLocInfo for the pack expansion would be usable for
3776 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003777 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003778 TemplateArgument::pack_iterator>
3779 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003780 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003781 In.getArgument().pack_begin()),
3782 PackLocIterator(*this,
3783 In.getArgument().pack_end()),
Richard Smithd784e682015-09-23 21:41:42 +00003784 Outputs, Uneval))
Douglas Gregorfe921a72010-12-20 23:36:19 +00003785 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003786
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003787 continue;
3788 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003789
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003790 if (In.getArgument().isPackExpansion()) {
3791 // We have a pack expansion, for which we will be substituting into
3792 // the pattern.
3793 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003794 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003795 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003796 = getSema().getTemplateArgumentPackExpansionPattern(
3797 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003798
Chris Lattner01cf8db2011-07-20 06:58:45 +00003799 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003800 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3801 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003802
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003803 // Determine whether the set of unexpanded parameter packs can and should
3804 // be expanded.
3805 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003806 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003807 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003808 if (getDerived().TryExpandParameterPacks(Ellipsis,
3809 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003810 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003811 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003812 RetainExpansion,
3813 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003814 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003815
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003816 if (!Expand) {
3817 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003818 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003819 // expansion.
3820 TemplateArgumentLoc OutPattern;
3821 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Richard Smithd784e682015-09-23 21:41:42 +00003822 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003823 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003824
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003825 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3826 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003827 if (Out.getArgument().isNull())
3828 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003829
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003830 Outputs.addArgument(Out);
3831 continue;
3832 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003833
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003834 // The transform has determined that we should perform an elementwise
3835 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003836 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003837 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3838
Richard Smithd784e682015-09-23 21:41:42 +00003839 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003840 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003841
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003842 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003843 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3844 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003845 if (Out.getArgument().isNull())
3846 return true;
3847 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003848
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003849 Outputs.addArgument(Out);
3850 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003851
Douglas Gregor48d24112011-01-10 20:53:55 +00003852 // If we're supposed to retain a pack expansion, do so by temporarily
3853 // forgetting the partially-substituted parameter pack.
3854 if (RetainExpansion) {
3855 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003856
Richard Smithd784e682015-09-23 21:41:42 +00003857 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor48d24112011-01-10 20:53:55 +00003858 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003859
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003860 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3861 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003862 if (Out.getArgument().isNull())
3863 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003864
Douglas Gregor48d24112011-01-10 20:53:55 +00003865 Outputs.addArgument(Out);
3866 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003867
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003868 continue;
3869 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003870
3871 // The simple case:
Richard Smithd784e682015-09-23 21:41:42 +00003872 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003873 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003874
Douglas Gregor42cafa82010-12-20 17:42:22 +00003875 Outputs.addArgument(Out);
3876 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003877
Douglas Gregor42cafa82010-12-20 17:42:22 +00003878 return false;
3879
3880}
3881
Douglas Gregord6ff3322009-08-04 16:50:30 +00003882//===----------------------------------------------------------------------===//
3883// Type transformation
3884//===----------------------------------------------------------------------===//
3885
3886template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003887QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003888 if (getDerived().AlreadyTransformed(T))
3889 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003890
John McCall550e0c22009-10-21 00:40:46 +00003891 // Temporary workaround. All of these transformations should
3892 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003893 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3894 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003895
John McCall31f82722010-11-12 08:19:04 +00003896 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003897
John McCall550e0c22009-10-21 00:40:46 +00003898 if (!NewDI)
3899 return QualType();
3900
3901 return NewDI->getType();
3902}
3903
3904template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003905TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003906 // Refine the base location to the type's location.
3907 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3908 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003909 if (getDerived().AlreadyTransformed(DI->getType()))
3910 return DI;
3911
3912 TypeLocBuilder TLB;
3913
3914 TypeLoc TL = DI->getTypeLoc();
3915 TLB.reserve(TL.getFullDataSize());
3916
John McCall31f82722010-11-12 08:19:04 +00003917 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003918 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003919 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00003920
John McCallbcd03502009-12-07 02:54:59 +00003921 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003922}
3923
3924template<typename Derived>
3925QualType
John McCall31f82722010-11-12 08:19:04 +00003926TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003927 switch (T.getTypeLocClass()) {
3928#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003929#define TYPELOC(CLASS, PARENT) \
3930 case TypeLoc::CLASS: \
3931 return getDerived().Transform##CLASS##Type(TLB, \
3932 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003933#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003934 }
Mike Stump11289f42009-09-09 15:08:12 +00003935
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003936 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003937}
3938
3939/// FIXME: By default, this routine adds type qualifiers only to types
3940/// that can have qualifiers, and silently suppresses those qualifiers
3941/// that are not permitted (e.g., qualifiers on reference or function
3942/// types). This is the right thing for template instantiation, but
3943/// probably not for other clients.
3944template<typename Derived>
3945QualType
3946TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003947 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003948 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003949
John McCall31f82722010-11-12 08:19:04 +00003950 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003951 if (Result.isNull())
3952 return QualType();
3953
3954 // Silently suppress qualifiers if the result type can't be qualified.
3955 // FIXME: this is the right thing for template instantiation, but
3956 // probably not for other clients.
3957 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003958 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003959
John McCall31168b02011-06-15 23:02:42 +00003960 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003961 // resulting type.
3962 if (Quals.hasObjCLifetime()) {
3963 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3964 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003965 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003966 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003967 // A lifetime qualifier applied to a substituted template parameter
3968 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003969 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003970 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003971 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3972 QualType Replacement = SubstTypeParam->getReplacementType();
3973 Qualifiers Qs = Replacement.getQualifiers();
3974 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003975 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003976 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3977 Qs);
3978 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003979 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003980 Replacement);
3981 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003982 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3983 // 'auto' types behave the same way as template parameters.
3984 QualType Deduced = AutoTy->getDeducedType();
3985 Qualifiers Qs = Deduced.getQualifiers();
3986 Qs.removeObjCLifetime();
3987 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3988 Qs);
Richard Smithe301ba22015-11-11 02:02:15 +00003989 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
Faisal Vali2b391ab2013-09-26 19:54:12 +00003990 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003991 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003992 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003993 // Otherwise, complain about the addition of a qualifier to an
3994 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003995 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003996 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003997 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003998
Douglas Gregore46db902011-06-17 22:11:49 +00003999 Quals.removeObjCLifetime();
4000 }
4001 }
4002 }
John McCallcb0f89a2010-06-05 06:41:15 +00004003 if (!Quals.empty()) {
4004 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00004005 // BuildQualifiedType might not add qualifiers if they are invalid.
4006 if (Result.hasLocalQualifiers())
4007 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00004008 // No location information to preserve.
4009 }
John McCall550e0c22009-10-21 00:40:46 +00004010
4011 return Result;
4012}
4013
Douglas Gregor14454802011-02-25 02:25:35 +00004014template<typename Derived>
4015TypeLoc
4016TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
4017 QualType ObjectType,
4018 NamedDecl *UnqualLookup,
4019 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004020 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00004021 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00004022
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004023 TypeSourceInfo *TSI =
4024 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
4025 if (TSI)
4026 return TSI->getTypeLoc();
4027 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00004028}
4029
Douglas Gregor579c15f2011-03-02 18:32:08 +00004030template<typename Derived>
4031TypeSourceInfo *
4032TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4033 QualType ObjectType,
4034 NamedDecl *UnqualLookup,
4035 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004036 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00004037 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00004038
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004039 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
4040 UnqualLookup, SS);
4041}
4042
4043template <typename Derived>
4044TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
4045 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
4046 CXXScopeSpec &SS) {
4047 QualType T = TL.getType();
4048 assert(!getDerived().AlreadyTransformed(T));
4049
Douglas Gregor579c15f2011-03-02 18:32:08 +00004050 TypeLocBuilder TLB;
4051 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00004052
Douglas Gregor579c15f2011-03-02 18:32:08 +00004053 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004054 TemplateSpecializationTypeLoc SpecTL =
4055 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004056
Douglas Gregor579c15f2011-03-02 18:32:08 +00004057 TemplateName Template
4058 = getDerived().TransformTemplateName(SS,
4059 SpecTL.getTypePtr()->getTemplateName(),
4060 SpecTL.getTemplateNameLoc(),
4061 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00004062 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004063 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004064
4065 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004066 Template);
4067 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004068 DependentTemplateSpecializationTypeLoc SpecTL =
4069 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004070
Douglas Gregor579c15f2011-03-02 18:32:08 +00004071 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00004072 = getDerived().RebuildTemplateName(SS,
4073 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004074 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00004075 ObjectType, UnqualLookup);
4076 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004077 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004078
4079 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004080 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004081 Template,
4082 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00004083 } else {
4084 // Nothing special needs to be done for these.
4085 Result = getDerived().TransformType(TLB, TL);
4086 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004087
4088 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004089 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004090
Douglas Gregor579c15f2011-03-02 18:32:08 +00004091 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4092}
4093
John McCall550e0c22009-10-21 00:40:46 +00004094template <class TyLoc> static inline
4095QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
4096 TyLoc NewT = TLB.push<TyLoc>(T.getType());
4097 NewT.setNameLoc(T.getNameLoc());
4098 return T.getType();
4099}
4100
John McCall550e0c22009-10-21 00:40:46 +00004101template<typename Derived>
4102QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004103 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00004104 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
4105 NewT.setBuiltinLoc(T.getBuiltinLoc());
4106 if (T.needsExtraLocalData())
4107 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
4108 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004109}
Mike Stump11289f42009-09-09 15:08:12 +00004110
Douglas Gregord6ff3322009-08-04 16:50:30 +00004111template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004112QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004113 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00004114 // FIXME: recurse?
4115 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004116}
Mike Stump11289f42009-09-09 15:08:12 +00004117
Reid Kleckner0503a872013-12-05 01:23:43 +00004118template <typename Derived>
4119QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
4120 AdjustedTypeLoc TL) {
4121 // Adjustments applied during transformation are handled elsewhere.
4122 return getDerived().TransformType(TLB, TL.getOriginalLoc());
4123}
4124
Douglas Gregord6ff3322009-08-04 16:50:30 +00004125template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00004126QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
4127 DecayedTypeLoc TL) {
4128 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
4129 if (OriginalType.isNull())
4130 return QualType();
4131
4132 QualType Result = TL.getType();
4133 if (getDerived().AlwaysRebuild() ||
4134 OriginalType != TL.getOriginalLoc().getType())
4135 Result = SemaRef.Context.getDecayedType(OriginalType);
4136 TLB.push<DecayedTypeLoc>(Result);
4137 // Nothing to set for DecayedTypeLoc.
4138 return Result;
4139}
4140
4141template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004142QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004143 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004144 QualType PointeeType
4145 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004146 if (PointeeType.isNull())
4147 return QualType();
4148
4149 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00004150 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004151 // A dependent pointer type 'T *' has is being transformed such
4152 // that an Objective-C class type is being replaced for 'T'. The
4153 // resulting pointer type is an ObjCObjectPointerType, not a
4154 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00004155 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00004156
John McCall8b07ec22010-05-15 11:32:37 +00004157 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
4158 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004159 return Result;
4160 }
John McCall31f82722010-11-12 08:19:04 +00004161
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004162 if (getDerived().AlwaysRebuild() ||
4163 PointeeType != TL.getPointeeLoc().getType()) {
4164 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
4165 if (Result.isNull())
4166 return QualType();
4167 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004168
John McCall31168b02011-06-15 23:02:42 +00004169 // Objective-C ARC can add lifetime qualifiers to the type that we're
4170 // pointing to.
4171 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00004172
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004173 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
4174 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00004175 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004176}
Mike Stump11289f42009-09-09 15:08:12 +00004177
4178template<typename Derived>
4179QualType
John McCall550e0c22009-10-21 00:40:46 +00004180TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004181 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00004182 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00004183 = getDerived().TransformType(TLB, TL.getPointeeLoc());
4184 if (PointeeType.isNull())
4185 return QualType();
4186
4187 QualType Result = TL.getType();
4188 if (getDerived().AlwaysRebuild() ||
4189 PointeeType != TL.getPointeeLoc().getType()) {
4190 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00004191 TL.getSigilLoc());
4192 if (Result.isNull())
4193 return QualType();
4194 }
4195
Douglas Gregor049211a2010-04-22 16:50:51 +00004196 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00004197 NewT.setSigilLoc(TL.getSigilLoc());
4198 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004199}
4200
John McCall70dd5f62009-10-30 00:06:24 +00004201/// Transforms a reference type. Note that somewhat paradoxically we
4202/// don't care whether the type itself is an l-value type or an r-value
4203/// type; we only care if the type was *written* as an l-value type
4204/// or an r-value type.
4205template<typename Derived>
4206QualType
4207TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004208 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00004209 const ReferenceType *T = TL.getTypePtr();
4210
4211 // Note that this works with the pointee-as-written.
4212 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4213 if (PointeeType.isNull())
4214 return QualType();
4215
4216 QualType Result = TL.getType();
4217 if (getDerived().AlwaysRebuild() ||
4218 PointeeType != T->getPointeeTypeAsWritten()) {
4219 Result = getDerived().RebuildReferenceType(PointeeType,
4220 T->isSpelledAsLValue(),
4221 TL.getSigilLoc());
4222 if (Result.isNull())
4223 return QualType();
4224 }
4225
John McCall31168b02011-06-15 23:02:42 +00004226 // Objective-C ARC can add lifetime qualifiers to the type that we're
4227 // referring to.
4228 TLB.TypeWasModifiedSafely(
4229 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4230
John McCall70dd5f62009-10-30 00:06:24 +00004231 // r-value references can be rebuilt as l-value references.
4232 ReferenceTypeLoc NewTL;
4233 if (isa<LValueReferenceType>(Result))
4234 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4235 else
4236 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4237 NewTL.setSigilLoc(TL.getSigilLoc());
4238
4239 return Result;
4240}
4241
Mike Stump11289f42009-09-09 15:08:12 +00004242template<typename Derived>
4243QualType
John McCall550e0c22009-10-21 00:40:46 +00004244TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004245 LValueReferenceTypeLoc TL) {
4246 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004247}
4248
Mike Stump11289f42009-09-09 15:08:12 +00004249template<typename Derived>
4250QualType
John McCall550e0c22009-10-21 00:40:46 +00004251TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004252 RValueReferenceTypeLoc TL) {
4253 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004254}
Mike Stump11289f42009-09-09 15:08:12 +00004255
Douglas Gregord6ff3322009-08-04 16:50:30 +00004256template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004257QualType
John McCall550e0c22009-10-21 00:40:46 +00004258TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004259 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004260 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004261 if (PointeeType.isNull())
4262 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004263
Abramo Bagnara509357842011-03-05 14:42:21 +00004264 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004265 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00004266 if (OldClsTInfo) {
4267 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4268 if (!NewClsTInfo)
4269 return QualType();
4270 }
4271
4272 const MemberPointerType *T = TL.getTypePtr();
4273 QualType OldClsType = QualType(T->getClass(), 0);
4274 QualType NewClsType;
4275 if (NewClsTInfo)
4276 NewClsType = NewClsTInfo->getType();
4277 else {
4278 NewClsType = getDerived().TransformType(OldClsType);
4279 if (NewClsType.isNull())
4280 return QualType();
4281 }
Mike Stump11289f42009-09-09 15:08:12 +00004282
John McCall550e0c22009-10-21 00:40:46 +00004283 QualType Result = TL.getType();
4284 if (getDerived().AlwaysRebuild() ||
4285 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00004286 NewClsType != OldClsType) {
4287 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004288 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004289 if (Result.isNull())
4290 return QualType();
4291 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004292
Reid Kleckner0503a872013-12-05 01:23:43 +00004293 // If we had to adjust the pointee type when building a member pointer, make
4294 // sure to push TypeLoc info for it.
4295 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4296 if (MPT && PointeeType != MPT->getPointeeType()) {
4297 assert(isa<AdjustedType>(MPT->getPointeeType()));
4298 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4299 }
4300
John McCall550e0c22009-10-21 00:40:46 +00004301 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4302 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004303 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004304
4305 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004306}
4307
Mike Stump11289f42009-09-09 15:08:12 +00004308template<typename Derived>
4309QualType
John McCall550e0c22009-10-21 00:40:46 +00004310TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004311 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004312 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004313 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004314 if (ElementType.isNull())
4315 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004316
John McCall550e0c22009-10-21 00:40:46 +00004317 QualType Result = TL.getType();
4318 if (getDerived().AlwaysRebuild() ||
4319 ElementType != T->getElementType()) {
4320 Result = getDerived().RebuildConstantArrayType(ElementType,
4321 T->getSizeModifier(),
4322 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004323 T->getIndexTypeCVRQualifiers(),
4324 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004325 if (Result.isNull())
4326 return QualType();
4327 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004328
4329 // We might have either a ConstantArrayType or a VariableArrayType now:
4330 // a ConstantArrayType is allowed to have an element type which is a
4331 // VariableArrayType if the type is dependent. Fortunately, all array
4332 // types have the same location layout.
4333 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004334 NewTL.setLBracketLoc(TL.getLBracketLoc());
4335 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004336
John McCall550e0c22009-10-21 00:40:46 +00004337 Expr *Size = TL.getSizeExpr();
4338 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004339 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4340 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004341 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4342 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004343 }
4344 NewTL.setSizeExpr(Size);
4345
4346 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004347}
Mike Stump11289f42009-09-09 15:08:12 +00004348
Douglas Gregord6ff3322009-08-04 16:50:30 +00004349template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004350QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004351 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004352 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004353 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004354 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004355 if (ElementType.isNull())
4356 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004357
John McCall550e0c22009-10-21 00:40:46 +00004358 QualType Result = TL.getType();
4359 if (getDerived().AlwaysRebuild() ||
4360 ElementType != T->getElementType()) {
4361 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004362 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004363 T->getIndexTypeCVRQualifiers(),
4364 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004365 if (Result.isNull())
4366 return QualType();
4367 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004368
John McCall550e0c22009-10-21 00:40:46 +00004369 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4370 NewTL.setLBracketLoc(TL.getLBracketLoc());
4371 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004372 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004373
4374 return Result;
4375}
4376
4377template<typename Derived>
4378QualType
4379TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004380 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004381 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004382 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4383 if (ElementType.isNull())
4384 return QualType();
4385
John McCalldadc5752010-08-24 06:29:42 +00004386 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00004387 = getDerived().TransformExpr(T->getSizeExpr());
4388 if (SizeResult.isInvalid())
4389 return QualType();
4390
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004391 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004392
4393 QualType Result = TL.getType();
4394 if (getDerived().AlwaysRebuild() ||
4395 ElementType != T->getElementType() ||
4396 Size != T->getSizeExpr()) {
4397 Result = getDerived().RebuildVariableArrayType(ElementType,
4398 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004399 Size,
John McCall550e0c22009-10-21 00:40:46 +00004400 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004401 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004402 if (Result.isNull())
4403 return QualType();
4404 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004405
Serge Pavlov774c6d02014-02-06 03:49:11 +00004406 // We might have constant size array now, but fortunately it has the same
4407 // location layout.
4408 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004409 NewTL.setLBracketLoc(TL.getLBracketLoc());
4410 NewTL.setRBracketLoc(TL.getRBracketLoc());
4411 NewTL.setSizeExpr(Size);
4412
4413 return Result;
4414}
4415
4416template<typename Derived>
4417QualType
4418TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004419 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004420 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004421 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4422 if (ElementType.isNull())
4423 return QualType();
4424
Richard Smith764d2fe2011-12-20 02:08:33 +00004425 // Array bounds are constant expressions.
4426 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4427 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004428
John McCall33ddac02011-01-19 10:06:00 +00004429 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4430 Expr *origSize = TL.getSizeExpr();
4431 if (!origSize) origSize = T->getSizeExpr();
4432
4433 ExprResult sizeResult
4434 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004435 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004436 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004437 return QualType();
4438
John McCall33ddac02011-01-19 10:06:00 +00004439 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004440
4441 QualType Result = TL.getType();
4442 if (getDerived().AlwaysRebuild() ||
4443 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004444 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004445 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4446 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004447 size,
John McCall550e0c22009-10-21 00:40:46 +00004448 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004449 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004450 if (Result.isNull())
4451 return QualType();
4452 }
John McCall550e0c22009-10-21 00:40:46 +00004453
4454 // We might have any sort of array type now, but fortunately they
4455 // all have the same location layout.
4456 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4457 NewTL.setLBracketLoc(TL.getLBracketLoc());
4458 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004459 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004460
4461 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004462}
Mike Stump11289f42009-09-09 15:08:12 +00004463
4464template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004465QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004466 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004467 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004468 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004469
4470 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004471 QualType ElementType = getDerived().TransformType(T->getElementType());
4472 if (ElementType.isNull())
4473 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004474
Richard Smith764d2fe2011-12-20 02:08:33 +00004475 // Vector sizes are constant expressions.
4476 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4477 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004478
John McCalldadc5752010-08-24 06:29:42 +00004479 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004480 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004481 if (Size.isInvalid())
4482 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004483
John McCall550e0c22009-10-21 00:40:46 +00004484 QualType Result = TL.getType();
4485 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004486 ElementType != T->getElementType() ||
4487 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004488 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004489 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004490 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004491 if (Result.isNull())
4492 return QualType();
4493 }
John McCall550e0c22009-10-21 00:40:46 +00004494
4495 // Result might be dependent or not.
4496 if (isa<DependentSizedExtVectorType>(Result)) {
4497 DependentSizedExtVectorTypeLoc NewTL
4498 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4499 NewTL.setNameLoc(TL.getNameLoc());
4500 } else {
4501 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4502 NewTL.setNameLoc(TL.getNameLoc());
4503 }
4504
4505 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004506}
Mike Stump11289f42009-09-09 15:08:12 +00004507
4508template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004509QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004510 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004511 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004512 QualType ElementType = getDerived().TransformType(T->getElementType());
4513 if (ElementType.isNull())
4514 return QualType();
4515
John McCall550e0c22009-10-21 00:40:46 +00004516 QualType Result = TL.getType();
4517 if (getDerived().AlwaysRebuild() ||
4518 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004519 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004520 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004521 if (Result.isNull())
4522 return QualType();
4523 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004524
John McCall550e0c22009-10-21 00:40:46 +00004525 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4526 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004527
John McCall550e0c22009-10-21 00:40:46 +00004528 return Result;
4529}
4530
4531template<typename Derived>
4532QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004533 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004534 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004535 QualType ElementType = getDerived().TransformType(T->getElementType());
4536 if (ElementType.isNull())
4537 return QualType();
4538
4539 QualType Result = TL.getType();
4540 if (getDerived().AlwaysRebuild() ||
4541 ElementType != T->getElementType()) {
4542 Result = getDerived().RebuildExtVectorType(ElementType,
4543 T->getNumElements(),
4544 /*FIXME*/ SourceLocation());
4545 if (Result.isNull())
4546 return QualType();
4547 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004548
John McCall550e0c22009-10-21 00:40:46 +00004549 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4550 NewTL.setNameLoc(TL.getNameLoc());
4551
4552 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004553}
Mike Stump11289f42009-09-09 15:08:12 +00004554
David Blaikie05785d12013-02-20 22:23:23 +00004555template <typename Derived>
4556ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4557 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4558 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004559 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004560 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004561
Douglas Gregor715e4612011-01-14 22:40:04 +00004562 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004563 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004564 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004565 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004566 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004567
Douglas Gregor715e4612011-01-14 22:40:04 +00004568 TypeLocBuilder TLB;
4569 TypeLoc NewTL = OldDI->getTypeLoc();
4570 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004571
4572 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004573 OldExpansionTL.getPatternLoc());
4574 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004575 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004576
4577 Result = RebuildPackExpansionType(Result,
4578 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004579 OldExpansionTL.getEllipsisLoc(),
4580 NumExpansions);
4581 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004582 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004583
Douglas Gregor715e4612011-01-14 22:40:04 +00004584 PackExpansionTypeLoc NewExpansionTL
4585 = TLB.push<PackExpansionTypeLoc>(Result);
4586 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4587 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4588 } else
4589 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004590 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004591 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004592
John McCall8fb0d9d2011-05-01 22:35:37 +00004593 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004594 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004595
4596 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4597 OldParm->getDeclContext(),
4598 OldParm->getInnerLocStart(),
4599 OldParm->getLocation(),
4600 OldParm->getIdentifier(),
4601 NewDI->getType(),
4602 NewDI,
4603 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004604 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004605 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4606 OldParm->getFunctionScopeIndex() + indexAdjustment);
4607 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004608}
4609
4610template<typename Derived>
4611bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004612 TransformFunctionTypeParams(SourceLocation Loc,
4613 ParmVarDecl **Params, unsigned NumParams,
4614 const QualType *ParamTypes,
John McCallc8e321d2016-03-01 02:09:25 +00004615 const FunctionProtoType::ExtParameterInfo *ParamInfos,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004616 SmallVectorImpl<QualType> &OutParamTypes,
John McCallc8e321d2016-03-01 02:09:25 +00004617 SmallVectorImpl<ParmVarDecl*> *PVars,
4618 Sema::ExtParameterInfoBuilder &PInfos) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004619 int indexAdjustment = 0;
4620
Douglas Gregordd472162011-01-07 00:20:55 +00004621 for (unsigned i = 0; i != NumParams; ++i) {
4622 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004623 assert(OldParm->getFunctionScopeIndex() == i);
4624
David Blaikie05785d12013-02-20 22:23:23 +00004625 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004626 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004627 if (OldParm->isParameterPack()) {
4628 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004629 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004630
Douglas Gregor5499af42011-01-05 23:12:31 +00004631 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004632 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004633 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004634 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4635 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004636 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4637
Douglas Gregor5499af42011-01-05 23:12:31 +00004638 // Determine whether we should expand the parameter packs.
4639 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004640 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004641 Optional<unsigned> OrigNumExpansions =
4642 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004643 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004644 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4645 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004646 Unexpanded,
4647 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004648 RetainExpansion,
4649 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004650 return true;
4651 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004652
Douglas Gregor5499af42011-01-05 23:12:31 +00004653 if (ShouldExpand) {
4654 // Expand the function parameter pack into multiple, separate
4655 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004656 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004657 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004658 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004659 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004660 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004661 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004662 OrigNumExpansions,
4663 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004664 if (!NewParm)
4665 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004666
John McCallc8e321d2016-03-01 02:09:25 +00004667 if (ParamInfos)
4668 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004669 OutParamTypes.push_back(NewParm->getType());
4670 if (PVars)
4671 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004672 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004673
4674 // If we're supposed to retain a pack expansion, do so by temporarily
4675 // forgetting the partially-substituted parameter pack.
4676 if (RetainExpansion) {
4677 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004678 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004679 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004680 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004681 OrigNumExpansions,
4682 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004683 if (!NewParm)
4684 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004685
John McCallc8e321d2016-03-01 02:09:25 +00004686 if (ParamInfos)
4687 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004688 OutParamTypes.push_back(NewParm->getType());
4689 if (PVars)
4690 PVars->push_back(NewParm);
4691 }
4692
John McCall8fb0d9d2011-05-01 22:35:37 +00004693 // The next parameter should have the same adjustment as the
4694 // last thing we pushed, but we post-incremented indexAdjustment
4695 // on every push. Also, if we push nothing, the adjustment should
4696 // go down by one.
4697 indexAdjustment--;
4698
Douglas Gregor5499af42011-01-05 23:12:31 +00004699 // We're done with the pack expansion.
4700 continue;
4701 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004702
4703 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004704 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004705 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4706 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004707 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004708 NumExpansions,
4709 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004710 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004711 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004712 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004713 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004714
John McCall58f10c32010-03-11 09:03:00 +00004715 if (!NewParm)
4716 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004717
John McCallc8e321d2016-03-01 02:09:25 +00004718 if (ParamInfos)
4719 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004720 OutParamTypes.push_back(NewParm->getType());
4721 if (PVars)
4722 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004723 continue;
4724 }
John McCall58f10c32010-03-11 09:03:00 +00004725
4726 // Deal with the possibility that we don't have a parameter
4727 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004728 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004729 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004730 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004731 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004732 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004733 = dyn_cast<PackExpansionType>(OldType)) {
4734 // We have a function parameter pack that may need to be expanded.
4735 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004736 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004737 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004738
Douglas Gregor5499af42011-01-05 23:12:31 +00004739 // Determine whether we should expand the parameter packs.
4740 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004741 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004742 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004743 Unexpanded,
4744 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004745 RetainExpansion,
4746 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004747 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004748 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004749
Douglas Gregor5499af42011-01-05 23:12:31 +00004750 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004751 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004752 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004753 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004754 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4755 QualType NewType = getDerived().TransformType(Pattern);
4756 if (NewType.isNull())
4757 return true;
John McCall58f10c32010-03-11 09:03:00 +00004758
John McCallc8e321d2016-03-01 02:09:25 +00004759 if (ParamInfos)
4760 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004761 OutParamTypes.push_back(NewType);
4762 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004763 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004764 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004765
Douglas Gregor5499af42011-01-05 23:12:31 +00004766 // We're done with the pack expansion.
4767 continue;
4768 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004769
Douglas Gregor48d24112011-01-10 20:53:55 +00004770 // If we're supposed to retain a pack expansion, do so by temporarily
4771 // forgetting the partially-substituted parameter pack.
4772 if (RetainExpansion) {
4773 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4774 QualType NewType = getDerived().TransformType(Pattern);
4775 if (NewType.isNull())
4776 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004777
John McCallc8e321d2016-03-01 02:09:25 +00004778 if (ParamInfos)
4779 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregor48d24112011-01-10 20:53:55 +00004780 OutParamTypes.push_back(NewType);
4781 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004782 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004783 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004784
Chad Rosier1dcde962012-08-08 18:46:20 +00004785 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004786 // expansion.
4787 OldType = Expansion->getPattern();
4788 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004789 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4790 NewType = getDerived().TransformType(OldType);
4791 } else {
4792 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004793 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004794
Douglas Gregor5499af42011-01-05 23:12:31 +00004795 if (NewType.isNull())
4796 return true;
4797
4798 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004799 NewType = getSema().Context.getPackExpansionType(NewType,
4800 NumExpansions);
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 Gregordd472162011-01-07 00:20:55 +00004804 OutParamTypes.push_back(NewType);
4805 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004806 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004807 }
4808
John McCall8fb0d9d2011-05-01 22:35:37 +00004809#ifndef NDEBUG
4810 if (PVars) {
4811 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4812 if (ParmVarDecl *parm = (*PVars)[i])
4813 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004814 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004815#endif
4816
4817 return false;
4818}
John McCall58f10c32010-03-11 09:03:00 +00004819
4820template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004821QualType
John McCall550e0c22009-10-21 00:40:46 +00004822TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004823 FunctionProtoTypeLoc TL) {
Richard Smith2e321552014-11-12 02:00:47 +00004824 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00004825 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00004826 return getDerived().TransformFunctionProtoType(
4827 TLB, TL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00004828 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
4829 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
4830 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00004831 });
Douglas Gregor3024f072012-04-16 07:05:22 +00004832}
4833
Richard Smith2e321552014-11-12 02:00:47 +00004834template<typename Derived> template<typename Fn>
4835QualType TreeTransform<Derived>::TransformFunctionProtoType(
4836 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
4837 unsigned ThisTypeQuals, Fn TransformExceptionSpec) {
John McCallc8e321d2016-03-01 02:09:25 +00004838
Douglas Gregor4afc2362010-08-31 00:26:14 +00004839 // Transform the parameters and return type.
4840 //
Richard Smithf623c962012-04-17 00:58:00 +00004841 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004842 // When the function has a trailing return type, we instantiate the
4843 // parameters before the return type, since the return type can then refer
4844 // to the parameters themselves (via decltype, sizeof, etc.).
4845 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004846 SmallVector<QualType, 4> ParamTypes;
4847 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallc8e321d2016-03-01 02:09:25 +00004848 Sema::ExtParameterInfoBuilder ExtParamInfos;
John McCall424cec92011-01-19 06:33:43 +00004849 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004850
Douglas Gregor7fb25412010-10-01 18:44:50 +00004851 QualType ResultType;
4852
Richard Smith1226c602012-08-14 22:51:13 +00004853 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004854 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004855 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
John McCallc8e321d2016-03-01 02:09:25 +00004856 TL.getTypePtr()->param_type_begin(),
4857 T->getExtParameterInfosOrNull(),
4858 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004859 return QualType();
4860
Douglas Gregor3024f072012-04-16 07:05:22 +00004861 {
4862 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004863 // If a declaration declares a member function or member function
4864 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004865 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004866 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004867 // declarator.
4868 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004869
Alp Toker42a16a62014-01-25 23:51:36 +00004870 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004871 if (ResultType.isNull())
4872 return QualType();
4873 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004874 }
4875 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004876 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004877 if (ResultType.isNull())
4878 return QualType();
4879
Alp Toker9cacbab2014-01-20 20:26:09 +00004880 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004881 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
John McCallc8e321d2016-03-01 02:09:25 +00004882 TL.getTypePtr()->param_type_begin(),
4883 T->getExtParameterInfosOrNull(),
4884 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004885 return QualType();
4886 }
4887
Richard Smith2e321552014-11-12 02:00:47 +00004888 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
4889
4890 bool EPIChanged = false;
4891 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
4892 return QualType();
4893
John McCallc8e321d2016-03-01 02:09:25 +00004894 // Handle extended parameter information.
4895 if (auto NewExtParamInfos =
4896 ExtParamInfos.getPointerOrNull(ParamTypes.size())) {
4897 if (!EPI.ExtParameterInfos ||
4898 llvm::makeArrayRef(EPI.ExtParameterInfos, TL.getNumParams())
4899 != llvm::makeArrayRef(NewExtParamInfos, ParamTypes.size())) {
4900 EPIChanged = true;
4901 }
4902 EPI.ExtParameterInfos = NewExtParamInfos;
4903 } else if (EPI.ExtParameterInfos) {
4904 EPIChanged = true;
4905 EPI.ExtParameterInfos = nullptr;
4906 }
Richard Smithf623c962012-04-17 00:58:00 +00004907
John McCall550e0c22009-10-21 00:40:46 +00004908 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004909 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Benjamin Kramere1c08b02015-08-18 08:10:39 +00004910 T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) {
Richard Smith2e321552014-11-12 02:00:47 +00004911 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
John McCall550e0c22009-10-21 00:40:46 +00004912 if (Result.isNull())
4913 return QualType();
4914 }
Mike Stump11289f42009-09-09 15:08:12 +00004915
John McCall550e0c22009-10-21 00:40:46 +00004916 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004917 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004918 NewTL.setLParenLoc(TL.getLParenLoc());
4919 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004920 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004921 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4922 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004923
4924 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004925}
Mike Stump11289f42009-09-09 15:08:12 +00004926
Douglas Gregord6ff3322009-08-04 16:50:30 +00004927template<typename Derived>
Richard Smith2e321552014-11-12 02:00:47 +00004928bool TreeTransform<Derived>::TransformExceptionSpec(
4929 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
4930 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
4931 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
4932
4933 // Instantiate a dynamic noexcept expression, if any.
4934 if (ESI.Type == EST_ComputedNoexcept) {
4935 EnterExpressionEvaluationContext Unevaluated(getSema(),
4936 Sema::ConstantEvaluated);
4937 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
4938 if (NoexceptExpr.isInvalid())
4939 return true;
4940
4941 NoexceptExpr = getSema().CheckBooleanCondition(
4942 NoexceptExpr.get(), NoexceptExpr.get()->getLocStart());
4943 if (NoexceptExpr.isInvalid())
4944 return true;
4945
4946 if (!NoexceptExpr.get()->isValueDependent()) {
4947 NoexceptExpr = getSema().VerifyIntegerConstantExpression(
4948 NoexceptExpr.get(), nullptr,
4949 diag::err_noexcept_needs_constant_expression,
4950 /*AllowFold*/false);
4951 if (NoexceptExpr.isInvalid())
4952 return true;
4953 }
4954
4955 if (ESI.NoexceptExpr != NoexceptExpr.get())
4956 Changed = true;
4957 ESI.NoexceptExpr = NoexceptExpr.get();
4958 }
4959
4960 if (ESI.Type != EST_Dynamic)
4961 return false;
4962
4963 // Instantiate a dynamic exception specification's type.
4964 for (QualType T : ESI.Exceptions) {
4965 if (const PackExpansionType *PackExpansion =
4966 T->getAs<PackExpansionType>()) {
4967 Changed = true;
4968
4969 // We have a pack expansion. Instantiate it.
4970 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
4971 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
4972 Unexpanded);
4973 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4974
4975 // Determine whether the set of unexpanded parameter packs can and
4976 // should
4977 // be expanded.
4978 bool Expand = false;
4979 bool RetainExpansion = false;
4980 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
4981 // FIXME: Track the location of the ellipsis (and track source location
4982 // information for the types in the exception specification in general).
4983 if (getDerived().TryExpandParameterPacks(
4984 Loc, SourceRange(), Unexpanded, Expand,
4985 RetainExpansion, NumExpansions))
4986 return true;
4987
4988 if (!Expand) {
4989 // We can't expand this pack expansion into separate arguments yet;
4990 // just substitute into the pattern and create a new pack expansion
4991 // type.
4992 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4993 QualType U = getDerived().TransformType(PackExpansion->getPattern());
4994 if (U.isNull())
4995 return true;
4996
4997 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
4998 Exceptions.push_back(U);
4999 continue;
5000 }
5001
5002 // Substitute into the pack expansion pattern for each slice of the
5003 // pack.
5004 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5005 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5006
5007 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5008 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5009 return true;
5010
5011 Exceptions.push_back(U);
5012 }
5013 } else {
5014 QualType U = getDerived().TransformType(T);
5015 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5016 return true;
5017 if (T != U)
5018 Changed = true;
5019
5020 Exceptions.push_back(U);
5021 }
5022 }
5023
5024 ESI.Exceptions = Exceptions;
5025 return false;
5026}
5027
5028template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00005029QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00005030 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005031 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005032 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00005033 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00005034 if (ResultType.isNull())
5035 return QualType();
5036
5037 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00005038 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00005039 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
5040
5041 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005042 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00005043 NewTL.setLParenLoc(TL.getLParenLoc());
5044 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005045 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00005046
5047 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005048}
Mike Stump11289f42009-09-09 15:08:12 +00005049
John McCallb96ec562009-12-04 22:46:56 +00005050template<typename Derived> QualType
5051TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005052 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005053 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005054 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00005055 if (!D)
5056 return QualType();
5057
5058 QualType Result = TL.getType();
5059 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
5060 Result = getDerived().RebuildUnresolvedUsingType(D);
5061 if (Result.isNull())
5062 return QualType();
5063 }
5064
5065 // We might get an arbitrary type spec type back. We should at
5066 // least always get a type spec type, though.
5067 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
5068 NewTL.setNameLoc(TL.getNameLoc());
5069
5070 return Result;
5071}
5072
Douglas Gregord6ff3322009-08-04 16:50:30 +00005073template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005074QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005075 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005076 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00005077 TypedefNameDecl *Typedef
5078 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5079 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005080 if (!Typedef)
5081 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005082
John McCall550e0c22009-10-21 00:40:46 +00005083 QualType Result = TL.getType();
5084 if (getDerived().AlwaysRebuild() ||
5085 Typedef != T->getDecl()) {
5086 Result = getDerived().RebuildTypedefType(Typedef);
5087 if (Result.isNull())
5088 return QualType();
5089 }
Mike Stump11289f42009-09-09 15:08:12 +00005090
John McCall550e0c22009-10-21 00:40:46 +00005091 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
5092 NewTL.setNameLoc(TL.getNameLoc());
5093
5094 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005095}
Mike Stump11289f42009-09-09 15:08:12 +00005096
Douglas Gregord6ff3322009-08-04 16:50:30 +00005097template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005098QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005099 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00005100 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00005101 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
5102 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00005103
John McCalldadc5752010-08-24 06:29:42 +00005104 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005105 if (E.isInvalid())
5106 return QualType();
5107
Eli Friedmane4f22df2012-02-29 04:03:55 +00005108 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
5109 if (E.isInvalid())
5110 return QualType();
5111
John McCall550e0c22009-10-21 00:40:46 +00005112 QualType Result = TL.getType();
5113 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00005114 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005115 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00005116 if (Result.isNull())
5117 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005118 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005119 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005120
John McCall550e0c22009-10-21 00:40:46 +00005121 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005122 NewTL.setTypeofLoc(TL.getTypeofLoc());
5123 NewTL.setLParenLoc(TL.getLParenLoc());
5124 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00005125
5126 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005127}
Mike Stump11289f42009-09-09 15:08:12 +00005128
5129template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005130QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005131 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00005132 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
5133 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
5134 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005135 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005136
John McCall550e0c22009-10-21 00:40:46 +00005137 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00005138 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
5139 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00005140 if (Result.isNull())
5141 return QualType();
5142 }
Mike Stump11289f42009-09-09 15:08:12 +00005143
John McCall550e0c22009-10-21 00:40:46 +00005144 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005145 NewTL.setTypeofLoc(TL.getTypeofLoc());
5146 NewTL.setLParenLoc(TL.getLParenLoc());
5147 NewTL.setRParenLoc(TL.getRParenLoc());
5148 NewTL.setUnderlyingTInfo(New_Under_TI);
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>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005155 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005156 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00005157
Douglas Gregore922c772009-08-04 22:27:00 +00005158 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00005159 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
5160 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00005161
John McCalldadc5752010-08-24 06:29:42 +00005162 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005163 if (E.isInvalid())
5164 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005165
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005166 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00005167 if (E.isInvalid())
5168 return QualType();
5169
John McCall550e0c22009-10-21 00:40:46 +00005170 QualType Result = TL.getType();
5171 if (getDerived().AlwaysRebuild() ||
5172 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005173 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005174 if (Result.isNull())
5175 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005176 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005177 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005178
John McCall550e0c22009-10-21 00:40:46 +00005179 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
5180 NewTL.setNameLoc(TL.getNameLoc());
5181
5182 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005183}
5184
5185template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00005186QualType TreeTransform<Derived>::TransformUnaryTransformType(
5187 TypeLocBuilder &TLB,
5188 UnaryTransformTypeLoc TL) {
5189 QualType Result = TL.getType();
5190 if (Result->isDependentType()) {
5191 const UnaryTransformType *T = TL.getTypePtr();
5192 QualType NewBase =
5193 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
5194 Result = getDerived().RebuildUnaryTransformType(NewBase,
5195 T->getUTTKind(),
5196 TL.getKWLoc());
5197 if (Result.isNull())
5198 return QualType();
5199 }
5200
5201 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
5202 NewTL.setKWLoc(TL.getKWLoc());
5203 NewTL.setParensRange(TL.getParensRange());
5204 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
5205 return Result;
5206}
5207
5208template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00005209QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
5210 AutoTypeLoc TL) {
5211 const AutoType *T = TL.getTypePtr();
5212 QualType OldDeduced = T->getDeducedType();
5213 QualType NewDeduced;
5214 if (!OldDeduced.isNull()) {
5215 NewDeduced = getDerived().TransformType(OldDeduced);
5216 if (NewDeduced.isNull())
5217 return QualType();
5218 }
5219
5220 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00005221 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
5222 T->isDependentType()) {
Richard Smithe301ba22015-11-11 02:02:15 +00005223 Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword());
Richard Smith30482bc2011-02-20 03:19:35 +00005224 if (Result.isNull())
5225 return QualType();
5226 }
5227
5228 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5229 NewTL.setNameLoc(TL.getNameLoc());
5230
5231 return Result;
5232}
5233
5234template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005235QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005236 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005237 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005238 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005239 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5240 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005241 if (!Record)
5242 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005243
John McCall550e0c22009-10-21 00:40:46 +00005244 QualType Result = TL.getType();
5245 if (getDerived().AlwaysRebuild() ||
5246 Record != T->getDecl()) {
5247 Result = getDerived().RebuildRecordType(Record);
5248 if (Result.isNull())
5249 return QualType();
5250 }
Mike Stump11289f42009-09-09 15:08:12 +00005251
John McCall550e0c22009-10-21 00:40:46 +00005252 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5253 NewTL.setNameLoc(TL.getNameLoc());
5254
5255 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005256}
Mike Stump11289f42009-09-09 15:08:12 +00005257
5258template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005259QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005260 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005261 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005262 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005263 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5264 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005265 if (!Enum)
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 Enum != T->getDecl()) {
5271 Result = getDerived().RebuildEnumType(Enum);
5272 if (Result.isNull())
5273 return QualType();
5274 }
Mike Stump11289f42009-09-09 15:08:12 +00005275
John McCall550e0c22009-10-21 00:40:46 +00005276 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5277 NewTL.setNameLoc(TL.getNameLoc());
5278
5279 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005280}
John McCallfcc33b02009-09-05 00:15:47 +00005281
John McCalle78aac42010-03-10 03:28:59 +00005282template<typename Derived>
5283QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5284 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005285 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00005286 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5287 TL.getTypePtr()->getDecl());
5288 if (!D) return QualType();
5289
5290 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5291 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5292 return T;
5293}
5294
Douglas Gregord6ff3322009-08-04 16:50:30 +00005295template<typename Derived>
5296QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005297 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005298 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00005299 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005300}
5301
Mike Stump11289f42009-09-09 15:08:12 +00005302template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00005303QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005304 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005305 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005306 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005307
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005308 // Substitute into the replacement type, which itself might involve something
5309 // that needs to be transformed. This only tends to occur with default
5310 // template arguments of template template parameters.
5311 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5312 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5313 if (Replacement.isNull())
5314 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005315
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005316 // Always canonicalize the replacement type.
5317 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5318 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00005319 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005320 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00005321
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005322 // Propagate type-source information.
5323 SubstTemplateTypeParmTypeLoc NewTL
5324 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5325 NewTL.setNameLoc(TL.getNameLoc());
5326 return Result;
5327
John McCallcebee162009-10-18 09:09:24 +00005328}
5329
5330template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00005331QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5332 TypeLocBuilder &TLB,
5333 SubstTemplateTypeParmPackTypeLoc TL) {
5334 return TransformTypeSpecType(TLB, TL);
5335}
5336
5337template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00005338QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005339 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005340 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00005341 const TemplateSpecializationType *T = TL.getTypePtr();
5342
Douglas Gregordf846d12011-03-02 18:46:51 +00005343 // The nested-name-specifier never matters in a TemplateSpecializationType,
5344 // because we can't have a dependent nested-name-specifier anyway.
5345 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00005346 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00005347 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5348 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005349 if (Template.isNull())
5350 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005351
John McCall31f82722010-11-12 08:19:04 +00005352 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5353}
5354
Eli Friedman0dfb8892011-10-06 23:00:33 +00005355template<typename Derived>
5356QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5357 AtomicTypeLoc TL) {
5358 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5359 if (ValueType.isNull())
5360 return QualType();
5361
5362 QualType Result = TL.getType();
5363 if (getDerived().AlwaysRebuild() ||
5364 ValueType != TL.getValueLoc().getType()) {
5365 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5366 if (Result.isNull())
5367 return QualType();
5368 }
5369
5370 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5371 NewTL.setKWLoc(TL.getKWLoc());
5372 NewTL.setLParenLoc(TL.getLParenLoc());
5373 NewTL.setRParenLoc(TL.getRParenLoc());
5374
5375 return Result;
5376}
5377
Xiuli Pan9c14e282016-01-09 12:53:17 +00005378template <typename Derived>
5379QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB,
5380 PipeTypeLoc TL) {
5381 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5382 if (ValueType.isNull())
5383 return QualType();
5384
5385 QualType Result = TL.getType();
5386 if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
5387 Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc());
5388 if (Result.isNull())
5389 return QualType();
5390 }
5391
5392 PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
5393 NewTL.setKWLoc(TL.getKWLoc());
5394
5395 return Result;
5396}
5397
Chad Rosier1dcde962012-08-08 18:46:20 +00005398 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00005399 /// container that provides a \c getArgLoc() member function.
5400 ///
5401 /// This iterator is intended to be used with the iterator form of
5402 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5403 template<typename ArgLocContainer>
5404 class TemplateArgumentLocContainerIterator {
5405 ArgLocContainer *Container;
5406 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00005407
Douglas Gregorfe921a72010-12-20 23:36:19 +00005408 public:
5409 typedef TemplateArgumentLoc value_type;
5410 typedef TemplateArgumentLoc reference;
5411 typedef int difference_type;
5412 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00005413
Douglas Gregorfe921a72010-12-20 23:36:19 +00005414 class pointer {
5415 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00005416
Douglas Gregorfe921a72010-12-20 23:36:19 +00005417 public:
5418 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005419
Douglas Gregorfe921a72010-12-20 23:36:19 +00005420 const TemplateArgumentLoc *operator->() const {
5421 return &Arg;
5422 }
5423 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005424
5425
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00005426 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00005427
Douglas Gregorfe921a72010-12-20 23:36:19 +00005428 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5429 unsigned Index)
5430 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005431
Douglas Gregorfe921a72010-12-20 23:36:19 +00005432 TemplateArgumentLocContainerIterator &operator++() {
5433 ++Index;
5434 return *this;
5435 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005436
Douglas Gregorfe921a72010-12-20 23:36:19 +00005437 TemplateArgumentLocContainerIterator operator++(int) {
5438 TemplateArgumentLocContainerIterator Old(*this);
5439 ++(*this);
5440 return Old;
5441 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005442
Douglas Gregorfe921a72010-12-20 23:36:19 +00005443 TemplateArgumentLoc operator*() const {
5444 return Container->getArgLoc(Index);
5445 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005446
Douglas Gregorfe921a72010-12-20 23:36:19 +00005447 pointer operator->() const {
5448 return pointer(Container->getArgLoc(Index));
5449 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005450
Douglas Gregorfe921a72010-12-20 23:36:19 +00005451 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005452 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005453 return X.Container == Y.Container && X.Index == Y.Index;
5454 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005455
Douglas Gregorfe921a72010-12-20 23:36:19 +00005456 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005457 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005458 return !(X == Y);
5459 }
5460 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005461
5462
John McCall31f82722010-11-12 08:19:04 +00005463template <typename Derived>
5464QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5465 TypeLocBuilder &TLB,
5466 TemplateSpecializationTypeLoc TL,
5467 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005468 TemplateArgumentListInfo NewTemplateArgs;
5469 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5470 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005471 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5472 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005473 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005474 ArgIterator(TL, TL.getNumArgs()),
5475 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005476 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005477
John McCall0ad16662009-10-29 08:12:44 +00005478 // FIXME: maybe don't rebuild if all the template arguments are the same.
5479
5480 QualType Result =
5481 getDerived().RebuildTemplateSpecializationType(Template,
5482 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005483 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005484
5485 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005486 // Specializations of template template parameters are represented as
5487 // TemplateSpecializationTypes, and substitution of type alias templates
5488 // within a dependent context can transform them into
5489 // DependentTemplateSpecializationTypes.
5490 if (isa<DependentTemplateSpecializationType>(Result)) {
5491 DependentTemplateSpecializationTypeLoc NewTL
5492 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005493 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005494 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005495 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005496 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005497 NewTL.setLAngleLoc(TL.getLAngleLoc());
5498 NewTL.setRAngleLoc(TL.getRAngleLoc());
5499 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5500 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5501 return Result;
5502 }
5503
John McCall0ad16662009-10-29 08:12:44 +00005504 TemplateSpecializationTypeLoc NewTL
5505 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005506 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005507 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5508 NewTL.setLAngleLoc(TL.getLAngleLoc());
5509 NewTL.setRAngleLoc(TL.getRAngleLoc());
5510 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5511 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005512 }
Mike Stump11289f42009-09-09 15:08:12 +00005513
John McCall0ad16662009-10-29 08:12:44 +00005514 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005515}
Mike Stump11289f42009-09-09 15:08:12 +00005516
Douglas Gregor5a064722011-02-28 17:23:35 +00005517template <typename Derived>
5518QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5519 TypeLocBuilder &TLB,
5520 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005521 TemplateName Template,
5522 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005523 TemplateArgumentListInfo NewTemplateArgs;
5524 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5525 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5526 typedef TemplateArgumentLocContainerIterator<
5527 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005528 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005529 ArgIterator(TL, TL.getNumArgs()),
5530 NewTemplateArgs))
5531 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005532
Douglas Gregor5a064722011-02-28 17:23:35 +00005533 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005534
Douglas Gregor5a064722011-02-28 17:23:35 +00005535 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5536 QualType Result
5537 = getSema().Context.getDependentTemplateSpecializationType(
5538 TL.getTypePtr()->getKeyword(),
5539 DTN->getQualifier(),
5540 DTN->getIdentifier(),
5541 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005542
Douglas Gregor5a064722011-02-28 17:23:35 +00005543 DependentTemplateSpecializationTypeLoc NewTL
5544 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005545 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005546 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005547 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005548 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005549 NewTL.setLAngleLoc(TL.getLAngleLoc());
5550 NewTL.setRAngleLoc(TL.getRAngleLoc());
5551 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5552 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5553 return Result;
5554 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005555
5556 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005557 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005558 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005559 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005560
Douglas Gregor5a064722011-02-28 17:23:35 +00005561 if (!Result.isNull()) {
5562 /// FIXME: Wrap this in an elaborated-type-specifier?
5563 TemplateSpecializationTypeLoc NewTL
5564 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005565 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005566 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005567 NewTL.setLAngleLoc(TL.getLAngleLoc());
5568 NewTL.setRAngleLoc(TL.getRAngleLoc());
5569 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5570 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5571 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005572
Douglas Gregor5a064722011-02-28 17:23:35 +00005573 return Result;
5574}
5575
Mike Stump11289f42009-09-09 15:08:12 +00005576template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005577QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005578TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005579 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005580 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005581
Douglas Gregor844cb502011-03-01 18:12:44 +00005582 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005583 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005584 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005585 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005586 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5587 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005588 return QualType();
5589 }
Mike Stump11289f42009-09-09 15:08:12 +00005590
John McCall31f82722010-11-12 08:19:04 +00005591 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5592 if (NamedT.isNull())
5593 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005594
Richard Smith3f1b5d02011-05-05 21:57:07 +00005595 // C++0x [dcl.type.elab]p2:
5596 // If the identifier resolves to a typedef-name or the simple-template-id
5597 // resolves to an alias template specialization, the
5598 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005599 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5600 if (const TemplateSpecializationType *TST =
5601 NamedT->getAs<TemplateSpecializationType>()) {
5602 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00005603 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5604 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00005605 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5606 diag::err_tag_reference_non_tag) << 4;
5607 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5608 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005609 }
5610 }
5611
John McCall550e0c22009-10-21 00:40:46 +00005612 QualType Result = TL.getType();
5613 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005614 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005615 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005616 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005617 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005618 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005619 if (Result.isNull())
5620 return QualType();
5621 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005622
Abramo Bagnara6150c882010-05-11 21:36:43 +00005623 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005624 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005625 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005626 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005627}
Mike Stump11289f42009-09-09 15:08:12 +00005628
5629template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005630QualType TreeTransform<Derived>::TransformAttributedType(
5631 TypeLocBuilder &TLB,
5632 AttributedTypeLoc TL) {
5633 const AttributedType *oldType = TL.getTypePtr();
5634 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5635 if (modifiedType.isNull())
5636 return QualType();
5637
5638 QualType result = TL.getType();
5639
5640 // FIXME: dependent operand expressions?
5641 if (getDerived().AlwaysRebuild() ||
5642 modifiedType != oldType->getModifiedType()) {
5643 // TODO: this is really lame; we should really be rebuilding the
5644 // equivalent type from first principles.
5645 QualType equivalentType
5646 = getDerived().TransformType(oldType->getEquivalentType());
5647 if (equivalentType.isNull())
5648 return QualType();
Douglas Gregor261a89b2015-06-19 17:51:05 +00005649
5650 // Check whether we can add nullability; it is only represented as
5651 // type sugar, and therefore cannot be diagnosed in any other way.
5652 if (auto nullability = oldType->getImmediateNullability()) {
5653 if (!modifiedType->canHaveNullability()) {
5654 SemaRef.Diag(TL.getAttrNameLoc(), diag::err_nullability_nonpointer)
Douglas Gregoraea7afd2015-06-24 22:02:08 +00005655 << DiagNullabilityKind(*nullability, false) << modifiedType;
Douglas Gregor261a89b2015-06-19 17:51:05 +00005656 return QualType();
5657 }
5658 }
5659
John McCall81904512011-01-06 01:58:22 +00005660 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5661 modifiedType,
5662 equivalentType);
5663 }
5664
5665 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5666 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5667 if (TL.hasAttrOperand())
5668 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5669 if (TL.hasAttrExprOperand())
5670 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5671 else if (TL.hasAttrEnumOperand())
5672 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5673
5674 return result;
5675}
5676
5677template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005678QualType
5679TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5680 ParenTypeLoc TL) {
5681 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5682 if (Inner.isNull())
5683 return QualType();
5684
5685 QualType Result = TL.getType();
5686 if (getDerived().AlwaysRebuild() ||
5687 Inner != TL.getInnerLoc().getType()) {
5688 Result = getDerived().RebuildParenType(Inner);
5689 if (Result.isNull())
5690 return QualType();
5691 }
5692
5693 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5694 NewTL.setLParenLoc(TL.getLParenLoc());
5695 NewTL.setRParenLoc(TL.getRParenLoc());
5696 return Result;
5697}
5698
5699template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005700QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005701 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005702 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005703
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005704 NestedNameSpecifierLoc QualifierLoc
5705 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5706 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005707 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005708
John McCallc392f372010-06-11 00:33:02 +00005709 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005710 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005711 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005712 QualifierLoc,
5713 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005714 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005715 if (Result.isNull())
5716 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005717
Abramo Bagnarad7548482010-05-19 21:37:53 +00005718 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5719 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005720 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5721
Abramo Bagnarad7548482010-05-19 21:37:53 +00005722 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005723 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005724 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005725 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005726 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005727 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005728 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005729 NewTL.setNameLoc(TL.getNameLoc());
5730 }
John McCall550e0c22009-10-21 00:40:46 +00005731 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005732}
Mike Stump11289f42009-09-09 15:08:12 +00005733
Douglas Gregord6ff3322009-08-04 16:50:30 +00005734template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005735QualType TreeTransform<Derived>::
5736 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005737 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005738 NestedNameSpecifierLoc QualifierLoc;
5739 if (TL.getQualifierLoc()) {
5740 QualifierLoc
5741 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5742 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005743 return QualType();
5744 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005745
John McCall31f82722010-11-12 08:19:04 +00005746 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005747 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005748}
5749
5750template<typename Derived>
5751QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005752TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5753 DependentTemplateSpecializationTypeLoc TL,
5754 NestedNameSpecifierLoc QualifierLoc) {
5755 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005756
Douglas Gregora7a795b2011-03-01 20:11:18 +00005757 TemplateArgumentListInfo NewTemplateArgs;
5758 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5759 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005760
Douglas Gregora7a795b2011-03-01 20:11:18 +00005761 typedef TemplateArgumentLocContainerIterator<
5762 DependentTemplateSpecializationTypeLoc> ArgIterator;
5763 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5764 ArgIterator(TL, TL.getNumArgs()),
5765 NewTemplateArgs))
5766 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005767
Douglas Gregora7a795b2011-03-01 20:11:18 +00005768 QualType Result
5769 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5770 QualifierLoc,
5771 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005772 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005773 NewTemplateArgs);
5774 if (Result.isNull())
5775 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005776
Douglas Gregora7a795b2011-03-01 20:11:18 +00005777 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5778 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005779
Douglas Gregora7a795b2011-03-01 20:11:18 +00005780 // Copy information relevant to the template specialization.
5781 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005782 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005783 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005784 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005785 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5786 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005787 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005788 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005789
Douglas Gregora7a795b2011-03-01 20:11:18 +00005790 // Copy information relevant to the elaborated type.
5791 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005792 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005793 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005794 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5795 DependentTemplateSpecializationTypeLoc SpecTL
5796 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005797 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005798 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005799 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005800 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005801 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5802 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005803 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005804 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005805 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005806 TemplateSpecializationTypeLoc SpecTL
5807 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005808 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005809 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005810 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5811 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005812 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005813 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005814 }
5815 return Result;
5816}
5817
5818template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005819QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5820 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005821 QualType Pattern
5822 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005823 if (Pattern.isNull())
5824 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005825
5826 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005827 if (getDerived().AlwaysRebuild() ||
5828 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005829 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005830 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005831 TL.getEllipsisLoc(),
5832 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005833 if (Result.isNull())
5834 return QualType();
5835 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005836
Douglas Gregor822d0302011-01-12 17:07:58 +00005837 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5838 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5839 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005840}
5841
5842template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005843QualType
5844TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005845 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005846 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005847 TLB.pushFullCopy(TL);
5848 return TL.getType();
5849}
5850
5851template<typename Derived>
5852QualType
5853TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005854 ObjCObjectTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00005855 // Transform base type.
5856 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
5857 if (BaseType.isNull())
5858 return QualType();
5859
5860 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
5861
5862 // Transform type arguments.
5863 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
5864 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
5865 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
5866 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
5867 QualType TypeArg = TypeArgInfo->getType();
5868 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
5869 AnyChanged = true;
5870
5871 // We have a pack expansion. Instantiate it.
5872 const auto *PackExpansion = PackExpansionLoc.getType()
5873 ->castAs<PackExpansionType>();
5874 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5875 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5876 Unexpanded);
5877 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5878
5879 // Determine whether the set of unexpanded parameter packs can
5880 // and should be expanded.
5881 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
5882 bool Expand = false;
5883 bool RetainExpansion = false;
5884 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5885 if (getDerived().TryExpandParameterPacks(
5886 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
5887 Unexpanded, Expand, RetainExpansion, NumExpansions))
5888 return QualType();
5889
5890 if (!Expand) {
5891 // We can't expand this pack expansion into separate arguments yet;
5892 // just substitute into the pattern and create a new pack expansion
5893 // type.
5894 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5895
5896 TypeLocBuilder TypeArgBuilder;
5897 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
5898 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
5899 PatternLoc);
5900 if (NewPatternType.isNull())
5901 return QualType();
5902
5903 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
5904 NewPatternType, NumExpansions);
5905 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
5906 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
5907 NewTypeArgInfos.push_back(
5908 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
5909 continue;
5910 }
5911
5912 // Substitute into the pack expansion pattern for each slice of the
5913 // pack.
5914 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5915 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5916
5917 TypeLocBuilder TypeArgBuilder;
5918 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
5919
5920 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
5921 PatternLoc);
5922 if (NewTypeArg.isNull())
5923 return QualType();
5924
5925 NewTypeArgInfos.push_back(
5926 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
5927 }
5928
5929 continue;
5930 }
5931
5932 TypeLocBuilder TypeArgBuilder;
5933 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
5934 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
5935 if (NewTypeArg.isNull())
5936 return QualType();
5937
5938 // If nothing changed, just keep the old TypeSourceInfo.
5939 if (NewTypeArg == TypeArg) {
5940 NewTypeArgInfos.push_back(TypeArgInfo);
5941 continue;
5942 }
5943
5944 NewTypeArgInfos.push_back(
5945 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
5946 AnyChanged = true;
5947 }
5948
5949 QualType Result = TL.getType();
5950 if (getDerived().AlwaysRebuild() || AnyChanged) {
5951 // Rebuild the type.
5952 Result = getDerived().RebuildObjCObjectType(
5953 BaseType,
5954 TL.getLocStart(),
5955 TL.getTypeArgsLAngleLoc(),
5956 NewTypeArgInfos,
5957 TL.getTypeArgsRAngleLoc(),
5958 TL.getProtocolLAngleLoc(),
5959 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
5960 TL.getNumProtocols()),
5961 TL.getProtocolLocs(),
5962 TL.getProtocolRAngleLoc());
5963
5964 if (Result.isNull())
5965 return QualType();
5966 }
5967
5968 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00005969 NewT.setHasBaseTypeAsWritten(true);
5970 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
5971 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
5972 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
5973 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
5974 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
5975 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
5976 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
5977 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
5978 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005979}
Mike Stump11289f42009-09-09 15:08:12 +00005980
5981template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005982QualType
5983TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005984 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00005985 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
5986 if (PointeeType.isNull())
5987 return QualType();
5988
5989 QualType Result = TL.getType();
5990 if (getDerived().AlwaysRebuild() ||
5991 PointeeType != TL.getPointeeLoc().getType()) {
5992 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
5993 TL.getStarLoc());
5994 if (Result.isNull())
5995 return QualType();
5996 }
5997
5998 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
5999 NewT.setStarLoc(TL.getStarLoc());
6000 return Result;
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00006001}
6002
Douglas Gregord6ff3322009-08-04 16:50:30 +00006003//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00006004// Statement transformation
6005//===----------------------------------------------------------------------===//
6006template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006007StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006008TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006009 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006010}
6011
6012template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006013StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006014TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
6015 return getDerived().TransformCompoundStmt(S, false);
6016}
6017
6018template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006019StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006020TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00006021 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00006022 Sema::CompoundScopeRAII CompoundScope(getSema());
6023
John McCall1ababa62010-08-27 19:56:05 +00006024 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00006025 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006026 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006027 for (auto *B : S->body()) {
6028 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00006029 if (Result.isInvalid()) {
6030 // Immediately fail if this was a DeclStmt, since it's very
6031 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006032 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00006033 return StmtError();
6034
6035 // Otherwise, just keep processing substatements and fail later.
6036 SubStmtInvalid = true;
6037 continue;
6038 }
Mike Stump11289f42009-09-09 15:08:12 +00006039
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006040 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006041 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006042 }
Mike Stump11289f42009-09-09 15:08:12 +00006043
John McCall1ababa62010-08-27 19:56:05 +00006044 if (SubStmtInvalid)
6045 return StmtError();
6046
Douglas Gregorebe10102009-08-20 07:17:43 +00006047 if (!getDerived().AlwaysRebuild() &&
6048 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006049 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006050
6051 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006052 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00006053 S->getRBracLoc(),
6054 IsStmtExpr);
6055}
Mike Stump11289f42009-09-09 15:08:12 +00006056
Douglas Gregorebe10102009-08-20 07:17:43 +00006057template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006058StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006059TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006060 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00006061 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00006062 EnterExpressionEvaluationContext Unevaluated(SemaRef,
6063 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006064
Eli Friedman06577382009-11-19 03:14:00 +00006065 // Transform the left-hand case value.
6066 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00006067 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00006068 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006069 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006070
Eli Friedman06577382009-11-19 03:14:00 +00006071 // Transform the right-hand case value (for the GNU case-range extension).
6072 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00006073 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00006074 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006075 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00006076 }
Mike Stump11289f42009-09-09 15:08:12 +00006077
Douglas Gregorebe10102009-08-20 07:17:43 +00006078 // Build the case statement.
6079 // Case statements are always rebuilt so that they will attached to their
6080 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006081 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00006082 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006083 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00006084 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006085 S->getColonLoc());
6086 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006087 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006088
Douglas Gregorebe10102009-08-20 07:17:43 +00006089 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00006090 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006091 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006092 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006093
Douglas Gregorebe10102009-08-20 07:17:43 +00006094 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00006095 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006096}
6097
6098template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006099StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006100TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006101 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00006102 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006103 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006104 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006105
Douglas Gregorebe10102009-08-20 07:17:43 +00006106 // Default statements are always rebuilt
6107 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006108 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006109}
Mike Stump11289f42009-09-09 15:08:12 +00006110
Douglas Gregorebe10102009-08-20 07:17:43 +00006111template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006112StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006113TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
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
Chris Lattnercab02a62011-02-17 20:34:02 +00006118 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
6119 S->getDecl());
6120 if (!LD)
6121 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00006122
6123
Douglas Gregorebe10102009-08-20 07:17:43 +00006124 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00006125 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006126 cast<LabelDecl>(LD), SourceLocation(),
6127 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006128}
Mike Stump11289f42009-09-09 15:08:12 +00006129
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006130template <typename Derived>
6131const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
6132 if (!R)
6133 return R;
6134
6135 switch (R->getKind()) {
6136// Transform attributes with a pragma spelling by calling TransformXXXAttr.
6137#define ATTR(X)
6138#define PRAGMA_SPELLING_ATTR(X) \
6139 case attr::X: \
6140 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
6141#include "clang/Basic/AttrList.inc"
6142 default:
6143 return R;
6144 }
6145}
6146
6147template <typename Derived>
6148StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
6149 bool AttrsChanged = false;
6150 SmallVector<const Attr *, 1> Attrs;
6151
6152 // Visit attributes and keep track if any are transformed.
6153 for (const auto *I : S->getAttrs()) {
6154 const Attr *R = getDerived().TransformAttr(I);
6155 AttrsChanged |= (I != R);
6156 Attrs.push_back(R);
6157 }
6158
Richard Smithc202b282012-04-14 00:33:13 +00006159 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6160 if (SubStmt.isInvalid())
6161 return StmtError();
6162
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006163 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
Richard Smithc202b282012-04-14 00:33:13 +00006164 return S;
6165
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006166 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00006167 SubStmt.get());
6168}
6169
6170template<typename Derived>
6171StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006172TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006173 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006174 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006175 VarDecl *ConditionVar = nullptr;
Douglas Gregor633caca2009-11-23 23:44:04 +00006176 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006177 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00006178 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006179 getDerived().TransformDefinition(
6180 S->getConditionVariable()->getLocation(),
6181 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00006182 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006183 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006184 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00006185 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006186
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006187 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006188 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006189
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006190 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00006191 if (S->getCond()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006192 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00006193 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00006194 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006195 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006196
John McCallb268a282010-08-23 23:25:46 +00006197 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006198 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006199 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006200
Richard Trieu43b4c822016-01-06 21:11:18 +00006201 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get(), S->getIfLoc()));
John McCallb268a282010-08-23 23:25:46 +00006202 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006203 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006204
Douglas Gregorebe10102009-08-20 07:17:43 +00006205 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00006206 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00006207 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006208 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006209
Douglas Gregorebe10102009-08-20 07:17:43 +00006210 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00006211 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00006212 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006213 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006214
Douglas Gregorebe10102009-08-20 07:17:43 +00006215 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00006216 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006217 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006218 Then.get() == S->getThen() &&
6219 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006220 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006221
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006222 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00006223 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00006224 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006225}
6226
6227template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006228StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006229TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006230 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00006231 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006232 VarDecl *ConditionVar = nullptr;
Douglas Gregordcf19622009-11-24 17:07:59 +00006233 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006234 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00006235 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006236 getDerived().TransformDefinition(
6237 S->getConditionVariable()->getLocation(),
6238 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00006239 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006240 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006241 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00006242 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006243
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006244 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006245 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006246 }
Mike Stump11289f42009-09-09 15:08:12 +00006247
Douglas Gregorebe10102009-08-20 07:17:43 +00006248 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006249 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00006250 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00006251 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00006252 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006253 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006254
Douglas Gregorebe10102009-08-20 07:17:43 +00006255 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006256 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006257 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006258 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006259
Douglas Gregorebe10102009-08-20 07:17:43 +00006260 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00006261 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
6262 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006263}
Mike Stump11289f42009-09-09 15:08:12 +00006264
Douglas Gregorebe10102009-08-20 07:17:43 +00006265template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006266StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006267TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006268 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006269 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006270 VarDecl *ConditionVar = nullptr;
Douglas Gregor680f8612009-11-24 21:15:44 +00006271 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006272 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00006273 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006274 getDerived().TransformDefinition(
6275 S->getConditionVariable()->getLocation(),
6276 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00006277 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006278 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006279 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00006280 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006281
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006282 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006283 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006284
6285 if (S->getCond()) {
6286 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00006287 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
6288 S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00006289 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00006290 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006291 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00006292 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00006293 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006294 }
Mike Stump11289f42009-09-09 15:08:12 +00006295
Richard Trieu43b4c822016-01-06 21:11:18 +00006296 Sema::FullExprArg FullCond(
6297 getSema().MakeFullExpr(Cond.get(), S->getWhileLoc()));
John McCallb268a282010-08-23 23:25:46 +00006298 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006299 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006300
Douglas Gregorebe10102009-08-20 07:17:43 +00006301 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006302 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006303 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006304 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006305
Douglas Gregorebe10102009-08-20 07:17:43 +00006306 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00006307 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006308 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006309 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00006310 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00006311
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006312 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00006313 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006314}
Mike Stump11289f42009-09-09 15:08:12 +00006315
Douglas Gregorebe10102009-08-20 07:17:43 +00006316template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006317StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006318TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006319 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006320 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006321 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006322 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006323
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006324 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006325 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006326 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006327 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006328
Douglas Gregorebe10102009-08-20 07:17:43 +00006329 if (!getDerived().AlwaysRebuild() &&
6330 Cond.get() == S->getCond() &&
6331 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006332 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006333
John McCallb268a282010-08-23 23:25:46 +00006334 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
6335 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006336 S->getRParenLoc());
6337}
Mike Stump11289f42009-09-09 15:08:12 +00006338
Douglas Gregorebe10102009-08-20 07:17:43 +00006339template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006340StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006341TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006342 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00006343 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00006344 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006345 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006346
Alexey Bataeva636c7f2015-12-23 10:27:45 +00006347 // In OpenMP loop region loop control variable must be captured and be
6348 // private. Perform analysis of first part (if any).
6349 if (getSema().getLangOpts().OpenMP && Init.isUsable())
6350 getSema().ActOnOpenMPLoopInitialization(S->getForLoc(), Init.get());
6351
Douglas Gregorebe10102009-08-20 07:17:43 +00006352 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006353 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006354 VarDecl *ConditionVar = nullptr;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006355 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006356 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006357 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006358 getDerived().TransformDefinition(
6359 S->getConditionVariable()->getLocation(),
6360 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006361 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006362 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006363 } else {
6364 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006365
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006366 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006367 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006368
6369 if (S->getCond()) {
6370 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00006371 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
6372 S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00006373 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00006374 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006375 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006376
John McCallb268a282010-08-23 23:25:46 +00006377 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006378 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006379 }
Mike Stump11289f42009-09-09 15:08:12 +00006380
Richard Trieu43b4c822016-01-06 21:11:18 +00006381 Sema::FullExprArg FullCond(
6382 getSema().MakeFullExpr(Cond.get(), S->getForLoc()));
John McCallb268a282010-08-23 23:25:46 +00006383 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006384 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006385
Douglas Gregorebe10102009-08-20 07:17:43 +00006386 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00006387 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006388 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006389 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006390
Richard Smith945f8d32013-01-14 22:39:08 +00006391 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00006392 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006393 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006394
Douglas Gregorebe10102009-08-20 07:17:43 +00006395 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006396 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006397 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006398 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006399
Douglas Gregorebe10102009-08-20 07:17:43 +00006400 if (!getDerived().AlwaysRebuild() &&
6401 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00006402 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006403 Inc.get() == S->getInc() &&
6404 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006405 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006406
Douglas Gregorebe10102009-08-20 07:17:43 +00006407 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006408 Init.get(), FullCond, ConditionVar,
6409 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006410}
6411
6412template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006413StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006414TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006415 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6416 S->getLabel());
6417 if (!LD)
6418 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006419
Douglas Gregorebe10102009-08-20 07:17:43 +00006420 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00006421 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006422 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00006423}
6424
6425template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006426StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006427TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006428 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00006429 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006430 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006431 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00006432
Douglas Gregorebe10102009-08-20 07:17:43 +00006433 if (!getDerived().AlwaysRebuild() &&
6434 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006435 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006436
6437 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00006438 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006439}
6440
6441template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006442StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006443TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006444 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006445}
Mike Stump11289f42009-09-09 15:08:12 +00006446
Douglas Gregorebe10102009-08-20 07:17:43 +00006447template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006448StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006449TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006450 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006451}
Mike Stump11289f42009-09-09 15:08:12 +00006452
Douglas Gregorebe10102009-08-20 07:17:43 +00006453template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006454StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006455TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00006456 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6457 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00006458 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006459 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006460
Mike Stump11289f42009-09-09 15:08:12 +00006461 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00006462 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00006463 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006464}
Mike Stump11289f42009-09-09 15:08:12 +00006465
Douglas Gregorebe10102009-08-20 07:17:43 +00006466template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006467StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006468TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006469 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006470 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006471 for (auto *D : S->decls()) {
6472 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00006473 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00006474 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006475
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006476 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00006477 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00006478
Douglas Gregorebe10102009-08-20 07:17:43 +00006479 Decls.push_back(Transformed);
6480 }
Mike Stump11289f42009-09-09 15:08:12 +00006481
Douglas Gregorebe10102009-08-20 07:17:43 +00006482 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006483 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006484
Rafael Espindolaab417692013-07-09 12:05:01 +00006485 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006486}
Mike Stump11289f42009-09-09 15:08:12 +00006487
Douglas Gregorebe10102009-08-20 07:17:43 +00006488template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006489StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00006490TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006491
Benjamin Kramerf0623432012-08-23 22:51:59 +00006492 SmallVector<Expr*, 8> Constraints;
6493 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006494 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00006495
John McCalldadc5752010-08-24 06:29:42 +00006496 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006497 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006498
6499 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00006500
Anders Carlssonaaeef072010-01-24 05:50:09 +00006501 // Go through the outputs.
6502 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006503 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006504
Anders Carlssonaaeef072010-01-24 05:50:09 +00006505 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006506 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006507
Anders Carlssonaaeef072010-01-24 05:50:09 +00006508 // Transform the output expr.
6509 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006510 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006511 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006512 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006513
Anders Carlssonaaeef072010-01-24 05:50:09 +00006514 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006515
John McCallb268a282010-08-23 23:25:46 +00006516 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006517 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006518
Anders Carlssonaaeef072010-01-24 05:50:09 +00006519 // Go through the inputs.
6520 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006521 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006522
Anders Carlssonaaeef072010-01-24 05:50:09 +00006523 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006524 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006525
Anders Carlssonaaeef072010-01-24 05:50:09 +00006526 // Transform the input expr.
6527 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006528 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006529 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006530 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006531
Anders Carlssonaaeef072010-01-24 05:50:09 +00006532 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006533
John McCallb268a282010-08-23 23:25:46 +00006534 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006535 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006536
Anders Carlssonaaeef072010-01-24 05:50:09 +00006537 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006538 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006539
6540 // Go through the clobbers.
6541 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00006542 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00006543
6544 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006545 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00006546 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
6547 S->isVolatile(), S->getNumOutputs(),
6548 S->getNumInputs(), Names.data(),
6549 Constraints, Exprs, AsmString.get(),
6550 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006551}
6552
Chad Rosier32503022012-06-11 20:47:18 +00006553template<typename Derived>
6554StmtResult
6555TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00006556 ArrayRef<Token> AsmToks =
6557 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00006558
John McCallf413f5e2013-05-03 00:10:13 +00006559 bool HadError = false, HadChange = false;
6560
6561 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6562 SmallVector<Expr*, 8> TransformedExprs;
6563 TransformedExprs.reserve(SrcExprs.size());
6564 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6565 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
6566 if (!Result.isUsable()) {
6567 HadError = true;
6568 } else {
6569 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006570 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00006571 }
6572 }
6573
6574 if (HadError) return StmtError();
6575 if (!HadChange && !getDerived().AlwaysRebuild())
6576 return Owned(S);
6577
Chad Rosierb6f46c12012-08-15 16:53:30 +00006578 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00006579 AsmToks, S->getAsmString(),
6580 S->getNumOutputs(), S->getNumInputs(),
6581 S->getAllConstraints(), S->getClobbers(),
6582 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00006583}
Douglas Gregorebe10102009-08-20 07:17:43 +00006584
Richard Smith9f690bd2015-10-27 06:02:45 +00006585// C++ Coroutines TS
6586
6587template<typename Derived>
6588StmtResult
6589TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) {
6590 // The coroutine body should be re-formed by the caller if necessary.
6591 return getDerived().TransformStmt(S->getBody());
6592}
6593
6594template<typename Derived>
6595StmtResult
6596TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
6597 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
6598 /*NotCopyInit*/false);
6599 if (Result.isInvalid())
6600 return StmtError();
6601
6602 // Always rebuild; we don't know if this needs to be injected into a new
6603 // context or if the promise type has changed.
6604 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get());
6605}
6606
6607template<typename Derived>
6608ExprResult
6609TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) {
6610 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
6611 /*NotCopyInit*/false);
6612 if (Result.isInvalid())
6613 return ExprError();
6614
6615 // Always rebuild; we don't know if this needs to be injected into a new
6616 // context or if the promise type has changed.
6617 return getDerived().RebuildCoawaitExpr(E->getKeywordLoc(), Result.get());
6618}
6619
6620template<typename Derived>
6621ExprResult
6622TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) {
6623 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
6624 /*NotCopyInit*/false);
6625 if (Result.isInvalid())
6626 return ExprError();
6627
6628 // Always rebuild; we don't know if this needs to be injected into a new
6629 // context or if the promise type has changed.
6630 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
6631}
6632
6633// Objective-C Statements.
6634
Douglas Gregorebe10102009-08-20 07:17:43 +00006635template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006636StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006637TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006638 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00006639 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006640 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006641 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006642
Douglas Gregor96c79492010-04-23 22:50:49 +00006643 // Transform the @catch statements (if present).
6644 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006645 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00006646 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006647 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00006648 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006649 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00006650 if (Catch.get() != S->getCatchStmt(I))
6651 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006652 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006653 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006654
Douglas Gregor306de2f2010-04-22 23:59:56 +00006655 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00006656 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006657 if (S->getFinallyStmt()) {
6658 Finally = getDerived().TransformStmt(S->getFinallyStmt());
6659 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006660 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00006661 }
6662
6663 // If nothing changed, just retain this statement.
6664 if (!getDerived().AlwaysRebuild() &&
6665 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00006666 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00006667 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006668 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006669
Douglas Gregor306de2f2010-04-22 23:59:56 +00006670 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00006671 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006672 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006673}
Mike Stump11289f42009-09-09 15:08:12 +00006674
Douglas Gregorebe10102009-08-20 07:17:43 +00006675template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006676StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006677TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006678 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00006679 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006680 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006681 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006682 if (FromVar->getTypeSourceInfo()) {
6683 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
6684 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006685 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006686 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006687
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006688 QualType T;
6689 if (TSInfo)
6690 T = TSInfo->getType();
6691 else {
6692 T = getDerived().TransformType(FromVar->getType());
6693 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00006694 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006695 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006696
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006697 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6698 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00006699 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006700 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006701
John McCalldadc5752010-08-24 06:29:42 +00006702 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006703 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006704 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006705
6706 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006707 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006708 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006709}
Mike Stump11289f42009-09-09 15:08:12 +00006710
Douglas Gregorebe10102009-08-20 07:17:43 +00006711template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006712StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006713TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006714 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006715 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006716 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006717 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006718
Douglas Gregor306de2f2010-04-22 23:59:56 +00006719 // If nothing changed, just retain this statement.
6720 if (!getDerived().AlwaysRebuild() &&
6721 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006722 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006723
6724 // Build a new statement.
6725 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00006726 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006727}
Mike Stump11289f42009-09-09 15:08:12 +00006728
Douglas Gregorebe10102009-08-20 07:17:43 +00006729template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006730StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006731TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006732 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00006733 if (S->getThrowExpr()) {
6734 Operand = getDerived().TransformExpr(S->getThrowExpr());
6735 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006736 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00006737 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006738
Douglas Gregor2900c162010-04-22 21:44:01 +00006739 if (!getDerived().AlwaysRebuild() &&
6740 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006741 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006742
John McCallb268a282010-08-23 23:25:46 +00006743 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006744}
Mike Stump11289f42009-09-09 15:08:12 +00006745
Douglas Gregorebe10102009-08-20 07:17:43 +00006746template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006747StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006748TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006749 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00006750 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00006751 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00006752 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006753 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00006754 Object =
6755 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6756 Object.get());
6757 if (Object.isInvalid())
6758 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006759
Douglas Gregor6148de72010-04-22 22:01:21 +00006760 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006761 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00006762 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006763 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006764
Douglas Gregor6148de72010-04-22 22:01:21 +00006765 // If nothing change, just retain the current statement.
6766 if (!getDerived().AlwaysRebuild() &&
6767 Object.get() == S->getSynchExpr() &&
6768 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006769 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00006770
6771 // Build a new statement.
6772 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00006773 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006774}
6775
6776template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006777StmtResult
John McCall31168b02011-06-15 23:02:42 +00006778TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6779 ObjCAutoreleasePoolStmt *S) {
6780 // Transform the body.
6781 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6782 if (Body.isInvalid())
6783 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006784
John McCall31168b02011-06-15 23:02:42 +00006785 // If nothing changed, just retain this statement.
6786 if (!getDerived().AlwaysRebuild() &&
6787 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006788 return S;
John McCall31168b02011-06-15 23:02:42 +00006789
6790 // Build a new statement.
6791 return getDerived().RebuildObjCAutoreleasePoolStmt(
6792 S->getAtLoc(), Body.get());
6793}
6794
6795template<typename Derived>
6796StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006797TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006798 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006799 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006800 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006801 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006802 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006803
Douglas Gregorf68a5082010-04-22 23:10:45 +00006804 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006805 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006806 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006807 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006808
Douglas Gregorf68a5082010-04-22 23:10:45 +00006809 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006810 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006811 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006812 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006813
Douglas Gregorf68a5082010-04-22 23:10:45 +00006814 // If nothing changed, just retain this statement.
6815 if (!getDerived().AlwaysRebuild() &&
6816 Element.get() == S->getElement() &&
6817 Collection.get() == S->getCollection() &&
6818 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006819 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006820
Douglas Gregorf68a5082010-04-22 23:10:45 +00006821 // Build a new statement.
6822 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006823 Element.get(),
6824 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006825 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006826 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006827}
6828
David Majnemer5f7efef2013-10-15 09:50:08 +00006829template <typename Derived>
6830StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006831 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006832 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006833 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6834 TypeSourceInfo *T =
6835 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006836 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006837 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006838
David Majnemer5f7efef2013-10-15 09:50:08 +00006839 Var = getDerived().RebuildExceptionDecl(
6840 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6841 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006842 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006843 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006844 }
Mike Stump11289f42009-09-09 15:08:12 +00006845
Douglas Gregorebe10102009-08-20 07:17:43 +00006846 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006847 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006848 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006849 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006850
David Majnemer5f7efef2013-10-15 09:50:08 +00006851 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006852 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006853 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006854
David Majnemer5f7efef2013-10-15 09:50:08 +00006855 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006856}
Mike Stump11289f42009-09-09 15:08:12 +00006857
David Majnemer5f7efef2013-10-15 09:50:08 +00006858template <typename Derived>
6859StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006860 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006861 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006862 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006863 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006864
Douglas Gregorebe10102009-08-20 07:17:43 +00006865 // Transform the handlers.
6866 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006867 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006868 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006869 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006870 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006871 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006872
Douglas Gregorebe10102009-08-20 07:17:43 +00006873 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006874 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006875 }
Mike Stump11289f42009-09-09 15:08:12 +00006876
David Majnemer5f7efef2013-10-15 09:50:08 +00006877 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006878 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006879 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006880
John McCallb268a282010-08-23 23:25:46 +00006881 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006882 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006883}
Mike Stump11289f42009-09-09 15:08:12 +00006884
Richard Smith02e85f32011-04-14 22:09:26 +00006885template<typename Derived>
6886StmtResult
6887TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6888 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6889 if (Range.isInvalid())
6890 return StmtError();
6891
Richard Smith01694c32016-03-20 10:33:40 +00006892 StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
6893 if (Begin.isInvalid())
6894 return StmtError();
6895 StmtResult End = getDerived().TransformStmt(S->getEndStmt());
6896 if (End.isInvalid())
Richard Smith02e85f32011-04-14 22:09:26 +00006897 return StmtError();
6898
6899 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6900 if (Cond.isInvalid())
6901 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006902 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006903 Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc());
Eli Friedman87d32802012-01-31 22:45:40 +00006904 if (Cond.isInvalid())
6905 return StmtError();
6906 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006907 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006908
6909 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6910 if (Inc.isInvalid())
6911 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006912 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006913 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006914
6915 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6916 if (LoopVar.isInvalid())
6917 return StmtError();
6918
6919 StmtResult NewStmt = S;
6920 if (getDerived().AlwaysRebuild() ||
6921 Range.get() != S->getRangeStmt() ||
Richard Smith01694c32016-03-20 10:33:40 +00006922 Begin.get() != S->getBeginStmt() ||
6923 End.get() != S->getEndStmt() ||
Richard Smith02e85f32011-04-14 22:09:26 +00006924 Cond.get() != S->getCond() ||
6925 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006926 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006927 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00006928 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00006929 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00006930 Begin.get(), End.get(),
6931 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00006932 Inc.get(), LoopVar.get(),
6933 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006934 if (NewStmt.isInvalid())
6935 return StmtError();
6936 }
Richard Smith02e85f32011-04-14 22:09:26 +00006937
6938 StmtResult Body = getDerived().TransformStmt(S->getBody());
6939 if (Body.isInvalid())
6940 return StmtError();
6941
6942 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6943 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006944 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006945 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00006946 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00006947 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00006948 Begin.get(), End.get(),
6949 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00006950 Inc.get(), LoopVar.get(),
6951 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006952 if (NewStmt.isInvalid())
6953 return StmtError();
6954 }
Richard Smith02e85f32011-04-14 22:09:26 +00006955
6956 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006957 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00006958
6959 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6960}
6961
John Wiegley1c0675e2011-04-28 01:08:34 +00006962template<typename Derived>
6963StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006964TreeTransform<Derived>::TransformMSDependentExistsStmt(
6965 MSDependentExistsStmt *S) {
6966 // Transform the nested-name-specifier, if any.
6967 NestedNameSpecifierLoc QualifierLoc;
6968 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006969 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006970 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6971 if (!QualifierLoc)
6972 return StmtError();
6973 }
6974
6975 // Transform the declaration name.
6976 DeclarationNameInfo NameInfo = S->getNameInfo();
6977 if (NameInfo.getName()) {
6978 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6979 if (!NameInfo.getName())
6980 return StmtError();
6981 }
6982
6983 // Check whether anything changed.
6984 if (!getDerived().AlwaysRebuild() &&
6985 QualifierLoc == S->getQualifierLoc() &&
6986 NameInfo.getName() == S->getNameInfo().getName())
6987 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006988
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006989 // Determine whether this name exists, if we can.
6990 CXXScopeSpec SS;
6991 SS.Adopt(QualifierLoc);
6992 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00006993 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006994 case Sema::IER_Exists:
6995 if (S->isIfExists())
6996 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006997
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006998 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6999
7000 case Sema::IER_DoesNotExist:
7001 if (S->isIfNotExists())
7002 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007003
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007004 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00007005
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007006 case Sema::IER_Dependent:
7007 Dependent = true;
7008 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007009
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00007010 case Sema::IER_Error:
7011 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007012 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007013
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007014 // We need to continue with the instantiation, so do so now.
7015 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
7016 if (SubStmt.isInvalid())
7017 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007018
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007019 // If we have resolved the name, just transform to the substatement.
7020 if (!Dependent)
7021 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00007022
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007023 // The name is still dependent, so build a dependent expression again.
7024 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
7025 S->isIfExists(),
7026 QualifierLoc,
7027 NameInfo,
7028 SubStmt.get());
7029}
7030
7031template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00007032ExprResult
7033TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
7034 NestedNameSpecifierLoc QualifierLoc;
7035 if (E->getQualifierLoc()) {
7036 QualifierLoc
7037 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7038 if (!QualifierLoc)
7039 return ExprError();
7040 }
7041
7042 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
7043 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
7044 if (!PD)
7045 return ExprError();
7046
7047 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
7048 if (Base.isInvalid())
7049 return ExprError();
7050
7051 return new (SemaRef.getASTContext())
7052 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
7053 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
7054 QualifierLoc, E->getMemberLoc());
7055}
7056
David Majnemerfad8f482013-10-15 09:33:02 +00007057template <typename Derived>
Alexey Bataevf7630272015-11-25 12:01:00 +00007058ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr(
7059 MSPropertySubscriptExpr *E) {
7060 auto BaseRes = getDerived().TransformExpr(E->getBase());
7061 if (BaseRes.isInvalid())
7062 return ExprError();
7063 auto IdxRes = getDerived().TransformExpr(E->getIdx());
7064 if (IdxRes.isInvalid())
7065 return ExprError();
7066
7067 if (!getDerived().AlwaysRebuild() &&
7068 BaseRes.get() == E->getBase() &&
7069 IdxRes.get() == E->getIdx())
7070 return E;
7071
7072 return getDerived().RebuildArraySubscriptExpr(
7073 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
7074}
7075
7076template <typename Derived>
David Majnemerfad8f482013-10-15 09:33:02 +00007077StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007078 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007079 if (TryBlock.isInvalid())
7080 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007081
7082 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00007083 if (Handler.isInvalid())
7084 return StmtError();
7085
David Majnemerfad8f482013-10-15 09:33:02 +00007086 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
7087 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007088 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00007089
Warren Huntf6be4cb2014-07-25 20:52:51 +00007090 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
7091 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007092}
7093
David Majnemerfad8f482013-10-15 09:33:02 +00007094template <typename Derived>
7095StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007096 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007097 if (Block.isInvalid())
7098 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007099
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007100 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007101}
7102
David Majnemerfad8f482013-10-15 09:33:02 +00007103template <typename Derived>
7104StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00007105 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00007106 if (FilterExpr.isInvalid())
7107 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007108
David Majnemer7e755502013-10-15 09:30:14 +00007109 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007110 if (Block.isInvalid())
7111 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007112
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007113 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
7114 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007115}
7116
David Majnemerfad8f482013-10-15 09:33:02 +00007117template <typename Derived>
7118StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
7119 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00007120 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
7121 else
7122 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
7123}
7124
Nico Weber9b982072014-07-07 00:12:30 +00007125template<typename Derived>
7126StmtResult
7127TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
7128 return S;
7129}
7130
Alexander Musman64d33f12014-06-04 07:53:32 +00007131//===----------------------------------------------------------------------===//
7132// OpenMP directive transformation
7133//===----------------------------------------------------------------------===//
7134template <typename Derived>
7135StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
7136 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007137
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007138 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00007139 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007140 ArrayRef<OMPClause *> Clauses = D->clauses();
7141 TClauses.reserve(Clauses.size());
7142 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
7143 I != E; ++I) {
7144 if (*I) {
Alexey Bataevaac108a2015-06-23 04:51:00 +00007145 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007146 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevaac108a2015-06-23 04:51:00 +00007147 getDerived().getSema().EndOpenMPClause();
Alexey Bataevc5e02582014-06-16 07:08:35 +00007148 if (Clause)
7149 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00007150 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00007151 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007152 }
7153 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007154 StmtResult AssociatedStmt;
Alexey Bataeveb482352015-12-18 05:05:56 +00007155 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00007156 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
7157 /*CurScope=*/nullptr);
7158 StmtResult Body;
7159 {
7160 Sema::CompoundScopeRAII CompoundScope(getSema());
7161 Body = getDerived().TransformStmt(
7162 cast<CapturedStmt>(D->getAssociatedStmt())->getCapturedStmt());
7163 }
7164 AssociatedStmt =
7165 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
Alexey Bataev68446b72014-07-18 07:47:19 +00007166 if (AssociatedStmt.isInvalid()) {
7167 return StmtError();
7168 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00007169 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007170 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007171 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00007172 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007173
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007174 // Transform directive name for 'omp critical' directive.
7175 DeclarationNameInfo DirName;
7176 if (D->getDirectiveKind() == OMPD_critical) {
7177 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
7178 DirName = getDerived().TransformDeclarationNameInfo(DirName);
7179 }
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007180 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
7181 if (D->getDirectiveKind() == OMPD_cancellation_point) {
7182 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
Alexey Bataev80909872015-07-02 11:25:17 +00007183 } else if (D->getDirectiveKind() == OMPD_cancel) {
7184 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007185 }
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007186
Alexander Musman64d33f12014-06-04 07:53:32 +00007187 return getDerived().RebuildOMPExecutableDirective(
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007188 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
7189 AssociatedStmt.get(), D->getLocStart(), D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007190}
7191
Alexander Musman64d33f12014-06-04 07:53:32 +00007192template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007193StmtResult
7194TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
7195 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007196 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
7197 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007198 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7199 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7200 return Res;
7201}
7202
Alexander Musman64d33f12014-06-04 07:53:32 +00007203template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007204StmtResult
7205TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
7206 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007207 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
7208 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007209 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7210 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007211 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007212}
7213
Alexey Bataevf29276e2014-06-18 04:14:57 +00007214template <typename Derived>
7215StmtResult
7216TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
7217 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007218 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
7219 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00007220 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7221 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7222 return Res;
7223}
7224
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007225template <typename Derived>
7226StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00007227TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
7228 DeclarationNameInfo DirName;
7229 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
7230 D->getLocStart());
7231 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7232 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7233 return Res;
7234}
7235
7236template <typename Derived>
7237StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007238TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
7239 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007240 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
7241 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007242 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7243 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7244 return Res;
7245}
7246
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007247template <typename Derived>
7248StmtResult
7249TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
7250 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007251 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
7252 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007253 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7254 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7255 return Res;
7256}
7257
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007258template <typename Derived>
7259StmtResult
7260TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
7261 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007262 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
7263 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007264 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7265 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7266 return Res;
7267}
7268
Alexey Bataev4acb8592014-07-07 13:01:15 +00007269template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00007270StmtResult
7271TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
7272 DeclarationNameInfo DirName;
7273 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
7274 D->getLocStart());
7275 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7276 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7277 return Res;
7278}
7279
7280template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007281StmtResult
7282TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
7283 getDerived().getSema().StartOpenMPDSABlock(
7284 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
7285 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7286 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7287 return Res;
7288}
7289
7290template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00007291StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
7292 OMPParallelForDirective *D) {
7293 DeclarationNameInfo DirName;
7294 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
7295 nullptr, D->getLocStart());
7296 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7297 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7298 return Res;
7299}
7300
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007301template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00007302StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
7303 OMPParallelForSimdDirective *D) {
7304 DeclarationNameInfo DirName;
7305 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
7306 nullptr, D->getLocStart());
7307 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7308 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7309 return Res;
7310}
7311
7312template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007313StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
7314 OMPParallelSectionsDirective *D) {
7315 DeclarationNameInfo DirName;
7316 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
7317 nullptr, D->getLocStart());
7318 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7319 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7320 return Res;
7321}
7322
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00007323template <typename Derived>
7324StmtResult
7325TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
7326 DeclarationNameInfo DirName;
7327 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
7328 D->getLocStart());
7329 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7330 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7331 return Res;
7332}
7333
Alexey Bataev68446b72014-07-18 07:47:19 +00007334template <typename Derived>
7335StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
7336 OMPTaskyieldDirective *D) {
7337 DeclarationNameInfo DirName;
7338 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
7339 D->getLocStart());
7340 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7341 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7342 return Res;
7343}
7344
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00007345template <typename Derived>
7346StmtResult
7347TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
7348 DeclarationNameInfo DirName;
7349 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
7350 D->getLocStart());
7351 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7352 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7353 return Res;
7354}
7355
Alexey Bataev2df347a2014-07-18 10:17:07 +00007356template <typename Derived>
7357StmtResult
7358TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
7359 DeclarationNameInfo DirName;
7360 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
7361 D->getLocStart());
7362 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7363 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7364 return Res;
7365}
7366
Alexey Bataev6125da92014-07-21 11:26:11 +00007367template <typename Derived>
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00007368StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
7369 OMPTaskgroupDirective *D) {
7370 DeclarationNameInfo DirName;
7371 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
7372 D->getLocStart());
7373 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7374 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7375 return Res;
7376}
7377
7378template <typename Derived>
Alexey Bataev6125da92014-07-21 11:26:11 +00007379StmtResult
7380TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
7381 DeclarationNameInfo DirName;
7382 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
7383 D->getLocStart());
7384 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7385 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7386 return Res;
7387}
7388
Alexey Bataev9fb6e642014-07-22 06:45:04 +00007389template <typename Derived>
7390StmtResult
7391TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
7392 DeclarationNameInfo DirName;
7393 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
7394 D->getLocStart());
7395 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7396 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7397 return Res;
7398}
7399
Alexey Bataev0162e452014-07-22 10:10:35 +00007400template <typename Derived>
7401StmtResult
7402TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
7403 DeclarationNameInfo DirName;
7404 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
7405 D->getLocStart());
7406 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7407 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7408 return Res;
7409}
7410
Alexey Bataev0bd520b2014-09-19 08:19:49 +00007411template <typename Derived>
7412StmtResult
7413TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
7414 DeclarationNameInfo DirName;
7415 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
7416 D->getLocStart());
7417 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7418 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7419 return Res;
7420}
7421
Alexey Bataev13314bf2014-10-09 04:18:56 +00007422template <typename Derived>
Michael Wong65f367f2015-07-21 13:44:28 +00007423StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
7424 OMPTargetDataDirective *D) {
7425 DeclarationNameInfo DirName;
7426 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
7427 D->getLocStart());
7428 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7429 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7430 return Res;
7431}
7432
7433template <typename Derived>
Samuel Antaodf67fc42016-01-19 19:15:56 +00007434StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective(
7435 OMPTargetEnterDataDirective *D) {
7436 DeclarationNameInfo DirName;
7437 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_enter_data, DirName,
7438 nullptr, D->getLocStart());
7439 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7440 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7441 return Res;
7442}
7443
7444template <typename Derived>
Samuel Antao72590762016-01-19 20:04:50 +00007445StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective(
7446 OMPTargetExitDataDirective *D) {
7447 DeclarationNameInfo DirName;
7448 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_exit_data, DirName,
7449 nullptr, D->getLocStart());
7450 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7451 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7452 return Res;
7453}
7454
7455template <typename Derived>
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +00007456StmtResult TreeTransform<Derived>::TransformOMPTargetParallelDirective(
7457 OMPTargetParallelDirective *D) {
7458 DeclarationNameInfo DirName;
7459 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel, DirName,
7460 nullptr, D->getLocStart());
7461 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7462 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7463 return Res;
7464}
7465
7466template <typename Derived>
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +00007467StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForDirective(
7468 OMPTargetParallelForDirective *D) {
7469 DeclarationNameInfo DirName;
7470 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for, DirName,
7471 nullptr, D->getLocStart());
7472 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7473 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7474 return Res;
7475}
7476
7477template <typename Derived>
Alexey Bataev13314bf2014-10-09 04:18:56 +00007478StmtResult
7479TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
7480 DeclarationNameInfo DirName;
7481 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
7482 D->getLocStart());
7483 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7484 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7485 return Res;
7486}
7487
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007488template <typename Derived>
7489StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
7490 OMPCancellationPointDirective *D) {
7491 DeclarationNameInfo DirName;
7492 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
7493 nullptr, D->getLocStart());
7494 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7495 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7496 return Res;
7497}
7498
Alexey Bataev80909872015-07-02 11:25:17 +00007499template <typename Derived>
7500StmtResult
7501TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
7502 DeclarationNameInfo DirName;
7503 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
7504 D->getLocStart());
7505 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7506 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7507 return Res;
7508}
7509
Alexey Bataev49f6e782015-12-01 04:18:41 +00007510template <typename Derived>
7511StmtResult
7512TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
7513 DeclarationNameInfo DirName;
7514 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr,
7515 D->getLocStart());
7516 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7517 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7518 return Res;
7519}
7520
Alexey Bataev0a6ed842015-12-03 09:40:15 +00007521template <typename Derived>
7522StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective(
7523 OMPTaskLoopSimdDirective *D) {
7524 DeclarationNameInfo DirName;
7525 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop_simd, DirName,
7526 nullptr, D->getLocStart());
7527 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7528 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7529 return Res;
7530}
7531
Carlo Bertolli6200a3d2015-12-14 14:51:25 +00007532template <typename Derived>
7533StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective(
7534 OMPDistributeDirective *D) {
7535 DeclarationNameInfo DirName;
7536 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr,
7537 D->getLocStart());
7538 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7539 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7540 return Res;
7541}
7542
Alexander Musman64d33f12014-06-04 07:53:32 +00007543//===----------------------------------------------------------------------===//
7544// OpenMP clause transformation
7545//===----------------------------------------------------------------------===//
7546template <typename Derived>
7547OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00007548 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7549 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007550 return nullptr;
Alexey Bataev6b8046a2015-09-03 07:23:48 +00007551 return getDerived().RebuildOMPIfClause(
7552 C->getNameModifier(), Cond.get(), C->getLocStart(), C->getLParenLoc(),
7553 C->getNameModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007554}
7555
Alexander Musman64d33f12014-06-04 07:53:32 +00007556template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00007557OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
7558 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7559 if (Cond.isInvalid())
7560 return nullptr;
7561 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
7562 C->getLParenLoc(), C->getLocEnd());
7563}
7564
7565template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007566OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00007567TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
7568 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
7569 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007570 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00007571 return getDerived().RebuildOMPNumThreadsClause(
7572 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00007573}
7574
Alexey Bataev62c87d22014-03-21 04:51:18 +00007575template <typename Derived>
7576OMPClause *
7577TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
7578 ExprResult E = getDerived().TransformExpr(C->getSafelen());
7579 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007580 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00007581 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007582 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00007583}
7584
Alexander Musman8bd31e62014-05-27 15:12:19 +00007585template <typename Derived>
7586OMPClause *
Alexey Bataev66b15b52015-08-21 11:14:16 +00007587TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
7588 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
7589 if (E.isInvalid())
7590 return nullptr;
7591 return getDerived().RebuildOMPSimdlenClause(
7592 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7593}
7594
7595template <typename Derived>
7596OMPClause *
Alexander Musman8bd31e62014-05-27 15:12:19 +00007597TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
7598 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
7599 if (E.isInvalid())
Hans Wennborg59dbe862015-09-29 20:56:43 +00007600 return nullptr;
Alexander Musman8bd31e62014-05-27 15:12:19 +00007601 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007602 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00007603}
7604
Alexander Musman64d33f12014-06-04 07:53:32 +00007605template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00007606OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007607TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007608 return getDerived().RebuildOMPDefaultClause(
7609 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
7610 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007611}
7612
Alexander Musman64d33f12014-06-04 07:53:32 +00007613template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007614OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007615TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007616 return getDerived().RebuildOMPProcBindClause(
7617 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
7618 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007619}
7620
Alexander Musman64d33f12014-06-04 07:53:32 +00007621template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007622OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00007623TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
7624 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
7625 if (E.isInvalid())
7626 return nullptr;
7627 return getDerived().RebuildOMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00007628 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
Alexey Bataev56dafe82014-06-20 07:16:17 +00007629 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
Alexey Bataev6402bca2015-12-28 07:25:51 +00007630 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
Alexey Bataev56dafe82014-06-20 07:16:17 +00007631 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
7632}
7633
7634template <typename Derived>
7635OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007636TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
Alexey Bataev10e775f2015-07-30 11:36:16 +00007637 ExprResult E;
7638 if (auto *Num = C->getNumForLoops()) {
7639 E = getDerived().TransformExpr(Num);
7640 if (E.isInvalid())
7641 return nullptr;
7642 }
7643 return getDerived().RebuildOMPOrderedClause(C->getLocStart(), C->getLocEnd(),
7644 C->getLParenLoc(), E.get());
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007645}
7646
7647template <typename Derived>
7648OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00007649TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
7650 // No need to rebuild this clause, no template-dependent parameters.
7651 return C;
7652}
7653
7654template <typename Derived>
7655OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00007656TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
7657 // No need to rebuild this clause, no template-dependent parameters.
7658 return C;
7659}
7660
7661template <typename Derived>
7662OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007663TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
7664 // No need to rebuild this clause, no template-dependent parameters.
7665 return C;
7666}
7667
7668template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00007669OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
7670 // No need to rebuild this clause, no template-dependent parameters.
7671 return C;
7672}
7673
7674template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00007675OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
7676 // No need to rebuild this clause, no template-dependent parameters.
7677 return C;
7678}
7679
7680template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007681OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00007682TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
7683 // No need to rebuild this clause, no template-dependent parameters.
7684 return C;
7685}
7686
7687template <typename Derived>
7688OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00007689TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
7690 // No need to rebuild this clause, no template-dependent parameters.
7691 return C;
7692}
7693
7694template <typename Derived>
7695OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00007696TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
7697 // No need to rebuild this clause, no template-dependent parameters.
7698 return C;
7699}
7700
7701template <typename Derived>
7702OMPClause *
Alexey Bataev346265e2015-09-25 10:37:12 +00007703TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
7704 // No need to rebuild this clause, no template-dependent parameters.
7705 return C;
7706}
7707
7708template <typename Derived>
Alexey Bataevd14d1e62015-09-28 06:39:35 +00007709OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
7710 // No need to rebuild this clause, no template-dependent parameters.
7711 return C;
7712}
7713
7714template <typename Derived>
Alexey Bataev346265e2015-09-25 10:37:12 +00007715OMPClause *
Alexey Bataevb825de12015-12-07 10:51:44 +00007716TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
7717 // No need to rebuild this clause, no template-dependent parameters.
7718 return C;
7719}
7720
7721template <typename Derived>
7722OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007723TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007724 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007725 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007726 for (auto *VE : C->varlists()) {
7727 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007728 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007729 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007730 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007731 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007732 return getDerived().RebuildOMPPrivateClause(
7733 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007734}
7735
Alexander Musman64d33f12014-06-04 07:53:32 +00007736template <typename Derived>
7737OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
7738 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007739 llvm::SmallVector<Expr *, 16> Vars;
7740 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007741 for (auto *VE : C->varlists()) {
7742 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007743 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007744 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007745 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007746 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007747 return getDerived().RebuildOMPFirstprivateClause(
7748 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007749}
7750
Alexander Musman64d33f12014-06-04 07:53:32 +00007751template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007752OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00007753TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
7754 llvm::SmallVector<Expr *, 16> Vars;
7755 Vars.reserve(C->varlist_size());
7756 for (auto *VE : C->varlists()) {
7757 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7758 if (EVar.isInvalid())
7759 return nullptr;
7760 Vars.push_back(EVar.get());
7761 }
7762 return getDerived().RebuildOMPLastprivateClause(
7763 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7764}
7765
7766template <typename Derived>
7767OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00007768TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
7769 llvm::SmallVector<Expr *, 16> Vars;
7770 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007771 for (auto *VE : C->varlists()) {
7772 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00007773 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007774 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007775 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007776 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007777 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
7778 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007779}
7780
Alexander Musman64d33f12014-06-04 07:53:32 +00007781template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007782OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00007783TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
7784 llvm::SmallVector<Expr *, 16> Vars;
7785 Vars.reserve(C->varlist_size());
7786 for (auto *VE : C->varlists()) {
7787 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7788 if (EVar.isInvalid())
7789 return nullptr;
7790 Vars.push_back(EVar.get());
7791 }
7792 CXXScopeSpec ReductionIdScopeSpec;
7793 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
7794
7795 DeclarationNameInfo NameInfo = C->getNameInfo();
7796 if (NameInfo.getName()) {
7797 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7798 if (!NameInfo.getName())
7799 return nullptr;
7800 }
Alexey Bataeva839ddd2016-03-17 10:19:46 +00007801 // Build a list of all UDR decls with the same names ranged by the Scopes.
7802 // The Scope boundary is a duplication of the previous decl.
7803 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
7804 for (auto *E : C->reduction_ops()) {
7805 // Transform all the decls.
7806 if (E) {
7807 auto *ULE = cast<UnresolvedLookupExpr>(E);
7808 UnresolvedSet<8> Decls;
7809 for (auto *D : ULE->decls()) {
7810 NamedDecl *InstD =
7811 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
7812 Decls.addDecl(InstD, InstD->getAccess());
7813 }
7814 UnresolvedReductions.push_back(
7815 UnresolvedLookupExpr::Create(
7816 SemaRef.Context, /*NamingClass=*/nullptr,
7817 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context),
7818 NameInfo, /*ADL=*/true, ULE->isOverloaded(),
7819 Decls.begin(), Decls.end()));
7820 } else
7821 UnresolvedReductions.push_back(nullptr);
7822 }
Alexey Bataevc5e02582014-06-16 07:08:35 +00007823 return getDerived().RebuildOMPReductionClause(
7824 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
Alexey Bataeva839ddd2016-03-17 10:19:46 +00007825 C->getLocEnd(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00007826}
7827
7828template <typename Derived>
7829OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00007830TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
7831 llvm::SmallVector<Expr *, 16> Vars;
7832 Vars.reserve(C->varlist_size());
7833 for (auto *VE : C->varlists()) {
7834 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7835 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007836 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007837 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00007838 }
7839 ExprResult Step = getDerived().TransformExpr(C->getStep());
7840 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007841 return nullptr;
Alexey Bataev182227b2015-08-20 10:54:39 +00007842 return getDerived().RebuildOMPLinearClause(
7843 Vars, Step.get(), C->getLocStart(), C->getLParenLoc(), C->getModifier(),
7844 C->getModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00007845}
7846
Alexander Musman64d33f12014-06-04 07:53:32 +00007847template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00007848OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007849TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
7850 llvm::SmallVector<Expr *, 16> Vars;
7851 Vars.reserve(C->varlist_size());
7852 for (auto *VE : C->varlists()) {
7853 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7854 if (EVar.isInvalid())
7855 return nullptr;
7856 Vars.push_back(EVar.get());
7857 }
7858 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
7859 if (Alignment.isInvalid())
7860 return nullptr;
7861 return getDerived().RebuildOMPAlignedClause(
7862 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
7863 C->getColonLoc(), C->getLocEnd());
7864}
7865
Alexander Musman64d33f12014-06-04 07:53:32 +00007866template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007867OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007868TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
7869 llvm::SmallVector<Expr *, 16> Vars;
7870 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007871 for (auto *VE : C->varlists()) {
7872 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007873 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007874 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007875 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007876 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007877 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
7878 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007879}
7880
Alexey Bataevbae9a792014-06-27 10:37:06 +00007881template <typename Derived>
7882OMPClause *
7883TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
7884 llvm::SmallVector<Expr *, 16> Vars;
7885 Vars.reserve(C->varlist_size());
7886 for (auto *VE : C->varlists()) {
7887 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7888 if (EVar.isInvalid())
7889 return nullptr;
7890 Vars.push_back(EVar.get());
7891 }
7892 return getDerived().RebuildOMPCopyprivateClause(
7893 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7894}
7895
Alexey Bataev6125da92014-07-21 11:26:11 +00007896template <typename Derived>
7897OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
7898 llvm::SmallVector<Expr *, 16> Vars;
7899 Vars.reserve(C->varlist_size());
7900 for (auto *VE : C->varlists()) {
7901 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7902 if (EVar.isInvalid())
7903 return nullptr;
7904 Vars.push_back(EVar.get());
7905 }
7906 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
7907 C->getLParenLoc(), C->getLocEnd());
7908}
7909
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00007910template <typename Derived>
7911OMPClause *
7912TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
7913 llvm::SmallVector<Expr *, 16> Vars;
7914 Vars.reserve(C->varlist_size());
7915 for (auto *VE : C->varlists()) {
7916 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7917 if (EVar.isInvalid())
7918 return nullptr;
7919 Vars.push_back(EVar.get());
7920 }
7921 return getDerived().RebuildOMPDependClause(
7922 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
7923 C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7924}
7925
Michael Wonge710d542015-08-07 16:16:36 +00007926template <typename Derived>
7927OMPClause *
7928TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
7929 ExprResult E = getDerived().TransformExpr(C->getDevice());
7930 if (E.isInvalid())
7931 return nullptr;
7932 return getDerived().RebuildOMPDeviceClause(
7933 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7934}
7935
Kelvin Li0bff7af2015-11-23 05:32:03 +00007936template <typename Derived>
7937OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
7938 llvm::SmallVector<Expr *, 16> Vars;
7939 Vars.reserve(C->varlist_size());
7940 for (auto *VE : C->varlists()) {
7941 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7942 if (EVar.isInvalid())
7943 return nullptr;
7944 Vars.push_back(EVar.get());
7945 }
7946 return getDerived().RebuildOMPMapClause(
Samuel Antao23abd722016-01-19 20:40:49 +00007947 C->getMapTypeModifier(), C->getMapType(), C->isImplicitMapType(),
7948 C->getMapLoc(), C->getColonLoc(), Vars, C->getLocStart(),
7949 C->getLParenLoc(), C->getLocEnd());
Kelvin Li0bff7af2015-11-23 05:32:03 +00007950}
7951
Kelvin Li099bb8c2015-11-24 20:50:12 +00007952template <typename Derived>
7953OMPClause *
7954TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
7955 ExprResult E = getDerived().TransformExpr(C->getNumTeams());
7956 if (E.isInvalid())
7957 return nullptr;
7958 return getDerived().RebuildOMPNumTeamsClause(
7959 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7960}
7961
Kelvin Lia15fb1a2015-11-27 18:47:36 +00007962template <typename Derived>
7963OMPClause *
7964TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
7965 ExprResult E = getDerived().TransformExpr(C->getThreadLimit());
7966 if (E.isInvalid())
7967 return nullptr;
7968 return getDerived().RebuildOMPThreadLimitClause(
7969 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7970}
7971
Alexey Bataeva0569352015-12-01 10:17:31 +00007972template <typename Derived>
7973OMPClause *
7974TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
7975 ExprResult E = getDerived().TransformExpr(C->getPriority());
7976 if (E.isInvalid())
7977 return nullptr;
7978 return getDerived().RebuildOMPPriorityClause(
7979 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7980}
7981
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00007982template <typename Derived>
7983OMPClause *
7984TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
7985 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
7986 if (E.isInvalid())
7987 return nullptr;
7988 return getDerived().RebuildOMPGrainsizeClause(
7989 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7990}
7991
Alexey Bataev382967a2015-12-08 12:06:20 +00007992template <typename Derived>
7993OMPClause *
7994TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
7995 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
7996 if (E.isInvalid())
7997 return nullptr;
7998 return getDerived().RebuildOMPNumTasksClause(
7999 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8000}
8001
Alexey Bataev28c75412015-12-15 08:19:24 +00008002template <typename Derived>
8003OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) {
8004 ExprResult E = getDerived().TransformExpr(C->getHint());
8005 if (E.isInvalid())
8006 return nullptr;
8007 return getDerived().RebuildOMPHintClause(E.get(), C->getLocStart(),
8008 C->getLParenLoc(), C->getLocEnd());
8009}
8010
Carlo Bertollib4adf552016-01-15 18:50:31 +00008011template <typename Derived>
8012OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause(
8013 OMPDistScheduleClause *C) {
8014 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
8015 if (E.isInvalid())
8016 return nullptr;
8017 return getDerived().RebuildOMPDistScheduleClause(
8018 C->getDistScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
8019 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
8020}
8021
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +00008022template <typename Derived>
8023OMPClause *
8024TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) {
8025 return C;
8026}
8027
Douglas Gregorebe10102009-08-20 07:17:43 +00008028//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00008029// Expression transformation
8030//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00008031template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008032ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008033TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00008034 if (!E->isTypeDependent())
8035 return E;
8036
8037 return getDerived().RebuildPredefinedExpr(E->getLocation(),
8038 E->getIdentType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008039}
Mike Stump11289f42009-09-09 15:08:12 +00008040
8041template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008042ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008043TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00008044 NestedNameSpecifierLoc QualifierLoc;
8045 if (E->getQualifierLoc()) {
8046 QualifierLoc
8047 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8048 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008049 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008050 }
John McCallce546572009-12-08 09:08:17 +00008051
8052 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008053 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8054 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008055 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00008056 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008057
John McCall815039a2010-08-17 21:27:17 +00008058 DeclarationNameInfo NameInfo = E->getNameInfo();
8059 if (NameInfo.getName()) {
8060 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8061 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008062 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00008063 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008064
8065 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00008066 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008067 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008068 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00008069 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00008070
8071 // Mark it referenced in the new context regardless.
8072 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00008073 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00008074
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008075 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008076 }
John McCallce546572009-12-08 09:08:17 +00008077
Craig Topperc3ec1492014-05-26 06:22:03 +00008078 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00008079 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00008080 TemplateArgs = &TransArgs;
8081 TransArgs.setLAngleLoc(E->getLAngleLoc());
8082 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008083 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8084 E->getNumTemplateArgs(),
8085 TransArgs))
8086 return ExprError();
John McCallce546572009-12-08 09:08:17 +00008087 }
8088
Chad Rosier1dcde962012-08-08 18:46:20 +00008089 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00008090 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00008091}
Mike Stump11289f42009-09-09 15:08:12 +00008092
Douglas Gregora16548e2009-08-11 05:31:07 +00008093template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008094ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008095TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008096 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008097}
Mike Stump11289f42009-09-09 15:08:12 +00008098
Douglas Gregora16548e2009-08-11 05:31:07 +00008099template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008100ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008101TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008102 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008103}
Mike Stump11289f42009-09-09 15:08:12 +00008104
Douglas Gregora16548e2009-08-11 05:31:07 +00008105template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008106ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008107TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008108 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008109}
Mike Stump11289f42009-09-09 15:08:12 +00008110
Douglas Gregora16548e2009-08-11 05:31:07 +00008111template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008112ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008113TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008114 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008115}
Mike Stump11289f42009-09-09 15:08:12 +00008116
Douglas Gregora16548e2009-08-11 05:31:07 +00008117template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008118ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008119TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008120 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008121}
8122
8123template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008124ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00008125TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00008126 if (FunctionDecl *FD = E->getDirectCallee())
8127 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00008128 return SemaRef.MaybeBindToTemporary(E);
8129}
8130
8131template<typename Derived>
8132ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00008133TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
8134 ExprResult ControllingExpr =
8135 getDerived().TransformExpr(E->getControllingExpr());
8136 if (ControllingExpr.isInvalid())
8137 return ExprError();
8138
Chris Lattner01cf8db2011-07-20 06:58:45 +00008139 SmallVector<Expr *, 4> AssocExprs;
8140 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00008141 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
8142 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
8143 if (TS) {
8144 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
8145 if (!AssocType)
8146 return ExprError();
8147 AssocTypes.push_back(AssocType);
8148 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00008149 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00008150 }
8151
8152 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
8153 if (AssocExpr.isInvalid())
8154 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008155 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00008156 }
8157
8158 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
8159 E->getDefaultLoc(),
8160 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008161 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00008162 AssocTypes,
8163 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00008164}
8165
8166template<typename Derived>
8167ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008168TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008169 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008170 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008171 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008172
Douglas Gregora16548e2009-08-11 05:31:07 +00008173 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008174 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008175
John McCallb268a282010-08-23 23:25:46 +00008176 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008177 E->getRParen());
8178}
8179
Richard Smithdb2630f2012-10-21 03:28:35 +00008180/// \brief The operand of a unary address-of operator has special rules: it's
8181/// allowed to refer to a non-static member of a class even if there's no 'this'
8182/// object available.
8183template<typename Derived>
8184ExprResult
8185TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
8186 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00008187 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00008188 else
8189 return getDerived().TransformExpr(E);
8190}
8191
Mike Stump11289f42009-09-09 15:08:12 +00008192template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008193ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008194TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00008195 ExprResult SubExpr;
8196 if (E->getOpcode() == UO_AddrOf)
8197 SubExpr = TransformAddressOfOperand(E->getSubExpr());
8198 else
8199 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008200 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008201 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008202
Douglas Gregora16548e2009-08-11 05:31:07 +00008203 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008204 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008205
Douglas Gregora16548e2009-08-11 05:31:07 +00008206 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
8207 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008208 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008209}
Mike Stump11289f42009-09-09 15:08:12 +00008210
Douglas Gregora16548e2009-08-11 05:31:07 +00008211template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008212ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00008213TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
8214 // Transform the type.
8215 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
8216 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00008217 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008218
Douglas Gregor882211c2010-04-28 22:16:22 +00008219 // Transform all of the components into components similar to what the
8220 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00008221 // FIXME: It would be slightly more efficient in the non-dependent case to
8222 // just map FieldDecls, rather than requiring the rebuilder to look for
8223 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00008224 // template code that we don't care.
8225 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00008226 typedef Sema::OffsetOfComponent Component;
Chris Lattner01cf8db2011-07-20 06:58:45 +00008227 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00008228 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
James Y Knight7281c352015-12-29 22:31:18 +00008229 const OffsetOfNode &ON = E->getComponent(I);
Douglas Gregor882211c2010-04-28 22:16:22 +00008230 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00008231 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00008232 Comp.LocStart = ON.getSourceRange().getBegin();
8233 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00008234 switch (ON.getKind()) {
James Y Knight7281c352015-12-29 22:31:18 +00008235 case OffsetOfNode::Array: {
Douglas Gregor882211c2010-04-28 22:16:22 +00008236 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00008237 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00008238 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008239 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008240
Douglas Gregor882211c2010-04-28 22:16:22 +00008241 ExprChanged = ExprChanged || Index.get() != FromIndex;
8242 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00008243 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00008244 break;
8245 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008246
James Y Knight7281c352015-12-29 22:31:18 +00008247 case OffsetOfNode::Field:
8248 case OffsetOfNode::Identifier:
Douglas Gregor882211c2010-04-28 22:16:22 +00008249 Comp.isBrackets = false;
8250 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00008251 if (!Comp.U.IdentInfo)
8252 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008253
Douglas Gregor882211c2010-04-28 22:16:22 +00008254 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00008255
James Y Knight7281c352015-12-29 22:31:18 +00008256 case OffsetOfNode::Base:
Douglas Gregord1702062010-04-29 00:18:15 +00008257 // Will be recomputed during the rebuild.
8258 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00008259 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008260
Douglas Gregor882211c2010-04-28 22:16:22 +00008261 Components.push_back(Comp);
8262 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008263
Douglas Gregor882211c2010-04-28 22:16:22 +00008264 // If nothing changed, retain the existing expression.
8265 if (!getDerived().AlwaysRebuild() &&
8266 Type == E->getTypeSourceInfo() &&
8267 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008268 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00008269
Douglas Gregor882211c2010-04-28 22:16:22 +00008270 // Build a new offsetof expression.
8271 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
Craig Topperb5518242015-10-22 04:59:59 +00008272 Components, E->getRParenLoc());
Douglas Gregor882211c2010-04-28 22:16:22 +00008273}
8274
8275template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008276ExprResult
John McCall8d69a212010-11-15 23:31:06 +00008277TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
Hubert Tong2cded442015-09-01 22:50:31 +00008278 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
John McCall8d69a212010-11-15 23:31:06 +00008279 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008280 return E;
John McCall8d69a212010-11-15 23:31:06 +00008281}
8282
8283template<typename Derived>
8284ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00008285TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
8286 return E;
8287}
8288
8289template<typename Derived>
8290ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00008291TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00008292 // Rebuild the syntactic form. The original syntactic form has
8293 // opaque-value expressions in it, so strip those away and rebuild
8294 // the result. This is a really awful way of doing this, but the
8295 // better solution (rebuilding the semantic expressions and
8296 // rebinding OVEs as necessary) doesn't work; we'd need
8297 // TreeTransform to not strip away implicit conversions.
8298 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
8299 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00008300 if (result.isInvalid()) return ExprError();
8301
8302 // If that gives us a pseudo-object result back, the pseudo-object
8303 // expression must have been an lvalue-to-rvalue conversion which we
8304 // should reapply.
8305 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008306 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00008307
8308 return result;
8309}
8310
8311template<typename Derived>
8312ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00008313TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
8314 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008315 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00008316 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00008317
John McCallbcd03502009-12-07 02:54:59 +00008318 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00008319 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008320 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008321
John McCall4c98fd82009-11-04 07:28:41 +00008322 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008323 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008324
Peter Collingbournee190dee2011-03-11 19:24:49 +00008325 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
8326 E->getKind(),
8327 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008328 }
Mike Stump11289f42009-09-09 15:08:12 +00008329
Eli Friedmane4f22df2012-02-29 04:03:55 +00008330 // C++0x [expr.sizeof]p1:
8331 // The operand is either an expression, which is an unevaluated operand
8332 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00008333 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8334 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008335
Reid Kleckner32506ed2014-06-12 23:03:48 +00008336 // Try to recover if we have something like sizeof(T::X) where X is a type.
8337 // Notably, there must be *exactly* one set of parens if X is a type.
8338 TypeSourceInfo *RecoveryTSI = nullptr;
8339 ExprResult SubExpr;
8340 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
8341 if (auto *DRE =
8342 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
8343 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
8344 PE, DRE, false, &RecoveryTSI);
8345 else
8346 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
8347
8348 if (RecoveryTSI) {
8349 return getDerived().RebuildUnaryExprOrTypeTrait(
8350 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
8351 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00008352 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008353
Eli Friedmane4f22df2012-02-29 04:03:55 +00008354 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008355 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008356
Peter Collingbournee190dee2011-03-11 19:24:49 +00008357 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
8358 E->getOperatorLoc(),
8359 E->getKind(),
8360 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008361}
Mike Stump11289f42009-09-09 15:08:12 +00008362
Douglas Gregora16548e2009-08-11 05:31:07 +00008363template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008364ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008365TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008366 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008367 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008368 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008369
John McCalldadc5752010-08-24 06:29:42 +00008370 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008371 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008372 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008373
8374
Douglas Gregora16548e2009-08-11 05:31:07 +00008375 if (!getDerived().AlwaysRebuild() &&
8376 LHS.get() == E->getLHS() &&
8377 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008378 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008379
John McCallb268a282010-08-23 23:25:46 +00008380 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008381 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008382 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008383 E->getRBracketLoc());
8384}
Mike Stump11289f42009-09-09 15:08:12 +00008385
Alexey Bataev1a3320e2015-08-25 14:24:04 +00008386template <typename Derived>
8387ExprResult
8388TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
8389 ExprResult Base = getDerived().TransformExpr(E->getBase());
8390 if (Base.isInvalid())
8391 return ExprError();
8392
8393 ExprResult LowerBound;
8394 if (E->getLowerBound()) {
8395 LowerBound = getDerived().TransformExpr(E->getLowerBound());
8396 if (LowerBound.isInvalid())
8397 return ExprError();
8398 }
8399
8400 ExprResult Length;
8401 if (E->getLength()) {
8402 Length = getDerived().TransformExpr(E->getLength());
8403 if (Length.isInvalid())
8404 return ExprError();
8405 }
8406
8407 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
8408 LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
8409 return E;
8410
8411 return getDerived().RebuildOMPArraySectionExpr(
8412 Base.get(), E->getBase()->getLocEnd(), LowerBound.get(), E->getColonLoc(),
8413 Length.get(), E->getRBracketLoc());
8414}
8415
Mike Stump11289f42009-09-09 15:08:12 +00008416template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008417ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008418TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008419 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00008420 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00008421 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008422 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008423
8424 // Transform arguments.
8425 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008426 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008427 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008428 &ArgChanged))
8429 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008430
Douglas Gregora16548e2009-08-11 05:31:07 +00008431 if (!getDerived().AlwaysRebuild() &&
8432 Callee.get() == E->getCallee() &&
8433 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00008434 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00008435
Douglas Gregora16548e2009-08-11 05:31:07 +00008436 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00008437 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00008438 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00008439 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008440 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008441 E->getRParenLoc());
8442}
Mike Stump11289f42009-09-09 15:08:12 +00008443
8444template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008445ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008446TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008447 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008448 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008449 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008450
Douglas Gregorea972d32011-02-28 21:54:11 +00008451 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00008452 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00008453 QualifierLoc
8454 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00008455
Douglas Gregorea972d32011-02-28 21:54:11 +00008456 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008457 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00008458 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00008459 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008460
Eli Friedman2cfcef62009-12-04 06:40:45 +00008461 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008462 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
8463 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008464 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00008465 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008466
John McCall16df1e52010-03-30 21:47:33 +00008467 NamedDecl *FoundDecl = E->getFoundDecl();
8468 if (FoundDecl == E->getMemberDecl()) {
8469 FoundDecl = Member;
8470 } else {
8471 FoundDecl = cast_or_null<NamedDecl>(
8472 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
8473 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00008474 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00008475 }
8476
Douglas Gregora16548e2009-08-11 05:31:07 +00008477 if (!getDerived().AlwaysRebuild() &&
8478 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00008479 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008480 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00008481 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00008482 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008483
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008484 // Mark it referenced in the new context regardless.
8485 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00008486 SemaRef.MarkMemberReferenced(E);
8487
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008488 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008489 }
Douglas Gregora16548e2009-08-11 05:31:07 +00008490
John McCall6b51f282009-11-23 01:53:49 +00008491 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00008492 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00008493 TransArgs.setLAngleLoc(E->getLAngleLoc());
8494 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008495 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8496 E->getNumTemplateArgs(),
8497 TransArgs))
8498 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008499 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008500
Douglas Gregora16548e2009-08-11 05:31:07 +00008501 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00008502 SourceLocation FakeOperatorLoc =
8503 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00008504
John McCall38836f02010-01-15 08:34:02 +00008505 // FIXME: to do this check properly, we will need to preserve the
8506 // first-qualifier-in-scope here, just in case we had a dependent
8507 // base (and therefore couldn't do the check) and a
8508 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00008509 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00008510
John McCallb268a282010-08-23 23:25:46 +00008511 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008512 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00008513 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008514 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008515 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008516 Member,
John McCall16df1e52010-03-30 21:47:33 +00008517 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00008518 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00008519 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00008520 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00008521}
Mike Stump11289f42009-09-09 15:08:12 +00008522
Douglas Gregora16548e2009-08-11 05:31:07 +00008523template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008524ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008525TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008526 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008527 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008528 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008529
John McCalldadc5752010-08-24 06:29:42 +00008530 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008531 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008532 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008533
Douglas Gregora16548e2009-08-11 05:31:07 +00008534 if (!getDerived().AlwaysRebuild() &&
8535 LHS.get() == E->getLHS() &&
8536 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008537 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008538
Lang Hames5de91cc2012-10-02 04:45:10 +00008539 Sema::FPContractStateRAII FPContractState(getSema());
8540 getSema().FPFeatures.fp_contract = E->isFPContractable();
8541
Douglas Gregora16548e2009-08-11 05:31:07 +00008542 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008543 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008544}
8545
Mike Stump11289f42009-09-09 15:08:12 +00008546template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008547ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008548TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00008549 CompoundAssignOperator *E) {
8550 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008551}
Mike Stump11289f42009-09-09 15:08:12 +00008552
Douglas Gregora16548e2009-08-11 05:31:07 +00008553template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00008554ExprResult TreeTransform<Derived>::
8555TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
8556 // Just rebuild the common and RHS expressions and see whether we
8557 // get any changes.
8558
8559 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
8560 if (commonExpr.isInvalid())
8561 return ExprError();
8562
8563 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
8564 if (rhs.isInvalid())
8565 return ExprError();
8566
8567 if (!getDerived().AlwaysRebuild() &&
8568 commonExpr.get() == e->getCommon() &&
8569 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008570 return e;
John McCallc07a0c72011-02-17 10:25:35 +00008571
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008572 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00008573 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008574 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00008575 e->getColonLoc(),
8576 rhs.get());
8577}
8578
8579template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008580ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008581TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008582 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008583 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008584 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008585
John McCalldadc5752010-08-24 06:29:42 +00008586 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008587 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008588 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008589
John McCalldadc5752010-08-24 06:29:42 +00008590 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008591 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008592 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008593
Douglas Gregora16548e2009-08-11 05:31:07 +00008594 if (!getDerived().AlwaysRebuild() &&
8595 Cond.get() == E->getCond() &&
8596 LHS.get() == E->getLHS() &&
8597 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008598 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008599
John McCallb268a282010-08-23 23:25:46 +00008600 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008601 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00008602 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008603 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008604 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008605}
Mike Stump11289f42009-09-09 15:08:12 +00008606
8607template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008608ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008609TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00008610 // Implicit casts are eliminated during transformation, since they
8611 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00008612 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008613}
Mike Stump11289f42009-09-09 15:08:12 +00008614
Douglas Gregora16548e2009-08-11 05:31:07 +00008615template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008616ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008617TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008618 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8619 if (!Type)
8620 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008621
John McCalldadc5752010-08-24 06:29:42 +00008622 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008623 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008624 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008625 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008626
Douglas Gregora16548e2009-08-11 05:31:07 +00008627 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008628 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008629 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008630 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008631
John McCall97513962010-01-15 18:39:57 +00008632 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008633 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00008634 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008635 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008636}
Mike Stump11289f42009-09-09 15:08:12 +00008637
Douglas Gregora16548e2009-08-11 05:31:07 +00008638template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008639ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008640TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00008641 TypeSourceInfo *OldT = E->getTypeSourceInfo();
8642 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
8643 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008644 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008645
John McCalldadc5752010-08-24 06:29:42 +00008646 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00008647 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008648 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008649
Douglas Gregora16548e2009-08-11 05:31:07 +00008650 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00008651 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008652 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008653 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008654
John McCall5d7aa7f2010-01-19 22:33:45 +00008655 // Note: the expression type doesn't necessarily match the
8656 // type-as-written, but that's okay, because it should always be
8657 // derivable from the initializer.
8658
John McCalle15bbff2010-01-18 19:35:47 +00008659 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00008660 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00008661 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008662}
Mike Stump11289f42009-09-09 15:08:12 +00008663
Douglas Gregora16548e2009-08-11 05:31:07 +00008664template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008665ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008666TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008667 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008668 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008669 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008670
Douglas Gregora16548e2009-08-11 05:31:07 +00008671 if (!getDerived().AlwaysRebuild() &&
8672 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008673 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008674
Douglas Gregora16548e2009-08-11 05:31:07 +00008675 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00008676 SourceLocation FakeOperatorLoc =
8677 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00008678 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008679 E->getAccessorLoc(),
8680 E->getAccessor());
8681}
Mike Stump11289f42009-09-09 15:08:12 +00008682
Douglas Gregora16548e2009-08-11 05:31:07 +00008683template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008684ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008685TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Richard Smith520449d2015-02-05 06:15:50 +00008686 if (InitListExpr *Syntactic = E->getSyntacticForm())
8687 E = Syntactic;
8688
Douglas Gregora16548e2009-08-11 05:31:07 +00008689 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00008690
Benjamin Kramerf0623432012-08-23 22:51:59 +00008691 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00008692 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00008693 Inits, &InitChanged))
8694 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008695
Richard Smith520449d2015-02-05 06:15:50 +00008696 if (!getDerived().AlwaysRebuild() && !InitChanged) {
8697 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
8698 // in some cases. We can't reuse it in general, because the syntactic and
8699 // semantic forms are linked, and we can't know that semantic form will
8700 // match even if the syntactic form does.
8701 }
Mike Stump11289f42009-09-09 15:08:12 +00008702
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008703 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00008704 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008705}
Mike Stump11289f42009-09-09 15:08:12 +00008706
Douglas Gregora16548e2009-08-11 05:31:07 +00008707template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008708ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008709TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008710 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00008711
Douglas Gregorebe10102009-08-20 07:17:43 +00008712 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00008713 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008714 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008715 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008716
Douglas Gregorebe10102009-08-20 07:17:43 +00008717 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008718 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00008719 bool ExprChanged = false;
8720 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
8721 DEnd = E->designators_end();
8722 D != DEnd; ++D) {
8723 if (D->isFieldDesignator()) {
8724 Desig.AddDesignator(Designator::getField(D->getFieldName(),
8725 D->getDotLoc(),
8726 D->getFieldLoc()));
8727 continue;
8728 }
Mike Stump11289f42009-09-09 15:08:12 +00008729
Douglas Gregora16548e2009-08-11 05:31:07 +00008730 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00008731 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008732 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008733 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008734
8735 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008736 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008737
Douglas Gregora16548e2009-08-11 05:31:07 +00008738 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008739 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008740 continue;
8741 }
Mike Stump11289f42009-09-09 15:08:12 +00008742
Douglas Gregora16548e2009-08-11 05:31:07 +00008743 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00008744 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00008745 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
8746 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008747 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008748
John McCalldadc5752010-08-24 06:29:42 +00008749 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008750 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008751 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008752
8753 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008754 End.get(),
8755 D->getLBracketLoc(),
8756 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008757
Douglas Gregora16548e2009-08-11 05:31:07 +00008758 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
8759 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00008760
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008761 ArrayExprs.push_back(Start.get());
8762 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008763 }
Mike Stump11289f42009-09-09 15:08:12 +00008764
Douglas Gregora16548e2009-08-11 05:31:07 +00008765 if (!getDerived().AlwaysRebuild() &&
8766 Init.get() == E->getInit() &&
8767 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008768 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008769
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008770 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008771 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008772 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008773}
Mike Stump11289f42009-09-09 15:08:12 +00008774
Yunzhong Gaocb779302015-06-10 00:27:52 +00008775// Seems that if TransformInitListExpr() only works on the syntactic form of an
8776// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
8777template<typename Derived>
8778ExprResult
8779TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
8780 DesignatedInitUpdateExpr *E) {
8781 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
8782 "initializer");
8783 return ExprError();
8784}
8785
8786template<typename Derived>
8787ExprResult
8788TreeTransform<Derived>::TransformNoInitExpr(
8789 NoInitExpr *E) {
8790 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
8791 return ExprError();
8792}
8793
Douglas Gregora16548e2009-08-11 05:31:07 +00008794template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008795ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008796TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008797 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00008798 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00008799
Douglas Gregor3da3c062009-10-28 00:29:27 +00008800 // FIXME: Will we ever have proper type location here? Will we actually
8801 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00008802 QualType T = getDerived().TransformType(E->getType());
8803 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008804 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008805
Douglas Gregora16548e2009-08-11 05:31:07 +00008806 if (!getDerived().AlwaysRebuild() &&
8807 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008808 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008809
Douglas Gregora16548e2009-08-11 05:31:07 +00008810 return getDerived().RebuildImplicitValueInitExpr(T);
8811}
Mike Stump11289f42009-09-09 15:08:12 +00008812
Douglas Gregora16548e2009-08-11 05:31:07 +00008813template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008814ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008815TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00008816 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
8817 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008818 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008819
John McCalldadc5752010-08-24 06:29:42 +00008820 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008821 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008822 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008823
Douglas Gregora16548e2009-08-11 05:31:07 +00008824 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00008825 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008826 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008827 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008828
John McCallb268a282010-08-23 23:25:46 +00008829 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00008830 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008831}
8832
8833template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008834ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008835TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008836 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008837 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00008838 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
8839 &ArgumentChanged))
8840 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008841
Douglas Gregora16548e2009-08-11 05:31:07 +00008842 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008843 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00008844 E->getRParenLoc());
8845}
Mike Stump11289f42009-09-09 15:08:12 +00008846
Douglas Gregora16548e2009-08-11 05:31:07 +00008847/// \brief Transform an address-of-label expression.
8848///
8849/// By default, the transformation of an address-of-label expression always
8850/// rebuilds the expression, so that the label identifier can be resolved to
8851/// the corresponding label statement by semantic analysis.
8852template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008853ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008854TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00008855 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
8856 E->getLabel());
8857 if (!LD)
8858 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008859
Douglas Gregora16548e2009-08-11 05:31:07 +00008860 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00008861 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00008862}
Mike Stump11289f42009-09-09 15:08:12 +00008863
8864template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00008865ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008866TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00008867 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00008868 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00008869 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00008870 if (SubStmt.isInvalid()) {
8871 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00008872 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00008873 }
Mike Stump11289f42009-09-09 15:08:12 +00008874
Douglas Gregora16548e2009-08-11 05:31:07 +00008875 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00008876 SubStmt.get() == E->getSubStmt()) {
8877 // Calling this an 'error' is unintuitive, but it does the right thing.
8878 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008879 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00008880 }
Mike Stump11289f42009-09-09 15:08:12 +00008881
8882 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008883 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008884 E->getRParenLoc());
8885}
Mike Stump11289f42009-09-09 15:08:12 +00008886
Douglas Gregora16548e2009-08-11 05:31:07 +00008887template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008888ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008889TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008890 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008891 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008892 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008893
John McCalldadc5752010-08-24 06:29:42 +00008894 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008895 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008896 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008897
John McCalldadc5752010-08-24 06:29:42 +00008898 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008899 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008900 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008901
Douglas Gregora16548e2009-08-11 05:31:07 +00008902 if (!getDerived().AlwaysRebuild() &&
8903 Cond.get() == E->getCond() &&
8904 LHS.get() == E->getLHS() &&
8905 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008906 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008907
Douglas Gregora16548e2009-08-11 05:31:07 +00008908 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00008909 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008910 E->getRParenLoc());
8911}
Mike Stump11289f42009-09-09 15:08:12 +00008912
Douglas Gregora16548e2009-08-11 05:31:07 +00008913template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008914ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008915TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008916 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008917}
8918
8919template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008920ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008921TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008922 switch (E->getOperator()) {
8923 case OO_New:
8924 case OO_Delete:
8925 case OO_Array_New:
8926 case OO_Array_Delete:
8927 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00008928
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008929 case OO_Call: {
8930 // This is a call to an object's operator().
8931 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
8932
8933 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00008934 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008935 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008936 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008937
8938 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00008939 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
8940 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008941
8942 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008943 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008944 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00008945 Args))
8946 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008947
John McCallb268a282010-08-23 23:25:46 +00008948 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008949 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008950 E->getLocEnd());
8951 }
8952
8953#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
8954 case OO_##Name:
8955#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
8956#include "clang/Basic/OperatorKinds.def"
8957 case OO_Subscript:
8958 // Handled below.
8959 break;
8960
8961 case OO_Conditional:
8962 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008963
8964 case OO_None:
8965 case NUM_OVERLOADED_OPERATORS:
8966 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008967 }
8968
John McCalldadc5752010-08-24 06:29:42 +00008969 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00008970 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008971 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008972
Richard Smithdb2630f2012-10-21 03:28:35 +00008973 ExprResult First;
8974 if (E->getOperator() == OO_Amp)
8975 First = getDerived().TransformAddressOfOperand(E->getArg(0));
8976 else
8977 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00008978 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008979 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008980
John McCalldadc5752010-08-24 06:29:42 +00008981 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00008982 if (E->getNumArgs() == 2) {
8983 Second = getDerived().TransformExpr(E->getArg(1));
8984 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008985 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008986 }
Mike Stump11289f42009-09-09 15:08:12 +00008987
Douglas Gregora16548e2009-08-11 05:31:07 +00008988 if (!getDerived().AlwaysRebuild() &&
8989 Callee.get() == E->getCallee() &&
8990 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00008991 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008992 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00008993
Lang Hames5de91cc2012-10-02 04:45:10 +00008994 Sema::FPContractStateRAII FPContractState(getSema());
8995 getSema().FPFeatures.fp_contract = E->isFPContractable();
8996
Douglas Gregora16548e2009-08-11 05:31:07 +00008997 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
8998 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00008999 Callee.get(),
9000 First.get(),
9001 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009002}
Mike Stump11289f42009-09-09 15:08:12 +00009003
Douglas Gregora16548e2009-08-11 05:31:07 +00009004template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009005ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009006TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
9007 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009008}
Mike Stump11289f42009-09-09 15:08:12 +00009009
Douglas Gregora16548e2009-08-11 05:31:07 +00009010template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009011ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00009012TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
9013 // Transform the callee.
9014 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
9015 if (Callee.isInvalid())
9016 return ExprError();
9017
9018 // Transform exec config.
9019 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
9020 if (EC.isInvalid())
9021 return ExprError();
9022
9023 // Transform arguments.
9024 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009025 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009026 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00009027 &ArgChanged))
9028 return ExprError();
9029
9030 if (!getDerived().AlwaysRebuild() &&
9031 Callee.get() == E->getCallee() &&
9032 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009033 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00009034
9035 // FIXME: Wrong source location information for the '('.
9036 SourceLocation FakeLParenLoc
9037 = ((Expr *)Callee.get())->getSourceRange().getBegin();
9038 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009039 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00009040 E->getRParenLoc(), EC.get());
9041}
9042
9043template<typename Derived>
9044ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009045TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009046 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9047 if (!Type)
9048 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009049
John McCalldadc5752010-08-24 06:29:42 +00009050 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009051 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009052 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009053 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009054
Douglas Gregora16548e2009-08-11 05:31:07 +00009055 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009056 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009057 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009058 return E;
Nico Weberc153d242014-07-28 00:02:09 +00009059 return getDerived().RebuildCXXNamedCastExpr(
9060 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
9061 Type, E->getAngleBrackets().getEnd(),
9062 // FIXME. this should be '(' location
9063 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009064}
Mike Stump11289f42009-09-09 15:08:12 +00009065
Douglas Gregora16548e2009-08-11 05:31:07 +00009066template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009067ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009068TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
9069 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009070}
Mike Stump11289f42009-09-09 15:08:12 +00009071
9072template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009073ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009074TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
9075 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00009076}
9077
Douglas Gregora16548e2009-08-11 05:31:07 +00009078template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009079ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009080TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009081 CXXReinterpretCastExpr *E) {
9082 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009083}
Mike Stump11289f42009-09-09 15:08:12 +00009084
Douglas Gregora16548e2009-08-11 05:31:07 +00009085template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009086ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009087TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
9088 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009089}
Mike Stump11289f42009-09-09 15:08:12 +00009090
Douglas Gregora16548e2009-08-11 05:31:07 +00009091template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009092ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009093TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009094 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009095 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9096 if (!Type)
9097 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009098
John McCalldadc5752010-08-24 06:29:42 +00009099 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009100 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009101 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009102 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009103
Douglas Gregora16548e2009-08-11 05:31:07 +00009104 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009105 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009106 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009107 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009108
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009109 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00009110 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009111 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009112 E->getRParenLoc());
9113}
Mike Stump11289f42009-09-09 15:08:12 +00009114
Douglas Gregora16548e2009-08-11 05:31:07 +00009115template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009116ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009117TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009118 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00009119 TypeSourceInfo *TInfo
9120 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9121 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009122 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009123
Douglas Gregora16548e2009-08-11 05:31:07 +00009124 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00009125 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009126 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009127
Douglas Gregor9da64192010-04-26 22:37:10 +00009128 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9129 E->getLocStart(),
9130 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009131 E->getLocEnd());
9132 }
Mike Stump11289f42009-09-09 15:08:12 +00009133
Eli Friedman456f0182012-01-20 01:26:23 +00009134 // We don't know whether the subexpression is potentially evaluated until
9135 // after we perform semantic analysis. We speculatively assume it is
9136 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00009137 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00009138 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
9139 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00009140
John McCalldadc5752010-08-24 06:29:42 +00009141 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00009142 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009143 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009144
Douglas Gregora16548e2009-08-11 05:31:07 +00009145 if (!getDerived().AlwaysRebuild() &&
9146 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009147 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009148
Douglas Gregor9da64192010-04-26 22:37:10 +00009149 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9150 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00009151 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009152 E->getLocEnd());
9153}
9154
9155template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009156ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00009157TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
9158 if (E->isTypeOperand()) {
9159 TypeSourceInfo *TInfo
9160 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9161 if (!TInfo)
9162 return ExprError();
9163
9164 if (!getDerived().AlwaysRebuild() &&
9165 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009166 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00009167
Douglas Gregor69735112011-03-06 17:40:41 +00009168 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00009169 E->getLocStart(),
9170 TInfo,
9171 E->getLocEnd());
9172 }
9173
Francois Pichet9f4f2072010-09-08 12:20:18 +00009174 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9175
9176 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
9177 if (SubExpr.isInvalid())
9178 return ExprError();
9179
9180 if (!getDerived().AlwaysRebuild() &&
9181 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009182 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00009183
9184 return getDerived().RebuildCXXUuidofExpr(E->getType(),
9185 E->getLocStart(),
9186 SubExpr.get(),
9187 E->getLocEnd());
9188}
9189
9190template<typename Derived>
9191ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009192TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009193 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009194}
Mike Stump11289f42009-09-09 15:08:12 +00009195
Douglas Gregora16548e2009-08-11 05:31:07 +00009196template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009197ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009198TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009199 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009200 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009201}
Mike Stump11289f42009-09-09 15:08:12 +00009202
Douglas Gregora16548e2009-08-11 05:31:07 +00009203template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009204ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009205TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00009206 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00009207
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009208 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
9209 // Make sure that we capture 'this'.
9210 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009211 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009212 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009213
Douglas Gregorb15af892010-01-07 23:12:05 +00009214 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00009215}
Mike Stump11289f42009-09-09 15:08:12 +00009216
Douglas Gregora16548e2009-08-11 05:31:07 +00009217template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009218ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009219TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009220 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009221 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009222 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009223
Douglas Gregora16548e2009-08-11 05:31:07 +00009224 if (!getDerived().AlwaysRebuild() &&
9225 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009226 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009227
Douglas Gregor53e191ed2011-07-06 22:04:06 +00009228 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
9229 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00009230}
Mike Stump11289f42009-09-09 15:08:12 +00009231
Douglas Gregora16548e2009-08-11 05:31:07 +00009232template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009233ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009234TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00009235 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009236 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
9237 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009238 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00009239 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009240
Chandler Carruth794da4c2010-02-08 06:42:49 +00009241 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009242 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009243 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009244
Douglas Gregor033f6752009-12-23 23:03:06 +00009245 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00009246}
Mike Stump11289f42009-09-09 15:08:12 +00009247
Douglas Gregora16548e2009-08-11 05:31:07 +00009248template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009249ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00009250TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
9251 FieldDecl *Field
9252 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
9253 E->getField()));
9254 if (!Field)
9255 return ExprError();
9256
9257 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009258 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00009259
9260 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
9261}
9262
9263template<typename Derived>
9264ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00009265TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
9266 CXXScalarValueInitExpr *E) {
9267 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9268 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009269 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009270
Douglas Gregora16548e2009-08-11 05:31:07 +00009271 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009272 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009273 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009274
Chad Rosier1dcde962012-08-08 18:46:20 +00009275 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00009276 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00009277 E->getRParenLoc());
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>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009283 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00009284 TypeSourceInfo *AllocTypeInfo
9285 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
9286 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009287 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009288
Douglas Gregora16548e2009-08-11 05:31:07 +00009289 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00009290 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00009291 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009292 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009293
Douglas Gregora16548e2009-08-11 05:31:07 +00009294 // Transform the placement arguments (if any).
9295 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009296 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00009297 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00009298 E->getNumPlacementArgs(), true,
9299 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00009300 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009301
Sebastian Redl6047f072012-02-16 12:22:20 +00009302 // Transform the initializer (if any).
9303 Expr *OldInit = E->getInitializer();
9304 ExprResult NewInit;
9305 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +00009306 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +00009307 if (NewInit.isInvalid())
9308 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009309
Sebastian Redl6047f072012-02-16 12:22:20 +00009310 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00009311 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009312 if (E->getOperatorNew()) {
9313 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009314 getDerived().TransformDecl(E->getLocStart(),
9315 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009316 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00009317 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009318 }
9319
Craig Topperc3ec1492014-05-26 06:22:03 +00009320 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009321 if (E->getOperatorDelete()) {
9322 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009323 getDerived().TransformDecl(E->getLocStart(),
9324 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009325 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00009326 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009327 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009328
Douglas Gregora16548e2009-08-11 05:31:07 +00009329 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00009330 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009331 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00009332 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00009333 OperatorNew == E->getOperatorNew() &&
9334 OperatorDelete == E->getOperatorDelete() &&
9335 !ArgumentChanged) {
9336 // Mark any declarations we need as referenced.
9337 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00009338 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009339 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00009340 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009341 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00009342
Sebastian Redl6047f072012-02-16 12:22:20 +00009343 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00009344 QualType ElementType
9345 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
9346 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
9347 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
9348 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00009349 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00009350 }
9351 }
9352 }
Sebastian Redl6047f072012-02-16 12:22:20 +00009353
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009354 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009355 }
Mike Stump11289f42009-09-09 15:08:12 +00009356
Douglas Gregor0744ef62010-09-07 21:49:58 +00009357 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009358 if (!ArraySize.get()) {
9359 // If no array size was specified, but the new expression was
9360 // instantiated with an array type (e.g., "new T" where T is
9361 // instantiated with "int[4]"), extract the outer bound from the
9362 // array type as our array size. We do this with constant and
9363 // dependently-sized array types.
9364 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
9365 if (!ArrayT) {
9366 // Do nothing
9367 } else if (const ConstantArrayType *ConsArrayT
9368 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009369 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
9370 SemaRef.Context.getSizeType(),
9371 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009372 AllocType = ConsArrayT->getElementType();
9373 } else if (const DependentSizedArrayType *DepArrayT
9374 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
9375 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009376 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009377 AllocType = DepArrayT->getElementType();
9378 }
9379 }
9380 }
Sebastian Redl6047f072012-02-16 12:22:20 +00009381
Douglas Gregora16548e2009-08-11 05:31:07 +00009382 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
9383 E->isGlobalNew(),
9384 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009385 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009386 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00009387 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009388 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00009389 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00009390 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00009391 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009392 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009393}
Mike Stump11289f42009-09-09 15:08:12 +00009394
Douglas Gregora16548e2009-08-11 05:31:07 +00009395template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009396ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009397TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009398 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00009399 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009400 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009401
Douglas Gregord2d9da02010-02-26 00:38:10 +00009402 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00009403 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009404 if (E->getOperatorDelete()) {
9405 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009406 getDerived().TransformDecl(E->getLocStart(),
9407 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009408 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00009409 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009410 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009411
Douglas Gregora16548e2009-08-11 05:31:07 +00009412 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00009413 Operand.get() == E->getArgument() &&
9414 OperatorDelete == E->getOperatorDelete()) {
9415 // Mark any declarations we need as referenced.
9416 // FIXME: instantiation-specific.
9417 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009418 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00009419
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00009420 if (!E->getArgument()->isTypeDependent()) {
9421 QualType Destroyed = SemaRef.Context.getBaseElementType(
9422 E->getDestroyedType());
9423 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
9424 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00009425 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00009426 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00009427 }
9428 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009429
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009430 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009431 }
Mike Stump11289f42009-09-09 15:08:12 +00009432
Douglas Gregora16548e2009-08-11 05:31:07 +00009433 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
9434 E->isGlobalDelete(),
9435 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00009436 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009437}
Mike Stump11289f42009-09-09 15:08:12 +00009438
Douglas Gregora16548e2009-08-11 05:31:07 +00009439template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009440ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00009441TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009442 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009443 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00009444 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009445 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009446
John McCallba7bf592010-08-24 05:47:05 +00009447 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00009448 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00009449 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009450 E->getOperatorLoc(),
9451 E->isArrow()? tok::arrow : tok::period,
9452 ObjectTypePtr,
9453 MayBePseudoDestructor);
9454 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009455 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009456
John McCallba7bf592010-08-24 05:47:05 +00009457 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00009458 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
9459 if (QualifierLoc) {
9460 QualifierLoc
9461 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
9462 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00009463 return ExprError();
9464 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00009465 CXXScopeSpec SS;
9466 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00009467
Douglas Gregor678f90d2010-02-25 01:56:36 +00009468 PseudoDestructorTypeStorage Destroyed;
9469 if (E->getDestroyedTypeInfo()) {
9470 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00009471 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009472 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00009473 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009474 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00009475 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00009476 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00009477 // We aren't likely to be able to resolve the identifier down to a type
9478 // now anyway, so just retain the identifier.
9479 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
9480 E->getDestroyedTypeLoc());
9481 } else {
9482 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00009483 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009484 *E->getDestroyedTypeIdentifier(),
9485 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009486 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009487 SS, ObjectTypePtr,
9488 false);
9489 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009490 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009491
Douglas Gregor678f90d2010-02-25 01:56:36 +00009492 Destroyed
9493 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
9494 E->getDestroyedTypeLoc());
9495 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009496
Craig Topperc3ec1492014-05-26 06:22:03 +00009497 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009498 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00009499 CXXScopeSpec EmptySS;
9500 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00009501 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009502 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009503 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00009504 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009505
John McCallb268a282010-08-23 23:25:46 +00009506 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00009507 E->getOperatorLoc(),
9508 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00009509 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009510 ScopeTypeInfo,
9511 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009512 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009513 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00009514}
Mike Stump11289f42009-09-09 15:08:12 +00009515
Douglas Gregorad8a3362009-09-04 17:36:40 +00009516template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009517ExprResult
John McCalld14a8642009-11-21 08:51:07 +00009518TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009519 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00009520 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
9521 Sema::LookupOrdinaryName);
9522
9523 // Transform all the decls.
9524 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
9525 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009526 NamedDecl *InstD = static_cast<NamedDecl*>(
9527 getDerived().TransformDecl(Old->getNameLoc(),
9528 *I));
John McCall84d87672009-12-10 09:41:52 +00009529 if (!InstD) {
9530 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9531 // This can happen because of dependent hiding.
9532 if (isa<UsingShadowDecl>(*I))
9533 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00009534 else {
9535 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009536 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009537 }
John McCall84d87672009-12-10 09:41:52 +00009538 }
John McCalle66edc12009-11-24 19:00:30 +00009539
9540 // Expand using declarations.
9541 if (isa<UsingDecl>(InstD)) {
9542 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009543 for (auto *I : UD->shadows())
9544 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00009545 continue;
9546 }
9547
9548 R.addDecl(InstD);
9549 }
9550
9551 // Resolve a kind, but don't do any further analysis. If it's
9552 // ambiguous, the callee needs to deal with it.
9553 R.resolveKind();
9554
9555 // Rebuild the nested-name qualifier, if present.
9556 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00009557 if (Old->getQualifierLoc()) {
9558 NestedNameSpecifierLoc QualifierLoc
9559 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9560 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009561 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009562
Douglas Gregor0da1d432011-02-28 20:01:57 +00009563 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00009564 }
9565
Douglas Gregor9262f472010-04-27 18:19:34 +00009566 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00009567 CXXRecordDecl *NamingClass
9568 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
9569 Old->getNameLoc(),
9570 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00009571 if (!NamingClass) {
9572 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009573 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009574 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009575
Douglas Gregorda7be082010-04-27 16:10:10 +00009576 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00009577 }
9578
Abramo Bagnara7945c982012-01-27 09:46:47 +00009579 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9580
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009581 // If we have neither explicit template arguments, nor the template keyword,
Reid Kleckner744e3e72015-10-20 21:04:13 +00009582 // it's a normal declaration name or member reference.
9583 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
9584 NamedDecl *D = R.getAsSingle<NamedDecl>();
9585 // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
9586 // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
9587 // give a good diagnostic.
9588 if (D && D->isCXXInstanceMember()) {
9589 return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R,
9590 /*TemplateArgs=*/nullptr,
9591 /*Scope=*/nullptr);
9592 }
9593
John McCalle66edc12009-11-24 19:00:30 +00009594 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
Reid Kleckner744e3e72015-10-20 21:04:13 +00009595 }
John McCalle66edc12009-11-24 19:00:30 +00009596
9597 // If we have template arguments, rebuild them, then rebuild the
9598 // templateid expression.
9599 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00009600 if (Old->hasExplicitTemplateArgs() &&
9601 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00009602 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00009603 TransArgs)) {
9604 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00009605 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009606 }
John McCalle66edc12009-11-24 19:00:30 +00009607
Abramo Bagnara7945c982012-01-27 09:46:47 +00009608 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009609 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00009610}
Mike Stump11289f42009-09-09 15:08:12 +00009611
Douglas Gregora16548e2009-08-11 05:31:07 +00009612template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009613ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00009614TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
9615 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009616 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009617 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
9618 TypeSourceInfo *From = E->getArg(I);
9619 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00009620 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00009621 TypeLocBuilder TLB;
9622 TLB.reserve(FromTL.getFullDataSize());
9623 QualType To = getDerived().TransformType(TLB, FromTL);
9624 if (To.isNull())
9625 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009626
Douglas Gregor29c42f22012-02-24 07:38:34 +00009627 if (To == From->getType())
9628 Args.push_back(From);
9629 else {
9630 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9631 ArgChanged = true;
9632 }
9633 continue;
9634 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009635
Douglas Gregor29c42f22012-02-24 07:38:34 +00009636 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009637
Douglas Gregor29c42f22012-02-24 07:38:34 +00009638 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00009639 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00009640 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
9641 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9642 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00009643
Douglas Gregor29c42f22012-02-24 07:38:34 +00009644 // Determine whether the set of unexpanded parameter packs can and should
9645 // be expanded.
9646 bool Expand = true;
9647 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009648 Optional<unsigned> OrigNumExpansions =
9649 ExpansionTL.getTypePtr()->getNumExpansions();
9650 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009651 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
9652 PatternTL.getSourceRange(),
9653 Unexpanded,
9654 Expand, RetainExpansion,
9655 NumExpansions))
9656 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009657
Douglas Gregor29c42f22012-02-24 07:38:34 +00009658 if (!Expand) {
9659 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009660 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00009661 // expansion.
9662 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00009663
Douglas Gregor29c42f22012-02-24 07:38:34 +00009664 TypeLocBuilder TLB;
9665 TLB.reserve(From->getTypeLoc().getFullDataSize());
9666
9667 QualType To = getDerived().TransformType(TLB, PatternTL);
9668 if (To.isNull())
9669 return ExprError();
9670
Chad Rosier1dcde962012-08-08 18:46:20 +00009671 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009672 PatternTL.getSourceRange(),
9673 ExpansionTL.getEllipsisLoc(),
9674 NumExpansions);
9675 if (To.isNull())
9676 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009677
Douglas Gregor29c42f22012-02-24 07:38:34 +00009678 PackExpansionTypeLoc ToExpansionTL
9679 = TLB.push<PackExpansionTypeLoc>(To);
9680 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9681 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9682 continue;
9683 }
9684
9685 // Expand the pack expansion by substituting for each argument in the
9686 // pack(s).
9687 for (unsigned I = 0; I != *NumExpansions; ++I) {
9688 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
9689 TypeLocBuilder TLB;
9690 TLB.reserve(PatternTL.getFullDataSize());
9691 QualType To = getDerived().TransformType(TLB, PatternTL);
9692 if (To.isNull())
9693 return ExprError();
9694
Eli Friedman5e05c4a2013-07-19 21:49:32 +00009695 if (To->containsUnexpandedParameterPack()) {
9696 To = getDerived().RebuildPackExpansionType(To,
9697 PatternTL.getSourceRange(),
9698 ExpansionTL.getEllipsisLoc(),
9699 NumExpansions);
9700 if (To.isNull())
9701 return ExprError();
9702
9703 PackExpansionTypeLoc ToExpansionTL
9704 = TLB.push<PackExpansionTypeLoc>(To);
9705 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9706 }
9707
Douglas Gregor29c42f22012-02-24 07:38:34 +00009708 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9709 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009710
Douglas Gregor29c42f22012-02-24 07:38:34 +00009711 if (!RetainExpansion)
9712 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009713
Douglas Gregor29c42f22012-02-24 07:38:34 +00009714 // If we're supposed to retain a pack expansion, do so by temporarily
9715 // forgetting the partially-substituted parameter pack.
9716 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
9717
9718 TypeLocBuilder TLB;
9719 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00009720
Douglas Gregor29c42f22012-02-24 07:38:34 +00009721 QualType To = getDerived().TransformType(TLB, PatternTL);
9722 if (To.isNull())
9723 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009724
9725 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009726 PatternTL.getSourceRange(),
9727 ExpansionTL.getEllipsisLoc(),
9728 NumExpansions);
9729 if (To.isNull())
9730 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009731
Douglas Gregor29c42f22012-02-24 07:38:34 +00009732 PackExpansionTypeLoc ToExpansionTL
9733 = TLB.push<PackExpansionTypeLoc>(To);
9734 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9735 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9736 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009737
Douglas Gregor29c42f22012-02-24 07:38:34 +00009738 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009739 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009740
9741 return getDerived().RebuildTypeTrait(E->getTrait(),
9742 E->getLocStart(),
9743 Args,
9744 E->getLocEnd());
9745}
9746
9747template<typename Derived>
9748ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00009749TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
9750 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
9751 if (!T)
9752 return ExprError();
9753
9754 if (!getDerived().AlwaysRebuild() &&
9755 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009756 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009757
9758 ExprResult SubExpr;
9759 {
9760 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9761 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
9762 if (SubExpr.isInvalid())
9763 return ExprError();
9764
9765 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009766 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009767 }
9768
9769 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
9770 E->getLocStart(),
9771 T,
9772 SubExpr.get(),
9773 E->getLocEnd());
9774}
9775
9776template<typename Derived>
9777ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00009778TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
9779 ExprResult SubExpr;
9780 {
9781 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9782 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
9783 if (SubExpr.isInvalid())
9784 return ExprError();
9785
9786 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009787 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +00009788 }
9789
9790 return getDerived().RebuildExpressionTrait(
9791 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
9792}
9793
Reid Kleckner32506ed2014-06-12 23:03:48 +00009794template <typename Derived>
9795ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
9796 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
9797 TypeSourceInfo **RecoveryTSI) {
9798 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
9799 DRE, AddrTaken, RecoveryTSI);
9800
9801 // Propagate both errors and recovered types, which return ExprEmpty.
9802 if (!NewDRE.isUsable())
9803 return NewDRE;
9804
9805 // We got an expr, wrap it up in parens.
9806 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
9807 return PE;
9808 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
9809 PE->getRParen());
9810}
9811
9812template <typename Derived>
9813ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9814 DependentScopeDeclRefExpr *E) {
9815 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
9816 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00009817}
9818
9819template<typename Derived>
9820ExprResult
9821TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9822 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +00009823 bool IsAddressOfOperand,
9824 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00009825 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009826 NestedNameSpecifierLoc QualifierLoc
9827 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9828 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009829 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00009830 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00009831
John McCall31f82722010-11-12 08:19:04 +00009832 // TODO: If this is a conversion-function-id, verify that the
9833 // destination type name (if present) resolves the same way after
9834 // instantiation as it did in the local scope.
9835
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009836 DeclarationNameInfo NameInfo
9837 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
9838 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009839 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009840
John McCalle66edc12009-11-24 19:00:30 +00009841 if (!E->hasExplicitTemplateArgs()) {
9842 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009843 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009844 // Note: it is sufficient to compare the Name component of NameInfo:
9845 // if name has not changed, DNLoc has not changed either.
9846 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009847 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009848
Reid Kleckner32506ed2014-06-12 23:03:48 +00009849 return getDerived().RebuildDependentScopeDeclRefExpr(
9850 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
9851 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +00009852 }
John McCall6b51f282009-11-23 01:53:49 +00009853
9854 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009855 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9856 E->getNumTemplateArgs(),
9857 TransArgs))
9858 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009859
Reid Kleckner32506ed2014-06-12 23:03:48 +00009860 return getDerived().RebuildDependentScopeDeclRefExpr(
9861 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
9862 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00009863}
9864
9865template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009866ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009867TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00009868 // CXXConstructExprs other than for list-initialization and
9869 // CXXTemporaryObjectExpr are always implicit, so when we have
9870 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00009871 if ((E->getNumArgs() == 1 ||
9872 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00009873 (!getDerived().DropCallArgument(E->getArg(0))) &&
9874 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00009875 return getDerived().TransformExpr(E->getArg(0));
9876
Douglas Gregora16548e2009-08-11 05:31:07 +00009877 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
9878
9879 QualType T = getDerived().TransformType(E->getType());
9880 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00009881 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009882
9883 CXXConstructorDecl *Constructor
9884 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009885 getDerived().TransformDecl(E->getLocStart(),
9886 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009887 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009888 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009889
Douglas Gregora16548e2009-08-11 05:31:07 +00009890 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009891 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009892 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009893 &ArgumentChanged))
9894 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009895
Douglas Gregora16548e2009-08-11 05:31:07 +00009896 if (!getDerived().AlwaysRebuild() &&
9897 T == E->getType() &&
9898 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00009899 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00009900 // Mark the constructor as referenced.
9901 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009902 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009903 return E;
Douglas Gregorde550352010-02-26 00:01:57 +00009904 }
Mike Stump11289f42009-09-09 15:08:12 +00009905
Douglas Gregordb121ba2009-12-14 16:27:04 +00009906 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
9907 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009908 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00009909 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00009910 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +00009911 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00009912 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00009913 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00009914 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009915}
Mike Stump11289f42009-09-09 15:08:12 +00009916
Douglas Gregora16548e2009-08-11 05:31:07 +00009917/// \brief Transform a C++ temporary-binding expression.
9918///
Douglas Gregor363b1512009-12-24 18:51:59 +00009919/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
9920/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009921template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009922ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009923TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009924 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009925}
Mike Stump11289f42009-09-09 15:08:12 +00009926
John McCall5d413782010-12-06 08:20:24 +00009927/// \brief Transform a C++ expression that contains cleanups that should
9928/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00009929///
John McCall5d413782010-12-06 08:20:24 +00009930/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00009931/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009932template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009933ExprResult
John McCall5d413782010-12-06 08:20:24 +00009934TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009935 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009936}
Mike Stump11289f42009-09-09 15:08:12 +00009937
Douglas Gregora16548e2009-08-11 05:31:07 +00009938template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009939ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009940TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00009941 CXXTemporaryObjectExpr *E) {
9942 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9943 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009944 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009945
Douglas Gregora16548e2009-08-11 05:31:07 +00009946 CXXConstructorDecl *Constructor
9947 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00009948 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009949 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;
Douglas Gregora16548e2009-08-11 05:31:07 +00009955 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009956 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009957 &ArgumentChanged))
9958 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009959
Douglas Gregora16548e2009-08-11 05:31:07 +00009960 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009961 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009962 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009963 !ArgumentChanged) {
9964 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009965 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00009966 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009967 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009968
Richard Smithd59b8322012-12-19 01:39:02 +00009969 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00009970 return getDerived().RebuildCXXTemporaryObjectExpr(T,
9971 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009972 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009973 E->getLocEnd());
9974}
Mike Stump11289f42009-09-09 15:08:12 +00009975
Douglas Gregora16548e2009-08-11 05:31:07 +00009976template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009977ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00009978TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +00009979 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009980 // lambda body, because they are not semantically within that scope.
Richard Smithc38498f2015-04-27 21:27:54 +00009981 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009982 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
9983 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
Richard Smithc38498f2015-04-27 21:27:54 +00009984 E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009985 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +00009986 CEnd = E->capture_end();
9987 C != CEnd; ++C) {
James Dennettdd2ffea22015-05-07 18:48:18 +00009988 if (!E->isInitCapture(C))
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009989 continue;
Richard Smith01014ce2014-11-20 23:53:14 +00009990 EnterExpressionEvaluationContext EEEC(getSema(),
9991 Sema::PotentiallyEvaluated);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009992 ExprResult NewExprInitResult = getDerived().TransformInitializer(
9993 C->getCapturedVar()->getInit(),
9994 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith01014ce2014-11-20 23:53:14 +00009995
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009996 if (NewExprInitResult.isInvalid())
9997 return ExprError();
9998 Expr *NewExprInit = NewExprInitResult.get();
Richard Smith01014ce2014-11-20 23:53:14 +00009999
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010000 VarDecl *OldVD = C->getCapturedVar();
Richard Smith01014ce2014-11-20 23:53:14 +000010001 QualType NewInitCaptureType =
Richard Smith42b10572015-11-11 01:36:17 +000010002 getSema().buildLambdaInitCaptureInitialization(
10003 C->getLocation(), OldVD->getType()->isReferenceType(),
10004 OldVD->getIdentifier(),
10005 C->getCapturedVar()->getInitStyle() != VarDecl::CInit, NewExprInit);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010006 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010007 InitCaptureExprsAndTypes[C - E->capture_begin()] =
10008 std::make_pair(NewExprInitResult, NewInitCaptureType);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010009 }
10010
Faisal Vali2cba1332013-10-23 06:44:28 +000010011 // Transform the template parameters, and add them to the current
10012 // instantiation scope. The null case is handled correctly.
Richard Smithc38498f2015-04-27 21:27:54 +000010013 auto TPL = getDerived().TransformTemplateParameterList(
Faisal Vali2cba1332013-10-23 06:44:28 +000010014 E->getTemplateParameterList());
10015
Richard Smith01014ce2014-11-20 23:53:14 +000010016 // Transform the type of the original lambda's call operator.
10017 // The transformation MUST be done in the CurrentInstantiationScope since
10018 // it introduces a mapping of the original to the newly created
10019 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +000010020 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +000010021 {
10022 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
10023 FunctionProtoTypeLoc OldCallOpFPTL =
10024 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +000010025
10026 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +000010027 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +000010028 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +000010029 QualType NewCallOpType = TransformFunctionProtoType(
10030 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +000010031 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
10032 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
10033 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +000010034 });
Reid Kleckneraac43c62014-12-15 21:07:16 +000010035 if (NewCallOpType.isNull())
10036 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +000010037 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
10038 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +000010039 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010040
Richard Smithc38498f2015-04-27 21:27:54 +000010041 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
10042 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
10043 LSI->GLTemplateParameterList = TPL;
10044
Eli Friedmand564afb2012-09-19 01:18:11 +000010045 // Create the local class that will describe the lambda.
10046 CXXRecordDecl *Class
10047 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +000010048 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +000010049 /*KnownDependent=*/false,
10050 E->getCaptureDefault());
Eli Friedmand564afb2012-09-19 01:18:11 +000010051 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
10052
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010053 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +000010054 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
10055 Class, E->getIntroducerRange(), NewCallOpTSI,
10056 E->getCallOperator()->getLocEnd(),
10057 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams());
Faisal Vali2cba1332013-10-23 06:44:28 +000010058 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +000010059
Faisal Vali2cba1332013-10-23 06:44:28 +000010060 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
Richard Smithc38498f2015-04-27 21:27:54 +000010061 getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
Richard Smithba71c082013-05-16 06:20:58 +000010062
Douglas Gregorb4328232012-02-14 00:00:48 +000010063 // Introduce the context of the call operator.
Richard Smithc38498f2015-04-27 21:27:54 +000010064 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
Richard Smith7ff2bcb2014-01-24 01:54:52 +000010065 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +000010066
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010067 // Enter the scope of the lambda.
Richard Smithc38498f2015-04-27 21:27:54 +000010068 getSema().buildLambdaScope(LSI, NewCallOperator,
10069 E->getIntroducerRange(),
10070 E->getCaptureDefault(),
10071 E->getCaptureDefaultLoc(),
10072 E->hasExplicitParameters(),
10073 E->hasExplicitResultType(),
10074 E->isMutable());
10075
10076 bool Invalid = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010077
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010078 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010079 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010080 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010081 CEnd = E->capture_end();
10082 C != CEnd; ++C) {
10083 // When we hit the first implicit capture, tell Sema that we've finished
10084 // the list of explicit captures.
10085 if (!FinishedExplicitCaptures && C->isImplicit()) {
10086 getSema().finishLambdaExplicitCaptures(LSI);
10087 FinishedExplicitCaptures = true;
10088 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010089
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010090 // Capturing 'this' is trivial.
10091 if (C->capturesThis()) {
Faisal Validc6b5962016-03-21 09:25:37 +000010092 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
10093 /*BuildAndDiagnose*/ true, nullptr,
10094 C->getCaptureKind() == LCK_StarThis);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010095 continue;
10096 }
Alexey Bataev39c81e22014-08-28 04:28:19 +000010097 // Captured expression will be recaptured during captured variables
10098 // rebuilding.
10099 if (C->capturesVLAType())
10100 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +000010101
Richard Smithba71c082013-05-16 06:20:58 +000010102 // Rebuild init-captures, including the implied field declaration.
James Dennettdd2ffea22015-05-07 18:48:18 +000010103 if (E->isInitCapture(C)) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010104 InitCaptureInfoTy InitExprTypePair =
10105 InitCaptureExprsAndTypes[C - E->capture_begin()];
10106 ExprResult Init = InitExprTypePair.first;
10107 QualType InitQualType = InitExprTypePair.second;
10108 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +000010109 Invalid = true;
10110 continue;
10111 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000010112 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010113 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
Richard Smith42b10572015-11-11 01:36:17 +000010114 OldVD->getLocation(), InitExprTypePair.second, OldVD->getIdentifier(),
10115 OldVD->getInitStyle(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +000010116 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +000010117 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010118 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +000010119 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010120 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000010121 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +000010122 continue;
10123 }
10124
10125 assert(C->capturesVariable() && "unexpected kind of lambda capture");
10126
Douglas Gregor3e308b12012-02-14 19:27:52 +000010127 // Determine the capture kind for Sema.
10128 Sema::TryCaptureKind Kind
10129 = C->isImplicit()? Sema::TryCapture_Implicit
10130 : C->getCaptureKind() == LCK_ByCopy
10131 ? Sema::TryCapture_ExplicitByVal
10132 : Sema::TryCapture_ExplicitByRef;
10133 SourceLocation EllipsisLoc;
10134 if (C->isPackExpansion()) {
10135 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
10136 bool ShouldExpand = false;
10137 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010138 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +000010139 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
10140 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000010141 Unexpanded,
10142 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +000010143 NumExpansions)) {
10144 Invalid = true;
10145 continue;
10146 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010147
Douglas Gregor3e308b12012-02-14 19:27:52 +000010148 if (ShouldExpand) {
10149 // The transform has determined that we should perform an expansion;
10150 // transform and capture each of the arguments.
10151 // expansion of the pattern. Do so.
10152 VarDecl *Pack = C->getCapturedVar();
10153 for (unsigned I = 0; I != *NumExpansions; ++I) {
10154 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10155 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000010156 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000010157 Pack));
10158 if (!CapturedVar) {
10159 Invalid = true;
10160 continue;
10161 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010162
Douglas Gregor3e308b12012-02-14 19:27:52 +000010163 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +000010164 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
10165 }
Richard Smith9467be42014-06-06 17:33:35 +000010166
10167 // FIXME: Retain a pack expansion if RetainExpansion is true.
10168
Douglas Gregor3e308b12012-02-14 19:27:52 +000010169 continue;
10170 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010171
Douglas Gregor3e308b12012-02-14 19:27:52 +000010172 EllipsisLoc = C->getEllipsisLoc();
10173 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010174
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010175 // Transform the captured variable.
10176 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000010177 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010178 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +000010179 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010180 Invalid = true;
10181 continue;
10182 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010183
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010184 // Capture the transformed variable.
Meador Inge4f9dee72015-06-26 00:09:55 +000010185 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
10186 EllipsisLoc);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010187 }
10188 if (!FinishedExplicitCaptures)
10189 getSema().finishLambdaExplicitCaptures(LSI);
10190
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010191 // Enter a new evaluation context to insulate the lambda from any
10192 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +000010193 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010194
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010195 // Instantiate the body of the lambda expression.
Richard Smithc38498f2015-04-27 21:27:54 +000010196 StmtResult Body =
10197 Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
10198
10199 // ActOnLambda* will pop the function scope for us.
10200 FuncScopeCleanup.disable();
10201
Douglas Gregorb4328232012-02-14 00:00:48 +000010202 if (Body.isInvalid()) {
Richard Smithc38498f2015-04-27 21:27:54 +000010203 SavedContext.pop();
Craig Topperc3ec1492014-05-26 06:22:03 +000010204 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +000010205 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +000010206 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +000010207 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +000010208
Richard Smithc38498f2015-04-27 21:27:54 +000010209 // Copy the LSI before ActOnFinishFunctionBody removes it.
10210 // FIXME: This is dumb. Store the lambda information somewhere that outlives
10211 // the call operator.
10212 auto LSICopy = *LSI;
10213 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
10214 /*IsInstantiation*/ true);
10215 SavedContext.pop();
10216
10217 return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(),
10218 &LSICopy);
Douglas Gregore31e6062012-02-07 10:09:13 +000010219}
10220
10221template<typename Derived>
10222ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010223TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010224 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +000010225 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10226 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010227 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010228
Douglas Gregora16548e2009-08-11 05:31:07 +000010229 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010230 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000010231 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +000010232 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010233 &ArgumentChanged))
10234 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010235
Douglas Gregora16548e2009-08-11 05:31:07 +000010236 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010237 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010238 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010239 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010240
Douglas Gregora16548e2009-08-11 05:31:07 +000010241 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +000010242 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +000010243 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010244 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +000010245 E->getRParenLoc());
10246}
Mike Stump11289f42009-09-09 15:08:12 +000010247
Douglas Gregora16548e2009-08-11 05:31:07 +000010248template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010249ExprResult
John McCall8cd78132009-11-19 22:55:06 +000010250TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010251 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010252 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000010253 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000010254 Expr *OldBase;
10255 QualType BaseType;
10256 QualType ObjectType;
10257 if (!E->isImplicitAccess()) {
10258 OldBase = E->getBase();
10259 Base = getDerived().TransformExpr(OldBase);
10260 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010261 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010262
John McCall2d74de92009-12-01 22:10:20 +000010263 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +000010264 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +000010265 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +000010266 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010267 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010268 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +000010269 ObjectTy,
10270 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +000010271 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010272 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +000010273
John McCallba7bf592010-08-24 05:47:05 +000010274 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +000010275 BaseType = ((Expr*) Base.get())->getType();
10276 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +000010277 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +000010278 BaseType = getDerived().TransformType(E->getBaseType());
10279 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
10280 }
Mike Stump11289f42009-09-09 15:08:12 +000010281
Douglas Gregora5cb6da2009-10-20 05:58:46 +000010282 // Transform the first part of the nested-name-specifier that qualifies
10283 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +000010284 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +000010285 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +000010286 E->getFirstQualifierFoundInScope(),
10287 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +000010288
Douglas Gregore16af532011-02-28 18:50:33 +000010289 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010290 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +000010291 QualifierLoc
10292 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
10293 ObjectType,
10294 FirstQualifierInScope);
10295 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010296 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010297 }
Mike Stump11289f42009-09-09 15:08:12 +000010298
Abramo Bagnara7945c982012-01-27 09:46:47 +000010299 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
10300
John McCall31f82722010-11-12 08:19:04 +000010301 // TODO: If this is a conversion-function-id, verify that the
10302 // destination type name (if present) resolves the same way after
10303 // instantiation as it did in the local scope.
10304
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010305 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +000010306 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010307 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000010308 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010309
John McCall2d74de92009-12-01 22:10:20 +000010310 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +000010311 // This is a reference to a member without an explicitly-specified
10312 // template argument list. Optimize for this common case.
10313 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +000010314 Base.get() == OldBase &&
10315 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +000010316 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010317 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +000010318 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010319 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010320
John McCallb268a282010-08-23 23:25:46 +000010321 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010322 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +000010323 E->isArrow(),
10324 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000010325 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010326 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +000010327 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010328 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000010329 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +000010330 }
10331
John McCall6b51f282009-11-23 01:53:49 +000010332 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010333 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
10334 E->getNumTemplateArgs(),
10335 TransArgs))
10336 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010337
John McCallb268a282010-08-23 23:25:46 +000010338 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010339 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +000010340 E->isArrow(),
10341 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000010342 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010343 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +000010344 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010345 NameInfo,
John McCall10eae182009-11-30 22:42:35 +000010346 &TransArgs);
10347}
10348
10349template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010350ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010351TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +000010352 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000010353 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000010354 QualType BaseType;
10355 if (!Old->isImplicitAccess()) {
10356 Base = getDerived().TransformExpr(Old->getBase());
10357 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010358 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010359 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +000010360 Old->isArrow());
10361 if (Base.isInvalid())
10362 return ExprError();
10363 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +000010364 } else {
10365 BaseType = getDerived().TransformType(Old->getBaseType());
10366 }
John McCall10eae182009-11-30 22:42:35 +000010367
Douglas Gregor0da1d432011-02-28 20:01:57 +000010368 NestedNameSpecifierLoc QualifierLoc;
10369 if (Old->getQualifierLoc()) {
10370 QualifierLoc
10371 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
10372 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010373 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000010374 }
10375
Abramo Bagnara7945c982012-01-27 09:46:47 +000010376 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
10377
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010378 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +000010379 Sema::LookupOrdinaryName);
10380
10381 // Transform all the decls.
10382 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
10383 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010384 NamedDecl *InstD = static_cast<NamedDecl*>(
10385 getDerived().TransformDecl(Old->getMemberLoc(),
10386 *I));
John McCall84d87672009-12-10 09:41:52 +000010387 if (!InstD) {
10388 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
10389 // This can happen because of dependent hiding.
10390 if (isa<UsingShadowDecl>(*I))
10391 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +000010392 else {
10393 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +000010394 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +000010395 }
John McCall84d87672009-12-10 09:41:52 +000010396 }
John McCall10eae182009-11-30 22:42:35 +000010397
10398 // Expand using declarations.
10399 if (isa<UsingDecl>(InstD)) {
10400 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +000010401 for (auto *I : UD->shadows())
10402 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +000010403 continue;
10404 }
10405
10406 R.addDecl(InstD);
10407 }
10408
10409 R.resolveKind();
10410
Douglas Gregor9262f472010-04-27 18:19:34 +000010411 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +000010412 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +000010413 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +000010414 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +000010415 Old->getMemberLoc(),
10416 Old->getNamingClass()));
10417 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +000010418 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010419
Douglas Gregorda7be082010-04-27 16:10:10 +000010420 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +000010421 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010422
John McCall10eae182009-11-30 22:42:35 +000010423 TemplateArgumentListInfo TransArgs;
10424 if (Old->hasExplicitTemplateArgs()) {
10425 TransArgs.setLAngleLoc(Old->getLAngleLoc());
10426 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010427 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
10428 Old->getNumTemplateArgs(),
10429 TransArgs))
10430 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000010431 }
John McCall38836f02010-01-15 08:34:02 +000010432
10433 // FIXME: to do this check properly, we will need to preserve the
10434 // first-qualifier-in-scope here, just in case we had a dependent
10435 // base (and therefore couldn't do the check) and a
10436 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +000010437 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +000010438
John McCallb268a282010-08-23 23:25:46 +000010439 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010440 BaseType,
John McCall10eae182009-11-30 22:42:35 +000010441 Old->getOperatorLoc(),
10442 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +000010443 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010444 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +000010445 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +000010446 R,
10447 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +000010448 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +000010449}
10450
10451template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010452ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010453TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +000010454 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010455 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
10456 if (SubExpr.isInvalid())
10457 return ExprError();
10458
10459 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010460 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010461
10462 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
10463}
10464
10465template<typename Derived>
10466ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010467TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010468 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
10469 if (Pattern.isInvalid())
10470 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010471
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010472 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010473 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010474
Douglas Gregorb8840002011-01-14 21:20:45 +000010475 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
10476 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010477}
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010478
10479template<typename Derived>
10480ExprResult
10481TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
10482 // If E is not value-dependent, then nothing will change when we transform it.
10483 // Note: This is an instantiation-centric view.
10484 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010485 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010486
Richard Smithd784e682015-09-23 21:41:42 +000010487 EnterExpressionEvaluationContext Unevaluated(getSema(), Sema::Unevaluated);
Chad Rosier1dcde962012-08-08 18:46:20 +000010488
Richard Smithd784e682015-09-23 21:41:42 +000010489 ArrayRef<TemplateArgument> PackArgs;
10490 TemplateArgument ArgStorage;
Chad Rosier1dcde962012-08-08 18:46:20 +000010491
Richard Smithd784e682015-09-23 21:41:42 +000010492 // Find the argument list to transform.
10493 if (E->isPartiallySubstituted()) {
10494 PackArgs = E->getPartialArguments();
10495 } else if (E->isValueDependent()) {
10496 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
10497 bool ShouldExpand = false;
10498 bool RetainExpansion = false;
10499 Optional<unsigned> NumExpansions;
10500 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
10501 Unexpanded,
10502 ShouldExpand, RetainExpansion,
10503 NumExpansions))
10504 return ExprError();
10505
10506 // If we need to expand the pack, build a template argument from it and
10507 // expand that.
10508 if (ShouldExpand) {
10509 auto *Pack = E->getPack();
10510 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
10511 ArgStorage = getSema().Context.getPackExpansionType(
10512 getSema().Context.getTypeDeclType(TTPD), None);
10513 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
10514 ArgStorage = TemplateArgument(TemplateName(TTPD), None);
10515 } else {
10516 auto *VD = cast<ValueDecl>(Pack);
10517 ExprResult DRE = getSema().BuildDeclRefExpr(VD, VD->getType(),
10518 VK_RValue, E->getPackLoc());
10519 if (DRE.isInvalid())
10520 return ExprError();
10521 ArgStorage = new (getSema().Context) PackExpansionExpr(
10522 getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
10523 }
10524 PackArgs = ArgStorage;
10525 }
10526 }
10527
10528 // If we're not expanding the pack, just transform the decl.
10529 if (!PackArgs.size()) {
10530 auto *Pack = cast_or_null<NamedDecl>(
10531 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010532 if (!Pack)
10533 return ExprError();
Richard Smithd784e682015-09-23 21:41:42 +000010534 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
10535 E->getPackLoc(),
10536 E->getRParenLoc(), None, None);
10537 }
10538
10539 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
10540 E->getPackLoc());
10541 {
10542 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
10543 typedef TemplateArgumentLocInventIterator<
10544 Derived, const TemplateArgument*> PackLocIterator;
10545 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
10546 PackLocIterator(*this, PackArgs.end()),
10547 TransformedPackArgs, /*Uneval*/true))
10548 return ExprError();
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010549 }
10550
Richard Smithd784e682015-09-23 21:41:42 +000010551 SmallVector<TemplateArgument, 8> Args;
10552 bool PartialSubstitution = false;
10553 for (auto &Loc : TransformedPackArgs.arguments()) {
10554 Args.push_back(Loc.getArgument());
10555 if (Loc.getArgument().isPackExpansion())
10556 PartialSubstitution = true;
10557 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010558
Richard Smithd784e682015-09-23 21:41:42 +000010559 if (PartialSubstitution)
10560 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
10561 E->getPackLoc(),
10562 E->getRParenLoc(), None, Args);
10563
10564 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
Chad Rosier1dcde962012-08-08 18:46:20 +000010565 E->getPackLoc(), E->getRParenLoc(),
Richard Smithd784e682015-09-23 21:41:42 +000010566 Args.size(), None);
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010567}
10568
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010569template<typename Derived>
10570ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010571TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
10572 SubstNonTypeTemplateParmPackExpr *E) {
10573 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010574 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010575}
10576
10577template<typename Derived>
10578ExprResult
John McCall7c454bb2011-07-15 05:09:51 +000010579TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
10580 SubstNonTypeTemplateParmExpr *E) {
10581 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010582 return E;
John McCall7c454bb2011-07-15 05:09:51 +000010583}
10584
10585template<typename Derived>
10586ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +000010587TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
10588 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010589 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +000010590}
10591
10592template<typename Derived>
10593ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +000010594TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
10595 MaterializeTemporaryExpr *E) {
10596 return getDerived().TransformExpr(E->GetTemporaryExpr());
10597}
Chad Rosier1dcde962012-08-08 18:46:20 +000010598
Douglas Gregorfe314812011-06-21 17:03:29 +000010599template<typename Derived>
10600ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +000010601TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
10602 Expr *Pattern = E->getPattern();
10603
10604 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10605 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
10606 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10607
10608 // Determine whether the set of unexpanded parameter packs can and should
10609 // be expanded.
10610 bool Expand = true;
10611 bool RetainExpansion = false;
10612 Optional<unsigned> NumExpansions;
10613 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
10614 Pattern->getSourceRange(),
10615 Unexpanded,
10616 Expand, RetainExpansion,
10617 NumExpansions))
10618 return true;
10619
10620 if (!Expand) {
10621 // Do not expand any packs here, just transform and rebuild a fold
10622 // expression.
10623 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10624
10625 ExprResult LHS =
10626 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
10627 if (LHS.isInvalid())
10628 return true;
10629
10630 ExprResult RHS =
10631 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
10632 if (RHS.isInvalid())
10633 return true;
10634
10635 if (!getDerived().AlwaysRebuild() &&
10636 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
10637 return E;
10638
10639 return getDerived().RebuildCXXFoldExpr(
10640 E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
10641 RHS.get(), E->getLocEnd());
10642 }
10643
10644 // The transform has determined that we should perform an elementwise
10645 // expansion of the pattern. Do so.
10646 ExprResult Result = getDerived().TransformExpr(E->getInit());
10647 if (Result.isInvalid())
10648 return true;
10649 bool LeftFold = E->isLeftFold();
10650
10651 // If we're retaining an expansion for a right fold, it is the innermost
10652 // component and takes the init (if any).
10653 if (!LeftFold && RetainExpansion) {
10654 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10655
10656 ExprResult Out = getDerived().TransformExpr(Pattern);
10657 if (Out.isInvalid())
10658 return true;
10659
10660 Result = getDerived().RebuildCXXFoldExpr(
10661 E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
10662 Result.get(), E->getLocEnd());
10663 if (Result.isInvalid())
10664 return true;
10665 }
10666
10667 for (unsigned I = 0; I != *NumExpansions; ++I) {
10668 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
10669 getSema(), LeftFold ? I : *NumExpansions - I - 1);
10670 ExprResult Out = getDerived().TransformExpr(Pattern);
10671 if (Out.isInvalid())
10672 return true;
10673
10674 if (Out.get()->containsUnexpandedParameterPack()) {
10675 // We still have a pack; retain a pack expansion for this slice.
10676 Result = getDerived().RebuildCXXFoldExpr(
10677 E->getLocStart(),
10678 LeftFold ? Result.get() : Out.get(),
10679 E->getOperator(), E->getEllipsisLoc(),
10680 LeftFold ? Out.get() : Result.get(),
10681 E->getLocEnd());
10682 } else if (Result.isUsable()) {
10683 // We've got down to a single element; build a binary operator.
10684 Result = getDerived().RebuildBinaryOperator(
10685 E->getEllipsisLoc(), E->getOperator(),
10686 LeftFold ? Result.get() : Out.get(),
10687 LeftFold ? Out.get() : Result.get());
10688 } else
10689 Result = Out;
10690
10691 if (Result.isInvalid())
10692 return true;
10693 }
10694
10695 // If we're retaining an expansion for a left fold, it is the outermost
10696 // component and takes the complete expansion so far as its init (if any).
10697 if (LeftFold && RetainExpansion) {
10698 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10699
10700 ExprResult Out = getDerived().TransformExpr(Pattern);
10701 if (Out.isInvalid())
10702 return true;
10703
10704 Result = getDerived().RebuildCXXFoldExpr(
10705 E->getLocStart(), Result.get(),
10706 E->getOperator(), E->getEllipsisLoc(),
10707 Out.get(), E->getLocEnd());
10708 if (Result.isInvalid())
10709 return true;
10710 }
10711
10712 // If we had no init and an empty pack, and we're not retaining an expansion,
10713 // then produce a fallback value or error.
10714 if (Result.isUnset())
10715 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
10716 E->getOperator());
10717
10718 return Result;
10719}
10720
10721template<typename Derived>
10722ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +000010723TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
10724 CXXStdInitializerListExpr *E) {
10725 return getDerived().TransformExpr(E->getSubExpr());
10726}
10727
10728template<typename Derived>
10729ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010730TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010731 return SemaRef.MaybeBindToTemporary(E);
10732}
10733
10734template<typename Derived>
10735ExprResult
10736TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010737 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010738}
10739
10740template<typename Derived>
10741ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +000010742TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
10743 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
10744 if (SubExpr.isInvalid())
10745 return ExprError();
10746
10747 if (!getDerived().AlwaysRebuild() &&
10748 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010749 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +000010750
10751 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +000010752}
10753
10754template<typename Derived>
10755ExprResult
10756TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
10757 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010758 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010759 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010760 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000010761 /*IsCall=*/false, Elements, &ArgChanged))
10762 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010763
Ted Kremeneke65b0862012-03-06 20:05:56 +000010764 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10765 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000010766
Ted Kremeneke65b0862012-03-06 20:05:56 +000010767 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
10768 Elements.data(),
10769 Elements.size());
10770}
10771
10772template<typename Derived>
10773ExprResult
10774TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +000010775 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010776 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010777 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010778 bool ArgChanged = false;
10779 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
10780 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +000010781
Ted Kremeneke65b0862012-03-06 20:05:56 +000010782 if (OrigElement.isPackExpansion()) {
10783 // This key/value element is a pack expansion.
10784 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10785 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
10786 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
10787 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10788
10789 // Determine whether the set of unexpanded parameter packs can
10790 // and should be expanded.
10791 bool Expand = true;
10792 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010793 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
10794 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010795 SourceRange PatternRange(OrigElement.Key->getLocStart(),
10796 OrigElement.Value->getLocEnd());
10797 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
10798 PatternRange,
10799 Unexpanded,
10800 Expand, RetainExpansion,
10801 NumExpansions))
10802 return ExprError();
10803
10804 if (!Expand) {
10805 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000010806 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +000010807 // expansion.
10808 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10809 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10810 if (Key.isInvalid())
10811 return ExprError();
10812
10813 if (Key.get() != OrigElement.Key)
10814 ArgChanged = true;
10815
10816 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10817 if (Value.isInvalid())
10818 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010819
Ted Kremeneke65b0862012-03-06 20:05:56 +000010820 if (Value.get() != OrigElement.Value)
10821 ArgChanged = true;
10822
Chad Rosier1dcde962012-08-08 18:46:20 +000010823 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010824 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
10825 };
10826 Elements.push_back(Expansion);
10827 continue;
10828 }
10829
10830 // Record right away that the argument was changed. This needs
10831 // to happen even if the array expands to nothing.
10832 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010833
Ted Kremeneke65b0862012-03-06 20:05:56 +000010834 // The transform has determined that we should perform an elementwise
10835 // expansion of the pattern. Do so.
10836 for (unsigned I = 0; I != *NumExpansions; ++I) {
10837 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10838 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10839 if (Key.isInvalid())
10840 return ExprError();
10841
10842 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10843 if (Value.isInvalid())
10844 return ExprError();
10845
Chad Rosier1dcde962012-08-08 18:46:20 +000010846 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010847 Key.get(), Value.get(), SourceLocation(), NumExpansions
10848 };
10849
10850 // If any unexpanded parameter packs remain, we still have a
10851 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +000010852 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +000010853 if (Key.get()->containsUnexpandedParameterPack() ||
10854 Value.get()->containsUnexpandedParameterPack())
10855 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +000010856
Ted Kremeneke65b0862012-03-06 20:05:56 +000010857 Elements.push_back(Element);
10858 }
10859
Richard Smith9467be42014-06-06 17:33:35 +000010860 // FIXME: Retain a pack expansion if RetainExpansion is true.
10861
Ted Kremeneke65b0862012-03-06 20:05:56 +000010862 // We've finished with this pack expansion.
10863 continue;
10864 }
10865
10866 // Transform and check key.
10867 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10868 if (Key.isInvalid())
10869 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010870
Ted Kremeneke65b0862012-03-06 20:05:56 +000010871 if (Key.get() != OrigElement.Key)
10872 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010873
Ted Kremeneke65b0862012-03-06 20:05:56 +000010874 // Transform and check value.
10875 ExprResult Value
10876 = getDerived().TransformExpr(OrigElement.Value);
10877 if (Value.isInvalid())
10878 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010879
Ted Kremeneke65b0862012-03-06 20:05:56 +000010880 if (Value.get() != OrigElement.Value)
10881 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010882
10883 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +000010884 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +000010885 };
10886 Elements.push_back(Element);
10887 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010888
Ted Kremeneke65b0862012-03-06 20:05:56 +000010889 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10890 return SemaRef.MaybeBindToTemporary(E);
10891
10892 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
Craig Topperd4336e02015-12-24 23:58:15 +000010893 Elements);
Douglas Gregora16548e2009-08-11 05:31:07 +000010894}
10895
Mike Stump11289f42009-09-09 15:08:12 +000010896template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010897ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010898TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +000010899 TypeSourceInfo *EncodedTypeInfo
10900 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
10901 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010902 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010903
Douglas Gregora16548e2009-08-11 05:31:07 +000010904 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +000010905 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010906 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010907
10908 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +000010909 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000010910 E->getRParenLoc());
10911}
Mike Stump11289f42009-09-09 15:08:12 +000010912
Douglas Gregora16548e2009-08-11 05:31:07 +000010913template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +000010914ExprResult TreeTransform<Derived>::
10915TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +000010916 // This is a kind of implicit conversion, and it needs to get dropped
10917 // and recomputed for the same general reasons that ImplicitCastExprs
10918 // do, as well a more specific one: this expression is only valid when
10919 // it appears *immediately* as an argument expression.
10920 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +000010921}
10922
10923template<typename Derived>
10924ExprResult TreeTransform<Derived>::
10925TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +000010926 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +000010927 = getDerived().TransformType(E->getTypeInfoAsWritten());
10928 if (!TSInfo)
10929 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010930
John McCall31168b02011-06-15 23:02:42 +000010931 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +000010932 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +000010933 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010934
John McCall31168b02011-06-15 23:02:42 +000010935 if (!getDerived().AlwaysRebuild() &&
10936 TSInfo == E->getTypeInfoAsWritten() &&
10937 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010938 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010939
John McCall31168b02011-06-15 23:02:42 +000010940 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000010941 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000010942 Result.get());
10943}
10944
10945template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010946ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010947TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010948 // Transform arguments.
10949 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010950 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000010951 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010952 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010953 &ArgChanged))
10954 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010955
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010956 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
10957 // Class message: transform the receiver type.
10958 TypeSourceInfo *ReceiverTypeInfo
10959 = getDerived().TransformType(E->getClassReceiverTypeInfo());
10960 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010961 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010962
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010963 // If nothing changed, just retain the existing message send.
10964 if (!getDerived().AlwaysRebuild() &&
10965 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010966 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010967
10968 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010969 SmallVector<SourceLocation, 16> SelLocs;
10970 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010971 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
10972 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010973 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010974 E->getMethodDecl(),
10975 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010976 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010977 E->getRightLoc());
10978 }
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000010979 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
10980 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
10981 // Build a new class message send to 'super'.
10982 SmallVector<SourceLocation, 16> SelLocs;
10983 E->getSelectorLocs(SelLocs);
10984 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
10985 E->getSelector(),
10986 SelLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +000010987 E->getReceiverType(),
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000010988 E->getMethodDecl(),
10989 E->getLeftLoc(),
10990 Args,
10991 E->getRightLoc());
10992 }
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010993
10994 // Instance message: transform the receiver
10995 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
10996 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000010997 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010998 = getDerived().TransformExpr(E->getInstanceReceiver());
10999 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011000 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011001
11002 // If nothing changed, just retain the existing message send.
11003 if (!getDerived().AlwaysRebuild() &&
11004 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011005 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000011006
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011007 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011008 SmallVector<SourceLocation, 16> SelLocs;
11009 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000011010 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011011 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011012 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011013 E->getMethodDecl(),
11014 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011015 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011016 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000011017}
11018
Mike Stump11289f42009-09-09 15:08:12 +000011019template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011020ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011021TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011022 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011023}
11024
Mike Stump11289f42009-09-09 15:08:12 +000011025template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011026ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011027TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011028 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011029}
11030
Mike Stump11289f42009-09-09 15:08:12 +000011031template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011032ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011033TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000011034 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011035 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000011036 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011037 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000011038
11039 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000011040
Douglas Gregord51d90d2010-04-26 20:11:03 +000011041 // If nothing changed, just retain the existing expression.
11042 if (!getDerived().AlwaysRebuild() &&
11043 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011044 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011045
John McCallb268a282010-08-23 23:25:46 +000011046 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000011047 E->getLocation(),
11048 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000011049}
11050
Mike Stump11289f42009-09-09 15:08:12 +000011051template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011052ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011053TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000011054 // 'super' and types never change. Property never changes. Just
11055 // retain the existing expression.
11056 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011057 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011058
Douglas Gregor9faee212010-04-26 20:47:02 +000011059 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011060 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000011061 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011062 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011063
Douglas Gregor9faee212010-04-26 20:47:02 +000011064 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000011065
Douglas Gregor9faee212010-04-26 20:47:02 +000011066 // If nothing changed, just retain the existing expression.
11067 if (!getDerived().AlwaysRebuild() &&
11068 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011069 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011070
John McCallb7bd14f2010-12-02 01:19:52 +000011071 if (E->isExplicitProperty())
11072 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
11073 E->getExplicitProperty(),
11074 E->getLocation());
11075
11076 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000011077 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000011078 E->getImplicitPropertyGetter(),
11079 E->getImplicitPropertySetter(),
11080 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000011081}
11082
Mike Stump11289f42009-09-09 15:08:12 +000011083template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011084ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000011085TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
11086 // Transform the base expression.
11087 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
11088 if (Base.isInvalid())
11089 return ExprError();
11090
11091 // Transform the key expression.
11092 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
11093 if (Key.isInvalid())
11094 return ExprError();
11095
11096 // If nothing changed, just retain the existing expression.
11097 if (!getDerived().AlwaysRebuild() &&
11098 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011099 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011100
Chad Rosier1dcde962012-08-08 18:46:20 +000011101 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000011102 Base.get(), Key.get(),
11103 E->getAtIndexMethodDecl(),
11104 E->setAtIndexMethodDecl());
11105}
11106
11107template<typename Derived>
11108ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011109TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000011110 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011111 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000011112 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011113 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011114
Douglas Gregord51d90d2010-04-26 20:11:03 +000011115 // If nothing changed, just retain the existing expression.
11116 if (!getDerived().AlwaysRebuild() &&
11117 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011118 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011119
John McCallb268a282010-08-23 23:25:46 +000011120 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000011121 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000011122 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000011123}
11124
Mike Stump11289f42009-09-09 15:08:12 +000011125template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011126ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011127TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011128 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011129 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000011130 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000011131 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000011132 SubExprs, &ArgumentChanged))
11133 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011134
Douglas Gregora16548e2009-08-11 05:31:07 +000011135 if (!getDerived().AlwaysRebuild() &&
11136 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011137 return E;
Mike Stump11289f42009-09-09 15:08:12 +000011138
Douglas Gregora16548e2009-08-11 05:31:07 +000011139 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011140 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000011141 E->getRParenLoc());
11142}
11143
Mike Stump11289f42009-09-09 15:08:12 +000011144template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011145ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000011146TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
11147 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
11148 if (SrcExpr.isInvalid())
11149 return ExprError();
11150
11151 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
11152 if (!Type)
11153 return ExprError();
11154
11155 if (!getDerived().AlwaysRebuild() &&
11156 Type == E->getTypeSourceInfo() &&
11157 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011158 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000011159
11160 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
11161 SrcExpr.get(), Type,
11162 E->getRParenLoc());
11163}
11164
11165template<typename Derived>
11166ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011167TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000011168 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000011169
Craig Topperc3ec1492014-05-26 06:22:03 +000011170 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000011171 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
11172
11173 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000011174 blockScope->TheDecl->setBlockMissingReturnType(
11175 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000011176
Chris Lattner01cf8db2011-07-20 06:58:45 +000011177 SmallVector<ParmVarDecl*, 4> params;
11178 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000011179
John McCallc8e321d2016-03-01 02:09:25 +000011180 const FunctionProtoType *exprFunctionType = E->getFunctionType();
11181
Fariborz Jahanian1babe772010-07-09 18:44:02 +000011182 // Parameter substitution.
John McCallc8e321d2016-03-01 02:09:25 +000011183 Sema::ExtParameterInfoBuilder extParamInfos;
John McCall490112f2011-02-04 18:33:18 +000011184 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
11185 oldBlock->param_begin(),
11186 oldBlock->param_size(),
John McCallc8e321d2016-03-01 02:09:25 +000011187 nullptr,
11188 exprFunctionType->getExtParameterInfosOrNull(),
11189 paramTypes, &params,
11190 extParamInfos)) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011191 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011192 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011193 }
John McCall490112f2011-02-04 18:33:18 +000011194
Eli Friedman34b49062012-01-26 03:00:14 +000011195 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000011196 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000011197
John McCallc8e321d2016-03-01 02:09:25 +000011198 auto epi = exprFunctionType->getExtProtoInfo();
11199 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
11200
Jordan Rose5c382722013-03-08 21:51:21 +000011201 QualType functionType =
John McCallc8e321d2016-03-01 02:09:25 +000011202 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
John McCall490112f2011-02-04 18:33:18 +000011203 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000011204
11205 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000011206 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000011207 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000011208
11209 if (!oldBlock->blockMissingReturnType()) {
11210 blockScope->HasImplicitReturnType = false;
11211 blockScope->ReturnType = exprResultType;
11212 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011213
John McCall3882ace2011-01-05 12:14:39 +000011214 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000011215 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011216 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011217 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000011218 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011219 }
John McCall3882ace2011-01-05 12:14:39 +000011220
John McCall490112f2011-02-04 18:33:18 +000011221#ifndef NDEBUG
11222 // In builds with assertions, make sure that we captured everything we
11223 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011224 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000011225 for (const auto &I : oldBlock->captures()) {
11226 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000011227
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011228 // Ignore parameter packs.
11229 if (isa<ParmVarDecl>(oldCapture) &&
11230 cast<ParmVarDecl>(oldCapture)->isParameterPack())
11231 continue;
John McCall490112f2011-02-04 18:33:18 +000011232
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011233 VarDecl *newCapture =
11234 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
11235 oldCapture));
11236 assert(blockScope->CaptureMap.count(newCapture));
11237 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000011238 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000011239 }
11240#endif
11241
11242 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000011243 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000011244}
11245
Mike Stump11289f42009-09-09 15:08:12 +000011246template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011247ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000011248TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000011249 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000011250}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000011251
11252template<typename Derived>
11253ExprResult
11254TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011255 QualType RetTy = getDerived().TransformType(E->getType());
11256 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011257 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011258 SubExprs.reserve(E->getNumSubExprs());
11259 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
11260 SubExprs, &ArgumentChanged))
11261 return ExprError();
11262
11263 if (!getDerived().AlwaysRebuild() &&
11264 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011265 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011266
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011267 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011268 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000011269}
Chad Rosier1dcde962012-08-08 18:46:20 +000011270
Douglas Gregora16548e2009-08-11 05:31:07 +000011271//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000011272// Type reconstruction
11273//===----------------------------------------------------------------------===//
11274
Mike Stump11289f42009-09-09 15:08:12 +000011275template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000011276QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
11277 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000011278 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011279 getDerived().getBaseEntity());
11280}
11281
Mike Stump11289f42009-09-09 15:08:12 +000011282template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000011283QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
11284 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000011285 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011286 getDerived().getBaseEntity());
11287}
11288
Mike Stump11289f42009-09-09 15:08:12 +000011289template<typename Derived>
11290QualType
John McCall70dd5f62009-10-30 00:06:24 +000011291TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
11292 bool WrittenAsLValue,
11293 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000011294 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000011295 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011296}
11297
11298template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011299QualType
John McCall70dd5f62009-10-30 00:06:24 +000011300TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
11301 QualType ClassType,
11302 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000011303 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
11304 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011305}
11306
11307template<typename Derived>
Douglas Gregor9bda6cf2015-07-07 03:58:14 +000011308QualType TreeTransform<Derived>::RebuildObjCObjectType(
11309 QualType BaseType,
11310 SourceLocation Loc,
11311 SourceLocation TypeArgsLAngleLoc,
11312 ArrayRef<TypeSourceInfo *> TypeArgs,
11313 SourceLocation TypeArgsRAngleLoc,
11314 SourceLocation ProtocolLAngleLoc,
11315 ArrayRef<ObjCProtocolDecl *> Protocols,
11316 ArrayRef<SourceLocation> ProtocolLocs,
11317 SourceLocation ProtocolRAngleLoc) {
11318 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
11319 TypeArgs, TypeArgsRAngleLoc,
11320 ProtocolLAngleLoc, Protocols, ProtocolLocs,
11321 ProtocolRAngleLoc,
11322 /*FailOnError=*/true);
11323}
11324
11325template<typename Derived>
11326QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
11327 QualType PointeeType,
11328 SourceLocation Star) {
11329 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
11330}
11331
11332template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011333QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000011334TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
11335 ArrayType::ArraySizeModifier SizeMod,
11336 const llvm::APInt *Size,
11337 Expr *SizeExpr,
11338 unsigned IndexTypeQuals,
11339 SourceRange BracketsRange) {
11340 if (SizeExpr || !Size)
11341 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
11342 IndexTypeQuals, BracketsRange,
11343 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000011344
11345 QualType Types[] = {
11346 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
11347 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
11348 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000011349 };
Craig Toppere5ce8312013-07-15 03:38:40 +000011350 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011351 QualType SizeType;
11352 for (unsigned I = 0; I != NumTypes; ++I)
11353 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
11354 SizeType = Types[I];
11355 break;
11356 }
Mike Stump11289f42009-09-09 15:08:12 +000011357
Eli Friedman9562f392012-01-25 23:20:27 +000011358 // Note that we can return a VariableArrayType here in the case where
11359 // the element type was a dependent VariableArrayType.
11360 IntegerLiteral *ArraySize
11361 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
11362 /*FIXME*/BracketsRange.getBegin());
11363 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011364 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000011365 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011366}
Mike Stump11289f42009-09-09 15:08:12 +000011367
Douglas Gregord6ff3322009-08-04 16:50:30 +000011368template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011369QualType
11370TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011371 ArrayType::ArraySizeModifier SizeMod,
11372 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000011373 unsigned IndexTypeQuals,
11374 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011375 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000011376 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011377}
11378
11379template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011380QualType
Mike Stump11289f42009-09-09 15:08:12 +000011381TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011382 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000011383 unsigned IndexTypeQuals,
11384 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011385 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000011386 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011387}
Mike Stump11289f42009-09-09 15:08:12 +000011388
Douglas Gregord6ff3322009-08-04 16:50:30 +000011389template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011390QualType
11391TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011392 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000011393 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011394 unsigned IndexTypeQuals,
11395 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011396 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000011397 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011398 IndexTypeQuals, BracketsRange);
11399}
11400
11401template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011402QualType
11403TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011404 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000011405 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011406 unsigned IndexTypeQuals,
11407 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011408 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000011409 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011410 IndexTypeQuals, BracketsRange);
11411}
11412
11413template<typename Derived>
11414QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +000011415 unsigned NumElements,
11416 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000011417 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000011418 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011419}
Mike Stump11289f42009-09-09 15:08:12 +000011420
Douglas Gregord6ff3322009-08-04 16:50:30 +000011421template<typename Derived>
11422QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
11423 unsigned NumElements,
11424 SourceLocation AttributeLoc) {
11425 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
11426 NumElements, true);
11427 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000011428 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
11429 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000011430 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011431}
Mike Stump11289f42009-09-09 15:08:12 +000011432
Douglas Gregord6ff3322009-08-04 16:50:30 +000011433template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011434QualType
11435TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000011436 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011437 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000011438 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011439}
Mike Stump11289f42009-09-09 15:08:12 +000011440
Douglas Gregord6ff3322009-08-04 16:50:30 +000011441template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000011442QualType TreeTransform<Derived>::RebuildFunctionProtoType(
11443 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000011444 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000011445 const FunctionProtoType::ExtProtoInfo &EPI) {
11446 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011447 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000011448 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000011449 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011450}
Mike Stump11289f42009-09-09 15:08:12 +000011451
Douglas Gregord6ff3322009-08-04 16:50:30 +000011452template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000011453QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
11454 return SemaRef.Context.getFunctionNoProtoType(T);
11455}
11456
11457template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +000011458QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
11459 assert(D && "no decl found");
11460 if (D->isInvalidDecl()) return QualType();
11461
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011462 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000011463 TypeDecl *Ty;
11464 if (isa<UsingDecl>(D)) {
11465 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000011466 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000011467 "UnresolvedUsingTypenameDecl transformed to non-typename using");
11468
11469 // A valid resolved using typename decl points to exactly one type decl.
11470 assert(++Using->shadow_begin() == Using->shadow_end());
11471 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000011472
John McCallb96ec562009-12-04 22:46:56 +000011473 } else {
11474 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
11475 "UnresolvedUsingTypenameDecl transformed to non-using decl");
11476 Ty = cast<UnresolvedUsingTypenameDecl>(D);
11477 }
11478
11479 return SemaRef.Context.getTypeDeclType(Ty);
11480}
11481
11482template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000011483QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
11484 SourceLocation Loc) {
11485 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011486}
11487
11488template<typename Derived>
11489QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
11490 return SemaRef.Context.getTypeOfType(Underlying);
11491}
11492
11493template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000011494QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
11495 SourceLocation Loc) {
11496 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011497}
11498
11499template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000011500QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
11501 UnaryTransformType::UTTKind UKind,
11502 SourceLocation Loc) {
11503 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
11504}
11505
11506template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000011507QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000011508 TemplateName Template,
11509 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000011510 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000011511 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011512}
Mike Stump11289f42009-09-09 15:08:12 +000011513
Douglas Gregor1135c352009-08-06 05:28:30 +000011514template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000011515QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
11516 SourceLocation KWLoc) {
11517 return SemaRef.BuildAtomicType(ValueType, KWLoc);
11518}
11519
11520template<typename Derived>
Xiuli Pan9c14e282016-01-09 12:53:17 +000011521QualType TreeTransform<Derived>::RebuildPipeType(QualType ValueType,
11522 SourceLocation KWLoc) {
11523 return SemaRef.BuildPipeType(ValueType, KWLoc);
11524}
11525
11526template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011527TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011528TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000011529 bool TemplateKW,
11530 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000011531 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000011532 Template);
11533}
11534
11535template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011536TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011537TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
11538 const IdentifierInfo &Name,
11539 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000011540 QualType ObjectType,
11541 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +000011542 UnqualifiedId TemplateName;
11543 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000011544 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000011545 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000011546 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011547 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000011548 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000011549 /*EnteringContext=*/false,
11550 Template);
John McCall31f82722010-11-12 08:19:04 +000011551 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000011552}
Mike Stump11289f42009-09-09 15:08:12 +000011553
Douglas Gregora16548e2009-08-11 05:31:07 +000011554template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000011555TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011556TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000011557 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000011558 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000011559 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000011560 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000011561 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000011562 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000011563 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000011564 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000011565 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000011566 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011567 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000011568 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000011569 /*EnteringContext=*/false,
11570 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000011571 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000011572}
Chad Rosier1dcde962012-08-08 18:46:20 +000011573
Douglas Gregor71395fa2009-11-04 00:56:37 +000011574template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011575ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000011576TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
11577 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000011578 Expr *OrigCallee,
11579 Expr *First,
11580 Expr *Second) {
11581 Expr *Callee = OrigCallee->IgnoreParenCasts();
11582 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000011583
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000011584 if (First->getObjectKind() == OK_ObjCProperty) {
11585 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
11586 if (BinaryOperator::isAssignmentOp(Opc))
11587 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
11588 First, Second);
11589 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
11590 if (Result.isInvalid())
11591 return ExprError();
11592 First = Result.get();
11593 }
11594
11595 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
11596 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
11597 if (Result.isInvalid())
11598 return ExprError();
11599 Second = Result.get();
11600 }
11601
Douglas Gregora16548e2009-08-11 05:31:07 +000011602 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000011603 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000011604 if (!First->getType()->isOverloadableType() &&
11605 !Second->getType()->isOverloadableType())
11606 return getSema().CreateBuiltinArraySubscriptExpr(First,
11607 Callee->getLocStart(),
11608 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000011609 } else if (Op == OO_Arrow) {
11610 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000011611 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
11612 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000011613 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011614 // The argument is not of overloadable type, so try to create a
11615 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000011616 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011617 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000011618
John McCallb268a282010-08-23 23:25:46 +000011619 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011620 }
11621 } else {
John McCallb268a282010-08-23 23:25:46 +000011622 if (!First->getType()->isOverloadableType() &&
11623 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011624 // Neither of the arguments is an overloadable type, so try to
11625 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000011626 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011627 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000011628 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000011629 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011630 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011631
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011632 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011633 }
11634 }
Mike Stump11289f42009-09-09 15:08:12 +000011635
11636 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000011637 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000011638 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000011639
John McCallb268a282010-08-23 23:25:46 +000011640 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000011641 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000011642 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000011643 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000011644 // If we've resolved this to a particular non-member function, just call
11645 // that function. If we resolved it to a member function,
11646 // CreateOverloaded* will find that function for us.
11647 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
11648 if (!isa<CXXMethodDecl>(ND))
11649 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000011650 }
Mike Stump11289f42009-09-09 15:08:12 +000011651
Douglas Gregora16548e2009-08-11 05:31:07 +000011652 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000011653 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000011654 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000011655
Douglas Gregora16548e2009-08-11 05:31:07 +000011656 // Create the overloaded operator invocation for unary operators.
11657 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000011658 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011659 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000011660 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011661 }
Mike Stump11289f42009-09-09 15:08:12 +000011662
Douglas Gregore9d62932011-07-15 16:25:15 +000011663 if (Op == OO_Subscript) {
11664 SourceLocation LBrace;
11665 SourceLocation RBrace;
11666
11667 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000011668 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000011669 LBrace = SourceLocation::getFromRawEncoding(
11670 NameLoc.CXXOperatorName.BeginOpNameLoc);
11671 RBrace = SourceLocation::getFromRawEncoding(
11672 NameLoc.CXXOperatorName.EndOpNameLoc);
11673 } else {
11674 LBrace = Callee->getLocStart();
11675 RBrace = OpLoc;
11676 }
11677
11678 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
11679 First, Second);
11680 }
Sebastian Redladba46e2009-10-29 20:17:01 +000011681
Douglas Gregora16548e2009-08-11 05:31:07 +000011682 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000011683 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011684 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000011685 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
11686 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011687 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011688
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011689 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011690}
Mike Stump11289f42009-09-09 15:08:12 +000011691
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011692template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000011693ExprResult
John McCallb268a282010-08-23 23:25:46 +000011694TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011695 SourceLocation OperatorLoc,
11696 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000011697 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011698 TypeSourceInfo *ScopeType,
11699 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000011700 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000011701 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000011702 QualType BaseType = Base->getType();
11703 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011704 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000011705 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000011706 !BaseType->getAs<PointerType>()->getPointeeType()
11707 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011708 // This pseudo-destructor expression is still a pseudo-destructor.
David Majnemerced8bdf2015-02-25 17:36:15 +000011709 return SemaRef.BuildPseudoDestructorExpr(
11710 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
11711 CCLoc, TildeLoc, Destroyed);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011712 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011713
Douglas Gregor678f90d2010-02-25 01:56:36 +000011714 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011715 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
11716 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
11717 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
11718 NameInfo.setNamedTypeInfo(DestroyedType);
11719
Richard Smith8e4a3862012-05-15 06:15:11 +000011720 // The scope type is now known to be a valid nested name specifier
11721 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000011722 if (ScopeType) {
11723 if (!ScopeType->getType()->getAs<TagType>()) {
11724 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
11725 diag::err_expected_class_or_namespace)
11726 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
11727 return ExprError();
11728 }
11729 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
11730 CCLoc);
11731 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011732
Abramo Bagnara7945c982012-01-27 09:46:47 +000011733 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000011734 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011735 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011736 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000011737 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011738 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +000011739 /*TemplateArgs*/ nullptr,
11740 /*S*/nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011741}
11742
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000011743template<typename Derived>
11744StmtResult
11745TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000011746 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000011747 CapturedDecl *CD = S->getCapturedDecl();
11748 unsigned NumParams = CD->getNumParams();
11749 unsigned ContextParamPos = CD->getContextParamPosition();
11750 SmallVector<Sema::CapturedParamNameType, 4> Params;
11751 for (unsigned I = 0; I < NumParams; ++I) {
11752 if (I != ContextParamPos) {
11753 Params.push_back(
11754 std::make_pair(
11755 CD->getParam(I)->getName(),
11756 getDerived().TransformType(CD->getParam(I)->getType())));
11757 } else {
11758 Params.push_back(std::make_pair(StringRef(), QualType()));
11759 }
11760 }
Craig Topperc3ec1492014-05-26 06:22:03 +000011761 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000011762 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000011763 StmtResult Body;
11764 {
11765 Sema::CompoundScopeRAII CompoundScope(getSema());
11766 Body = getDerived().TransformStmt(S->getCapturedStmt());
11767 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000011768
11769 if (Body.isInvalid()) {
11770 getSema().ActOnCapturedRegionError();
11771 return StmtError();
11772 }
11773
Nikola Smiljanic01a75982014-05-29 10:55:11 +000011774 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000011775}
11776
Douglas Gregord6ff3322009-08-04 16:50:30 +000011777} // end namespace clang
11778
Hans Wennborg59dbe862015-09-29 20:56:43 +000011779#endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H