blob: 88acc20600aada3c50ecaf03b188dc6242ae4bdb [file] [log] [blame]
Chris Lattnercab02a62011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnercab02a62011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00008//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
Chris Lattnercab02a62011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000014#ifndef LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
Douglas Gregord6ff3322009-08-04 16:50:30 +000016
Chandler Carruth3a022472012-12-04 09:13:33 +000017#include "TypeLocBuilder.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000018#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000019#include "clang/AST/DeclObjC.h"
Richard Smith3f1b5d02011-05-05 21:57:07 +000020#include "clang/AST/DeclTemplate.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000021#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000022#include "clang/AST/ExprCXX.h"
23#include "clang/AST/ExprObjC.h"
Alexey Bataev1a3320e2015-08-25 14:24:04 +000024#include "clang/AST/ExprOpenMP.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000025#include "clang/AST/Stmt.h"
26#include "clang/AST/StmtCXX.h"
27#include "clang/AST/StmtObjC.h"
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000028#include "clang/AST/StmtOpenMP.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000029#include "clang/Sema/Designator.h"
30#include "clang/Sema/Lookup.h"
31#include "clang/Sema/Ownership.h"
32#include "clang/Sema/ParsedTemplate.h"
33#include "clang/Sema/ScopeInfo.h"
34#include "clang/Sema/SemaDiagnostic.h"
35#include "clang/Sema/SemaInternal.h"
David Blaikieb9c168a2011-09-22 02:34:54 +000036#include "llvm/ADT/ArrayRef.h"
John McCall550e0c22009-10-21 00:40:46 +000037#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000038#include <algorithm>
39
40namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000041using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000042
Douglas Gregord6ff3322009-08-04 16:50:30 +000043/// \brief A semantic tree transformation that allows one to transform one
44/// abstract syntax tree into another.
45///
Mike Stump11289f42009-09-09 15:08:12 +000046/// A new tree transformation is defined by creating a new subclass \c X of
47/// \c TreeTransform<X> and then overriding certain operations to provide
48/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000049/// instantiation is implemented as a tree transformation where the
50/// transformation of TemplateTypeParmType nodes involves substituting the
51/// template arguments for their corresponding template parameters; a similar
52/// transformation is performed for non-type template parameters and
53/// template template parameters.
54///
55/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000056/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000057/// override any of the transformation or rebuild operators by providing an
58/// operation with the same signature as the default implementation. The
59/// overridding function should not be virtual.
60///
61/// Semantic tree transformations are split into two stages, either of which
62/// can be replaced by a subclass. The "transform" step transforms an AST node
63/// or the parts of an AST node using the various transformation functions,
64/// then passes the pieces on to the "rebuild" step, which constructs a new AST
65/// node of the appropriate kind from the pieces. The default transformation
66/// routines recursively transform the operands to composite AST nodes (e.g.,
67/// the pointee type of a PointerType node) and, if any of those operand nodes
68/// were changed by the transformation, invokes the rebuild operation to create
69/// a new AST node.
70///
Mike Stump11289f42009-09-09 15:08:12 +000071/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000072/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregorfd35cde2011-03-02 18:50:38 +000073/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000074/// TransformTemplateName(), or TransformTemplateArgument() with entirely
75/// new implementations.
76///
77/// For more fine-grained transformations, subclasses can replace any of the
78/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000079/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000080/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000081/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000082/// parameters. Additionally, subclasses can override the \c RebuildXXX
83/// functions to control how AST nodes are rebuilt when their operands change.
84/// By default, \c TreeTransform will invoke semantic analysis to rebuild
85/// AST nodes. However, certain other tree transformations (e.g, cloning) may
86/// be able to use more efficient rebuild steps.
87///
88/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000089/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000090/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
91/// operands have not changed (\c AlwaysRebuild()), and customize the
92/// default locations and entity names used for type-checking
93/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000094template<typename Derived>
95class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000096 /// \brief Private RAII object that helps us forget and then re-remember
97 /// the template argument corresponding to a partially-substituted parameter
98 /// pack.
99 class ForgetPartiallySubstitutedPackRAII {
100 Derived &Self;
101 TemplateArgument Old;
Chad Rosier1dcde962012-08-08 18:46:20 +0000102
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000103 public:
104 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
105 Old = Self.ForgetPartiallySubstitutedPack();
106 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000107
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000108 ~ForgetPartiallySubstitutedPackRAII() {
109 Self.RememberPartiallySubstitutedPack(Old);
110 }
111 };
Chad Rosier1dcde962012-08-08 18:46:20 +0000112
Douglas Gregord6ff3322009-08-04 16:50:30 +0000113protected:
114 Sema &SemaRef;
Chad Rosier1dcde962012-08-08 18:46:20 +0000115
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000116 /// \brief The set of local declarations that have been transformed, for
117 /// cases where we are forced to build new declarations within the transformer
118 /// rather than in the subclass (e.g., lambda closure types).
119 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
Chad Rosier1dcde962012-08-08 18:46:20 +0000120
Mike Stump11289f42009-09-09 15:08:12 +0000121public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000122 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000123 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000124
Douglas Gregord6ff3322009-08-04 16:50:30 +0000125 /// \brief Retrieves a reference to the derived class.
126 Derived &getDerived() { return static_cast<Derived&>(*this); }
127
128 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000129 const Derived &getDerived() const {
130 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000131 }
132
John McCalldadc5752010-08-24 06:29:42 +0000133 static inline ExprResult Owned(Expr *E) { return E; }
134 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000135
Douglas Gregord6ff3322009-08-04 16:50:30 +0000136 /// \brief Retrieves a reference to the semantic analysis object used for
137 /// this tree transform.
138 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000139
Douglas Gregord6ff3322009-08-04 16:50:30 +0000140 /// \brief Whether the transformation should always rebuild AST nodes, even
141 /// if none of the children have changed.
142 ///
143 /// Subclasses may override this function to specify when the transformation
144 /// should rebuild all AST nodes.
Richard Smith2aa81a72013-11-07 20:07:17 +0000145 ///
146 /// We must always rebuild all AST nodes when performing variadic template
147 /// pack expansion, in order to avoid violating the AST invariant that each
148 /// statement node appears at most once in its containing declaration.
149 bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; }
Mike Stump11289f42009-09-09 15:08:12 +0000150
Douglas Gregord6ff3322009-08-04 16:50:30 +0000151 /// \brief Returns the location of the entity being transformed, if that
152 /// information was not available elsewhere in the AST.
153 ///
Mike Stump11289f42009-09-09 15:08:12 +0000154 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000155 /// provide an alternative implementation that provides better location
156 /// information.
157 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000158
Douglas Gregord6ff3322009-08-04 16:50:30 +0000159 /// \brief Returns the name of the entity being transformed, if that
160 /// information was not available elsewhere in the AST.
161 ///
162 /// By default, returns an empty name. Subclasses can provide an alternative
163 /// implementation with a more precise name.
164 DeclarationName getBaseEntity() { return DeclarationName(); }
165
Douglas Gregora16548e2009-08-11 05:31:07 +0000166 /// \brief Sets the "base" location and entity when that
167 /// information is known based on another transformation.
168 ///
169 /// By default, the source location and entity are ignored. Subclasses can
170 /// override this function to provide a customized implementation.
171 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000172
Douglas Gregora16548e2009-08-11 05:31:07 +0000173 /// \brief RAII object that temporarily sets the base location and entity
174 /// used for reporting diagnostics in types.
175 class TemporaryBase {
176 TreeTransform &Self;
177 SourceLocation OldLocation;
178 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000179
Douglas Gregora16548e2009-08-11 05:31:07 +0000180 public:
181 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000182 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000183 OldLocation = Self.getDerived().getBaseLocation();
184 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier1dcde962012-08-08 18:46:20 +0000185
Douglas Gregora518d5b2011-01-25 17:51:48 +0000186 if (Location.isValid())
187 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000188 }
Mike Stump11289f42009-09-09 15:08:12 +0000189
Douglas Gregora16548e2009-08-11 05:31:07 +0000190 ~TemporaryBase() {
191 Self.getDerived().setBase(OldLocation, OldEntity);
192 }
193 };
Mike Stump11289f42009-09-09 15:08:12 +0000194
195 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000196 /// transformed.
197 ///
198 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000199 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000200 /// not change. For example, template instantiation need not traverse
201 /// non-dependent types.
202 bool AlreadyTransformed(QualType T) {
203 return T.isNull();
204 }
205
Douglas Gregord196a582009-12-14 19:27:10 +0000206 /// \brief Determine whether the given call argument should be dropped, e.g.,
207 /// because it is a default argument.
208 ///
209 /// Subclasses can provide an alternative implementation of this routine to
210 /// determine which kinds of call arguments get dropped. By default,
211 /// CXXDefaultArgument nodes are dropped (prior to transformation).
212 bool DropCallArgument(Expr *E) {
213 return E->isDefaultArgument();
214 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000215
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000216 /// \brief Determine whether we should expand a pack expansion with the
217 /// given set of parameter packs into separate arguments by repeatedly
218 /// transforming the pattern.
219 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000220 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000221 /// Subclasses can override this routine to provide different behavior.
222 ///
223 /// \param EllipsisLoc The location of the ellipsis that identifies the
224 /// pack expansion.
225 ///
226 /// \param PatternRange The source range that covers the entire pattern of
227 /// the pack expansion.
228 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000229 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000230 /// pattern.
231 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000232 /// \param ShouldExpand Will be set to \c true if the transformer should
233 /// expand the corresponding pack expansions into separate arguments. When
234 /// set, \c NumExpansions must also be set.
235 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000236 /// \param RetainExpansion Whether the caller should add an unexpanded
237 /// pack expansion after all of the expanded arguments. This is used
238 /// when extending explicitly-specified template argument packs per
239 /// C++0x [temp.arg.explicit]p9.
240 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000241 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000242 /// the expanded form of the corresponding pack expansion. This is both an
243 /// input and an output parameter, which can be set by the caller if the
244 /// number of expansions is known a priori (e.g., due to a prior substitution)
245 /// and will be set by the callee when the number of expansions is known.
246 /// The callee must set this value when \c ShouldExpand is \c true; it may
247 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000248 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000249 /// \returns true if an error occurred (e.g., because the parameter packs
250 /// are to be instantiated with arguments of different lengths), false
251 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000252 /// must be set.
253 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
254 SourceRange PatternRange,
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000255 ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000256 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000257 bool &RetainExpansion,
David Blaikie05785d12013-02-20 22:23:23 +0000258 Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000259 ShouldExpand = false;
260 return false;
261 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000262
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000263 /// \brief "Forget" about the partially-substituted pack template argument,
264 /// when performing an instantiation that must preserve the parameter pack
265 /// use.
266 ///
267 /// This routine is meant to be overridden by the template instantiator.
268 TemplateArgument ForgetPartiallySubstitutedPack() {
269 return TemplateArgument();
270 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000271
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000272 /// \brief "Remember" the partially-substituted pack template argument
273 /// after performing an instantiation that must preserve the parameter pack
274 /// use.
275 ///
276 /// This routine is meant to be overridden by the template instantiator.
277 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000278
Douglas Gregorf3010112011-01-07 16:43:16 +0000279 /// \brief Note to the derived class when a function parameter pack is
280 /// being expanded.
281 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000282
Douglas Gregord6ff3322009-08-04 16:50:30 +0000283 /// \brief Transforms the given type into another type.
284 ///
John McCall550e0c22009-10-21 00:40:46 +0000285 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000286 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000287 /// function. This is expensive, but we don't mind, because
288 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000289 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000290 ///
291 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000292 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000293
John McCall550e0c22009-10-21 00:40:46 +0000294 /// \brief Transforms the given type-with-location into a new
295 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000296 ///
John McCall550e0c22009-10-21 00:40:46 +0000297 /// By default, this routine transforms a type by delegating to the
298 /// appropriate TransformXXXType to build a new type. Subclasses
299 /// may override this function (to take over all type
300 /// transformations) or some set of the TransformXXXType functions
301 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000302 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000303
304 /// \brief Transform the given type-with-location into a new
305 /// type, collecting location information in the given builder
306 /// as necessary.
307 ///
John McCall31f82722010-11-12 08:19:04 +0000308 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000309
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000310 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000311 ///
Mike Stump11289f42009-09-09 15:08:12 +0000312 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000313 /// appropriate TransformXXXStmt function to transform a specific kind of
314 /// statement or the TransformExpr() function to transform an expression.
315 /// Subclasses may override this function to transform statements using some
316 /// other mechanism.
317 ///
318 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000319 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000320
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000321 /// \brief Transform the given statement.
322 ///
323 /// By default, this routine transforms a statement by delegating to the
324 /// appropriate TransformOMPXXXClause function to transform a specific kind
325 /// of clause. Subclasses may override this function to transform statements
326 /// using some other mechanism.
327 ///
328 /// \returns the transformed OpenMP clause.
329 OMPClause *TransformOMPClause(OMPClause *S);
330
Tyler Nowickic724a83e2014-10-12 20:46:07 +0000331 /// \brief Transform the given attribute.
332 ///
333 /// By default, this routine transforms a statement by delegating to the
334 /// appropriate TransformXXXAttr function to transform a specific kind
335 /// of attribute. Subclasses may override this function to transform
336 /// attributed statements using some other mechanism.
337 ///
338 /// \returns the transformed attribute
339 const Attr *TransformAttr(const Attr *S);
340
341/// \brief Transform the specified attribute.
342///
343/// Subclasses should override the transformation of attributes with a pragma
344/// spelling to transform expressions stored within the attribute.
345///
346/// \returns the transformed attribute.
347#define ATTR(X)
348#define PRAGMA_SPELLING_ATTR(X) \
349 const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; }
350#include "clang/Basic/AttrList.inc"
351
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000352 /// \brief Transform the given expression.
353 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000354 /// By default, this routine transforms an expression by delegating to the
355 /// appropriate TransformXXXExpr function to build a new expression.
356 /// Subclasses may override this function to transform expressions using some
357 /// other mechanism.
358 ///
359 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000360 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000361
Richard Smithd59b8322012-12-19 01:39:02 +0000362 /// \brief Transform the given initializer.
363 ///
364 /// By default, this routine transforms an initializer by stripping off the
365 /// semantic nodes added by initialization, then passing the result to
366 /// TransformExpr or TransformExprs.
367 ///
368 /// \returns the transformed initializer.
Richard Smithc6abd962014-07-25 01:12:44 +0000369 ExprResult TransformInitializer(Expr *Init, bool NotCopyInit);
Richard Smithd59b8322012-12-19 01:39:02 +0000370
Douglas Gregora3efea12011-01-03 19:04:46 +0000371 /// \brief Transform the given list of expressions.
372 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000373 /// This routine transforms a list of expressions by invoking
374 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregora3efea12011-01-03 19:04:46 +0000375 /// support for variadic templates by expanding any pack expansions (if the
376 /// derived class permits such expansion) along the way. When pack expansions
377 /// are present, the number of outputs may not equal the number of inputs.
378 ///
379 /// \param Inputs The set of expressions to be transformed.
380 ///
381 /// \param NumInputs The number of expressions in \c Inputs.
382 ///
383 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier1dcde962012-08-08 18:46:20 +0000384 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregora3efea12011-01-03 19:04:46 +0000385 /// be.
386 ///
387 /// \param Outputs The transformed input expressions will be added to this
388 /// vector.
389 ///
390 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
391 /// due to transformation.
392 ///
393 /// \returns true if an error occurred, false otherwise.
Craig Topper99d23532015-12-24 23:58:29 +0000394 bool TransformExprs(Expr *const *Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000395 SmallVectorImpl<Expr *> &Outputs,
Craig Topperc3ec1492014-05-26 06:22:03 +0000396 bool *ArgChanged = nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000397
Douglas Gregord6ff3322009-08-04 16:50:30 +0000398 /// \brief Transform the given declaration, which is referenced from a type
399 /// or expression.
400 ///
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000401 /// By default, acts as the identity function on declarations, unless the
402 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregor1135c352009-08-06 05:28:30 +0000403 /// may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000404 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000405 llvm::DenseMap<Decl *, Decl *>::iterator Known
406 = TransformedLocalDecls.find(D);
407 if (Known != TransformedLocalDecls.end())
408 return Known->second;
Chad Rosier1dcde962012-08-08 18:46:20 +0000409
410 return D;
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000411 }
Douglas Gregorebe10102009-08-20 07:17:43 +0000412
Richard Smith03a4aa32016-06-23 19:02:52 +0000413 /// \brief Transform the specified condition.
414 ///
415 /// By default, this transforms the variable and expression and rebuilds
416 /// the condition.
417 Sema::ConditionResult TransformCondition(SourceLocation Loc, VarDecl *Var,
418 Expr *Expr,
419 Sema::ConditionKind Kind);
420
Chad Rosier1dcde962012-08-08 18:46:20 +0000421 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000422 /// place them on the new declaration.
423 ///
424 /// By default, this operation does nothing. Subclasses may override this
425 /// behavior to transform attributes.
426 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000427
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000428 /// \brief Note that a local declaration has been transformed by this
429 /// transformer.
430 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000431 /// Local declarations are typically transformed via a call to
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000432 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
433 /// the transformer itself has to transform the declarations. This routine
434 /// can be overridden by a subclass that keeps track of such mappings.
435 void transformedLocalDecl(Decl *Old, Decl *New) {
436 TransformedLocalDecls[Old] = New;
437 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000438
Douglas Gregorebe10102009-08-20 07:17:43 +0000439 /// \brief Transform the definition of the given declaration.
440 ///
Mike Stump11289f42009-09-09 15:08:12 +0000441 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000442 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000443 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
444 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000445 }
Mike Stump11289f42009-09-09 15:08:12 +0000446
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000447 /// \brief Transform the given declaration, which was the first part of a
448 /// nested-name-specifier in a member access expression.
449 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000450 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000451 /// identifier in a nested-name-specifier of a member access expression, e.g.,
452 /// the \c T in \c x->T::member
453 ///
454 /// By default, invokes TransformDecl() to transform the declaration.
455 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000456 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
457 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000458 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000459
Douglas Gregor14454802011-02-25 02:25:35 +0000460 /// \brief Transform the given nested-name-specifier with source-location
461 /// information.
462 ///
463 /// By default, transforms all of the types and declarations within the
464 /// nested-name-specifier. Subclasses may override this function to provide
465 /// alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000466 NestedNameSpecifierLoc
467 TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
468 QualType ObjectType = QualType(),
469 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor14454802011-02-25 02:25:35 +0000470
Douglas Gregorf816bd72009-09-03 22:13:48 +0000471 /// \brief Transform the given declaration name.
472 ///
473 /// By default, transforms the types of conversion function, constructor,
474 /// and destructor names and then (if needed) rebuilds the declaration name.
475 /// Identifiers and selectors are returned unmodified. Sublcasses may
476 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000477 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000478 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000479
Douglas Gregord6ff3322009-08-04 16:50:30 +0000480 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000481 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000482 /// \param SS The nested-name-specifier that qualifies the template
483 /// name. This nested-name-specifier must already have been transformed.
484 ///
485 /// \param Name The template name to transform.
486 ///
487 /// \param NameLoc The source location of the template name.
488 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000489 /// \param ObjectType If we're translating a template name within a member
Douglas Gregor9db53502011-03-02 18:07:45 +0000490 /// access expression, this is the type of the object whose member template
491 /// is being referenced.
492 ///
493 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
494 /// also refers to a name within the current (lexical) scope, this is the
495 /// declaration it refers to.
496 ///
497 /// By default, transforms the template name by transforming the declarations
498 /// and nested-name-specifiers that occur within the template name.
499 /// Subclasses may override this function to provide alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000500 TemplateName
501 TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
502 SourceLocation NameLoc,
503 QualType ObjectType = QualType(),
504 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor9db53502011-03-02 18:07:45 +0000505
Douglas Gregord6ff3322009-08-04 16:50:30 +0000506 /// \brief Transform the given template argument.
507 ///
Mike Stump11289f42009-09-09 15:08:12 +0000508 /// By default, this operation transforms the type, expression, or
509 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000510 /// new template argument from the transformed result. Subclasses may
511 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000512 ///
513 /// Returns true if there was an error.
514 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +0000515 TemplateArgumentLoc &Output,
516 bool Uneval = false);
John McCall0ad16662009-10-29 08:12:44 +0000517
Douglas Gregor62e06f22010-12-20 17:31:10 +0000518 /// \brief Transform the given set of template arguments.
519 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000520 /// By default, this operation transforms all of the template arguments
Douglas Gregor62e06f22010-12-20 17:31:10 +0000521 /// in the input set using \c TransformTemplateArgument(), and appends
522 /// the transformed arguments to the output list.
523 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000524 /// Note that this overload of \c TransformTemplateArguments() is merely
525 /// a convenience function. Subclasses that wish to override this behavior
526 /// should override the iterator-based member template version.
527 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000528 /// \param Inputs The set of template arguments to be transformed.
529 ///
530 /// \param NumInputs The number of template arguments in \p Inputs.
531 ///
532 /// \param Outputs The set of transformed template arguments output by this
533 /// routine.
534 ///
535 /// Returns true if an error occurred.
536 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
537 unsigned NumInputs,
Richard Smithd784e682015-09-23 21:41:42 +0000538 TemplateArgumentListInfo &Outputs,
539 bool Uneval = false) {
540 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs,
541 Uneval);
Douglas Gregorfe921a72010-12-20 23:36:19 +0000542 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000543
544 /// \brief Transform the given set of template arguments.
545 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000546 /// By default, this operation transforms all of the template arguments
Douglas Gregor42cafa82010-12-20 17:42:22 +0000547 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier1dcde962012-08-08 18:46:20 +0000548 /// the transformed arguments to the output list.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000549 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000550 /// \param First An iterator to the first template argument.
551 ///
552 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000553 ///
554 /// \param Outputs The set of transformed template arguments output by this
555 /// routine.
556 ///
557 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000558 template<typename InputIterator>
559 bool TransformTemplateArguments(InputIterator First,
560 InputIterator Last,
Richard Smithd784e682015-09-23 21:41:42 +0000561 TemplateArgumentListInfo &Outputs,
562 bool Uneval = false);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000563
John McCall0ad16662009-10-29 08:12:44 +0000564 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
565 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
566 TemplateArgumentLoc &ArgLoc);
567
John McCallbcd03502009-12-07 02:54:59 +0000568 /// \brief Fakes up a TypeSourceInfo for a type.
569 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
570 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000571 getDerived().getBaseLocation());
572 }
Mike Stump11289f42009-09-09 15:08:12 +0000573
John McCall550e0c22009-10-21 00:40:46 +0000574#define ABSTRACT_TYPELOC(CLASS, PARENT)
575#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000576 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000577#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000578
Richard Smith2e321552014-11-12 02:00:47 +0000579 template<typename Fn>
Douglas Gregor3024f072012-04-16 07:05:22 +0000580 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
581 FunctionProtoTypeLoc TL,
582 CXXRecordDecl *ThisContext,
Richard Smith2e321552014-11-12 02:00:47 +0000583 unsigned ThisTypeQuals,
584 Fn TransformExceptionSpec);
585
586 bool TransformExceptionSpec(SourceLocation Loc,
587 FunctionProtoType::ExceptionSpecInfo &ESI,
588 SmallVectorImpl<QualType> &Exceptions,
589 bool &Changed);
Douglas Gregor3024f072012-04-16 07:05:22 +0000590
David Majnemerfad8f482013-10-15 09:33:02 +0000591 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000592
Chad Rosier1dcde962012-08-08 18:46:20 +0000593 QualType
John McCall31f82722010-11-12 08:19:04 +0000594 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
595 TemplateSpecializationTypeLoc TL,
596 TemplateName Template);
597
Chad Rosier1dcde962012-08-08 18:46:20 +0000598 QualType
John McCall31f82722010-11-12 08:19:04 +0000599 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
600 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000601 TemplateName Template,
602 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000603
Nico Weberc153d242014-07-28 00:02:09 +0000604 QualType TransformDependentTemplateSpecializationType(
605 TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL,
606 NestedNameSpecifierLoc QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000607
John McCall58f10c32010-03-11 09:03:00 +0000608 /// \brief Transforms the parameters of a function type into the
609 /// given vectors.
610 ///
611 /// The result vectors should be kept in sync; null entries in the
612 /// variables vector are acceptable.
613 ///
614 /// Return true on error.
David Majnemer59f77922016-06-24 04:05:48 +0000615 bool TransformFunctionTypeParams(
616 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
617 const QualType *ParamTypes,
618 const FunctionProtoType::ExtParameterInfo *ParamInfos,
619 SmallVectorImpl<QualType> &PTypes, SmallVectorImpl<ParmVarDecl *> *PVars,
620 Sema::ExtParameterInfoBuilder &PInfos);
John McCall58f10c32010-03-11 09:03:00 +0000621
622 /// \brief Transforms a single function-type parameter. Return null
623 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000624 ///
625 /// \param indexAdjustment - A number to add to the parameter's
626 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000627 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000628 int indexAdjustment,
David Blaikie05785d12013-02-20 22:23:23 +0000629 Optional<unsigned> NumExpansions,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +0000630 bool ExpectParameterPack);
John McCall58f10c32010-03-11 09:03:00 +0000631
John McCall31f82722010-11-12 08:19:04 +0000632 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000633
John McCalldadc5752010-08-24 06:29:42 +0000634 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
635 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Richard Smith2589b9802012-07-25 03:56:55 +0000636
Faisal Vali2cba1332013-10-23 06:44:28 +0000637 TemplateParameterList *TransformTemplateParameterList(
638 TemplateParameterList *TPL) {
639 return TPL;
640 }
641
Richard Smithdb2630f2012-10-21 03:28:35 +0000642 ExprResult TransformAddressOfOperand(Expr *E);
Reid Kleckner32506ed2014-06-12 23:03:48 +0000643
Richard Smithdb2630f2012-10-21 03:28:35 +0000644 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +0000645 bool IsAddressOfOperand,
646 TypeSourceInfo **RecoveryTSI);
647
648 ExprResult TransformParenDependentScopeDeclRefExpr(
649 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
650 TypeSourceInfo **RecoveryTSI);
651
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000652 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000653
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000654// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
655// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000656#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000657 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000658 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000659#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000660 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000661 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000662#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000663#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000664
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000665#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000666 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000667 OMPClause *Transform ## Class(Class *S);
668#include "clang/Basic/OpenMPKinds.def"
669
Douglas Gregord6ff3322009-08-04 16:50:30 +0000670 /// \brief Build a new pointer type given its pointee type.
671 ///
672 /// By default, performs semantic analysis when building the pointer type.
673 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000674 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000675
676 /// \brief Build a new block pointer type given its pointee type.
677 ///
Mike Stump11289f42009-09-09 15:08:12 +0000678 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000679 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000680 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000681
John McCall70dd5f62009-10-30 00:06:24 +0000682 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000683 ///
John McCall70dd5f62009-10-30 00:06:24 +0000684 /// By default, performs semantic analysis when building the
685 /// reference type. Subclasses may override this routine to provide
686 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000687 ///
John McCall70dd5f62009-10-30 00:06:24 +0000688 /// \param LValue whether the type was written with an lvalue sigil
689 /// or an rvalue sigil.
690 QualType RebuildReferenceType(QualType ReferentType,
691 bool LValue,
692 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000693
Douglas Gregord6ff3322009-08-04 16:50:30 +0000694 /// \brief Build a new member pointer type given the pointee type and the
695 /// class type it refers into.
696 ///
697 /// By default, performs semantic analysis when building the member pointer
698 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000699 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
700 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000701
Douglas Gregor9bda6cf2015-07-07 03:58:14 +0000702 /// \brief Build an Objective-C object type.
703 ///
704 /// By default, performs semantic analysis when building the object type.
705 /// Subclasses may override this routine to provide different behavior.
706 QualType RebuildObjCObjectType(QualType BaseType,
707 SourceLocation Loc,
708 SourceLocation TypeArgsLAngleLoc,
709 ArrayRef<TypeSourceInfo *> TypeArgs,
710 SourceLocation TypeArgsRAngleLoc,
711 SourceLocation ProtocolLAngleLoc,
712 ArrayRef<ObjCProtocolDecl *> Protocols,
713 ArrayRef<SourceLocation> ProtocolLocs,
714 SourceLocation ProtocolRAngleLoc);
715
716 /// \brief Build a new Objective-C object pointer type given the pointee type.
717 ///
718 /// By default, directly builds the pointer type, with no additional semantic
719 /// analysis.
720 QualType RebuildObjCObjectPointerType(QualType PointeeType,
721 SourceLocation Star);
722
Douglas Gregord6ff3322009-08-04 16:50:30 +0000723 /// \brief Build a new array type given the element type, size
724 /// modifier, size of the array (if known), size expression, and index type
725 /// qualifiers.
726 ///
727 /// By default, performs semantic analysis when building the array type.
728 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000729 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000730 QualType RebuildArrayType(QualType ElementType,
731 ArrayType::ArraySizeModifier SizeMod,
732 const llvm::APInt *Size,
733 Expr *SizeExpr,
734 unsigned IndexTypeQuals,
735 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000736
Douglas Gregord6ff3322009-08-04 16:50:30 +0000737 /// \brief Build a new constant array type given the element type, size
738 /// modifier, (known) size of the array, and index type qualifiers.
739 ///
740 /// By default, performs semantic analysis when building the array type.
741 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000742 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000743 ArrayType::ArraySizeModifier SizeMod,
744 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000745 unsigned IndexTypeQuals,
746 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000747
Douglas Gregord6ff3322009-08-04 16:50:30 +0000748 /// \brief Build a new incomplete array type given the element type, size
749 /// modifier, and index type qualifiers.
750 ///
751 /// By default, performs semantic analysis when building the array type.
752 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000753 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000754 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000755 unsigned IndexTypeQuals,
756 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000757
Mike Stump11289f42009-09-09 15:08:12 +0000758 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000759 /// size modifier, size expression, and index type qualifiers.
760 ///
761 /// By default, performs semantic analysis when building the array type.
762 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000763 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000764 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000765 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000766 unsigned IndexTypeQuals,
767 SourceRange BracketsRange);
768
Mike Stump11289f42009-09-09 15:08:12 +0000769 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000770 /// size modifier, size expression, and index type qualifiers.
771 ///
772 /// By default, performs semantic analysis when building the array type.
773 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000774 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000775 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000776 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000777 unsigned IndexTypeQuals,
778 SourceRange BracketsRange);
779
780 /// \brief Build a new vector type given the element type and
781 /// number of elements.
782 ///
783 /// By default, performs semantic analysis when building the vector type.
784 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000785 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000786 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000787
Douglas Gregord6ff3322009-08-04 16:50:30 +0000788 /// \brief Build a new extended vector type given the element type and
789 /// number of elements.
790 ///
791 /// By default, performs semantic analysis when building the vector type.
792 /// Subclasses may override this routine to provide different behavior.
793 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
794 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000795
796 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000797 /// given the element type and number of elements.
798 ///
799 /// By default, performs semantic analysis when building the vector type.
800 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000801 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000802 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000803 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000804
Douglas Gregord6ff3322009-08-04 16:50:30 +0000805 /// \brief Build a new function type.
806 ///
807 /// By default, performs semantic analysis when building the function type.
808 /// Subclasses may override this routine to provide different behavior.
809 QualType RebuildFunctionProtoType(QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +0000810 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000811 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000812
John McCall550e0c22009-10-21 00:40:46 +0000813 /// \brief Build a new unprototyped function type.
814 QualType RebuildFunctionNoProtoType(QualType ResultType);
815
John McCallb96ec562009-12-04 22:46:56 +0000816 /// \brief Rebuild an unresolved typename type, given the decl that
817 /// the UnresolvedUsingTypenameDecl was transformed to.
818 QualType RebuildUnresolvedUsingType(Decl *D);
819
Douglas Gregord6ff3322009-08-04 16:50:30 +0000820 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000821 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000822 return SemaRef.Context.getTypeDeclType(Typedef);
823 }
824
825 /// \brief Build a new class/struct/union type.
826 QualType RebuildRecordType(RecordDecl *Record) {
827 return SemaRef.Context.getTypeDeclType(Record);
828 }
829
830 /// \brief Build a new Enum type.
831 QualType RebuildEnumType(EnumDecl *Enum) {
832 return SemaRef.Context.getTypeDeclType(Enum);
833 }
John McCallfcc33b02009-09-05 00:15:47 +0000834
Mike Stump11289f42009-09-09 15:08:12 +0000835 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000836 ///
837 /// By default, performs semantic analysis when building the typeof type.
838 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000839 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000840
Mike Stump11289f42009-09-09 15:08:12 +0000841 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000842 ///
843 /// By default, builds a new TypeOfType with the given underlying type.
844 QualType RebuildTypeOfType(QualType Underlying);
845
Alexis Hunte852b102011-05-24 22:41:36 +0000846 /// \brief Build a new unary transform type.
847 QualType RebuildUnaryTransformType(QualType BaseType,
848 UnaryTransformType::UTTKind UKind,
849 SourceLocation Loc);
850
Richard Smith74aeef52013-04-26 16:15:35 +0000851 /// \brief Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000852 ///
853 /// By default, performs semantic analysis when building the decltype type.
854 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000855 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000856
Richard Smith74aeef52013-04-26 16:15:35 +0000857 /// \brief Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000858 ///
859 /// By default, builds a new AutoType with the given deduced type.
Richard Smithe301ba22015-11-11 02:02:15 +0000860 QualType RebuildAutoType(QualType Deduced, AutoTypeKeyword Keyword) {
Richard Smith27d807c2013-04-30 13:56:41 +0000861 // Note, IsDependent is always false here: we implicitly convert an 'auto'
862 // which has been deduced to a dependent type into an undeduced 'auto', so
863 // that we'll retry deduction after the transformation.
Richard Smithe301ba22015-11-11 02:02:15 +0000864 return SemaRef.Context.getAutoType(Deduced, Keyword,
Faisal Vali2b391ab2013-09-26 19:54:12 +0000865 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000866 }
867
Douglas Gregord6ff3322009-08-04 16:50:30 +0000868 /// \brief Build a new template specialization type.
869 ///
870 /// By default, performs semantic analysis when building the template
871 /// specialization type. Subclasses may override this routine to provide
872 /// different behavior.
873 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000874 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000875 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000876
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000877 /// \brief Build a new parenthesized type.
878 ///
879 /// By default, builds a new ParenType type from the inner type.
880 /// Subclasses may override this routine to provide different behavior.
881 QualType RebuildParenType(QualType InnerType) {
882 return SemaRef.Context.getParenType(InnerType);
883 }
884
Douglas Gregord6ff3322009-08-04 16:50:30 +0000885 /// \brief Build a new qualified name type.
886 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000887 /// By default, builds a new ElaboratedType type from the keyword,
888 /// the nested-name-specifier and the named type.
889 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000890 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
891 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000892 NestedNameSpecifierLoc QualifierLoc,
893 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000894 return SemaRef.Context.getElaboratedType(Keyword,
895 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000896 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000897 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000898
899 /// \brief Build a new typename type that refers to a template-id.
900 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000901 /// By default, builds a new DependentNameType type from the
902 /// nested-name-specifier and the given type. Subclasses may override
903 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000904 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000905 ElaboratedTypeKeyword Keyword,
906 NestedNameSpecifierLoc QualifierLoc,
907 const IdentifierInfo *Name,
908 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000909 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000910 // Rebuild the template name.
911 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000912 CXXScopeSpec SS;
913 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +0000914 TemplateName InstName
Craig Topperc3ec1492014-05-26 06:22:03 +0000915 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(),
916 nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000917
Douglas Gregora7a795b2011-03-01 20:11:18 +0000918 if (InstName.isNull())
919 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000920
Douglas Gregora7a795b2011-03-01 20:11:18 +0000921 // If it's still dependent, make a dependent specialization.
922 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000923 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
924 QualifierLoc.getNestedNameSpecifier(),
925 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000926 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000927
Douglas Gregora7a795b2011-03-01 20:11:18 +0000928 // Otherwise, make an elaborated type wrapping a non-dependent
929 // specialization.
930 QualType T =
931 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
932 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000933
Craig Topperc3ec1492014-05-26 06:22:03 +0000934 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
Douglas Gregora7a795b2011-03-01 20:11:18 +0000935 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +0000936
937 return SemaRef.Context.getElaboratedType(Keyword,
938 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +0000939 T);
940 }
941
Douglas Gregord6ff3322009-08-04 16:50:30 +0000942 /// \brief Build a new typename type that refers to an identifier.
943 ///
944 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000945 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000946 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000947 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000948 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000949 NestedNameSpecifierLoc QualifierLoc,
950 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000951 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000952 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000953 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000954
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000955 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000956 // If the name is still dependent, just build a new dependent name type.
957 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +0000958 return SemaRef.Context.getDependentNameType(Keyword,
959 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000960 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000961 }
962
Abramo Bagnara6150c882010-05-11 21:36:43 +0000963 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000964 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000965 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000966
967 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
968
Abramo Bagnarad7548482010-05-19 21:37:53 +0000969 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000970 // into a non-dependent elaborated-type-specifier. Find the tag we're
971 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000972 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000973 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
974 if (!DC)
975 return QualType();
976
John McCallbf8c5192010-05-27 06:40:31 +0000977 if (SemaRef.RequireCompleteDeclContext(SS, DC))
978 return QualType();
979
Craig Topperc3ec1492014-05-26 06:22:03 +0000980 TagDecl *Tag = nullptr;
Douglas Gregore677daf2010-03-31 22:19:08 +0000981 SemaRef.LookupQualifiedName(Result, DC);
982 switch (Result.getResultKind()) {
983 case LookupResult::NotFound:
984 case LookupResult::NotFoundInCurrentInstantiation:
985 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000986
Douglas Gregore677daf2010-03-31 22:19:08 +0000987 case LookupResult::Found:
988 Tag = Result.getAsSingle<TagDecl>();
989 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000990
Douglas Gregore677daf2010-03-31 22:19:08 +0000991 case LookupResult::FoundOverloaded:
992 case LookupResult::FoundUnresolvedValue:
993 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +0000994
Douglas Gregore677daf2010-03-31 22:19:08 +0000995 case LookupResult::Ambiguous:
996 // Let the LookupResult structure handle ambiguities.
997 return QualType();
998 }
999
1000 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +00001001 // Check where the name exists but isn't a tag type and use that to emit
1002 // better diagnostics.
1003 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
1004 SemaRef.LookupQualifiedName(Result, DC);
1005 switch (Result.getResultKind()) {
1006 case LookupResult::Found:
1007 case LookupResult::FoundOverloaded:
1008 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +00001009 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky0c438082011-01-24 19:01:04 +00001010 unsigned Kind = 0;
1011 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smithdda56e42011-04-15 14:24:37 +00001012 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
1013 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky0c438082011-01-24 19:01:04 +00001014 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
1015 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1016 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +00001017 }
Nick Lewycky0c438082011-01-24 19:01:04 +00001018 default:
Nick Lewycky0c438082011-01-24 19:01:04 +00001019 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +00001020 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +00001021 break;
1022 }
Douglas Gregore677daf2010-03-31 22:19:08 +00001023 return QualType();
1024 }
Abramo Bagnara6150c882010-05-11 21:36:43 +00001025
Richard Trieucaa33d32011-06-10 03:11:26 +00001026 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
Justin Bognerc6ecb7c2015-07-10 23:05:47 +00001027 IdLoc, Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +00001028 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +00001029 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1030 return QualType();
1031 }
1032
1033 // Build the elaborated-type-specifier type.
1034 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +00001035 return SemaRef.Context.getElaboratedType(Keyword,
1036 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001037 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00001038 }
Mike Stump11289f42009-09-09 15:08:12 +00001039
Douglas Gregor822d0302011-01-12 17:07:58 +00001040 /// \brief Build a new pack expansion type.
1041 ///
1042 /// By default, builds a new PackExpansionType type from the given pattern.
1043 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001044 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00001045 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001046 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00001047 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001048 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1049 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +00001050 }
1051
Eli Friedman0dfb8892011-10-06 23:00:33 +00001052 /// \brief Build a new atomic type given its value type.
1053 ///
1054 /// By default, performs semantic analysis when building the atomic type.
1055 /// Subclasses may override this routine to provide different behavior.
1056 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1057
Xiuli Pan9c14e282016-01-09 12:53:17 +00001058 /// \brief Build a new pipe type given its value type.
1059 QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc);
1060
Douglas Gregor71dc5092009-08-06 06:41:21 +00001061 /// \brief Build a new template name given a nested name specifier, a flag
1062 /// indicating whether the "template" keyword was provided, and the template
1063 /// that the template name refers to.
1064 ///
1065 /// By default, builds the new template name directly. Subclasses may override
1066 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001067 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001068 bool TemplateKW,
1069 TemplateDecl *Template);
1070
Douglas Gregor71dc5092009-08-06 06:41:21 +00001071 /// \brief Build a new template name given a nested name specifier and the
1072 /// name that is referred to as a template.
1073 ///
1074 /// By default, performs semantic analysis to determine whether the name can
1075 /// be resolved to a specific template, then builds the appropriate kind of
1076 /// template name. Subclasses may override this routine to provide different
1077 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001078 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1079 const IdentifierInfo &Name,
1080 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00001081 QualType ObjectType,
1082 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001083
Douglas Gregor71395fa2009-11-04 00:56:37 +00001084 /// \brief Build a new template name given a nested name specifier and the
1085 /// overloaded operator name that is referred to as a template.
1086 ///
1087 /// By default, performs semantic analysis to determine whether the name can
1088 /// be resolved to a specific template, then builds the appropriate kind of
1089 /// template name. Subclasses may override this routine to provide different
1090 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001091 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001092 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00001093 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001094 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +00001095
1096 /// \brief Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001097 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001098 ///
1099 /// By default, performs semantic analysis to determine whether the name can
1100 /// be resolved to a specific template, then builds the appropriate kind of
1101 /// template name. Subclasses may override this routine to provide different
1102 /// behavior.
1103 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1104 const TemplateArgument &ArgPack) {
1105 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1106 }
1107
Douglas Gregorebe10102009-08-20 07:17:43 +00001108 /// \brief Build a new compound statement.
1109 ///
1110 /// By default, performs semantic analysis to build the new statement.
1111 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001112 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001113 MultiStmtArg Statements,
1114 SourceLocation RBraceLoc,
1115 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001116 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001117 IsStmtExpr);
1118 }
1119
1120 /// \brief Build a new case statement.
1121 ///
1122 /// By default, performs semantic analysis to build the new statement.
1123 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001124 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001125 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001126 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001127 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001128 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001129 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001130 ColonLoc);
1131 }
Mike Stump11289f42009-09-09 15:08:12 +00001132
Douglas Gregorebe10102009-08-20 07:17:43 +00001133 /// \brief Attach the body to a new case statement.
1134 ///
1135 /// By default, performs semantic analysis to build the new statement.
1136 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001137 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001138 getSema().ActOnCaseStmtBody(S, Body);
1139 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001140 }
Mike Stump11289f42009-09-09 15:08:12 +00001141
Douglas Gregorebe10102009-08-20 07:17:43 +00001142 /// \brief Build a new default statement.
1143 ///
1144 /// By default, performs semantic analysis to build the new statement.
1145 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001146 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001147 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001148 Stmt *SubStmt) {
1149 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Craig Topperc3ec1492014-05-26 06:22:03 +00001150 /*CurScope=*/nullptr);
Douglas Gregorebe10102009-08-20 07:17:43 +00001151 }
Mike Stump11289f42009-09-09 15:08:12 +00001152
Douglas Gregorebe10102009-08-20 07:17:43 +00001153 /// \brief Build a new label statement.
1154 ///
1155 /// By default, performs semantic analysis to build the new statement.
1156 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001157 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1158 SourceLocation ColonLoc, Stmt *SubStmt) {
1159 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001160 }
Mike Stump11289f42009-09-09 15:08:12 +00001161
Richard Smithc202b282012-04-14 00:33:13 +00001162 /// \brief Build a new label statement.
1163 ///
1164 /// By default, performs semantic analysis to build the new statement.
1165 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001166 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1167 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001168 Stmt *SubStmt) {
1169 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1170 }
1171
Douglas Gregorebe10102009-08-20 07:17:43 +00001172 /// \brief Build a new "if" statement.
1173 ///
1174 /// By default, performs semantic analysis to build the new statement.
1175 /// Subclasses may override this routine to provide different behavior.
Richard Smithb130fe72016-06-23 19:16:49 +00001176 StmtResult RebuildIfStmt(SourceLocation IfLoc, bool IsConstexpr,
1177 Sema::ConditionResult Cond, Stmt *Then,
1178 SourceLocation ElseLoc, Stmt *Else) {
Richard Smithc7a05a92016-06-29 21:17:59 +00001179 return getSema().ActOnIfStmt(IfLoc, IsConstexpr, nullptr, Cond, Then,
1180 ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001181 }
Mike Stump11289f42009-09-09 15:08:12 +00001182
Douglas Gregorebe10102009-08-20 07:17:43 +00001183 /// \brief Start building a new switch statement.
1184 ///
1185 /// By default, performs semantic analysis to build the new statement.
1186 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001187 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Richard Smith03a4aa32016-06-23 19:02:52 +00001188 Sema::ConditionResult Cond) {
Richard Smithc7a05a92016-06-29 21:17:59 +00001189 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, nullptr, Cond);
Douglas Gregorebe10102009-08-20 07:17:43 +00001190 }
Mike Stump11289f42009-09-09 15:08:12 +00001191
Douglas Gregorebe10102009-08-20 07:17:43 +00001192 /// \brief Attach the body to the switch statement.
1193 ///
1194 /// By default, performs semantic analysis to build the new statement.
1195 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001196 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001197 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001198 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001199 }
1200
1201 /// \brief Build a new while statement.
1202 ///
1203 /// By default, performs semantic analysis to build the new statement.
1204 /// Subclasses may override this routine to provide different behavior.
Richard Smith03a4aa32016-06-23 19:02:52 +00001205 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
1206 Sema::ConditionResult Cond, Stmt *Body) {
1207 return getSema().ActOnWhileStmt(WhileLoc, Cond, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001208 }
Mike Stump11289f42009-09-09 15:08:12 +00001209
Douglas Gregorebe10102009-08-20 07:17:43 +00001210 /// \brief Build a new do-while statement.
1211 ///
1212 /// By default, performs semantic analysis to build the new statement.
1213 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001214 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001215 SourceLocation WhileLoc, SourceLocation LParenLoc,
1216 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001217 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1218 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001219 }
1220
1221 /// \brief Build a new for statement.
1222 ///
1223 /// By default, performs semantic analysis to build the new statement.
1224 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001225 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Richard Smith03a4aa32016-06-23 19:02:52 +00001226 Stmt *Init, Sema::ConditionResult Cond,
1227 Sema::FullExprArg Inc, SourceLocation RParenLoc,
1228 Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001229 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Richard Smith03a4aa32016-06-23 19:02:52 +00001230 Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001231 }
Mike Stump11289f42009-09-09 15:08:12 +00001232
Douglas Gregorebe10102009-08-20 07:17:43 +00001233 /// \brief Build a new goto statement.
1234 ///
1235 /// By default, performs semantic analysis to build the new statement.
1236 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001237 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1238 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001239 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001240 }
1241
1242 /// \brief Build a new indirect goto statement.
1243 ///
1244 /// By default, performs semantic analysis to build the new statement.
1245 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001246 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001247 SourceLocation StarLoc,
1248 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001249 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001250 }
Mike Stump11289f42009-09-09 15:08:12 +00001251
Douglas Gregorebe10102009-08-20 07:17:43 +00001252 /// \brief Build a new return statement.
1253 ///
1254 /// By default, performs semantic analysis to build the new statement.
1255 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001256 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001257 return getSema().BuildReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001258 }
Mike Stump11289f42009-09-09 15:08:12 +00001259
Douglas Gregorebe10102009-08-20 07:17:43 +00001260 /// \brief Build a new declaration statement.
1261 ///
1262 /// By default, performs semantic analysis to build the new statement.
1263 /// Subclasses may override this routine to provide different behavior.
Craig Toppere3d2ecbe2014-06-28 23:22:33 +00001264 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
Rafael Espindolaab417692013-07-09 12:05:01 +00001265 SourceLocation StartLoc, SourceLocation EndLoc) {
1266 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001267 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001268 }
Mike Stump11289f42009-09-09 15:08:12 +00001269
Anders Carlssonaaeef072010-01-24 05:50:09 +00001270 /// \brief Build a new inline asm statement.
1271 ///
1272 /// By default, performs semantic analysis to build the new statement.
1273 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001274 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1275 bool IsVolatile, unsigned NumOutputs,
1276 unsigned NumInputs, IdentifierInfo **Names,
1277 MultiExprArg Constraints, MultiExprArg Exprs,
1278 Expr *AsmString, MultiExprArg Clobbers,
1279 SourceLocation RParenLoc) {
1280 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1281 NumInputs, Names, Constraints, Exprs,
1282 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001283 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001284
Chad Rosier32503022012-06-11 20:47:18 +00001285 /// \brief Build a new MS style inline asm statement.
1286 ///
1287 /// By default, performs semantic analysis to build the new statement.
1288 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001289 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001290 ArrayRef<Token> AsmToks,
1291 StringRef AsmString,
1292 unsigned NumOutputs, unsigned NumInputs,
1293 ArrayRef<StringRef> Constraints,
1294 ArrayRef<StringRef> Clobbers,
1295 ArrayRef<Expr*> Exprs,
1296 SourceLocation EndLoc) {
1297 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1298 NumOutputs, NumInputs,
1299 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001300 }
1301
Richard Smith9f690bd2015-10-27 06:02:45 +00001302 /// \brief Build a new co_return statement.
1303 ///
1304 /// By default, performs semantic analysis to build the new statement.
1305 /// Subclasses may override this routine to provide different behavior.
1306 StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result) {
1307 return getSema().BuildCoreturnStmt(CoreturnLoc, Result);
1308 }
1309
1310 /// \brief Build a new co_await expression.
1311 ///
1312 /// By default, performs semantic analysis to build the new expression.
1313 /// Subclasses may override this routine to provide different behavior.
1314 ExprResult RebuildCoawaitExpr(SourceLocation CoawaitLoc, Expr *Result) {
1315 return getSema().BuildCoawaitExpr(CoawaitLoc, Result);
1316 }
1317
1318 /// \brief Build a new co_yield expression.
1319 ///
1320 /// By default, performs semantic analysis to build the new expression.
1321 /// Subclasses may override this routine to provide different behavior.
1322 ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result) {
1323 return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1324 }
1325
James Dennett2a4d13c2012-06-15 07:13:21 +00001326 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001327 ///
1328 /// By default, performs semantic analysis to build the new statement.
1329 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001330 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001331 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001332 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001333 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001334 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001335 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001336 }
1337
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001338 /// \brief Rebuild an Objective-C exception declaration.
1339 ///
1340 /// By default, performs semantic analysis to build the new declaration.
1341 /// Subclasses may override this routine to provide different behavior.
1342 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1343 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001344 return getSema().BuildObjCExceptionDecl(TInfo, T,
1345 ExceptionDecl->getInnerLocStart(),
1346 ExceptionDecl->getLocation(),
1347 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001348 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001349
James Dennett2a4d13c2012-06-15 07:13:21 +00001350 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001351 ///
1352 /// By default, performs semantic analysis to build the new statement.
1353 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001354 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001355 SourceLocation RParenLoc,
1356 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001357 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001358 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001359 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001360 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001361
James Dennett2a4d13c2012-06-15 07:13:21 +00001362 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001363 ///
1364 /// By default, performs semantic analysis to build the new statement.
1365 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001366 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001367 Stmt *Body) {
1368 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001369 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001370
James Dennett2a4d13c2012-06-15 07:13:21 +00001371 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001372 ///
1373 /// By default, performs semantic analysis to build the new statement.
1374 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001375 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001376 Expr *Operand) {
1377 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001378 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001379
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001380 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001381 ///
1382 /// By default, performs semantic analysis to build the new statement.
1383 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001384 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001385 DeclarationNameInfo DirName,
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001386 OpenMPDirectiveKind CancelRegion,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001387 ArrayRef<OMPClause *> Clauses,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001388 Stmt *AStmt, SourceLocation StartLoc,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001389 SourceLocation EndLoc) {
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001390 return getSema().ActOnOpenMPExecutableDirective(
1391 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001392 }
1393
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001394 /// \brief Build a new OpenMP 'if' clause.
1395 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001396 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001397 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001398 OMPClause *RebuildOMPIfClause(OpenMPDirectiveKind NameModifier,
1399 Expr *Condition, SourceLocation StartLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001400 SourceLocation LParenLoc,
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001401 SourceLocation NameModifierLoc,
1402 SourceLocation ColonLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001403 SourceLocation EndLoc) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001404 return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc,
1405 LParenLoc, NameModifierLoc, ColonLoc,
1406 EndLoc);
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001407 }
1408
Alexey Bataev3778b602014-07-17 07:32:53 +00001409 /// \brief Build a new OpenMP 'final' clause.
1410 ///
1411 /// By default, performs semantic analysis to build the new OpenMP clause.
1412 /// Subclasses may override this routine to provide different behavior.
1413 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1414 SourceLocation LParenLoc,
1415 SourceLocation EndLoc) {
1416 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1417 EndLoc);
1418 }
1419
Alexey Bataev568a8332014-03-06 06:15:19 +00001420 /// \brief Build a new OpenMP 'num_threads' clause.
1421 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001422 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001423 /// Subclasses may override this routine to provide different behavior.
1424 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1425 SourceLocation StartLoc,
1426 SourceLocation LParenLoc,
1427 SourceLocation EndLoc) {
1428 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1429 LParenLoc, EndLoc);
1430 }
1431
Alexey Bataev62c87d22014-03-21 04:51:18 +00001432 /// \brief Build a new OpenMP 'safelen' clause.
1433 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001434 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001435 /// Subclasses may override this routine to provide different behavior.
1436 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1437 SourceLocation LParenLoc,
1438 SourceLocation EndLoc) {
1439 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1440 }
1441
Alexey Bataev66b15b52015-08-21 11:14:16 +00001442 /// \brief Build a new OpenMP 'simdlen' clause.
1443 ///
1444 /// By default, performs semantic analysis to build the new OpenMP clause.
1445 /// Subclasses may override this routine to provide different behavior.
1446 OMPClause *RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc,
1447 SourceLocation LParenLoc,
1448 SourceLocation EndLoc) {
1449 return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc);
1450 }
1451
Alexander Musman8bd31e62014-05-27 15:12:19 +00001452 /// \brief Build a new OpenMP 'collapse' clause.
1453 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001454 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001455 /// Subclasses may override this routine to provide different behavior.
1456 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1457 SourceLocation LParenLoc,
1458 SourceLocation EndLoc) {
1459 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1460 EndLoc);
1461 }
1462
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001463 /// \brief Build a new OpenMP 'default' clause.
1464 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001465 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001466 /// Subclasses may override this routine to provide different behavior.
1467 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1468 SourceLocation KindKwLoc,
1469 SourceLocation StartLoc,
1470 SourceLocation LParenLoc,
1471 SourceLocation EndLoc) {
1472 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1473 StartLoc, LParenLoc, EndLoc);
1474 }
1475
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001476 /// \brief Build a new OpenMP 'proc_bind' clause.
1477 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001478 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001479 /// Subclasses may override this routine to provide different behavior.
1480 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1481 SourceLocation KindKwLoc,
1482 SourceLocation StartLoc,
1483 SourceLocation LParenLoc,
1484 SourceLocation EndLoc) {
1485 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1486 StartLoc, LParenLoc, EndLoc);
1487 }
1488
Alexey Bataev56dafe82014-06-20 07:16:17 +00001489 /// \brief Build a new OpenMP 'schedule' clause.
1490 ///
1491 /// By default, performs semantic analysis to build the new OpenMP clause.
1492 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6402bca2015-12-28 07:25:51 +00001493 OMPClause *RebuildOMPScheduleClause(
1494 OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2,
1495 OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1496 SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1497 SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
Alexey Bataev56dafe82014-06-20 07:16:17 +00001498 return getSema().ActOnOpenMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00001499 M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1500 CommaLoc, EndLoc);
Alexey Bataev56dafe82014-06-20 07:16:17 +00001501 }
1502
Alexey Bataev10e775f2015-07-30 11:36:16 +00001503 /// \brief Build a new OpenMP 'ordered' clause.
1504 ///
1505 /// By default, performs semantic analysis to build the new OpenMP clause.
1506 /// Subclasses may override this routine to provide different behavior.
1507 OMPClause *RebuildOMPOrderedClause(SourceLocation StartLoc,
1508 SourceLocation EndLoc,
1509 SourceLocation LParenLoc, Expr *Num) {
1510 return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num);
1511 }
1512
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001513 /// \brief Build a new OpenMP 'private' clause.
1514 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001515 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001516 /// Subclasses may override this routine to provide different behavior.
1517 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1518 SourceLocation StartLoc,
1519 SourceLocation LParenLoc,
1520 SourceLocation EndLoc) {
1521 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1522 EndLoc);
1523 }
1524
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001525 /// \brief Build a new OpenMP 'firstprivate' clause.
1526 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001527 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001528 /// Subclasses may override this routine to provide different behavior.
1529 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1530 SourceLocation StartLoc,
1531 SourceLocation LParenLoc,
1532 SourceLocation EndLoc) {
1533 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1534 EndLoc);
1535 }
1536
Alexander Musman1bb328c2014-06-04 13:06:39 +00001537 /// \brief Build a new OpenMP 'lastprivate' clause.
1538 ///
1539 /// By default, performs semantic analysis to build the new OpenMP clause.
1540 /// Subclasses may override this routine to provide different behavior.
1541 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1542 SourceLocation StartLoc,
1543 SourceLocation LParenLoc,
1544 SourceLocation EndLoc) {
1545 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1546 EndLoc);
1547 }
1548
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001549 /// \brief Build a new OpenMP 'shared' clause.
1550 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001551 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001552 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001553 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1554 SourceLocation StartLoc,
1555 SourceLocation LParenLoc,
1556 SourceLocation EndLoc) {
1557 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1558 EndLoc);
1559 }
1560
Alexey Bataevc5e02582014-06-16 07:08:35 +00001561 /// \brief Build a new OpenMP 'reduction' clause.
1562 ///
1563 /// By default, performs semantic analysis to build the new statement.
1564 /// Subclasses may override this routine to provide different behavior.
1565 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1566 SourceLocation StartLoc,
1567 SourceLocation LParenLoc,
1568 SourceLocation ColonLoc,
1569 SourceLocation EndLoc,
1570 CXXScopeSpec &ReductionIdScopeSpec,
Alexey Bataeva839ddd2016-03-17 10:19:46 +00001571 const DeclarationNameInfo &ReductionId,
1572 ArrayRef<Expr *> UnresolvedReductions) {
Alexey Bataevc5e02582014-06-16 07:08:35 +00001573 return getSema().ActOnOpenMPReductionClause(
1574 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
Alexey Bataeva839ddd2016-03-17 10:19:46 +00001575 ReductionId, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00001576 }
1577
Alexander Musman8dba6642014-04-22 13:09:42 +00001578 /// \brief Build a new OpenMP 'linear' clause.
1579 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001580 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001581 /// Subclasses may override this routine to provide different behavior.
1582 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1583 SourceLocation StartLoc,
1584 SourceLocation LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001585 OpenMPLinearClauseKind Modifier,
1586 SourceLocation ModifierLoc,
Alexander Musman8dba6642014-04-22 13:09:42 +00001587 SourceLocation ColonLoc,
1588 SourceLocation EndLoc) {
1589 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001590 Modifier, ModifierLoc, ColonLoc,
1591 EndLoc);
Alexander Musman8dba6642014-04-22 13:09:42 +00001592 }
1593
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001594 /// \brief Build a new OpenMP 'aligned' clause.
1595 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001596 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001597 /// Subclasses may override this routine to provide different behavior.
1598 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1599 SourceLocation StartLoc,
1600 SourceLocation LParenLoc,
1601 SourceLocation ColonLoc,
1602 SourceLocation EndLoc) {
1603 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1604 LParenLoc, ColonLoc, EndLoc);
1605 }
1606
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001607 /// \brief Build a new OpenMP 'copyin' clause.
1608 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001609 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001610 /// Subclasses may override this routine to provide different behavior.
1611 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1612 SourceLocation StartLoc,
1613 SourceLocation LParenLoc,
1614 SourceLocation EndLoc) {
1615 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1616 EndLoc);
1617 }
1618
Alexey Bataevbae9a792014-06-27 10:37:06 +00001619 /// \brief Build a new OpenMP 'copyprivate' clause.
1620 ///
1621 /// By default, performs semantic analysis to build the new OpenMP clause.
1622 /// Subclasses may override this routine to provide different behavior.
1623 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1624 SourceLocation StartLoc,
1625 SourceLocation LParenLoc,
1626 SourceLocation EndLoc) {
1627 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1628 EndLoc);
1629 }
1630
Alexey Bataev6125da92014-07-21 11:26:11 +00001631 /// \brief Build a new OpenMP 'flush' pseudo clause.
1632 ///
1633 /// By default, performs semantic analysis to build the new OpenMP clause.
1634 /// Subclasses may override this routine to provide different behavior.
1635 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1636 SourceLocation StartLoc,
1637 SourceLocation LParenLoc,
1638 SourceLocation EndLoc) {
1639 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1640 EndLoc);
1641 }
1642
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001643 /// \brief Build a new OpenMP 'depend' pseudo clause.
1644 ///
1645 /// By default, performs semantic analysis to build the new OpenMP clause.
1646 /// Subclasses may override this routine to provide different behavior.
1647 OMPClause *
1648 RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
1649 SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1650 SourceLocation StartLoc, SourceLocation LParenLoc,
1651 SourceLocation EndLoc) {
1652 return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList,
1653 StartLoc, LParenLoc, EndLoc);
1654 }
1655
Michael Wonge710d542015-08-07 16:16:36 +00001656 /// \brief Build a new OpenMP 'device' clause.
1657 ///
1658 /// By default, performs semantic analysis to build the new statement.
1659 /// Subclasses may override this routine to provide different behavior.
1660 OMPClause *RebuildOMPDeviceClause(Expr *Device, SourceLocation StartLoc,
1661 SourceLocation LParenLoc,
1662 SourceLocation EndLoc) {
Kelvin Li099bb8c2015-11-24 20:50:12 +00001663 return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc,
Michael Wonge710d542015-08-07 16:16:36 +00001664 EndLoc);
1665 }
1666
Kelvin Li0bff7af2015-11-23 05:32:03 +00001667 /// \brief Build a new OpenMP 'map' clause.
1668 ///
1669 /// By default, performs semantic analysis to build the new OpenMP clause.
1670 /// Subclasses may override this routine to provide different behavior.
Samuel Antao23abd722016-01-19 20:40:49 +00001671 OMPClause *
1672 RebuildOMPMapClause(OpenMPMapClauseKind MapTypeModifier,
1673 OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
1674 SourceLocation MapLoc, SourceLocation ColonLoc,
1675 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1676 SourceLocation LParenLoc, SourceLocation EndLoc) {
1677 return getSema().ActOnOpenMPMapClause(MapTypeModifier, MapType,
1678 IsMapTypeImplicit, MapLoc, ColonLoc,
1679 VarList, StartLoc, LParenLoc, EndLoc);
Kelvin Li0bff7af2015-11-23 05:32:03 +00001680 }
1681
Kelvin Li099bb8c2015-11-24 20:50:12 +00001682 /// \brief Build a new OpenMP 'num_teams' clause.
1683 ///
1684 /// By default, performs semantic analysis to build the new statement.
1685 /// Subclasses may override this routine to provide different behavior.
1686 OMPClause *RebuildOMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc,
1687 SourceLocation LParenLoc,
1688 SourceLocation EndLoc) {
1689 return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc,
1690 EndLoc);
1691 }
1692
Kelvin Lia15fb1a2015-11-27 18:47:36 +00001693 /// \brief Build a new OpenMP 'thread_limit' clause.
1694 ///
1695 /// By default, performs semantic analysis to build the new statement.
1696 /// Subclasses may override this routine to provide different behavior.
1697 OMPClause *RebuildOMPThreadLimitClause(Expr *ThreadLimit,
1698 SourceLocation StartLoc,
1699 SourceLocation LParenLoc,
1700 SourceLocation EndLoc) {
1701 return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc,
1702 LParenLoc, EndLoc);
1703 }
1704
Alexey Bataeva0569352015-12-01 10:17:31 +00001705 /// \brief Build a new OpenMP 'priority' clause.
1706 ///
1707 /// By default, performs semantic analysis to build the new statement.
1708 /// Subclasses may override this routine to provide different behavior.
1709 OMPClause *RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc,
1710 SourceLocation LParenLoc,
1711 SourceLocation EndLoc) {
1712 return getSema().ActOnOpenMPPriorityClause(Priority, StartLoc, LParenLoc,
1713 EndLoc);
1714 }
1715
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00001716 /// \brief Build a new OpenMP 'grainsize' clause.
1717 ///
1718 /// By default, performs semantic analysis to build the new statement.
1719 /// Subclasses may override this routine to provide different behavior.
1720 OMPClause *RebuildOMPGrainsizeClause(Expr *Grainsize, SourceLocation StartLoc,
1721 SourceLocation LParenLoc,
1722 SourceLocation EndLoc) {
1723 return getSema().ActOnOpenMPGrainsizeClause(Grainsize, StartLoc, LParenLoc,
1724 EndLoc);
1725 }
1726
Alexey Bataev382967a2015-12-08 12:06:20 +00001727 /// \brief Build a new OpenMP 'num_tasks' clause.
1728 ///
1729 /// By default, performs semantic analysis to build the new statement.
1730 /// Subclasses may override this routine to provide different behavior.
1731 OMPClause *RebuildOMPNumTasksClause(Expr *NumTasks, SourceLocation StartLoc,
1732 SourceLocation LParenLoc,
1733 SourceLocation EndLoc) {
1734 return getSema().ActOnOpenMPNumTasksClause(NumTasks, StartLoc, LParenLoc,
1735 EndLoc);
1736 }
1737
Alexey Bataev28c75412015-12-15 08:19:24 +00001738 /// \brief Build a new OpenMP 'hint' clause.
1739 ///
1740 /// By default, performs semantic analysis to build the new statement.
1741 /// Subclasses may override this routine to provide different behavior.
1742 OMPClause *RebuildOMPHintClause(Expr *Hint, SourceLocation StartLoc,
1743 SourceLocation LParenLoc,
1744 SourceLocation EndLoc) {
1745 return getSema().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc, EndLoc);
1746 }
1747
Carlo Bertollib4adf552016-01-15 18:50:31 +00001748 /// \brief Build a new OpenMP 'dist_schedule' clause.
1749 ///
1750 /// By default, performs semantic analysis to build the new OpenMP clause.
1751 /// Subclasses may override this routine to provide different behavior.
1752 OMPClause *
1753 RebuildOMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind,
1754 Expr *ChunkSize, SourceLocation StartLoc,
1755 SourceLocation LParenLoc, SourceLocation KindLoc,
1756 SourceLocation CommaLoc, SourceLocation EndLoc) {
1757 return getSema().ActOnOpenMPDistScheduleClause(
1758 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1759 }
1760
Samuel Antao661c0902016-05-26 17:39:58 +00001761 /// \brief Build a new OpenMP 'to' clause.
1762 ///
1763 /// By default, performs semantic analysis to build the new statement.
1764 /// Subclasses may override this routine to provide different behavior.
1765 OMPClause *RebuildOMPToClause(ArrayRef<Expr *> VarList,
1766 SourceLocation StartLoc,
1767 SourceLocation LParenLoc,
1768 SourceLocation EndLoc) {
1769 return getSema().ActOnOpenMPToClause(VarList, StartLoc, LParenLoc, EndLoc);
1770 }
1771
Samuel Antaoec172c62016-05-26 17:49:04 +00001772 /// \brief Build a new OpenMP 'from' clause.
1773 ///
1774 /// By default, performs semantic analysis to build the new statement.
1775 /// Subclasses may override this routine to provide different behavior.
1776 OMPClause *RebuildOMPFromClause(ArrayRef<Expr *> VarList,
1777 SourceLocation StartLoc,
1778 SourceLocation LParenLoc,
1779 SourceLocation EndLoc) {
1780 return getSema().ActOnOpenMPFromClause(VarList, StartLoc, LParenLoc,
1781 EndLoc);
1782 }
1783
James Dennett2a4d13c2012-06-15 07:13:21 +00001784 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001785 ///
1786 /// By default, performs semantic analysis to build the new statement.
1787 /// Subclasses may override this routine to provide different behavior.
1788 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1789 Expr *object) {
1790 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1791 }
1792
James Dennett2a4d13c2012-06-15 07:13:21 +00001793 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001794 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001795 /// By default, performs semantic analysis to build the new statement.
1796 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001797 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001798 Expr *Object, Stmt *Body) {
1799 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001800 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001801
James Dennett2a4d13c2012-06-15 07:13:21 +00001802 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001803 ///
1804 /// By default, performs semantic analysis to build the new statement.
1805 /// Subclasses may override this routine to provide different behavior.
1806 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1807 Stmt *Body) {
1808 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1809 }
John McCall53848232011-07-27 01:07:15 +00001810
Douglas Gregorf68a5082010-04-22 23:10:45 +00001811 /// \brief Build a new Objective-C fast enumeration statement.
1812 ///
1813 /// By default, performs semantic analysis to build the new statement.
1814 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001815 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001816 Stmt *Element,
1817 Expr *Collection,
1818 SourceLocation RParenLoc,
1819 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001820 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001821 Element,
John McCallb268a282010-08-23 23:25:46 +00001822 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001823 RParenLoc);
1824 if (ForEachStmt.isInvalid())
1825 return StmtError();
1826
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001827 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001828 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001829
Douglas Gregorebe10102009-08-20 07:17:43 +00001830 /// \brief Build a new C++ exception declaration.
1831 ///
1832 /// By default, performs semantic analysis to build the new decaration.
1833 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001834 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001835 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001836 SourceLocation StartLoc,
1837 SourceLocation IdLoc,
1838 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001839 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001840 StartLoc, IdLoc, Id);
1841 if (Var)
1842 getSema().CurContext->addDecl(Var);
1843 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001844 }
1845
1846 /// \brief Build a new C++ catch statement.
1847 ///
1848 /// By default, performs semantic analysis to build the new statement.
1849 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001850 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001851 VarDecl *ExceptionDecl,
1852 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001853 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1854 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001855 }
Mike Stump11289f42009-09-09 15:08:12 +00001856
Douglas Gregorebe10102009-08-20 07:17:43 +00001857 /// \brief Build a new C++ try statement.
1858 ///
1859 /// By default, performs semantic analysis to build the new statement.
1860 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001861 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1862 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001863 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001864 }
Mike Stump11289f42009-09-09 15:08:12 +00001865
Richard Smith02e85f32011-04-14 22:09:26 +00001866 /// \brief Build a new C++0x range-based for statement.
1867 ///
1868 /// By default, performs semantic analysis to build the new statement.
1869 /// Subclasses may override this routine to provide different behavior.
1870 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
Richard Smith9f690bd2015-10-27 06:02:45 +00001871 SourceLocation CoawaitLoc,
Richard Smith02e85f32011-04-14 22:09:26 +00001872 SourceLocation ColonLoc,
Richard Smith01694c32016-03-20 10:33:40 +00001873 Stmt *Range, Stmt *Begin, Stmt *End,
Richard Smith02e85f32011-04-14 22:09:26 +00001874 Expr *Cond, Expr *Inc,
1875 Stmt *LoopVar,
1876 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001877 // If we've just learned that the range is actually an Objective-C
1878 // collection, treat this as an Objective-C fast enumeration loop.
1879 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1880 if (RangeStmt->isSingleDecl()) {
1881 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001882 if (RangeVar->isInvalidDecl())
1883 return StmtError();
1884
Douglas Gregorf7106af2013-04-08 18:40:13 +00001885 Expr *RangeExpr = RangeVar->getInit();
1886 if (!RangeExpr->isTypeDependent() &&
1887 RangeExpr->getType()->isObjCObjectPointerType())
1888 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1889 RParenLoc);
1890 }
1891 }
1892 }
1893
Richard Smithcfd53b42015-10-22 06:13:50 +00001894 return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, ColonLoc,
Richard Smith01694c32016-03-20 10:33:40 +00001895 Range, Begin, End,
Richard Smitha05b3b52012-09-20 21:52:32 +00001896 Cond, Inc, LoopVar, RParenLoc,
1897 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001898 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001899
1900 /// \brief Build a new C++0x range-based for statement.
1901 ///
1902 /// By default, performs semantic analysis to build the new statement.
1903 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001904 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001905 bool IsIfExists,
1906 NestedNameSpecifierLoc QualifierLoc,
1907 DeclarationNameInfo NameInfo,
1908 Stmt *Nested) {
1909 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1910 QualifierLoc, NameInfo, Nested);
1911 }
1912
Richard Smith02e85f32011-04-14 22:09:26 +00001913 /// \brief Attach body to a C++0x range-based for statement.
1914 ///
1915 /// By default, performs semantic analysis to finish the new statement.
1916 /// Subclasses may override this routine to provide different behavior.
1917 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1918 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1919 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001920
David Majnemerfad8f482013-10-15 09:33:02 +00001921 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00001922 Stmt *TryBlock, Stmt *Handler) {
1923 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001924 }
1925
David Majnemerfad8f482013-10-15 09:33:02 +00001926 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001927 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001928 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001929 }
1930
David Majnemerfad8f482013-10-15 09:33:02 +00001931 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
Nico Weberd64657f2015-03-09 02:47:59 +00001932 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001933 }
1934
Alexey Bataevec474782014-10-09 08:45:04 +00001935 /// \brief Build a new predefined expression.
1936 ///
1937 /// By default, performs semantic analysis to build the new expression.
1938 /// Subclasses may override this routine to provide different behavior.
1939 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
1940 PredefinedExpr::IdentType IT) {
1941 return getSema().BuildPredefinedExpr(Loc, IT);
1942 }
1943
Douglas Gregora16548e2009-08-11 05:31:07 +00001944 /// \brief Build a new expression that references a declaration.
1945 ///
1946 /// By default, performs semantic analysis to build the new expression.
1947 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001948 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001949 LookupResult &R,
1950 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001951 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1952 }
1953
1954
1955 /// \brief Build a new expression that references a declaration.
1956 ///
1957 /// By default, performs semantic analysis to build the new expression.
1958 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001959 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001960 ValueDecl *VD,
1961 const DeclarationNameInfo &NameInfo,
1962 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001963 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001964 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001965
1966 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001967
1968 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001969 }
Mike Stump11289f42009-09-09 15:08:12 +00001970
Douglas Gregora16548e2009-08-11 05:31:07 +00001971 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001972 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001973 /// By default, performs semantic analysis to build the new expression.
1974 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001975 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001976 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001977 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001978 }
1979
Douglas Gregorad8a3362009-09-04 17:36:40 +00001980 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001981 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001982 /// By default, performs semantic analysis to build the new expression.
1983 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001984 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001985 SourceLocation OperatorLoc,
1986 bool isArrow,
1987 CXXScopeSpec &SS,
1988 TypeSourceInfo *ScopeType,
1989 SourceLocation CCLoc,
1990 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001991 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001992
Douglas Gregora16548e2009-08-11 05:31:07 +00001993 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001994 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001995 /// By default, performs semantic analysis to build the new expression.
1996 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001997 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001998 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001999 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002000 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002001 }
Mike Stump11289f42009-09-09 15:08:12 +00002002
Douglas Gregor882211c2010-04-28 22:16:22 +00002003 /// \brief Build a new builtin offsetof expression.
2004 ///
2005 /// By default, performs semantic analysis to build the new expression.
2006 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002007 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Craig Topperb5518242015-10-22 04:59:59 +00002008 TypeSourceInfo *Type,
2009 ArrayRef<Sema::OffsetOfComponent> Components,
2010 SourceLocation RParenLoc) {
Douglas Gregor882211c2010-04-28 22:16:22 +00002011 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
Craig Topperb5518242015-10-22 04:59:59 +00002012 RParenLoc);
Douglas Gregor882211c2010-04-28 22:16:22 +00002013 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002014
2015 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00002016 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00002017 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002018 /// By default, performs semantic analysis to build the new expression.
2019 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00002020 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
2021 SourceLocation OpLoc,
2022 UnaryExprOrTypeTrait ExprKind,
2023 SourceRange R) {
2024 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00002025 }
2026
Peter Collingbournee190dee2011-03-11 19:24:49 +00002027 /// \brief Build a new sizeof, alignof or vec step expression with an
2028 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00002029 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002030 /// By default, performs semantic analysis to build the new expression.
2031 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00002032 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
2033 UnaryExprOrTypeTrait ExprKind,
2034 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00002035 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00002036 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00002037 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002038 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002039
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002040 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002041 }
Mike Stump11289f42009-09-09 15:08:12 +00002042
Douglas Gregora16548e2009-08-11 05:31:07 +00002043 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00002044 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002045 /// By default, performs semantic analysis to build the new expression.
2046 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002047 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002048 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00002049 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002050 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002051 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00002052 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002053 RBracketLoc);
2054 }
2055
Alexey Bataev1a3320e2015-08-25 14:24:04 +00002056 /// \brief Build a new array section expression.
2057 ///
2058 /// By default, performs semantic analysis to build the new expression.
2059 /// Subclasses may override this routine to provide different behavior.
2060 ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc,
2061 Expr *LowerBound,
2062 SourceLocation ColonLoc, Expr *Length,
2063 SourceLocation RBracketLoc) {
2064 return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound,
2065 ColonLoc, Length, RBracketLoc);
2066 }
2067
Douglas Gregora16548e2009-08-11 05:31:07 +00002068 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00002069 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002070 /// By default, performs semantic analysis to build the new expression.
2071 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002072 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002073 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00002074 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00002075 Expr *ExecConfig = nullptr) {
2076 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002077 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00002078 }
2079
2080 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002081 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002082 /// By default, performs semantic analysis to build the new expression.
2083 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002084 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002085 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00002086 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002087 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002088 const DeclarationNameInfo &MemberNameInfo,
2089 ValueDecl *Member,
2090 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00002091 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00002092 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00002093 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
2094 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00002095 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00002096 // We have a reference to an unnamed field. This is always the
2097 // base of an anonymous struct/union member access, i.e. the
2098 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00002099 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00002100 assert(Member->getType()->isRecordType() &&
2101 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00002102
Richard Smithcab9a7d2011-10-26 19:06:56 +00002103 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002104 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00002105 QualifierLoc.getNestedNameSpecifier(),
2106 FoundDecl, Member);
2107 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002108 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002109 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00002110 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Aaron Ballmanf4cb2be2015-03-24 15:07:53 +00002111 MemberExpr *ME = new (getSema().Context)
2112 MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
2113 cast<FieldDecl>(Member)->getType(), VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002114 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00002115 }
Mike Stump11289f42009-09-09 15:08:12 +00002116
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002117 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00002118 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002119
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002120 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00002121 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00002122
John McCall16df1e52010-03-30 21:47:33 +00002123 // FIXME: this involves duplicating earlier analysis in a lot of
2124 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002125 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00002126 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00002127 R.resolveKind();
2128
John McCallb268a282010-08-23 23:25:46 +00002129 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002130 SS, TemplateKWLoc,
2131 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002132 R, ExplicitTemplateArgs,
2133 /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002134 }
Mike Stump11289f42009-09-09 15:08:12 +00002135
Douglas Gregora16548e2009-08-11 05:31:07 +00002136 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002137 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002138 /// By default, performs semantic analysis to build the new expression.
2139 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002140 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00002141 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00002142 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002143 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002144 }
2145
2146 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002147 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002148 /// By default, performs semantic analysis to build the new expression.
2149 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002150 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00002151 SourceLocation QuestionLoc,
2152 Expr *LHS,
2153 SourceLocation ColonLoc,
2154 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00002155 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
2156 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002157 }
2158
Douglas Gregora16548e2009-08-11 05:31:07 +00002159 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00002160 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002161 /// By default, performs semantic analysis to build the new expression.
2162 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002163 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00002164 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002165 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002166 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00002167 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002168 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002169 }
Mike Stump11289f42009-09-09 15:08:12 +00002170
Douglas Gregora16548e2009-08-11 05:31:07 +00002171 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00002172 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002173 /// By default, performs semantic analysis to build the new expression.
2174 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002175 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00002176 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002177 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002178 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00002179 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002180 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002181 }
Mike Stump11289f42009-09-09 15:08:12 +00002182
Douglas Gregora16548e2009-08-11 05:31:07 +00002183 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002184 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002185 /// By default, performs semantic analysis to build the new expression.
2186 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002187 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00002188 SourceLocation OpLoc,
2189 SourceLocation AccessorLoc,
2190 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00002191
John McCall10eae182009-11-30 22:42:35 +00002192 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002193 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00002194 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00002195 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002196 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002197 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002198 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002199 /* TemplateArgs */ nullptr,
2200 /*S*/ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002201 }
Mike Stump11289f42009-09-09 15:08:12 +00002202
Douglas Gregora16548e2009-08-11 05:31:07 +00002203 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00002204 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002205 /// By default, performs semantic analysis to build the new expression.
2206 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002207 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00002208 MultiExprArg Inits,
2209 SourceLocation RBraceLoc,
2210 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00002211 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002212 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00002213 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002214 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002215
Douglas Gregord3d93062009-11-09 17:16:50 +00002216 // Patch in the result type we were given, which may have been computed
2217 // when the initial InitListExpr was built.
2218 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
2219 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002220 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002221 }
Mike Stump11289f42009-09-09 15:08:12 +00002222
Douglas Gregora16548e2009-08-11 05:31:07 +00002223 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00002224 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002225 /// By default, performs semantic analysis to build the new expression.
2226 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002227 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00002228 MultiExprArg ArrayExprs,
2229 SourceLocation EqualOrColonLoc,
2230 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002231 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00002232 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00002233 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002234 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002235 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002236 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002237
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002238 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002239 }
Mike Stump11289f42009-09-09 15:08:12 +00002240
Douglas Gregora16548e2009-08-11 05:31:07 +00002241 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00002242 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002243 /// By default, builds the implicit value initialization without performing
2244 /// any semantic analysis. Subclasses may override this routine to provide
2245 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002246 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002247 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00002248 }
Mike Stump11289f42009-09-09 15:08:12 +00002249
Douglas Gregora16548e2009-08-11 05:31:07 +00002250 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00002251 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002252 /// By default, performs semantic analysis to build the new expression.
2253 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002254 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002255 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002256 SourceLocation RParenLoc) {
2257 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002258 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002259 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002260 }
2261
2262 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002263 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002264 /// 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 RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00002267 MultiExprArg SubExprs,
2268 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002269 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002270 }
Mike Stump11289f42009-09-09 15:08:12 +00002271
Douglas Gregora16548e2009-08-11 05:31:07 +00002272 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00002273 ///
2274 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002275 /// rather than attempting to map the label statement itself.
2276 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002277 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002278 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002279 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002280 }
Mike Stump11289f42009-09-09 15:08:12 +00002281
Douglas Gregora16548e2009-08-11 05:31:07 +00002282 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002283 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002284 /// By default, performs semantic analysis to build the new expression.
2285 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002286 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002287 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002288 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002289 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002290 }
Mike Stump11289f42009-09-09 15:08:12 +00002291
Douglas Gregora16548e2009-08-11 05:31:07 +00002292 /// \brief Build a new __builtin_choose_expr expression.
2293 ///
2294 /// By default, performs semantic analysis to build the new expression.
2295 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002296 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002297 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002298 SourceLocation RParenLoc) {
2299 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002300 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002301 RParenLoc);
2302 }
Mike Stump11289f42009-09-09 15:08:12 +00002303
Peter Collingbourne91147592011-04-15 00:35:48 +00002304 /// \brief Build a new generic selection expression.
2305 ///
2306 /// By default, performs semantic analysis to build the new expression.
2307 /// Subclasses may override this routine to provide different behavior.
2308 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2309 SourceLocation DefaultLoc,
2310 SourceLocation RParenLoc,
2311 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002312 ArrayRef<TypeSourceInfo *> Types,
2313 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002314 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002315 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002316 }
2317
Douglas Gregora16548e2009-08-11 05:31:07 +00002318 /// \brief Build a new overloaded operator call expression.
2319 ///
2320 /// By default, performs semantic analysis to build the new expression.
2321 /// The semantic analysis provides the behavior of template instantiation,
2322 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002323 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002324 /// argument-dependent lookup, etc. Subclasses may override this routine to
2325 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002326 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002327 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002328 Expr *Callee,
2329 Expr *First,
2330 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002331
2332 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002333 /// reinterpret_cast.
2334 ///
2335 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002336 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002337 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002338 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002339 Stmt::StmtClass Class,
2340 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002341 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002342 SourceLocation RAngleLoc,
2343 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002344 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002345 SourceLocation RParenLoc) {
2346 switch (Class) {
2347 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002348 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002349 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002350 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002351
2352 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002353 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002354 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002355 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002356
Douglas Gregora16548e2009-08-11 05:31:07 +00002357 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002358 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002359 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002360 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002361 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002362
Douglas Gregora16548e2009-08-11 05:31:07 +00002363 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002364 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002365 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002366 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002367
Douglas Gregora16548e2009-08-11 05:31:07 +00002368 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002369 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002370 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002371 }
Mike Stump11289f42009-09-09 15:08:12 +00002372
Douglas Gregora16548e2009-08-11 05:31:07 +00002373 /// \brief Build a new C++ static_cast expression.
2374 ///
2375 /// By default, performs semantic analysis to build the new expression.
2376 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002377 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002378 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002379 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002380 SourceLocation RAngleLoc,
2381 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002382 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002383 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002384 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002385 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002386 SourceRange(LAngleLoc, RAngleLoc),
2387 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002388 }
2389
2390 /// \brief Build a new C++ dynamic_cast expression.
2391 ///
2392 /// By default, performs semantic analysis to build the new expression.
2393 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002394 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002395 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002396 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002397 SourceLocation RAngleLoc,
2398 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002399 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002400 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002401 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002402 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002403 SourceRange(LAngleLoc, RAngleLoc),
2404 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002405 }
2406
2407 /// \brief Build a new C++ reinterpret_cast expression.
2408 ///
2409 /// By default, performs semantic analysis to build the new expression.
2410 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002411 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002412 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002413 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002414 SourceLocation RAngleLoc,
2415 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002416 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002417 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002418 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002419 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002420 SourceRange(LAngleLoc, RAngleLoc),
2421 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002422 }
2423
2424 /// \brief Build a new C++ const_cast 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 RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002429 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002430 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002431 SourceLocation RAngleLoc,
2432 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002433 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002434 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002435 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002436 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002437 SourceRange(LAngleLoc, RAngleLoc),
2438 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002439 }
Mike Stump11289f42009-09-09 15:08:12 +00002440
Douglas Gregora16548e2009-08-11 05:31:07 +00002441 /// \brief Build a new C++ functional-style cast expression.
2442 ///
2443 /// By default, performs semantic analysis to build the new expression.
2444 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002445 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2446 SourceLocation LParenLoc,
2447 Expr *Sub,
2448 SourceLocation RParenLoc) {
2449 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002450 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002451 RParenLoc);
2452 }
Mike Stump11289f42009-09-09 15:08:12 +00002453
Douglas Gregora16548e2009-08-11 05:31:07 +00002454 /// \brief Build a new C++ typeid(type) expression.
2455 ///
2456 /// By default, performs semantic analysis to build the new expression.
2457 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002458 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002459 SourceLocation TypeidLoc,
2460 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002461 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002462 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002463 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002464 }
Mike Stump11289f42009-09-09 15:08:12 +00002465
Francois Pichet9f4f2072010-09-08 12:20:18 +00002466
Douglas Gregora16548e2009-08-11 05:31:07 +00002467 /// \brief Build a new C++ typeid(expr) expression.
2468 ///
2469 /// By default, performs semantic analysis to build the new expression.
2470 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002471 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002472 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002473 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002474 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002475 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002476 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002477 }
2478
Francois Pichet9f4f2072010-09-08 12:20:18 +00002479 /// \brief Build a new C++ __uuidof(type) expression.
2480 ///
2481 /// By default, performs semantic analysis to build the new expression.
2482 /// Subclasses may override this routine to provide different behavior.
2483 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2484 SourceLocation TypeidLoc,
2485 TypeSourceInfo *Operand,
2486 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002487 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002488 RParenLoc);
2489 }
2490
2491 /// \brief Build a new C++ __uuidof(expr) expression.
2492 ///
2493 /// By default, performs semantic analysis to build the new expression.
2494 /// Subclasses may override this routine to provide different behavior.
2495 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2496 SourceLocation TypeidLoc,
2497 Expr *Operand,
2498 SourceLocation RParenLoc) {
2499 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2500 RParenLoc);
2501 }
2502
Douglas Gregora16548e2009-08-11 05:31:07 +00002503 /// \brief Build a new C++ "this" expression.
2504 ///
2505 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002506 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002507 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002508 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002509 QualType ThisType,
2510 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002511 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002512 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002513 }
2514
2515 /// \brief Build a new C++ throw expression.
2516 ///
2517 /// By default, performs semantic analysis to build the new expression.
2518 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002519 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2520 bool IsThrownVariableInScope) {
2521 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002522 }
2523
2524 /// \brief Build a new C++ default-argument expression.
2525 ///
2526 /// By default, builds a new default-argument expression, which does not
2527 /// require any semantic analysis. Subclasses may override this routine to
2528 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002529 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002530 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002531 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002532 }
2533
Richard Smith852c9db2013-04-20 22:23:05 +00002534 /// \brief Build a new C++11 default-initialization expression.
2535 ///
2536 /// By default, builds a new default field initialization expression, which
2537 /// does not require any semantic analysis. Subclasses may override this
2538 /// routine to provide different behavior.
2539 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2540 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002541 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002542 }
2543
Douglas Gregora16548e2009-08-11 05:31:07 +00002544 /// \brief Build a new C++ zero-initialization expression.
2545 ///
2546 /// By default, performs semantic analysis to build the new expression.
2547 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002548 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2549 SourceLocation LParenLoc,
2550 SourceLocation RParenLoc) {
2551 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002552 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002553 }
Mike Stump11289f42009-09-09 15:08:12 +00002554
Douglas Gregora16548e2009-08-11 05:31:07 +00002555 /// \brief Build a new C++ "new" expression.
2556 ///
2557 /// By default, performs semantic analysis to build the new expression.
2558 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002559 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002560 bool UseGlobal,
2561 SourceLocation PlacementLParen,
2562 MultiExprArg PlacementArgs,
2563 SourceLocation PlacementRParen,
2564 SourceRange TypeIdParens,
2565 QualType AllocatedType,
2566 TypeSourceInfo *AllocatedTypeInfo,
2567 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002568 SourceRange DirectInitRange,
2569 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002570 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002571 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002572 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002573 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002574 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002575 AllocatedType,
2576 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002577 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002578 DirectInitRange,
2579 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002580 }
Mike Stump11289f42009-09-09 15:08:12 +00002581
Douglas Gregora16548e2009-08-11 05:31:07 +00002582 /// \brief Build a new C++ "delete" expression.
2583 ///
2584 /// By default, performs semantic analysis to build the new expression.
2585 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002586 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002587 bool IsGlobalDelete,
2588 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002589 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002590 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002591 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002592 }
Mike Stump11289f42009-09-09 15:08:12 +00002593
Douglas Gregor29c42f22012-02-24 07:38:34 +00002594 /// \brief Build a new type trait expression.
2595 ///
2596 /// By default, performs semantic analysis to build the new expression.
2597 /// Subclasses may override this routine to provide different behavior.
2598 ExprResult RebuildTypeTrait(TypeTrait Trait,
2599 SourceLocation StartLoc,
2600 ArrayRef<TypeSourceInfo *> Args,
2601 SourceLocation RParenLoc) {
2602 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2603 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002604
John Wiegley6242b6a2011-04-28 00:16:57 +00002605 /// \brief Build a new array type trait expression.
2606 ///
2607 /// By default, performs semantic analysis to build the new expression.
2608 /// Subclasses may override this routine to provide different behavior.
2609 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2610 SourceLocation StartLoc,
2611 TypeSourceInfo *TSInfo,
2612 Expr *DimExpr,
2613 SourceLocation RParenLoc) {
2614 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2615 }
2616
John Wiegleyf9f65842011-04-25 06:54:41 +00002617 /// \brief Build a new expression trait expression.
2618 ///
2619 /// By default, performs semantic analysis to build the new expression.
2620 /// Subclasses may override this routine to provide different behavior.
2621 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2622 SourceLocation StartLoc,
2623 Expr *Queried,
2624 SourceLocation RParenLoc) {
2625 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2626 }
2627
Mike Stump11289f42009-09-09 15:08:12 +00002628 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002629 /// expression.
2630 ///
2631 /// By default, performs semantic analysis to build the new expression.
2632 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002633 ExprResult RebuildDependentScopeDeclRefExpr(
2634 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002635 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002636 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002637 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002638 bool IsAddressOfOperand,
2639 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002640 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002641 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002642
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002643 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002644 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2645 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002646
Reid Kleckner32506ed2014-06-12 23:03:48 +00002647 return getSema().BuildQualifiedDeclarationNameExpr(
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002648 SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002649 }
2650
2651 /// \brief Build a new template-id expression.
2652 ///
2653 /// By default, performs semantic analysis to build the new expression.
2654 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002655 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002656 SourceLocation TemplateKWLoc,
2657 LookupResult &R,
2658 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002659 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002660 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2661 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002662 }
2663
2664 /// \brief Build a new object-construction expression.
2665 ///
2666 /// By default, performs semantic analysis to build the new expression.
2667 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002668 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002669 SourceLocation Loc,
2670 CXXConstructorDecl *Constructor,
2671 bool IsElidable,
2672 MultiExprArg Args,
2673 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002674 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002675 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002676 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002677 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002678 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002679 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002680 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002681 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002682 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002683
Richard Smithc83bf822016-06-10 00:58:19 +00002684 return getSema().BuildCXXConstructExpr(Loc, T, Constructor,
Richard Smithc2bebe92016-05-11 20:37:46 +00002685 IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002686 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002687 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002688 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002689 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002690 RequiresZeroInit, ConstructKind,
2691 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002692 }
2693
Richard Smith5179eb72016-06-28 19:03:57 +00002694 /// \brief Build a new implicit construction via inherited constructor
2695 /// expression.
2696 ExprResult RebuildCXXInheritedCtorInitExpr(QualType T, SourceLocation Loc,
2697 CXXConstructorDecl *Constructor,
2698 bool ConstructsVBase,
2699 bool InheritedFromVBase) {
2700 return new (getSema().Context) CXXInheritedCtorInitExpr(
2701 Loc, T, Constructor, ConstructsVBase, InheritedFromVBase);
2702 }
2703
Douglas Gregora16548e2009-08-11 05:31:07 +00002704 /// \brief Build a new object-construction expression.
2705 ///
2706 /// By default, performs semantic analysis to build the new expression.
2707 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002708 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2709 SourceLocation LParenLoc,
2710 MultiExprArg Args,
2711 SourceLocation RParenLoc) {
2712 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002713 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002714 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002715 RParenLoc);
2716 }
2717
2718 /// \brief Build a new object-construction expression.
2719 ///
2720 /// By default, performs semantic analysis to build the new expression.
2721 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002722 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2723 SourceLocation LParenLoc,
2724 MultiExprArg Args,
2725 SourceLocation RParenLoc) {
2726 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002727 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002728 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002729 RParenLoc);
2730 }
Mike Stump11289f42009-09-09 15:08:12 +00002731
Douglas Gregora16548e2009-08-11 05:31:07 +00002732 /// \brief Build a new member reference expression.
2733 ///
2734 /// By default, performs semantic analysis to build the new expression.
2735 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002736 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002737 QualType BaseType,
2738 bool IsArrow,
2739 SourceLocation OperatorLoc,
2740 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002741 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002742 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002743 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002744 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002745 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002746 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002747
John McCallb268a282010-08-23 23:25:46 +00002748 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002749 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002750 SS, TemplateKWLoc,
2751 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002752 MemberNameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002753 TemplateArgs, /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002754 }
2755
John McCall10eae182009-11-30 22:42:35 +00002756 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002757 ///
2758 /// By default, performs semantic analysis to build the new expression.
2759 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002760 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2761 SourceLocation OperatorLoc,
2762 bool IsArrow,
2763 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002764 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002765 NamedDecl *FirstQualifierInScope,
2766 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002767 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002768 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002769 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002770
John McCallb268a282010-08-23 23:25:46 +00002771 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002772 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002773 SS, TemplateKWLoc,
2774 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002775 R, TemplateArgs, /*S*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00002776 }
Mike Stump11289f42009-09-09 15:08:12 +00002777
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002778 /// \brief Build a new noexcept expression.
2779 ///
2780 /// By default, performs semantic analysis to build the new expression.
2781 /// Subclasses may override this routine to provide different behavior.
2782 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2783 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2784 }
2785
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002786 /// \brief Build a new expression to compute the length of a parameter pack.
Richard Smithd784e682015-09-23 21:41:42 +00002787 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc,
2788 NamedDecl *Pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00002789 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002790 SourceLocation RParenLoc,
Richard Smithd784e682015-09-23 21:41:42 +00002791 Optional<unsigned> Length,
2792 ArrayRef<TemplateArgument> PartialArgs) {
2793 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
2794 RParenLoc, Length, PartialArgs);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002795 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002796
Patrick Beard0caa3942012-04-19 00:25:12 +00002797 /// \brief Build a new Objective-C boxed expression.
2798 ///
2799 /// By default, performs semantic analysis to build the new expression.
2800 /// Subclasses may override this routine to provide different behavior.
2801 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2802 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2803 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002804
Ted Kremeneke65b0862012-03-06 20:05:56 +00002805 /// \brief Build a new Objective-C array literal.
2806 ///
2807 /// By default, performs semantic analysis to build the new expression.
2808 /// Subclasses may override this routine to provide different behavior.
2809 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2810 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002811 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002812 MultiExprArg(Elements, NumElements));
2813 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002814
2815 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002816 Expr *Base, Expr *Key,
2817 ObjCMethodDecl *getterMethod,
2818 ObjCMethodDecl *setterMethod) {
2819 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2820 getterMethod, setterMethod);
2821 }
2822
2823 /// \brief Build a new Objective-C dictionary literal.
2824 ///
2825 /// By default, performs semantic analysis to build the new expression.
2826 /// Subclasses may override this routine to provide different behavior.
2827 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
Craig Topperd4336e02015-12-24 23:58:15 +00002828 MutableArrayRef<ObjCDictionaryElement> Elements) {
2829 return getSema().BuildObjCDictionaryLiteral(Range, Elements);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002830 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002831
James Dennett2a4d13c2012-06-15 07:13:21 +00002832 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002833 ///
2834 /// By default, performs semantic analysis to build the new expression.
2835 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002836 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002837 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002838 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002839 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002840 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002841
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002842 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002843 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002844 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002845 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002846 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002847 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002848 MultiExprArg Args,
2849 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002850 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2851 ReceiverTypeInfo->getType(),
2852 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002853 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002854 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002855 }
2856
2857 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002858 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002859 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002860 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002861 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002862 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002863 MultiExprArg Args,
2864 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002865 return SemaRef.BuildInstanceMessage(Receiver,
2866 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002867 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002868 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002869 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002870 }
2871
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002872 /// \brief Build a new Objective-C instance/class message to 'super'.
2873 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
2874 Selector Sel,
2875 ArrayRef<SourceLocation> SelectorLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002876 QualType SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002877 ObjCMethodDecl *Method,
2878 SourceLocation LBracLoc,
2879 MultiExprArg Args,
2880 SourceLocation RBracLoc) {
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002881 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002882 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002883 SuperLoc,
2884 Sel, Method, LBracLoc, SelectorLocs,
2885 RBracLoc, Args)
2886 : SemaRef.BuildClassMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002887 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002888 SuperLoc,
2889 Sel, Method, LBracLoc, SelectorLocs,
2890 RBracLoc, Args);
2891
2892
2893 }
2894
Douglas Gregord51d90d2010-04-26 20:11:03 +00002895 /// \brief Build a new Objective-C ivar reference expression.
2896 ///
2897 /// By default, performs semantic analysis to build the new expression.
2898 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002899 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002900 SourceLocation IvarLoc,
2901 bool IsArrow, bool IsFreeIvar) {
2902 // FIXME: We lose track of the IsFreeIvar bit.
2903 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002904 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2905 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002906 /*FIXME:*/IvarLoc, IsArrow,
2907 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002908 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002909 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002910 /*TemplateArgs=*/nullptr,
2911 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002912 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002913
2914 /// \brief Build a new Objective-C property reference expression.
2915 ///
2916 /// By default, performs semantic analysis to build the new expression.
2917 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002918 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002919 ObjCPropertyDecl *Property,
2920 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002921 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002922 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2923 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2924 /*FIXME:*/PropertyLoc,
2925 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002926 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002927 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002928 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002929 /*TemplateArgs=*/nullptr,
2930 /*S=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002931 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002932
John McCallb7bd14f2010-12-02 01:19:52 +00002933 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002934 ///
2935 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002936 /// Subclasses may override this routine to provide different behavior.
2937 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2938 ObjCMethodDecl *Getter,
2939 ObjCMethodDecl *Setter,
2940 SourceLocation PropertyLoc) {
2941 // Since these expressions can only be value-dependent, we do not
2942 // need to perform semantic analysis again.
2943 return Owned(
2944 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2945 VK_LValue, OK_ObjCProperty,
2946 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002947 }
2948
Douglas Gregord51d90d2010-04-26 20:11:03 +00002949 /// \brief Build a new Objective-C "isa" expression.
2950 ///
2951 /// By default, performs semantic analysis to build the new expression.
2952 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002953 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00002954 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00002955 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002956 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2957 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002958 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002959 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002960 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002961 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002962 /*TemplateArgs=*/nullptr,
2963 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002964 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002965
Douglas Gregora16548e2009-08-11 05:31:07 +00002966 /// \brief Build a new shuffle vector expression.
2967 ///
2968 /// By default, performs semantic analysis to build the new expression.
2969 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002970 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002971 MultiExprArg SubExprs,
2972 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002973 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002974 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002975 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2976 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2977 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002978 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002979
Douglas Gregora16548e2009-08-11 05:31:07 +00002980 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002981 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002982 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2983 SemaRef.Context.BuiltinFnTy,
2984 VK_RValue, BuiltinLoc);
2985 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2986 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002987 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00002988
2989 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002990 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00002991 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002992 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002993
Douglas Gregora16548e2009-08-11 05:31:07 +00002994 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002995 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002996 }
John McCall31f82722010-11-12 08:19:04 +00002997
Hal Finkelc4d7c822013-09-18 03:29:45 +00002998 /// \brief Build a new convert vector expression.
2999 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
3000 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
3001 SourceLocation RParenLoc) {
3002 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
3003 BuiltinLoc, RParenLoc);
3004 }
3005
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003006 /// \brief Build a new template argument pack expansion.
3007 ///
3008 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00003009 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003010 /// different behavior.
3011 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003012 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00003013 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003014 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00003015 case TemplateArgument::Expression: {
3016 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00003017 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
3018 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00003019 if (Result.isInvalid())
3020 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003021
Douglas Gregor98318c22011-01-03 21:37:45 +00003022 return TemplateArgumentLoc(Result.get(), Result.get());
3023 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003024
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003025 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003026 return TemplateArgumentLoc(TemplateArgument(
3027 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00003028 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00003029 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003030 Pattern.getTemplateNameLoc(),
3031 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003032
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003033 case TemplateArgument::Null:
3034 case TemplateArgument::Integral:
3035 case TemplateArgument::Declaration:
3036 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003037 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00003038 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003039 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00003040
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003041 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00003042 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003043 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003044 EllipsisLoc,
3045 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003046 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
3047 Expansion);
3048 break;
3049 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003050
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003051 return TemplateArgumentLoc();
3052 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003053
Douglas Gregor968f23a2011-01-03 19:31:53 +00003054 /// \brief Build a new expression pack expansion.
3055 ///
3056 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00003057 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00003058 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00003059 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00003060 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00003061 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003062 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003063
Richard Smith0f0af192014-11-08 05:07:16 +00003064 /// \brief Build a new C++1z fold-expression.
3065 ///
3066 /// By default, performs semantic analysis in order to build a new fold
3067 /// expression.
3068 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
3069 BinaryOperatorKind Operator,
3070 SourceLocation EllipsisLoc, Expr *RHS,
3071 SourceLocation RParenLoc) {
3072 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
3073 RHS, RParenLoc);
3074 }
3075
3076 /// \brief Build an empty C++1z fold-expression with the given operator.
3077 ///
3078 /// By default, produces the fallback value for the fold-expression, or
3079 /// produce an error if there is no fallback value.
3080 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
3081 BinaryOperatorKind Operator) {
3082 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
3083 }
3084
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003085 /// \brief Build a new atomic operation expression.
3086 ///
3087 /// By default, performs semantic analysis to build the new expression.
3088 /// Subclasses may override this routine to provide different behavior.
3089 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
3090 MultiExprArg SubExprs,
3091 QualType RetTy,
3092 AtomicExpr::AtomicOp Op,
3093 SourceLocation RParenLoc) {
3094 // Just create the expression; there is not any interesting semantic
3095 // analysis here because we can't actually build an AtomicExpr until
3096 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00003097 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003098 RParenLoc);
3099 }
3100
John McCall31f82722010-11-12 08:19:04 +00003101private:
Douglas Gregor14454802011-02-25 02:25:35 +00003102 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
3103 QualType ObjectType,
3104 NamedDecl *FirstQualifierInScope,
3105 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003106
3107 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3108 QualType ObjectType,
3109 NamedDecl *FirstQualifierInScope,
3110 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003111
3112 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
3113 NamedDecl *FirstQualifierInScope,
3114 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003115};
Douglas Gregora16548e2009-08-11 05:31:07 +00003116
Douglas Gregorebe10102009-08-20 07:17:43 +00003117template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003118StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003119 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003120 return S;
Mike Stump11289f42009-09-09 15:08:12 +00003121
Douglas Gregorebe10102009-08-20 07:17:43 +00003122 switch (S->getStmtClass()) {
3123 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00003124
Douglas Gregorebe10102009-08-20 07:17:43 +00003125 // Transform individual statement nodes
3126#define STMT(Node, Parent) \
3127 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00003128#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00003129#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00003130#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003131
Douglas Gregorebe10102009-08-20 07:17:43 +00003132 // Transform expressions by calling TransformExpr.
3133#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00003134#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00003135#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00003136#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00003137 {
John McCalldadc5752010-08-24 06:29:42 +00003138 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00003139 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003140 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003141
Richard Smith945f8d32013-01-14 22:39:08 +00003142 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00003143 }
Mike Stump11289f42009-09-09 15:08:12 +00003144 }
3145
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003146 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00003147}
Mike Stump11289f42009-09-09 15:08:12 +00003148
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00003149template<typename Derived>
3150OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
3151 if (!S)
3152 return S;
3153
3154 switch (S->getClauseKind()) {
3155 default: break;
3156 // Transform individual clause nodes
3157#define OPENMP_CLAUSE(Name, Class) \
3158 case OMPC_ ## Name : \
3159 return getDerived().Transform ## Class(cast<Class>(S));
3160#include "clang/Basic/OpenMPKinds.def"
3161 }
3162
3163 return S;
3164}
3165
Mike Stump11289f42009-09-09 15:08:12 +00003166
Douglas Gregore922c772009-08-04 22:27:00 +00003167template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003168ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003169 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003170 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00003171
3172 switch (E->getStmtClass()) {
3173 case Stmt::NoStmtClass: break;
3174#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00003175#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00003176#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00003177 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00003178#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003179 }
3180
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003181 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00003182}
3183
3184template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00003185ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00003186 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00003187 // Initializers are instantiated like expressions, except that various outer
3188 // layers are stripped.
3189 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003190 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00003191
3192 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
3193 Init = ExprTemp->getSubExpr();
3194
Richard Smithe6ca4752013-05-30 22:40:16 +00003195 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
3196 Init = MTE->GetTemporaryExpr();
3197
Richard Smithd59b8322012-12-19 01:39:02 +00003198 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
3199 Init = Binder->getSubExpr();
3200
3201 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
3202 Init = ICE->getSubExprAsWritten();
3203
Richard Smithcc1b96d2013-06-12 22:31:48 +00003204 if (CXXStdInitializerListExpr *ILE =
3205 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00003206 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00003207
Richard Smithc6abd962014-07-25 01:12:44 +00003208 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00003209 // InitListExprs. Other forms of copy-initialization will be a no-op if
3210 // the initializer is already the right type.
3211 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00003212 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00003213 return getDerived().TransformExpr(Init);
3214
3215 // Revert value-initialization back to empty parens.
3216 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
3217 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003218 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003219 Parens.getEnd());
3220 }
3221
3222 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3223 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003224 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003225 SourceLocation());
3226
3227 // Revert initialization by constructor back to a parenthesized or braced list
3228 // of expressions. Any other form of initializer can just be reused directly.
3229 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00003230 return getDerived().TransformExpr(Init);
3231
Richard Smithf8adcdc2014-07-17 05:12:35 +00003232 // If the initialization implicitly converted an initializer list to a
3233 // std::initializer_list object, unwrap the std::initializer_list too.
3234 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00003235 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00003236
Richard Smithd59b8322012-12-19 01:39:02 +00003237 SmallVector<Expr*, 8> NewArgs;
3238 bool ArgChanged = false;
3239 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00003240 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00003241 return ExprError();
3242
3243 // If this was list initialization, revert to list form.
3244 if (Construct->isListInitialization())
3245 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
3246 Construct->getLocEnd(),
3247 Construct->getType());
3248
Richard Smithd59b8322012-12-19 01:39:02 +00003249 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00003250 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00003251 if (Parens.isInvalid()) {
3252 // This was a variable declaration's initialization for which no initializer
3253 // was specified.
3254 assert(NewArgs.empty() &&
3255 "no parens or braces but have direct init with arguments?");
3256 return ExprEmpty();
3257 }
Richard Smithd59b8322012-12-19 01:39:02 +00003258 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3259 Parens.getEnd());
3260}
3261
3262template<typename Derived>
Craig Topper99d23532015-12-24 23:58:29 +00003263bool TreeTransform<Derived>::TransformExprs(Expr *const *Inputs,
Chad Rosier1dcde962012-08-08 18:46:20 +00003264 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003265 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003266 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003267 bool *ArgChanged) {
3268 for (unsigned I = 0; I != NumInputs; ++I) {
3269 // If requested, drop call arguments that need to be dropped.
3270 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3271 if (ArgChanged)
3272 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003273
Douglas Gregora3efea12011-01-03 19:04:46 +00003274 break;
3275 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003276
Douglas Gregor968f23a2011-01-03 19:31:53 +00003277 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3278 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00003279
Chris Lattner01cf8db2011-07-20 06:58:45 +00003280 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003281 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3282 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003283
Douglas Gregor968f23a2011-01-03 19:31:53 +00003284 // Determine whether the set of unexpanded parameter packs can and should
3285 // be expanded.
3286 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003287 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003288 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3289 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003290 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3291 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003292 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003293 Expand, RetainExpansion,
3294 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00003295 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003296
Douglas Gregor968f23a2011-01-03 19:31:53 +00003297 if (!Expand) {
3298 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003299 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00003300 // expansion.
3301 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3302 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3303 if (OutPattern.isInvalid())
3304 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003305
3306 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00003307 Expansion->getEllipsisLoc(),
3308 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003309 if (Out.isInvalid())
3310 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003311
Douglas Gregor968f23a2011-01-03 19:31:53 +00003312 if (ArgChanged)
3313 *ArgChanged = true;
3314 Outputs.push_back(Out.get());
3315 continue;
3316 }
John McCall542e7c62011-07-06 07:30:07 +00003317
3318 // Record right away that the argument was changed. This needs
3319 // to happen even if the array expands to nothing.
3320 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003321
Douglas Gregor968f23a2011-01-03 19:31:53 +00003322 // The transform has determined that we should perform an elementwise
3323 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003324 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00003325 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3326 ExprResult Out = getDerived().TransformExpr(Pattern);
3327 if (Out.isInvalid())
3328 return true;
3329
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003330 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003331 Out = getDerived().RebuildPackExpansion(
3332 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003333 if (Out.isInvalid())
3334 return true;
3335 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003336
Douglas Gregor968f23a2011-01-03 19:31:53 +00003337 Outputs.push_back(Out.get());
3338 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003339
Richard Smith9467be42014-06-06 17:33:35 +00003340 // If we're supposed to retain a pack expansion, do so by temporarily
3341 // forgetting the partially-substituted parameter pack.
3342 if (RetainExpansion) {
3343 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3344
3345 ExprResult Out = getDerived().TransformExpr(Pattern);
3346 if (Out.isInvalid())
3347 return true;
3348
3349 Out = getDerived().RebuildPackExpansion(
3350 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3351 if (Out.isInvalid())
3352 return true;
3353
3354 Outputs.push_back(Out.get());
3355 }
3356
Douglas Gregor968f23a2011-01-03 19:31:53 +00003357 continue;
3358 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003359
Richard Smithd59b8322012-12-19 01:39:02 +00003360 ExprResult Result =
3361 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3362 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003363 if (Result.isInvalid())
3364 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003365
Douglas Gregora3efea12011-01-03 19:04:46 +00003366 if (Result.get() != Inputs[I] && ArgChanged)
3367 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003368
3369 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003370 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003371
Douglas Gregora3efea12011-01-03 19:04:46 +00003372 return false;
3373}
3374
Richard Smith03a4aa32016-06-23 19:02:52 +00003375template <typename Derived>
3376Sema::ConditionResult TreeTransform<Derived>::TransformCondition(
3377 SourceLocation Loc, VarDecl *Var, Expr *Expr, Sema::ConditionKind Kind) {
3378 if (Var) {
3379 VarDecl *ConditionVar = cast_or_null<VarDecl>(
3380 getDerived().TransformDefinition(Var->getLocation(), Var));
3381
3382 if (!ConditionVar)
3383 return Sema::ConditionError();
3384
3385 return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
3386 }
3387
3388 if (Expr) {
3389 ExprResult CondExpr = getDerived().TransformExpr(Expr);
3390
3391 if (CondExpr.isInvalid())
3392 return Sema::ConditionError();
3393
3394 return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind);
3395 }
3396
3397 return Sema::ConditionResult();
3398}
3399
Douglas Gregora3efea12011-01-03 19:04:46 +00003400template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003401NestedNameSpecifierLoc
3402TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3403 NestedNameSpecifierLoc NNS,
3404 QualType ObjectType,
3405 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003406 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003407 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003408 Qualifier = Qualifier.getPrefix())
3409 Qualifiers.push_back(Qualifier);
3410
3411 CXXScopeSpec SS;
3412 while (!Qualifiers.empty()) {
3413 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3414 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003415
Douglas Gregor14454802011-02-25 02:25:35 +00003416 switch (QNNS->getKind()) {
3417 case NestedNameSpecifier::Identifier:
Craig Topperc3ec1492014-05-26 06:22:03 +00003418 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
Douglas Gregor14454802011-02-25 02:25:35 +00003419 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003420 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003421 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003422 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00003423 FirstQualifierInScope, false))
3424 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003425
Douglas Gregor14454802011-02-25 02:25:35 +00003426 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003427
Douglas Gregor14454802011-02-25 02:25:35 +00003428 case NestedNameSpecifier::Namespace: {
3429 NamespaceDecl *NS
3430 = cast_or_null<NamespaceDecl>(
3431 getDerived().TransformDecl(
3432 Q.getLocalBeginLoc(),
3433 QNNS->getAsNamespace()));
3434 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3435 break;
3436 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003437
Douglas Gregor14454802011-02-25 02:25:35 +00003438 case NestedNameSpecifier::NamespaceAlias: {
3439 NamespaceAliasDecl *Alias
3440 = cast_or_null<NamespaceAliasDecl>(
3441 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3442 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003443 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003444 Q.getLocalEndLoc());
3445 break;
3446 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003447
Douglas Gregor14454802011-02-25 02:25:35 +00003448 case NestedNameSpecifier::Global:
3449 // There is no meaningful transformation that one could perform on the
3450 // global scope.
3451 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3452 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003453
Nikola Smiljanic67860242014-09-26 00:28:20 +00003454 case NestedNameSpecifier::Super: {
3455 CXXRecordDecl *RD =
3456 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3457 SourceLocation(), QNNS->getAsRecordDecl()));
3458 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3459 break;
3460 }
3461
Douglas Gregor14454802011-02-25 02:25:35 +00003462 case NestedNameSpecifier::TypeSpecWithTemplate:
3463 case NestedNameSpecifier::TypeSpec: {
3464 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3465 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003466
Douglas Gregor14454802011-02-25 02:25:35 +00003467 if (!TL)
3468 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003469
Douglas Gregor14454802011-02-25 02:25:35 +00003470 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003471 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003472 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003473 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003474 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003475 if (TL.getType()->isEnumeralType())
3476 SemaRef.Diag(TL.getBeginLoc(),
3477 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003478 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3479 Q.getLocalEndLoc());
3480 break;
3481 }
Richard Trieude756fb2011-05-07 01:36:37 +00003482 // If the nested-name-specifier is an invalid type def, don't emit an
3483 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003484 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3485 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003486 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003487 << TL.getType() << SS.getRange();
3488 }
Douglas Gregor14454802011-02-25 02:25:35 +00003489 return NestedNameSpecifierLoc();
3490 }
Douglas Gregore16af532011-02-28 18:50:33 +00003491 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003492
Douglas Gregore16af532011-02-28 18:50:33 +00003493 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003494 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003495 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003496 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003497
Douglas Gregor14454802011-02-25 02:25:35 +00003498 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003499 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003500 !getDerived().AlwaysRebuild())
3501 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003502
3503 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003504 // nested-name-specifier, do so.
3505 if (SS.location_size() == NNS.getDataLength() &&
3506 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3507 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3508
3509 // Allocate new nested-name-specifier location information.
3510 return SS.getWithLocInContext(SemaRef.Context);
3511}
3512
3513template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003514DeclarationNameInfo
3515TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003516::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003517 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003518 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003519 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003520
3521 switch (Name.getNameKind()) {
3522 case DeclarationName::Identifier:
3523 case DeclarationName::ObjCZeroArgSelector:
3524 case DeclarationName::ObjCOneArgSelector:
3525 case DeclarationName::ObjCMultiArgSelector:
3526 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003527 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003528 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003529 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003530
Douglas Gregorf816bd72009-09-03 22:13:48 +00003531 case DeclarationName::CXXConstructorName:
3532 case DeclarationName::CXXDestructorName:
3533 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003534 TypeSourceInfo *NewTInfo;
3535 CanQualType NewCanTy;
3536 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003537 NewTInfo = getDerived().TransformType(OldTInfo);
3538 if (!NewTInfo)
3539 return DeclarationNameInfo();
3540 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003541 }
3542 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003543 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003544 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003545 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003546 if (NewT.isNull())
3547 return DeclarationNameInfo();
3548 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3549 }
Mike Stump11289f42009-09-09 15:08:12 +00003550
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003551 DeclarationName NewName
3552 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3553 NewCanTy);
3554 DeclarationNameInfo NewNameInfo(NameInfo);
3555 NewNameInfo.setName(NewName);
3556 NewNameInfo.setNamedTypeInfo(NewTInfo);
3557 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003558 }
Mike Stump11289f42009-09-09 15:08:12 +00003559 }
3560
David Blaikie83d382b2011-09-23 05:06:16 +00003561 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003562}
3563
3564template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003565TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003566TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3567 TemplateName Name,
3568 SourceLocation NameLoc,
3569 QualType ObjectType,
3570 NamedDecl *FirstQualifierInScope) {
3571 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3572 TemplateDecl *Template = QTN->getTemplateDecl();
3573 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003574
Douglas Gregor9db53502011-03-02 18:07:45 +00003575 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003576 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003577 Template));
3578 if (!TransTemplate)
3579 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003580
Douglas Gregor9db53502011-03-02 18:07:45 +00003581 if (!getDerived().AlwaysRebuild() &&
3582 SS.getScopeRep() == QTN->getQualifier() &&
3583 TransTemplate == Template)
3584 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003585
Douglas Gregor9db53502011-03-02 18:07:45 +00003586 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3587 TransTemplate);
3588 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003589
Douglas Gregor9db53502011-03-02 18:07:45 +00003590 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3591 if (SS.getScopeRep()) {
3592 // These apply to the scope specifier, not the template.
3593 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003594 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003595 }
3596
Douglas Gregor9db53502011-03-02 18:07:45 +00003597 if (!getDerived().AlwaysRebuild() &&
3598 SS.getScopeRep() == DTN->getQualifier() &&
3599 ObjectType.isNull())
3600 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003601
Douglas Gregor9db53502011-03-02 18:07:45 +00003602 if (DTN->isIdentifier()) {
3603 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003604 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003605 NameLoc,
3606 ObjectType,
3607 FirstQualifierInScope);
3608 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003609
Douglas Gregor9db53502011-03-02 18:07:45 +00003610 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3611 ObjectType);
3612 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003613
Douglas Gregor9db53502011-03-02 18:07:45 +00003614 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3615 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003616 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003617 Template));
3618 if (!TransTemplate)
3619 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003620
Douglas Gregor9db53502011-03-02 18:07:45 +00003621 if (!getDerived().AlwaysRebuild() &&
3622 TransTemplate == Template)
3623 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003624
Douglas Gregor9db53502011-03-02 18:07:45 +00003625 return TemplateName(TransTemplate);
3626 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003627
Douglas Gregor9db53502011-03-02 18:07:45 +00003628 if (SubstTemplateTemplateParmPackStorage *SubstPack
3629 = Name.getAsSubstTemplateTemplateParmPack()) {
3630 TemplateTemplateParmDecl *TransParam
3631 = cast_or_null<TemplateTemplateParmDecl>(
3632 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3633 if (!TransParam)
3634 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003635
Douglas Gregor9db53502011-03-02 18:07:45 +00003636 if (!getDerived().AlwaysRebuild() &&
3637 TransParam == SubstPack->getParameterPack())
3638 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003639
3640 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003641 SubstPack->getArgumentPack());
3642 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003643
Douglas Gregor9db53502011-03-02 18:07:45 +00003644 // These should be getting filtered out before they reach the AST.
3645 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003646}
3647
3648template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003649void TreeTransform<Derived>::InventTemplateArgumentLoc(
3650 const TemplateArgument &Arg,
3651 TemplateArgumentLoc &Output) {
3652 SourceLocation Loc = getDerived().getBaseLocation();
3653 switch (Arg.getKind()) {
3654 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003655 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003656 break;
3657
3658 case TemplateArgument::Type:
3659 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003660 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003661
John McCall0ad16662009-10-29 08:12:44 +00003662 break;
3663
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003664 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003665 case TemplateArgument::TemplateExpansion: {
3666 NestedNameSpecifierLocBuilder Builder;
Manuel Klimek4c67fa72016-01-11 11:39:00 +00003667 TemplateName Template = Arg.getAsTemplateOrTemplatePattern();
Douglas Gregor9d802122011-03-02 17:09:35 +00003668 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3669 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3670 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3671 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003672
Douglas Gregor9d802122011-03-02 17:09:35 +00003673 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003674 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003675 Builder.getWithLocInContext(SemaRef.Context),
3676 Loc);
3677 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003678 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003679 Builder.getWithLocInContext(SemaRef.Context),
3680 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003681
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003682 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003683 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003684
John McCall0ad16662009-10-29 08:12:44 +00003685 case TemplateArgument::Expression:
3686 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3687 break;
3688
3689 case TemplateArgument::Declaration:
3690 case TemplateArgument::Integral:
3691 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003692 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003693 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003694 break;
3695 }
3696}
3697
3698template<typename Derived>
3699bool TreeTransform<Derived>::TransformTemplateArgument(
3700 const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +00003701 TemplateArgumentLoc &Output, bool Uneval) {
John McCall0ad16662009-10-29 08:12:44 +00003702 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003703 switch (Arg.getKind()) {
3704 case TemplateArgument::Null:
3705 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003706 case TemplateArgument::Pack:
3707 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003708 case TemplateArgument::NullPtr:
3709 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003710
Douglas Gregore922c772009-08-04 22:27:00 +00003711 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003712 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003713 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003714 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003715
3716 DI = getDerived().TransformType(DI);
3717 if (!DI) return true;
3718
3719 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3720 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003721 }
Mike Stump11289f42009-09-09 15:08:12 +00003722
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003723 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003724 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3725 if (QualifierLoc) {
3726 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3727 if (!QualifierLoc)
3728 return true;
3729 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003730
Douglas Gregordf846d12011-03-02 18:46:51 +00003731 CXXScopeSpec SS;
3732 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003733 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003734 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3735 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003736 if (Template.isNull())
3737 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003738
Douglas Gregor9d802122011-03-02 17:09:35 +00003739 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003740 Input.getTemplateNameLoc());
3741 return false;
3742 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003743
3744 case TemplateArgument::TemplateExpansion:
3745 llvm_unreachable("Caller should expand pack expansions");
3746
Douglas Gregore922c772009-08-04 22:27:00 +00003747 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003748 // Template argument expressions are constant expressions.
Richard Smithd784e682015-09-23 21:41:42 +00003749 EnterExpressionEvaluationContext Unevaluated(
3750 getSema(), Uneval ? Sema::Unevaluated : Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003751
John McCall0ad16662009-10-29 08:12:44 +00003752 Expr *InputExpr = Input.getSourceExpression();
3753 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3754
Chris Lattnercdb591a2011-04-25 20:37:58 +00003755 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003756 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003757 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003758 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003759 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003760 }
Douglas Gregore922c772009-08-04 22:27:00 +00003761 }
Mike Stump11289f42009-09-09 15:08:12 +00003762
Douglas Gregore922c772009-08-04 22:27:00 +00003763 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003764 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003765}
3766
Douglas Gregorfe921a72010-12-20 23:36:19 +00003767/// \brief Iterator adaptor that invents template argument location information
3768/// for each of the template arguments in its underlying iterator.
3769template<typename Derived, typename InputIterator>
3770class TemplateArgumentLocInventIterator {
3771 TreeTransform<Derived> &Self;
3772 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003773
Douglas Gregorfe921a72010-12-20 23:36:19 +00003774public:
3775 typedef TemplateArgumentLoc value_type;
3776 typedef TemplateArgumentLoc reference;
3777 typedef typename std::iterator_traits<InputIterator>::difference_type
3778 difference_type;
3779 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003780
Douglas Gregorfe921a72010-12-20 23:36:19 +00003781 class pointer {
3782 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003783
Douglas Gregorfe921a72010-12-20 23:36:19 +00003784 public:
3785 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003786
Douglas Gregorfe921a72010-12-20 23:36:19 +00003787 const TemplateArgumentLoc *operator->() const { return &Arg; }
3788 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003789
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00003790 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003791
Douglas Gregorfe921a72010-12-20 23:36:19 +00003792 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3793 InputIterator Iter)
3794 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003795
Douglas Gregorfe921a72010-12-20 23:36:19 +00003796 TemplateArgumentLocInventIterator &operator++() {
3797 ++Iter;
3798 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003799 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003800
Douglas Gregorfe921a72010-12-20 23:36:19 +00003801 TemplateArgumentLocInventIterator operator++(int) {
3802 TemplateArgumentLocInventIterator Old(*this);
3803 ++(*this);
3804 return Old;
3805 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003806
Douglas Gregorfe921a72010-12-20 23:36:19 +00003807 reference operator*() const {
3808 TemplateArgumentLoc Result;
3809 Self.InventTemplateArgumentLoc(*Iter, Result);
3810 return Result;
3811 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003812
Douglas Gregorfe921a72010-12-20 23:36:19 +00003813 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003814
Douglas Gregorfe921a72010-12-20 23:36:19 +00003815 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3816 const TemplateArgumentLocInventIterator &Y) {
3817 return X.Iter == Y.Iter;
3818 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003819
Douglas Gregorfe921a72010-12-20 23:36:19 +00003820 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3821 const TemplateArgumentLocInventIterator &Y) {
3822 return X.Iter != Y.Iter;
3823 }
3824};
Chad Rosier1dcde962012-08-08 18:46:20 +00003825
Douglas Gregor42cafa82010-12-20 17:42:22 +00003826template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003827template<typename InputIterator>
Richard Smithd784e682015-09-23 21:41:42 +00003828bool TreeTransform<Derived>::TransformTemplateArguments(
3829 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
3830 bool Uneval) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003831 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003832 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003833 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003834
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003835 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3836 // Unpack argument packs, which we translate them into separate
3837 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003838 // FIXME: We could do much better if we could guarantee that the
3839 // TemplateArgumentLocInfo for the pack expansion would be usable for
3840 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003841 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003842 TemplateArgument::pack_iterator>
3843 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003844 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003845 In.getArgument().pack_begin()),
3846 PackLocIterator(*this,
3847 In.getArgument().pack_end()),
Richard Smithd784e682015-09-23 21:41:42 +00003848 Outputs, Uneval))
Douglas Gregorfe921a72010-12-20 23:36:19 +00003849 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003850
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003851 continue;
3852 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003853
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003854 if (In.getArgument().isPackExpansion()) {
3855 // We have a pack expansion, for which we will be substituting into
3856 // the pattern.
3857 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003858 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003859 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003860 = getSema().getTemplateArgumentPackExpansionPattern(
3861 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003862
Chris Lattner01cf8db2011-07-20 06:58:45 +00003863 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003864 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3865 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003866
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003867 // Determine whether the set of unexpanded parameter packs can and should
3868 // be expanded.
3869 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003870 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003871 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003872 if (getDerived().TryExpandParameterPacks(Ellipsis,
3873 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003874 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003875 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003876 RetainExpansion,
3877 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003878 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003879
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003880 if (!Expand) {
3881 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003882 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003883 // expansion.
3884 TemplateArgumentLoc OutPattern;
3885 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Richard Smithd784e682015-09-23 21:41:42 +00003886 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003887 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003888
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003889 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3890 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003891 if (Out.getArgument().isNull())
3892 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003893
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003894 Outputs.addArgument(Out);
3895 continue;
3896 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003897
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003898 // The transform has determined that we should perform an elementwise
3899 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003900 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003901 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3902
Richard Smithd784e682015-09-23 21:41:42 +00003903 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003904 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003905
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003906 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003907 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3908 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003909 if (Out.getArgument().isNull())
3910 return true;
3911 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003912
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003913 Outputs.addArgument(Out);
3914 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003915
Douglas Gregor48d24112011-01-10 20:53:55 +00003916 // If we're supposed to retain a pack expansion, do so by temporarily
3917 // forgetting the partially-substituted parameter pack.
3918 if (RetainExpansion) {
3919 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003920
Richard Smithd784e682015-09-23 21:41:42 +00003921 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor48d24112011-01-10 20:53:55 +00003922 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003923
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003924 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3925 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003926 if (Out.getArgument().isNull())
3927 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003928
Douglas Gregor48d24112011-01-10 20:53:55 +00003929 Outputs.addArgument(Out);
3930 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003931
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003932 continue;
3933 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003934
3935 // The simple case:
Richard Smithd784e682015-09-23 21:41:42 +00003936 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003937 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003938
Douglas Gregor42cafa82010-12-20 17:42:22 +00003939 Outputs.addArgument(Out);
3940 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003941
Douglas Gregor42cafa82010-12-20 17:42:22 +00003942 return false;
3943
3944}
3945
Douglas Gregord6ff3322009-08-04 16:50:30 +00003946//===----------------------------------------------------------------------===//
3947// Type transformation
3948//===----------------------------------------------------------------------===//
3949
3950template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003951QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003952 if (getDerived().AlreadyTransformed(T))
3953 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003954
John McCall550e0c22009-10-21 00:40:46 +00003955 // Temporary workaround. All of these transformations should
3956 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003957 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3958 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003959
John McCall31f82722010-11-12 08:19:04 +00003960 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003961
John McCall550e0c22009-10-21 00:40:46 +00003962 if (!NewDI)
3963 return QualType();
3964
3965 return NewDI->getType();
3966}
3967
3968template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003969TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003970 // Refine the base location to the type's location.
3971 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3972 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003973 if (getDerived().AlreadyTransformed(DI->getType()))
3974 return DI;
3975
3976 TypeLocBuilder TLB;
3977
3978 TypeLoc TL = DI->getTypeLoc();
3979 TLB.reserve(TL.getFullDataSize());
3980
John McCall31f82722010-11-12 08:19:04 +00003981 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003982 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003983 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00003984
John McCallbcd03502009-12-07 02:54:59 +00003985 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003986}
3987
3988template<typename Derived>
3989QualType
John McCall31f82722010-11-12 08:19:04 +00003990TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003991 switch (T.getTypeLocClass()) {
3992#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003993#define TYPELOC(CLASS, PARENT) \
3994 case TypeLoc::CLASS: \
3995 return getDerived().Transform##CLASS##Type(TLB, \
3996 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003997#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003998 }
Mike Stump11289f42009-09-09 15:08:12 +00003999
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00004000 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00004001}
4002
4003/// FIXME: By default, this routine adds type qualifiers only to types
4004/// that can have qualifiers, and silently suppresses those qualifiers
4005/// that are not permitted (e.g., qualifiers on reference or function
4006/// types). This is the right thing for template instantiation, but
4007/// probably not for other clients.
4008template<typename Derived>
4009QualType
4010TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004011 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00004012 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00004013
John McCall31f82722010-11-12 08:19:04 +00004014 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00004015 if (Result.isNull())
4016 return QualType();
4017
4018 // Silently suppress qualifiers if the result type can't be qualified.
4019 // FIXME: this is the right thing for template instantiation, but
4020 // probably not for other clients.
4021 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00004022 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00004023
John McCall31168b02011-06-15 23:02:42 +00004024 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00004025 // resulting type.
4026 if (Quals.hasObjCLifetime()) {
4027 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
4028 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00004029 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004030 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00004031 // A lifetime qualifier applied to a substituted template parameter
4032 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00004033 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00004034 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00004035 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
4036 QualType Replacement = SubstTypeParam->getReplacementType();
4037 Qualifiers Qs = Replacement.getQualifiers();
4038 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00004039 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00004040 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
4041 Qs);
4042 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00004043 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00004044 Replacement);
4045 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00004046 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
4047 // 'auto' types behave the same way as template parameters.
4048 QualType Deduced = AutoTy->getDeducedType();
4049 Qualifiers Qs = Deduced.getQualifiers();
4050 Qs.removeObjCLifetime();
4051 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
4052 Qs);
Richard Smithe301ba22015-11-11 02:02:15 +00004053 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
Faisal Vali2b391ab2013-09-26 19:54:12 +00004054 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00004055 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00004056 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00004057 // Otherwise, complain about the addition of a qualifier to an
4058 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00004059 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00004060 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00004061 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00004062
Douglas Gregore46db902011-06-17 22:11:49 +00004063 Quals.removeObjCLifetime();
4064 }
4065 }
4066 }
John McCallcb0f89a2010-06-05 06:41:15 +00004067 if (!Quals.empty()) {
4068 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00004069 // BuildQualifiedType might not add qualifiers if they are invalid.
4070 if (Result.hasLocalQualifiers())
4071 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00004072 // No location information to preserve.
4073 }
John McCall550e0c22009-10-21 00:40:46 +00004074
4075 return Result;
4076}
4077
Douglas Gregor14454802011-02-25 02:25:35 +00004078template<typename Derived>
4079TypeLoc
4080TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
4081 QualType ObjectType,
4082 NamedDecl *UnqualLookup,
4083 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004084 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00004085 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00004086
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004087 TypeSourceInfo *TSI =
4088 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
4089 if (TSI)
4090 return TSI->getTypeLoc();
4091 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00004092}
4093
Douglas Gregor579c15f2011-03-02 18:32:08 +00004094template<typename Derived>
4095TypeSourceInfo *
4096TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4097 QualType ObjectType,
4098 NamedDecl *UnqualLookup,
4099 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004100 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00004101 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00004102
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004103 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
4104 UnqualLookup, SS);
4105}
4106
4107template <typename Derived>
4108TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
4109 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
4110 CXXScopeSpec &SS) {
4111 QualType T = TL.getType();
4112 assert(!getDerived().AlreadyTransformed(T));
4113
Douglas Gregor579c15f2011-03-02 18:32:08 +00004114 TypeLocBuilder TLB;
4115 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00004116
Douglas Gregor579c15f2011-03-02 18:32:08 +00004117 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004118 TemplateSpecializationTypeLoc SpecTL =
4119 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004120
Douglas Gregor579c15f2011-03-02 18:32:08 +00004121 TemplateName Template
4122 = getDerived().TransformTemplateName(SS,
4123 SpecTL.getTypePtr()->getTemplateName(),
4124 SpecTL.getTemplateNameLoc(),
4125 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00004126 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004127 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004128
4129 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004130 Template);
4131 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004132 DependentTemplateSpecializationTypeLoc SpecTL =
4133 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004134
Douglas Gregor579c15f2011-03-02 18:32:08 +00004135 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00004136 = getDerived().RebuildTemplateName(SS,
4137 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004138 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00004139 ObjectType, UnqualLookup);
4140 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004141 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004142
4143 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004144 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004145 Template,
4146 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00004147 } else {
4148 // Nothing special needs to be done for these.
4149 Result = getDerived().TransformType(TLB, TL);
4150 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004151
4152 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004153 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004154
Douglas Gregor579c15f2011-03-02 18:32:08 +00004155 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4156}
4157
John McCall550e0c22009-10-21 00:40:46 +00004158template <class TyLoc> static inline
4159QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
4160 TyLoc NewT = TLB.push<TyLoc>(T.getType());
4161 NewT.setNameLoc(T.getNameLoc());
4162 return T.getType();
4163}
4164
John McCall550e0c22009-10-21 00:40:46 +00004165template<typename Derived>
4166QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004167 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00004168 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
4169 NewT.setBuiltinLoc(T.getBuiltinLoc());
4170 if (T.needsExtraLocalData())
4171 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
4172 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004173}
Mike Stump11289f42009-09-09 15:08:12 +00004174
Douglas Gregord6ff3322009-08-04 16:50:30 +00004175template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004176QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004177 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00004178 // FIXME: recurse?
4179 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004180}
Mike Stump11289f42009-09-09 15:08:12 +00004181
Reid Kleckner0503a872013-12-05 01:23:43 +00004182template <typename Derived>
4183QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
4184 AdjustedTypeLoc TL) {
4185 // Adjustments applied during transformation are handled elsewhere.
4186 return getDerived().TransformType(TLB, TL.getOriginalLoc());
4187}
4188
Douglas Gregord6ff3322009-08-04 16:50:30 +00004189template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00004190QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
4191 DecayedTypeLoc TL) {
4192 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
4193 if (OriginalType.isNull())
4194 return QualType();
4195
4196 QualType Result = TL.getType();
4197 if (getDerived().AlwaysRebuild() ||
4198 OriginalType != TL.getOriginalLoc().getType())
4199 Result = SemaRef.Context.getDecayedType(OriginalType);
4200 TLB.push<DecayedTypeLoc>(Result);
4201 // Nothing to set for DecayedTypeLoc.
4202 return Result;
4203}
4204
4205template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004206QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004207 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004208 QualType PointeeType
4209 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004210 if (PointeeType.isNull())
4211 return QualType();
4212
4213 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00004214 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004215 // A dependent pointer type 'T *' has is being transformed such
4216 // that an Objective-C class type is being replaced for 'T'. The
4217 // resulting pointer type is an ObjCObjectPointerType, not a
4218 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00004219 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00004220
John McCall8b07ec22010-05-15 11:32:37 +00004221 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
4222 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004223 return Result;
4224 }
John McCall31f82722010-11-12 08:19:04 +00004225
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004226 if (getDerived().AlwaysRebuild() ||
4227 PointeeType != TL.getPointeeLoc().getType()) {
4228 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
4229 if (Result.isNull())
4230 return QualType();
4231 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004232
John McCall31168b02011-06-15 23:02:42 +00004233 // Objective-C ARC can add lifetime qualifiers to the type that we're
4234 // pointing to.
4235 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00004236
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004237 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
4238 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00004239 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004240}
Mike Stump11289f42009-09-09 15:08:12 +00004241
4242template<typename Derived>
4243QualType
John McCall550e0c22009-10-21 00:40:46 +00004244TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004245 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00004246 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00004247 = getDerived().TransformType(TLB, TL.getPointeeLoc());
4248 if (PointeeType.isNull())
4249 return QualType();
4250
4251 QualType Result = TL.getType();
4252 if (getDerived().AlwaysRebuild() ||
4253 PointeeType != TL.getPointeeLoc().getType()) {
4254 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00004255 TL.getSigilLoc());
4256 if (Result.isNull())
4257 return QualType();
4258 }
4259
Douglas Gregor049211a2010-04-22 16:50:51 +00004260 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00004261 NewT.setSigilLoc(TL.getSigilLoc());
4262 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004263}
4264
John McCall70dd5f62009-10-30 00:06:24 +00004265/// Transforms a reference type. Note that somewhat paradoxically we
4266/// don't care whether the type itself is an l-value type or an r-value
4267/// type; we only care if the type was *written* as an l-value type
4268/// or an r-value type.
4269template<typename Derived>
4270QualType
4271TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004272 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00004273 const ReferenceType *T = TL.getTypePtr();
4274
4275 // Note that this works with the pointee-as-written.
4276 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4277 if (PointeeType.isNull())
4278 return QualType();
4279
4280 QualType Result = TL.getType();
4281 if (getDerived().AlwaysRebuild() ||
4282 PointeeType != T->getPointeeTypeAsWritten()) {
4283 Result = getDerived().RebuildReferenceType(PointeeType,
4284 T->isSpelledAsLValue(),
4285 TL.getSigilLoc());
4286 if (Result.isNull())
4287 return QualType();
4288 }
4289
John McCall31168b02011-06-15 23:02:42 +00004290 // Objective-C ARC can add lifetime qualifiers to the type that we're
4291 // referring to.
4292 TLB.TypeWasModifiedSafely(
4293 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4294
John McCall70dd5f62009-10-30 00:06:24 +00004295 // r-value references can be rebuilt as l-value references.
4296 ReferenceTypeLoc NewTL;
4297 if (isa<LValueReferenceType>(Result))
4298 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4299 else
4300 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4301 NewTL.setSigilLoc(TL.getSigilLoc());
4302
4303 return Result;
4304}
4305
Mike Stump11289f42009-09-09 15:08:12 +00004306template<typename Derived>
4307QualType
John McCall550e0c22009-10-21 00:40:46 +00004308TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004309 LValueReferenceTypeLoc TL) {
4310 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004311}
4312
Mike Stump11289f42009-09-09 15:08:12 +00004313template<typename Derived>
4314QualType
John McCall550e0c22009-10-21 00:40:46 +00004315TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004316 RValueReferenceTypeLoc TL) {
4317 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004318}
Mike Stump11289f42009-09-09 15:08:12 +00004319
Douglas Gregord6ff3322009-08-04 16:50:30 +00004320template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004321QualType
John McCall550e0c22009-10-21 00:40:46 +00004322TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004323 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004324 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004325 if (PointeeType.isNull())
4326 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004327
Abramo Bagnara509357842011-03-05 14:42:21 +00004328 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004329 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00004330 if (OldClsTInfo) {
4331 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4332 if (!NewClsTInfo)
4333 return QualType();
4334 }
4335
4336 const MemberPointerType *T = TL.getTypePtr();
4337 QualType OldClsType = QualType(T->getClass(), 0);
4338 QualType NewClsType;
4339 if (NewClsTInfo)
4340 NewClsType = NewClsTInfo->getType();
4341 else {
4342 NewClsType = getDerived().TransformType(OldClsType);
4343 if (NewClsType.isNull())
4344 return QualType();
4345 }
Mike Stump11289f42009-09-09 15:08:12 +00004346
John McCall550e0c22009-10-21 00:40:46 +00004347 QualType Result = TL.getType();
4348 if (getDerived().AlwaysRebuild() ||
4349 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00004350 NewClsType != OldClsType) {
4351 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004352 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004353 if (Result.isNull())
4354 return QualType();
4355 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004356
Reid Kleckner0503a872013-12-05 01:23:43 +00004357 // If we had to adjust the pointee type when building a member pointer, make
4358 // sure to push TypeLoc info for it.
4359 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4360 if (MPT && PointeeType != MPT->getPointeeType()) {
4361 assert(isa<AdjustedType>(MPT->getPointeeType()));
4362 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4363 }
4364
John McCall550e0c22009-10-21 00:40:46 +00004365 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4366 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004367 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004368
4369 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004370}
4371
Mike Stump11289f42009-09-09 15:08:12 +00004372template<typename Derived>
4373QualType
John McCall550e0c22009-10-21 00:40:46 +00004374TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004375 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004376 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004377 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004378 if (ElementType.isNull())
4379 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004380
John McCall550e0c22009-10-21 00:40:46 +00004381 QualType Result = TL.getType();
4382 if (getDerived().AlwaysRebuild() ||
4383 ElementType != T->getElementType()) {
4384 Result = getDerived().RebuildConstantArrayType(ElementType,
4385 T->getSizeModifier(),
4386 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004387 T->getIndexTypeCVRQualifiers(),
4388 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004389 if (Result.isNull())
4390 return QualType();
4391 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004392
4393 // We might have either a ConstantArrayType or a VariableArrayType now:
4394 // a ConstantArrayType is allowed to have an element type which is a
4395 // VariableArrayType if the type is dependent. Fortunately, all array
4396 // types have the same location layout.
4397 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004398 NewTL.setLBracketLoc(TL.getLBracketLoc());
4399 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004400
John McCall550e0c22009-10-21 00:40:46 +00004401 Expr *Size = TL.getSizeExpr();
4402 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004403 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4404 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004405 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4406 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004407 }
4408 NewTL.setSizeExpr(Size);
4409
4410 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004411}
Mike Stump11289f42009-09-09 15:08:12 +00004412
Douglas Gregord6ff3322009-08-04 16:50:30 +00004413template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004414QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004415 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004416 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004417 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004418 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004419 if (ElementType.isNull())
4420 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004421
John McCall550e0c22009-10-21 00:40:46 +00004422 QualType Result = TL.getType();
4423 if (getDerived().AlwaysRebuild() ||
4424 ElementType != T->getElementType()) {
4425 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004426 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004427 T->getIndexTypeCVRQualifiers(),
4428 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004429 if (Result.isNull())
4430 return QualType();
4431 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004432
John McCall550e0c22009-10-21 00:40:46 +00004433 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4434 NewTL.setLBracketLoc(TL.getLBracketLoc());
4435 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004436 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004437
4438 return Result;
4439}
4440
4441template<typename Derived>
4442QualType
4443TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004444 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004445 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004446 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4447 if (ElementType.isNull())
4448 return QualType();
4449
John McCalldadc5752010-08-24 06:29:42 +00004450 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00004451 = getDerived().TransformExpr(T->getSizeExpr());
4452 if (SizeResult.isInvalid())
4453 return QualType();
4454
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004455 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004456
4457 QualType Result = TL.getType();
4458 if (getDerived().AlwaysRebuild() ||
4459 ElementType != T->getElementType() ||
4460 Size != T->getSizeExpr()) {
4461 Result = getDerived().RebuildVariableArrayType(ElementType,
4462 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004463 Size,
John McCall550e0c22009-10-21 00:40:46 +00004464 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004465 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004466 if (Result.isNull())
4467 return QualType();
4468 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004469
Serge Pavlov774c6d02014-02-06 03:49:11 +00004470 // We might have constant size array now, but fortunately it has the same
4471 // location layout.
4472 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004473 NewTL.setLBracketLoc(TL.getLBracketLoc());
4474 NewTL.setRBracketLoc(TL.getRBracketLoc());
4475 NewTL.setSizeExpr(Size);
4476
4477 return Result;
4478}
4479
4480template<typename Derived>
4481QualType
4482TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004483 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004484 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004485 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4486 if (ElementType.isNull())
4487 return QualType();
4488
Richard Smith764d2fe2011-12-20 02:08:33 +00004489 // Array bounds are constant expressions.
4490 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4491 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004492
John McCall33ddac02011-01-19 10:06:00 +00004493 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4494 Expr *origSize = TL.getSizeExpr();
4495 if (!origSize) origSize = T->getSizeExpr();
4496
4497 ExprResult sizeResult
4498 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004499 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004500 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004501 return QualType();
4502
John McCall33ddac02011-01-19 10:06:00 +00004503 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004504
4505 QualType Result = TL.getType();
4506 if (getDerived().AlwaysRebuild() ||
4507 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004508 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004509 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4510 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004511 size,
John McCall550e0c22009-10-21 00:40:46 +00004512 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004513 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004514 if (Result.isNull())
4515 return QualType();
4516 }
John McCall550e0c22009-10-21 00:40:46 +00004517
4518 // We might have any sort of array type now, but fortunately they
4519 // all have the same location layout.
4520 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4521 NewTL.setLBracketLoc(TL.getLBracketLoc());
4522 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004523 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004524
4525 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004526}
Mike Stump11289f42009-09-09 15:08:12 +00004527
4528template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004529QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004530 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004531 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004532 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004533
4534 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004535 QualType ElementType = getDerived().TransformType(T->getElementType());
4536 if (ElementType.isNull())
4537 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004538
Richard Smith764d2fe2011-12-20 02:08:33 +00004539 // Vector sizes are constant expressions.
4540 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4541 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004542
John McCalldadc5752010-08-24 06:29:42 +00004543 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004544 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004545 if (Size.isInvalid())
4546 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004547
John McCall550e0c22009-10-21 00:40:46 +00004548 QualType Result = TL.getType();
4549 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004550 ElementType != T->getElementType() ||
4551 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004552 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004553 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004554 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004555 if (Result.isNull())
4556 return QualType();
4557 }
John McCall550e0c22009-10-21 00:40:46 +00004558
4559 // Result might be dependent or not.
4560 if (isa<DependentSizedExtVectorType>(Result)) {
4561 DependentSizedExtVectorTypeLoc NewTL
4562 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4563 NewTL.setNameLoc(TL.getNameLoc());
4564 } else {
4565 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4566 NewTL.setNameLoc(TL.getNameLoc());
4567 }
4568
4569 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004570}
Mike Stump11289f42009-09-09 15:08:12 +00004571
4572template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004573QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004574 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004575 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004576 QualType ElementType = getDerived().TransformType(T->getElementType());
4577 if (ElementType.isNull())
4578 return QualType();
4579
John McCall550e0c22009-10-21 00:40:46 +00004580 QualType Result = TL.getType();
4581 if (getDerived().AlwaysRebuild() ||
4582 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004583 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004584 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004585 if (Result.isNull())
4586 return QualType();
4587 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004588
John McCall550e0c22009-10-21 00:40:46 +00004589 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4590 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004591
John McCall550e0c22009-10-21 00:40:46 +00004592 return Result;
4593}
4594
4595template<typename Derived>
4596QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004597 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004598 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004599 QualType ElementType = getDerived().TransformType(T->getElementType());
4600 if (ElementType.isNull())
4601 return QualType();
4602
4603 QualType Result = TL.getType();
4604 if (getDerived().AlwaysRebuild() ||
4605 ElementType != T->getElementType()) {
4606 Result = getDerived().RebuildExtVectorType(ElementType,
4607 T->getNumElements(),
4608 /*FIXME*/ SourceLocation());
4609 if (Result.isNull())
4610 return QualType();
4611 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004612
John McCall550e0c22009-10-21 00:40:46 +00004613 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4614 NewTL.setNameLoc(TL.getNameLoc());
4615
4616 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004617}
Mike Stump11289f42009-09-09 15:08:12 +00004618
David Blaikie05785d12013-02-20 22:23:23 +00004619template <typename Derived>
4620ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4621 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4622 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004623 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004624 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004625
Douglas Gregor715e4612011-01-14 22:40:04 +00004626 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004627 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004628 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004629 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004630 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004631
Douglas Gregor715e4612011-01-14 22:40:04 +00004632 TypeLocBuilder TLB;
4633 TypeLoc NewTL = OldDI->getTypeLoc();
4634 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004635
4636 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004637 OldExpansionTL.getPatternLoc());
4638 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004639 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004640
4641 Result = RebuildPackExpansionType(Result,
4642 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004643 OldExpansionTL.getEllipsisLoc(),
4644 NumExpansions);
4645 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004646 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004647
Douglas Gregor715e4612011-01-14 22:40:04 +00004648 PackExpansionTypeLoc NewExpansionTL
4649 = TLB.push<PackExpansionTypeLoc>(Result);
4650 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4651 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4652 } else
4653 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004654 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004655 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004656
John McCall8fb0d9d2011-05-01 22:35:37 +00004657 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004658 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004659
4660 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4661 OldParm->getDeclContext(),
4662 OldParm->getInnerLocStart(),
4663 OldParm->getLocation(),
4664 OldParm->getIdentifier(),
4665 NewDI->getType(),
4666 NewDI,
4667 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004668 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004669 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4670 OldParm->getFunctionScopeIndex() + indexAdjustment);
4671 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004672}
4673
David Majnemer59f77922016-06-24 04:05:48 +00004674template <typename Derived>
4675bool TreeTransform<Derived>::TransformFunctionTypeParams(
4676 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
4677 const QualType *ParamTypes,
4678 const FunctionProtoType::ExtParameterInfo *ParamInfos,
4679 SmallVectorImpl<QualType> &OutParamTypes,
4680 SmallVectorImpl<ParmVarDecl *> *PVars,
4681 Sema::ExtParameterInfoBuilder &PInfos) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004682 int indexAdjustment = 0;
4683
David Majnemer59f77922016-06-24 04:05:48 +00004684 unsigned NumParams = Params.size();
Douglas Gregordd472162011-01-07 00:20:55 +00004685 for (unsigned i = 0; i != NumParams; ++i) {
4686 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004687 assert(OldParm->getFunctionScopeIndex() == i);
4688
David Blaikie05785d12013-02-20 22:23:23 +00004689 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004690 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004691 if (OldParm->isParameterPack()) {
4692 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004693 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004694
Douglas Gregor5499af42011-01-05 23:12:31 +00004695 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004696 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004697 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004698 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4699 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004700 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4701
Douglas Gregor5499af42011-01-05 23:12:31 +00004702 // Determine whether we should expand the parameter packs.
4703 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004704 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004705 Optional<unsigned> OrigNumExpansions =
4706 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004707 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004708 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4709 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004710 Unexpanded,
4711 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004712 RetainExpansion,
4713 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004714 return true;
4715 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004716
Douglas Gregor5499af42011-01-05 23:12:31 +00004717 if (ShouldExpand) {
4718 // Expand the function parameter pack into multiple, separate
4719 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004720 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004721 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004722 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004723 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004724 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004725 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004726 OrigNumExpansions,
4727 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004728 if (!NewParm)
4729 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004730
John McCallc8e321d2016-03-01 02:09:25 +00004731 if (ParamInfos)
4732 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004733 OutParamTypes.push_back(NewParm->getType());
4734 if (PVars)
4735 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004736 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004737
4738 // If we're supposed to retain a pack expansion, do so by temporarily
4739 // forgetting the partially-substituted parameter pack.
4740 if (RetainExpansion) {
4741 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004742 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004743 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004744 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004745 OrigNumExpansions,
4746 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004747 if (!NewParm)
4748 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004749
John McCallc8e321d2016-03-01 02:09:25 +00004750 if (ParamInfos)
4751 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004752 OutParamTypes.push_back(NewParm->getType());
4753 if (PVars)
4754 PVars->push_back(NewParm);
4755 }
4756
John McCall8fb0d9d2011-05-01 22:35:37 +00004757 // The next parameter should have the same adjustment as the
4758 // last thing we pushed, but we post-incremented indexAdjustment
4759 // on every push. Also, if we push nothing, the adjustment should
4760 // go down by one.
4761 indexAdjustment--;
4762
Douglas Gregor5499af42011-01-05 23:12:31 +00004763 // We're done with the pack expansion.
4764 continue;
4765 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004766
4767 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004768 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004769 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4770 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004771 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004772 NumExpansions,
4773 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004774 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004775 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004776 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004777 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004778
John McCall58f10c32010-03-11 09:03:00 +00004779 if (!NewParm)
4780 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004781
John McCallc8e321d2016-03-01 02:09:25 +00004782 if (ParamInfos)
4783 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004784 OutParamTypes.push_back(NewParm->getType());
4785 if (PVars)
4786 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004787 continue;
4788 }
John McCall58f10c32010-03-11 09:03:00 +00004789
4790 // Deal with the possibility that we don't have a parameter
4791 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004792 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004793 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004794 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004795 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004796 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004797 = dyn_cast<PackExpansionType>(OldType)) {
4798 // We have a function parameter pack that may need to be expanded.
4799 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004800 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004801 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004802
Douglas Gregor5499af42011-01-05 23:12:31 +00004803 // Determine whether we should expand the parameter packs.
4804 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004805 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004806 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004807 Unexpanded,
4808 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004809 RetainExpansion,
4810 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004811 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004812 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004813
Douglas Gregor5499af42011-01-05 23:12:31 +00004814 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004815 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004816 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004817 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004818 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4819 QualType NewType = getDerived().TransformType(Pattern);
4820 if (NewType.isNull())
4821 return true;
John McCall58f10c32010-03-11 09:03:00 +00004822
Erik Pilkingtonf1bd0002016-07-05 17:57:24 +00004823 if (NewType->containsUnexpandedParameterPack()) {
4824 NewType =
4825 getSema().getASTContext().getPackExpansionType(NewType, None);
4826
4827 if (NewType.isNull())
4828 return true;
4829 }
4830
John McCallc8e321d2016-03-01 02:09:25 +00004831 if (ParamInfos)
4832 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004833 OutParamTypes.push_back(NewType);
4834 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004835 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004836 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004837
Douglas Gregor5499af42011-01-05 23:12:31 +00004838 // We're done with the pack expansion.
4839 continue;
4840 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004841
Douglas Gregor48d24112011-01-10 20:53:55 +00004842 // If we're supposed to retain a pack expansion, do so by temporarily
4843 // forgetting the partially-substituted parameter pack.
4844 if (RetainExpansion) {
4845 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4846 QualType NewType = getDerived().TransformType(Pattern);
4847 if (NewType.isNull())
4848 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004849
John McCallc8e321d2016-03-01 02:09:25 +00004850 if (ParamInfos)
4851 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregor48d24112011-01-10 20:53:55 +00004852 OutParamTypes.push_back(NewType);
4853 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004854 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004855 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004856
Chad Rosier1dcde962012-08-08 18:46:20 +00004857 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004858 // expansion.
4859 OldType = Expansion->getPattern();
4860 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004861 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4862 NewType = getDerived().TransformType(OldType);
4863 } else {
4864 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004865 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004866
Douglas Gregor5499af42011-01-05 23:12:31 +00004867 if (NewType.isNull())
4868 return true;
4869
4870 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004871 NewType = getSema().Context.getPackExpansionType(NewType,
4872 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004873
John McCallc8e321d2016-03-01 02:09:25 +00004874 if (ParamInfos)
4875 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004876 OutParamTypes.push_back(NewType);
4877 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004878 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004879 }
4880
John McCall8fb0d9d2011-05-01 22:35:37 +00004881#ifndef NDEBUG
4882 if (PVars) {
4883 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4884 if (ParmVarDecl *parm = (*PVars)[i])
4885 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004886 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004887#endif
4888
4889 return false;
4890}
John McCall58f10c32010-03-11 09:03:00 +00004891
4892template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004893QualType
John McCall550e0c22009-10-21 00:40:46 +00004894TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004895 FunctionProtoTypeLoc TL) {
Richard Smith2e321552014-11-12 02:00:47 +00004896 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00004897 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00004898 return getDerived().TransformFunctionProtoType(
4899 TLB, TL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00004900 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
4901 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
4902 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00004903 });
Douglas Gregor3024f072012-04-16 07:05:22 +00004904}
4905
Richard Smith2e321552014-11-12 02:00:47 +00004906template<typename Derived> template<typename Fn>
4907QualType TreeTransform<Derived>::TransformFunctionProtoType(
4908 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
4909 unsigned ThisTypeQuals, Fn TransformExceptionSpec) {
John McCallc8e321d2016-03-01 02:09:25 +00004910
Douglas Gregor4afc2362010-08-31 00:26:14 +00004911 // Transform the parameters and return type.
4912 //
Richard Smithf623c962012-04-17 00:58:00 +00004913 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004914 // When the function has a trailing return type, we instantiate the
4915 // parameters before the return type, since the return type can then refer
4916 // to the parameters themselves (via decltype, sizeof, etc.).
4917 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004918 SmallVector<QualType, 4> ParamTypes;
4919 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallc8e321d2016-03-01 02:09:25 +00004920 Sema::ExtParameterInfoBuilder ExtParamInfos;
John McCall424cec92011-01-19 06:33:43 +00004921 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004922
Douglas Gregor7fb25412010-10-01 18:44:50 +00004923 QualType ResultType;
4924
Richard Smith1226c602012-08-14 22:51:13 +00004925 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004926 if (getDerived().TransformFunctionTypeParams(
David Majnemer59f77922016-06-24 04:05:48 +00004927 TL.getBeginLoc(), TL.getParams(),
John McCallc8e321d2016-03-01 02:09:25 +00004928 TL.getTypePtr()->param_type_begin(),
4929 T->getExtParameterInfosOrNull(),
4930 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004931 return QualType();
4932
Douglas Gregor3024f072012-04-16 07:05:22 +00004933 {
4934 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004935 // If a declaration declares a member function or member function
4936 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004937 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004938 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004939 // declarator.
4940 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004941
Alp Toker42a16a62014-01-25 23:51:36 +00004942 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004943 if (ResultType.isNull())
4944 return QualType();
4945 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004946 }
4947 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004948 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004949 if (ResultType.isNull())
4950 return QualType();
4951
Alp Toker9cacbab2014-01-20 20:26:09 +00004952 if (getDerived().TransformFunctionTypeParams(
David Majnemer59f77922016-06-24 04:05:48 +00004953 TL.getBeginLoc(), TL.getParams(),
John McCallc8e321d2016-03-01 02:09:25 +00004954 TL.getTypePtr()->param_type_begin(),
4955 T->getExtParameterInfosOrNull(),
4956 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004957 return QualType();
4958 }
4959
Richard Smith2e321552014-11-12 02:00:47 +00004960 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
4961
4962 bool EPIChanged = false;
4963 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
4964 return QualType();
4965
John McCallc8e321d2016-03-01 02:09:25 +00004966 // Handle extended parameter information.
4967 if (auto NewExtParamInfos =
4968 ExtParamInfos.getPointerOrNull(ParamTypes.size())) {
4969 if (!EPI.ExtParameterInfos ||
4970 llvm::makeArrayRef(EPI.ExtParameterInfos, TL.getNumParams())
4971 != llvm::makeArrayRef(NewExtParamInfos, ParamTypes.size())) {
4972 EPIChanged = true;
4973 }
4974 EPI.ExtParameterInfos = NewExtParamInfos;
4975 } else if (EPI.ExtParameterInfos) {
4976 EPIChanged = true;
4977 EPI.ExtParameterInfos = nullptr;
4978 }
Richard Smithf623c962012-04-17 00:58:00 +00004979
John McCall550e0c22009-10-21 00:40:46 +00004980 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004981 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Benjamin Kramere1c08b02015-08-18 08:10:39 +00004982 T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) {
Richard Smith2e321552014-11-12 02:00:47 +00004983 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
John McCall550e0c22009-10-21 00:40:46 +00004984 if (Result.isNull())
4985 return QualType();
4986 }
Mike Stump11289f42009-09-09 15:08:12 +00004987
John McCall550e0c22009-10-21 00:40:46 +00004988 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004989 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004990 NewTL.setLParenLoc(TL.getLParenLoc());
4991 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004992 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004993 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4994 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004995
4996 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004997}
Mike Stump11289f42009-09-09 15:08:12 +00004998
Douglas Gregord6ff3322009-08-04 16:50:30 +00004999template<typename Derived>
Richard Smith2e321552014-11-12 02:00:47 +00005000bool TreeTransform<Derived>::TransformExceptionSpec(
5001 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
5002 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
5003 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
5004
5005 // Instantiate a dynamic noexcept expression, if any.
5006 if (ESI.Type == EST_ComputedNoexcept) {
5007 EnterExpressionEvaluationContext Unevaluated(getSema(),
5008 Sema::ConstantEvaluated);
5009 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
5010 if (NoexceptExpr.isInvalid())
5011 return true;
5012
Richard Smith03a4aa32016-06-23 19:02:52 +00005013 // FIXME: This is bogus, a noexcept expression is not a condition.
5014 NoexceptExpr = getSema().CheckBooleanCondition(Loc, NoexceptExpr.get());
Richard Smith2e321552014-11-12 02:00:47 +00005015 if (NoexceptExpr.isInvalid())
5016 return true;
5017
5018 if (!NoexceptExpr.get()->isValueDependent()) {
5019 NoexceptExpr = getSema().VerifyIntegerConstantExpression(
5020 NoexceptExpr.get(), nullptr,
5021 diag::err_noexcept_needs_constant_expression,
5022 /*AllowFold*/false);
5023 if (NoexceptExpr.isInvalid())
5024 return true;
5025 }
5026
5027 if (ESI.NoexceptExpr != NoexceptExpr.get())
5028 Changed = true;
5029 ESI.NoexceptExpr = NoexceptExpr.get();
5030 }
5031
5032 if (ESI.Type != EST_Dynamic)
5033 return false;
5034
5035 // Instantiate a dynamic exception specification's type.
5036 for (QualType T : ESI.Exceptions) {
5037 if (const PackExpansionType *PackExpansion =
5038 T->getAs<PackExpansionType>()) {
5039 Changed = true;
5040
5041 // We have a pack expansion. Instantiate it.
5042 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5043 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5044 Unexpanded);
5045 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5046
5047 // Determine whether the set of unexpanded parameter packs can and
5048 // should
5049 // be expanded.
5050 bool Expand = false;
5051 bool RetainExpansion = false;
5052 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5053 // FIXME: Track the location of the ellipsis (and track source location
5054 // information for the types in the exception specification in general).
5055 if (getDerived().TryExpandParameterPacks(
5056 Loc, SourceRange(), Unexpanded, Expand,
5057 RetainExpansion, NumExpansions))
5058 return true;
5059
5060 if (!Expand) {
5061 // We can't expand this pack expansion into separate arguments yet;
5062 // just substitute into the pattern and create a new pack expansion
5063 // type.
5064 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5065 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5066 if (U.isNull())
5067 return true;
5068
5069 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
5070 Exceptions.push_back(U);
5071 continue;
5072 }
5073
5074 // Substitute into the pack expansion pattern for each slice of the
5075 // pack.
5076 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5077 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5078
5079 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5080 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5081 return true;
5082
5083 Exceptions.push_back(U);
5084 }
5085 } else {
5086 QualType U = getDerived().TransformType(T);
5087 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5088 return true;
5089 if (T != U)
5090 Changed = true;
5091
5092 Exceptions.push_back(U);
5093 }
5094 }
5095
5096 ESI.Exceptions = Exceptions;
5097 return false;
5098}
5099
5100template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00005101QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00005102 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005103 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005104 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00005105 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00005106 if (ResultType.isNull())
5107 return QualType();
5108
5109 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00005110 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00005111 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
5112
5113 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005114 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00005115 NewTL.setLParenLoc(TL.getLParenLoc());
5116 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005117 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00005118
5119 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005120}
Mike Stump11289f42009-09-09 15:08:12 +00005121
John McCallb96ec562009-12-04 22:46:56 +00005122template<typename Derived> QualType
5123TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005124 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005125 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005126 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00005127 if (!D)
5128 return QualType();
5129
5130 QualType Result = TL.getType();
5131 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
5132 Result = getDerived().RebuildUnresolvedUsingType(D);
5133 if (Result.isNull())
5134 return QualType();
5135 }
5136
5137 // We might get an arbitrary type spec type back. We should at
5138 // least always get a type spec type, though.
5139 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
5140 NewTL.setNameLoc(TL.getNameLoc());
5141
5142 return Result;
5143}
5144
Douglas Gregord6ff3322009-08-04 16:50:30 +00005145template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005146QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005147 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005148 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00005149 TypedefNameDecl *Typedef
5150 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5151 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005152 if (!Typedef)
5153 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005154
John McCall550e0c22009-10-21 00:40:46 +00005155 QualType Result = TL.getType();
5156 if (getDerived().AlwaysRebuild() ||
5157 Typedef != T->getDecl()) {
5158 Result = getDerived().RebuildTypedefType(Typedef);
5159 if (Result.isNull())
5160 return QualType();
5161 }
Mike Stump11289f42009-09-09 15:08:12 +00005162
John McCall550e0c22009-10-21 00:40:46 +00005163 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
5164 NewTL.setNameLoc(TL.getNameLoc());
5165
5166 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005167}
Mike Stump11289f42009-09-09 15:08:12 +00005168
Douglas Gregord6ff3322009-08-04 16:50:30 +00005169template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005170QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005171 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00005172 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00005173 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
5174 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00005175
John McCalldadc5752010-08-24 06:29:42 +00005176 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005177 if (E.isInvalid())
5178 return QualType();
5179
Eli Friedmane4f22df2012-02-29 04:03:55 +00005180 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
5181 if (E.isInvalid())
5182 return QualType();
5183
John McCall550e0c22009-10-21 00:40:46 +00005184 QualType Result = TL.getType();
5185 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00005186 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005187 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00005188 if (Result.isNull())
5189 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005190 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005191 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005192
John McCall550e0c22009-10-21 00:40:46 +00005193 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005194 NewTL.setTypeofLoc(TL.getTypeofLoc());
5195 NewTL.setLParenLoc(TL.getLParenLoc());
5196 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00005197
5198 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005199}
Mike Stump11289f42009-09-09 15:08:12 +00005200
5201template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005202QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005203 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00005204 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
5205 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
5206 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005207 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005208
John McCall550e0c22009-10-21 00:40:46 +00005209 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00005210 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
5211 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00005212 if (Result.isNull())
5213 return QualType();
5214 }
Mike Stump11289f42009-09-09 15:08:12 +00005215
John McCall550e0c22009-10-21 00:40:46 +00005216 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005217 NewTL.setTypeofLoc(TL.getTypeofLoc());
5218 NewTL.setLParenLoc(TL.getLParenLoc());
5219 NewTL.setRParenLoc(TL.getRParenLoc());
5220 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00005221
5222 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005223}
Mike Stump11289f42009-09-09 15:08:12 +00005224
5225template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005226QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005227 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005228 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00005229
Douglas Gregore922c772009-08-04 22:27:00 +00005230 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00005231 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
5232 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00005233
John McCalldadc5752010-08-24 06:29:42 +00005234 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005235 if (E.isInvalid())
5236 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005237
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005238 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00005239 if (E.isInvalid())
5240 return QualType();
5241
John McCall550e0c22009-10-21 00:40:46 +00005242 QualType Result = TL.getType();
5243 if (getDerived().AlwaysRebuild() ||
5244 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005245 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005246 if (Result.isNull())
5247 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005248 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005249 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005250
John McCall550e0c22009-10-21 00:40:46 +00005251 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
5252 NewTL.setNameLoc(TL.getNameLoc());
5253
5254 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005255}
5256
5257template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00005258QualType TreeTransform<Derived>::TransformUnaryTransformType(
5259 TypeLocBuilder &TLB,
5260 UnaryTransformTypeLoc TL) {
5261 QualType Result = TL.getType();
5262 if (Result->isDependentType()) {
5263 const UnaryTransformType *T = TL.getTypePtr();
5264 QualType NewBase =
5265 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
5266 Result = getDerived().RebuildUnaryTransformType(NewBase,
5267 T->getUTTKind(),
5268 TL.getKWLoc());
5269 if (Result.isNull())
5270 return QualType();
5271 }
5272
5273 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
5274 NewTL.setKWLoc(TL.getKWLoc());
5275 NewTL.setParensRange(TL.getParensRange());
5276 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
5277 return Result;
5278}
5279
5280template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00005281QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
5282 AutoTypeLoc TL) {
5283 const AutoType *T = TL.getTypePtr();
5284 QualType OldDeduced = T->getDeducedType();
5285 QualType NewDeduced;
5286 if (!OldDeduced.isNull()) {
5287 NewDeduced = getDerived().TransformType(OldDeduced);
5288 if (NewDeduced.isNull())
5289 return QualType();
5290 }
5291
5292 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00005293 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
5294 T->isDependentType()) {
Richard Smithe301ba22015-11-11 02:02:15 +00005295 Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword());
Richard Smith30482bc2011-02-20 03:19:35 +00005296 if (Result.isNull())
5297 return QualType();
5298 }
5299
5300 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5301 NewTL.setNameLoc(TL.getNameLoc());
5302
5303 return Result;
5304}
5305
5306template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005307QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005308 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005309 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005310 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005311 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5312 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005313 if (!Record)
5314 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005315
John McCall550e0c22009-10-21 00:40:46 +00005316 QualType Result = TL.getType();
5317 if (getDerived().AlwaysRebuild() ||
5318 Record != T->getDecl()) {
5319 Result = getDerived().RebuildRecordType(Record);
5320 if (Result.isNull())
5321 return QualType();
5322 }
Mike Stump11289f42009-09-09 15:08:12 +00005323
John McCall550e0c22009-10-21 00:40:46 +00005324 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5325 NewTL.setNameLoc(TL.getNameLoc());
5326
5327 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005328}
Mike Stump11289f42009-09-09 15:08:12 +00005329
5330template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005331QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005332 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005333 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005334 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005335 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5336 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005337 if (!Enum)
5338 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005339
John McCall550e0c22009-10-21 00:40:46 +00005340 QualType Result = TL.getType();
5341 if (getDerived().AlwaysRebuild() ||
5342 Enum != T->getDecl()) {
5343 Result = getDerived().RebuildEnumType(Enum);
5344 if (Result.isNull())
5345 return QualType();
5346 }
Mike Stump11289f42009-09-09 15:08:12 +00005347
John McCall550e0c22009-10-21 00:40:46 +00005348 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5349 NewTL.setNameLoc(TL.getNameLoc());
5350
5351 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005352}
John McCallfcc33b02009-09-05 00:15:47 +00005353
John McCalle78aac42010-03-10 03:28:59 +00005354template<typename Derived>
5355QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5356 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005357 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00005358 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5359 TL.getTypePtr()->getDecl());
5360 if (!D) return QualType();
5361
5362 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5363 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5364 return T;
5365}
5366
Douglas Gregord6ff3322009-08-04 16:50:30 +00005367template<typename Derived>
5368QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005369 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005370 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00005371 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005372}
5373
Mike Stump11289f42009-09-09 15:08:12 +00005374template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00005375QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005376 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005377 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005378 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005379
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005380 // Substitute into the replacement type, which itself might involve something
5381 // that needs to be transformed. This only tends to occur with default
5382 // template arguments of template template parameters.
5383 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5384 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5385 if (Replacement.isNull())
5386 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005387
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005388 // Always canonicalize the replacement type.
5389 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5390 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00005391 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005392 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00005393
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005394 // Propagate type-source information.
5395 SubstTemplateTypeParmTypeLoc NewTL
5396 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5397 NewTL.setNameLoc(TL.getNameLoc());
5398 return Result;
5399
John McCallcebee162009-10-18 09:09:24 +00005400}
5401
5402template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00005403QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5404 TypeLocBuilder &TLB,
5405 SubstTemplateTypeParmPackTypeLoc TL) {
5406 return TransformTypeSpecType(TLB, TL);
5407}
5408
5409template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00005410QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005411 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005412 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00005413 const TemplateSpecializationType *T = TL.getTypePtr();
5414
Douglas Gregordf846d12011-03-02 18:46:51 +00005415 // The nested-name-specifier never matters in a TemplateSpecializationType,
5416 // because we can't have a dependent nested-name-specifier anyway.
5417 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00005418 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00005419 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5420 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005421 if (Template.isNull())
5422 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005423
John McCall31f82722010-11-12 08:19:04 +00005424 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5425}
5426
Eli Friedman0dfb8892011-10-06 23:00:33 +00005427template<typename Derived>
5428QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5429 AtomicTypeLoc TL) {
5430 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5431 if (ValueType.isNull())
5432 return QualType();
5433
5434 QualType Result = TL.getType();
5435 if (getDerived().AlwaysRebuild() ||
5436 ValueType != TL.getValueLoc().getType()) {
5437 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5438 if (Result.isNull())
5439 return QualType();
5440 }
5441
5442 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5443 NewTL.setKWLoc(TL.getKWLoc());
5444 NewTL.setLParenLoc(TL.getLParenLoc());
5445 NewTL.setRParenLoc(TL.getRParenLoc());
5446
5447 return Result;
5448}
5449
Xiuli Pan9c14e282016-01-09 12:53:17 +00005450template <typename Derived>
5451QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB,
5452 PipeTypeLoc TL) {
5453 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5454 if (ValueType.isNull())
5455 return QualType();
5456
5457 QualType Result = TL.getType();
5458 if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
5459 Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc());
5460 if (Result.isNull())
5461 return QualType();
5462 }
5463
5464 PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
5465 NewTL.setKWLoc(TL.getKWLoc());
5466
5467 return Result;
5468}
5469
Chad Rosier1dcde962012-08-08 18:46:20 +00005470 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00005471 /// container that provides a \c getArgLoc() member function.
5472 ///
5473 /// This iterator is intended to be used with the iterator form of
5474 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5475 template<typename ArgLocContainer>
5476 class TemplateArgumentLocContainerIterator {
5477 ArgLocContainer *Container;
5478 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00005479
Douglas Gregorfe921a72010-12-20 23:36:19 +00005480 public:
5481 typedef TemplateArgumentLoc value_type;
5482 typedef TemplateArgumentLoc reference;
5483 typedef int difference_type;
5484 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00005485
Douglas Gregorfe921a72010-12-20 23:36:19 +00005486 class pointer {
5487 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00005488
Douglas Gregorfe921a72010-12-20 23:36:19 +00005489 public:
5490 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005491
Douglas Gregorfe921a72010-12-20 23:36:19 +00005492 const TemplateArgumentLoc *operator->() const {
5493 return &Arg;
5494 }
5495 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005496
5497
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00005498 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00005499
Douglas Gregorfe921a72010-12-20 23:36:19 +00005500 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5501 unsigned Index)
5502 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005503
Douglas Gregorfe921a72010-12-20 23:36:19 +00005504 TemplateArgumentLocContainerIterator &operator++() {
5505 ++Index;
5506 return *this;
5507 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005508
Douglas Gregorfe921a72010-12-20 23:36:19 +00005509 TemplateArgumentLocContainerIterator operator++(int) {
5510 TemplateArgumentLocContainerIterator Old(*this);
5511 ++(*this);
5512 return Old;
5513 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005514
Douglas Gregorfe921a72010-12-20 23:36:19 +00005515 TemplateArgumentLoc operator*() const {
5516 return Container->getArgLoc(Index);
5517 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005518
Douglas Gregorfe921a72010-12-20 23:36:19 +00005519 pointer operator->() const {
5520 return pointer(Container->getArgLoc(Index));
5521 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005522
Douglas Gregorfe921a72010-12-20 23:36:19 +00005523 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005524 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005525 return X.Container == Y.Container && X.Index == Y.Index;
5526 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005527
Douglas Gregorfe921a72010-12-20 23:36:19 +00005528 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005529 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005530 return !(X == Y);
5531 }
5532 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005533
5534
John McCall31f82722010-11-12 08:19:04 +00005535template <typename Derived>
5536QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5537 TypeLocBuilder &TLB,
5538 TemplateSpecializationTypeLoc TL,
5539 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005540 TemplateArgumentListInfo NewTemplateArgs;
5541 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5542 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005543 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5544 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005545 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005546 ArgIterator(TL, TL.getNumArgs()),
5547 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005548 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005549
John McCall0ad16662009-10-29 08:12:44 +00005550 // FIXME: maybe don't rebuild if all the template arguments are the same.
5551
5552 QualType Result =
5553 getDerived().RebuildTemplateSpecializationType(Template,
5554 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005555 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005556
5557 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005558 // Specializations of template template parameters are represented as
5559 // TemplateSpecializationTypes, and substitution of type alias templates
5560 // within a dependent context can transform them into
5561 // DependentTemplateSpecializationTypes.
5562 if (isa<DependentTemplateSpecializationType>(Result)) {
5563 DependentTemplateSpecializationTypeLoc NewTL
5564 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005565 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005566 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005567 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005568 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005569 NewTL.setLAngleLoc(TL.getLAngleLoc());
5570 NewTL.setRAngleLoc(TL.getRAngleLoc());
5571 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5572 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5573 return Result;
5574 }
5575
John McCall0ad16662009-10-29 08:12:44 +00005576 TemplateSpecializationTypeLoc NewTL
5577 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005578 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005579 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5580 NewTL.setLAngleLoc(TL.getLAngleLoc());
5581 NewTL.setRAngleLoc(TL.getRAngleLoc());
5582 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5583 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005584 }
Mike Stump11289f42009-09-09 15:08:12 +00005585
John McCall0ad16662009-10-29 08:12:44 +00005586 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005587}
Mike Stump11289f42009-09-09 15:08:12 +00005588
Douglas Gregor5a064722011-02-28 17:23:35 +00005589template <typename Derived>
5590QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5591 TypeLocBuilder &TLB,
5592 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005593 TemplateName Template,
5594 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005595 TemplateArgumentListInfo NewTemplateArgs;
5596 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5597 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5598 typedef TemplateArgumentLocContainerIterator<
5599 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005600 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005601 ArgIterator(TL, TL.getNumArgs()),
5602 NewTemplateArgs))
5603 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005604
Douglas Gregor5a064722011-02-28 17:23:35 +00005605 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005606
Douglas Gregor5a064722011-02-28 17:23:35 +00005607 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5608 QualType Result
5609 = getSema().Context.getDependentTemplateSpecializationType(
5610 TL.getTypePtr()->getKeyword(),
5611 DTN->getQualifier(),
5612 DTN->getIdentifier(),
5613 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005614
Douglas Gregor5a064722011-02-28 17:23:35 +00005615 DependentTemplateSpecializationTypeLoc NewTL
5616 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005617 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005618 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005619 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005620 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005621 NewTL.setLAngleLoc(TL.getLAngleLoc());
5622 NewTL.setRAngleLoc(TL.getRAngleLoc());
5623 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5624 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5625 return Result;
5626 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005627
5628 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005629 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005630 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005631 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005632
Douglas Gregor5a064722011-02-28 17:23:35 +00005633 if (!Result.isNull()) {
5634 /// FIXME: Wrap this in an elaborated-type-specifier?
5635 TemplateSpecializationTypeLoc NewTL
5636 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005637 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005638 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005639 NewTL.setLAngleLoc(TL.getLAngleLoc());
5640 NewTL.setRAngleLoc(TL.getRAngleLoc());
5641 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5642 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5643 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005644
Douglas Gregor5a064722011-02-28 17:23:35 +00005645 return Result;
5646}
5647
Mike Stump11289f42009-09-09 15:08:12 +00005648template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005649QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005650TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005651 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005652 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005653
Douglas Gregor844cb502011-03-01 18:12:44 +00005654 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005655 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005656 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005657 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005658 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5659 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005660 return QualType();
5661 }
Mike Stump11289f42009-09-09 15:08:12 +00005662
John McCall31f82722010-11-12 08:19:04 +00005663 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5664 if (NamedT.isNull())
5665 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005666
Richard Smith3f1b5d02011-05-05 21:57:07 +00005667 // C++0x [dcl.type.elab]p2:
5668 // If the identifier resolves to a typedef-name or the simple-template-id
5669 // resolves to an alias template specialization, the
5670 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005671 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5672 if (const TemplateSpecializationType *TST =
5673 NamedT->getAs<TemplateSpecializationType>()) {
5674 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00005675 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5676 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00005677 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5678 diag::err_tag_reference_non_tag) << 4;
5679 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5680 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005681 }
5682 }
5683
John McCall550e0c22009-10-21 00:40:46 +00005684 QualType Result = TL.getType();
5685 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005686 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005687 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005688 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005689 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005690 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005691 if (Result.isNull())
5692 return QualType();
5693 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005694
Abramo Bagnara6150c882010-05-11 21:36:43 +00005695 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005696 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005697 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005698 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005699}
Mike Stump11289f42009-09-09 15:08:12 +00005700
5701template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005702QualType TreeTransform<Derived>::TransformAttributedType(
5703 TypeLocBuilder &TLB,
5704 AttributedTypeLoc TL) {
5705 const AttributedType *oldType = TL.getTypePtr();
5706 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5707 if (modifiedType.isNull())
5708 return QualType();
5709
5710 QualType result = TL.getType();
5711
5712 // FIXME: dependent operand expressions?
5713 if (getDerived().AlwaysRebuild() ||
5714 modifiedType != oldType->getModifiedType()) {
5715 // TODO: this is really lame; we should really be rebuilding the
5716 // equivalent type from first principles.
5717 QualType equivalentType
5718 = getDerived().TransformType(oldType->getEquivalentType());
5719 if (equivalentType.isNull())
5720 return QualType();
Douglas Gregor261a89b2015-06-19 17:51:05 +00005721
5722 // Check whether we can add nullability; it is only represented as
5723 // type sugar, and therefore cannot be diagnosed in any other way.
5724 if (auto nullability = oldType->getImmediateNullability()) {
5725 if (!modifiedType->canHaveNullability()) {
5726 SemaRef.Diag(TL.getAttrNameLoc(), diag::err_nullability_nonpointer)
Douglas Gregoraea7afd2015-06-24 22:02:08 +00005727 << DiagNullabilityKind(*nullability, false) << modifiedType;
Douglas Gregor261a89b2015-06-19 17:51:05 +00005728 return QualType();
5729 }
5730 }
5731
John McCall81904512011-01-06 01:58:22 +00005732 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5733 modifiedType,
5734 equivalentType);
5735 }
5736
5737 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5738 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5739 if (TL.hasAttrOperand())
5740 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5741 if (TL.hasAttrExprOperand())
5742 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5743 else if (TL.hasAttrEnumOperand())
5744 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5745
5746 return result;
5747}
5748
5749template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005750QualType
5751TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5752 ParenTypeLoc TL) {
5753 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5754 if (Inner.isNull())
5755 return QualType();
5756
5757 QualType Result = TL.getType();
5758 if (getDerived().AlwaysRebuild() ||
5759 Inner != TL.getInnerLoc().getType()) {
5760 Result = getDerived().RebuildParenType(Inner);
5761 if (Result.isNull())
5762 return QualType();
5763 }
5764
5765 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5766 NewTL.setLParenLoc(TL.getLParenLoc());
5767 NewTL.setRParenLoc(TL.getRParenLoc());
5768 return Result;
5769}
5770
5771template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005772QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005773 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005774 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005775
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005776 NestedNameSpecifierLoc QualifierLoc
5777 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5778 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005779 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005780
John McCallc392f372010-06-11 00:33:02 +00005781 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005782 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005783 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005784 QualifierLoc,
5785 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005786 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005787 if (Result.isNull())
5788 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005789
Abramo Bagnarad7548482010-05-19 21:37:53 +00005790 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5791 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005792 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5793
Abramo Bagnarad7548482010-05-19 21:37:53 +00005794 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005795 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005796 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005797 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005798 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005799 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005800 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005801 NewTL.setNameLoc(TL.getNameLoc());
5802 }
John McCall550e0c22009-10-21 00:40:46 +00005803 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005804}
Mike Stump11289f42009-09-09 15:08:12 +00005805
Douglas Gregord6ff3322009-08-04 16:50:30 +00005806template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005807QualType TreeTransform<Derived>::
5808 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005809 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005810 NestedNameSpecifierLoc QualifierLoc;
5811 if (TL.getQualifierLoc()) {
5812 QualifierLoc
5813 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5814 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005815 return QualType();
5816 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005817
John McCall31f82722010-11-12 08:19:04 +00005818 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005819 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005820}
5821
5822template<typename Derived>
5823QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005824TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5825 DependentTemplateSpecializationTypeLoc TL,
5826 NestedNameSpecifierLoc QualifierLoc) {
5827 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005828
Douglas Gregora7a795b2011-03-01 20:11:18 +00005829 TemplateArgumentListInfo NewTemplateArgs;
5830 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5831 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005832
Douglas Gregora7a795b2011-03-01 20:11:18 +00005833 typedef TemplateArgumentLocContainerIterator<
5834 DependentTemplateSpecializationTypeLoc> ArgIterator;
5835 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5836 ArgIterator(TL, TL.getNumArgs()),
5837 NewTemplateArgs))
5838 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005839
Douglas Gregora7a795b2011-03-01 20:11:18 +00005840 QualType Result
5841 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5842 QualifierLoc,
5843 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005844 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005845 NewTemplateArgs);
5846 if (Result.isNull())
5847 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005848
Douglas Gregora7a795b2011-03-01 20:11:18 +00005849 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5850 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005851
Douglas Gregora7a795b2011-03-01 20:11:18 +00005852 // Copy information relevant to the template specialization.
5853 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005854 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005855 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005856 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005857 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5858 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005859 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005860 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005861
Douglas Gregora7a795b2011-03-01 20:11:18 +00005862 // Copy information relevant to the elaborated type.
5863 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005864 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005865 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005866 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5867 DependentTemplateSpecializationTypeLoc SpecTL
5868 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005869 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005870 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005871 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005872 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005873 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5874 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005875 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005876 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005877 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005878 TemplateSpecializationTypeLoc SpecTL
5879 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005880 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005881 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005882 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5883 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005884 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005885 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005886 }
5887 return Result;
5888}
5889
5890template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005891QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5892 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005893 QualType Pattern
5894 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005895 if (Pattern.isNull())
5896 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005897
5898 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005899 if (getDerived().AlwaysRebuild() ||
5900 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005901 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005902 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005903 TL.getEllipsisLoc(),
5904 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005905 if (Result.isNull())
5906 return QualType();
5907 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005908
Douglas Gregor822d0302011-01-12 17:07:58 +00005909 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5910 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5911 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005912}
5913
5914template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005915QualType
5916TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005917 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005918 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005919 TLB.pushFullCopy(TL);
5920 return TL.getType();
5921}
5922
5923template<typename Derived>
5924QualType
5925TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005926 ObjCObjectTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00005927 // Transform base type.
5928 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
5929 if (BaseType.isNull())
5930 return QualType();
5931
5932 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
5933
5934 // Transform type arguments.
5935 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
5936 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
5937 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
5938 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
5939 QualType TypeArg = TypeArgInfo->getType();
5940 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
5941 AnyChanged = true;
5942
5943 // We have a pack expansion. Instantiate it.
5944 const auto *PackExpansion = PackExpansionLoc.getType()
5945 ->castAs<PackExpansionType>();
5946 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5947 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5948 Unexpanded);
5949 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5950
5951 // Determine whether the set of unexpanded parameter packs can
5952 // and should be expanded.
5953 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
5954 bool Expand = false;
5955 bool RetainExpansion = false;
5956 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5957 if (getDerived().TryExpandParameterPacks(
5958 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
5959 Unexpanded, Expand, RetainExpansion, NumExpansions))
5960 return QualType();
5961
5962 if (!Expand) {
5963 // We can't expand this pack expansion into separate arguments yet;
5964 // just substitute into the pattern and create a new pack expansion
5965 // type.
5966 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5967
5968 TypeLocBuilder TypeArgBuilder;
5969 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
5970 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
5971 PatternLoc);
5972 if (NewPatternType.isNull())
5973 return QualType();
5974
5975 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
5976 NewPatternType, NumExpansions);
5977 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
5978 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
5979 NewTypeArgInfos.push_back(
5980 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
5981 continue;
5982 }
5983
5984 // Substitute into the pack expansion pattern for each slice of the
5985 // pack.
5986 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5987 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5988
5989 TypeLocBuilder TypeArgBuilder;
5990 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
5991
5992 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
5993 PatternLoc);
5994 if (NewTypeArg.isNull())
5995 return QualType();
5996
5997 NewTypeArgInfos.push_back(
5998 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
5999 }
6000
6001 continue;
6002 }
6003
6004 TypeLocBuilder TypeArgBuilder;
6005 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
6006 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
6007 if (NewTypeArg.isNull())
6008 return QualType();
6009
6010 // If nothing changed, just keep the old TypeSourceInfo.
6011 if (NewTypeArg == TypeArg) {
6012 NewTypeArgInfos.push_back(TypeArgInfo);
6013 continue;
6014 }
6015
6016 NewTypeArgInfos.push_back(
6017 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6018 AnyChanged = true;
6019 }
6020
6021 QualType Result = TL.getType();
6022 if (getDerived().AlwaysRebuild() || AnyChanged) {
6023 // Rebuild the type.
6024 Result = getDerived().RebuildObjCObjectType(
6025 BaseType,
6026 TL.getLocStart(),
6027 TL.getTypeArgsLAngleLoc(),
6028 NewTypeArgInfos,
6029 TL.getTypeArgsRAngleLoc(),
6030 TL.getProtocolLAngleLoc(),
6031 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
6032 TL.getNumProtocols()),
6033 TL.getProtocolLocs(),
6034 TL.getProtocolRAngleLoc());
6035
6036 if (Result.isNull())
6037 return QualType();
6038 }
6039
6040 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006041 NewT.setHasBaseTypeAsWritten(true);
6042 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
6043 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
6044 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
6045 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
6046 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
6047 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
6048 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
6049 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
6050 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006051}
Mike Stump11289f42009-09-09 15:08:12 +00006052
6053template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006054QualType
6055TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006056 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006057 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
6058 if (PointeeType.isNull())
6059 return QualType();
6060
6061 QualType Result = TL.getType();
6062 if (getDerived().AlwaysRebuild() ||
6063 PointeeType != TL.getPointeeLoc().getType()) {
6064 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
6065 TL.getStarLoc());
6066 if (Result.isNull())
6067 return QualType();
6068 }
6069
6070 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
6071 NewT.setStarLoc(TL.getStarLoc());
6072 return Result;
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00006073}
6074
Douglas Gregord6ff3322009-08-04 16:50:30 +00006075//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00006076// Statement transformation
6077//===----------------------------------------------------------------------===//
6078template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006079StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006080TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006081 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006082}
6083
6084template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006085StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006086TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
6087 return getDerived().TransformCompoundStmt(S, false);
6088}
6089
6090template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006091StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006092TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00006093 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00006094 Sema::CompoundScopeRAII CompoundScope(getSema());
6095
John McCall1ababa62010-08-27 19:56:05 +00006096 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00006097 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006098 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006099 for (auto *B : S->body()) {
6100 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00006101 if (Result.isInvalid()) {
6102 // Immediately fail if this was a DeclStmt, since it's very
6103 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006104 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00006105 return StmtError();
6106
6107 // Otherwise, just keep processing substatements and fail later.
6108 SubStmtInvalid = true;
6109 continue;
6110 }
Mike Stump11289f42009-09-09 15:08:12 +00006111
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006112 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006113 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006114 }
Mike Stump11289f42009-09-09 15:08:12 +00006115
John McCall1ababa62010-08-27 19:56:05 +00006116 if (SubStmtInvalid)
6117 return StmtError();
6118
Douglas Gregorebe10102009-08-20 07:17:43 +00006119 if (!getDerived().AlwaysRebuild() &&
6120 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006121 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006122
6123 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006124 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00006125 S->getRBracLoc(),
6126 IsStmtExpr);
6127}
Mike Stump11289f42009-09-09 15:08:12 +00006128
Douglas Gregorebe10102009-08-20 07:17:43 +00006129template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006130StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006131TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006132 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00006133 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00006134 EnterExpressionEvaluationContext Unevaluated(SemaRef,
6135 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006136
Eli Friedman06577382009-11-19 03:14:00 +00006137 // Transform the left-hand case value.
6138 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00006139 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00006140 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006141 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006142
Eli Friedman06577382009-11-19 03:14:00 +00006143 // Transform the right-hand case value (for the GNU case-range extension).
6144 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00006145 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00006146 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006147 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00006148 }
Mike Stump11289f42009-09-09 15:08:12 +00006149
Douglas Gregorebe10102009-08-20 07:17:43 +00006150 // Build the case statement.
6151 // Case statements are always rebuilt so that they will attached to their
6152 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006153 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00006154 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006155 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00006156 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006157 S->getColonLoc());
6158 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006159 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006160
Douglas Gregorebe10102009-08-20 07:17:43 +00006161 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00006162 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006163 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006164 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006165
Douglas Gregorebe10102009-08-20 07:17:43 +00006166 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00006167 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006168}
6169
6170template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006171StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006172TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006173 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00006174 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006175 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006176 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006177
Douglas Gregorebe10102009-08-20 07:17:43 +00006178 // Default statements are always rebuilt
6179 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006180 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006181}
Mike Stump11289f42009-09-09 15:08:12 +00006182
Douglas Gregorebe10102009-08-20 07:17:43 +00006183template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006184StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006185TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006186 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006187 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006188 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006189
Chris Lattnercab02a62011-02-17 20:34:02 +00006190 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
6191 S->getDecl());
6192 if (!LD)
6193 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00006194
6195
Douglas Gregorebe10102009-08-20 07:17:43 +00006196 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00006197 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006198 cast<LabelDecl>(LD), SourceLocation(),
6199 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006200}
Mike Stump11289f42009-09-09 15:08:12 +00006201
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006202template <typename Derived>
6203const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
6204 if (!R)
6205 return R;
6206
6207 switch (R->getKind()) {
6208// Transform attributes with a pragma spelling by calling TransformXXXAttr.
6209#define ATTR(X)
6210#define PRAGMA_SPELLING_ATTR(X) \
6211 case attr::X: \
6212 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
6213#include "clang/Basic/AttrList.inc"
6214 default:
6215 return R;
6216 }
6217}
6218
6219template <typename Derived>
6220StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
6221 bool AttrsChanged = false;
6222 SmallVector<const Attr *, 1> Attrs;
6223
6224 // Visit attributes and keep track if any are transformed.
6225 for (const auto *I : S->getAttrs()) {
6226 const Attr *R = getDerived().TransformAttr(I);
6227 AttrsChanged |= (I != R);
6228 Attrs.push_back(R);
6229 }
6230
Richard Smithc202b282012-04-14 00:33:13 +00006231 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6232 if (SubStmt.isInvalid())
6233 return StmtError();
6234
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006235 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
Richard Smithc202b282012-04-14 00:33:13 +00006236 return S;
6237
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006238 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00006239 SubStmt.get());
6240}
6241
6242template<typename Derived>
6243StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006244TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006245 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006246 Sema::ConditionResult Cond = getDerived().TransformCondition(
6247 S->getIfLoc(), S->getConditionVariable(), S->getCond(),
Richard Smithb130fe72016-06-23 19:16:49 +00006248 S->isConstexpr() ? Sema::ConditionKind::ConstexprIf
6249 : Sema::ConditionKind::Boolean);
Richard Smith03a4aa32016-06-23 19:02:52 +00006250 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006251 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006252
Richard Smithb130fe72016-06-23 19:16:49 +00006253 // If this is a constexpr if, determine which arm we should instantiate.
6254 llvm::Optional<bool> ConstexprConditionValue;
6255 if (S->isConstexpr())
6256 ConstexprConditionValue = Cond.getKnownValue();
6257
Douglas Gregorebe10102009-08-20 07:17:43 +00006258 // Transform the "then" branch.
Richard Smithb130fe72016-06-23 19:16:49 +00006259 StmtResult Then;
6260 if (!ConstexprConditionValue || *ConstexprConditionValue) {
6261 Then = getDerived().TransformStmt(S->getThen());
6262 if (Then.isInvalid())
6263 return StmtError();
6264 } else {
6265 Then = new (getSema().Context) NullStmt(S->getThen()->getLocStart());
6266 }
Mike Stump11289f42009-09-09 15:08:12 +00006267
Douglas Gregorebe10102009-08-20 07:17:43 +00006268 // Transform the "else" branch.
Richard Smithb130fe72016-06-23 19:16:49 +00006269 StmtResult Else;
6270 if (!ConstexprConditionValue || !*ConstexprConditionValue) {
6271 Else = getDerived().TransformStmt(S->getElse());
6272 if (Else.isInvalid())
6273 return StmtError();
6274 }
Mike Stump11289f42009-09-09 15:08:12 +00006275
Douglas Gregorebe10102009-08-20 07:17:43 +00006276 if (!getDerived().AlwaysRebuild() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006277 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006278 Then.get() == S->getThen() &&
6279 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006280 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006281
Richard Smithb130fe72016-06-23 19:16:49 +00006282 return getDerived().RebuildIfStmt(S->getIfLoc(), S->isConstexpr(), Cond,
6283 Then.get(), S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006284}
6285
6286template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006287StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006288TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006289 // Transform the condition.
Richard Smith03a4aa32016-06-23 19:02:52 +00006290 Sema::ConditionResult Cond = getDerived().TransformCondition(
6291 S->getSwitchLoc(), S->getConditionVariable(), S->getCond(),
6292 Sema::ConditionKind::Switch);
6293 if (Cond.isInvalid())
6294 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006295
Douglas Gregorebe10102009-08-20 07:17:43 +00006296 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006297 StmtResult Switch
Richard Smith03a4aa32016-06-23 19:02:52 +00006298 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond);
Douglas Gregorebe10102009-08-20 07:17:43 +00006299 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006300 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006301
Douglas Gregorebe10102009-08-20 07:17:43 +00006302 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006303 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006304 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006305 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006306
Douglas Gregorebe10102009-08-20 07:17:43 +00006307 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00006308 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
6309 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006310}
Mike Stump11289f42009-09-09 15:08:12 +00006311
Douglas Gregorebe10102009-08-20 07:17:43 +00006312template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006313StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006314TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006315 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006316 Sema::ConditionResult Cond = getDerived().TransformCondition(
6317 S->getWhileLoc(), S->getConditionVariable(), S->getCond(),
6318 Sema::ConditionKind::Boolean);
6319 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006320 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006321
Douglas Gregorebe10102009-08-20 07:17:43 +00006322 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006323 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006324 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006325 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006326
Douglas Gregorebe10102009-08-20 07:17:43 +00006327 if (!getDerived().AlwaysRebuild() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006328 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006329 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00006330 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00006331
Richard Smith03a4aa32016-06-23 19:02:52 +00006332 return getDerived().RebuildWhileStmt(S->getWhileLoc(), Cond, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006333}
Mike Stump11289f42009-09-09 15:08:12 +00006334
Douglas Gregorebe10102009-08-20 07:17:43 +00006335template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006336StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006337TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006338 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006339 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006340 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006341 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006342
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006343 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006344 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006345 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006346 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006347
Douglas Gregorebe10102009-08-20 07:17:43 +00006348 if (!getDerived().AlwaysRebuild() &&
6349 Cond.get() == S->getCond() &&
6350 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006351 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006352
John McCallb268a282010-08-23 23:25:46 +00006353 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
6354 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006355 S->getRParenLoc());
6356}
Mike Stump11289f42009-09-09 15:08:12 +00006357
Douglas Gregorebe10102009-08-20 07:17:43 +00006358template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006359StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006360TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006361 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00006362 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00006363 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006364 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006365
Alexey Bataeva636c7f2015-12-23 10:27:45 +00006366 // In OpenMP loop region loop control variable must be captured and be
6367 // private. Perform analysis of first part (if any).
6368 if (getSema().getLangOpts().OpenMP && Init.isUsable())
6369 getSema().ActOnOpenMPLoopInitialization(S->getForLoc(), Init.get());
6370
Douglas Gregorebe10102009-08-20 07:17:43 +00006371 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006372 Sema::ConditionResult Cond = getDerived().TransformCondition(
6373 S->getForLoc(), S->getConditionVariable(), S->getCond(),
6374 Sema::ConditionKind::Boolean);
6375 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006376 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006377
Douglas Gregorebe10102009-08-20 07:17:43 +00006378 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00006379 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006380 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006381 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006382
Richard Smith945f8d32013-01-14 22:39:08 +00006383 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00006384 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006385 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006386
Douglas Gregorebe10102009-08-20 07:17:43 +00006387 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006388 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006389 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006390 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006391
Douglas Gregorebe10102009-08-20 07:17:43 +00006392 if (!getDerived().AlwaysRebuild() &&
6393 Init.get() == S->getInit() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006394 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006395 Inc.get() == S->getInc() &&
6396 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006397 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006398
Douglas Gregorebe10102009-08-20 07:17:43 +00006399 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Richard Smith03a4aa32016-06-23 19:02:52 +00006400 Init.get(), Cond, FullInc,
6401 S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006402}
6403
6404template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006405StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006406TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006407 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6408 S->getLabel());
6409 if (!LD)
6410 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006411
Douglas Gregorebe10102009-08-20 07:17:43 +00006412 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00006413 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006414 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00006415}
6416
6417template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006418StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006419TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006420 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00006421 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006422 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006423 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00006424
Douglas Gregorebe10102009-08-20 07:17:43 +00006425 if (!getDerived().AlwaysRebuild() &&
6426 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006427 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006428
6429 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00006430 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006431}
6432
6433template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006434StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006435TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006436 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006437}
Mike Stump11289f42009-09-09 15:08:12 +00006438
Douglas Gregorebe10102009-08-20 07:17:43 +00006439template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006440StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006441TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006442 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006443}
Mike Stump11289f42009-09-09 15:08:12 +00006444
Douglas Gregorebe10102009-08-20 07:17:43 +00006445template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006446StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006447TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00006448 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6449 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00006450 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006451 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006452
Mike Stump11289f42009-09-09 15:08:12 +00006453 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00006454 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00006455 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006456}
Mike Stump11289f42009-09-09 15:08:12 +00006457
Douglas Gregorebe10102009-08-20 07:17:43 +00006458template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006459StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006460TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006461 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006462 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006463 for (auto *D : S->decls()) {
6464 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00006465 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00006466 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006467
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006468 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00006469 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00006470
Douglas Gregorebe10102009-08-20 07:17:43 +00006471 Decls.push_back(Transformed);
6472 }
Mike Stump11289f42009-09-09 15:08:12 +00006473
Douglas Gregorebe10102009-08-20 07:17:43 +00006474 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006475 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006476
Rafael Espindolaab417692013-07-09 12:05:01 +00006477 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006478}
Mike Stump11289f42009-09-09 15:08:12 +00006479
Douglas Gregorebe10102009-08-20 07:17:43 +00006480template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006481StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00006482TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006483
Benjamin Kramerf0623432012-08-23 22:51:59 +00006484 SmallVector<Expr*, 8> Constraints;
6485 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006486 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00006487
John McCalldadc5752010-08-24 06:29:42 +00006488 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006489 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006490
6491 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00006492
Anders Carlssonaaeef072010-01-24 05:50:09 +00006493 // Go through the outputs.
6494 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006495 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006496
Anders Carlssonaaeef072010-01-24 05:50:09 +00006497 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006498 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006499
Anders Carlssonaaeef072010-01-24 05:50:09 +00006500 // Transform the output expr.
6501 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006502 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006503 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006504 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006505
Anders Carlssonaaeef072010-01-24 05:50:09 +00006506 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006507
John McCallb268a282010-08-23 23:25:46 +00006508 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006509 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006510
Anders Carlssonaaeef072010-01-24 05:50:09 +00006511 // Go through the inputs.
6512 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006513 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006514
Anders Carlssonaaeef072010-01-24 05:50:09 +00006515 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006516 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006517
Anders Carlssonaaeef072010-01-24 05:50:09 +00006518 // Transform the input expr.
6519 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006520 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006521 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006522 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006523
Anders Carlssonaaeef072010-01-24 05:50:09 +00006524 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006525
John McCallb268a282010-08-23 23:25:46 +00006526 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006527 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006528
Anders Carlssonaaeef072010-01-24 05:50:09 +00006529 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006530 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006531
6532 // Go through the clobbers.
6533 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00006534 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00006535
6536 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006537 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00006538 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
6539 S->isVolatile(), S->getNumOutputs(),
6540 S->getNumInputs(), Names.data(),
6541 Constraints, Exprs, AsmString.get(),
6542 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006543}
6544
Chad Rosier32503022012-06-11 20:47:18 +00006545template<typename Derived>
6546StmtResult
6547TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00006548 ArrayRef<Token> AsmToks =
6549 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00006550
John McCallf413f5e2013-05-03 00:10:13 +00006551 bool HadError = false, HadChange = false;
6552
6553 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6554 SmallVector<Expr*, 8> TransformedExprs;
6555 TransformedExprs.reserve(SrcExprs.size());
6556 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6557 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
6558 if (!Result.isUsable()) {
6559 HadError = true;
6560 } else {
6561 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006562 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00006563 }
6564 }
6565
6566 if (HadError) return StmtError();
6567 if (!HadChange && !getDerived().AlwaysRebuild())
6568 return Owned(S);
6569
Chad Rosierb6f46c12012-08-15 16:53:30 +00006570 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00006571 AsmToks, S->getAsmString(),
6572 S->getNumOutputs(), S->getNumInputs(),
6573 S->getAllConstraints(), S->getClobbers(),
6574 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00006575}
Douglas Gregorebe10102009-08-20 07:17:43 +00006576
Richard Smith9f690bd2015-10-27 06:02:45 +00006577// C++ Coroutines TS
6578
6579template<typename Derived>
6580StmtResult
6581TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) {
6582 // The coroutine body should be re-formed by the caller if necessary.
6583 return getDerived().TransformStmt(S->getBody());
6584}
6585
6586template<typename Derived>
6587StmtResult
6588TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
6589 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
6590 /*NotCopyInit*/false);
6591 if (Result.isInvalid())
6592 return StmtError();
6593
6594 // Always rebuild; we don't know if this needs to be injected into a new
6595 // context or if the promise type has changed.
6596 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get());
6597}
6598
6599template<typename Derived>
6600ExprResult
6601TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) {
6602 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
6603 /*NotCopyInit*/false);
6604 if (Result.isInvalid())
6605 return ExprError();
6606
6607 // Always rebuild; we don't know if this needs to be injected into a new
6608 // context or if the promise type has changed.
6609 return getDerived().RebuildCoawaitExpr(E->getKeywordLoc(), Result.get());
6610}
6611
6612template<typename Derived>
6613ExprResult
6614TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) {
6615 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
6616 /*NotCopyInit*/false);
6617 if (Result.isInvalid())
6618 return ExprError();
6619
6620 // Always rebuild; we don't know if this needs to be injected into a new
6621 // context or if the promise type has changed.
6622 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
6623}
6624
6625// Objective-C Statements.
6626
Douglas Gregorebe10102009-08-20 07:17:43 +00006627template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006628StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006629TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006630 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00006631 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006632 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006633 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006634
Douglas Gregor96c79492010-04-23 22:50:49 +00006635 // Transform the @catch statements (if present).
6636 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006637 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00006638 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006639 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00006640 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006641 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00006642 if (Catch.get() != S->getCatchStmt(I))
6643 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006644 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006645 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006646
Douglas Gregor306de2f2010-04-22 23:59:56 +00006647 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00006648 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006649 if (S->getFinallyStmt()) {
6650 Finally = getDerived().TransformStmt(S->getFinallyStmt());
6651 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006652 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00006653 }
6654
6655 // If nothing changed, just retain this statement.
6656 if (!getDerived().AlwaysRebuild() &&
6657 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00006658 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00006659 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006660 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006661
Douglas Gregor306de2f2010-04-22 23:59:56 +00006662 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00006663 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006664 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006665}
Mike Stump11289f42009-09-09 15:08:12 +00006666
Douglas Gregorebe10102009-08-20 07:17:43 +00006667template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006668StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006669TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006670 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00006671 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006672 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006673 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006674 if (FromVar->getTypeSourceInfo()) {
6675 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
6676 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006677 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006678 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006679
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006680 QualType T;
6681 if (TSInfo)
6682 T = TSInfo->getType();
6683 else {
6684 T = getDerived().TransformType(FromVar->getType());
6685 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00006686 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006687 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006688
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006689 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6690 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00006691 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006692 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006693
John McCalldadc5752010-08-24 06:29:42 +00006694 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006695 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006696 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006697
6698 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006699 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006700 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006701}
Mike Stump11289f42009-09-09 15:08:12 +00006702
Douglas Gregorebe10102009-08-20 07:17:43 +00006703template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006704StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006705TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006706 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006707 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006708 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006709 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006710
Douglas Gregor306de2f2010-04-22 23:59:56 +00006711 // If nothing changed, just retain this statement.
6712 if (!getDerived().AlwaysRebuild() &&
6713 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006714 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006715
6716 // Build a new statement.
6717 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00006718 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006719}
Mike Stump11289f42009-09-09 15:08:12 +00006720
Douglas Gregorebe10102009-08-20 07:17:43 +00006721template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006722StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006723TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006724 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00006725 if (S->getThrowExpr()) {
6726 Operand = getDerived().TransformExpr(S->getThrowExpr());
6727 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006728 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00006729 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006730
Douglas Gregor2900c162010-04-22 21:44:01 +00006731 if (!getDerived().AlwaysRebuild() &&
6732 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006733 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006734
John McCallb268a282010-08-23 23:25:46 +00006735 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006736}
Mike Stump11289f42009-09-09 15:08:12 +00006737
Douglas Gregorebe10102009-08-20 07:17:43 +00006738template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006739StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006740TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006741 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00006742 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00006743 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00006744 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006745 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00006746 Object =
6747 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6748 Object.get());
6749 if (Object.isInvalid())
6750 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006751
Douglas Gregor6148de72010-04-22 22:01:21 +00006752 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006753 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00006754 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006755 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006756
Douglas Gregor6148de72010-04-22 22:01:21 +00006757 // If nothing change, just retain the current statement.
6758 if (!getDerived().AlwaysRebuild() &&
6759 Object.get() == S->getSynchExpr() &&
6760 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006761 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00006762
6763 // Build a new statement.
6764 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00006765 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006766}
6767
6768template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006769StmtResult
John McCall31168b02011-06-15 23:02:42 +00006770TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6771 ObjCAutoreleasePoolStmt *S) {
6772 // Transform the body.
6773 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6774 if (Body.isInvalid())
6775 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006776
John McCall31168b02011-06-15 23:02:42 +00006777 // If nothing changed, just retain this statement.
6778 if (!getDerived().AlwaysRebuild() &&
6779 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006780 return S;
John McCall31168b02011-06-15 23:02:42 +00006781
6782 // Build a new statement.
6783 return getDerived().RebuildObjCAutoreleasePoolStmt(
6784 S->getAtLoc(), Body.get());
6785}
6786
6787template<typename Derived>
6788StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006789TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006790 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006791 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006792 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006793 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006794 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006795
Douglas Gregorf68a5082010-04-22 23:10:45 +00006796 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006797 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006798 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006799 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006800
Douglas Gregorf68a5082010-04-22 23:10:45 +00006801 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006802 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006803 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006804 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006805
Douglas Gregorf68a5082010-04-22 23:10:45 +00006806 // If nothing changed, just retain this statement.
6807 if (!getDerived().AlwaysRebuild() &&
6808 Element.get() == S->getElement() &&
6809 Collection.get() == S->getCollection() &&
6810 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006811 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006812
Douglas Gregorf68a5082010-04-22 23:10:45 +00006813 // Build a new statement.
6814 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006815 Element.get(),
6816 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006817 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006818 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006819}
6820
David Majnemer5f7efef2013-10-15 09:50:08 +00006821template <typename Derived>
6822StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006823 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006824 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006825 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6826 TypeSourceInfo *T =
6827 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006828 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006829 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006830
David Majnemer5f7efef2013-10-15 09:50:08 +00006831 Var = getDerived().RebuildExceptionDecl(
6832 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6833 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006834 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006835 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006836 }
Mike Stump11289f42009-09-09 15:08:12 +00006837
Douglas Gregorebe10102009-08-20 07:17:43 +00006838 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006839 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006840 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006841 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006842
David Majnemer5f7efef2013-10-15 09:50:08 +00006843 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006844 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006845 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006846
David Majnemer5f7efef2013-10-15 09:50:08 +00006847 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006848}
Mike Stump11289f42009-09-09 15:08:12 +00006849
David Majnemer5f7efef2013-10-15 09:50:08 +00006850template <typename Derived>
6851StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006852 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006853 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006854 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006855 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006856
Douglas Gregorebe10102009-08-20 07:17:43 +00006857 // Transform the handlers.
6858 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006859 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006860 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006861 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006862 if (Handler.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 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006866 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006867 }
Mike Stump11289f42009-09-09 15:08:12 +00006868
David Majnemer5f7efef2013-10-15 09:50:08 +00006869 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006870 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006871 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006872
John McCallb268a282010-08-23 23:25:46 +00006873 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006874 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006875}
Mike Stump11289f42009-09-09 15:08:12 +00006876
Richard Smith02e85f32011-04-14 22:09:26 +00006877template<typename Derived>
6878StmtResult
6879TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6880 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6881 if (Range.isInvalid())
6882 return StmtError();
6883
Richard Smith01694c32016-03-20 10:33:40 +00006884 StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
6885 if (Begin.isInvalid())
6886 return StmtError();
6887 StmtResult End = getDerived().TransformStmt(S->getEndStmt());
6888 if (End.isInvalid())
Richard Smith02e85f32011-04-14 22:09:26 +00006889 return StmtError();
6890
6891 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6892 if (Cond.isInvalid())
6893 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006894 if (Cond.get())
Richard Smith03a4aa32016-06-23 19:02:52 +00006895 Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get());
Eli Friedman87d32802012-01-31 22:45:40 +00006896 if (Cond.isInvalid())
6897 return StmtError();
6898 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006899 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006900
6901 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6902 if (Inc.isInvalid())
6903 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006904 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006905 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006906
6907 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6908 if (LoopVar.isInvalid())
6909 return StmtError();
6910
6911 StmtResult NewStmt = S;
6912 if (getDerived().AlwaysRebuild() ||
6913 Range.get() != S->getRangeStmt() ||
Richard Smith01694c32016-03-20 10:33:40 +00006914 Begin.get() != S->getBeginStmt() ||
6915 End.get() != S->getEndStmt() ||
Richard Smith02e85f32011-04-14 22:09:26 +00006916 Cond.get() != S->getCond() ||
6917 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006918 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006919 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00006920 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00006921 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00006922 Begin.get(), End.get(),
6923 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00006924 Inc.get(), LoopVar.get(),
6925 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006926 if (NewStmt.isInvalid())
6927 return StmtError();
6928 }
Richard Smith02e85f32011-04-14 22:09:26 +00006929
6930 StmtResult Body = getDerived().TransformStmt(S->getBody());
6931 if (Body.isInvalid())
6932 return StmtError();
6933
6934 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6935 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006936 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006937 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00006938 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00006939 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00006940 Begin.get(), End.get(),
6941 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00006942 Inc.get(), LoopVar.get(),
6943 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006944 if (NewStmt.isInvalid())
6945 return StmtError();
6946 }
Richard Smith02e85f32011-04-14 22:09:26 +00006947
6948 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006949 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00006950
6951 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6952}
6953
John Wiegley1c0675e2011-04-28 01:08:34 +00006954template<typename Derived>
6955StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006956TreeTransform<Derived>::TransformMSDependentExistsStmt(
6957 MSDependentExistsStmt *S) {
6958 // Transform the nested-name-specifier, if any.
6959 NestedNameSpecifierLoc QualifierLoc;
6960 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006961 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006962 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6963 if (!QualifierLoc)
6964 return StmtError();
6965 }
6966
6967 // Transform the declaration name.
6968 DeclarationNameInfo NameInfo = S->getNameInfo();
6969 if (NameInfo.getName()) {
6970 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6971 if (!NameInfo.getName())
6972 return StmtError();
6973 }
6974
6975 // Check whether anything changed.
6976 if (!getDerived().AlwaysRebuild() &&
6977 QualifierLoc == S->getQualifierLoc() &&
6978 NameInfo.getName() == S->getNameInfo().getName())
6979 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006980
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006981 // Determine whether this name exists, if we can.
6982 CXXScopeSpec SS;
6983 SS.Adopt(QualifierLoc);
6984 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00006985 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006986 case Sema::IER_Exists:
6987 if (S->isIfExists())
6988 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006989
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006990 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6991
6992 case Sema::IER_DoesNotExist:
6993 if (S->isIfNotExists())
6994 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006995
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006996 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006997
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006998 case Sema::IER_Dependent:
6999 Dependent = true;
7000 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007001
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00007002 case Sema::IER_Error:
7003 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007004 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007005
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007006 // We need to continue with the instantiation, so do so now.
7007 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
7008 if (SubStmt.isInvalid())
7009 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007010
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007011 // If we have resolved the name, just transform to the substatement.
7012 if (!Dependent)
7013 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00007014
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007015 // The name is still dependent, so build a dependent expression again.
7016 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
7017 S->isIfExists(),
7018 QualifierLoc,
7019 NameInfo,
7020 SubStmt.get());
7021}
7022
7023template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00007024ExprResult
7025TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
7026 NestedNameSpecifierLoc QualifierLoc;
7027 if (E->getQualifierLoc()) {
7028 QualifierLoc
7029 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7030 if (!QualifierLoc)
7031 return ExprError();
7032 }
7033
7034 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
7035 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
7036 if (!PD)
7037 return ExprError();
7038
7039 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
7040 if (Base.isInvalid())
7041 return ExprError();
7042
7043 return new (SemaRef.getASTContext())
7044 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
7045 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
7046 QualifierLoc, E->getMemberLoc());
7047}
7048
David Majnemerfad8f482013-10-15 09:33:02 +00007049template <typename Derived>
Alexey Bataevf7630272015-11-25 12:01:00 +00007050ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr(
7051 MSPropertySubscriptExpr *E) {
7052 auto BaseRes = getDerived().TransformExpr(E->getBase());
7053 if (BaseRes.isInvalid())
7054 return ExprError();
7055 auto IdxRes = getDerived().TransformExpr(E->getIdx());
7056 if (IdxRes.isInvalid())
7057 return ExprError();
7058
7059 if (!getDerived().AlwaysRebuild() &&
7060 BaseRes.get() == E->getBase() &&
7061 IdxRes.get() == E->getIdx())
7062 return E;
7063
7064 return getDerived().RebuildArraySubscriptExpr(
7065 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
7066}
7067
7068template <typename Derived>
David Majnemerfad8f482013-10-15 09:33:02 +00007069StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007070 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007071 if (TryBlock.isInvalid())
7072 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007073
7074 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00007075 if (Handler.isInvalid())
7076 return StmtError();
7077
David Majnemerfad8f482013-10-15 09:33:02 +00007078 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
7079 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007080 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00007081
Warren Huntf6be4cb2014-07-25 20:52:51 +00007082 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
7083 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007084}
7085
David Majnemerfad8f482013-10-15 09:33:02 +00007086template <typename Derived>
7087StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007088 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007089 if (Block.isInvalid())
7090 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007091
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007092 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007093}
7094
David Majnemerfad8f482013-10-15 09:33:02 +00007095template <typename Derived>
7096StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00007097 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00007098 if (FilterExpr.isInvalid())
7099 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007100
David Majnemer7e755502013-10-15 09:30:14 +00007101 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007102 if (Block.isInvalid())
7103 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007104
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007105 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
7106 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007107}
7108
David Majnemerfad8f482013-10-15 09:33:02 +00007109template <typename Derived>
7110StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
7111 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00007112 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
7113 else
7114 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
7115}
7116
Nico Weber9b982072014-07-07 00:12:30 +00007117template<typename Derived>
7118StmtResult
7119TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
7120 return S;
7121}
7122
Alexander Musman64d33f12014-06-04 07:53:32 +00007123//===----------------------------------------------------------------------===//
7124// OpenMP directive transformation
7125//===----------------------------------------------------------------------===//
7126template <typename Derived>
7127StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
7128 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007129
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007130 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00007131 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007132 ArrayRef<OMPClause *> Clauses = D->clauses();
7133 TClauses.reserve(Clauses.size());
7134 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
7135 I != E; ++I) {
7136 if (*I) {
Alexey Bataevaac108a2015-06-23 04:51:00 +00007137 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007138 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevaac108a2015-06-23 04:51:00 +00007139 getDerived().getSema().EndOpenMPClause();
Alexey Bataevc5e02582014-06-16 07:08:35 +00007140 if (Clause)
7141 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00007142 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00007143 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007144 }
7145 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007146 StmtResult AssociatedStmt;
Alexey Bataeveb482352015-12-18 05:05:56 +00007147 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00007148 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
7149 /*CurScope=*/nullptr);
7150 StmtResult Body;
7151 {
7152 Sema::CompoundScopeRAII CompoundScope(getSema());
7153 Body = getDerived().TransformStmt(
7154 cast<CapturedStmt>(D->getAssociatedStmt())->getCapturedStmt());
7155 }
7156 AssociatedStmt =
7157 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
Alexey Bataev68446b72014-07-18 07:47:19 +00007158 if (AssociatedStmt.isInvalid()) {
7159 return StmtError();
7160 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00007161 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007162 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007163 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00007164 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007165
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007166 // Transform directive name for 'omp critical' directive.
7167 DeclarationNameInfo DirName;
7168 if (D->getDirectiveKind() == OMPD_critical) {
7169 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
7170 DirName = getDerived().TransformDeclarationNameInfo(DirName);
7171 }
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007172 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
7173 if (D->getDirectiveKind() == OMPD_cancellation_point) {
7174 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
Alexey Bataev80909872015-07-02 11:25:17 +00007175 } else if (D->getDirectiveKind() == OMPD_cancel) {
7176 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007177 }
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007178
Alexander Musman64d33f12014-06-04 07:53:32 +00007179 return getDerived().RebuildOMPExecutableDirective(
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007180 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
7181 AssociatedStmt.get(), D->getLocStart(), D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007182}
7183
Alexander Musman64d33f12014-06-04 07:53:32 +00007184template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007185StmtResult
7186TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
7187 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007188 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
7189 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007190 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7191 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7192 return Res;
7193}
7194
Alexander Musman64d33f12014-06-04 07:53:32 +00007195template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007196StmtResult
7197TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
7198 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007199 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
7200 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007201 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7202 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007203 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007204}
7205
Alexey Bataevf29276e2014-06-18 04:14:57 +00007206template <typename Derived>
7207StmtResult
7208TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
7209 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007210 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
7211 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00007212 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7213 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7214 return Res;
7215}
7216
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007217template <typename Derived>
7218StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00007219TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
7220 DeclarationNameInfo DirName;
7221 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
7222 D->getLocStart());
7223 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7224 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7225 return Res;
7226}
7227
7228template <typename Derived>
7229StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007230TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
7231 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007232 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
7233 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007234 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7235 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7236 return Res;
7237}
7238
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007239template <typename Derived>
7240StmtResult
7241TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
7242 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007243 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
7244 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007245 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7246 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7247 return Res;
7248}
7249
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007250template <typename Derived>
7251StmtResult
7252TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
7253 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007254 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
7255 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007256 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7257 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7258 return Res;
7259}
7260
Alexey Bataev4acb8592014-07-07 13:01:15 +00007261template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00007262StmtResult
7263TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
7264 DeclarationNameInfo DirName;
7265 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
7266 D->getLocStart());
7267 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7268 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7269 return Res;
7270}
7271
7272template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007273StmtResult
7274TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
7275 getDerived().getSema().StartOpenMPDSABlock(
7276 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
7277 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7278 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7279 return Res;
7280}
7281
7282template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00007283StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
7284 OMPParallelForDirective *D) {
7285 DeclarationNameInfo DirName;
7286 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
7287 nullptr, D->getLocStart());
7288 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7289 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7290 return Res;
7291}
7292
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007293template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00007294StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
7295 OMPParallelForSimdDirective *D) {
7296 DeclarationNameInfo DirName;
7297 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
7298 nullptr, D->getLocStart());
7299 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7300 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7301 return Res;
7302}
7303
7304template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007305StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
7306 OMPParallelSectionsDirective *D) {
7307 DeclarationNameInfo DirName;
7308 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
7309 nullptr, D->getLocStart());
7310 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7311 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7312 return Res;
7313}
7314
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00007315template <typename Derived>
7316StmtResult
7317TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
7318 DeclarationNameInfo DirName;
7319 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
7320 D->getLocStart());
7321 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7322 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7323 return Res;
7324}
7325
Alexey Bataev68446b72014-07-18 07:47:19 +00007326template <typename Derived>
7327StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
7328 OMPTaskyieldDirective *D) {
7329 DeclarationNameInfo DirName;
7330 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
7331 D->getLocStart());
7332 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7333 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7334 return Res;
7335}
7336
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00007337template <typename Derived>
7338StmtResult
7339TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
7340 DeclarationNameInfo DirName;
7341 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
7342 D->getLocStart());
7343 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7344 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7345 return Res;
7346}
7347
Alexey Bataev2df347a2014-07-18 10:17:07 +00007348template <typename Derived>
7349StmtResult
7350TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
7351 DeclarationNameInfo DirName;
7352 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
7353 D->getLocStart());
7354 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7355 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7356 return Res;
7357}
7358
Alexey Bataev6125da92014-07-21 11:26:11 +00007359template <typename Derived>
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00007360StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
7361 OMPTaskgroupDirective *D) {
7362 DeclarationNameInfo DirName;
7363 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
7364 D->getLocStart());
7365 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7366 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7367 return Res;
7368}
7369
7370template <typename Derived>
Alexey Bataev6125da92014-07-21 11:26:11 +00007371StmtResult
7372TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
7373 DeclarationNameInfo DirName;
7374 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
7375 D->getLocStart());
7376 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7377 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7378 return Res;
7379}
7380
Alexey Bataev9fb6e642014-07-22 06:45:04 +00007381template <typename Derived>
7382StmtResult
7383TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
7384 DeclarationNameInfo DirName;
7385 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
7386 D->getLocStart());
7387 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7388 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7389 return Res;
7390}
7391
Alexey Bataev0162e452014-07-22 10:10:35 +00007392template <typename Derived>
7393StmtResult
7394TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
7395 DeclarationNameInfo DirName;
7396 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
7397 D->getLocStart());
7398 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7399 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7400 return Res;
7401}
7402
Alexey Bataev0bd520b2014-09-19 08:19:49 +00007403template <typename Derived>
7404StmtResult
7405TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
7406 DeclarationNameInfo DirName;
7407 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
7408 D->getLocStart());
7409 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7410 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7411 return Res;
7412}
7413
Alexey Bataev13314bf2014-10-09 04:18:56 +00007414template <typename Derived>
Michael Wong65f367f2015-07-21 13:44:28 +00007415StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
7416 OMPTargetDataDirective *D) {
7417 DeclarationNameInfo DirName;
7418 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
7419 D->getLocStart());
7420 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7421 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7422 return Res;
7423}
7424
7425template <typename Derived>
Samuel Antaodf67fc42016-01-19 19:15:56 +00007426StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective(
7427 OMPTargetEnterDataDirective *D) {
7428 DeclarationNameInfo DirName;
7429 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_enter_data, DirName,
7430 nullptr, D->getLocStart());
7431 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7432 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7433 return Res;
7434}
7435
7436template <typename Derived>
Samuel Antao72590762016-01-19 20:04:50 +00007437StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective(
7438 OMPTargetExitDataDirective *D) {
7439 DeclarationNameInfo DirName;
7440 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_exit_data, DirName,
7441 nullptr, D->getLocStart());
7442 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7443 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7444 return Res;
7445}
7446
7447template <typename Derived>
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +00007448StmtResult TreeTransform<Derived>::TransformOMPTargetParallelDirective(
7449 OMPTargetParallelDirective *D) {
7450 DeclarationNameInfo DirName;
7451 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel, DirName,
7452 nullptr, D->getLocStart());
7453 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7454 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7455 return Res;
7456}
7457
7458template <typename Derived>
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +00007459StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForDirective(
7460 OMPTargetParallelForDirective *D) {
7461 DeclarationNameInfo DirName;
7462 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for, DirName,
7463 nullptr, D->getLocStart());
7464 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7465 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7466 return Res;
7467}
7468
7469template <typename Derived>
Samuel Antao686c70c2016-05-26 17:30:50 +00007470StmtResult TreeTransform<Derived>::TransformOMPTargetUpdateDirective(
7471 OMPTargetUpdateDirective *D) {
7472 DeclarationNameInfo DirName;
7473 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_update, DirName,
7474 nullptr, D->getLocStart());
7475 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7476 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7477 return Res;
7478}
7479
7480template <typename Derived>
Alexey Bataev13314bf2014-10-09 04:18:56 +00007481StmtResult
7482TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
7483 DeclarationNameInfo DirName;
7484 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
7485 D->getLocStart());
7486 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7487 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7488 return Res;
7489}
7490
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007491template <typename Derived>
7492StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
7493 OMPCancellationPointDirective *D) {
7494 DeclarationNameInfo DirName;
7495 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
7496 nullptr, D->getLocStart());
7497 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7498 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7499 return Res;
7500}
7501
Alexey Bataev80909872015-07-02 11:25:17 +00007502template <typename Derived>
7503StmtResult
7504TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
7505 DeclarationNameInfo DirName;
7506 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
7507 D->getLocStart());
7508 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7509 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7510 return Res;
7511}
7512
Alexey Bataev49f6e782015-12-01 04:18:41 +00007513template <typename Derived>
7514StmtResult
7515TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
7516 DeclarationNameInfo DirName;
7517 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr,
7518 D->getLocStart());
7519 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7520 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7521 return Res;
7522}
7523
Alexey Bataev0a6ed842015-12-03 09:40:15 +00007524template <typename Derived>
7525StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective(
7526 OMPTaskLoopSimdDirective *D) {
7527 DeclarationNameInfo DirName;
7528 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop_simd, DirName,
7529 nullptr, D->getLocStart());
7530 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7531 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7532 return Res;
7533}
7534
Carlo Bertolli6200a3d2015-12-14 14:51:25 +00007535template <typename Derived>
7536StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective(
7537 OMPDistributeDirective *D) {
7538 DeclarationNameInfo DirName;
7539 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr,
7540 D->getLocStart());
7541 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7542 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7543 return Res;
7544}
7545
Carlo Bertolli9925f152016-06-27 14:55:37 +00007546template <typename Derived>
7547StmtResult TreeTransform<Derived>::TransformOMPDistributeParallelForDirective(
7548 OMPDistributeParallelForDirective *D) {
7549 DeclarationNameInfo DirName;
7550 getDerived().getSema().StartOpenMPDSABlock(
7551 OMPD_distribute_parallel_for, DirName, nullptr, D->getLocStart());
7552 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7553 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7554 return Res;
7555}
7556
Kelvin Li4a39add2016-07-05 05:00:15 +00007557template <typename Derived>
7558StmtResult
7559TreeTransform<Derived>::TransformOMPDistributeParallelForSimdDirective(
7560 OMPDistributeParallelForSimdDirective *D) {
7561 DeclarationNameInfo DirName;
7562 getDerived().getSema().StartOpenMPDSABlock(
7563 OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getLocStart());
7564 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7565 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7566 return Res;
7567}
7568
Alexander Musman64d33f12014-06-04 07:53:32 +00007569//===----------------------------------------------------------------------===//
7570// OpenMP clause transformation
7571//===----------------------------------------------------------------------===//
7572template <typename Derived>
7573OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00007574 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7575 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007576 return nullptr;
Alexey Bataev6b8046a2015-09-03 07:23:48 +00007577 return getDerived().RebuildOMPIfClause(
7578 C->getNameModifier(), Cond.get(), C->getLocStart(), C->getLParenLoc(),
7579 C->getNameModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007580}
7581
Alexander Musman64d33f12014-06-04 07:53:32 +00007582template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00007583OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
7584 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7585 if (Cond.isInvalid())
7586 return nullptr;
7587 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
7588 C->getLParenLoc(), C->getLocEnd());
7589}
7590
7591template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007592OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00007593TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
7594 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
7595 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007596 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00007597 return getDerived().RebuildOMPNumThreadsClause(
7598 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00007599}
7600
Alexey Bataev62c87d22014-03-21 04:51:18 +00007601template <typename Derived>
7602OMPClause *
7603TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
7604 ExprResult E = getDerived().TransformExpr(C->getSafelen());
7605 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007606 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00007607 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007608 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00007609}
7610
Alexander Musman8bd31e62014-05-27 15:12:19 +00007611template <typename Derived>
7612OMPClause *
Alexey Bataev66b15b52015-08-21 11:14:16 +00007613TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
7614 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
7615 if (E.isInvalid())
7616 return nullptr;
7617 return getDerived().RebuildOMPSimdlenClause(
7618 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7619}
7620
7621template <typename Derived>
7622OMPClause *
Alexander Musman8bd31e62014-05-27 15:12:19 +00007623TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
7624 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
7625 if (E.isInvalid())
Hans Wennborg59dbe862015-09-29 20:56:43 +00007626 return nullptr;
Alexander Musman8bd31e62014-05-27 15:12:19 +00007627 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007628 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00007629}
7630
Alexander Musman64d33f12014-06-04 07:53:32 +00007631template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00007632OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007633TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007634 return getDerived().RebuildOMPDefaultClause(
7635 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
7636 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007637}
7638
Alexander Musman64d33f12014-06-04 07:53:32 +00007639template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007640OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007641TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007642 return getDerived().RebuildOMPProcBindClause(
7643 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
7644 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007645}
7646
Alexander Musman64d33f12014-06-04 07:53:32 +00007647template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007648OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00007649TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
7650 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
7651 if (E.isInvalid())
7652 return nullptr;
7653 return getDerived().RebuildOMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00007654 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
Alexey Bataev56dafe82014-06-20 07:16:17 +00007655 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
Alexey Bataev6402bca2015-12-28 07:25:51 +00007656 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
Alexey Bataev56dafe82014-06-20 07:16:17 +00007657 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
7658}
7659
7660template <typename Derived>
7661OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007662TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
Alexey Bataev10e775f2015-07-30 11:36:16 +00007663 ExprResult E;
7664 if (auto *Num = C->getNumForLoops()) {
7665 E = getDerived().TransformExpr(Num);
7666 if (E.isInvalid())
7667 return nullptr;
7668 }
7669 return getDerived().RebuildOMPOrderedClause(C->getLocStart(), C->getLocEnd(),
7670 C->getLParenLoc(), E.get());
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007671}
7672
7673template <typename Derived>
7674OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00007675TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
7676 // No need to rebuild this clause, no template-dependent parameters.
7677 return C;
7678}
7679
7680template <typename Derived>
7681OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00007682TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
7683 // No need to rebuild this clause, no template-dependent parameters.
7684 return C;
7685}
7686
7687template <typename Derived>
7688OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007689TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
7690 // No need to rebuild this clause, no template-dependent parameters.
7691 return C;
7692}
7693
7694template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00007695OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
7696 // No need to rebuild this clause, no template-dependent parameters.
7697 return C;
7698}
7699
7700template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00007701OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
7702 // No need to rebuild this clause, no template-dependent parameters.
7703 return C;
7704}
7705
7706template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007707OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00007708TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
7709 // No need to rebuild this clause, no template-dependent parameters.
7710 return C;
7711}
7712
7713template <typename Derived>
7714OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00007715TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
7716 // No need to rebuild this clause, no template-dependent parameters.
7717 return C;
7718}
7719
7720template <typename Derived>
7721OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00007722TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
7723 // No need to rebuild this clause, no template-dependent parameters.
7724 return C;
7725}
7726
7727template <typename Derived>
7728OMPClause *
Alexey Bataev346265e2015-09-25 10:37:12 +00007729TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
7730 // No need to rebuild this clause, no template-dependent parameters.
7731 return C;
7732}
7733
7734template <typename Derived>
Alexey Bataevd14d1e62015-09-28 06:39:35 +00007735OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
7736 // No need to rebuild this clause, no template-dependent parameters.
7737 return C;
7738}
7739
7740template <typename Derived>
Alexey Bataev346265e2015-09-25 10:37:12 +00007741OMPClause *
Alexey Bataevb825de12015-12-07 10:51:44 +00007742TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
7743 // No need to rebuild this clause, no template-dependent parameters.
7744 return C;
7745}
7746
7747template <typename Derived>
7748OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007749TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007750 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007751 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007752 for (auto *VE : C->varlists()) {
7753 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007754 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007755 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007756 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007757 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007758 return getDerived().RebuildOMPPrivateClause(
7759 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007760}
7761
Alexander Musman64d33f12014-06-04 07:53:32 +00007762template <typename Derived>
7763OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
7764 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007765 llvm::SmallVector<Expr *, 16> Vars;
7766 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007767 for (auto *VE : C->varlists()) {
7768 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007769 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007770 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007771 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007772 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007773 return getDerived().RebuildOMPFirstprivateClause(
7774 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007775}
7776
Alexander Musman64d33f12014-06-04 07:53:32 +00007777template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007778OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00007779TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
7780 llvm::SmallVector<Expr *, 16> Vars;
7781 Vars.reserve(C->varlist_size());
7782 for (auto *VE : C->varlists()) {
7783 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7784 if (EVar.isInvalid())
7785 return nullptr;
7786 Vars.push_back(EVar.get());
7787 }
7788 return getDerived().RebuildOMPLastprivateClause(
7789 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7790}
7791
7792template <typename Derived>
7793OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00007794TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
7795 llvm::SmallVector<Expr *, 16> Vars;
7796 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007797 for (auto *VE : C->varlists()) {
7798 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00007799 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007800 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007801 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007802 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007803 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
7804 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007805}
7806
Alexander Musman64d33f12014-06-04 07:53:32 +00007807template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007808OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00007809TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
7810 llvm::SmallVector<Expr *, 16> Vars;
7811 Vars.reserve(C->varlist_size());
7812 for (auto *VE : C->varlists()) {
7813 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7814 if (EVar.isInvalid())
7815 return nullptr;
7816 Vars.push_back(EVar.get());
7817 }
7818 CXXScopeSpec ReductionIdScopeSpec;
7819 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
7820
7821 DeclarationNameInfo NameInfo = C->getNameInfo();
7822 if (NameInfo.getName()) {
7823 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7824 if (!NameInfo.getName())
7825 return nullptr;
7826 }
Alexey Bataeva839ddd2016-03-17 10:19:46 +00007827 // Build a list of all UDR decls with the same names ranged by the Scopes.
7828 // The Scope boundary is a duplication of the previous decl.
7829 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
7830 for (auto *E : C->reduction_ops()) {
7831 // Transform all the decls.
7832 if (E) {
7833 auto *ULE = cast<UnresolvedLookupExpr>(E);
7834 UnresolvedSet<8> Decls;
7835 for (auto *D : ULE->decls()) {
7836 NamedDecl *InstD =
7837 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
7838 Decls.addDecl(InstD, InstD->getAccess());
7839 }
7840 UnresolvedReductions.push_back(
7841 UnresolvedLookupExpr::Create(
7842 SemaRef.Context, /*NamingClass=*/nullptr,
7843 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context),
7844 NameInfo, /*ADL=*/true, ULE->isOverloaded(),
7845 Decls.begin(), Decls.end()));
7846 } else
7847 UnresolvedReductions.push_back(nullptr);
7848 }
Alexey Bataevc5e02582014-06-16 07:08:35 +00007849 return getDerived().RebuildOMPReductionClause(
7850 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
Alexey Bataeva839ddd2016-03-17 10:19:46 +00007851 C->getLocEnd(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00007852}
7853
7854template <typename Derived>
7855OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00007856TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
7857 llvm::SmallVector<Expr *, 16> Vars;
7858 Vars.reserve(C->varlist_size());
7859 for (auto *VE : C->varlists()) {
7860 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7861 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007862 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007863 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00007864 }
7865 ExprResult Step = getDerived().TransformExpr(C->getStep());
7866 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007867 return nullptr;
Alexey Bataev182227b2015-08-20 10:54:39 +00007868 return getDerived().RebuildOMPLinearClause(
7869 Vars, Step.get(), C->getLocStart(), C->getLParenLoc(), C->getModifier(),
7870 C->getModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00007871}
7872
Alexander Musman64d33f12014-06-04 07:53:32 +00007873template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00007874OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007875TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
7876 llvm::SmallVector<Expr *, 16> Vars;
7877 Vars.reserve(C->varlist_size());
7878 for (auto *VE : C->varlists()) {
7879 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7880 if (EVar.isInvalid())
7881 return nullptr;
7882 Vars.push_back(EVar.get());
7883 }
7884 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
7885 if (Alignment.isInvalid())
7886 return nullptr;
7887 return getDerived().RebuildOMPAlignedClause(
7888 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
7889 C->getColonLoc(), C->getLocEnd());
7890}
7891
Alexander Musman64d33f12014-06-04 07:53:32 +00007892template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007893OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007894TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
7895 llvm::SmallVector<Expr *, 16> Vars;
7896 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007897 for (auto *VE : C->varlists()) {
7898 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007899 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007900 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007901 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007902 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007903 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
7904 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007905}
7906
Alexey Bataevbae9a792014-06-27 10:37:06 +00007907template <typename Derived>
7908OMPClause *
7909TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
7910 llvm::SmallVector<Expr *, 16> Vars;
7911 Vars.reserve(C->varlist_size());
7912 for (auto *VE : C->varlists()) {
7913 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7914 if (EVar.isInvalid())
7915 return nullptr;
7916 Vars.push_back(EVar.get());
7917 }
7918 return getDerived().RebuildOMPCopyprivateClause(
7919 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7920}
7921
Alexey Bataev6125da92014-07-21 11:26:11 +00007922template <typename Derived>
7923OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
7924 llvm::SmallVector<Expr *, 16> Vars;
7925 Vars.reserve(C->varlist_size());
7926 for (auto *VE : C->varlists()) {
7927 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7928 if (EVar.isInvalid())
7929 return nullptr;
7930 Vars.push_back(EVar.get());
7931 }
7932 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
7933 C->getLParenLoc(), C->getLocEnd());
7934}
7935
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00007936template <typename Derived>
7937OMPClause *
7938TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
7939 llvm::SmallVector<Expr *, 16> Vars;
7940 Vars.reserve(C->varlist_size());
7941 for (auto *VE : C->varlists()) {
7942 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7943 if (EVar.isInvalid())
7944 return nullptr;
7945 Vars.push_back(EVar.get());
7946 }
7947 return getDerived().RebuildOMPDependClause(
7948 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
7949 C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7950}
7951
Michael Wonge710d542015-08-07 16:16:36 +00007952template <typename Derived>
7953OMPClause *
7954TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
7955 ExprResult E = getDerived().TransformExpr(C->getDevice());
7956 if (E.isInvalid())
7957 return nullptr;
7958 return getDerived().RebuildOMPDeviceClause(
7959 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7960}
7961
Kelvin Li0bff7af2015-11-23 05:32:03 +00007962template <typename Derived>
7963OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
7964 llvm::SmallVector<Expr *, 16> Vars;
7965 Vars.reserve(C->varlist_size());
7966 for (auto *VE : C->varlists()) {
7967 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7968 if (EVar.isInvalid())
7969 return nullptr;
7970 Vars.push_back(EVar.get());
7971 }
7972 return getDerived().RebuildOMPMapClause(
Samuel Antao23abd722016-01-19 20:40:49 +00007973 C->getMapTypeModifier(), C->getMapType(), C->isImplicitMapType(),
7974 C->getMapLoc(), C->getColonLoc(), Vars, C->getLocStart(),
7975 C->getLParenLoc(), C->getLocEnd());
Kelvin Li0bff7af2015-11-23 05:32:03 +00007976}
7977
Kelvin Li099bb8c2015-11-24 20:50:12 +00007978template <typename Derived>
7979OMPClause *
7980TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
7981 ExprResult E = getDerived().TransformExpr(C->getNumTeams());
7982 if (E.isInvalid())
7983 return nullptr;
7984 return getDerived().RebuildOMPNumTeamsClause(
7985 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7986}
7987
Kelvin Lia15fb1a2015-11-27 18:47:36 +00007988template <typename Derived>
7989OMPClause *
7990TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
7991 ExprResult E = getDerived().TransformExpr(C->getThreadLimit());
7992 if (E.isInvalid())
7993 return nullptr;
7994 return getDerived().RebuildOMPThreadLimitClause(
7995 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7996}
7997
Alexey Bataeva0569352015-12-01 10:17:31 +00007998template <typename Derived>
7999OMPClause *
8000TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
8001 ExprResult E = getDerived().TransformExpr(C->getPriority());
8002 if (E.isInvalid())
8003 return nullptr;
8004 return getDerived().RebuildOMPPriorityClause(
8005 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8006}
8007
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00008008template <typename Derived>
8009OMPClause *
8010TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
8011 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
8012 if (E.isInvalid())
8013 return nullptr;
8014 return getDerived().RebuildOMPGrainsizeClause(
8015 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8016}
8017
Alexey Bataev382967a2015-12-08 12:06:20 +00008018template <typename Derived>
8019OMPClause *
8020TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
8021 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
8022 if (E.isInvalid())
8023 return nullptr;
8024 return getDerived().RebuildOMPNumTasksClause(
8025 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8026}
8027
Alexey Bataev28c75412015-12-15 08:19:24 +00008028template <typename Derived>
8029OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) {
8030 ExprResult E = getDerived().TransformExpr(C->getHint());
8031 if (E.isInvalid())
8032 return nullptr;
8033 return getDerived().RebuildOMPHintClause(E.get(), C->getLocStart(),
8034 C->getLParenLoc(), C->getLocEnd());
8035}
8036
Carlo Bertollib4adf552016-01-15 18:50:31 +00008037template <typename Derived>
8038OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause(
8039 OMPDistScheduleClause *C) {
8040 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
8041 if (E.isInvalid())
8042 return nullptr;
8043 return getDerived().RebuildOMPDistScheduleClause(
8044 C->getDistScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
8045 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
8046}
8047
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +00008048template <typename Derived>
8049OMPClause *
8050TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) {
8051 return C;
8052}
8053
Samuel Antao661c0902016-05-26 17:39:58 +00008054template <typename Derived>
8055OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) {
8056 llvm::SmallVector<Expr *, 16> Vars;
8057 Vars.reserve(C->varlist_size());
8058 for (auto *VE : C->varlists()) {
8059 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8060 if (EVar.isInvalid())
8061 return 0;
8062 Vars.push_back(EVar.get());
8063 }
8064 return getDerived().RebuildOMPToClause(Vars, C->getLocStart(),
8065 C->getLParenLoc(), C->getLocEnd());
8066}
8067
Samuel Antaoec172c62016-05-26 17:49:04 +00008068template <typename Derived>
8069OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) {
8070 llvm::SmallVector<Expr *, 16> Vars;
8071 Vars.reserve(C->varlist_size());
8072 for (auto *VE : C->varlists()) {
8073 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8074 if (EVar.isInvalid())
8075 return 0;
8076 Vars.push_back(EVar.get());
8077 }
8078 return getDerived().RebuildOMPFromClause(Vars, C->getLocStart(),
8079 C->getLParenLoc(), C->getLocEnd());
8080}
8081
Douglas Gregorebe10102009-08-20 07:17:43 +00008082//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00008083// Expression transformation
8084//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00008085template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008086ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008087TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00008088 if (!E->isTypeDependent())
8089 return E;
8090
8091 return getDerived().RebuildPredefinedExpr(E->getLocation(),
8092 E->getIdentType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008093}
Mike Stump11289f42009-09-09 15:08:12 +00008094
8095template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008096ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008097TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00008098 NestedNameSpecifierLoc QualifierLoc;
8099 if (E->getQualifierLoc()) {
8100 QualifierLoc
8101 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8102 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008103 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008104 }
John McCallce546572009-12-08 09:08:17 +00008105
8106 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008107 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8108 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008109 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00008110 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008111
John McCall815039a2010-08-17 21:27:17 +00008112 DeclarationNameInfo NameInfo = E->getNameInfo();
8113 if (NameInfo.getName()) {
8114 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8115 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008116 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00008117 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008118
8119 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00008120 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008121 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008122 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00008123 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00008124
8125 // Mark it referenced in the new context regardless.
8126 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00008127 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00008128
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008129 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008130 }
John McCallce546572009-12-08 09:08:17 +00008131
Craig Topperc3ec1492014-05-26 06:22:03 +00008132 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00008133 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00008134 TemplateArgs = &TransArgs;
8135 TransArgs.setLAngleLoc(E->getLAngleLoc());
8136 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008137 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8138 E->getNumTemplateArgs(),
8139 TransArgs))
8140 return ExprError();
John McCallce546572009-12-08 09:08:17 +00008141 }
8142
Chad Rosier1dcde962012-08-08 18:46:20 +00008143 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00008144 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00008145}
Mike Stump11289f42009-09-09 15:08:12 +00008146
Douglas Gregora16548e2009-08-11 05:31:07 +00008147template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008148ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008149TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008150 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008151}
Mike Stump11289f42009-09-09 15:08:12 +00008152
Douglas Gregora16548e2009-08-11 05:31:07 +00008153template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008154ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008155TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008156 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008157}
Mike Stump11289f42009-09-09 15:08:12 +00008158
Douglas Gregora16548e2009-08-11 05:31:07 +00008159template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008160ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008161TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008162 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008163}
Mike Stump11289f42009-09-09 15:08:12 +00008164
Douglas Gregora16548e2009-08-11 05:31:07 +00008165template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008166ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008167TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008168 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008169}
Mike Stump11289f42009-09-09 15:08:12 +00008170
Douglas Gregora16548e2009-08-11 05:31:07 +00008171template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008172ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008173TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008174 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008175}
8176
8177template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008178ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00008179TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00008180 if (FunctionDecl *FD = E->getDirectCallee())
8181 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00008182 return SemaRef.MaybeBindToTemporary(E);
8183}
8184
8185template<typename Derived>
8186ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00008187TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
8188 ExprResult ControllingExpr =
8189 getDerived().TransformExpr(E->getControllingExpr());
8190 if (ControllingExpr.isInvalid())
8191 return ExprError();
8192
Chris Lattner01cf8db2011-07-20 06:58:45 +00008193 SmallVector<Expr *, 4> AssocExprs;
8194 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00008195 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
8196 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
8197 if (TS) {
8198 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
8199 if (!AssocType)
8200 return ExprError();
8201 AssocTypes.push_back(AssocType);
8202 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00008203 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00008204 }
8205
8206 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
8207 if (AssocExpr.isInvalid())
8208 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008209 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00008210 }
8211
8212 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
8213 E->getDefaultLoc(),
8214 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008215 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00008216 AssocTypes,
8217 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00008218}
8219
8220template<typename Derived>
8221ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008222TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008223 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008224 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008225 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008226
Douglas Gregora16548e2009-08-11 05:31:07 +00008227 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008228 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008229
John McCallb268a282010-08-23 23:25:46 +00008230 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008231 E->getRParen());
8232}
8233
Richard Smithdb2630f2012-10-21 03:28:35 +00008234/// \brief The operand of a unary address-of operator has special rules: it's
8235/// allowed to refer to a non-static member of a class even if there's no 'this'
8236/// object available.
8237template<typename Derived>
8238ExprResult
8239TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
8240 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00008241 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00008242 else
8243 return getDerived().TransformExpr(E);
8244}
8245
Mike Stump11289f42009-09-09 15:08:12 +00008246template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008247ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008248TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00008249 ExprResult SubExpr;
8250 if (E->getOpcode() == UO_AddrOf)
8251 SubExpr = TransformAddressOfOperand(E->getSubExpr());
8252 else
8253 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008254 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008255 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008256
Douglas Gregora16548e2009-08-11 05:31:07 +00008257 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008258 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008259
Douglas Gregora16548e2009-08-11 05:31:07 +00008260 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
8261 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008262 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008263}
Mike Stump11289f42009-09-09 15:08:12 +00008264
Douglas Gregora16548e2009-08-11 05:31:07 +00008265template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008266ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00008267TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
8268 // Transform the type.
8269 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
8270 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00008271 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008272
Douglas Gregor882211c2010-04-28 22:16:22 +00008273 // Transform all of the components into components similar to what the
8274 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00008275 // FIXME: It would be slightly more efficient in the non-dependent case to
8276 // just map FieldDecls, rather than requiring the rebuilder to look for
8277 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00008278 // template code that we don't care.
8279 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00008280 typedef Sema::OffsetOfComponent Component;
Chris Lattner01cf8db2011-07-20 06:58:45 +00008281 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00008282 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
James Y Knight7281c352015-12-29 22:31:18 +00008283 const OffsetOfNode &ON = E->getComponent(I);
Douglas Gregor882211c2010-04-28 22:16:22 +00008284 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00008285 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00008286 Comp.LocStart = ON.getSourceRange().getBegin();
8287 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00008288 switch (ON.getKind()) {
James Y Knight7281c352015-12-29 22:31:18 +00008289 case OffsetOfNode::Array: {
Douglas Gregor882211c2010-04-28 22:16:22 +00008290 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00008291 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00008292 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008293 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008294
Douglas Gregor882211c2010-04-28 22:16:22 +00008295 ExprChanged = ExprChanged || Index.get() != FromIndex;
8296 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00008297 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00008298 break;
8299 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008300
James Y Knight7281c352015-12-29 22:31:18 +00008301 case OffsetOfNode::Field:
8302 case OffsetOfNode::Identifier:
Douglas Gregor882211c2010-04-28 22:16:22 +00008303 Comp.isBrackets = false;
8304 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00008305 if (!Comp.U.IdentInfo)
8306 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008307
Douglas Gregor882211c2010-04-28 22:16:22 +00008308 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00008309
James Y Knight7281c352015-12-29 22:31:18 +00008310 case OffsetOfNode::Base:
Douglas Gregord1702062010-04-29 00:18:15 +00008311 // Will be recomputed during the rebuild.
8312 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00008313 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008314
Douglas Gregor882211c2010-04-28 22:16:22 +00008315 Components.push_back(Comp);
8316 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008317
Douglas Gregor882211c2010-04-28 22:16:22 +00008318 // If nothing changed, retain the existing expression.
8319 if (!getDerived().AlwaysRebuild() &&
8320 Type == E->getTypeSourceInfo() &&
8321 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008322 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00008323
Douglas Gregor882211c2010-04-28 22:16:22 +00008324 // Build a new offsetof expression.
8325 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
Craig Topperb5518242015-10-22 04:59:59 +00008326 Components, E->getRParenLoc());
Douglas Gregor882211c2010-04-28 22:16:22 +00008327}
8328
8329template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008330ExprResult
John McCall8d69a212010-11-15 23:31:06 +00008331TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
Hubert Tong2cded442015-09-01 22:50:31 +00008332 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
John McCall8d69a212010-11-15 23:31:06 +00008333 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008334 return E;
John McCall8d69a212010-11-15 23:31:06 +00008335}
8336
8337template<typename Derived>
8338ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00008339TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
8340 return E;
8341}
8342
8343template<typename Derived>
8344ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00008345TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00008346 // Rebuild the syntactic form. The original syntactic form has
8347 // opaque-value expressions in it, so strip those away and rebuild
8348 // the result. This is a really awful way of doing this, but the
8349 // better solution (rebuilding the semantic expressions and
8350 // rebinding OVEs as necessary) doesn't work; we'd need
8351 // TreeTransform to not strip away implicit conversions.
8352 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
8353 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00008354 if (result.isInvalid()) return ExprError();
8355
8356 // If that gives us a pseudo-object result back, the pseudo-object
8357 // expression must have been an lvalue-to-rvalue conversion which we
8358 // should reapply.
8359 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008360 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00008361
8362 return result;
8363}
8364
8365template<typename Derived>
8366ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00008367TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
8368 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008369 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00008370 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00008371
John McCallbcd03502009-12-07 02:54:59 +00008372 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00008373 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008374 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008375
John McCall4c98fd82009-11-04 07:28:41 +00008376 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008377 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008378
Peter Collingbournee190dee2011-03-11 19:24:49 +00008379 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
8380 E->getKind(),
8381 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008382 }
Mike Stump11289f42009-09-09 15:08:12 +00008383
Eli Friedmane4f22df2012-02-29 04:03:55 +00008384 // C++0x [expr.sizeof]p1:
8385 // The operand is either an expression, which is an unevaluated operand
8386 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00008387 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8388 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008389
Reid Kleckner32506ed2014-06-12 23:03:48 +00008390 // Try to recover if we have something like sizeof(T::X) where X is a type.
8391 // Notably, there must be *exactly* one set of parens if X is a type.
8392 TypeSourceInfo *RecoveryTSI = nullptr;
8393 ExprResult SubExpr;
8394 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
8395 if (auto *DRE =
8396 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
8397 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
8398 PE, DRE, false, &RecoveryTSI);
8399 else
8400 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
8401
8402 if (RecoveryTSI) {
8403 return getDerived().RebuildUnaryExprOrTypeTrait(
8404 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
8405 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00008406 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008407
Eli Friedmane4f22df2012-02-29 04:03:55 +00008408 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008409 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008410
Peter Collingbournee190dee2011-03-11 19:24:49 +00008411 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
8412 E->getOperatorLoc(),
8413 E->getKind(),
8414 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008415}
Mike Stump11289f42009-09-09 15:08:12 +00008416
Douglas Gregora16548e2009-08-11 05:31:07 +00008417template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008418ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008419TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008420 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008421 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008422 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008423
John McCalldadc5752010-08-24 06:29:42 +00008424 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008425 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008426 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008427
8428
Douglas Gregora16548e2009-08-11 05:31:07 +00008429 if (!getDerived().AlwaysRebuild() &&
8430 LHS.get() == E->getLHS() &&
8431 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008432 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008433
John McCallb268a282010-08-23 23:25:46 +00008434 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008435 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008436 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008437 E->getRBracketLoc());
8438}
Mike Stump11289f42009-09-09 15:08:12 +00008439
Alexey Bataev1a3320e2015-08-25 14:24:04 +00008440template <typename Derived>
8441ExprResult
8442TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
8443 ExprResult Base = getDerived().TransformExpr(E->getBase());
8444 if (Base.isInvalid())
8445 return ExprError();
8446
8447 ExprResult LowerBound;
8448 if (E->getLowerBound()) {
8449 LowerBound = getDerived().TransformExpr(E->getLowerBound());
8450 if (LowerBound.isInvalid())
8451 return ExprError();
8452 }
8453
8454 ExprResult Length;
8455 if (E->getLength()) {
8456 Length = getDerived().TransformExpr(E->getLength());
8457 if (Length.isInvalid())
8458 return ExprError();
8459 }
8460
8461 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
8462 LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
8463 return E;
8464
8465 return getDerived().RebuildOMPArraySectionExpr(
8466 Base.get(), E->getBase()->getLocEnd(), LowerBound.get(), E->getColonLoc(),
8467 Length.get(), E->getRBracketLoc());
8468}
8469
Mike Stump11289f42009-09-09 15:08:12 +00008470template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008471ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008472TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008473 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00008474 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00008475 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008476 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008477
8478 // Transform arguments.
8479 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008480 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008481 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008482 &ArgChanged))
8483 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008484
Douglas Gregora16548e2009-08-11 05:31:07 +00008485 if (!getDerived().AlwaysRebuild() &&
8486 Callee.get() == E->getCallee() &&
8487 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00008488 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00008489
Douglas Gregora16548e2009-08-11 05:31:07 +00008490 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00008491 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00008492 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00008493 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008494 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008495 E->getRParenLoc());
8496}
Mike Stump11289f42009-09-09 15:08:12 +00008497
8498template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008499ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008500TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008501 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008502 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008503 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008504
Douglas Gregorea972d32011-02-28 21:54:11 +00008505 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00008506 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00008507 QualifierLoc
8508 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00008509
Douglas Gregorea972d32011-02-28 21:54:11 +00008510 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008511 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00008512 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00008513 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008514
Eli Friedman2cfcef62009-12-04 06:40:45 +00008515 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008516 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
8517 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008518 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00008519 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008520
John McCall16df1e52010-03-30 21:47:33 +00008521 NamedDecl *FoundDecl = E->getFoundDecl();
8522 if (FoundDecl == E->getMemberDecl()) {
8523 FoundDecl = Member;
8524 } else {
8525 FoundDecl = cast_or_null<NamedDecl>(
8526 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
8527 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00008528 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00008529 }
8530
Douglas Gregora16548e2009-08-11 05:31:07 +00008531 if (!getDerived().AlwaysRebuild() &&
8532 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00008533 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008534 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00008535 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00008536 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008537
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008538 // Mark it referenced in the new context regardless.
8539 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00008540 SemaRef.MarkMemberReferenced(E);
8541
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008542 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008543 }
Douglas Gregora16548e2009-08-11 05:31:07 +00008544
John McCall6b51f282009-11-23 01:53:49 +00008545 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00008546 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00008547 TransArgs.setLAngleLoc(E->getLAngleLoc());
8548 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008549 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8550 E->getNumTemplateArgs(),
8551 TransArgs))
8552 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008553 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008554
Douglas Gregora16548e2009-08-11 05:31:07 +00008555 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00008556 SourceLocation FakeOperatorLoc =
8557 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00008558
John McCall38836f02010-01-15 08:34:02 +00008559 // FIXME: to do this check properly, we will need to preserve the
8560 // first-qualifier-in-scope here, just in case we had a dependent
8561 // base (and therefore couldn't do the check) and a
8562 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00008563 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00008564
John McCallb268a282010-08-23 23:25:46 +00008565 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008566 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00008567 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008568 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008569 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008570 Member,
John McCall16df1e52010-03-30 21:47:33 +00008571 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00008572 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00008573 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00008574 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00008575}
Mike Stump11289f42009-09-09 15:08:12 +00008576
Douglas Gregora16548e2009-08-11 05:31:07 +00008577template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008578ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008579TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008580 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008581 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008582 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008583
John McCalldadc5752010-08-24 06:29:42 +00008584 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008585 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008586 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008587
Douglas Gregora16548e2009-08-11 05:31:07 +00008588 if (!getDerived().AlwaysRebuild() &&
8589 LHS.get() == E->getLHS() &&
8590 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008591 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008592
Lang Hames5de91cc2012-10-02 04:45:10 +00008593 Sema::FPContractStateRAII FPContractState(getSema());
8594 getSema().FPFeatures.fp_contract = E->isFPContractable();
8595
Douglas Gregora16548e2009-08-11 05:31:07 +00008596 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008597 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008598}
8599
Mike Stump11289f42009-09-09 15:08:12 +00008600template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008601ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008602TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00008603 CompoundAssignOperator *E) {
8604 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008605}
Mike Stump11289f42009-09-09 15:08:12 +00008606
Douglas Gregora16548e2009-08-11 05:31:07 +00008607template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00008608ExprResult TreeTransform<Derived>::
8609TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
8610 // Just rebuild the common and RHS expressions and see whether we
8611 // get any changes.
8612
8613 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
8614 if (commonExpr.isInvalid())
8615 return ExprError();
8616
8617 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
8618 if (rhs.isInvalid())
8619 return ExprError();
8620
8621 if (!getDerived().AlwaysRebuild() &&
8622 commonExpr.get() == e->getCommon() &&
8623 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008624 return e;
John McCallc07a0c72011-02-17 10:25:35 +00008625
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008626 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00008627 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008628 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00008629 e->getColonLoc(),
8630 rhs.get());
8631}
8632
8633template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008634ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008635TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008636 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008637 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008638 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008639
John McCalldadc5752010-08-24 06:29:42 +00008640 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008641 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008642 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008643
John McCalldadc5752010-08-24 06:29:42 +00008644 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008645 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008646 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008647
Douglas Gregora16548e2009-08-11 05:31:07 +00008648 if (!getDerived().AlwaysRebuild() &&
8649 Cond.get() == E->getCond() &&
8650 LHS.get() == E->getLHS() &&
8651 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008652 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008653
John McCallb268a282010-08-23 23:25:46 +00008654 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008655 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00008656 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008657 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008658 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008659}
Mike Stump11289f42009-09-09 15:08:12 +00008660
8661template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008662ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008663TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00008664 // Implicit casts are eliminated during transformation, since they
8665 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00008666 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008667}
Mike Stump11289f42009-09-09 15:08:12 +00008668
Douglas Gregora16548e2009-08-11 05:31:07 +00008669template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008670ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008671TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008672 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8673 if (!Type)
8674 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008675
John McCalldadc5752010-08-24 06:29:42 +00008676 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008677 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008678 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008679 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008680
Douglas Gregora16548e2009-08-11 05:31:07 +00008681 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008682 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008683 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008684 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008685
John McCall97513962010-01-15 18:39:57 +00008686 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008687 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00008688 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008689 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008690}
Mike Stump11289f42009-09-09 15:08:12 +00008691
Douglas Gregora16548e2009-08-11 05:31:07 +00008692template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008693ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008694TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00008695 TypeSourceInfo *OldT = E->getTypeSourceInfo();
8696 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
8697 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008698 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008699
John McCalldadc5752010-08-24 06:29:42 +00008700 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00008701 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008702 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008703
Douglas Gregora16548e2009-08-11 05:31:07 +00008704 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00008705 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008706 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008707 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008708
John McCall5d7aa7f2010-01-19 22:33:45 +00008709 // Note: the expression type doesn't necessarily match the
8710 // type-as-written, but that's okay, because it should always be
8711 // derivable from the initializer.
8712
John McCalle15bbff2010-01-18 19:35:47 +00008713 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00008714 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00008715 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008716}
Mike Stump11289f42009-09-09 15:08:12 +00008717
Douglas Gregora16548e2009-08-11 05:31:07 +00008718template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008719ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008720TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008721 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008722 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008723 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008724
Douglas Gregora16548e2009-08-11 05:31:07 +00008725 if (!getDerived().AlwaysRebuild() &&
8726 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008727 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008728
Douglas Gregora16548e2009-08-11 05:31:07 +00008729 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00008730 SourceLocation FakeOperatorLoc =
8731 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00008732 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008733 E->getAccessorLoc(),
8734 E->getAccessor());
8735}
Mike Stump11289f42009-09-09 15:08:12 +00008736
Douglas Gregora16548e2009-08-11 05:31:07 +00008737template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008738ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008739TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Richard Smith520449d2015-02-05 06:15:50 +00008740 if (InitListExpr *Syntactic = E->getSyntacticForm())
8741 E = Syntactic;
8742
Douglas Gregora16548e2009-08-11 05:31:07 +00008743 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00008744
Benjamin Kramerf0623432012-08-23 22:51:59 +00008745 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00008746 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00008747 Inits, &InitChanged))
8748 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008749
Richard Smith520449d2015-02-05 06:15:50 +00008750 if (!getDerived().AlwaysRebuild() && !InitChanged) {
8751 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
8752 // in some cases. We can't reuse it in general, because the syntactic and
8753 // semantic forms are linked, and we can't know that semantic form will
8754 // match even if the syntactic form does.
8755 }
Mike Stump11289f42009-09-09 15:08:12 +00008756
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008757 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00008758 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008759}
Mike Stump11289f42009-09-09 15:08:12 +00008760
Douglas Gregora16548e2009-08-11 05:31:07 +00008761template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008762ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008763TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008764 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00008765
Douglas Gregorebe10102009-08-20 07:17:43 +00008766 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00008767 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008768 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008769 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008770
Douglas Gregorebe10102009-08-20 07:17:43 +00008771 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008772 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00008773 bool ExprChanged = false;
David Majnemerf7e36092016-06-23 00:15:04 +00008774 for (const DesignatedInitExpr::Designator &D : E->designators()) {
8775 if (D.isFieldDesignator()) {
8776 Desig.AddDesignator(Designator::getField(D.getFieldName(),
8777 D.getDotLoc(),
8778 D.getFieldLoc()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008779 continue;
8780 }
Mike Stump11289f42009-09-09 15:08:12 +00008781
David Majnemerf7e36092016-06-23 00:15:04 +00008782 if (D.isArrayDesignator()) {
8783 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008784 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008785 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008786
David Majnemerf7e36092016-06-23 00:15:04 +00008787 Desig.AddDesignator(
8788 Designator::getArray(Index.get(), D.getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008789
David Majnemerf7e36092016-06-23 00:15:04 +00008790 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008791 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008792 continue;
8793 }
Mike Stump11289f42009-09-09 15:08:12 +00008794
David Majnemerf7e36092016-06-23 00:15:04 +00008795 assert(D.isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00008796 ExprResult Start
David Majnemerf7e36092016-06-23 00:15:04 +00008797 = getDerived().TransformExpr(E->getArrayRangeStart(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008798 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008799 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008800
David Majnemerf7e36092016-06-23 00:15:04 +00008801 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008802 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008803 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008804
8805 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008806 End.get(),
David Majnemerf7e36092016-06-23 00:15:04 +00008807 D.getLBracketLoc(),
8808 D.getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008809
David Majnemerf7e36092016-06-23 00:15:04 +00008810 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
8811 End.get() != E->getArrayRangeEnd(D);
Mike Stump11289f42009-09-09 15:08:12 +00008812
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008813 ArrayExprs.push_back(Start.get());
8814 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008815 }
Mike Stump11289f42009-09-09 15:08:12 +00008816
Douglas Gregora16548e2009-08-11 05:31:07 +00008817 if (!getDerived().AlwaysRebuild() &&
8818 Init.get() == E->getInit() &&
8819 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008820 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008821
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008822 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008823 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008824 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008825}
Mike Stump11289f42009-09-09 15:08:12 +00008826
Yunzhong Gaocb779302015-06-10 00:27:52 +00008827// Seems that if TransformInitListExpr() only works on the syntactic form of an
8828// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
8829template<typename Derived>
8830ExprResult
8831TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
8832 DesignatedInitUpdateExpr *E) {
8833 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
8834 "initializer");
8835 return ExprError();
8836}
8837
8838template<typename Derived>
8839ExprResult
8840TreeTransform<Derived>::TransformNoInitExpr(
8841 NoInitExpr *E) {
8842 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
8843 return ExprError();
8844}
8845
Douglas Gregora16548e2009-08-11 05:31:07 +00008846template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008847ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008848TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008849 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00008850 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00008851
Douglas Gregor3da3c062009-10-28 00:29:27 +00008852 // FIXME: Will we ever have proper type location here? Will we actually
8853 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00008854 QualType T = getDerived().TransformType(E->getType());
8855 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008856 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008857
Douglas Gregora16548e2009-08-11 05:31:07 +00008858 if (!getDerived().AlwaysRebuild() &&
8859 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008860 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008861
Douglas Gregora16548e2009-08-11 05:31:07 +00008862 return getDerived().RebuildImplicitValueInitExpr(T);
8863}
Mike Stump11289f42009-09-09 15:08:12 +00008864
Douglas Gregora16548e2009-08-11 05:31:07 +00008865template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008866ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008867TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00008868 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
8869 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008870 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008871
John McCalldadc5752010-08-24 06:29:42 +00008872 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008873 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008874 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008875
Douglas Gregora16548e2009-08-11 05:31:07 +00008876 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00008877 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008878 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008879 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008880
John McCallb268a282010-08-23 23:25:46 +00008881 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00008882 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008883}
8884
8885template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008886ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008887TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008888 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008889 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00008890 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
8891 &ArgumentChanged))
8892 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008893
Douglas Gregora16548e2009-08-11 05:31:07 +00008894 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008895 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00008896 E->getRParenLoc());
8897}
Mike Stump11289f42009-09-09 15:08:12 +00008898
Douglas Gregora16548e2009-08-11 05:31:07 +00008899/// \brief Transform an address-of-label expression.
8900///
8901/// By default, the transformation of an address-of-label expression always
8902/// rebuilds the expression, so that the label identifier can be resolved to
8903/// the corresponding label statement by semantic analysis.
8904template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008905ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008906TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00008907 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
8908 E->getLabel());
8909 if (!LD)
8910 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008911
Douglas Gregora16548e2009-08-11 05:31:07 +00008912 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00008913 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00008914}
Mike Stump11289f42009-09-09 15:08:12 +00008915
8916template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00008917ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008918TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00008919 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00008920 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00008921 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00008922 if (SubStmt.isInvalid()) {
8923 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00008924 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00008925 }
Mike Stump11289f42009-09-09 15:08:12 +00008926
Douglas Gregora16548e2009-08-11 05:31:07 +00008927 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00008928 SubStmt.get() == E->getSubStmt()) {
8929 // Calling this an 'error' is unintuitive, but it does the right thing.
8930 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008931 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00008932 }
Mike Stump11289f42009-09-09 15:08:12 +00008933
8934 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008935 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008936 E->getRParenLoc());
8937}
Mike Stump11289f42009-09-09 15:08:12 +00008938
Douglas Gregora16548e2009-08-11 05:31:07 +00008939template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008940ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008941TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008942 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008943 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008944 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008945
John McCalldadc5752010-08-24 06:29:42 +00008946 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008947 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008948 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008949
John McCalldadc5752010-08-24 06:29:42 +00008950 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008951 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008952 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008953
Douglas Gregora16548e2009-08-11 05:31:07 +00008954 if (!getDerived().AlwaysRebuild() &&
8955 Cond.get() == E->getCond() &&
8956 LHS.get() == E->getLHS() &&
8957 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008958 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008959
Douglas Gregora16548e2009-08-11 05:31:07 +00008960 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00008961 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008962 E->getRParenLoc());
8963}
Mike Stump11289f42009-09-09 15:08:12 +00008964
Douglas Gregora16548e2009-08-11 05:31:07 +00008965template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008966ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008967TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008968 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008969}
8970
8971template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008972ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008973TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008974 switch (E->getOperator()) {
8975 case OO_New:
8976 case OO_Delete:
8977 case OO_Array_New:
8978 case OO_Array_Delete:
8979 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00008980
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008981 case OO_Call: {
8982 // This is a call to an object's operator().
8983 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
8984
8985 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00008986 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008987 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008988 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008989
8990 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00008991 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
8992 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008993
8994 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008995 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008996 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00008997 Args))
8998 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008999
John McCallb268a282010-08-23 23:25:46 +00009000 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009001 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009002 E->getLocEnd());
9003 }
9004
9005#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
9006 case OO_##Name:
9007#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
9008#include "clang/Basic/OperatorKinds.def"
9009 case OO_Subscript:
9010 // Handled below.
9011 break;
9012
9013 case OO_Conditional:
9014 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009015
9016 case OO_None:
9017 case NUM_OVERLOADED_OPERATORS:
9018 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009019 }
9020
John McCalldadc5752010-08-24 06:29:42 +00009021 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00009022 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009023 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009024
Richard Smithdb2630f2012-10-21 03:28:35 +00009025 ExprResult First;
9026 if (E->getOperator() == OO_Amp)
9027 First = getDerived().TransformAddressOfOperand(E->getArg(0));
9028 else
9029 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00009030 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009031 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009032
John McCalldadc5752010-08-24 06:29:42 +00009033 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00009034 if (E->getNumArgs() == 2) {
9035 Second = getDerived().TransformExpr(E->getArg(1));
9036 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009037 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009038 }
Mike Stump11289f42009-09-09 15:08:12 +00009039
Douglas Gregora16548e2009-08-11 05:31:07 +00009040 if (!getDerived().AlwaysRebuild() &&
9041 Callee.get() == E->getCallee() &&
9042 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00009043 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009044 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00009045
Lang Hames5de91cc2012-10-02 04:45:10 +00009046 Sema::FPContractStateRAII FPContractState(getSema());
9047 getSema().FPFeatures.fp_contract = E->isFPContractable();
9048
Douglas Gregora16548e2009-08-11 05:31:07 +00009049 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
9050 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00009051 Callee.get(),
9052 First.get(),
9053 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009054}
Mike Stump11289f42009-09-09 15:08:12 +00009055
Douglas Gregora16548e2009-08-11 05:31:07 +00009056template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009057ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009058TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
9059 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009060}
Mike Stump11289f42009-09-09 15:08:12 +00009061
Douglas Gregora16548e2009-08-11 05:31:07 +00009062template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009063ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00009064TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
9065 // Transform the callee.
9066 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
9067 if (Callee.isInvalid())
9068 return ExprError();
9069
9070 // Transform exec config.
9071 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
9072 if (EC.isInvalid())
9073 return ExprError();
9074
9075 // Transform arguments.
9076 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009077 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009078 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00009079 &ArgChanged))
9080 return ExprError();
9081
9082 if (!getDerived().AlwaysRebuild() &&
9083 Callee.get() == E->getCallee() &&
9084 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009085 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00009086
9087 // FIXME: Wrong source location information for the '('.
9088 SourceLocation FakeLParenLoc
9089 = ((Expr *)Callee.get())->getSourceRange().getBegin();
9090 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009091 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00009092 E->getRParenLoc(), EC.get());
9093}
9094
9095template<typename Derived>
9096ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009097TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009098 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9099 if (!Type)
9100 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009101
John McCalldadc5752010-08-24 06:29:42 +00009102 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009103 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009104 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009105 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009106
Douglas Gregora16548e2009-08-11 05:31:07 +00009107 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009108 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009109 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009110 return E;
Nico Weberc153d242014-07-28 00:02:09 +00009111 return getDerived().RebuildCXXNamedCastExpr(
9112 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
9113 Type, E->getAngleBrackets().getEnd(),
9114 // FIXME. this should be '(' location
9115 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009116}
Mike Stump11289f42009-09-09 15:08:12 +00009117
Douglas Gregora16548e2009-08-11 05:31:07 +00009118template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009119ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009120TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
9121 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009122}
Mike Stump11289f42009-09-09 15:08:12 +00009123
9124template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009125ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009126TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
9127 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00009128}
9129
Douglas Gregora16548e2009-08-11 05:31:07 +00009130template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009131ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009132TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009133 CXXReinterpretCastExpr *E) {
9134 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009135}
Mike Stump11289f42009-09-09 15:08:12 +00009136
Douglas Gregora16548e2009-08-11 05:31:07 +00009137template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009138ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009139TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
9140 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009141}
Mike Stump11289f42009-09-09 15:08:12 +00009142
Douglas Gregora16548e2009-08-11 05:31:07 +00009143template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009144ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009145TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009146 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009147 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9148 if (!Type)
9149 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009150
John McCalldadc5752010-08-24 06:29:42 +00009151 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009152 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009153 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009154 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009155
Douglas Gregora16548e2009-08-11 05:31:07 +00009156 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009157 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009158 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009159 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009160
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009161 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00009162 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009163 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009164 E->getRParenLoc());
9165}
Mike Stump11289f42009-09-09 15:08:12 +00009166
Douglas Gregora16548e2009-08-11 05:31:07 +00009167template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009168ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009169TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009170 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00009171 TypeSourceInfo *TInfo
9172 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9173 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009174 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009175
Douglas Gregora16548e2009-08-11 05:31:07 +00009176 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00009177 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009178 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009179
Douglas Gregor9da64192010-04-26 22:37:10 +00009180 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9181 E->getLocStart(),
9182 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009183 E->getLocEnd());
9184 }
Mike Stump11289f42009-09-09 15:08:12 +00009185
Eli Friedman456f0182012-01-20 01:26:23 +00009186 // We don't know whether the subexpression is potentially evaluated until
9187 // after we perform semantic analysis. We speculatively assume it is
9188 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00009189 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00009190 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
9191 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00009192
John McCalldadc5752010-08-24 06:29:42 +00009193 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00009194 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009195 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009196
Douglas Gregora16548e2009-08-11 05:31:07 +00009197 if (!getDerived().AlwaysRebuild() &&
9198 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009199 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009200
Douglas Gregor9da64192010-04-26 22:37:10 +00009201 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9202 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00009203 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009204 E->getLocEnd());
9205}
9206
9207template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009208ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00009209TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
9210 if (E->isTypeOperand()) {
9211 TypeSourceInfo *TInfo
9212 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9213 if (!TInfo)
9214 return ExprError();
9215
9216 if (!getDerived().AlwaysRebuild() &&
9217 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009218 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00009219
Douglas Gregor69735112011-03-06 17:40:41 +00009220 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00009221 E->getLocStart(),
9222 TInfo,
9223 E->getLocEnd());
9224 }
9225
Francois Pichet9f4f2072010-09-08 12:20:18 +00009226 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9227
9228 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
9229 if (SubExpr.isInvalid())
9230 return ExprError();
9231
9232 if (!getDerived().AlwaysRebuild() &&
9233 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009234 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00009235
9236 return getDerived().RebuildCXXUuidofExpr(E->getType(),
9237 E->getLocStart(),
9238 SubExpr.get(),
9239 E->getLocEnd());
9240}
9241
9242template<typename Derived>
9243ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009244TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009245 return E;
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
Douglas Gregora16548e2009-08-11 05:31:07 +00009250TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009251 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009252 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009253}
Mike Stump11289f42009-09-09 15:08:12 +00009254
Douglas Gregora16548e2009-08-11 05:31:07 +00009255template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009256ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009257TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00009258 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00009259
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009260 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
9261 // Make sure that we capture 'this'.
9262 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009263 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009264 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009265
Douglas Gregorb15af892010-01-07 23:12:05 +00009266 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00009267}
Mike Stump11289f42009-09-09 15:08:12 +00009268
Douglas Gregora16548e2009-08-11 05:31:07 +00009269template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009270ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009271TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009272 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009273 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009274 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009275
Douglas Gregora16548e2009-08-11 05:31:07 +00009276 if (!getDerived().AlwaysRebuild() &&
9277 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009278 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009279
Douglas Gregor53e191ed2011-07-06 22:04:06 +00009280 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
9281 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00009282}
Mike Stump11289f42009-09-09 15:08:12 +00009283
Douglas Gregora16548e2009-08-11 05:31:07 +00009284template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009285ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009286TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00009287 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009288 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
9289 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009290 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00009291 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009292
Chandler Carruth794da4c2010-02-08 06:42:49 +00009293 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009294 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009295 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009296
Douglas Gregor033f6752009-12-23 23:03:06 +00009297 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00009298}
Mike Stump11289f42009-09-09 15:08:12 +00009299
Douglas Gregora16548e2009-08-11 05:31:07 +00009300template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009301ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00009302TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
9303 FieldDecl *Field
9304 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
9305 E->getField()));
9306 if (!Field)
9307 return ExprError();
9308
9309 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009310 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00009311
9312 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
9313}
9314
9315template<typename Derived>
9316ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00009317TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
9318 CXXScalarValueInitExpr *E) {
9319 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9320 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009321 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009322
Douglas Gregora16548e2009-08-11 05:31:07 +00009323 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009324 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009325 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009326
Chad Rosier1dcde962012-08-08 18:46:20 +00009327 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00009328 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00009329 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009330}
Mike Stump11289f42009-09-09 15:08:12 +00009331
Douglas Gregora16548e2009-08-11 05:31:07 +00009332template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009333ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009334TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009335 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00009336 TypeSourceInfo *AllocTypeInfo
9337 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
9338 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009339 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009340
Douglas Gregora16548e2009-08-11 05:31:07 +00009341 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00009342 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00009343 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009344 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009345
Douglas Gregora16548e2009-08-11 05:31:07 +00009346 // Transform the placement arguments (if any).
9347 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009348 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00009349 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00009350 E->getNumPlacementArgs(), true,
9351 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00009352 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009353
Sebastian Redl6047f072012-02-16 12:22:20 +00009354 // Transform the initializer (if any).
9355 Expr *OldInit = E->getInitializer();
9356 ExprResult NewInit;
9357 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +00009358 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +00009359 if (NewInit.isInvalid())
9360 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009361
Sebastian Redl6047f072012-02-16 12:22:20 +00009362 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00009363 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009364 if (E->getOperatorNew()) {
9365 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009366 getDerived().TransformDecl(E->getLocStart(),
9367 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009368 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00009369 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009370 }
9371
Craig Topperc3ec1492014-05-26 06:22:03 +00009372 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009373 if (E->getOperatorDelete()) {
9374 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009375 getDerived().TransformDecl(E->getLocStart(),
9376 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009377 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00009378 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009379 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009380
Douglas Gregora16548e2009-08-11 05:31:07 +00009381 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00009382 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009383 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00009384 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00009385 OperatorNew == E->getOperatorNew() &&
9386 OperatorDelete == E->getOperatorDelete() &&
9387 !ArgumentChanged) {
9388 // Mark any declarations we need as referenced.
9389 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00009390 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009391 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00009392 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009393 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00009394
Sebastian Redl6047f072012-02-16 12:22:20 +00009395 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00009396 QualType ElementType
9397 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
9398 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
9399 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
9400 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00009401 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00009402 }
9403 }
9404 }
Sebastian Redl6047f072012-02-16 12:22:20 +00009405
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009406 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009407 }
Mike Stump11289f42009-09-09 15:08:12 +00009408
Douglas Gregor0744ef62010-09-07 21:49:58 +00009409 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009410 if (!ArraySize.get()) {
9411 // If no array size was specified, but the new expression was
9412 // instantiated with an array type (e.g., "new T" where T is
9413 // instantiated with "int[4]"), extract the outer bound from the
9414 // array type as our array size. We do this with constant and
9415 // dependently-sized array types.
9416 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
9417 if (!ArrayT) {
9418 // Do nothing
9419 } else if (const ConstantArrayType *ConsArrayT
9420 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009421 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
9422 SemaRef.Context.getSizeType(),
9423 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009424 AllocType = ConsArrayT->getElementType();
9425 } else if (const DependentSizedArrayType *DepArrayT
9426 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
9427 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009428 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009429 AllocType = DepArrayT->getElementType();
9430 }
9431 }
9432 }
Sebastian Redl6047f072012-02-16 12:22:20 +00009433
Douglas Gregora16548e2009-08-11 05:31:07 +00009434 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
9435 E->isGlobalNew(),
9436 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009437 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009438 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00009439 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009440 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00009441 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00009442 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00009443 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009444 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009445}
Mike Stump11289f42009-09-09 15:08:12 +00009446
Douglas Gregora16548e2009-08-11 05:31:07 +00009447template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009448ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009449TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009450 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00009451 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009452 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009453
Douglas Gregord2d9da02010-02-26 00:38:10 +00009454 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00009455 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009456 if (E->getOperatorDelete()) {
9457 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009458 getDerived().TransformDecl(E->getLocStart(),
9459 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009460 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00009461 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009462 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009463
Douglas Gregora16548e2009-08-11 05:31:07 +00009464 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00009465 Operand.get() == E->getArgument() &&
9466 OperatorDelete == E->getOperatorDelete()) {
9467 // Mark any declarations we need as referenced.
9468 // FIXME: instantiation-specific.
9469 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009470 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00009471
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00009472 if (!E->getArgument()->isTypeDependent()) {
9473 QualType Destroyed = SemaRef.Context.getBaseElementType(
9474 E->getDestroyedType());
9475 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
9476 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00009477 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00009478 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00009479 }
9480 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009481
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009482 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009483 }
Mike Stump11289f42009-09-09 15:08:12 +00009484
Douglas Gregora16548e2009-08-11 05:31:07 +00009485 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
9486 E->isGlobalDelete(),
9487 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00009488 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009489}
Mike Stump11289f42009-09-09 15:08:12 +00009490
Douglas Gregora16548e2009-08-11 05:31:07 +00009491template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009492ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00009493TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009494 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009495 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00009496 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009497 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009498
John McCallba7bf592010-08-24 05:47:05 +00009499 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00009500 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00009501 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009502 E->getOperatorLoc(),
9503 E->isArrow()? tok::arrow : tok::period,
9504 ObjectTypePtr,
9505 MayBePseudoDestructor);
9506 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009507 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009508
John McCallba7bf592010-08-24 05:47:05 +00009509 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00009510 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
9511 if (QualifierLoc) {
9512 QualifierLoc
9513 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
9514 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00009515 return ExprError();
9516 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00009517 CXXScopeSpec SS;
9518 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00009519
Douglas Gregor678f90d2010-02-25 01:56:36 +00009520 PseudoDestructorTypeStorage Destroyed;
9521 if (E->getDestroyedTypeInfo()) {
9522 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00009523 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009524 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00009525 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009526 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00009527 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00009528 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00009529 // We aren't likely to be able to resolve the identifier down to a type
9530 // now anyway, so just retain the identifier.
9531 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
9532 E->getDestroyedTypeLoc());
9533 } else {
9534 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00009535 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009536 *E->getDestroyedTypeIdentifier(),
9537 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009538 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009539 SS, ObjectTypePtr,
9540 false);
9541 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009542 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009543
Douglas Gregor678f90d2010-02-25 01:56:36 +00009544 Destroyed
9545 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
9546 E->getDestroyedTypeLoc());
9547 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009548
Craig Topperc3ec1492014-05-26 06:22:03 +00009549 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009550 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00009551 CXXScopeSpec EmptySS;
9552 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00009553 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009554 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009555 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00009556 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009557
John McCallb268a282010-08-23 23:25:46 +00009558 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00009559 E->getOperatorLoc(),
9560 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00009561 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009562 ScopeTypeInfo,
9563 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009564 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009565 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00009566}
Mike Stump11289f42009-09-09 15:08:12 +00009567
Douglas Gregorad8a3362009-09-04 17:36:40 +00009568template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009569ExprResult
John McCalld14a8642009-11-21 08:51:07 +00009570TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009571 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00009572 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
9573 Sema::LookupOrdinaryName);
9574
9575 // Transform all the decls.
9576 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
9577 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009578 NamedDecl *InstD = static_cast<NamedDecl*>(
9579 getDerived().TransformDecl(Old->getNameLoc(),
9580 *I));
John McCall84d87672009-12-10 09:41:52 +00009581 if (!InstD) {
9582 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9583 // This can happen because of dependent hiding.
9584 if (isa<UsingShadowDecl>(*I))
9585 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00009586 else {
9587 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009588 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009589 }
John McCall84d87672009-12-10 09:41:52 +00009590 }
John McCalle66edc12009-11-24 19:00:30 +00009591
9592 // Expand using declarations.
9593 if (isa<UsingDecl>(InstD)) {
9594 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009595 for (auto *I : UD->shadows())
9596 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00009597 continue;
9598 }
9599
9600 R.addDecl(InstD);
9601 }
9602
9603 // Resolve a kind, but don't do any further analysis. If it's
9604 // ambiguous, the callee needs to deal with it.
9605 R.resolveKind();
9606
9607 // Rebuild the nested-name qualifier, if present.
9608 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00009609 if (Old->getQualifierLoc()) {
9610 NestedNameSpecifierLoc QualifierLoc
9611 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9612 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009613 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009614
Douglas Gregor0da1d432011-02-28 20:01:57 +00009615 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00009616 }
9617
Douglas Gregor9262f472010-04-27 18:19:34 +00009618 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00009619 CXXRecordDecl *NamingClass
9620 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
9621 Old->getNameLoc(),
9622 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00009623 if (!NamingClass) {
9624 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009625 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009626 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009627
Douglas Gregorda7be082010-04-27 16:10:10 +00009628 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00009629 }
9630
Abramo Bagnara7945c982012-01-27 09:46:47 +00009631 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9632
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009633 // If we have neither explicit template arguments, nor the template keyword,
Reid Kleckner744e3e72015-10-20 21:04:13 +00009634 // it's a normal declaration name or member reference.
9635 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
9636 NamedDecl *D = R.getAsSingle<NamedDecl>();
9637 // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
9638 // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
9639 // give a good diagnostic.
9640 if (D && D->isCXXInstanceMember()) {
9641 return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R,
9642 /*TemplateArgs=*/nullptr,
9643 /*Scope=*/nullptr);
9644 }
9645
John McCalle66edc12009-11-24 19:00:30 +00009646 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
Reid Kleckner744e3e72015-10-20 21:04:13 +00009647 }
John McCalle66edc12009-11-24 19:00:30 +00009648
9649 // If we have template arguments, rebuild them, then rebuild the
9650 // templateid expression.
9651 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00009652 if (Old->hasExplicitTemplateArgs() &&
9653 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00009654 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00009655 TransArgs)) {
9656 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00009657 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009658 }
John McCalle66edc12009-11-24 19:00:30 +00009659
Abramo Bagnara7945c982012-01-27 09:46:47 +00009660 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009661 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00009662}
Mike Stump11289f42009-09-09 15:08:12 +00009663
Douglas Gregora16548e2009-08-11 05:31:07 +00009664template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009665ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00009666TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
9667 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009668 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009669 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
9670 TypeSourceInfo *From = E->getArg(I);
9671 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00009672 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00009673 TypeLocBuilder TLB;
9674 TLB.reserve(FromTL.getFullDataSize());
9675 QualType To = getDerived().TransformType(TLB, FromTL);
9676 if (To.isNull())
9677 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009678
Douglas Gregor29c42f22012-02-24 07:38:34 +00009679 if (To == From->getType())
9680 Args.push_back(From);
9681 else {
9682 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9683 ArgChanged = true;
9684 }
9685 continue;
9686 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009687
Douglas Gregor29c42f22012-02-24 07:38:34 +00009688 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009689
Douglas Gregor29c42f22012-02-24 07:38:34 +00009690 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00009691 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00009692 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
9693 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9694 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00009695
Douglas Gregor29c42f22012-02-24 07:38:34 +00009696 // Determine whether the set of unexpanded parameter packs can and should
9697 // be expanded.
9698 bool Expand = true;
9699 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009700 Optional<unsigned> OrigNumExpansions =
9701 ExpansionTL.getTypePtr()->getNumExpansions();
9702 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009703 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
9704 PatternTL.getSourceRange(),
9705 Unexpanded,
9706 Expand, RetainExpansion,
9707 NumExpansions))
9708 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009709
Douglas Gregor29c42f22012-02-24 07:38:34 +00009710 if (!Expand) {
9711 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009712 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00009713 // expansion.
9714 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00009715
Douglas Gregor29c42f22012-02-24 07:38:34 +00009716 TypeLocBuilder TLB;
9717 TLB.reserve(From->getTypeLoc().getFullDataSize());
9718
9719 QualType To = getDerived().TransformType(TLB, PatternTL);
9720 if (To.isNull())
9721 return ExprError();
9722
Chad Rosier1dcde962012-08-08 18:46:20 +00009723 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009724 PatternTL.getSourceRange(),
9725 ExpansionTL.getEllipsisLoc(),
9726 NumExpansions);
9727 if (To.isNull())
9728 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009729
Douglas Gregor29c42f22012-02-24 07:38:34 +00009730 PackExpansionTypeLoc ToExpansionTL
9731 = TLB.push<PackExpansionTypeLoc>(To);
9732 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9733 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9734 continue;
9735 }
9736
9737 // Expand the pack expansion by substituting for each argument in the
9738 // pack(s).
9739 for (unsigned I = 0; I != *NumExpansions; ++I) {
9740 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
9741 TypeLocBuilder TLB;
9742 TLB.reserve(PatternTL.getFullDataSize());
9743 QualType To = getDerived().TransformType(TLB, PatternTL);
9744 if (To.isNull())
9745 return ExprError();
9746
Eli Friedman5e05c4a2013-07-19 21:49:32 +00009747 if (To->containsUnexpandedParameterPack()) {
9748 To = getDerived().RebuildPackExpansionType(To,
9749 PatternTL.getSourceRange(),
9750 ExpansionTL.getEllipsisLoc(),
9751 NumExpansions);
9752 if (To.isNull())
9753 return ExprError();
9754
9755 PackExpansionTypeLoc ToExpansionTL
9756 = TLB.push<PackExpansionTypeLoc>(To);
9757 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9758 }
9759
Douglas Gregor29c42f22012-02-24 07:38:34 +00009760 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9761 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009762
Douglas Gregor29c42f22012-02-24 07:38:34 +00009763 if (!RetainExpansion)
9764 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009765
Douglas Gregor29c42f22012-02-24 07:38:34 +00009766 // If we're supposed to retain a pack expansion, do so by temporarily
9767 // forgetting the partially-substituted parameter pack.
9768 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
9769
9770 TypeLocBuilder TLB;
9771 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00009772
Douglas Gregor29c42f22012-02-24 07:38:34 +00009773 QualType To = getDerived().TransformType(TLB, PatternTL);
9774 if (To.isNull())
9775 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009776
9777 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009778 PatternTL.getSourceRange(),
9779 ExpansionTL.getEllipsisLoc(),
9780 NumExpansions);
9781 if (To.isNull())
9782 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009783
Douglas Gregor29c42f22012-02-24 07:38:34 +00009784 PackExpansionTypeLoc ToExpansionTL
9785 = TLB.push<PackExpansionTypeLoc>(To);
9786 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9787 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9788 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009789
Douglas Gregor29c42f22012-02-24 07:38:34 +00009790 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009791 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009792
9793 return getDerived().RebuildTypeTrait(E->getTrait(),
9794 E->getLocStart(),
9795 Args,
9796 E->getLocEnd());
9797}
9798
9799template<typename Derived>
9800ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00009801TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
9802 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
9803 if (!T)
9804 return ExprError();
9805
9806 if (!getDerived().AlwaysRebuild() &&
9807 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009808 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009809
9810 ExprResult SubExpr;
9811 {
9812 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9813 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
9814 if (SubExpr.isInvalid())
9815 return ExprError();
9816
9817 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009818 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009819 }
9820
9821 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
9822 E->getLocStart(),
9823 T,
9824 SubExpr.get(),
9825 E->getLocEnd());
9826}
9827
9828template<typename Derived>
9829ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00009830TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
9831 ExprResult SubExpr;
9832 {
9833 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9834 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
9835 if (SubExpr.isInvalid())
9836 return ExprError();
9837
9838 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009839 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +00009840 }
9841
9842 return getDerived().RebuildExpressionTrait(
9843 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
9844}
9845
Reid Kleckner32506ed2014-06-12 23:03:48 +00009846template <typename Derived>
9847ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
9848 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
9849 TypeSourceInfo **RecoveryTSI) {
9850 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
9851 DRE, AddrTaken, RecoveryTSI);
9852
9853 // Propagate both errors and recovered types, which return ExprEmpty.
9854 if (!NewDRE.isUsable())
9855 return NewDRE;
9856
9857 // We got an expr, wrap it up in parens.
9858 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
9859 return PE;
9860 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
9861 PE->getRParen());
9862}
9863
9864template <typename Derived>
9865ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9866 DependentScopeDeclRefExpr *E) {
9867 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
9868 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00009869}
9870
9871template<typename Derived>
9872ExprResult
9873TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9874 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +00009875 bool IsAddressOfOperand,
9876 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00009877 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009878 NestedNameSpecifierLoc QualifierLoc
9879 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9880 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009881 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00009882 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00009883
John McCall31f82722010-11-12 08:19:04 +00009884 // TODO: If this is a conversion-function-id, verify that the
9885 // destination type name (if present) resolves the same way after
9886 // instantiation as it did in the local scope.
9887
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009888 DeclarationNameInfo NameInfo
9889 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
9890 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009891 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009892
John McCalle66edc12009-11-24 19:00:30 +00009893 if (!E->hasExplicitTemplateArgs()) {
9894 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009895 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009896 // Note: it is sufficient to compare the Name component of NameInfo:
9897 // if name has not changed, DNLoc has not changed either.
9898 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009899 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009900
Reid Kleckner32506ed2014-06-12 23:03:48 +00009901 return getDerived().RebuildDependentScopeDeclRefExpr(
9902 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
9903 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +00009904 }
John McCall6b51f282009-11-23 01:53:49 +00009905
9906 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009907 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9908 E->getNumTemplateArgs(),
9909 TransArgs))
9910 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009911
Reid Kleckner32506ed2014-06-12 23:03:48 +00009912 return getDerived().RebuildDependentScopeDeclRefExpr(
9913 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
9914 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00009915}
9916
9917template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009918ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009919TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00009920 // CXXConstructExprs other than for list-initialization and
9921 // CXXTemporaryObjectExpr are always implicit, so when we have
9922 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00009923 if ((E->getNumArgs() == 1 ||
9924 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00009925 (!getDerived().DropCallArgument(E->getArg(0))) &&
9926 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00009927 return getDerived().TransformExpr(E->getArg(0));
9928
Douglas Gregora16548e2009-08-11 05:31:07 +00009929 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
9930
9931 QualType T = getDerived().TransformType(E->getType());
9932 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00009933 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009934
9935 CXXConstructorDecl *Constructor
9936 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009937 getDerived().TransformDecl(E->getLocStart(),
9938 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009939 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009940 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009941
Douglas Gregora16548e2009-08-11 05:31:07 +00009942 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009943 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009944 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009945 &ArgumentChanged))
9946 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009947
Douglas Gregora16548e2009-08-11 05:31:07 +00009948 if (!getDerived().AlwaysRebuild() &&
9949 T == E->getType() &&
9950 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00009951 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00009952 // Mark the constructor as referenced.
9953 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009954 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009955 return E;
Douglas Gregorde550352010-02-26 00:01:57 +00009956 }
Mike Stump11289f42009-09-09 15:08:12 +00009957
Douglas Gregordb121ba2009-12-14 16:27:04 +00009958 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
Richard Smithc83bf822016-06-10 00:58:19 +00009959 Constructor,
Richard Smithc2bebe92016-05-11 20:37:46 +00009960 E->isElidable(), Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00009961 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00009962 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +00009963 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00009964 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00009965 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00009966 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009967}
Mike Stump11289f42009-09-09 15:08:12 +00009968
Richard Smith5179eb72016-06-28 19:03:57 +00009969template<typename Derived>
9970ExprResult TreeTransform<Derived>::TransformCXXInheritedCtorInitExpr(
9971 CXXInheritedCtorInitExpr *E) {
9972 QualType T = getDerived().TransformType(E->getType());
9973 if (T.isNull())
9974 return ExprError();
9975
9976 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
9977 getDerived().TransformDecl(E->getLocStart(), E->getConstructor()));
9978 if (!Constructor)
9979 return ExprError();
9980
9981 if (!getDerived().AlwaysRebuild() &&
9982 T == E->getType() &&
9983 Constructor == E->getConstructor()) {
9984 // Mark the constructor as referenced.
9985 // FIXME: Instantiation-specific
9986 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
9987 return E;
9988 }
9989
9990 return getDerived().RebuildCXXInheritedCtorInitExpr(
9991 T, E->getLocation(), Constructor,
9992 E->constructsVBase(), E->inheritedFromVBase());
9993}
9994
Douglas Gregora16548e2009-08-11 05:31:07 +00009995/// \brief Transform a C++ temporary-binding expression.
9996///
Douglas Gregor363b1512009-12-24 18:51:59 +00009997/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
9998/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009999template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010000ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010001TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +000010002 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010003}
Mike Stump11289f42009-09-09 15:08:12 +000010004
John McCall5d413782010-12-06 08:20:24 +000010005/// \brief Transform a C++ expression that contains cleanups that should
10006/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +000010007///
John McCall5d413782010-12-06 08:20:24 +000010008/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +000010009/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +000010010template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010011ExprResult
John McCall5d413782010-12-06 08:20:24 +000010012TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +000010013 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010014}
Mike Stump11289f42009-09-09 15:08:12 +000010015
Douglas Gregora16548e2009-08-11 05:31:07 +000010016template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010017ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010018TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +000010019 CXXTemporaryObjectExpr *E) {
10020 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10021 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010022 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010023
Douglas Gregora16548e2009-08-11 05:31:07 +000010024 CXXConstructorDecl *Constructor
10025 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +000010026 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010027 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +000010028 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +000010029 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010030
Douglas Gregora16548e2009-08-11 05:31:07 +000010031 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010032 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +000010033 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010034 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010035 &ArgumentChanged))
10036 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010037
Douglas Gregora16548e2009-08-11 05:31:07 +000010038 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010039 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010040 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000010041 !ArgumentChanged) {
10042 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +000010043 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +000010044 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000010045 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010046
Richard Smithd59b8322012-12-19 01:39:02 +000010047 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +000010048 return getDerived().RebuildCXXTemporaryObjectExpr(T,
10049 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010050 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +000010051 E->getLocEnd());
10052}
Mike Stump11289f42009-09-09 15:08:12 +000010053
Douglas Gregora16548e2009-08-11 05:31:07 +000010054template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010055ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +000010056TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +000010057 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010058 // lambda body, because they are not semantically within that scope.
Richard Smithc38498f2015-04-27 21:27:54 +000010059 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010060 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
10061 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
Richard Smithc38498f2015-04-27 21:27:54 +000010062 E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010063 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +000010064 CEnd = E->capture_end();
10065 C != CEnd; ++C) {
James Dennettdd2ffea22015-05-07 18:48:18 +000010066 if (!E->isInitCapture(C))
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010067 continue;
Richard Smith01014ce2014-11-20 23:53:14 +000010068 EnterExpressionEvaluationContext EEEC(getSema(),
10069 Sema::PotentiallyEvaluated);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010070 ExprResult NewExprInitResult = getDerived().TransformInitializer(
10071 C->getCapturedVar()->getInit(),
10072 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith01014ce2014-11-20 23:53:14 +000010073
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010074 if (NewExprInitResult.isInvalid())
10075 return ExprError();
10076 Expr *NewExprInit = NewExprInitResult.get();
Richard Smith01014ce2014-11-20 23:53:14 +000010077
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010078 VarDecl *OldVD = C->getCapturedVar();
Richard Smith01014ce2014-11-20 23:53:14 +000010079 QualType NewInitCaptureType =
Richard Smith42b10572015-11-11 01:36:17 +000010080 getSema().buildLambdaInitCaptureInitialization(
10081 C->getLocation(), OldVD->getType()->isReferenceType(),
10082 OldVD->getIdentifier(),
10083 C->getCapturedVar()->getInitStyle() != VarDecl::CInit, NewExprInit);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010084 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010085 InitCaptureExprsAndTypes[C - E->capture_begin()] =
10086 std::make_pair(NewExprInitResult, NewInitCaptureType);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010087 }
10088
Faisal Vali2cba1332013-10-23 06:44:28 +000010089 // Transform the template parameters, and add them to the current
10090 // instantiation scope. The null case is handled correctly.
Richard Smithc38498f2015-04-27 21:27:54 +000010091 auto TPL = getDerived().TransformTemplateParameterList(
Faisal Vali2cba1332013-10-23 06:44:28 +000010092 E->getTemplateParameterList());
10093
Richard Smith01014ce2014-11-20 23:53:14 +000010094 // Transform the type of the original lambda's call operator.
10095 // The transformation MUST be done in the CurrentInstantiationScope since
10096 // it introduces a mapping of the original to the newly created
10097 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +000010098 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +000010099 {
10100 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
10101 FunctionProtoTypeLoc OldCallOpFPTL =
10102 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +000010103
10104 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +000010105 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +000010106 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +000010107 QualType NewCallOpType = TransformFunctionProtoType(
10108 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +000010109 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
10110 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
10111 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +000010112 });
Reid Kleckneraac43c62014-12-15 21:07:16 +000010113 if (NewCallOpType.isNull())
10114 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +000010115 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
10116 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +000010117 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010118
Richard Smithc38498f2015-04-27 21:27:54 +000010119 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
10120 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
10121 LSI->GLTemplateParameterList = TPL;
10122
Eli Friedmand564afb2012-09-19 01:18:11 +000010123 // Create the local class that will describe the lambda.
10124 CXXRecordDecl *Class
10125 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +000010126 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +000010127 /*KnownDependent=*/false,
10128 E->getCaptureDefault());
Eli Friedmand564afb2012-09-19 01:18:11 +000010129 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
10130
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010131 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +000010132 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
10133 Class, E->getIntroducerRange(), NewCallOpTSI,
10134 E->getCallOperator()->getLocEnd(),
Faisal Valia734ab92016-03-26 16:11:37 +000010135 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams(),
10136 E->getCallOperator()->isConstexpr());
10137
Faisal Vali2cba1332013-10-23 06:44:28 +000010138 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +000010139
Faisal Vali2cba1332013-10-23 06:44:28 +000010140 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
Richard Smithc38498f2015-04-27 21:27:54 +000010141 getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
Richard Smithba71c082013-05-16 06:20:58 +000010142
Douglas Gregorb4328232012-02-14 00:00:48 +000010143 // Introduce the context of the call operator.
Richard Smithc38498f2015-04-27 21:27:54 +000010144 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
Richard Smith7ff2bcb2014-01-24 01:54:52 +000010145 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +000010146
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010147 // Enter the scope of the lambda.
Richard Smithc38498f2015-04-27 21:27:54 +000010148 getSema().buildLambdaScope(LSI, NewCallOperator,
10149 E->getIntroducerRange(),
10150 E->getCaptureDefault(),
10151 E->getCaptureDefaultLoc(),
10152 E->hasExplicitParameters(),
10153 E->hasExplicitResultType(),
10154 E->isMutable());
10155
10156 bool Invalid = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010157
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010158 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010159 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010160 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010161 CEnd = E->capture_end();
10162 C != CEnd; ++C) {
10163 // When we hit the first implicit capture, tell Sema that we've finished
10164 // the list of explicit captures.
10165 if (!FinishedExplicitCaptures && C->isImplicit()) {
10166 getSema().finishLambdaExplicitCaptures(LSI);
10167 FinishedExplicitCaptures = true;
10168 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010169
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010170 // Capturing 'this' is trivial.
10171 if (C->capturesThis()) {
Faisal Validc6b5962016-03-21 09:25:37 +000010172 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
10173 /*BuildAndDiagnose*/ true, nullptr,
10174 C->getCaptureKind() == LCK_StarThis);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010175 continue;
10176 }
Alexey Bataev39c81e22014-08-28 04:28:19 +000010177 // Captured expression will be recaptured during captured variables
10178 // rebuilding.
10179 if (C->capturesVLAType())
10180 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +000010181
Richard Smithba71c082013-05-16 06:20:58 +000010182 // Rebuild init-captures, including the implied field declaration.
James Dennettdd2ffea22015-05-07 18:48:18 +000010183 if (E->isInitCapture(C)) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010184 InitCaptureInfoTy InitExprTypePair =
10185 InitCaptureExprsAndTypes[C - E->capture_begin()];
10186 ExprResult Init = InitExprTypePair.first;
10187 QualType InitQualType = InitExprTypePair.second;
10188 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +000010189 Invalid = true;
10190 continue;
10191 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000010192 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010193 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
Richard Smith42b10572015-11-11 01:36:17 +000010194 OldVD->getLocation(), InitExprTypePair.second, OldVD->getIdentifier(),
10195 OldVD->getInitStyle(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +000010196 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +000010197 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010198 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +000010199 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010200 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000010201 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +000010202 continue;
10203 }
10204
10205 assert(C->capturesVariable() && "unexpected kind of lambda capture");
10206
Douglas Gregor3e308b12012-02-14 19:27:52 +000010207 // Determine the capture kind for Sema.
10208 Sema::TryCaptureKind Kind
10209 = C->isImplicit()? Sema::TryCapture_Implicit
10210 : C->getCaptureKind() == LCK_ByCopy
10211 ? Sema::TryCapture_ExplicitByVal
10212 : Sema::TryCapture_ExplicitByRef;
10213 SourceLocation EllipsisLoc;
10214 if (C->isPackExpansion()) {
10215 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
10216 bool ShouldExpand = false;
10217 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010218 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +000010219 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
10220 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000010221 Unexpanded,
10222 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +000010223 NumExpansions)) {
10224 Invalid = true;
10225 continue;
10226 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010227
Douglas Gregor3e308b12012-02-14 19:27:52 +000010228 if (ShouldExpand) {
10229 // The transform has determined that we should perform an expansion;
10230 // transform and capture each of the arguments.
10231 // expansion of the pattern. Do so.
10232 VarDecl *Pack = C->getCapturedVar();
10233 for (unsigned I = 0; I != *NumExpansions; ++I) {
10234 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10235 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000010236 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000010237 Pack));
10238 if (!CapturedVar) {
10239 Invalid = true;
10240 continue;
10241 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010242
Douglas Gregor3e308b12012-02-14 19:27:52 +000010243 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +000010244 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
10245 }
Richard Smith9467be42014-06-06 17:33:35 +000010246
10247 // FIXME: Retain a pack expansion if RetainExpansion is true.
10248
Douglas Gregor3e308b12012-02-14 19:27:52 +000010249 continue;
10250 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010251
Douglas Gregor3e308b12012-02-14 19:27:52 +000010252 EllipsisLoc = C->getEllipsisLoc();
10253 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010254
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010255 // Transform the captured variable.
10256 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000010257 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010258 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +000010259 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010260 Invalid = true;
10261 continue;
10262 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010263
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010264 // Capture the transformed variable.
Meador Inge4f9dee72015-06-26 00:09:55 +000010265 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
10266 EllipsisLoc);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010267 }
10268 if (!FinishedExplicitCaptures)
10269 getSema().finishLambdaExplicitCaptures(LSI);
10270
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010271 // Enter a new evaluation context to insulate the lambda from any
10272 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +000010273 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010274
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010275 // Instantiate the body of the lambda expression.
Richard Smithc38498f2015-04-27 21:27:54 +000010276 StmtResult Body =
10277 Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
10278
10279 // ActOnLambda* will pop the function scope for us.
10280 FuncScopeCleanup.disable();
10281
Douglas Gregorb4328232012-02-14 00:00:48 +000010282 if (Body.isInvalid()) {
Richard Smithc38498f2015-04-27 21:27:54 +000010283 SavedContext.pop();
Craig Topperc3ec1492014-05-26 06:22:03 +000010284 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +000010285 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +000010286 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +000010287 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +000010288
Richard Smithc38498f2015-04-27 21:27:54 +000010289 // Copy the LSI before ActOnFinishFunctionBody removes it.
10290 // FIXME: This is dumb. Store the lambda information somewhere that outlives
10291 // the call operator.
10292 auto LSICopy = *LSI;
10293 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
10294 /*IsInstantiation*/ true);
10295 SavedContext.pop();
10296
10297 return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(),
10298 &LSICopy);
Douglas Gregore31e6062012-02-07 10:09:13 +000010299}
10300
10301template<typename Derived>
10302ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010303TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010304 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +000010305 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10306 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010307 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010308
Douglas Gregora16548e2009-08-11 05:31:07 +000010309 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010310 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000010311 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +000010312 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010313 &ArgumentChanged))
10314 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010315
Douglas Gregora16548e2009-08-11 05:31:07 +000010316 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010317 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010318 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010319 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010320
Douglas Gregora16548e2009-08-11 05:31:07 +000010321 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +000010322 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +000010323 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010324 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +000010325 E->getRParenLoc());
10326}
Mike Stump11289f42009-09-09 15:08:12 +000010327
Douglas Gregora16548e2009-08-11 05:31:07 +000010328template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010329ExprResult
John McCall8cd78132009-11-19 22:55:06 +000010330TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010331 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010332 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000010333 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000010334 Expr *OldBase;
10335 QualType BaseType;
10336 QualType ObjectType;
10337 if (!E->isImplicitAccess()) {
10338 OldBase = E->getBase();
10339 Base = getDerived().TransformExpr(OldBase);
10340 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010341 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010342
John McCall2d74de92009-12-01 22:10:20 +000010343 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +000010344 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +000010345 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +000010346 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010347 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010348 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +000010349 ObjectTy,
10350 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +000010351 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010352 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +000010353
John McCallba7bf592010-08-24 05:47:05 +000010354 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +000010355 BaseType = ((Expr*) Base.get())->getType();
10356 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +000010357 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +000010358 BaseType = getDerived().TransformType(E->getBaseType());
10359 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
10360 }
Mike Stump11289f42009-09-09 15:08:12 +000010361
Douglas Gregora5cb6da2009-10-20 05:58:46 +000010362 // Transform the first part of the nested-name-specifier that qualifies
10363 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +000010364 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +000010365 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +000010366 E->getFirstQualifierFoundInScope(),
10367 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +000010368
Douglas Gregore16af532011-02-28 18:50:33 +000010369 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010370 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +000010371 QualifierLoc
10372 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
10373 ObjectType,
10374 FirstQualifierInScope);
10375 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010376 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010377 }
Mike Stump11289f42009-09-09 15:08:12 +000010378
Abramo Bagnara7945c982012-01-27 09:46:47 +000010379 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
10380
John McCall31f82722010-11-12 08:19:04 +000010381 // TODO: If this is a conversion-function-id, verify that the
10382 // destination type name (if present) resolves the same way after
10383 // instantiation as it did in the local scope.
10384
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010385 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +000010386 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010387 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000010388 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010389
John McCall2d74de92009-12-01 22:10:20 +000010390 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +000010391 // This is a reference to a member without an explicitly-specified
10392 // template argument list. Optimize for this common case.
10393 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +000010394 Base.get() == OldBase &&
10395 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +000010396 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010397 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +000010398 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010399 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010400
John McCallb268a282010-08-23 23:25:46 +000010401 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010402 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +000010403 E->isArrow(),
10404 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000010405 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010406 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +000010407 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010408 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000010409 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +000010410 }
10411
John McCall6b51f282009-11-23 01:53:49 +000010412 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010413 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
10414 E->getNumTemplateArgs(),
10415 TransArgs))
10416 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010417
John McCallb268a282010-08-23 23:25:46 +000010418 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010419 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +000010420 E->isArrow(),
10421 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000010422 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010423 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +000010424 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010425 NameInfo,
John McCall10eae182009-11-30 22:42:35 +000010426 &TransArgs);
10427}
10428
10429template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010430ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010431TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +000010432 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000010433 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000010434 QualType BaseType;
10435 if (!Old->isImplicitAccess()) {
10436 Base = getDerived().TransformExpr(Old->getBase());
10437 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010438 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010439 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +000010440 Old->isArrow());
10441 if (Base.isInvalid())
10442 return ExprError();
10443 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +000010444 } else {
10445 BaseType = getDerived().TransformType(Old->getBaseType());
10446 }
John McCall10eae182009-11-30 22:42:35 +000010447
Douglas Gregor0da1d432011-02-28 20:01:57 +000010448 NestedNameSpecifierLoc QualifierLoc;
10449 if (Old->getQualifierLoc()) {
10450 QualifierLoc
10451 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
10452 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010453 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000010454 }
10455
Abramo Bagnara7945c982012-01-27 09:46:47 +000010456 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
10457
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010458 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +000010459 Sema::LookupOrdinaryName);
10460
10461 // Transform all the decls.
10462 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
10463 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010464 NamedDecl *InstD = static_cast<NamedDecl*>(
10465 getDerived().TransformDecl(Old->getMemberLoc(),
10466 *I));
John McCall84d87672009-12-10 09:41:52 +000010467 if (!InstD) {
10468 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
10469 // This can happen because of dependent hiding.
10470 if (isa<UsingShadowDecl>(*I))
10471 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +000010472 else {
10473 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +000010474 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +000010475 }
John McCall84d87672009-12-10 09:41:52 +000010476 }
John McCall10eae182009-11-30 22:42:35 +000010477
10478 // Expand using declarations.
10479 if (isa<UsingDecl>(InstD)) {
10480 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +000010481 for (auto *I : UD->shadows())
10482 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +000010483 continue;
10484 }
10485
10486 R.addDecl(InstD);
10487 }
10488
10489 R.resolveKind();
10490
Douglas Gregor9262f472010-04-27 18:19:34 +000010491 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +000010492 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +000010493 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +000010494 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +000010495 Old->getMemberLoc(),
10496 Old->getNamingClass()));
10497 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +000010498 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010499
Douglas Gregorda7be082010-04-27 16:10:10 +000010500 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +000010501 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010502
John McCall10eae182009-11-30 22:42:35 +000010503 TemplateArgumentListInfo TransArgs;
10504 if (Old->hasExplicitTemplateArgs()) {
10505 TransArgs.setLAngleLoc(Old->getLAngleLoc());
10506 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010507 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
10508 Old->getNumTemplateArgs(),
10509 TransArgs))
10510 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000010511 }
John McCall38836f02010-01-15 08:34:02 +000010512
10513 // FIXME: to do this check properly, we will need to preserve the
10514 // first-qualifier-in-scope here, just in case we had a dependent
10515 // base (and therefore couldn't do the check) and a
10516 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +000010517 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +000010518
John McCallb268a282010-08-23 23:25:46 +000010519 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010520 BaseType,
John McCall10eae182009-11-30 22:42:35 +000010521 Old->getOperatorLoc(),
10522 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +000010523 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010524 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +000010525 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +000010526 R,
10527 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +000010528 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +000010529}
10530
10531template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010532ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010533TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +000010534 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010535 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
10536 if (SubExpr.isInvalid())
10537 return ExprError();
10538
10539 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010540 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010541
10542 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
10543}
10544
10545template<typename Derived>
10546ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010547TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010548 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
10549 if (Pattern.isInvalid())
10550 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010551
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010552 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010553 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010554
Douglas Gregorb8840002011-01-14 21:20:45 +000010555 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
10556 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010557}
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010558
10559template<typename Derived>
10560ExprResult
10561TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
10562 // If E is not value-dependent, then nothing will change when we transform it.
10563 // Note: This is an instantiation-centric view.
10564 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010565 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010566
Richard Smithd784e682015-09-23 21:41:42 +000010567 EnterExpressionEvaluationContext Unevaluated(getSema(), Sema::Unevaluated);
Chad Rosier1dcde962012-08-08 18:46:20 +000010568
Richard Smithd784e682015-09-23 21:41:42 +000010569 ArrayRef<TemplateArgument> PackArgs;
10570 TemplateArgument ArgStorage;
Chad Rosier1dcde962012-08-08 18:46:20 +000010571
Richard Smithd784e682015-09-23 21:41:42 +000010572 // Find the argument list to transform.
10573 if (E->isPartiallySubstituted()) {
10574 PackArgs = E->getPartialArguments();
10575 } else if (E->isValueDependent()) {
10576 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
10577 bool ShouldExpand = false;
10578 bool RetainExpansion = false;
10579 Optional<unsigned> NumExpansions;
10580 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
10581 Unexpanded,
10582 ShouldExpand, RetainExpansion,
10583 NumExpansions))
10584 return ExprError();
10585
10586 // If we need to expand the pack, build a template argument from it and
10587 // expand that.
10588 if (ShouldExpand) {
10589 auto *Pack = E->getPack();
10590 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
10591 ArgStorage = getSema().Context.getPackExpansionType(
10592 getSema().Context.getTypeDeclType(TTPD), None);
10593 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
10594 ArgStorage = TemplateArgument(TemplateName(TTPD), None);
10595 } else {
10596 auto *VD = cast<ValueDecl>(Pack);
10597 ExprResult DRE = getSema().BuildDeclRefExpr(VD, VD->getType(),
10598 VK_RValue, E->getPackLoc());
10599 if (DRE.isInvalid())
10600 return ExprError();
10601 ArgStorage = new (getSema().Context) PackExpansionExpr(
10602 getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
10603 }
10604 PackArgs = ArgStorage;
10605 }
10606 }
10607
10608 // If we're not expanding the pack, just transform the decl.
10609 if (!PackArgs.size()) {
10610 auto *Pack = cast_or_null<NamedDecl>(
10611 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010612 if (!Pack)
10613 return ExprError();
Richard Smithd784e682015-09-23 21:41:42 +000010614 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
10615 E->getPackLoc(),
10616 E->getRParenLoc(), None, None);
10617 }
10618
10619 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
10620 E->getPackLoc());
10621 {
10622 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
10623 typedef TemplateArgumentLocInventIterator<
10624 Derived, const TemplateArgument*> PackLocIterator;
10625 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
10626 PackLocIterator(*this, PackArgs.end()),
10627 TransformedPackArgs, /*Uneval*/true))
10628 return ExprError();
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010629 }
10630
Richard Smithd784e682015-09-23 21:41:42 +000010631 SmallVector<TemplateArgument, 8> Args;
10632 bool PartialSubstitution = false;
10633 for (auto &Loc : TransformedPackArgs.arguments()) {
10634 Args.push_back(Loc.getArgument());
10635 if (Loc.getArgument().isPackExpansion())
10636 PartialSubstitution = true;
10637 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010638
Richard Smithd784e682015-09-23 21:41:42 +000010639 if (PartialSubstitution)
10640 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
10641 E->getPackLoc(),
10642 E->getRParenLoc(), None, Args);
10643
10644 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
Chad Rosier1dcde962012-08-08 18:46:20 +000010645 E->getPackLoc(), E->getRParenLoc(),
Richard Smithd784e682015-09-23 21:41:42 +000010646 Args.size(), None);
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010647}
10648
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010649template<typename Derived>
10650ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010651TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
10652 SubstNonTypeTemplateParmPackExpr *E) {
10653 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010654 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010655}
10656
10657template<typename Derived>
10658ExprResult
John McCall7c454bb2011-07-15 05:09:51 +000010659TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
10660 SubstNonTypeTemplateParmExpr *E) {
10661 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010662 return E;
John McCall7c454bb2011-07-15 05:09:51 +000010663}
10664
10665template<typename Derived>
10666ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +000010667TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
10668 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010669 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +000010670}
10671
10672template<typename Derived>
10673ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +000010674TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
10675 MaterializeTemporaryExpr *E) {
10676 return getDerived().TransformExpr(E->GetTemporaryExpr());
10677}
Chad Rosier1dcde962012-08-08 18:46:20 +000010678
Douglas Gregorfe314812011-06-21 17:03:29 +000010679template<typename Derived>
10680ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +000010681TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
10682 Expr *Pattern = E->getPattern();
10683
10684 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10685 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
10686 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10687
10688 // Determine whether the set of unexpanded parameter packs can and should
10689 // be expanded.
10690 bool Expand = true;
10691 bool RetainExpansion = false;
10692 Optional<unsigned> NumExpansions;
10693 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
10694 Pattern->getSourceRange(),
10695 Unexpanded,
10696 Expand, RetainExpansion,
10697 NumExpansions))
10698 return true;
10699
10700 if (!Expand) {
10701 // Do not expand any packs here, just transform and rebuild a fold
10702 // expression.
10703 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10704
10705 ExprResult LHS =
10706 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
10707 if (LHS.isInvalid())
10708 return true;
10709
10710 ExprResult RHS =
10711 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
10712 if (RHS.isInvalid())
10713 return true;
10714
10715 if (!getDerived().AlwaysRebuild() &&
10716 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
10717 return E;
10718
10719 return getDerived().RebuildCXXFoldExpr(
10720 E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
10721 RHS.get(), E->getLocEnd());
10722 }
10723
10724 // The transform has determined that we should perform an elementwise
10725 // expansion of the pattern. Do so.
10726 ExprResult Result = getDerived().TransformExpr(E->getInit());
10727 if (Result.isInvalid())
10728 return true;
10729 bool LeftFold = E->isLeftFold();
10730
10731 // If we're retaining an expansion for a right fold, it is the innermost
10732 // component and takes the init (if any).
10733 if (!LeftFold && RetainExpansion) {
10734 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10735
10736 ExprResult Out = getDerived().TransformExpr(Pattern);
10737 if (Out.isInvalid())
10738 return true;
10739
10740 Result = getDerived().RebuildCXXFoldExpr(
10741 E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
10742 Result.get(), E->getLocEnd());
10743 if (Result.isInvalid())
10744 return true;
10745 }
10746
10747 for (unsigned I = 0; I != *NumExpansions; ++I) {
10748 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
10749 getSema(), LeftFold ? I : *NumExpansions - I - 1);
10750 ExprResult Out = getDerived().TransformExpr(Pattern);
10751 if (Out.isInvalid())
10752 return true;
10753
10754 if (Out.get()->containsUnexpandedParameterPack()) {
10755 // We still have a pack; retain a pack expansion for this slice.
10756 Result = getDerived().RebuildCXXFoldExpr(
10757 E->getLocStart(),
10758 LeftFold ? Result.get() : Out.get(),
10759 E->getOperator(), E->getEllipsisLoc(),
10760 LeftFold ? Out.get() : Result.get(),
10761 E->getLocEnd());
10762 } else if (Result.isUsable()) {
10763 // We've got down to a single element; build a binary operator.
10764 Result = getDerived().RebuildBinaryOperator(
10765 E->getEllipsisLoc(), E->getOperator(),
10766 LeftFold ? Result.get() : Out.get(),
10767 LeftFold ? Out.get() : Result.get());
10768 } else
10769 Result = Out;
10770
10771 if (Result.isInvalid())
10772 return true;
10773 }
10774
10775 // If we're retaining an expansion for a left fold, it is the outermost
10776 // component and takes the complete expansion so far as its init (if any).
10777 if (LeftFold && RetainExpansion) {
10778 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10779
10780 ExprResult Out = getDerived().TransformExpr(Pattern);
10781 if (Out.isInvalid())
10782 return true;
10783
10784 Result = getDerived().RebuildCXXFoldExpr(
10785 E->getLocStart(), Result.get(),
10786 E->getOperator(), E->getEllipsisLoc(),
10787 Out.get(), E->getLocEnd());
10788 if (Result.isInvalid())
10789 return true;
10790 }
10791
10792 // If we had no init and an empty pack, and we're not retaining an expansion,
10793 // then produce a fallback value or error.
10794 if (Result.isUnset())
10795 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
10796 E->getOperator());
10797
10798 return Result;
10799}
10800
10801template<typename Derived>
10802ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +000010803TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
10804 CXXStdInitializerListExpr *E) {
10805 return getDerived().TransformExpr(E->getSubExpr());
10806}
10807
10808template<typename Derived>
10809ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010810TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010811 return SemaRef.MaybeBindToTemporary(E);
10812}
10813
10814template<typename Derived>
10815ExprResult
10816TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010817 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010818}
10819
10820template<typename Derived>
10821ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +000010822TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
10823 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
10824 if (SubExpr.isInvalid())
10825 return ExprError();
10826
10827 if (!getDerived().AlwaysRebuild() &&
10828 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010829 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +000010830
10831 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +000010832}
10833
10834template<typename Derived>
10835ExprResult
10836TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
10837 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010838 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010839 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010840 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000010841 /*IsCall=*/false, Elements, &ArgChanged))
10842 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010843
Ted Kremeneke65b0862012-03-06 20:05:56 +000010844 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10845 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000010846
Ted Kremeneke65b0862012-03-06 20:05:56 +000010847 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
10848 Elements.data(),
10849 Elements.size());
10850}
10851
10852template<typename Derived>
10853ExprResult
10854TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +000010855 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010856 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010857 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010858 bool ArgChanged = false;
10859 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
10860 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +000010861
Ted Kremeneke65b0862012-03-06 20:05:56 +000010862 if (OrigElement.isPackExpansion()) {
10863 // This key/value element is a pack expansion.
10864 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10865 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
10866 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
10867 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10868
10869 // Determine whether the set of unexpanded parameter packs can
10870 // and should be expanded.
10871 bool Expand = true;
10872 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010873 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
10874 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010875 SourceRange PatternRange(OrigElement.Key->getLocStart(),
10876 OrigElement.Value->getLocEnd());
10877 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
10878 PatternRange,
10879 Unexpanded,
10880 Expand, RetainExpansion,
10881 NumExpansions))
10882 return ExprError();
10883
10884 if (!Expand) {
10885 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000010886 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +000010887 // expansion.
10888 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10889 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10890 if (Key.isInvalid())
10891 return ExprError();
10892
10893 if (Key.get() != OrigElement.Key)
10894 ArgChanged = true;
10895
10896 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10897 if (Value.isInvalid())
10898 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010899
Ted Kremeneke65b0862012-03-06 20:05:56 +000010900 if (Value.get() != OrigElement.Value)
10901 ArgChanged = true;
10902
Chad Rosier1dcde962012-08-08 18:46:20 +000010903 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010904 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
10905 };
10906 Elements.push_back(Expansion);
10907 continue;
10908 }
10909
10910 // Record right away that the argument was changed. This needs
10911 // to happen even if the array expands to nothing.
10912 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010913
Ted Kremeneke65b0862012-03-06 20:05:56 +000010914 // The transform has determined that we should perform an elementwise
10915 // expansion of the pattern. Do so.
10916 for (unsigned I = 0; I != *NumExpansions; ++I) {
10917 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10918 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10919 if (Key.isInvalid())
10920 return ExprError();
10921
10922 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10923 if (Value.isInvalid())
10924 return ExprError();
10925
Chad Rosier1dcde962012-08-08 18:46:20 +000010926 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010927 Key.get(), Value.get(), SourceLocation(), NumExpansions
10928 };
10929
10930 // If any unexpanded parameter packs remain, we still have a
10931 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +000010932 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +000010933 if (Key.get()->containsUnexpandedParameterPack() ||
10934 Value.get()->containsUnexpandedParameterPack())
10935 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +000010936
Ted Kremeneke65b0862012-03-06 20:05:56 +000010937 Elements.push_back(Element);
10938 }
10939
Richard Smith9467be42014-06-06 17:33:35 +000010940 // FIXME: Retain a pack expansion if RetainExpansion is true.
10941
Ted Kremeneke65b0862012-03-06 20:05:56 +000010942 // We've finished with this pack expansion.
10943 continue;
10944 }
10945
10946 // Transform and check key.
10947 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10948 if (Key.isInvalid())
10949 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010950
Ted Kremeneke65b0862012-03-06 20:05:56 +000010951 if (Key.get() != OrigElement.Key)
10952 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010953
Ted Kremeneke65b0862012-03-06 20:05:56 +000010954 // Transform and check value.
10955 ExprResult Value
10956 = getDerived().TransformExpr(OrigElement.Value);
10957 if (Value.isInvalid())
10958 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010959
Ted Kremeneke65b0862012-03-06 20:05:56 +000010960 if (Value.get() != OrigElement.Value)
10961 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010962
10963 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +000010964 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +000010965 };
10966 Elements.push_back(Element);
10967 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010968
Ted Kremeneke65b0862012-03-06 20:05:56 +000010969 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10970 return SemaRef.MaybeBindToTemporary(E);
10971
10972 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
Craig Topperd4336e02015-12-24 23:58:15 +000010973 Elements);
Douglas Gregora16548e2009-08-11 05:31:07 +000010974}
10975
Mike Stump11289f42009-09-09 15:08:12 +000010976template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010977ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010978TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +000010979 TypeSourceInfo *EncodedTypeInfo
10980 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
10981 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010982 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010983
Douglas Gregora16548e2009-08-11 05:31:07 +000010984 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +000010985 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010986 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010987
10988 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +000010989 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000010990 E->getRParenLoc());
10991}
Mike Stump11289f42009-09-09 15:08:12 +000010992
Douglas Gregora16548e2009-08-11 05:31:07 +000010993template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +000010994ExprResult TreeTransform<Derived>::
10995TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +000010996 // This is a kind of implicit conversion, and it needs to get dropped
10997 // and recomputed for the same general reasons that ImplicitCastExprs
10998 // do, as well a more specific one: this expression is only valid when
10999 // it appears *immediately* as an argument expression.
11000 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +000011001}
11002
11003template<typename Derived>
11004ExprResult TreeTransform<Derived>::
11005TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +000011006 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +000011007 = getDerived().TransformType(E->getTypeInfoAsWritten());
11008 if (!TSInfo)
11009 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011010
John McCall31168b02011-06-15 23:02:42 +000011011 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +000011012 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +000011013 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011014
John McCall31168b02011-06-15 23:02:42 +000011015 if (!getDerived().AlwaysRebuild() &&
11016 TSInfo == E->getTypeInfoAsWritten() &&
11017 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011018 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011019
John McCall31168b02011-06-15 23:02:42 +000011020 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000011021 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000011022 Result.get());
11023}
11024
11025template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011026ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011027TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011028 // Transform arguments.
11029 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011030 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000011031 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000011032 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000011033 &ArgChanged))
11034 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011035
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011036 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
11037 // Class message: transform the receiver type.
11038 TypeSourceInfo *ReceiverTypeInfo
11039 = getDerived().TransformType(E->getClassReceiverTypeInfo());
11040 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000011041 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011042
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011043 // If nothing changed, just retain the existing message send.
11044 if (!getDerived().AlwaysRebuild() &&
11045 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011046 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011047
11048 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011049 SmallVector<SourceLocation, 16> SelLocs;
11050 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011051 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
11052 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011053 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011054 E->getMethodDecl(),
11055 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011056 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011057 E->getRightLoc());
11058 }
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011059 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
11060 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
11061 // Build a new class message send to 'super'.
11062 SmallVector<SourceLocation, 16> SelLocs;
11063 E->getSelectorLocs(SelLocs);
11064 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
11065 E->getSelector(),
11066 SelLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +000011067 E->getReceiverType(),
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011068 E->getMethodDecl(),
11069 E->getLeftLoc(),
11070 Args,
11071 E->getRightLoc());
11072 }
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011073
11074 // Instance message: transform the receiver
11075 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
11076 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000011077 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011078 = getDerived().TransformExpr(E->getInstanceReceiver());
11079 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011080 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011081
11082 // If nothing changed, just retain the existing message send.
11083 if (!getDerived().AlwaysRebuild() &&
11084 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011085 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000011086
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011087 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011088 SmallVector<SourceLocation, 16> SelLocs;
11089 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000011090 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011091 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011092 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011093 E->getMethodDecl(),
11094 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011095 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011096 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000011097}
11098
Mike Stump11289f42009-09-09 15:08:12 +000011099template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011100ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011101TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011102 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011103}
11104
Mike Stump11289f42009-09-09 15:08:12 +000011105template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011106ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011107TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011108 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011109}
11110
Mike Stump11289f42009-09-09 15:08:12 +000011111template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011112ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011113TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000011114 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011115 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000011116 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011117 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000011118
11119 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000011120
Douglas Gregord51d90d2010-04-26 20:11:03 +000011121 // If nothing changed, just retain the existing expression.
11122 if (!getDerived().AlwaysRebuild() &&
11123 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011124 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011125
John McCallb268a282010-08-23 23:25:46 +000011126 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000011127 E->getLocation(),
11128 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000011129}
11130
Mike Stump11289f42009-09-09 15:08:12 +000011131template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011132ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011133TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000011134 // 'super' and types never change. Property never changes. Just
11135 // retain the existing expression.
11136 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011137 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011138
Douglas Gregor9faee212010-04-26 20:47:02 +000011139 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011140 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000011141 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011142 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011143
Douglas Gregor9faee212010-04-26 20:47:02 +000011144 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000011145
Douglas Gregor9faee212010-04-26 20:47:02 +000011146 // If nothing changed, just retain the existing expression.
11147 if (!getDerived().AlwaysRebuild() &&
11148 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011149 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011150
John McCallb7bd14f2010-12-02 01:19:52 +000011151 if (E->isExplicitProperty())
11152 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
11153 E->getExplicitProperty(),
11154 E->getLocation());
11155
11156 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000011157 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000011158 E->getImplicitPropertyGetter(),
11159 E->getImplicitPropertySetter(),
11160 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000011161}
11162
Mike Stump11289f42009-09-09 15:08:12 +000011163template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011164ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000011165TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
11166 // Transform the base expression.
11167 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
11168 if (Base.isInvalid())
11169 return ExprError();
11170
11171 // Transform the key expression.
11172 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
11173 if (Key.isInvalid())
11174 return ExprError();
11175
11176 // If nothing changed, just retain the existing expression.
11177 if (!getDerived().AlwaysRebuild() &&
11178 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011179 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011180
Chad Rosier1dcde962012-08-08 18:46:20 +000011181 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000011182 Base.get(), Key.get(),
11183 E->getAtIndexMethodDecl(),
11184 E->setAtIndexMethodDecl());
11185}
11186
11187template<typename Derived>
11188ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011189TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000011190 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011191 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000011192 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011193 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011194
Douglas Gregord51d90d2010-04-26 20:11:03 +000011195 // If nothing changed, just retain the existing expression.
11196 if (!getDerived().AlwaysRebuild() &&
11197 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011198 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011199
John McCallb268a282010-08-23 23:25:46 +000011200 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000011201 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000011202 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000011203}
11204
Mike Stump11289f42009-09-09 15:08:12 +000011205template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011206ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011207TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011208 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011209 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000011210 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000011211 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000011212 SubExprs, &ArgumentChanged))
11213 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011214
Douglas Gregora16548e2009-08-11 05:31:07 +000011215 if (!getDerived().AlwaysRebuild() &&
11216 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011217 return E;
Mike Stump11289f42009-09-09 15:08:12 +000011218
Douglas Gregora16548e2009-08-11 05:31:07 +000011219 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011220 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000011221 E->getRParenLoc());
11222}
11223
Mike Stump11289f42009-09-09 15:08:12 +000011224template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011225ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000011226TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
11227 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
11228 if (SrcExpr.isInvalid())
11229 return ExprError();
11230
11231 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
11232 if (!Type)
11233 return ExprError();
11234
11235 if (!getDerived().AlwaysRebuild() &&
11236 Type == E->getTypeSourceInfo() &&
11237 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011238 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000011239
11240 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
11241 SrcExpr.get(), Type,
11242 E->getRParenLoc());
11243}
11244
11245template<typename Derived>
11246ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011247TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000011248 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000011249
Craig Topperc3ec1492014-05-26 06:22:03 +000011250 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000011251 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
11252
11253 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000011254 blockScope->TheDecl->setBlockMissingReturnType(
11255 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000011256
Chris Lattner01cf8db2011-07-20 06:58:45 +000011257 SmallVector<ParmVarDecl*, 4> params;
11258 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000011259
John McCallc8e321d2016-03-01 02:09:25 +000011260 const FunctionProtoType *exprFunctionType = E->getFunctionType();
11261
Fariborz Jahanian1babe772010-07-09 18:44:02 +000011262 // Parameter substitution.
John McCallc8e321d2016-03-01 02:09:25 +000011263 Sema::ExtParameterInfoBuilder extParamInfos;
David Majnemer59f77922016-06-24 04:05:48 +000011264 if (getDerived().TransformFunctionTypeParams(
11265 E->getCaretLocation(), oldBlock->parameters(), nullptr,
11266 exprFunctionType->getExtParameterInfosOrNull(), paramTypes, &params,
11267 extParamInfos)) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011268 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011269 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011270 }
John McCall490112f2011-02-04 18:33:18 +000011271
Eli Friedman34b49062012-01-26 03:00:14 +000011272 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000011273 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000011274
John McCallc8e321d2016-03-01 02:09:25 +000011275 auto epi = exprFunctionType->getExtProtoInfo();
11276 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
11277
Jordan Rose5c382722013-03-08 21:51:21 +000011278 QualType functionType =
John McCallc8e321d2016-03-01 02:09:25 +000011279 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
John McCall490112f2011-02-04 18:33:18 +000011280 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000011281
11282 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000011283 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000011284 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000011285
11286 if (!oldBlock->blockMissingReturnType()) {
11287 blockScope->HasImplicitReturnType = false;
11288 blockScope->ReturnType = exprResultType;
11289 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011290
John McCall3882ace2011-01-05 12:14:39 +000011291 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000011292 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011293 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011294 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000011295 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011296 }
John McCall3882ace2011-01-05 12:14:39 +000011297
John McCall490112f2011-02-04 18:33:18 +000011298#ifndef NDEBUG
11299 // In builds with assertions, make sure that we captured everything we
11300 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011301 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000011302 for (const auto &I : oldBlock->captures()) {
11303 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000011304
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011305 // Ignore parameter packs.
11306 if (isa<ParmVarDecl>(oldCapture) &&
11307 cast<ParmVarDecl>(oldCapture)->isParameterPack())
11308 continue;
John McCall490112f2011-02-04 18:33:18 +000011309
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011310 VarDecl *newCapture =
11311 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
11312 oldCapture));
11313 assert(blockScope->CaptureMap.count(newCapture));
11314 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000011315 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000011316 }
11317#endif
11318
11319 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000011320 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000011321}
11322
Mike Stump11289f42009-09-09 15:08:12 +000011323template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011324ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000011325TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000011326 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000011327}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000011328
11329template<typename Derived>
11330ExprResult
11331TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011332 QualType RetTy = getDerived().TransformType(E->getType());
11333 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011334 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011335 SubExprs.reserve(E->getNumSubExprs());
11336 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
11337 SubExprs, &ArgumentChanged))
11338 return ExprError();
11339
11340 if (!getDerived().AlwaysRebuild() &&
11341 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011342 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011343
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011344 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011345 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000011346}
Chad Rosier1dcde962012-08-08 18:46:20 +000011347
Douglas Gregora16548e2009-08-11 05:31:07 +000011348//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000011349// Type reconstruction
11350//===----------------------------------------------------------------------===//
11351
Mike Stump11289f42009-09-09 15:08:12 +000011352template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000011353QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
11354 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000011355 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011356 getDerived().getBaseEntity());
11357}
11358
Mike Stump11289f42009-09-09 15:08:12 +000011359template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000011360QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
11361 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000011362 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011363 getDerived().getBaseEntity());
11364}
11365
Mike Stump11289f42009-09-09 15:08:12 +000011366template<typename Derived>
11367QualType
John McCall70dd5f62009-10-30 00:06:24 +000011368TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
11369 bool WrittenAsLValue,
11370 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000011371 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000011372 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011373}
11374
11375template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011376QualType
John McCall70dd5f62009-10-30 00:06:24 +000011377TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
11378 QualType ClassType,
11379 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000011380 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
11381 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011382}
11383
11384template<typename Derived>
Douglas Gregor9bda6cf2015-07-07 03:58:14 +000011385QualType TreeTransform<Derived>::RebuildObjCObjectType(
11386 QualType BaseType,
11387 SourceLocation Loc,
11388 SourceLocation TypeArgsLAngleLoc,
11389 ArrayRef<TypeSourceInfo *> TypeArgs,
11390 SourceLocation TypeArgsRAngleLoc,
11391 SourceLocation ProtocolLAngleLoc,
11392 ArrayRef<ObjCProtocolDecl *> Protocols,
11393 ArrayRef<SourceLocation> ProtocolLocs,
11394 SourceLocation ProtocolRAngleLoc) {
11395 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
11396 TypeArgs, TypeArgsRAngleLoc,
11397 ProtocolLAngleLoc, Protocols, ProtocolLocs,
11398 ProtocolRAngleLoc,
11399 /*FailOnError=*/true);
11400}
11401
11402template<typename Derived>
11403QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
11404 QualType PointeeType,
11405 SourceLocation Star) {
11406 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
11407}
11408
11409template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011410QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000011411TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
11412 ArrayType::ArraySizeModifier SizeMod,
11413 const llvm::APInt *Size,
11414 Expr *SizeExpr,
11415 unsigned IndexTypeQuals,
11416 SourceRange BracketsRange) {
11417 if (SizeExpr || !Size)
11418 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
11419 IndexTypeQuals, BracketsRange,
11420 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000011421
11422 QualType Types[] = {
11423 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
11424 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
11425 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000011426 };
Craig Toppere5ce8312013-07-15 03:38:40 +000011427 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011428 QualType SizeType;
11429 for (unsigned I = 0; I != NumTypes; ++I)
11430 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
11431 SizeType = Types[I];
11432 break;
11433 }
Mike Stump11289f42009-09-09 15:08:12 +000011434
Eli Friedman9562f392012-01-25 23:20:27 +000011435 // Note that we can return a VariableArrayType here in the case where
11436 // the element type was a dependent VariableArrayType.
11437 IntegerLiteral *ArraySize
11438 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
11439 /*FIXME*/BracketsRange.getBegin());
11440 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011441 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000011442 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011443}
Mike Stump11289f42009-09-09 15:08:12 +000011444
Douglas Gregord6ff3322009-08-04 16:50:30 +000011445template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011446QualType
11447TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011448 ArrayType::ArraySizeModifier SizeMod,
11449 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000011450 unsigned IndexTypeQuals,
11451 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011452 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000011453 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011454}
11455
11456template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011457QualType
Mike Stump11289f42009-09-09 15:08:12 +000011458TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011459 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000011460 unsigned IndexTypeQuals,
11461 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011462 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000011463 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011464}
Mike Stump11289f42009-09-09 15:08:12 +000011465
Douglas Gregord6ff3322009-08-04 16:50:30 +000011466template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011467QualType
11468TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011469 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000011470 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011471 unsigned IndexTypeQuals,
11472 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011473 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000011474 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011475 IndexTypeQuals, BracketsRange);
11476}
11477
11478template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011479QualType
11480TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011481 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000011482 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011483 unsigned IndexTypeQuals,
11484 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011485 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000011486 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011487 IndexTypeQuals, BracketsRange);
11488}
11489
11490template<typename Derived>
11491QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +000011492 unsigned NumElements,
11493 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000011494 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000011495 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011496}
Mike Stump11289f42009-09-09 15:08:12 +000011497
Douglas Gregord6ff3322009-08-04 16:50:30 +000011498template<typename Derived>
11499QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
11500 unsigned NumElements,
11501 SourceLocation AttributeLoc) {
11502 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
11503 NumElements, true);
11504 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000011505 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
11506 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000011507 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011508}
Mike Stump11289f42009-09-09 15:08:12 +000011509
Douglas Gregord6ff3322009-08-04 16:50:30 +000011510template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011511QualType
11512TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000011513 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011514 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000011515 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011516}
Mike Stump11289f42009-09-09 15:08:12 +000011517
Douglas Gregord6ff3322009-08-04 16:50:30 +000011518template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000011519QualType TreeTransform<Derived>::RebuildFunctionProtoType(
11520 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000011521 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000011522 const FunctionProtoType::ExtProtoInfo &EPI) {
11523 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011524 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000011525 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000011526 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011527}
Mike Stump11289f42009-09-09 15:08:12 +000011528
Douglas Gregord6ff3322009-08-04 16:50:30 +000011529template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000011530QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
11531 return SemaRef.Context.getFunctionNoProtoType(T);
11532}
11533
11534template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +000011535QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
11536 assert(D && "no decl found");
11537 if (D->isInvalidDecl()) return QualType();
11538
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011539 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000011540 TypeDecl *Ty;
11541 if (isa<UsingDecl>(D)) {
11542 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000011543 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000011544 "UnresolvedUsingTypenameDecl transformed to non-typename using");
11545
11546 // A valid resolved using typename decl points to exactly one type decl.
11547 assert(++Using->shadow_begin() == Using->shadow_end());
11548 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000011549
John McCallb96ec562009-12-04 22:46:56 +000011550 } else {
11551 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
11552 "UnresolvedUsingTypenameDecl transformed to non-using decl");
11553 Ty = cast<UnresolvedUsingTypenameDecl>(D);
11554 }
11555
11556 return SemaRef.Context.getTypeDeclType(Ty);
11557}
11558
11559template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000011560QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
11561 SourceLocation Loc) {
11562 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011563}
11564
11565template<typename Derived>
11566QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
11567 return SemaRef.Context.getTypeOfType(Underlying);
11568}
11569
11570template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000011571QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
11572 SourceLocation Loc) {
11573 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011574}
11575
11576template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000011577QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
11578 UnaryTransformType::UTTKind UKind,
11579 SourceLocation Loc) {
11580 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
11581}
11582
11583template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000011584QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000011585 TemplateName Template,
11586 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000011587 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000011588 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011589}
Mike Stump11289f42009-09-09 15:08:12 +000011590
Douglas Gregor1135c352009-08-06 05:28:30 +000011591template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000011592QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
11593 SourceLocation KWLoc) {
11594 return SemaRef.BuildAtomicType(ValueType, KWLoc);
11595}
11596
11597template<typename Derived>
Xiuli Pan9c14e282016-01-09 12:53:17 +000011598QualType TreeTransform<Derived>::RebuildPipeType(QualType ValueType,
11599 SourceLocation KWLoc) {
11600 return SemaRef.BuildPipeType(ValueType, KWLoc);
11601}
11602
11603template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011604TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011605TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000011606 bool TemplateKW,
11607 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000011608 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000011609 Template);
11610}
11611
11612template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011613TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011614TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
11615 const IdentifierInfo &Name,
11616 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000011617 QualType ObjectType,
11618 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +000011619 UnqualifiedId TemplateName;
11620 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000011621 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000011622 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000011623 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011624 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000011625 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000011626 /*EnteringContext=*/false,
11627 Template);
John McCall31f82722010-11-12 08:19:04 +000011628 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000011629}
Mike Stump11289f42009-09-09 15:08:12 +000011630
Douglas Gregora16548e2009-08-11 05:31:07 +000011631template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000011632TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011633TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000011634 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000011635 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000011636 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000011637 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000011638 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000011639 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000011640 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000011641 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000011642 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000011643 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011644 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000011645 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000011646 /*EnteringContext=*/false,
11647 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000011648 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000011649}
Chad Rosier1dcde962012-08-08 18:46:20 +000011650
Douglas Gregor71395fa2009-11-04 00:56:37 +000011651template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011652ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000011653TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
11654 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000011655 Expr *OrigCallee,
11656 Expr *First,
11657 Expr *Second) {
11658 Expr *Callee = OrigCallee->IgnoreParenCasts();
11659 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000011660
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000011661 if (First->getObjectKind() == OK_ObjCProperty) {
11662 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
11663 if (BinaryOperator::isAssignmentOp(Opc))
11664 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
11665 First, Second);
11666 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
11667 if (Result.isInvalid())
11668 return ExprError();
11669 First = Result.get();
11670 }
11671
11672 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
11673 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
11674 if (Result.isInvalid())
11675 return ExprError();
11676 Second = Result.get();
11677 }
11678
Douglas Gregora16548e2009-08-11 05:31:07 +000011679 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000011680 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000011681 if (!First->getType()->isOverloadableType() &&
11682 !Second->getType()->isOverloadableType())
11683 return getSema().CreateBuiltinArraySubscriptExpr(First,
11684 Callee->getLocStart(),
11685 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000011686 } else if (Op == OO_Arrow) {
11687 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000011688 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
11689 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000011690 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011691 // The argument is not of overloadable type, so try to create a
11692 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000011693 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011694 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000011695
John McCallb268a282010-08-23 23:25:46 +000011696 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011697 }
11698 } else {
John McCallb268a282010-08-23 23:25:46 +000011699 if (!First->getType()->isOverloadableType() &&
11700 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011701 // Neither of the arguments is an overloadable type, so try to
11702 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000011703 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011704 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000011705 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000011706 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011707 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011708
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011709 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011710 }
11711 }
Mike Stump11289f42009-09-09 15:08:12 +000011712
11713 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000011714 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000011715 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000011716
John McCallb268a282010-08-23 23:25:46 +000011717 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000011718 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000011719 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000011720 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000011721 // If we've resolved this to a particular non-member function, just call
11722 // that function. If we resolved it to a member function,
11723 // CreateOverloaded* will find that function for us.
11724 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
11725 if (!isa<CXXMethodDecl>(ND))
11726 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000011727 }
Mike Stump11289f42009-09-09 15:08:12 +000011728
Douglas Gregora16548e2009-08-11 05:31:07 +000011729 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000011730 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000011731 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000011732
Douglas Gregora16548e2009-08-11 05:31:07 +000011733 // Create the overloaded operator invocation for unary operators.
11734 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000011735 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011736 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000011737 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011738 }
Mike Stump11289f42009-09-09 15:08:12 +000011739
Douglas Gregore9d62932011-07-15 16:25:15 +000011740 if (Op == OO_Subscript) {
11741 SourceLocation LBrace;
11742 SourceLocation RBrace;
11743
11744 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000011745 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000011746 LBrace = SourceLocation::getFromRawEncoding(
11747 NameLoc.CXXOperatorName.BeginOpNameLoc);
11748 RBrace = SourceLocation::getFromRawEncoding(
11749 NameLoc.CXXOperatorName.EndOpNameLoc);
11750 } else {
11751 LBrace = Callee->getLocStart();
11752 RBrace = OpLoc;
11753 }
11754
11755 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
11756 First, Second);
11757 }
Sebastian Redladba46e2009-10-29 20:17:01 +000011758
Douglas Gregora16548e2009-08-11 05:31:07 +000011759 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000011760 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011761 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000011762 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
11763 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011764 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011765
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011766 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011767}
Mike Stump11289f42009-09-09 15:08:12 +000011768
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011769template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000011770ExprResult
John McCallb268a282010-08-23 23:25:46 +000011771TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011772 SourceLocation OperatorLoc,
11773 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000011774 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011775 TypeSourceInfo *ScopeType,
11776 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000011777 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000011778 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000011779 QualType BaseType = Base->getType();
11780 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011781 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000011782 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000011783 !BaseType->getAs<PointerType>()->getPointeeType()
11784 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011785 // This pseudo-destructor expression is still a pseudo-destructor.
David Majnemerced8bdf2015-02-25 17:36:15 +000011786 return SemaRef.BuildPseudoDestructorExpr(
11787 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
11788 CCLoc, TildeLoc, Destroyed);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011789 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011790
Douglas Gregor678f90d2010-02-25 01:56:36 +000011791 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011792 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
11793 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
11794 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
11795 NameInfo.setNamedTypeInfo(DestroyedType);
11796
Richard Smith8e4a3862012-05-15 06:15:11 +000011797 // The scope type is now known to be a valid nested name specifier
11798 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000011799 if (ScopeType) {
11800 if (!ScopeType->getType()->getAs<TagType>()) {
11801 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
11802 diag::err_expected_class_or_namespace)
11803 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
11804 return ExprError();
11805 }
11806 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
11807 CCLoc);
11808 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011809
Abramo Bagnara7945c982012-01-27 09:46:47 +000011810 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000011811 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011812 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011813 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000011814 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011815 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +000011816 /*TemplateArgs*/ nullptr,
11817 /*S*/nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011818}
11819
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000011820template<typename Derived>
11821StmtResult
11822TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000011823 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000011824 CapturedDecl *CD = S->getCapturedDecl();
11825 unsigned NumParams = CD->getNumParams();
11826 unsigned ContextParamPos = CD->getContextParamPosition();
11827 SmallVector<Sema::CapturedParamNameType, 4> Params;
11828 for (unsigned I = 0; I < NumParams; ++I) {
11829 if (I != ContextParamPos) {
11830 Params.push_back(
11831 std::make_pair(
11832 CD->getParam(I)->getName(),
11833 getDerived().TransformType(CD->getParam(I)->getType())));
11834 } else {
11835 Params.push_back(std::make_pair(StringRef(), QualType()));
11836 }
11837 }
Craig Topperc3ec1492014-05-26 06:22:03 +000011838 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000011839 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000011840 StmtResult Body;
11841 {
11842 Sema::CompoundScopeRAII CompoundScope(getSema());
11843 Body = getDerived().TransformStmt(S->getCapturedStmt());
11844 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000011845
11846 if (Body.isInvalid()) {
11847 getSema().ActOnCapturedRegionError();
11848 return StmtError();
11849 }
11850
Nikola Smiljanic01a75982014-05-29 10:55:11 +000011851 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000011852}
11853
Douglas Gregord6ff3322009-08-04 16:50:30 +000011854} // end namespace clang
11855
Hans Wennborg59dbe862015-09-29 20:56:43 +000011856#endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H