blob: 36a6520fcd04e60fe2245dde3a45a0cdeb42c84e [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
Douglas Gregord6ff3322009-08-04 16:50:30 +000014#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_SEMA_TREETRANSFORM_H
16
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"
Douglas Gregorebe10102009-08-20 07:17:43 +000024#include "clang/AST/Stmt.h"
25#include "clang/AST/StmtCXX.h"
26#include "clang/AST/StmtObjC.h"
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000027#include "clang/AST/StmtOpenMP.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000028#include "clang/Lex/Preprocessor.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
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000331 /// \brief Transform the given expression.
332 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000333 /// By default, this routine transforms an expression by delegating to the
334 /// appropriate TransformXXXExpr function to build a new expression.
335 /// Subclasses may override this function to transform expressions using some
336 /// other mechanism.
337 ///
338 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000339 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000340
Richard Smithd59b8322012-12-19 01:39:02 +0000341 /// \brief Transform the given initializer.
342 ///
343 /// By default, this routine transforms an initializer by stripping off the
344 /// semantic nodes added by initialization, then passing the result to
345 /// TransformExpr or TransformExprs.
346 ///
347 /// \returns the transformed initializer.
348 ExprResult TransformInitializer(Expr *Init, bool CXXDirectInit);
349
Douglas Gregora3efea12011-01-03 19:04:46 +0000350 /// \brief Transform the given list of expressions.
351 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000352 /// This routine transforms a list of expressions by invoking
353 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregora3efea12011-01-03 19:04:46 +0000354 /// support for variadic templates by expanding any pack expansions (if the
355 /// derived class permits such expansion) along the way. When pack expansions
356 /// are present, the number of outputs may not equal the number of inputs.
357 ///
358 /// \param Inputs The set of expressions to be transformed.
359 ///
360 /// \param NumInputs The number of expressions in \c Inputs.
361 ///
362 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier1dcde962012-08-08 18:46:20 +0000363 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregora3efea12011-01-03 19:04:46 +0000364 /// be.
365 ///
366 /// \param Outputs The transformed input expressions will be added to this
367 /// vector.
368 ///
369 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
370 /// due to transformation.
371 ///
372 /// \returns true if an error occurred, false otherwise.
373 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000374 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +0000375 bool *ArgChanged = 0);
Chad Rosier1dcde962012-08-08 18:46:20 +0000376
Douglas Gregord6ff3322009-08-04 16:50:30 +0000377 /// \brief Transform the given declaration, which is referenced from a type
378 /// or expression.
379 ///
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000380 /// By default, acts as the identity function on declarations, unless the
381 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregor1135c352009-08-06 05:28:30 +0000382 /// may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000383 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000384 llvm::DenseMap<Decl *, Decl *>::iterator Known
385 = TransformedLocalDecls.find(D);
386 if (Known != TransformedLocalDecls.end())
387 return Known->second;
Chad Rosier1dcde962012-08-08 18:46:20 +0000388
389 return D;
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000390 }
Douglas Gregorebe10102009-08-20 07:17:43 +0000391
Chad Rosier1dcde962012-08-08 18:46:20 +0000392 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000393 /// place them on the new declaration.
394 ///
395 /// By default, this operation does nothing. Subclasses may override this
396 /// behavior to transform attributes.
397 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000398
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000399 /// \brief Note that a local declaration has been transformed by this
400 /// transformer.
401 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000402 /// Local declarations are typically transformed via a call to
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000403 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
404 /// the transformer itself has to transform the declarations. This routine
405 /// can be overridden by a subclass that keeps track of such mappings.
406 void transformedLocalDecl(Decl *Old, Decl *New) {
407 TransformedLocalDecls[Old] = New;
408 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000409
Douglas Gregorebe10102009-08-20 07:17:43 +0000410 /// \brief Transform the definition of the given declaration.
411 ///
Mike Stump11289f42009-09-09 15:08:12 +0000412 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000413 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000414 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
415 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000416 }
Mike Stump11289f42009-09-09 15:08:12 +0000417
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000418 /// \brief Transform the given declaration, which was the first part of a
419 /// nested-name-specifier in a member access expression.
420 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000421 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000422 /// identifier in a nested-name-specifier of a member access expression, e.g.,
423 /// the \c T in \c x->T::member
424 ///
425 /// By default, invokes TransformDecl() to transform the declaration.
426 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000427 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
428 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000429 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000430
Douglas Gregor14454802011-02-25 02:25:35 +0000431 /// \brief Transform the given nested-name-specifier with source-location
432 /// information.
433 ///
434 /// By default, transforms all of the types and declarations within the
435 /// nested-name-specifier. Subclasses may override this function to provide
436 /// alternate behavior.
437 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
438 NestedNameSpecifierLoc NNS,
439 QualType ObjectType = QualType(),
440 NamedDecl *FirstQualifierInScope = 0);
441
Douglas Gregorf816bd72009-09-03 22:13:48 +0000442 /// \brief Transform the given declaration name.
443 ///
444 /// By default, transforms the types of conversion function, constructor,
445 /// and destructor names and then (if needed) rebuilds the declaration name.
446 /// Identifiers and selectors are returned unmodified. Sublcasses may
447 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000448 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000449 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000450
Douglas Gregord6ff3322009-08-04 16:50:30 +0000451 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000452 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000453 /// \param SS The nested-name-specifier that qualifies the template
454 /// name. This nested-name-specifier must already have been transformed.
455 ///
456 /// \param Name The template name to transform.
457 ///
458 /// \param NameLoc The source location of the template name.
459 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000460 /// \param ObjectType If we're translating a template name within a member
Douglas Gregor9db53502011-03-02 18:07:45 +0000461 /// access expression, this is the type of the object whose member template
462 /// is being referenced.
463 ///
464 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
465 /// also refers to a name within the current (lexical) scope, this is the
466 /// declaration it refers to.
467 ///
468 /// By default, transforms the template name by transforming the declarations
469 /// and nested-name-specifiers that occur within the template name.
470 /// Subclasses may override this function to provide alternate behavior.
471 TemplateName TransformTemplateName(CXXScopeSpec &SS,
472 TemplateName Name,
Abramo Bagnara7945c982012-01-27 09:46:47 +0000473 SourceLocation NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +0000474 QualType ObjectType = QualType(),
475 NamedDecl *FirstQualifierInScope = 0);
476
Douglas Gregord6ff3322009-08-04 16:50:30 +0000477 /// \brief Transform the given template argument.
478 ///
Mike Stump11289f42009-09-09 15:08:12 +0000479 /// By default, this operation transforms the type, expression, or
480 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000481 /// new template argument from the transformed result. Subclasses may
482 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000483 ///
484 /// Returns true if there was an error.
485 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
486 TemplateArgumentLoc &Output);
487
Douglas Gregor62e06f22010-12-20 17:31:10 +0000488 /// \brief Transform the given set of template arguments.
489 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000490 /// By default, this operation transforms all of the template arguments
Douglas Gregor62e06f22010-12-20 17:31:10 +0000491 /// in the input set using \c TransformTemplateArgument(), and appends
492 /// the transformed arguments to the output list.
493 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000494 /// Note that this overload of \c TransformTemplateArguments() is merely
495 /// a convenience function. Subclasses that wish to override this behavior
496 /// should override the iterator-based member template version.
497 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000498 /// \param Inputs The set of template arguments to be transformed.
499 ///
500 /// \param NumInputs The number of template arguments in \p Inputs.
501 ///
502 /// \param Outputs The set of transformed template arguments output by this
503 /// routine.
504 ///
505 /// Returns true if an error occurred.
506 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
507 unsigned NumInputs,
Douglas Gregorfe921a72010-12-20 23:36:19 +0000508 TemplateArgumentListInfo &Outputs) {
509 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
510 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000511
512 /// \brief Transform the given set of template arguments.
513 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000514 /// By default, this operation transforms all of the template arguments
Douglas Gregor42cafa82010-12-20 17:42:22 +0000515 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier1dcde962012-08-08 18:46:20 +0000516 /// the transformed arguments to the output list.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000517 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000518 /// \param First An iterator to the first template argument.
519 ///
520 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000521 ///
522 /// \param Outputs The set of transformed template arguments output by this
523 /// routine.
524 ///
525 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000526 template<typename InputIterator>
527 bool TransformTemplateArguments(InputIterator First,
528 InputIterator Last,
529 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000530
John McCall0ad16662009-10-29 08:12:44 +0000531 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
532 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
533 TemplateArgumentLoc &ArgLoc);
534
John McCallbcd03502009-12-07 02:54:59 +0000535 /// \brief Fakes up a TypeSourceInfo for a type.
536 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
537 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000538 getDerived().getBaseLocation());
539 }
Mike Stump11289f42009-09-09 15:08:12 +0000540
John McCall550e0c22009-10-21 00:40:46 +0000541#define ABSTRACT_TYPELOC(CLASS, PARENT)
542#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000543 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000544#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000545
Douglas Gregor3024f072012-04-16 07:05:22 +0000546 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
547 FunctionProtoTypeLoc TL,
548 CXXRecordDecl *ThisContext,
549 unsigned ThisTypeQuals);
550
David Majnemerfad8f482013-10-15 09:33:02 +0000551 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000552
Chad Rosier1dcde962012-08-08 18:46:20 +0000553 QualType
John McCall31f82722010-11-12 08:19:04 +0000554 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
555 TemplateSpecializationTypeLoc TL,
556 TemplateName Template);
557
Chad Rosier1dcde962012-08-08 18:46:20 +0000558 QualType
John McCall31f82722010-11-12 08:19:04 +0000559 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
560 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000561 TemplateName Template,
562 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000563
Chad Rosier1dcde962012-08-08 18:46:20 +0000564 QualType
Douglas Gregor5a064722011-02-28 17:23:35 +0000565 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000566 DependentTemplateSpecializationTypeLoc TL,
567 NestedNameSpecifierLoc QualifierLoc);
568
John McCall58f10c32010-03-11 09:03:00 +0000569 /// \brief Transforms the parameters of a function type into the
570 /// given vectors.
571 ///
572 /// The result vectors should be kept in sync; null entries in the
573 /// variables vector are acceptable.
574 ///
575 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000576 bool TransformFunctionTypeParams(SourceLocation Loc,
577 ParmVarDecl **Params, unsigned NumParams,
578 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000579 SmallVectorImpl<QualType> &PTypes,
580 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000581
582 /// \brief Transforms a single function-type parameter. Return null
583 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000584 ///
585 /// \param indexAdjustment - A number to add to the parameter's
586 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000587 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000588 int indexAdjustment,
David Blaikie05785d12013-02-20 22:23:23 +0000589 Optional<unsigned> NumExpansions,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +0000590 bool ExpectParameterPack);
John McCall58f10c32010-03-11 09:03:00 +0000591
John McCall31f82722010-11-12 08:19:04 +0000592 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000593
John McCalldadc5752010-08-24 06:29:42 +0000594 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
595 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +0000596
597 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Richard Smith2589b9802012-07-25 03:56:55 +0000598 /// \brief Transform the captures and body of a lambda expression.
Faisal Vali5fb7c3c2013-12-05 01:40:41 +0000599 ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator,
600 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +0000601
Faisal Vali2cba1332013-10-23 06:44:28 +0000602 TemplateParameterList *TransformTemplateParameterList(
603 TemplateParameterList *TPL) {
604 return TPL;
605 }
606
Richard Smithdb2630f2012-10-21 03:28:35 +0000607 ExprResult TransformAddressOfOperand(Expr *E);
608 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
609 bool IsAddressOfOperand);
610
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000611// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
612// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000613#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000614 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000615 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000616#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000617 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000618 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000619#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000620#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000621
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000622#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000623 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000624 OMPClause *Transform ## Class(Class *S);
625#include "clang/Basic/OpenMPKinds.def"
626
Douglas Gregord6ff3322009-08-04 16:50:30 +0000627 /// \brief Build a new pointer type given its pointee type.
628 ///
629 /// By default, performs semantic analysis when building the pointer type.
630 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000631 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000632
633 /// \brief Build a new block pointer type given its pointee type.
634 ///
Mike Stump11289f42009-09-09 15:08:12 +0000635 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000636 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000637 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000638
John McCall70dd5f62009-10-30 00:06:24 +0000639 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000640 ///
John McCall70dd5f62009-10-30 00:06:24 +0000641 /// By default, performs semantic analysis when building the
642 /// reference type. Subclasses may override this routine to provide
643 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000644 ///
John McCall70dd5f62009-10-30 00:06:24 +0000645 /// \param LValue whether the type was written with an lvalue sigil
646 /// or an rvalue sigil.
647 QualType RebuildReferenceType(QualType ReferentType,
648 bool LValue,
649 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000650
Douglas Gregord6ff3322009-08-04 16:50:30 +0000651 /// \brief Build a new member pointer type given the pointee type and the
652 /// class type it refers into.
653 ///
654 /// By default, performs semantic analysis when building the member pointer
655 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000656 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
657 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000658
Douglas Gregord6ff3322009-08-04 16:50:30 +0000659 /// \brief Build a new array type given the element type, size
660 /// modifier, size of the array (if known), size expression, and index type
661 /// qualifiers.
662 ///
663 /// By default, performs semantic analysis when building the array type.
664 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000665 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000666 QualType RebuildArrayType(QualType ElementType,
667 ArrayType::ArraySizeModifier SizeMod,
668 const llvm::APInt *Size,
669 Expr *SizeExpr,
670 unsigned IndexTypeQuals,
671 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000672
Douglas Gregord6ff3322009-08-04 16:50:30 +0000673 /// \brief Build a new constant array type given the element type, size
674 /// modifier, (known) size of the array, and index type qualifiers.
675 ///
676 /// By default, performs semantic analysis when building the array type.
677 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000678 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000679 ArrayType::ArraySizeModifier SizeMod,
680 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000681 unsigned IndexTypeQuals,
682 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000683
Douglas Gregord6ff3322009-08-04 16:50:30 +0000684 /// \brief Build a new incomplete array type given the element type, size
685 /// modifier, and index type qualifiers.
686 ///
687 /// By default, performs semantic analysis when building the array type.
688 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000689 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000690 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000691 unsigned IndexTypeQuals,
692 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000693
Mike Stump11289f42009-09-09 15:08:12 +0000694 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000695 /// size modifier, size expression, and index type qualifiers.
696 ///
697 /// By default, performs semantic analysis when building the array type.
698 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000699 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000700 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000701 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000702 unsigned IndexTypeQuals,
703 SourceRange BracketsRange);
704
Mike Stump11289f42009-09-09 15:08:12 +0000705 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000706 /// size modifier, size expression, and index type qualifiers.
707 ///
708 /// By default, performs semantic analysis when building the array type.
709 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000710 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000711 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000712 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000713 unsigned IndexTypeQuals,
714 SourceRange BracketsRange);
715
716 /// \brief Build a new vector type given the element type and
717 /// number of elements.
718 ///
719 /// By default, performs semantic analysis when building the vector type.
720 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000721 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000722 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000723
Douglas Gregord6ff3322009-08-04 16:50:30 +0000724 /// \brief Build a new extended vector type given the element type and
725 /// number of elements.
726 ///
727 /// By default, performs semantic analysis when building the vector type.
728 /// Subclasses may override this routine to provide different behavior.
729 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
730 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000731
732 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000733 /// given the element type and number of elements.
734 ///
735 /// By default, performs semantic analysis when building the vector type.
736 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000737 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000738 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000739 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000740
Douglas Gregord6ff3322009-08-04 16:50:30 +0000741 /// \brief Build a new function type.
742 ///
743 /// By default, performs semantic analysis when building the function type.
744 /// Subclasses may override this routine to provide different behavior.
745 QualType RebuildFunctionProtoType(QualType T,
Jordan Rose5c382722013-03-08 21:51:21 +0000746 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000747 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000748
John McCall550e0c22009-10-21 00:40:46 +0000749 /// \brief Build a new unprototyped function type.
750 QualType RebuildFunctionNoProtoType(QualType ResultType);
751
John McCallb96ec562009-12-04 22:46:56 +0000752 /// \brief Rebuild an unresolved typename type, given the decl that
753 /// the UnresolvedUsingTypenameDecl was transformed to.
754 QualType RebuildUnresolvedUsingType(Decl *D);
755
Douglas Gregord6ff3322009-08-04 16:50:30 +0000756 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000757 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000758 return SemaRef.Context.getTypeDeclType(Typedef);
759 }
760
761 /// \brief Build a new class/struct/union type.
762 QualType RebuildRecordType(RecordDecl *Record) {
763 return SemaRef.Context.getTypeDeclType(Record);
764 }
765
766 /// \brief Build a new Enum type.
767 QualType RebuildEnumType(EnumDecl *Enum) {
768 return SemaRef.Context.getTypeDeclType(Enum);
769 }
John McCallfcc33b02009-09-05 00:15:47 +0000770
Mike Stump11289f42009-09-09 15:08:12 +0000771 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000772 ///
773 /// By default, performs semantic analysis when building the typeof type.
774 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000775 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000776
Mike Stump11289f42009-09-09 15:08:12 +0000777 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000778 ///
779 /// By default, builds a new TypeOfType with the given underlying type.
780 QualType RebuildTypeOfType(QualType Underlying);
781
Alexis Hunte852b102011-05-24 22:41:36 +0000782 /// \brief Build a new unary transform type.
783 QualType RebuildUnaryTransformType(QualType BaseType,
784 UnaryTransformType::UTTKind UKind,
785 SourceLocation Loc);
786
Richard Smith74aeef52013-04-26 16:15:35 +0000787 /// \brief Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000788 ///
789 /// By default, performs semantic analysis when building the decltype type.
790 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000791 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000792
Richard Smith74aeef52013-04-26 16:15:35 +0000793 /// \brief Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000794 ///
795 /// By default, builds a new AutoType with the given deduced type.
Richard Smith74aeef52013-04-26 16:15:35 +0000796 QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) {
Richard Smith27d807c2013-04-30 13:56:41 +0000797 // Note, IsDependent is always false here: we implicitly convert an 'auto'
798 // which has been deduced to a dependent type into an undeduced 'auto', so
799 // that we'll retry deduction after the transformation.
Faisal Vali2b391ab2013-09-26 19:54:12 +0000800 return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto,
801 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000802 }
803
Douglas Gregord6ff3322009-08-04 16:50:30 +0000804 /// \brief Build a new template specialization type.
805 ///
806 /// By default, performs semantic analysis when building the template
807 /// specialization type. Subclasses may override this routine to provide
808 /// different behavior.
809 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000810 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000811 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000812
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000813 /// \brief Build a new parenthesized type.
814 ///
815 /// By default, builds a new ParenType type from the inner type.
816 /// Subclasses may override this routine to provide different behavior.
817 QualType RebuildParenType(QualType InnerType) {
818 return SemaRef.Context.getParenType(InnerType);
819 }
820
Douglas Gregord6ff3322009-08-04 16:50:30 +0000821 /// \brief Build a new qualified name type.
822 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000823 /// By default, builds a new ElaboratedType type from the keyword,
824 /// the nested-name-specifier and the named type.
825 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000826 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
827 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000828 NestedNameSpecifierLoc QualifierLoc,
829 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000830 return SemaRef.Context.getElaboratedType(Keyword,
831 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000832 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000833 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000834
835 /// \brief Build a new typename type that refers to a template-id.
836 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000837 /// By default, builds a new DependentNameType type from the
838 /// nested-name-specifier and the given type. Subclasses may override
839 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000840 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000841 ElaboratedTypeKeyword Keyword,
842 NestedNameSpecifierLoc QualifierLoc,
843 const IdentifierInfo *Name,
844 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000845 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000846 // Rebuild the template name.
847 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000848 CXXScopeSpec SS;
849 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +0000850 TemplateName InstName
Douglas Gregor9db53502011-03-02 18:07:45 +0000851 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Chad Rosier1dcde962012-08-08 18:46:20 +0000852
Douglas Gregora7a795b2011-03-01 20:11:18 +0000853 if (InstName.isNull())
854 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000855
Douglas Gregora7a795b2011-03-01 20:11:18 +0000856 // If it's still dependent, make a dependent specialization.
857 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000858 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
859 QualifierLoc.getNestedNameSpecifier(),
860 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000861 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000862
Douglas Gregora7a795b2011-03-01 20:11:18 +0000863 // Otherwise, make an elaborated type wrapping a non-dependent
864 // specialization.
865 QualType T =
866 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
867 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000868
Douglas Gregora7a795b2011-03-01 20:11:18 +0000869 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
870 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +0000871
872 return SemaRef.Context.getElaboratedType(Keyword,
873 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +0000874 T);
875 }
876
Douglas Gregord6ff3322009-08-04 16:50:30 +0000877 /// \brief Build a new typename type that refers to an identifier.
878 ///
879 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000880 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000881 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000882 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000883 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000884 NestedNameSpecifierLoc QualifierLoc,
885 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000886 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000887 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000888 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000889
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000890 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000891 // If the name is still dependent, just build a new dependent name type.
892 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +0000893 return SemaRef.Context.getDependentNameType(Keyword,
894 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000895 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000896 }
897
Abramo Bagnara6150c882010-05-11 21:36:43 +0000898 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000899 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000900 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000901
902 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
903
Abramo Bagnarad7548482010-05-19 21:37:53 +0000904 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000905 // into a non-dependent elaborated-type-specifier. Find the tag we're
906 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000907 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000908 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
909 if (!DC)
910 return QualType();
911
John McCallbf8c5192010-05-27 06:40:31 +0000912 if (SemaRef.RequireCompleteDeclContext(SS, DC))
913 return QualType();
914
Douglas Gregore677daf2010-03-31 22:19:08 +0000915 TagDecl *Tag = 0;
916 SemaRef.LookupQualifiedName(Result, DC);
917 switch (Result.getResultKind()) {
918 case LookupResult::NotFound:
919 case LookupResult::NotFoundInCurrentInstantiation:
920 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000921
Douglas Gregore677daf2010-03-31 22:19:08 +0000922 case LookupResult::Found:
923 Tag = Result.getAsSingle<TagDecl>();
924 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000925
Douglas Gregore677daf2010-03-31 22:19:08 +0000926 case LookupResult::FoundOverloaded:
927 case LookupResult::FoundUnresolvedValue:
928 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +0000929
Douglas Gregore677daf2010-03-31 22:19:08 +0000930 case LookupResult::Ambiguous:
931 // Let the LookupResult structure handle ambiguities.
932 return QualType();
933 }
934
935 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000936 // Check where the name exists but isn't a tag type and use that to emit
937 // better diagnostics.
938 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
939 SemaRef.LookupQualifiedName(Result, DC);
940 switch (Result.getResultKind()) {
941 case LookupResult::Found:
942 case LookupResult::FoundOverloaded:
943 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +0000944 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky0c438082011-01-24 19:01:04 +0000945 unsigned Kind = 0;
946 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smithdda56e42011-04-15 14:24:37 +0000947 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
948 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky0c438082011-01-24 19:01:04 +0000949 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
950 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
951 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +0000952 }
Nick Lewycky0c438082011-01-24 19:01:04 +0000953 default:
954 // FIXME: Would be nice to highlight just the source range.
955 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
956 << Kind << Id << DC;
957 break;
958 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000959 return QualType();
960 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000961
Richard Trieucaa33d32011-06-10 03:11:26 +0000962 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
963 IdLoc, *Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +0000964 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000965 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
966 return QualType();
967 }
968
969 // Build the elaborated-type-specifier type.
970 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +0000971 return SemaRef.Context.getElaboratedType(Keyword,
972 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000973 T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000974 }
Mike Stump11289f42009-09-09 15:08:12 +0000975
Douglas Gregor822d0302011-01-12 17:07:58 +0000976 /// \brief Build a new pack expansion type.
977 ///
978 /// By default, builds a new PackExpansionType type from the given pattern.
979 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000980 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +0000981 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000982 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +0000983 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000984 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
985 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +0000986 }
987
Eli Friedman0dfb8892011-10-06 23:00:33 +0000988 /// \brief Build a new atomic type given its value type.
989 ///
990 /// By default, performs semantic analysis when building the atomic type.
991 /// Subclasses may override this routine to provide different behavior.
992 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
993
Douglas Gregor71dc5092009-08-06 06:41:21 +0000994 /// \brief Build a new template name given a nested name specifier, a flag
995 /// indicating whether the "template" keyword was provided, and the template
996 /// that the template name refers to.
997 ///
998 /// By default, builds the new template name directly. Subclasses may override
999 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001000 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001001 bool TemplateKW,
1002 TemplateDecl *Template);
1003
Douglas Gregor71dc5092009-08-06 06:41:21 +00001004 /// \brief Build a new template name given a nested name specifier and the
1005 /// name that is referred to as a template.
1006 ///
1007 /// By default, performs semantic analysis to determine whether the name can
1008 /// be resolved to a specific template, then builds the appropriate kind of
1009 /// template name. Subclasses may override this routine to provide different
1010 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001011 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1012 const IdentifierInfo &Name,
1013 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00001014 QualType ObjectType,
1015 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001016
Douglas Gregor71395fa2009-11-04 00:56:37 +00001017 /// \brief Build a new template name given a nested name specifier and the
1018 /// overloaded operator name that is referred to as a template.
1019 ///
1020 /// By default, performs semantic analysis to determine whether the name can
1021 /// be resolved to a specific template, then builds the appropriate kind of
1022 /// template name. Subclasses may override this routine to provide different
1023 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001024 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001025 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00001026 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001027 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +00001028
1029 /// \brief Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001030 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001031 ///
1032 /// By default, performs semantic analysis to determine whether the name can
1033 /// be resolved to a specific template, then builds the appropriate kind of
1034 /// template name. Subclasses may override this routine to provide different
1035 /// behavior.
1036 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1037 const TemplateArgument &ArgPack) {
1038 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1039 }
1040
Douglas Gregorebe10102009-08-20 07:17:43 +00001041 /// \brief Build a new compound statement.
1042 ///
1043 /// By default, performs semantic analysis to build the new statement.
1044 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001045 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001046 MultiStmtArg Statements,
1047 SourceLocation RBraceLoc,
1048 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001049 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001050 IsStmtExpr);
1051 }
1052
1053 /// \brief Build a new case statement.
1054 ///
1055 /// By default, performs semantic analysis to build the new statement.
1056 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001057 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001058 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001059 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001060 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001061 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001062 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001063 ColonLoc);
1064 }
Mike Stump11289f42009-09-09 15:08:12 +00001065
Douglas Gregorebe10102009-08-20 07:17:43 +00001066 /// \brief Attach the body to a new case statement.
1067 ///
1068 /// By default, performs semantic analysis to build the new statement.
1069 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001070 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001071 getSema().ActOnCaseStmtBody(S, Body);
1072 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001073 }
Mike Stump11289f42009-09-09 15:08:12 +00001074
Douglas Gregorebe10102009-08-20 07:17:43 +00001075 /// \brief Build a new default statement.
1076 ///
1077 /// By default, performs semantic analysis to build the new statement.
1078 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001079 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001080 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001081 Stmt *SubStmt) {
1082 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +00001083 /*CurScope=*/0);
1084 }
Mike Stump11289f42009-09-09 15:08:12 +00001085
Douglas Gregorebe10102009-08-20 07:17:43 +00001086 /// \brief Build a new label statement.
1087 ///
1088 /// By default, performs semantic analysis to build the new statement.
1089 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001090 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1091 SourceLocation ColonLoc, Stmt *SubStmt) {
1092 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001093 }
Mike Stump11289f42009-09-09 15:08:12 +00001094
Richard Smithc202b282012-04-14 00:33:13 +00001095 /// \brief Build a new label statement.
1096 ///
1097 /// By default, performs semantic analysis to build the new statement.
1098 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001099 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1100 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001101 Stmt *SubStmt) {
1102 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1103 }
1104
Douglas Gregorebe10102009-08-20 07:17:43 +00001105 /// \brief Build a new "if" statement.
1106 ///
1107 /// By default, performs semantic analysis to build the new statement.
1108 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001109 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier1dcde962012-08-08 18:46:20 +00001110 VarDecl *CondVar, Stmt *Then,
Chris Lattnercab02a62011-02-17 20:34:02 +00001111 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001112 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001113 }
Mike Stump11289f42009-09-09 15:08:12 +00001114
Douglas Gregorebe10102009-08-20 07:17:43 +00001115 /// \brief Start building a new switch statement.
1116 ///
1117 /// By default, performs semantic analysis to build the new statement.
1118 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001119 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001120 Expr *Cond, VarDecl *CondVar) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001121 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001122 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001123 }
Mike Stump11289f42009-09-09 15:08:12 +00001124
Douglas Gregorebe10102009-08-20 07:17:43 +00001125 /// \brief Attach the body to the switch statement.
1126 ///
1127 /// By default, performs semantic analysis to build the new statement.
1128 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001129 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001130 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001131 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001132 }
1133
1134 /// \brief Build a new while statement.
1135 ///
1136 /// By default, performs semantic analysis to build the new statement.
1137 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001138 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1139 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001140 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001141 }
Mike Stump11289f42009-09-09 15:08:12 +00001142
Douglas Gregorebe10102009-08-20 07:17:43 +00001143 /// \brief Build a new do-while statement.
1144 ///
1145 /// By default, performs semantic analysis to build the new statement.
1146 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001147 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001148 SourceLocation WhileLoc, SourceLocation LParenLoc,
1149 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001150 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1151 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001152 }
1153
1154 /// \brief Build a new for statement.
1155 ///
1156 /// By default, performs semantic analysis to build the new statement.
1157 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001158 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier1dcde962012-08-08 18:46:20 +00001159 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001160 VarDecl *CondVar, Sema::FullExprArg Inc,
1161 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001162 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001163 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001164 }
Mike Stump11289f42009-09-09 15:08:12 +00001165
Douglas Gregorebe10102009-08-20 07:17:43 +00001166 /// \brief Build a new goto statement.
1167 ///
1168 /// By default, performs semantic analysis to build the new statement.
1169 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001170 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1171 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001172 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001173 }
1174
1175 /// \brief Build a new indirect goto statement.
1176 ///
1177 /// By default, performs semantic analysis to build the new statement.
1178 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001179 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001180 SourceLocation StarLoc,
1181 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001182 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001183 }
Mike Stump11289f42009-09-09 15:08:12 +00001184
Douglas Gregorebe10102009-08-20 07:17:43 +00001185 /// \brief Build a new return statement.
1186 ///
1187 /// By default, performs semantic analysis to build the new statement.
1188 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001189 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCallb268a282010-08-23 23:25:46 +00001190 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001191 }
Mike Stump11289f42009-09-09 15:08:12 +00001192
Douglas Gregorebe10102009-08-20 07:17:43 +00001193 /// \brief Build a new declaration statement.
1194 ///
1195 /// By default, performs semantic analysis to build the new statement.
1196 /// Subclasses may override this routine to provide different behavior.
Rafael Espindolaab417692013-07-09 12:05:01 +00001197 StmtResult RebuildDeclStmt(llvm::MutableArrayRef<Decl *> Decls,
1198 SourceLocation StartLoc, SourceLocation EndLoc) {
1199 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001200 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001201 }
Mike Stump11289f42009-09-09 15:08:12 +00001202
Anders Carlssonaaeef072010-01-24 05:50:09 +00001203 /// \brief Build a new inline asm statement.
1204 ///
1205 /// By default, performs semantic analysis to build the new statement.
1206 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001207 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1208 bool IsVolatile, unsigned NumOutputs,
1209 unsigned NumInputs, IdentifierInfo **Names,
1210 MultiExprArg Constraints, MultiExprArg Exprs,
1211 Expr *AsmString, MultiExprArg Clobbers,
1212 SourceLocation RParenLoc) {
1213 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1214 NumInputs, Names, Constraints, Exprs,
1215 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001216 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001217
Chad Rosier32503022012-06-11 20:47:18 +00001218 /// \brief Build a new MS style inline asm statement.
1219 ///
1220 /// By default, performs semantic analysis to build the new statement.
1221 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001222 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001223 ArrayRef<Token> AsmToks,
1224 StringRef AsmString,
1225 unsigned NumOutputs, unsigned NumInputs,
1226 ArrayRef<StringRef> Constraints,
1227 ArrayRef<StringRef> Clobbers,
1228 ArrayRef<Expr*> Exprs,
1229 SourceLocation EndLoc) {
1230 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1231 NumOutputs, NumInputs,
1232 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001233 }
1234
James Dennett2a4d13c2012-06-15 07:13:21 +00001235 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001236 ///
1237 /// By default, performs semantic analysis to build the new statement.
1238 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001239 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001240 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001241 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001242 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001243 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001244 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001245 }
1246
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001247 /// \brief Rebuild an Objective-C exception declaration.
1248 ///
1249 /// By default, performs semantic analysis to build the new declaration.
1250 /// Subclasses may override this routine to provide different behavior.
1251 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1252 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001253 return getSema().BuildObjCExceptionDecl(TInfo, T,
1254 ExceptionDecl->getInnerLocStart(),
1255 ExceptionDecl->getLocation(),
1256 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001257 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001258
James Dennett2a4d13c2012-06-15 07:13:21 +00001259 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001260 ///
1261 /// By default, performs semantic analysis to build the new statement.
1262 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001263 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001264 SourceLocation RParenLoc,
1265 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001266 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001267 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001268 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001269 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001270
James Dennett2a4d13c2012-06-15 07:13:21 +00001271 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001272 ///
1273 /// By default, performs semantic analysis to build the new statement.
1274 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001275 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001276 Stmt *Body) {
1277 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001278 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001279
James Dennett2a4d13c2012-06-15 07:13:21 +00001280 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001281 ///
1282 /// By default, performs semantic analysis to build the new statement.
1283 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001284 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001285 Expr *Operand) {
1286 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001287 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001288
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001289 /// \brief Build a new OpenMP parallel directive.
1290 ///
1291 /// By default, performs semantic analysis to build the new statement.
1292 /// Subclasses may override this routine to provide different behavior.
1293 StmtResult RebuildOMPParallelDirective(ArrayRef<OMPClause *> Clauses,
1294 Stmt *AStmt,
1295 SourceLocation StartLoc,
1296 SourceLocation EndLoc) {
1297 return getSema().ActOnOpenMPParallelDirective(Clauses, AStmt,
1298 StartLoc, EndLoc);
1299 }
1300
1301 /// \brief Build a new OpenMP 'default' clause.
1302 ///
1303 /// By default, performs semantic analysis to build the new statement.
1304 /// Subclasses may override this routine to provide different behavior.
1305 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1306 SourceLocation KindKwLoc,
1307 SourceLocation StartLoc,
1308 SourceLocation LParenLoc,
1309 SourceLocation EndLoc) {
1310 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1311 StartLoc, LParenLoc, EndLoc);
1312 }
1313
1314 /// \brief Build a new OpenMP 'private' clause.
1315 ///
1316 /// By default, performs semantic analysis to build the new statement.
1317 /// Subclasses may override this routine to provide different behavior.
1318 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1319 SourceLocation StartLoc,
1320 SourceLocation LParenLoc,
1321 SourceLocation EndLoc) {
1322 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1323 EndLoc);
1324 }
1325
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001326 /// \brief Build a new OpenMP 'firstprivate' clause.
1327 ///
1328 /// By default, performs semantic analysis to build the new statement.
1329 /// Subclasses may override this routine to provide different behavior.
1330 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1331 SourceLocation StartLoc,
1332 SourceLocation LParenLoc,
1333 SourceLocation EndLoc) {
1334 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1335 EndLoc);
1336 }
1337
Alexey Bataev758e55e2013-09-06 18:03:48 +00001338 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1339 SourceLocation StartLoc,
1340 SourceLocation LParenLoc,
1341 SourceLocation EndLoc) {
1342 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1343 EndLoc);
1344 }
1345
James Dennett2a4d13c2012-06-15 07:13:21 +00001346 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001347 ///
1348 /// By default, performs semantic analysis to build the new statement.
1349 /// Subclasses may override this routine to provide different behavior.
1350 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1351 Expr *object) {
1352 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1353 }
1354
James Dennett2a4d13c2012-06-15 07:13:21 +00001355 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001356 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001357 /// By default, performs semantic analysis to build the new statement.
1358 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001359 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001360 Expr *Object, Stmt *Body) {
1361 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001362 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001363
James Dennett2a4d13c2012-06-15 07:13:21 +00001364 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001365 ///
1366 /// By default, performs semantic analysis to build the new statement.
1367 /// Subclasses may override this routine to provide different behavior.
1368 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1369 Stmt *Body) {
1370 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1371 }
John McCall53848232011-07-27 01:07:15 +00001372
Douglas Gregorf68a5082010-04-22 23:10:45 +00001373 /// \brief Build a new Objective-C fast enumeration statement.
1374 ///
1375 /// By default, performs semantic analysis to build the new statement.
1376 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001377 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001378 Stmt *Element,
1379 Expr *Collection,
1380 SourceLocation RParenLoc,
1381 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001382 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001383 Element,
John McCallb268a282010-08-23 23:25:46 +00001384 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001385 RParenLoc);
1386 if (ForEachStmt.isInvalid())
1387 return StmtError();
1388
1389 return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001390 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001391
Douglas Gregorebe10102009-08-20 07:17:43 +00001392 /// \brief Build a new C++ exception declaration.
1393 ///
1394 /// By default, performs semantic analysis to build the new decaration.
1395 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001396 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001397 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001398 SourceLocation StartLoc,
1399 SourceLocation IdLoc,
1400 IdentifierInfo *Id) {
Douglas Gregor40965fa2011-04-14 22:32:28 +00001401 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1402 StartLoc, IdLoc, Id);
1403 if (Var)
1404 getSema().CurContext->addDecl(Var);
1405 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001406 }
1407
1408 /// \brief Build a new C++ catch statement.
1409 ///
1410 /// By default, performs semantic analysis to build the new statement.
1411 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001412 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001413 VarDecl *ExceptionDecl,
1414 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001415 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1416 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001417 }
Mike Stump11289f42009-09-09 15:08:12 +00001418
Douglas Gregorebe10102009-08-20 07:17:43 +00001419 /// \brief Build a new C++ try statement.
1420 ///
1421 /// By default, performs semantic analysis to build the new statement.
1422 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001423 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1424 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001425 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001426 }
Mike Stump11289f42009-09-09 15:08:12 +00001427
Richard Smith02e85f32011-04-14 22:09:26 +00001428 /// \brief Build a new C++0x range-based for statement.
1429 ///
1430 /// By default, performs semantic analysis to build the new statement.
1431 /// Subclasses may override this routine to provide different behavior.
1432 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1433 SourceLocation ColonLoc,
1434 Stmt *Range, Stmt *BeginEnd,
1435 Expr *Cond, Expr *Inc,
1436 Stmt *LoopVar,
1437 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001438 // If we've just learned that the range is actually an Objective-C
1439 // collection, treat this as an Objective-C fast enumeration loop.
1440 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1441 if (RangeStmt->isSingleDecl()) {
1442 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001443 if (RangeVar->isInvalidDecl())
1444 return StmtError();
1445
Douglas Gregorf7106af2013-04-08 18:40:13 +00001446 Expr *RangeExpr = RangeVar->getInit();
1447 if (!RangeExpr->isTypeDependent() &&
1448 RangeExpr->getType()->isObjCObjectPointerType())
1449 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1450 RParenLoc);
1451 }
1452 }
1453 }
1454
Richard Smith02e85f32011-04-14 22:09:26 +00001455 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001456 Cond, Inc, LoopVar, RParenLoc,
1457 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001458 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001459
1460 /// \brief Build a new C++0x range-based for statement.
1461 ///
1462 /// By default, performs semantic analysis to build the new statement.
1463 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001464 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001465 bool IsIfExists,
1466 NestedNameSpecifierLoc QualifierLoc,
1467 DeclarationNameInfo NameInfo,
1468 Stmt *Nested) {
1469 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1470 QualifierLoc, NameInfo, Nested);
1471 }
1472
Richard Smith02e85f32011-04-14 22:09:26 +00001473 /// \brief Attach body to a C++0x range-based for statement.
1474 ///
1475 /// By default, performs semantic analysis to finish the new statement.
1476 /// Subclasses may override this routine to provide different behavior.
1477 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1478 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1479 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001480
David Majnemerfad8f482013-10-15 09:33:02 +00001481 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
1482 Stmt *TryBlock, Stmt *Handler) {
1483 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001484 }
1485
David Majnemerfad8f482013-10-15 09:33:02 +00001486 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001487 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001488 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001489 }
1490
David Majnemerfad8f482013-10-15 09:33:02 +00001491 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
1492 return getSema().ActOnSEHFinallyBlock(Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001493 }
1494
Douglas Gregora16548e2009-08-11 05:31:07 +00001495 /// \brief Build a new expression that references a declaration.
1496 ///
1497 /// By default, performs semantic analysis to build the new expression.
1498 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001499 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001500 LookupResult &R,
1501 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001502 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1503 }
1504
1505
1506 /// \brief Build a new expression that references a declaration.
1507 ///
1508 /// By default, performs semantic analysis to build the new expression.
1509 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001510 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001511 ValueDecl *VD,
1512 const DeclarationNameInfo &NameInfo,
1513 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001514 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001515 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001516
1517 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001518
1519 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001520 }
Mike Stump11289f42009-09-09 15:08:12 +00001521
Douglas Gregora16548e2009-08-11 05:31:07 +00001522 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001523 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001524 /// By default, performs semantic analysis to build the new expression.
1525 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001526 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001527 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001528 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001529 }
1530
Douglas Gregorad8a3362009-09-04 17:36:40 +00001531 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001532 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001533 /// By default, performs semantic analysis to build the new expression.
1534 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001535 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001536 SourceLocation OperatorLoc,
1537 bool isArrow,
1538 CXXScopeSpec &SS,
1539 TypeSourceInfo *ScopeType,
1540 SourceLocation CCLoc,
1541 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001542 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001543
Douglas Gregora16548e2009-08-11 05:31:07 +00001544 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001545 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001546 /// By default, performs semantic analysis to build the new expression.
1547 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001548 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001549 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001550 Expr *SubExpr) {
1551 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001552 }
Mike Stump11289f42009-09-09 15:08:12 +00001553
Douglas Gregor882211c2010-04-28 22:16:22 +00001554 /// \brief Build a new builtin offsetof expression.
1555 ///
1556 /// By default, performs semantic analysis to build the new expression.
1557 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001558 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001559 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001560 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001561 unsigned NumComponents,
1562 SourceLocation RParenLoc) {
1563 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1564 NumComponents, RParenLoc);
1565 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001566
1567 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001568 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001569 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001570 /// By default, performs semantic analysis to build the new expression.
1571 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001572 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1573 SourceLocation OpLoc,
1574 UnaryExprOrTypeTrait ExprKind,
1575 SourceRange R) {
1576 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001577 }
1578
Peter Collingbournee190dee2011-03-11 19:24:49 +00001579 /// \brief Build a new sizeof, alignof or vec step expression with an
1580 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001581 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001582 /// By default, performs semantic analysis to build the new expression.
1583 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001584 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1585 UnaryExprOrTypeTrait ExprKind,
1586 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001587 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001588 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001589 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001590 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001591
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001592 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001593 }
Mike Stump11289f42009-09-09 15:08:12 +00001594
Douglas Gregora16548e2009-08-11 05:31:07 +00001595 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001596 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001597 /// By default, performs semantic analysis to build the new expression.
1598 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001599 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001600 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001601 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001602 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001603 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1604 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001605 RBracketLoc);
1606 }
1607
1608 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001609 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001610 /// By default, performs semantic analysis to build the new expression.
1611 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001612 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001613 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001614 SourceLocation RParenLoc,
1615 Expr *ExecConfig = 0) {
John McCallb268a282010-08-23 23:25:46 +00001616 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001617 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001618 }
1619
1620 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001621 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001622 /// By default, performs semantic analysis to build the new expression.
1623 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001624 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001625 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001626 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001627 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001628 const DeclarationNameInfo &MemberNameInfo,
1629 ValueDecl *Member,
1630 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001631 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001632 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00001633 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1634 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00001635 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001636 // We have a reference to an unnamed field. This is always the
1637 // base of an anonymous struct/union member access, i.e. the
1638 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001639 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001640 assert(Member->getType()->isRecordType() &&
1641 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001642
Richard Smithcab9a7d2011-10-26 19:06:56 +00001643 BaseResult =
1644 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley01296292011-04-08 18:41:53 +00001645 QualifierLoc.getNestedNameSpecifier(),
1646 FoundDecl, Member);
1647 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001648 return ExprError();
John Wiegley01296292011-04-08 18:41:53 +00001649 Base = BaseResult.take();
John McCall7decc9e2010-11-18 06:31:45 +00001650 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001651 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001652 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001653 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001654 cast<FieldDecl>(Member)->getType(),
1655 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001656 return getSema().Owned(ME);
1657 }
Mike Stump11289f42009-09-09 15:08:12 +00001658
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001659 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001660 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001661
John Wiegley01296292011-04-08 18:41:53 +00001662 Base = BaseResult.take();
John McCallb268a282010-08-23 23:25:46 +00001663 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001664
John McCall16df1e52010-03-30 21:47:33 +00001665 // FIXME: this involves duplicating earlier analysis in a lot of
1666 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001667 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001668 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001669 R.resolveKind();
1670
John McCallb268a282010-08-23 23:25:46 +00001671 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001672 SS, TemplateKWLoc,
1673 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001674 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001675 }
Mike Stump11289f42009-09-09 15:08:12 +00001676
Douglas Gregora16548e2009-08-11 05:31:07 +00001677 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001678 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001679 /// By default, performs semantic analysis to build the new expression.
1680 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001681 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001682 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001683 Expr *LHS, Expr *RHS) {
1684 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001685 }
1686
1687 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001688 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001689 /// By default, performs semantic analysis to build the new expression.
1690 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001691 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001692 SourceLocation QuestionLoc,
1693 Expr *LHS,
1694 SourceLocation ColonLoc,
1695 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001696 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1697 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001698 }
1699
Douglas Gregora16548e2009-08-11 05:31:07 +00001700 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001701 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001702 /// By default, performs semantic analysis to build the new expression.
1703 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001704 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001705 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001706 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001707 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001708 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001709 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001710 }
Mike Stump11289f42009-09-09 15:08:12 +00001711
Douglas Gregora16548e2009-08-11 05:31:07 +00001712 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001713 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001714 /// By default, performs semantic analysis to build the new expression.
1715 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001716 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001717 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001718 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001719 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001720 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001721 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001722 }
Mike Stump11289f42009-09-09 15:08:12 +00001723
Douglas Gregora16548e2009-08-11 05:31:07 +00001724 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001725 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001726 /// By default, performs semantic analysis to build the new expression.
1727 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001728 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001729 SourceLocation OpLoc,
1730 SourceLocation AccessorLoc,
1731 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001732
John McCall10eae182009-11-30 22:42:35 +00001733 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001734 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001735 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001736 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001737 SS, SourceLocation(),
1738 /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001739 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001740 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001741 }
Mike Stump11289f42009-09-09 15:08:12 +00001742
Douglas Gregora16548e2009-08-11 05:31:07 +00001743 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001744 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001745 /// By default, performs semantic analysis to build the new expression.
1746 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001747 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00001748 MultiExprArg Inits,
1749 SourceLocation RBraceLoc,
1750 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001751 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001752 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00001753 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001754 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00001755
Douglas Gregord3d93062009-11-09 17:16:50 +00001756 // Patch in the result type we were given, which may have been computed
1757 // when the initial InitListExpr was built.
1758 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1759 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001760 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001761 }
Mike Stump11289f42009-09-09 15:08:12 +00001762
Douglas Gregora16548e2009-08-11 05:31:07 +00001763 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001764 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001765 /// By default, performs semantic analysis to build the new expression.
1766 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001767 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001768 MultiExprArg ArrayExprs,
1769 SourceLocation EqualOrColonLoc,
1770 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001771 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001772 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001773 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001774 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001775 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001776 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001777
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001778 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001779 }
Mike Stump11289f42009-09-09 15:08:12 +00001780
Douglas Gregora16548e2009-08-11 05:31:07 +00001781 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001782 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001783 /// By default, builds the implicit value initialization without performing
1784 /// any semantic analysis. Subclasses may override this routine to provide
1785 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001786 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001787 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1788 }
Mike Stump11289f42009-09-09 15:08:12 +00001789
Douglas Gregora16548e2009-08-11 05:31:07 +00001790 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001791 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001792 /// By default, performs semantic analysis to build the new expression.
1793 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001794 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001795 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001796 SourceLocation RParenLoc) {
1797 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001798 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001799 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001800 }
1801
1802 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001803 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001804 /// By default, performs semantic analysis to build the new expression.
1805 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001806 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00001807 MultiExprArg SubExprs,
1808 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001809 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001810 }
Mike Stump11289f42009-09-09 15:08:12 +00001811
Douglas Gregora16548e2009-08-11 05:31:07 +00001812 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001813 ///
1814 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001815 /// rather than attempting to map the label statement itself.
1816 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001817 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001818 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001819 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001820 }
Mike Stump11289f42009-09-09 15:08:12 +00001821
Douglas Gregora16548e2009-08-11 05:31:07 +00001822 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001823 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001824 /// By default, performs semantic analysis to build the new expression.
1825 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001826 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001827 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001828 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001829 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001830 }
Mike Stump11289f42009-09-09 15:08:12 +00001831
Douglas Gregora16548e2009-08-11 05:31:07 +00001832 /// \brief Build a new __builtin_choose_expr expression.
1833 ///
1834 /// By default, performs semantic analysis to build the new expression.
1835 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001836 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001837 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001838 SourceLocation RParenLoc) {
1839 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001840 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001841 RParenLoc);
1842 }
Mike Stump11289f42009-09-09 15:08:12 +00001843
Peter Collingbourne91147592011-04-15 00:35:48 +00001844 /// \brief Build a new generic selection expression.
1845 ///
1846 /// By default, performs semantic analysis to build the new expression.
1847 /// Subclasses may override this routine to provide different behavior.
1848 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1849 SourceLocation DefaultLoc,
1850 SourceLocation RParenLoc,
1851 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00001852 ArrayRef<TypeSourceInfo *> Types,
1853 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00001854 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00001855 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00001856 }
1857
Douglas Gregora16548e2009-08-11 05:31:07 +00001858 /// \brief Build a new overloaded operator call expression.
1859 ///
1860 /// By default, performs semantic analysis to build the new expression.
1861 /// The semantic analysis provides the behavior of template instantiation,
1862 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001863 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001864 /// argument-dependent lookup, etc. Subclasses may override this routine to
1865 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001866 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001867 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001868 Expr *Callee,
1869 Expr *First,
1870 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001871
1872 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001873 /// reinterpret_cast.
1874 ///
1875 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001876 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001877 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001878 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001879 Stmt::StmtClass Class,
1880 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001881 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001882 SourceLocation RAngleLoc,
1883 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001884 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001885 SourceLocation RParenLoc) {
1886 switch (Class) {
1887 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001888 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001889 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001890 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001891
1892 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001893 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001894 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001895 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001896
Douglas Gregora16548e2009-08-11 05:31:07 +00001897 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001898 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001899 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001900 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001901 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001902
Douglas Gregora16548e2009-08-11 05:31:07 +00001903 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001904 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001905 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001906 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001907
Douglas Gregora16548e2009-08-11 05:31:07 +00001908 default:
David Blaikie83d382b2011-09-23 05:06:16 +00001909 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00001910 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001911 }
Mike Stump11289f42009-09-09 15:08:12 +00001912
Douglas Gregora16548e2009-08-11 05:31:07 +00001913 /// \brief Build a new C++ static_cast expression.
1914 ///
1915 /// By default, performs semantic analysis to build the new expression.
1916 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001917 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001918 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001919 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001920 SourceLocation RAngleLoc,
1921 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001922 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001923 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001924 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001925 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001926 SourceRange(LAngleLoc, RAngleLoc),
1927 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001928 }
1929
1930 /// \brief Build a new C++ dynamic_cast expression.
1931 ///
1932 /// By default, performs semantic analysis to build the new expression.
1933 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001934 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001935 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001936 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001937 SourceLocation RAngleLoc,
1938 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001939 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001940 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001941 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001942 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001943 SourceRange(LAngleLoc, RAngleLoc),
1944 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001945 }
1946
1947 /// \brief Build a new C++ reinterpret_cast expression.
1948 ///
1949 /// By default, performs semantic analysis to build the new expression.
1950 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001951 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001952 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001953 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001954 SourceLocation RAngleLoc,
1955 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001956 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001957 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001958 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001959 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001960 SourceRange(LAngleLoc, RAngleLoc),
1961 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001962 }
1963
1964 /// \brief Build a new C++ const_cast expression.
1965 ///
1966 /// By default, performs semantic analysis to build the new expression.
1967 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001968 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001969 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001970 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001971 SourceLocation RAngleLoc,
1972 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001973 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001974 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001975 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001976 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001977 SourceRange(LAngleLoc, RAngleLoc),
1978 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001979 }
Mike Stump11289f42009-09-09 15:08:12 +00001980
Douglas Gregora16548e2009-08-11 05:31:07 +00001981 /// \brief Build a new C++ functional-style cast expression.
1982 ///
1983 /// By default, performs semantic analysis to build the new expression.
1984 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001985 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1986 SourceLocation LParenLoc,
1987 Expr *Sub,
1988 SourceLocation RParenLoc) {
1989 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001990 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001991 RParenLoc);
1992 }
Mike Stump11289f42009-09-09 15:08:12 +00001993
Douglas Gregora16548e2009-08-11 05:31:07 +00001994 /// \brief Build a new C++ typeid(type) expression.
1995 ///
1996 /// By default, performs semantic analysis to build the new expression.
1997 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001998 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001999 SourceLocation TypeidLoc,
2000 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002001 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002002 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002003 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002004 }
Mike Stump11289f42009-09-09 15:08:12 +00002005
Francois Pichet9f4f2072010-09-08 12:20:18 +00002006
Douglas Gregora16548e2009-08-11 05:31:07 +00002007 /// \brief Build a new C++ typeid(expr) expression.
2008 ///
2009 /// By default, performs semantic analysis to build the new expression.
2010 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002011 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002012 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002013 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002014 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002015 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002016 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002017 }
2018
Francois Pichet9f4f2072010-09-08 12:20:18 +00002019 /// \brief Build a new C++ __uuidof(type) expression.
2020 ///
2021 /// By default, performs semantic analysis to build the new expression.
2022 /// Subclasses may override this routine to provide different behavior.
2023 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2024 SourceLocation TypeidLoc,
2025 TypeSourceInfo *Operand,
2026 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002027 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002028 RParenLoc);
2029 }
2030
2031 /// \brief Build a new C++ __uuidof(expr) expression.
2032 ///
2033 /// By default, performs semantic analysis to build the new expression.
2034 /// Subclasses may override this routine to provide different behavior.
2035 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2036 SourceLocation TypeidLoc,
2037 Expr *Operand,
2038 SourceLocation RParenLoc) {
2039 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2040 RParenLoc);
2041 }
2042
Douglas Gregora16548e2009-08-11 05:31:07 +00002043 /// \brief Build a new C++ "this" expression.
2044 ///
2045 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002046 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002047 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002048 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002049 QualType ThisType,
2050 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002051 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002052 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00002053 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
2054 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00002055 }
2056
2057 /// \brief Build a new C++ throw expression.
2058 ///
2059 /// By default, performs semantic analysis to build the new expression.
2060 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002061 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2062 bool IsThrownVariableInScope) {
2063 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002064 }
2065
2066 /// \brief Build a new C++ default-argument expression.
2067 ///
2068 /// By default, builds a new default-argument expression, which does not
2069 /// require any semantic analysis. Subclasses may override this routine to
2070 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002071 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002072 ParmVarDecl *Param) {
2073 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
2074 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00002075 }
2076
Richard Smith852c9db2013-04-20 22:23:05 +00002077 /// \brief Build a new C++11 default-initialization expression.
2078 ///
2079 /// By default, builds a new default field initialization expression, which
2080 /// does not require any semantic analysis. Subclasses may override this
2081 /// routine to provide different behavior.
2082 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2083 FieldDecl *Field) {
2084 return getSema().Owned(CXXDefaultInitExpr::Create(getSema().Context, Loc,
2085 Field));
2086 }
2087
Douglas Gregora16548e2009-08-11 05:31:07 +00002088 /// \brief Build a new C++ zero-initialization expression.
2089 ///
2090 /// By default, performs semantic analysis to build the new expression.
2091 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002092 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2093 SourceLocation LParenLoc,
2094 SourceLocation RParenLoc) {
2095 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002096 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002097 }
Mike Stump11289f42009-09-09 15:08:12 +00002098
Douglas Gregora16548e2009-08-11 05:31:07 +00002099 /// \brief Build a new C++ "new" expression.
2100 ///
2101 /// By default, performs semantic analysis to build the new expression.
2102 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002103 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002104 bool UseGlobal,
2105 SourceLocation PlacementLParen,
2106 MultiExprArg PlacementArgs,
2107 SourceLocation PlacementRParen,
2108 SourceRange TypeIdParens,
2109 QualType AllocatedType,
2110 TypeSourceInfo *AllocatedTypeInfo,
2111 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002112 SourceRange DirectInitRange,
2113 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002114 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002115 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002116 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002117 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002118 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002119 AllocatedType,
2120 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002121 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002122 DirectInitRange,
2123 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002124 }
Mike Stump11289f42009-09-09 15:08:12 +00002125
Douglas Gregora16548e2009-08-11 05:31:07 +00002126 /// \brief Build a new C++ "delete" expression.
2127 ///
2128 /// By default, performs semantic analysis to build the new expression.
2129 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002130 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002131 bool IsGlobalDelete,
2132 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002133 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002134 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002135 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002136 }
Mike Stump11289f42009-09-09 15:08:12 +00002137
Douglas Gregor29c42f22012-02-24 07:38:34 +00002138 /// \brief Build a new type trait expression.
2139 ///
2140 /// By default, performs semantic analysis to build the new expression.
2141 /// Subclasses may override this routine to provide different behavior.
2142 ExprResult RebuildTypeTrait(TypeTrait Trait,
2143 SourceLocation StartLoc,
2144 ArrayRef<TypeSourceInfo *> Args,
2145 SourceLocation RParenLoc) {
2146 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2147 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002148
John Wiegley6242b6a2011-04-28 00:16:57 +00002149 /// \brief Build a new array type trait expression.
2150 ///
2151 /// By default, performs semantic analysis to build the new expression.
2152 /// Subclasses may override this routine to provide different behavior.
2153 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2154 SourceLocation StartLoc,
2155 TypeSourceInfo *TSInfo,
2156 Expr *DimExpr,
2157 SourceLocation RParenLoc) {
2158 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2159 }
2160
John Wiegleyf9f65842011-04-25 06:54:41 +00002161 /// \brief Build a new expression trait expression.
2162 ///
2163 /// By default, performs semantic analysis to build the new expression.
2164 /// Subclasses may override this routine to provide different behavior.
2165 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2166 SourceLocation StartLoc,
2167 Expr *Queried,
2168 SourceLocation RParenLoc) {
2169 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2170 }
2171
Mike Stump11289f42009-09-09 15:08:12 +00002172 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002173 /// expression.
2174 ///
2175 /// By default, performs semantic analysis to build the new expression.
2176 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002177 ExprResult RebuildDependentScopeDeclRefExpr(
2178 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002179 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002180 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002181 const TemplateArgumentListInfo *TemplateArgs,
2182 bool IsAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002183 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002184 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002185
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002186 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnara7945c982012-01-27 09:46:47 +00002187 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002188 NameInfo, TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002189
Richard Smithdb2630f2012-10-21 03:28:35 +00002190 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo,
2191 IsAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002192 }
2193
2194 /// \brief Build a new template-id expression.
2195 ///
2196 /// By default, performs semantic analysis to build the new expression.
2197 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002198 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002199 SourceLocation TemplateKWLoc,
2200 LookupResult &R,
2201 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002202 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002203 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2204 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002205 }
2206
2207 /// \brief Build a new object-construction expression.
2208 ///
2209 /// By default, performs semantic analysis to build the new expression.
2210 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002211 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002212 SourceLocation Loc,
2213 CXXConstructorDecl *Constructor,
2214 bool IsElidable,
2215 MultiExprArg Args,
2216 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002217 bool ListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002218 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002219 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002220 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002221 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002222 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002223 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002224 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002225
Douglas Gregordb121ba2009-12-14 16:27:04 +00002226 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002227 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002228 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002229 ListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002230 RequiresZeroInit, ConstructKind,
2231 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002232 }
2233
2234 /// \brief Build a new object-construction expression.
2235 ///
2236 /// By default, performs semantic analysis to build the new expression.
2237 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002238 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2239 SourceLocation LParenLoc,
2240 MultiExprArg Args,
2241 SourceLocation RParenLoc) {
2242 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002243 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002244 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002245 RParenLoc);
2246 }
2247
2248 /// \brief Build a new object-construction expression.
2249 ///
2250 /// By default, performs semantic analysis to build the new expression.
2251 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002252 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2253 SourceLocation LParenLoc,
2254 MultiExprArg Args,
2255 SourceLocation RParenLoc) {
2256 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002257 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002258 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002259 RParenLoc);
2260 }
Mike Stump11289f42009-09-09 15:08:12 +00002261
Douglas Gregora16548e2009-08-11 05:31:07 +00002262 /// \brief Build a new member reference expression.
2263 ///
2264 /// By default, performs semantic analysis to build the new expression.
2265 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002266 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002267 QualType BaseType,
2268 bool IsArrow,
2269 SourceLocation OperatorLoc,
2270 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002271 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002272 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002273 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002274 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002275 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002276 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002277
John McCallb268a282010-08-23 23:25:46 +00002278 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002279 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002280 SS, TemplateKWLoc,
2281 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002282 MemberNameInfo,
2283 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002284 }
2285
John McCall10eae182009-11-30 22:42:35 +00002286 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002287 ///
2288 /// By default, performs semantic analysis to build the new expression.
2289 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002290 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2291 SourceLocation OperatorLoc,
2292 bool IsArrow,
2293 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002294 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002295 NamedDecl *FirstQualifierInScope,
2296 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002297 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002298 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002299 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002300
John McCallb268a282010-08-23 23:25:46 +00002301 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002302 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002303 SS, TemplateKWLoc,
2304 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00002305 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002306 }
Mike Stump11289f42009-09-09 15:08:12 +00002307
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002308 /// \brief Build a new noexcept expression.
2309 ///
2310 /// By default, performs semantic analysis to build the new expression.
2311 /// Subclasses may override this routine to provide different behavior.
2312 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2313 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2314 }
2315
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002316 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00002317 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2318 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002319 SourceLocation RParenLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002320 Optional<unsigned> Length) {
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002321 if (Length)
Chad Rosier1dcde962012-08-08 18:46:20 +00002322 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2323 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002324 RParenLoc, *Length);
Chad Rosier1dcde962012-08-08 18:46:20 +00002325
2326 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2327 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002328 RParenLoc);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002329 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002330
Patrick Beard0caa3942012-04-19 00:25:12 +00002331 /// \brief Build a new Objective-C boxed expression.
2332 ///
2333 /// By default, performs semantic analysis to build the new expression.
2334 /// Subclasses may override this routine to provide different behavior.
2335 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2336 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2337 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002338
Ted Kremeneke65b0862012-03-06 20:05:56 +00002339 /// \brief Build a new Objective-C array literal.
2340 ///
2341 /// By default, performs semantic analysis to build the new expression.
2342 /// Subclasses may override this routine to provide different behavior.
2343 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2344 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002345 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002346 MultiExprArg(Elements, NumElements));
2347 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002348
2349 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002350 Expr *Base, Expr *Key,
2351 ObjCMethodDecl *getterMethod,
2352 ObjCMethodDecl *setterMethod) {
2353 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2354 getterMethod, setterMethod);
2355 }
2356
2357 /// \brief Build a new Objective-C dictionary literal.
2358 ///
2359 /// By default, performs semantic analysis to build the new expression.
2360 /// Subclasses may override this routine to provide different behavior.
2361 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2362 ObjCDictionaryElement *Elements,
2363 unsigned NumElements) {
2364 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2365 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002366
James Dennett2a4d13c2012-06-15 07:13:21 +00002367 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002368 ///
2369 /// By default, performs semantic analysis to build the new expression.
2370 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002371 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002372 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002373 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00002374 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002375 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002376 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002377
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002378 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002379 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002380 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002381 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002382 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002383 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002384 MultiExprArg Args,
2385 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002386 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2387 ReceiverTypeInfo->getType(),
2388 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002389 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002390 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002391 }
2392
2393 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002394 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002395 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002396 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002397 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002398 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002399 MultiExprArg Args,
2400 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002401 return SemaRef.BuildInstanceMessage(Receiver,
2402 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002403 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002404 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002405 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002406 }
2407
Douglas Gregord51d90d2010-04-26 20:11:03 +00002408 /// \brief Build a new Objective-C ivar reference expression.
2409 ///
2410 /// By default, performs semantic analysis to build the new expression.
2411 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002412 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002413 SourceLocation IvarLoc,
2414 bool IsArrow, bool IsFreeIvar) {
2415 // FIXME: We lose track of the IsFreeIvar bit.
2416 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002417 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002418 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2419 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002420 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002421 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00002422 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00002423 false);
John Wiegley01296292011-04-08 18:41:53 +00002424 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002425 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002426
Douglas Gregord51d90d2010-04-26 20:11:03 +00002427 if (Result.get())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002428 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002429
John Wiegley01296292011-04-08 18:41:53 +00002430 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002431 /*FIXME:*/IvarLoc, IsArrow,
2432 SS, SourceLocation(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00002433 /*FirstQualifierInScope=*/0,
Chad Rosier1dcde962012-08-08 18:46:20 +00002434 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002435 /*TemplateArgs=*/0);
2436 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002437
2438 /// \brief Build a new Objective-C property reference expression.
2439 ///
2440 /// By default, performs semantic analysis to build the new expression.
2441 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002442 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002443 ObjCPropertyDecl *Property,
2444 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002445 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002446 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregor9faee212010-04-26 20:47:02 +00002447 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2448 Sema::LookupMemberName);
2449 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002450 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002451 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002452 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002453 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002454 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002455
Douglas Gregor9faee212010-04-26 20:47:02 +00002456 if (Result.get())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002457 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002458
John Wiegley01296292011-04-08 18:41:53 +00002459 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Chad Rosier1dcde962012-08-08 18:46:20 +00002460 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002461 SS, SourceLocation(),
Douglas Gregor9faee212010-04-26 20:47:02 +00002462 /*FirstQualifierInScope=*/0,
Chad Rosier1dcde962012-08-08 18:46:20 +00002463 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002464 /*TemplateArgs=*/0);
2465 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002466
John McCallb7bd14f2010-12-02 01:19:52 +00002467 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002468 ///
2469 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002470 /// Subclasses may override this routine to provide different behavior.
2471 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2472 ObjCMethodDecl *Getter,
2473 ObjCMethodDecl *Setter,
2474 SourceLocation PropertyLoc) {
2475 // Since these expressions can only be value-dependent, we do not
2476 // need to perform semantic analysis again.
2477 return Owned(
2478 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2479 VK_LValue, OK_ObjCProperty,
2480 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002481 }
2482
Douglas Gregord51d90d2010-04-26 20:11:03 +00002483 /// \brief Build a new Objective-C "isa" expression.
2484 ///
2485 /// By default, performs semantic analysis to build the new expression.
2486 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002487 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002488 SourceLocation OpLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002489 bool IsArrow) {
2490 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002491 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002492 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2493 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002494 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002495 OpLoc,
John McCall48871652010-08-21 09:40:31 +00002496 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002497 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002498 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002499
Douglas Gregord51d90d2010-04-26 20:11:03 +00002500 if (Result.get())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002501 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002502
John Wiegley01296292011-04-08 18:41:53 +00002503 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002504 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002505 SS, SourceLocation(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00002506 /*FirstQualifierInScope=*/0,
Chad Rosier1dcde962012-08-08 18:46:20 +00002507 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002508 /*TemplateArgs=*/0);
2509 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002510
Douglas Gregora16548e2009-08-11 05:31:07 +00002511 /// \brief Build a new shuffle vector expression.
2512 ///
2513 /// By default, performs semantic analysis to build the new expression.
2514 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002515 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002516 MultiExprArg SubExprs,
2517 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002518 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002519 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002520 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2521 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2522 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002523 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002524
Douglas Gregora16548e2009-08-11 05:31:07 +00002525 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002526 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002527 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2528 SemaRef.Context.BuiltinFnTy,
2529 VK_RValue, BuiltinLoc);
2530 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2531 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
2532 CK_BuiltinFnToFnPtr).take();
Mike Stump11289f42009-09-09 15:08:12 +00002533
2534 // Build the CallExpr
John Wiegley01296292011-04-08 18:41:53 +00002535 ExprResult TheCall = SemaRef.Owned(
Eli Friedman34866c72012-08-31 00:14:07 +00002536 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, SubExprs,
Benjamin Kramerc215e762012-08-24 11:54:20 +00002537 Builtin->getCallResultType(),
John McCall7decc9e2010-11-18 06:31:45 +00002538 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley01296292011-04-08 18:41:53 +00002539 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002540
Douglas Gregora16548e2009-08-11 05:31:07 +00002541 // Type-check the __builtin_shufflevector expression.
John Wiegley01296292011-04-08 18:41:53 +00002542 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002543 }
John McCall31f82722010-11-12 08:19:04 +00002544
Hal Finkelc4d7c822013-09-18 03:29:45 +00002545 /// \brief Build a new convert vector expression.
2546 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2547 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2548 SourceLocation RParenLoc) {
2549 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2550 BuiltinLoc, RParenLoc);
2551 }
2552
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002553 /// \brief Build a new template argument pack expansion.
2554 ///
2555 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002556 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002557 /// different behavior.
2558 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002559 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002560 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002561 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002562 case TemplateArgument::Expression: {
2563 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002564 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2565 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002566 if (Result.isInvalid())
2567 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002568
Douglas Gregor98318c22011-01-03 21:37:45 +00002569 return TemplateArgumentLoc(Result.get(), Result.get());
2570 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002571
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002572 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002573 return TemplateArgumentLoc(TemplateArgument(
2574 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002575 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002576 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002577 Pattern.getTemplateNameLoc(),
2578 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002579
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002580 case TemplateArgument::Null:
2581 case TemplateArgument::Integral:
2582 case TemplateArgument::Declaration:
2583 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002584 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002585 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002586 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002587
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002588 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002589 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002590 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002591 EllipsisLoc,
2592 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002593 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2594 Expansion);
2595 break;
2596 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002597
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002598 return TemplateArgumentLoc();
2599 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002600
Douglas Gregor968f23a2011-01-03 19:31:53 +00002601 /// \brief Build a new expression pack expansion.
2602 ///
2603 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002604 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002605 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002606 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002607 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002608 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002609 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002610
2611 /// \brief Build a new atomic operation expression.
2612 ///
2613 /// By default, performs semantic analysis to build the new expression.
2614 /// Subclasses may override this routine to provide different behavior.
2615 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2616 MultiExprArg SubExprs,
2617 QualType RetTy,
2618 AtomicExpr::AtomicOp Op,
2619 SourceLocation RParenLoc) {
2620 // Just create the expression; there is not any interesting semantic
2621 // analysis here because we can't actually build an AtomicExpr until
2622 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00002623 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002624 RParenLoc);
2625 }
2626
John McCall31f82722010-11-12 08:19:04 +00002627private:
Douglas Gregor14454802011-02-25 02:25:35 +00002628 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2629 QualType ObjectType,
2630 NamedDecl *FirstQualifierInScope,
2631 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002632
2633 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2634 QualType ObjectType,
2635 NamedDecl *FirstQualifierInScope,
2636 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00002637
2638 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
2639 NamedDecl *FirstQualifierInScope,
2640 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002641};
Douglas Gregora16548e2009-08-11 05:31:07 +00002642
Douglas Gregorebe10102009-08-20 07:17:43 +00002643template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002644StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002645 if (!S)
2646 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002647
Douglas Gregorebe10102009-08-20 07:17:43 +00002648 switch (S->getStmtClass()) {
2649 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002650
Douglas Gregorebe10102009-08-20 07:17:43 +00002651 // Transform individual statement nodes
2652#define STMT(Node, Parent) \
2653 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002654#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002655#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002656#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002657
Douglas Gregorebe10102009-08-20 07:17:43 +00002658 // Transform expressions by calling TransformExpr.
2659#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002660#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002661#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002662#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002663 {
John McCalldadc5752010-08-24 06:29:42 +00002664 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002665 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002666 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002667
Richard Smith945f8d32013-01-14 22:39:08 +00002668 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00002669 }
Mike Stump11289f42009-09-09 15:08:12 +00002670 }
2671
John McCallc3007a22010-10-26 07:05:15 +00002672 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002673}
Mike Stump11289f42009-09-09 15:08:12 +00002674
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002675template<typename Derived>
2676OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2677 if (!S)
2678 return S;
2679
2680 switch (S->getClauseKind()) {
2681 default: break;
2682 // Transform individual clause nodes
2683#define OPENMP_CLAUSE(Name, Class) \
2684 case OMPC_ ## Name : \
2685 return getDerived().Transform ## Class(cast<Class>(S));
2686#include "clang/Basic/OpenMPKinds.def"
2687 }
2688
2689 return S;
2690}
2691
Mike Stump11289f42009-09-09 15:08:12 +00002692
Douglas Gregore922c772009-08-04 22:27:00 +00002693template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002694ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002695 if (!E)
2696 return SemaRef.Owned(E);
2697
2698 switch (E->getStmtClass()) {
2699 case Stmt::NoStmtClass: break;
2700#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002701#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002702#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002703 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002704#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002705 }
2706
John McCallc3007a22010-10-26 07:05:15 +00002707 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002708}
2709
2710template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00002711ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2712 bool CXXDirectInit) {
2713 // Initializers are instantiated like expressions, except that various outer
2714 // layers are stripped.
2715 if (!Init)
2716 return SemaRef.Owned(Init);
2717
2718 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2719 Init = ExprTemp->getSubExpr();
2720
Richard Smithe6ca4752013-05-30 22:40:16 +00002721 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2722 Init = MTE->GetTemporaryExpr();
2723
Richard Smithd59b8322012-12-19 01:39:02 +00002724 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2725 Init = Binder->getSubExpr();
2726
2727 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2728 Init = ICE->getSubExprAsWritten();
2729
Richard Smithcc1b96d2013-06-12 22:31:48 +00002730 if (CXXStdInitializerListExpr *ILE =
2731 dyn_cast<CXXStdInitializerListExpr>(Init))
2732 return TransformInitializer(ILE->getSubExpr(), CXXDirectInit);
2733
Richard Smith38a549b2012-12-21 08:13:35 +00002734 // If this is not a direct-initializer, we only need to reconstruct
2735 // InitListExprs. Other forms of copy-initialization will be a no-op if
2736 // the initializer is already the right type.
2737 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2738 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2739 return getDerived().TransformExpr(Init);
2740
2741 // Revert value-initialization back to empty parens.
2742 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2743 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002744 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002745 Parens.getEnd());
2746 }
2747
2748 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2749 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002750 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002751 SourceLocation());
2752
2753 // Revert initialization by constructor back to a parenthesized or braced list
2754 // of expressions. Any other form of initializer can just be reused directly.
2755 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00002756 return getDerived().TransformExpr(Init);
2757
2758 SmallVector<Expr*, 8> NewArgs;
2759 bool ArgChanged = false;
2760 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2761 /*IsCall*/true, NewArgs, &ArgChanged))
2762 return ExprError();
2763
2764 // If this was list initialization, revert to list form.
2765 if (Construct->isListInitialization())
2766 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2767 Construct->getLocEnd(),
2768 Construct->getType());
2769
Richard Smithd59b8322012-12-19 01:39:02 +00002770 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00002771 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smithd59b8322012-12-19 01:39:02 +00002772 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2773 Parens.getEnd());
2774}
2775
2776template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00002777bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2778 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002779 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00002780 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002781 bool *ArgChanged) {
2782 for (unsigned I = 0; I != NumInputs; ++I) {
2783 // If requested, drop call arguments that need to be dropped.
2784 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2785 if (ArgChanged)
2786 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002787
Douglas Gregora3efea12011-01-03 19:04:46 +00002788 break;
2789 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002790
Douglas Gregor968f23a2011-01-03 19:31:53 +00002791 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2792 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00002793
Chris Lattner01cf8db2011-07-20 06:58:45 +00002794 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002795 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2796 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00002797
Douglas Gregor968f23a2011-01-03 19:31:53 +00002798 // Determine whether the set of unexpanded parameter packs can and should
2799 // be expanded.
2800 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002801 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00002802 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2803 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002804 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2805 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00002806 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002807 Expand, RetainExpansion,
2808 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002809 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002810
Douglas Gregor968f23a2011-01-03 19:31:53 +00002811 if (!Expand) {
2812 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00002813 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00002814 // expansion.
2815 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2816 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2817 if (OutPattern.isInvalid())
2818 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002819
2820 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002821 Expansion->getEllipsisLoc(),
2822 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002823 if (Out.isInvalid())
2824 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002825
Douglas Gregor968f23a2011-01-03 19:31:53 +00002826 if (ArgChanged)
2827 *ArgChanged = true;
2828 Outputs.push_back(Out.get());
2829 continue;
2830 }
John McCall542e7c62011-07-06 07:30:07 +00002831
2832 // Record right away that the argument was changed. This needs
2833 // to happen even if the array expands to nothing.
2834 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002835
Douglas Gregor968f23a2011-01-03 19:31:53 +00002836 // The transform has determined that we should perform an elementwise
2837 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002838 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002839 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2840 ExprResult Out = getDerived().TransformExpr(Pattern);
2841 if (Out.isInvalid())
2842 return true;
2843
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002844 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002845 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2846 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002847 if (Out.isInvalid())
2848 return true;
2849 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002850
Douglas Gregor968f23a2011-01-03 19:31:53 +00002851 Outputs.push_back(Out.get());
2852 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002853
Douglas Gregor968f23a2011-01-03 19:31:53 +00002854 continue;
2855 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002856
Richard Smithd59b8322012-12-19 01:39:02 +00002857 ExprResult Result =
2858 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
2859 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00002860 if (Result.isInvalid())
2861 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002862
Douglas Gregora3efea12011-01-03 19:04:46 +00002863 if (Result.get() != Inputs[I] && ArgChanged)
2864 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002865
2866 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00002867 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002868
Douglas Gregora3efea12011-01-03 19:04:46 +00002869 return false;
2870}
2871
2872template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00002873NestedNameSpecifierLoc
2874TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2875 NestedNameSpecifierLoc NNS,
2876 QualType ObjectType,
2877 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00002878 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00002879 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00002880 Qualifier = Qualifier.getPrefix())
2881 Qualifiers.push_back(Qualifier);
2882
2883 CXXScopeSpec SS;
2884 while (!Qualifiers.empty()) {
2885 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2886 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00002887
Douglas Gregor14454802011-02-25 02:25:35 +00002888 switch (QNNS->getKind()) {
2889 case NestedNameSpecifier::Identifier:
Chad Rosier1dcde962012-08-08 18:46:20 +00002890 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregor14454802011-02-25 02:25:35 +00002891 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00002892 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00002893 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00002894 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00002895 FirstQualifierInScope, false))
2896 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002897
Douglas Gregor14454802011-02-25 02:25:35 +00002898 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00002899
Douglas Gregor14454802011-02-25 02:25:35 +00002900 case NestedNameSpecifier::Namespace: {
2901 NamespaceDecl *NS
2902 = cast_or_null<NamespaceDecl>(
2903 getDerived().TransformDecl(
2904 Q.getLocalBeginLoc(),
2905 QNNS->getAsNamespace()));
2906 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2907 break;
2908 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002909
Douglas Gregor14454802011-02-25 02:25:35 +00002910 case NestedNameSpecifier::NamespaceAlias: {
2911 NamespaceAliasDecl *Alias
2912 = cast_or_null<NamespaceAliasDecl>(
2913 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2914 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00002915 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00002916 Q.getLocalEndLoc());
2917 break;
2918 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002919
Douglas Gregor14454802011-02-25 02:25:35 +00002920 case NestedNameSpecifier::Global:
2921 // There is no meaningful transformation that one could perform on the
2922 // global scope.
2923 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2924 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00002925
Douglas Gregor14454802011-02-25 02:25:35 +00002926 case NestedNameSpecifier::TypeSpecWithTemplate:
2927 case NestedNameSpecifier::TypeSpec: {
2928 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2929 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00002930
Douglas Gregor14454802011-02-25 02:25:35 +00002931 if (!TL)
2932 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002933
Douglas Gregor14454802011-02-25 02:25:35 +00002934 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00002935 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00002936 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002937 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00002938 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00002939 if (TL.getType()->isEnumeralType())
2940 SemaRef.Diag(TL.getBeginLoc(),
2941 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00002942 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2943 Q.getLocalEndLoc());
2944 break;
2945 }
Richard Trieude756fb2011-05-07 01:36:37 +00002946 // If the nested-name-specifier is an invalid type def, don't emit an
2947 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00002948 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
2949 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002950 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00002951 << TL.getType() << SS.getRange();
2952 }
Douglas Gregor14454802011-02-25 02:25:35 +00002953 return NestedNameSpecifierLoc();
2954 }
Douglas Gregore16af532011-02-28 18:50:33 +00002955 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002956
Douglas Gregore16af532011-02-28 18:50:33 +00002957 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregor14454802011-02-25 02:25:35 +00002958 FirstQualifierInScope = 0;
Douglas Gregore16af532011-02-28 18:50:33 +00002959 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00002960 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002961
Douglas Gregor14454802011-02-25 02:25:35 +00002962 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00002963 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00002964 !getDerived().AlwaysRebuild())
2965 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00002966
2967 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00002968 // nested-name-specifier, do so.
2969 if (SS.location_size() == NNS.getDataLength() &&
2970 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2971 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2972
2973 // Allocate new nested-name-specifier location information.
2974 return SS.getWithLocInContext(SemaRef.Context);
2975}
2976
2977template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002978DeclarationNameInfo
2979TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002980::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002981 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002982 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002983 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002984
2985 switch (Name.getNameKind()) {
2986 case DeclarationName::Identifier:
2987 case DeclarationName::ObjCZeroArgSelector:
2988 case DeclarationName::ObjCOneArgSelector:
2989 case DeclarationName::ObjCMultiArgSelector:
2990 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002991 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002992 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002993 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002994
Douglas Gregorf816bd72009-09-03 22:13:48 +00002995 case DeclarationName::CXXConstructorName:
2996 case DeclarationName::CXXDestructorName:
2997 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002998 TypeSourceInfo *NewTInfo;
2999 CanQualType NewCanTy;
3000 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003001 NewTInfo = getDerived().TransformType(OldTInfo);
3002 if (!NewTInfo)
3003 return DeclarationNameInfo();
3004 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003005 }
3006 else {
3007 NewTInfo = 0;
3008 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003009 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003010 if (NewT.isNull())
3011 return DeclarationNameInfo();
3012 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3013 }
Mike Stump11289f42009-09-09 15:08:12 +00003014
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003015 DeclarationName NewName
3016 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3017 NewCanTy);
3018 DeclarationNameInfo NewNameInfo(NameInfo);
3019 NewNameInfo.setName(NewName);
3020 NewNameInfo.setNamedTypeInfo(NewTInfo);
3021 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003022 }
Mike Stump11289f42009-09-09 15:08:12 +00003023 }
3024
David Blaikie83d382b2011-09-23 05:06:16 +00003025 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003026}
3027
3028template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003029TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003030TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3031 TemplateName Name,
3032 SourceLocation NameLoc,
3033 QualType ObjectType,
3034 NamedDecl *FirstQualifierInScope) {
3035 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3036 TemplateDecl *Template = QTN->getTemplateDecl();
3037 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003038
Douglas Gregor9db53502011-03-02 18:07:45 +00003039 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003040 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003041 Template));
3042 if (!TransTemplate)
3043 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003044
Douglas Gregor9db53502011-03-02 18:07:45 +00003045 if (!getDerived().AlwaysRebuild() &&
3046 SS.getScopeRep() == QTN->getQualifier() &&
3047 TransTemplate == Template)
3048 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003049
Douglas Gregor9db53502011-03-02 18:07:45 +00003050 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3051 TransTemplate);
3052 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003053
Douglas Gregor9db53502011-03-02 18:07:45 +00003054 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3055 if (SS.getScopeRep()) {
3056 // These apply to the scope specifier, not the template.
3057 ObjectType = QualType();
3058 FirstQualifierInScope = 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00003059 }
3060
Douglas Gregor9db53502011-03-02 18:07:45 +00003061 if (!getDerived().AlwaysRebuild() &&
3062 SS.getScopeRep() == DTN->getQualifier() &&
3063 ObjectType.isNull())
3064 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003065
Douglas Gregor9db53502011-03-02 18:07:45 +00003066 if (DTN->isIdentifier()) {
3067 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003068 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003069 NameLoc,
3070 ObjectType,
3071 FirstQualifierInScope);
3072 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003073
Douglas Gregor9db53502011-03-02 18:07:45 +00003074 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3075 ObjectType);
3076 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003077
Douglas Gregor9db53502011-03-02 18:07:45 +00003078 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3079 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003080 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003081 Template));
3082 if (!TransTemplate)
3083 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003084
Douglas Gregor9db53502011-03-02 18:07:45 +00003085 if (!getDerived().AlwaysRebuild() &&
3086 TransTemplate == Template)
3087 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003088
Douglas Gregor9db53502011-03-02 18:07:45 +00003089 return TemplateName(TransTemplate);
3090 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003091
Douglas Gregor9db53502011-03-02 18:07:45 +00003092 if (SubstTemplateTemplateParmPackStorage *SubstPack
3093 = Name.getAsSubstTemplateTemplateParmPack()) {
3094 TemplateTemplateParmDecl *TransParam
3095 = cast_or_null<TemplateTemplateParmDecl>(
3096 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3097 if (!TransParam)
3098 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003099
Douglas Gregor9db53502011-03-02 18:07:45 +00003100 if (!getDerived().AlwaysRebuild() &&
3101 TransParam == SubstPack->getParameterPack())
3102 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003103
3104 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003105 SubstPack->getArgumentPack());
3106 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003107
Douglas Gregor9db53502011-03-02 18:07:45 +00003108 // These should be getting filtered out before they reach the AST.
3109 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003110}
3111
3112template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003113void TreeTransform<Derived>::InventTemplateArgumentLoc(
3114 const TemplateArgument &Arg,
3115 TemplateArgumentLoc &Output) {
3116 SourceLocation Loc = getDerived().getBaseLocation();
3117 switch (Arg.getKind()) {
3118 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003119 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003120 break;
3121
3122 case TemplateArgument::Type:
3123 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003124 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003125
John McCall0ad16662009-10-29 08:12:44 +00003126 break;
3127
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003128 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003129 case TemplateArgument::TemplateExpansion: {
3130 NestedNameSpecifierLocBuilder Builder;
3131 TemplateName Template = Arg.getAsTemplate();
3132 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3133 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3134 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3135 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003136
Douglas Gregor9d802122011-03-02 17:09:35 +00003137 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003138 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003139 Builder.getWithLocInContext(SemaRef.Context),
3140 Loc);
3141 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003142 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003143 Builder.getWithLocInContext(SemaRef.Context),
3144 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003145
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003146 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003147 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003148
John McCall0ad16662009-10-29 08:12:44 +00003149 case TemplateArgument::Expression:
3150 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3151 break;
3152
3153 case TemplateArgument::Declaration:
3154 case TemplateArgument::Integral:
3155 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003156 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003157 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003158 break;
3159 }
3160}
3161
3162template<typename Derived>
3163bool TreeTransform<Derived>::TransformTemplateArgument(
3164 const TemplateArgumentLoc &Input,
3165 TemplateArgumentLoc &Output) {
3166 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003167 switch (Arg.getKind()) {
3168 case TemplateArgument::Null:
3169 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003170 case TemplateArgument::Pack:
3171 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003172 case TemplateArgument::NullPtr:
3173 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003174
Douglas Gregore922c772009-08-04 22:27:00 +00003175 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003176 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00003177 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00003178 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003179
3180 DI = getDerived().TransformType(DI);
3181 if (!DI) return true;
3182
3183 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3184 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003185 }
Mike Stump11289f42009-09-09 15:08:12 +00003186
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003187 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003188 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3189 if (QualifierLoc) {
3190 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3191 if (!QualifierLoc)
3192 return true;
3193 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003194
Douglas Gregordf846d12011-03-02 18:46:51 +00003195 CXXScopeSpec SS;
3196 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003197 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003198 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3199 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003200 if (Template.isNull())
3201 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003202
Douglas Gregor9d802122011-03-02 17:09:35 +00003203 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003204 Input.getTemplateNameLoc());
3205 return false;
3206 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003207
3208 case TemplateArgument::TemplateExpansion:
3209 llvm_unreachable("Caller should expand pack expansions");
3210
Douglas Gregore922c772009-08-04 22:27:00 +00003211 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003212 // Template argument expressions are constant expressions.
Mike Stump11289f42009-09-09 15:08:12 +00003213 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smith764d2fe2011-12-20 02:08:33 +00003214 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003215
John McCall0ad16662009-10-29 08:12:44 +00003216 Expr *InputExpr = Input.getSourceExpression();
3217 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3218
Chris Lattnercdb591a2011-04-25 20:37:58 +00003219 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003220 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003221 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00003222 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00003223 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003224 }
Douglas Gregore922c772009-08-04 22:27:00 +00003225 }
Mike Stump11289f42009-09-09 15:08:12 +00003226
Douglas Gregore922c772009-08-04 22:27:00 +00003227 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003228 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003229}
3230
Douglas Gregorfe921a72010-12-20 23:36:19 +00003231/// \brief Iterator adaptor that invents template argument location information
3232/// for each of the template arguments in its underlying iterator.
3233template<typename Derived, typename InputIterator>
3234class TemplateArgumentLocInventIterator {
3235 TreeTransform<Derived> &Self;
3236 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003237
Douglas Gregorfe921a72010-12-20 23:36:19 +00003238public:
3239 typedef TemplateArgumentLoc value_type;
3240 typedef TemplateArgumentLoc reference;
3241 typedef typename std::iterator_traits<InputIterator>::difference_type
3242 difference_type;
3243 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003244
Douglas Gregorfe921a72010-12-20 23:36:19 +00003245 class pointer {
3246 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003247
Douglas Gregorfe921a72010-12-20 23:36:19 +00003248 public:
3249 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003250
Douglas Gregorfe921a72010-12-20 23:36:19 +00003251 const TemplateArgumentLoc *operator->() const { return &Arg; }
3252 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003253
Douglas Gregorfe921a72010-12-20 23:36:19 +00003254 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003255
Douglas Gregorfe921a72010-12-20 23:36:19 +00003256 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3257 InputIterator Iter)
3258 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003259
Douglas Gregorfe921a72010-12-20 23:36:19 +00003260 TemplateArgumentLocInventIterator &operator++() {
3261 ++Iter;
3262 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003263 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003264
Douglas Gregorfe921a72010-12-20 23:36:19 +00003265 TemplateArgumentLocInventIterator operator++(int) {
3266 TemplateArgumentLocInventIterator Old(*this);
3267 ++(*this);
3268 return Old;
3269 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003270
Douglas Gregorfe921a72010-12-20 23:36:19 +00003271 reference operator*() const {
3272 TemplateArgumentLoc Result;
3273 Self.InventTemplateArgumentLoc(*Iter, Result);
3274 return Result;
3275 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003276
Douglas Gregorfe921a72010-12-20 23:36:19 +00003277 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003278
Douglas Gregorfe921a72010-12-20 23:36:19 +00003279 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3280 const TemplateArgumentLocInventIterator &Y) {
3281 return X.Iter == Y.Iter;
3282 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003283
Douglas Gregorfe921a72010-12-20 23:36:19 +00003284 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3285 const TemplateArgumentLocInventIterator &Y) {
3286 return X.Iter != Y.Iter;
3287 }
3288};
Chad Rosier1dcde962012-08-08 18:46:20 +00003289
Douglas Gregor42cafa82010-12-20 17:42:22 +00003290template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003291template<typename InputIterator>
3292bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3293 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00003294 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003295 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003296 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003297 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003298
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003299 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3300 // Unpack argument packs, which we translate them into separate
3301 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003302 // FIXME: We could do much better if we could guarantee that the
3303 // TemplateArgumentLocInfo for the pack expansion would be usable for
3304 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003305 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003306 TemplateArgument::pack_iterator>
3307 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003308 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003309 In.getArgument().pack_begin()),
3310 PackLocIterator(*this,
3311 In.getArgument().pack_end()),
3312 Outputs))
3313 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003314
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003315 continue;
3316 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003317
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003318 if (In.getArgument().isPackExpansion()) {
3319 // We have a pack expansion, for which we will be substituting into
3320 // the pattern.
3321 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003322 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003323 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003324 = getSema().getTemplateArgumentPackExpansionPattern(
3325 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003326
Chris Lattner01cf8db2011-07-20 06:58:45 +00003327 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003328 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3329 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003330
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003331 // Determine whether the set of unexpanded parameter packs can and should
3332 // be expanded.
3333 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003334 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003335 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003336 if (getDerived().TryExpandParameterPacks(Ellipsis,
3337 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003338 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003339 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003340 RetainExpansion,
3341 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003342 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003343
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003344 if (!Expand) {
3345 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003346 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003347 // expansion.
3348 TemplateArgumentLoc OutPattern;
3349 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3350 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3351 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003352
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003353 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3354 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003355 if (Out.getArgument().isNull())
3356 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003357
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003358 Outputs.addArgument(Out);
3359 continue;
3360 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003361
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003362 // The transform has determined that we should perform an elementwise
3363 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003364 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003365 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3366
3367 if (getDerived().TransformTemplateArgument(Pattern, Out))
3368 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003369
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003370 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003371 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3372 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003373 if (Out.getArgument().isNull())
3374 return true;
3375 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003376
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003377 Outputs.addArgument(Out);
3378 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003379
Douglas Gregor48d24112011-01-10 20:53:55 +00003380 // If we're supposed to retain a pack expansion, do so by temporarily
3381 // forgetting the partially-substituted parameter pack.
3382 if (RetainExpansion) {
3383 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003384
Douglas Gregor48d24112011-01-10 20:53:55 +00003385 if (getDerived().TransformTemplateArgument(Pattern, Out))
3386 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003387
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003388 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3389 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003390 if (Out.getArgument().isNull())
3391 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003392
Douglas Gregor48d24112011-01-10 20:53:55 +00003393 Outputs.addArgument(Out);
3394 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003395
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003396 continue;
3397 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003398
3399 // The simple case:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003400 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003401 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003402
Douglas Gregor42cafa82010-12-20 17:42:22 +00003403 Outputs.addArgument(Out);
3404 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003405
Douglas Gregor42cafa82010-12-20 17:42:22 +00003406 return false;
3407
3408}
3409
Douglas Gregord6ff3322009-08-04 16:50:30 +00003410//===----------------------------------------------------------------------===//
3411// Type transformation
3412//===----------------------------------------------------------------------===//
3413
3414template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003415QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003416 if (getDerived().AlreadyTransformed(T))
3417 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003418
John McCall550e0c22009-10-21 00:40:46 +00003419 // Temporary workaround. All of these transformations should
3420 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003421 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3422 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003423
John McCall31f82722010-11-12 08:19:04 +00003424 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003425
John McCall550e0c22009-10-21 00:40:46 +00003426 if (!NewDI)
3427 return QualType();
3428
3429 return NewDI->getType();
3430}
3431
3432template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003433TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003434 // Refine the base location to the type's location.
3435 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3436 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003437 if (getDerived().AlreadyTransformed(DI->getType()))
3438 return DI;
3439
3440 TypeLocBuilder TLB;
3441
3442 TypeLoc TL = DI->getTypeLoc();
3443 TLB.reserve(TL.getFullDataSize());
3444
John McCall31f82722010-11-12 08:19:04 +00003445 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003446 if (Result.isNull())
3447 return 0;
3448
John McCallbcd03502009-12-07 02:54:59 +00003449 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003450}
3451
3452template<typename Derived>
3453QualType
John McCall31f82722010-11-12 08:19:04 +00003454TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003455 switch (T.getTypeLocClass()) {
3456#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003457#define TYPELOC(CLASS, PARENT) \
3458 case TypeLoc::CLASS: \
3459 return getDerived().Transform##CLASS##Type(TLB, \
3460 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003461#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003462 }
Mike Stump11289f42009-09-09 15:08:12 +00003463
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003464 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003465}
3466
3467/// FIXME: By default, this routine adds type qualifiers only to types
3468/// that can have qualifiers, and silently suppresses those qualifiers
3469/// that are not permitted (e.g., qualifiers on reference or function
3470/// types). This is the right thing for template instantiation, but
3471/// probably not for other clients.
3472template<typename Derived>
3473QualType
3474TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003475 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003476 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003477
John McCall31f82722010-11-12 08:19:04 +00003478 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003479 if (Result.isNull())
3480 return QualType();
3481
3482 // Silently suppress qualifiers if the result type can't be qualified.
3483 // FIXME: this is the right thing for template instantiation, but
3484 // probably not for other clients.
3485 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003486 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003487
John McCall31168b02011-06-15 23:02:42 +00003488 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003489 // resulting type.
3490 if (Quals.hasObjCLifetime()) {
3491 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3492 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003493 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003494 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003495 // A lifetime qualifier applied to a substituted template parameter
3496 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003497 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003498 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003499 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3500 QualType Replacement = SubstTypeParam->getReplacementType();
3501 Qualifiers Qs = Replacement.getQualifiers();
3502 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003503 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003504 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3505 Qs);
3506 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003507 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003508 Replacement);
3509 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003510 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3511 // 'auto' types behave the same way as template parameters.
3512 QualType Deduced = AutoTy->getDeducedType();
3513 Qualifiers Qs = Deduced.getQualifiers();
3514 Qs.removeObjCLifetime();
3515 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3516 Qs);
Faisal Vali2b391ab2013-09-26 19:54:12 +00003517 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3518 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003519 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003520 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003521 // Otherwise, complain about the addition of a qualifier to an
3522 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003523 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003524 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003525 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003526
Douglas Gregore46db902011-06-17 22:11:49 +00003527 Quals.removeObjCLifetime();
3528 }
3529 }
3530 }
John McCallcb0f89a2010-06-05 06:41:15 +00003531 if (!Quals.empty()) {
3532 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003533 // BuildQualifiedType might not add qualifiers if they are invalid.
3534 if (Result.hasLocalQualifiers())
3535 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003536 // No location information to preserve.
3537 }
John McCall550e0c22009-10-21 00:40:46 +00003538
3539 return Result;
3540}
3541
Douglas Gregor14454802011-02-25 02:25:35 +00003542template<typename Derived>
3543TypeLoc
3544TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3545 QualType ObjectType,
3546 NamedDecl *UnqualLookup,
3547 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003548 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00003549 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00003550
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003551 TypeSourceInfo *TSI =
3552 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3553 if (TSI)
3554 return TSI->getTypeLoc();
3555 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00003556}
3557
Douglas Gregor579c15f2011-03-02 18:32:08 +00003558template<typename Derived>
3559TypeSourceInfo *
3560TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3561 QualType ObjectType,
3562 NamedDecl *UnqualLookup,
3563 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003564 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00003565 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00003566
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003567 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
3568 UnqualLookup, SS);
3569}
3570
3571template <typename Derived>
3572TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
3573 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
3574 CXXScopeSpec &SS) {
3575 QualType T = TL.getType();
3576 assert(!getDerived().AlreadyTransformed(T));
3577
Douglas Gregor579c15f2011-03-02 18:32:08 +00003578 TypeLocBuilder TLB;
3579 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00003580
Douglas Gregor579c15f2011-03-02 18:32:08 +00003581 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003582 TemplateSpecializationTypeLoc SpecTL =
3583 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003584
Douglas Gregor579c15f2011-03-02 18:32:08 +00003585 TemplateName Template
3586 = getDerived().TransformTemplateName(SS,
3587 SpecTL.getTypePtr()->getTemplateName(),
3588 SpecTL.getTemplateNameLoc(),
3589 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00003590 if (Template.isNull())
Douglas Gregor579c15f2011-03-02 18:32:08 +00003591 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00003592
3593 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003594 Template);
3595 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003596 DependentTemplateSpecializationTypeLoc SpecTL =
3597 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003598
Douglas Gregor579c15f2011-03-02 18:32:08 +00003599 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00003600 = getDerived().RebuildTemplateName(SS,
3601 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00003602 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00003603 ObjectType, UnqualLookup);
3604 if (Template.isNull())
3605 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00003606
3607 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003608 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003609 Template,
3610 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003611 } else {
3612 // Nothing special needs to be done for these.
3613 Result = getDerived().TransformType(TLB, TL);
3614 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003615
3616 if (Result.isNull())
Douglas Gregor579c15f2011-03-02 18:32:08 +00003617 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00003618
Douglas Gregor579c15f2011-03-02 18:32:08 +00003619 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3620}
3621
John McCall550e0c22009-10-21 00:40:46 +00003622template <class TyLoc> static inline
3623QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3624 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3625 NewT.setNameLoc(T.getNameLoc());
3626 return T.getType();
3627}
3628
John McCall550e0c22009-10-21 00:40:46 +00003629template<typename Derived>
3630QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003631 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003632 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3633 NewT.setBuiltinLoc(T.getBuiltinLoc());
3634 if (T.needsExtraLocalData())
3635 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3636 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003637}
Mike Stump11289f42009-09-09 15:08:12 +00003638
Douglas Gregord6ff3322009-08-04 16:50:30 +00003639template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003640QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003641 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003642 // FIXME: recurse?
3643 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003644}
Mike Stump11289f42009-09-09 15:08:12 +00003645
Reid Kleckner0503a872013-12-05 01:23:43 +00003646template <typename Derived>
3647QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
3648 AdjustedTypeLoc TL) {
3649 // Adjustments applied during transformation are handled elsewhere.
3650 return getDerived().TransformType(TLB, TL.getOriginalLoc());
3651}
3652
Douglas Gregord6ff3322009-08-04 16:50:30 +00003653template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00003654QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3655 DecayedTypeLoc TL) {
3656 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3657 if (OriginalType.isNull())
3658 return QualType();
3659
3660 QualType Result = TL.getType();
3661 if (getDerived().AlwaysRebuild() ||
3662 OriginalType != TL.getOriginalLoc().getType())
3663 Result = SemaRef.Context.getDecayedType(OriginalType);
3664 TLB.push<DecayedTypeLoc>(Result);
3665 // Nothing to set for DecayedTypeLoc.
3666 return Result;
3667}
3668
3669template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003670QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003671 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003672 QualType PointeeType
3673 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003674 if (PointeeType.isNull())
3675 return QualType();
3676
3677 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003678 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003679 // A dependent pointer type 'T *' has is being transformed such
3680 // that an Objective-C class type is being replaced for 'T'. The
3681 // resulting pointer type is an ObjCObjectPointerType, not a
3682 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003683 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00003684
John McCall8b07ec22010-05-15 11:32:37 +00003685 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3686 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003687 return Result;
3688 }
John McCall31f82722010-11-12 08:19:04 +00003689
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003690 if (getDerived().AlwaysRebuild() ||
3691 PointeeType != TL.getPointeeLoc().getType()) {
3692 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3693 if (Result.isNull())
3694 return QualType();
3695 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003696
John McCall31168b02011-06-15 23:02:42 +00003697 // Objective-C ARC can add lifetime qualifiers to the type that we're
3698 // pointing to.
3699 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00003700
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003701 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3702 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00003703 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003704}
Mike Stump11289f42009-09-09 15:08:12 +00003705
3706template<typename Derived>
3707QualType
John McCall550e0c22009-10-21 00:40:46 +00003708TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003709 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003710 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00003711 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3712 if (PointeeType.isNull())
3713 return QualType();
3714
3715 QualType Result = TL.getType();
3716 if (getDerived().AlwaysRebuild() ||
3717 PointeeType != TL.getPointeeLoc().getType()) {
3718 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003719 TL.getSigilLoc());
3720 if (Result.isNull())
3721 return QualType();
3722 }
3723
Douglas Gregor049211a2010-04-22 16:50:51 +00003724 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003725 NewT.setSigilLoc(TL.getSigilLoc());
3726 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003727}
3728
John McCall70dd5f62009-10-30 00:06:24 +00003729/// Transforms a reference type. Note that somewhat paradoxically we
3730/// don't care whether the type itself is an l-value type or an r-value
3731/// type; we only care if the type was *written* as an l-value type
3732/// or an r-value type.
3733template<typename Derived>
3734QualType
3735TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003736 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003737 const ReferenceType *T = TL.getTypePtr();
3738
3739 // Note that this works with the pointee-as-written.
3740 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3741 if (PointeeType.isNull())
3742 return QualType();
3743
3744 QualType Result = TL.getType();
3745 if (getDerived().AlwaysRebuild() ||
3746 PointeeType != T->getPointeeTypeAsWritten()) {
3747 Result = getDerived().RebuildReferenceType(PointeeType,
3748 T->isSpelledAsLValue(),
3749 TL.getSigilLoc());
3750 if (Result.isNull())
3751 return QualType();
3752 }
3753
John McCall31168b02011-06-15 23:02:42 +00003754 // Objective-C ARC can add lifetime qualifiers to the type that we're
3755 // referring to.
3756 TLB.TypeWasModifiedSafely(
3757 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3758
John McCall70dd5f62009-10-30 00:06:24 +00003759 // r-value references can be rebuilt as l-value references.
3760 ReferenceTypeLoc NewTL;
3761 if (isa<LValueReferenceType>(Result))
3762 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3763 else
3764 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3765 NewTL.setSigilLoc(TL.getSigilLoc());
3766
3767 return Result;
3768}
3769
Mike Stump11289f42009-09-09 15:08:12 +00003770template<typename Derived>
3771QualType
John McCall550e0c22009-10-21 00:40:46 +00003772TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003773 LValueReferenceTypeLoc TL) {
3774 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003775}
3776
Mike Stump11289f42009-09-09 15:08:12 +00003777template<typename Derived>
3778QualType
John McCall550e0c22009-10-21 00:40:46 +00003779TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003780 RValueReferenceTypeLoc TL) {
3781 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003782}
Mike Stump11289f42009-09-09 15:08:12 +00003783
Douglas Gregord6ff3322009-08-04 16:50:30 +00003784template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003785QualType
John McCall550e0c22009-10-21 00:40:46 +00003786TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003787 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003788 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003789 if (PointeeType.isNull())
3790 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003791
Abramo Bagnara509357842011-03-05 14:42:21 +00003792 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3793 TypeSourceInfo* NewClsTInfo = 0;
3794 if (OldClsTInfo) {
3795 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3796 if (!NewClsTInfo)
3797 return QualType();
3798 }
3799
3800 const MemberPointerType *T = TL.getTypePtr();
3801 QualType OldClsType = QualType(T->getClass(), 0);
3802 QualType NewClsType;
3803 if (NewClsTInfo)
3804 NewClsType = NewClsTInfo->getType();
3805 else {
3806 NewClsType = getDerived().TransformType(OldClsType);
3807 if (NewClsType.isNull())
3808 return QualType();
3809 }
Mike Stump11289f42009-09-09 15:08:12 +00003810
John McCall550e0c22009-10-21 00:40:46 +00003811 QualType Result = TL.getType();
3812 if (getDerived().AlwaysRebuild() ||
3813 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00003814 NewClsType != OldClsType) {
3815 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00003816 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003817 if (Result.isNull())
3818 return QualType();
3819 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003820
Reid Kleckner0503a872013-12-05 01:23:43 +00003821 // If we had to adjust the pointee type when building a member pointer, make
3822 // sure to push TypeLoc info for it.
3823 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
3824 if (MPT && PointeeType != MPT->getPointeeType()) {
3825 assert(isa<AdjustedType>(MPT->getPointeeType()));
3826 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
3827 }
3828
John McCall550e0c22009-10-21 00:40:46 +00003829 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3830 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00003831 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00003832
3833 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003834}
3835
Mike Stump11289f42009-09-09 15:08:12 +00003836template<typename Derived>
3837QualType
John McCall550e0c22009-10-21 00:40:46 +00003838TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003839 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003840 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003841 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003842 if (ElementType.isNull())
3843 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003844
John McCall550e0c22009-10-21 00:40:46 +00003845 QualType Result = TL.getType();
3846 if (getDerived().AlwaysRebuild() ||
3847 ElementType != T->getElementType()) {
3848 Result = getDerived().RebuildConstantArrayType(ElementType,
3849 T->getSizeModifier(),
3850 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003851 T->getIndexTypeCVRQualifiers(),
3852 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003853 if (Result.isNull())
3854 return QualType();
3855 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00003856
3857 // We might have either a ConstantArrayType or a VariableArrayType now:
3858 // a ConstantArrayType is allowed to have an element type which is a
3859 // VariableArrayType if the type is dependent. Fortunately, all array
3860 // types have the same location layout.
3861 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00003862 NewTL.setLBracketLoc(TL.getLBracketLoc());
3863 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003864
John McCall550e0c22009-10-21 00:40:46 +00003865 Expr *Size = TL.getSizeExpr();
3866 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003867 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3868 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00003869 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanc6237c62012-02-29 03:16:56 +00003870 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCall550e0c22009-10-21 00:40:46 +00003871 }
3872 NewTL.setSizeExpr(Size);
3873
3874 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003875}
Mike Stump11289f42009-09-09 15:08:12 +00003876
Douglas Gregord6ff3322009-08-04 16:50:30 +00003877template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003878QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003879 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003880 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003881 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003882 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003883 if (ElementType.isNull())
3884 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003885
John McCall550e0c22009-10-21 00:40:46 +00003886 QualType Result = TL.getType();
3887 if (getDerived().AlwaysRebuild() ||
3888 ElementType != T->getElementType()) {
3889 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003890 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003891 T->getIndexTypeCVRQualifiers(),
3892 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003893 if (Result.isNull())
3894 return QualType();
3895 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003896
John McCall550e0c22009-10-21 00:40:46 +00003897 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3898 NewTL.setLBracketLoc(TL.getLBracketLoc());
3899 NewTL.setRBracketLoc(TL.getRBracketLoc());
3900 NewTL.setSizeExpr(0);
3901
3902 return Result;
3903}
3904
3905template<typename Derived>
3906QualType
3907TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003908 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003909 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003910 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3911 if (ElementType.isNull())
3912 return QualType();
3913
John McCalldadc5752010-08-24 06:29:42 +00003914 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003915 = getDerived().TransformExpr(T->getSizeExpr());
3916 if (SizeResult.isInvalid())
3917 return QualType();
3918
John McCallb268a282010-08-23 23:25:46 +00003919 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003920
3921 QualType Result = TL.getType();
3922 if (getDerived().AlwaysRebuild() ||
3923 ElementType != T->getElementType() ||
3924 Size != T->getSizeExpr()) {
3925 Result = getDerived().RebuildVariableArrayType(ElementType,
3926 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003927 Size,
John McCall550e0c22009-10-21 00:40:46 +00003928 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003929 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003930 if (Result.isNull())
3931 return QualType();
3932 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003933
John McCall550e0c22009-10-21 00:40:46 +00003934 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3935 NewTL.setLBracketLoc(TL.getLBracketLoc());
3936 NewTL.setRBracketLoc(TL.getRBracketLoc());
3937 NewTL.setSizeExpr(Size);
3938
3939 return Result;
3940}
3941
3942template<typename Derived>
3943QualType
3944TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003945 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003946 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003947 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3948 if (ElementType.isNull())
3949 return QualType();
3950
Richard Smith764d2fe2011-12-20 02:08:33 +00003951 // Array bounds are constant expressions.
3952 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3953 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00003954
John McCall33ddac02011-01-19 10:06:00 +00003955 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3956 Expr *origSize = TL.getSizeExpr();
3957 if (!origSize) origSize = T->getSizeExpr();
3958
3959 ExprResult sizeResult
3960 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003961 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00003962 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00003963 return QualType();
3964
John McCall33ddac02011-01-19 10:06:00 +00003965 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00003966
3967 QualType Result = TL.getType();
3968 if (getDerived().AlwaysRebuild() ||
3969 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00003970 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00003971 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3972 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00003973 size,
John McCall550e0c22009-10-21 00:40:46 +00003974 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003975 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003976 if (Result.isNull())
3977 return QualType();
3978 }
John McCall550e0c22009-10-21 00:40:46 +00003979
3980 // We might have any sort of array type now, but fortunately they
3981 // all have the same location layout.
3982 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3983 NewTL.setLBracketLoc(TL.getLBracketLoc());
3984 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00003985 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00003986
3987 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003988}
Mike Stump11289f42009-09-09 15:08:12 +00003989
3990template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003991QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00003992 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003993 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003994 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003995
3996 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00003997 QualType ElementType = getDerived().TransformType(T->getElementType());
3998 if (ElementType.isNull())
3999 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004000
Richard Smith764d2fe2011-12-20 02:08:33 +00004001 // Vector sizes are constant expressions.
4002 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4003 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004004
John McCalldadc5752010-08-24 06:29:42 +00004005 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004006 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004007 if (Size.isInvalid())
4008 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004009
John McCall550e0c22009-10-21 00:40:46 +00004010 QualType Result = TL.getType();
4011 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004012 ElementType != T->getElementType() ||
4013 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004014 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00004015 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004016 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004017 if (Result.isNull())
4018 return QualType();
4019 }
John McCall550e0c22009-10-21 00:40:46 +00004020
4021 // Result might be dependent or not.
4022 if (isa<DependentSizedExtVectorType>(Result)) {
4023 DependentSizedExtVectorTypeLoc NewTL
4024 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4025 NewTL.setNameLoc(TL.getNameLoc());
4026 } else {
4027 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4028 NewTL.setNameLoc(TL.getNameLoc());
4029 }
4030
4031 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004032}
Mike Stump11289f42009-09-09 15:08:12 +00004033
4034template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004035QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004036 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004037 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004038 QualType ElementType = getDerived().TransformType(T->getElementType());
4039 if (ElementType.isNull())
4040 return QualType();
4041
John McCall550e0c22009-10-21 00:40:46 +00004042 QualType Result = TL.getType();
4043 if (getDerived().AlwaysRebuild() ||
4044 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004045 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004046 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004047 if (Result.isNull())
4048 return QualType();
4049 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004050
John McCall550e0c22009-10-21 00:40:46 +00004051 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4052 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004053
John McCall550e0c22009-10-21 00:40:46 +00004054 return Result;
4055}
4056
4057template<typename Derived>
4058QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004059 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004060 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004061 QualType ElementType = getDerived().TransformType(T->getElementType());
4062 if (ElementType.isNull())
4063 return QualType();
4064
4065 QualType Result = TL.getType();
4066 if (getDerived().AlwaysRebuild() ||
4067 ElementType != T->getElementType()) {
4068 Result = getDerived().RebuildExtVectorType(ElementType,
4069 T->getNumElements(),
4070 /*FIXME*/ SourceLocation());
4071 if (Result.isNull())
4072 return QualType();
4073 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004074
John McCall550e0c22009-10-21 00:40:46 +00004075 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4076 NewTL.setNameLoc(TL.getNameLoc());
4077
4078 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004079}
Mike Stump11289f42009-09-09 15:08:12 +00004080
David Blaikie05785d12013-02-20 22:23:23 +00004081template <typename Derived>
4082ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4083 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4084 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004085 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor715e4612011-01-14 22:40:04 +00004086 TypeSourceInfo *NewDI = 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00004087
Douglas Gregor715e4612011-01-14 22:40:04 +00004088 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004089 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004090 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004091 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004092 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004093
Douglas Gregor715e4612011-01-14 22:40:04 +00004094 TypeLocBuilder TLB;
4095 TypeLoc NewTL = OldDI->getTypeLoc();
4096 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004097
4098 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004099 OldExpansionTL.getPatternLoc());
4100 if (Result.isNull())
4101 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00004102
4103 Result = RebuildPackExpansionType(Result,
4104 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004105 OldExpansionTL.getEllipsisLoc(),
4106 NumExpansions);
4107 if (Result.isNull())
4108 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00004109
Douglas Gregor715e4612011-01-14 22:40:04 +00004110 PackExpansionTypeLoc NewExpansionTL
4111 = TLB.push<PackExpansionTypeLoc>(Result);
4112 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4113 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4114 } else
4115 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004116 if (!NewDI)
4117 return 0;
4118
John McCall8fb0d9d2011-05-01 22:35:37 +00004119 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004120 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004121
4122 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4123 OldParm->getDeclContext(),
4124 OldParm->getInnerLocStart(),
4125 OldParm->getLocation(),
4126 OldParm->getIdentifier(),
4127 NewDI->getType(),
4128 NewDI,
4129 OldParm->getStorageClass(),
John McCall8fb0d9d2011-05-01 22:35:37 +00004130 /* DefArg */ NULL);
4131 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4132 OldParm->getFunctionScopeIndex() + indexAdjustment);
4133 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004134}
4135
4136template<typename Derived>
4137bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004138 TransformFunctionTypeParams(SourceLocation Loc,
4139 ParmVarDecl **Params, unsigned NumParams,
4140 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004141 SmallVectorImpl<QualType> &OutParamTypes,
4142 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004143 int indexAdjustment = 0;
4144
Douglas Gregordd472162011-01-07 00:20:55 +00004145 for (unsigned i = 0; i != NumParams; ++i) {
4146 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004147 assert(OldParm->getFunctionScopeIndex() == i);
4148
David Blaikie05785d12013-02-20 22:23:23 +00004149 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004150 ParmVarDecl *NewParm = 0;
Douglas Gregor5499af42011-01-05 23:12:31 +00004151 if (OldParm->isParameterPack()) {
4152 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004153 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004154
Douglas Gregor5499af42011-01-05 23:12:31 +00004155 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004156 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004157 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004158 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4159 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004160 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4161
Douglas Gregor5499af42011-01-05 23:12:31 +00004162 // Determine whether we should expand the parameter packs.
4163 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004164 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004165 Optional<unsigned> OrigNumExpansions =
4166 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004167 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004168 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4169 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004170 Unexpanded,
4171 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004172 RetainExpansion,
4173 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004174 return true;
4175 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004176
Douglas Gregor5499af42011-01-05 23:12:31 +00004177 if (ShouldExpand) {
4178 // Expand the function parameter pack into multiple, separate
4179 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004180 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004181 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004182 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004183 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004184 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004185 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004186 OrigNumExpansions,
4187 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004188 if (!NewParm)
4189 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004190
Douglas Gregordd472162011-01-07 00:20:55 +00004191 OutParamTypes.push_back(NewParm->getType());
4192 if (PVars)
4193 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004194 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004195
4196 // If we're supposed to retain a pack expansion, do so by temporarily
4197 // forgetting the partially-substituted parameter pack.
4198 if (RetainExpansion) {
4199 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004200 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004201 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004202 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004203 OrigNumExpansions,
4204 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004205 if (!NewParm)
4206 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004207
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004208 OutParamTypes.push_back(NewParm->getType());
4209 if (PVars)
4210 PVars->push_back(NewParm);
4211 }
4212
John McCall8fb0d9d2011-05-01 22:35:37 +00004213 // The next parameter should have the same adjustment as the
4214 // last thing we pushed, but we post-incremented indexAdjustment
4215 // on every push. Also, if we push nothing, the adjustment should
4216 // go down by one.
4217 indexAdjustment--;
4218
Douglas Gregor5499af42011-01-05 23:12:31 +00004219 // We're done with the pack expansion.
4220 continue;
4221 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004222
4223 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004224 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004225 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4226 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004227 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004228 NumExpansions,
4229 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004230 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004231 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004232 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004233 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004234
John McCall58f10c32010-03-11 09:03:00 +00004235 if (!NewParm)
4236 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004237
Douglas Gregordd472162011-01-07 00:20:55 +00004238 OutParamTypes.push_back(NewParm->getType());
4239 if (PVars)
4240 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004241 continue;
4242 }
John McCall58f10c32010-03-11 09:03:00 +00004243
4244 // Deal with the possibility that we don't have a parameter
4245 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004246 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004247 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004248 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004249 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004250 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004251 = dyn_cast<PackExpansionType>(OldType)) {
4252 // We have a function parameter pack that may need to be expanded.
4253 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004254 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004255 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004256
Douglas Gregor5499af42011-01-05 23:12:31 +00004257 // Determine whether we should expand the parameter packs.
4258 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004259 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004260 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004261 Unexpanded,
4262 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004263 RetainExpansion,
4264 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004265 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004266 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004267
Douglas Gregor5499af42011-01-05 23:12:31 +00004268 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004269 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004270 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004271 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004272 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4273 QualType NewType = getDerived().TransformType(Pattern);
4274 if (NewType.isNull())
4275 return true;
John McCall58f10c32010-03-11 09:03:00 +00004276
Douglas Gregordd472162011-01-07 00:20:55 +00004277 OutParamTypes.push_back(NewType);
4278 if (PVars)
4279 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00004280 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004281
Douglas Gregor5499af42011-01-05 23:12:31 +00004282 // We're done with the pack expansion.
4283 continue;
4284 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004285
Douglas Gregor48d24112011-01-10 20:53:55 +00004286 // If we're supposed to retain a pack expansion, do so by temporarily
4287 // forgetting the partially-substituted parameter pack.
4288 if (RetainExpansion) {
4289 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4290 QualType NewType = getDerived().TransformType(Pattern);
4291 if (NewType.isNull())
4292 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004293
Douglas Gregor48d24112011-01-10 20:53:55 +00004294 OutParamTypes.push_back(NewType);
4295 if (PVars)
4296 PVars->push_back(0);
4297 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004298
Chad Rosier1dcde962012-08-08 18:46:20 +00004299 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004300 // expansion.
4301 OldType = Expansion->getPattern();
4302 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004303 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4304 NewType = getDerived().TransformType(OldType);
4305 } else {
4306 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004307 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004308
Douglas Gregor5499af42011-01-05 23:12:31 +00004309 if (NewType.isNull())
4310 return true;
4311
4312 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004313 NewType = getSema().Context.getPackExpansionType(NewType,
4314 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004315
Douglas Gregordd472162011-01-07 00:20:55 +00004316 OutParamTypes.push_back(NewType);
4317 if (PVars)
4318 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00004319 }
4320
John McCall8fb0d9d2011-05-01 22:35:37 +00004321#ifndef NDEBUG
4322 if (PVars) {
4323 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4324 if (ParmVarDecl *parm = (*PVars)[i])
4325 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004326 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004327#endif
4328
4329 return false;
4330}
John McCall58f10c32010-03-11 09:03:00 +00004331
4332template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004333QualType
John McCall550e0c22009-10-21 00:40:46 +00004334TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004335 FunctionProtoTypeLoc TL) {
Douglas Gregor3024f072012-04-16 07:05:22 +00004336 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4337}
4338
4339template<typename Derived>
4340QualType
4341TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4342 FunctionProtoTypeLoc TL,
4343 CXXRecordDecl *ThisContext,
4344 unsigned ThisTypeQuals) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004345 // Transform the parameters and return type.
4346 //
Richard Smithf623c962012-04-17 00:58:00 +00004347 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004348 // When the function has a trailing return type, we instantiate the
4349 // parameters before the return type, since the return type can then refer
4350 // to the parameters themselves (via decltype, sizeof, etc.).
4351 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004352 SmallVector<QualType, 4> ParamTypes;
4353 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004354 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004355
Douglas Gregor7fb25412010-10-01 18:44:50 +00004356 QualType ResultType;
4357
Richard Smith1226c602012-08-14 22:51:13 +00004358 if (T->hasTrailingReturn()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004359 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregordd472162011-01-07 00:20:55 +00004360 TL.getParmArray(),
4361 TL.getNumArgs(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004362 TL.getTypePtr()->arg_type_begin(),
Douglas Gregordd472162011-01-07 00:20:55 +00004363 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004364 return QualType();
4365
Douglas Gregor3024f072012-04-16 07:05:22 +00004366 {
4367 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004368 // If a declaration declares a member function or member function
4369 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004370 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004371 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004372 // declarator.
4373 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004374
Douglas Gregor3024f072012-04-16 07:05:22 +00004375 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4376 if (ResultType.isNull())
4377 return QualType();
4378 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004379 }
4380 else {
4381 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4382 if (ResultType.isNull())
4383 return QualType();
4384
Chad Rosier1dcde962012-08-08 18:46:20 +00004385 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregordd472162011-01-07 00:20:55 +00004386 TL.getParmArray(),
4387 TL.getNumArgs(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004388 TL.getTypePtr()->arg_type_begin(),
Douglas Gregordd472162011-01-07 00:20:55 +00004389 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004390 return QualType();
4391 }
4392
Richard Smithf623c962012-04-17 00:58:00 +00004393 // FIXME: Need to transform the exception-specification too.
4394
John McCall550e0c22009-10-21 00:40:46 +00004395 QualType Result = TL.getType();
4396 if (getDerived().AlwaysRebuild() ||
4397 ResultType != T->getResultType() ||
Douglas Gregor9f627df2011-01-07 19:27:47 +00004398 T->getNumArgs() != ParamTypes.size() ||
John McCall550e0c22009-10-21 00:40:46 +00004399 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
Jordan Rose5c382722013-03-08 21:51:21 +00004400 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00004401 T->getExtProtoInfo());
John McCall550e0c22009-10-21 00:40:46 +00004402 if (Result.isNull())
4403 return QualType();
4404 }
Mike Stump11289f42009-09-09 15:08:12 +00004405
John McCall550e0c22009-10-21 00:40:46 +00004406 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004407 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004408 NewTL.setLParenLoc(TL.getLParenLoc());
4409 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004410 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004411 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4412 NewTL.setArg(i, ParamDecls[i]);
4413
4414 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004415}
Mike Stump11289f42009-09-09 15:08:12 +00004416
Douglas Gregord6ff3322009-08-04 16:50:30 +00004417template<typename Derived>
4418QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004419 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004420 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004421 const FunctionNoProtoType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004422 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4423 if (ResultType.isNull())
4424 return QualType();
4425
4426 QualType Result = TL.getType();
4427 if (getDerived().AlwaysRebuild() ||
4428 ResultType != T->getResultType())
4429 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4430
4431 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004432 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004433 NewTL.setLParenLoc(TL.getLParenLoc());
4434 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004435 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004436
4437 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004438}
Mike Stump11289f42009-09-09 15:08:12 +00004439
John McCallb96ec562009-12-04 22:46:56 +00004440template<typename Derived> QualType
4441TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004442 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004443 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004444 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004445 if (!D)
4446 return QualType();
4447
4448 QualType Result = TL.getType();
4449 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4450 Result = getDerived().RebuildUnresolvedUsingType(D);
4451 if (Result.isNull())
4452 return QualType();
4453 }
4454
4455 // We might get an arbitrary type spec type back. We should at
4456 // least always get a type spec type, though.
4457 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4458 NewTL.setNameLoc(TL.getNameLoc());
4459
4460 return Result;
4461}
4462
Douglas Gregord6ff3322009-08-04 16:50:30 +00004463template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004464QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004465 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004466 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004467 TypedefNameDecl *Typedef
4468 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4469 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004470 if (!Typedef)
4471 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004472
John McCall550e0c22009-10-21 00:40:46 +00004473 QualType Result = TL.getType();
4474 if (getDerived().AlwaysRebuild() ||
4475 Typedef != T->getDecl()) {
4476 Result = getDerived().RebuildTypedefType(Typedef);
4477 if (Result.isNull())
4478 return QualType();
4479 }
Mike Stump11289f42009-09-09 15:08:12 +00004480
John McCall550e0c22009-10-21 00:40:46 +00004481 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4482 NewTL.setNameLoc(TL.getNameLoc());
4483
4484 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004485}
Mike Stump11289f42009-09-09 15:08:12 +00004486
Douglas Gregord6ff3322009-08-04 16:50:30 +00004487template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004488QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004489 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004490 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00004491 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4492 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00004493
John McCalldadc5752010-08-24 06:29:42 +00004494 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004495 if (E.isInvalid())
4496 return QualType();
4497
Eli Friedmane4f22df2012-02-29 04:03:55 +00004498 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4499 if (E.isInvalid())
4500 return QualType();
4501
John McCall550e0c22009-10-21 00:40:46 +00004502 QualType Result = TL.getType();
4503 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004504 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004505 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004506 if (Result.isNull())
4507 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004508 }
John McCall550e0c22009-10-21 00:40:46 +00004509 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004510
John McCall550e0c22009-10-21 00:40:46 +00004511 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004512 NewTL.setTypeofLoc(TL.getTypeofLoc());
4513 NewTL.setLParenLoc(TL.getLParenLoc());
4514 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004515
4516 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004517}
Mike Stump11289f42009-09-09 15:08:12 +00004518
4519template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004520QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004521 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004522 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4523 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4524 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004525 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004526
John McCall550e0c22009-10-21 00:40:46 +00004527 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004528 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4529 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004530 if (Result.isNull())
4531 return QualType();
4532 }
Mike Stump11289f42009-09-09 15:08:12 +00004533
John McCall550e0c22009-10-21 00:40:46 +00004534 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004535 NewTL.setTypeofLoc(TL.getTypeofLoc());
4536 NewTL.setLParenLoc(TL.getLParenLoc());
4537 NewTL.setRParenLoc(TL.getRParenLoc());
4538 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004539
4540 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004541}
Mike Stump11289f42009-09-09 15:08:12 +00004542
4543template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004544QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004545 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004546 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004547
Douglas Gregore922c772009-08-04 22:27:00 +00004548 // decltype expressions are not potentially evaluated contexts
Richard Smithfd555f62012-02-22 02:04:18 +00004549 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4550 /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00004551
John McCalldadc5752010-08-24 06:29:42 +00004552 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004553 if (E.isInvalid())
4554 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004555
Richard Smithfd555f62012-02-22 02:04:18 +00004556 E = getSema().ActOnDecltypeExpression(E.take());
4557 if (E.isInvalid())
4558 return QualType();
4559
John McCall550e0c22009-10-21 00:40:46 +00004560 QualType Result = TL.getType();
4561 if (getDerived().AlwaysRebuild() ||
4562 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004563 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004564 if (Result.isNull())
4565 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004566 }
John McCall550e0c22009-10-21 00:40:46 +00004567 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004568
John McCall550e0c22009-10-21 00:40:46 +00004569 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4570 NewTL.setNameLoc(TL.getNameLoc());
4571
4572 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004573}
4574
4575template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004576QualType TreeTransform<Derived>::TransformUnaryTransformType(
4577 TypeLocBuilder &TLB,
4578 UnaryTransformTypeLoc TL) {
4579 QualType Result = TL.getType();
4580 if (Result->isDependentType()) {
4581 const UnaryTransformType *T = TL.getTypePtr();
4582 QualType NewBase =
4583 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4584 Result = getDerived().RebuildUnaryTransformType(NewBase,
4585 T->getUTTKind(),
4586 TL.getKWLoc());
4587 if (Result.isNull())
4588 return QualType();
4589 }
4590
4591 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4592 NewTL.setKWLoc(TL.getKWLoc());
4593 NewTL.setParensRange(TL.getParensRange());
4594 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4595 return Result;
4596}
4597
4598template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004599QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4600 AutoTypeLoc TL) {
4601 const AutoType *T = TL.getTypePtr();
4602 QualType OldDeduced = T->getDeducedType();
4603 QualType NewDeduced;
4604 if (!OldDeduced.isNull()) {
4605 NewDeduced = getDerived().TransformType(OldDeduced);
4606 if (NewDeduced.isNull())
4607 return QualType();
4608 }
4609
4610 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00004611 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4612 T->isDependentType()) {
Richard Smith74aeef52013-04-26 16:15:35 +00004613 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith30482bc2011-02-20 03:19:35 +00004614 if (Result.isNull())
4615 return QualType();
4616 }
4617
4618 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4619 NewTL.setNameLoc(TL.getNameLoc());
4620
4621 return Result;
4622}
4623
4624template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004625QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004626 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004627 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004628 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004629 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4630 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004631 if (!Record)
4632 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004633
John McCall550e0c22009-10-21 00:40:46 +00004634 QualType Result = TL.getType();
4635 if (getDerived().AlwaysRebuild() ||
4636 Record != T->getDecl()) {
4637 Result = getDerived().RebuildRecordType(Record);
4638 if (Result.isNull())
4639 return QualType();
4640 }
Mike Stump11289f42009-09-09 15:08:12 +00004641
John McCall550e0c22009-10-21 00:40:46 +00004642 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4643 NewTL.setNameLoc(TL.getNameLoc());
4644
4645 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004646}
Mike Stump11289f42009-09-09 15:08:12 +00004647
4648template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004649QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004650 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004651 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004652 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004653 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4654 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004655 if (!Enum)
4656 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004657
John McCall550e0c22009-10-21 00:40:46 +00004658 QualType Result = TL.getType();
4659 if (getDerived().AlwaysRebuild() ||
4660 Enum != T->getDecl()) {
4661 Result = getDerived().RebuildEnumType(Enum);
4662 if (Result.isNull())
4663 return QualType();
4664 }
Mike Stump11289f42009-09-09 15:08:12 +00004665
John McCall550e0c22009-10-21 00:40:46 +00004666 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4667 NewTL.setNameLoc(TL.getNameLoc());
4668
4669 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004670}
John McCallfcc33b02009-09-05 00:15:47 +00004671
John McCalle78aac42010-03-10 03:28:59 +00004672template<typename Derived>
4673QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4674 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004675 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004676 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4677 TL.getTypePtr()->getDecl());
4678 if (!D) return QualType();
4679
4680 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4681 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4682 return T;
4683}
4684
Douglas Gregord6ff3322009-08-04 16:50:30 +00004685template<typename Derived>
4686QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004687 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004688 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004689 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004690}
4691
Mike Stump11289f42009-09-09 15:08:12 +00004692template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004693QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004694 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004695 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004696 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00004697
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004698 // Substitute into the replacement type, which itself might involve something
4699 // that needs to be transformed. This only tends to occur with default
4700 // template arguments of template template parameters.
4701 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4702 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4703 if (Replacement.isNull())
4704 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00004705
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004706 // Always canonicalize the replacement type.
4707 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4708 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00004709 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004710 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00004711
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004712 // Propagate type-source information.
4713 SubstTemplateTypeParmTypeLoc NewTL
4714 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4715 NewTL.setNameLoc(TL.getNameLoc());
4716 return Result;
4717
John McCallcebee162009-10-18 09:09:24 +00004718}
4719
4720template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004721QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4722 TypeLocBuilder &TLB,
4723 SubstTemplateTypeParmPackTypeLoc TL) {
4724 return TransformTypeSpecType(TLB, TL);
4725}
4726
4727template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004728QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004729 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004730 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004731 const TemplateSpecializationType *T = TL.getTypePtr();
4732
Douglas Gregordf846d12011-03-02 18:46:51 +00004733 // The nested-name-specifier never matters in a TemplateSpecializationType,
4734 // because we can't have a dependent nested-name-specifier anyway.
4735 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004736 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004737 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4738 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004739 if (Template.isNull())
4740 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004741
John McCall31f82722010-11-12 08:19:04 +00004742 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4743}
4744
Eli Friedman0dfb8892011-10-06 23:00:33 +00004745template<typename Derived>
4746QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4747 AtomicTypeLoc TL) {
4748 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4749 if (ValueType.isNull())
4750 return QualType();
4751
4752 QualType Result = TL.getType();
4753 if (getDerived().AlwaysRebuild() ||
4754 ValueType != TL.getValueLoc().getType()) {
4755 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4756 if (Result.isNull())
4757 return QualType();
4758 }
4759
4760 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4761 NewTL.setKWLoc(TL.getKWLoc());
4762 NewTL.setLParenLoc(TL.getLParenLoc());
4763 NewTL.setRParenLoc(TL.getRParenLoc());
4764
4765 return Result;
4766}
4767
Chad Rosier1dcde962012-08-08 18:46:20 +00004768 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00004769 /// container that provides a \c getArgLoc() member function.
4770 ///
4771 /// This iterator is intended to be used with the iterator form of
4772 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4773 template<typename ArgLocContainer>
4774 class TemplateArgumentLocContainerIterator {
4775 ArgLocContainer *Container;
4776 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00004777
Douglas Gregorfe921a72010-12-20 23:36:19 +00004778 public:
4779 typedef TemplateArgumentLoc value_type;
4780 typedef TemplateArgumentLoc reference;
4781 typedef int difference_type;
4782 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00004783
Douglas Gregorfe921a72010-12-20 23:36:19 +00004784 class pointer {
4785 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00004786
Douglas Gregorfe921a72010-12-20 23:36:19 +00004787 public:
4788 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004789
Douglas Gregorfe921a72010-12-20 23:36:19 +00004790 const TemplateArgumentLoc *operator->() const {
4791 return &Arg;
4792 }
4793 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004794
4795
Douglas Gregorfe921a72010-12-20 23:36:19 +00004796 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00004797
Douglas Gregorfe921a72010-12-20 23:36:19 +00004798 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4799 unsigned Index)
4800 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004801
Douglas Gregorfe921a72010-12-20 23:36:19 +00004802 TemplateArgumentLocContainerIterator &operator++() {
4803 ++Index;
4804 return *this;
4805 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004806
Douglas Gregorfe921a72010-12-20 23:36:19 +00004807 TemplateArgumentLocContainerIterator operator++(int) {
4808 TemplateArgumentLocContainerIterator Old(*this);
4809 ++(*this);
4810 return Old;
4811 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004812
Douglas Gregorfe921a72010-12-20 23:36:19 +00004813 TemplateArgumentLoc operator*() const {
4814 return Container->getArgLoc(Index);
4815 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004816
Douglas Gregorfe921a72010-12-20 23:36:19 +00004817 pointer operator->() const {
4818 return pointer(Container->getArgLoc(Index));
4819 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004820
Douglas Gregorfe921a72010-12-20 23:36:19 +00004821 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004822 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004823 return X.Container == Y.Container && X.Index == Y.Index;
4824 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004825
Douglas Gregorfe921a72010-12-20 23:36:19 +00004826 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004827 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004828 return !(X == Y);
4829 }
4830 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004831
4832
John McCall31f82722010-11-12 08:19:04 +00004833template <typename Derived>
4834QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4835 TypeLocBuilder &TLB,
4836 TemplateSpecializationTypeLoc TL,
4837 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004838 TemplateArgumentListInfo NewTemplateArgs;
4839 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4840 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004841 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4842 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004843 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00004844 ArgIterator(TL, TL.getNumArgs()),
4845 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004846 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004847
John McCall0ad16662009-10-29 08:12:44 +00004848 // FIXME: maybe don't rebuild if all the template arguments are the same.
4849
4850 QualType Result =
4851 getDerived().RebuildTemplateSpecializationType(Template,
4852 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004853 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004854
4855 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00004856 // Specializations of template template parameters are represented as
4857 // TemplateSpecializationTypes, and substitution of type alias templates
4858 // within a dependent context can transform them into
4859 // DependentTemplateSpecializationTypes.
4860 if (isa<DependentTemplateSpecializationType>(Result)) {
4861 DependentTemplateSpecializationTypeLoc NewTL
4862 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004863 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00004864 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00004865 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004866 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00004867 NewTL.setLAngleLoc(TL.getLAngleLoc());
4868 NewTL.setRAngleLoc(TL.getRAngleLoc());
4869 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4870 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4871 return Result;
4872 }
4873
John McCall0ad16662009-10-29 08:12:44 +00004874 TemplateSpecializationTypeLoc NewTL
4875 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004876 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00004877 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4878 NewTL.setLAngleLoc(TL.getLAngleLoc());
4879 NewTL.setRAngleLoc(TL.getRAngleLoc());
4880 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4881 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004882 }
Mike Stump11289f42009-09-09 15:08:12 +00004883
John McCall0ad16662009-10-29 08:12:44 +00004884 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004885}
Mike Stump11289f42009-09-09 15:08:12 +00004886
Douglas Gregor5a064722011-02-28 17:23:35 +00004887template <typename Derived>
4888QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4889 TypeLocBuilder &TLB,
4890 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004891 TemplateName Template,
4892 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00004893 TemplateArgumentListInfo NewTemplateArgs;
4894 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4895 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4896 typedef TemplateArgumentLocContainerIterator<
4897 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004898 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00004899 ArgIterator(TL, TL.getNumArgs()),
4900 NewTemplateArgs))
4901 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00004902
Douglas Gregor5a064722011-02-28 17:23:35 +00004903 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00004904
Douglas Gregor5a064722011-02-28 17:23:35 +00004905 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4906 QualType Result
4907 = getSema().Context.getDependentTemplateSpecializationType(
4908 TL.getTypePtr()->getKeyword(),
4909 DTN->getQualifier(),
4910 DTN->getIdentifier(),
4911 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00004912
Douglas Gregor5a064722011-02-28 17:23:35 +00004913 DependentTemplateSpecializationTypeLoc NewTL
4914 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004915 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004916 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00004917 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004918 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00004919 NewTL.setLAngleLoc(TL.getLAngleLoc());
4920 NewTL.setRAngleLoc(TL.getRAngleLoc());
4921 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4922 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4923 return Result;
4924 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004925
4926 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00004927 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004928 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00004929 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00004930
Douglas Gregor5a064722011-02-28 17:23:35 +00004931 if (!Result.isNull()) {
4932 /// FIXME: Wrap this in an elaborated-type-specifier?
4933 TemplateSpecializationTypeLoc NewTL
4934 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00004935 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004936 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00004937 NewTL.setLAngleLoc(TL.getLAngleLoc());
4938 NewTL.setRAngleLoc(TL.getRAngleLoc());
4939 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4940 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4941 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004942
Douglas Gregor5a064722011-02-28 17:23:35 +00004943 return Result;
4944}
4945
Mike Stump11289f42009-09-09 15:08:12 +00004946template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004947QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00004948TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004949 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004950 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00004951
Douglas Gregor844cb502011-03-01 18:12:44 +00004952 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00004953 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00004954 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004955 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00004956 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4957 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00004958 return QualType();
4959 }
Mike Stump11289f42009-09-09 15:08:12 +00004960
John McCall31f82722010-11-12 08:19:04 +00004961 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4962 if (NamedT.isNull())
4963 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00004964
Richard Smith3f1b5d02011-05-05 21:57:07 +00004965 // C++0x [dcl.type.elab]p2:
4966 // If the identifier resolves to a typedef-name or the simple-template-id
4967 // resolves to an alias template specialization, the
4968 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00004969 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4970 if (const TemplateSpecializationType *TST =
4971 NamedT->getAs<TemplateSpecializationType>()) {
4972 TemplateName Template = TST->getTemplateName();
4973 if (TypeAliasTemplateDecl *TAT =
4974 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4975 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4976 diag::err_tag_reference_non_tag) << 4;
4977 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4978 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00004979 }
4980 }
4981
John McCall550e0c22009-10-21 00:40:46 +00004982 QualType Result = TL.getType();
4983 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00004984 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00004985 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00004986 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004987 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00004988 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00004989 if (Result.isNull())
4990 return QualType();
4991 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004992
Abramo Bagnara6150c882010-05-11 21:36:43 +00004993 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00004994 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004995 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00004996 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004997}
Mike Stump11289f42009-09-09 15:08:12 +00004998
4999template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005000QualType TreeTransform<Derived>::TransformAttributedType(
5001 TypeLocBuilder &TLB,
5002 AttributedTypeLoc TL) {
5003 const AttributedType *oldType = TL.getTypePtr();
5004 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5005 if (modifiedType.isNull())
5006 return QualType();
5007
5008 QualType result = TL.getType();
5009
5010 // FIXME: dependent operand expressions?
5011 if (getDerived().AlwaysRebuild() ||
5012 modifiedType != oldType->getModifiedType()) {
5013 // TODO: this is really lame; we should really be rebuilding the
5014 // equivalent type from first principles.
5015 QualType equivalentType
5016 = getDerived().TransformType(oldType->getEquivalentType());
5017 if (equivalentType.isNull())
5018 return QualType();
5019 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5020 modifiedType,
5021 equivalentType);
5022 }
5023
5024 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5025 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5026 if (TL.hasAttrOperand())
5027 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5028 if (TL.hasAttrExprOperand())
5029 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5030 else if (TL.hasAttrEnumOperand())
5031 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5032
5033 return result;
5034}
5035
5036template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005037QualType
5038TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5039 ParenTypeLoc TL) {
5040 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5041 if (Inner.isNull())
5042 return QualType();
5043
5044 QualType Result = TL.getType();
5045 if (getDerived().AlwaysRebuild() ||
5046 Inner != TL.getInnerLoc().getType()) {
5047 Result = getDerived().RebuildParenType(Inner);
5048 if (Result.isNull())
5049 return QualType();
5050 }
5051
5052 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5053 NewTL.setLParenLoc(TL.getLParenLoc());
5054 NewTL.setRParenLoc(TL.getRParenLoc());
5055 return Result;
5056}
5057
5058template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005059QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005060 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005061 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005062
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005063 NestedNameSpecifierLoc QualifierLoc
5064 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5065 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005066 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005067
John McCallc392f372010-06-11 00:33:02 +00005068 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005069 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005070 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005071 QualifierLoc,
5072 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005073 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005074 if (Result.isNull())
5075 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005076
Abramo Bagnarad7548482010-05-19 21:37:53 +00005077 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5078 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005079 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5080
Abramo Bagnarad7548482010-05-19 21:37:53 +00005081 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005082 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005083 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005084 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005085 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005086 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005087 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005088 NewTL.setNameLoc(TL.getNameLoc());
5089 }
John McCall550e0c22009-10-21 00:40:46 +00005090 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005091}
Mike Stump11289f42009-09-09 15:08:12 +00005092
Douglas Gregord6ff3322009-08-04 16:50:30 +00005093template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005094QualType TreeTransform<Derived>::
5095 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005096 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005097 NestedNameSpecifierLoc QualifierLoc;
5098 if (TL.getQualifierLoc()) {
5099 QualifierLoc
5100 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5101 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005102 return QualType();
5103 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005104
John McCall31f82722010-11-12 08:19:04 +00005105 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005106 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005107}
5108
5109template<typename Derived>
5110QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005111TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5112 DependentTemplateSpecializationTypeLoc TL,
5113 NestedNameSpecifierLoc QualifierLoc) {
5114 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005115
Douglas Gregora7a795b2011-03-01 20:11:18 +00005116 TemplateArgumentListInfo NewTemplateArgs;
5117 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5118 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005119
Douglas Gregora7a795b2011-03-01 20:11:18 +00005120 typedef TemplateArgumentLocContainerIterator<
5121 DependentTemplateSpecializationTypeLoc> ArgIterator;
5122 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5123 ArgIterator(TL, TL.getNumArgs()),
5124 NewTemplateArgs))
5125 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005126
Douglas Gregora7a795b2011-03-01 20:11:18 +00005127 QualType Result
5128 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5129 QualifierLoc,
5130 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005131 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005132 NewTemplateArgs);
5133 if (Result.isNull())
5134 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005135
Douglas Gregora7a795b2011-03-01 20:11:18 +00005136 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5137 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005138
Douglas Gregora7a795b2011-03-01 20:11:18 +00005139 // Copy information relevant to the template specialization.
5140 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005141 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005142 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005143 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005144 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5145 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005146 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005147 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005148
Douglas Gregora7a795b2011-03-01 20:11:18 +00005149 // Copy information relevant to the elaborated type.
5150 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005151 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005152 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005153 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5154 DependentTemplateSpecializationTypeLoc SpecTL
5155 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005156 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005157 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005158 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005159 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005160 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5161 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005162 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005163 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005164 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005165 TemplateSpecializationTypeLoc SpecTL
5166 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005167 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005168 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005169 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5170 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005171 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005172 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005173 }
5174 return Result;
5175}
5176
5177template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005178QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5179 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005180 QualType Pattern
5181 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005182 if (Pattern.isNull())
5183 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005184
5185 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005186 if (getDerived().AlwaysRebuild() ||
5187 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005188 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005189 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005190 TL.getEllipsisLoc(),
5191 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005192 if (Result.isNull())
5193 return QualType();
5194 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005195
Douglas Gregor822d0302011-01-12 17:07:58 +00005196 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5197 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5198 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005199}
5200
5201template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005202QualType
5203TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005204 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005205 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005206 TLB.pushFullCopy(TL);
5207 return TL.getType();
5208}
5209
5210template<typename Derived>
5211QualType
5212TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005213 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00005214 // ObjCObjectType is never dependent.
5215 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005216 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005217}
Mike Stump11289f42009-09-09 15:08:12 +00005218
5219template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005220QualType
5221TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005222 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005223 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005224 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005225 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005226}
5227
Douglas Gregord6ff3322009-08-04 16:50:30 +00005228//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005229// Statement transformation
5230//===----------------------------------------------------------------------===//
5231template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005232StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005233TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005234 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005235}
5236
5237template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005238StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005239TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5240 return getDerived().TransformCompoundStmt(S, false);
5241}
5242
5243template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005244StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005245TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005246 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005247 Sema::CompoundScopeRAII CompoundScope(getSema());
5248
John McCall1ababa62010-08-27 19:56:05 +00005249 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005250 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005251 SmallVector<Stmt*, 8> Statements;
Douglas Gregorebe10102009-08-20 07:17:43 +00005252 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5253 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00005254 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00005255 if (Result.isInvalid()) {
5256 // Immediately fail if this was a DeclStmt, since it's very
5257 // likely that this will cause problems for future statements.
5258 if (isa<DeclStmt>(*B))
5259 return StmtError();
5260
5261 // Otherwise, just keep processing substatements and fail later.
5262 SubStmtInvalid = true;
5263 continue;
5264 }
Mike Stump11289f42009-09-09 15:08:12 +00005265
Douglas Gregorebe10102009-08-20 07:17:43 +00005266 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5267 Statements.push_back(Result.takeAs<Stmt>());
5268 }
Mike Stump11289f42009-09-09 15:08:12 +00005269
John McCall1ababa62010-08-27 19:56:05 +00005270 if (SubStmtInvalid)
5271 return StmtError();
5272
Douglas Gregorebe10102009-08-20 07:17:43 +00005273 if (!getDerived().AlwaysRebuild() &&
5274 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00005275 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005276
5277 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005278 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005279 S->getRBracLoc(),
5280 IsStmtExpr);
5281}
Mike Stump11289f42009-09-09 15:08:12 +00005282
Douglas Gregorebe10102009-08-20 07:17:43 +00005283template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005284StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005285TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005286 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005287 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005288 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5289 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005290
Eli Friedman06577382009-11-19 03:14:00 +00005291 // Transform the left-hand case value.
5292 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005293 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005294 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005295 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005296
Eli Friedman06577382009-11-19 03:14:00 +00005297 // Transform the right-hand case value (for the GNU case-range extension).
5298 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005299 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005300 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005301 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005302 }
Mike Stump11289f42009-09-09 15:08:12 +00005303
Douglas Gregorebe10102009-08-20 07:17:43 +00005304 // Build the case statement.
5305 // Case statements are always rebuilt so that they will attached to their
5306 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005307 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005308 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005309 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005310 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005311 S->getColonLoc());
5312 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005313 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005314
Douglas Gregorebe10102009-08-20 07:17:43 +00005315 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005316 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005317 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005318 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005319
Douglas Gregorebe10102009-08-20 07:17:43 +00005320 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005321 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005322}
5323
5324template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005325StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005326TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005327 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005328 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005329 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005330 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005331
Douglas Gregorebe10102009-08-20 07:17:43 +00005332 // Default statements are always rebuilt
5333 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005334 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005335}
Mike Stump11289f42009-09-09 15:08:12 +00005336
Douglas Gregorebe10102009-08-20 07:17:43 +00005337template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005338StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005339TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005340 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005341 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005342 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005343
Chris Lattnercab02a62011-02-17 20:34:02 +00005344 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5345 S->getDecl());
5346 if (!LD)
5347 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00005348
5349
Douglas Gregorebe10102009-08-20 07:17:43 +00005350 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005351 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005352 cast<LabelDecl>(LD), SourceLocation(),
5353 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005354}
Mike Stump11289f42009-09-09 15:08:12 +00005355
Douglas Gregorebe10102009-08-20 07:17:43 +00005356template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005357StmtResult
Richard Smithc202b282012-04-14 00:33:13 +00005358TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5359 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5360 if (SubStmt.isInvalid())
5361 return StmtError();
5362
5363 // TODO: transform attributes
5364 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5365 return S;
5366
5367 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5368 S->getAttrs(),
5369 SubStmt.get());
5370}
5371
5372template<typename Derived>
5373StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005374TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005375 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005376 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00005377 VarDecl *ConditionVar = 0;
5378 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005379 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00005380 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005381 getDerived().TransformDefinition(
5382 S->getConditionVariable()->getLocation(),
5383 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00005384 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005385 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005386 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00005387 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005388
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005389 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005390 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005391
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005392 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005393 if (S->getCond()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005394 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005395 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005396 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005397 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005398
John McCallb268a282010-08-23 23:25:46 +00005399 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005400 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005401 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005402
John McCallb268a282010-08-23 23:25:46 +00005403 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5404 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005405 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005406
Douglas Gregorebe10102009-08-20 07:17:43 +00005407 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005408 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005409 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005410 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005411
Douglas Gregorebe10102009-08-20 07:17:43 +00005412 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005413 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005414 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005415 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005416
Douglas Gregorebe10102009-08-20 07:17:43 +00005417 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005418 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005419 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005420 Then.get() == S->getThen() &&
5421 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00005422 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005423
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005424 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005425 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00005426 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005427}
5428
5429template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005430StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005431TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005432 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005433 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00005434 VarDecl *ConditionVar = 0;
5435 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005436 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005437 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005438 getDerived().TransformDefinition(
5439 S->getConditionVariable()->getLocation(),
5440 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005441 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005442 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005443 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005444 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005445
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005446 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005447 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005448 }
Mike Stump11289f42009-09-09 15:08:12 +00005449
Douglas Gregorebe10102009-08-20 07:17:43 +00005450 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005451 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005452 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005453 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005454 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005455 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005456
Douglas Gregorebe10102009-08-20 07:17:43 +00005457 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005458 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005459 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005460 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005461
Douglas Gregorebe10102009-08-20 07:17:43 +00005462 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005463 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5464 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005465}
Mike Stump11289f42009-09-09 15:08:12 +00005466
Douglas Gregorebe10102009-08-20 07:17:43 +00005467template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005468StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005469TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005470 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005471 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00005472 VarDecl *ConditionVar = 0;
5473 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005474 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005475 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005476 getDerived().TransformDefinition(
5477 S->getConditionVariable()->getLocation(),
5478 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005479 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005480 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005481 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005482 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005483
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005484 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005485 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005486
5487 if (S->getCond()) {
5488 // Convert the condition to a boolean value.
Chad Rosier1dcde962012-08-08 18:46:20 +00005489 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005490 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005491 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005492 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005493 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005494 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005495 }
Mike Stump11289f42009-09-09 15:08:12 +00005496
John McCallb268a282010-08-23 23:25:46 +00005497 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5498 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005499 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005500
Douglas Gregorebe10102009-08-20 07:17:43 +00005501 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005502 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005503 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005504 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005505
Douglas Gregorebe10102009-08-20 07:17:43 +00005506 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005507 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005508 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005509 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005510 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005511
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005512 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005513 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005514}
Mike Stump11289f42009-09-09 15:08:12 +00005515
Douglas Gregorebe10102009-08-20 07:17:43 +00005516template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005517StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005518TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005519 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005520 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005521 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005522 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005523
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005524 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005525 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005526 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005527 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005528
Douglas Gregorebe10102009-08-20 07:17:43 +00005529 if (!getDerived().AlwaysRebuild() &&
5530 Cond.get() == S->getCond() &&
5531 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005532 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005533
John McCallb268a282010-08-23 23:25:46 +00005534 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5535 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005536 S->getRParenLoc());
5537}
Mike Stump11289f42009-09-09 15:08:12 +00005538
Douglas Gregorebe10102009-08-20 07:17:43 +00005539template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005540StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005541TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005542 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005543 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005544 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005545 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005546
Douglas Gregorebe10102009-08-20 07:17:43 +00005547 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005548 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005549 VarDecl *ConditionVar = 0;
5550 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005551 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005552 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005553 getDerived().TransformDefinition(
5554 S->getConditionVariable()->getLocation(),
5555 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005556 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005557 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005558 } else {
5559 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005560
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005561 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005562 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005563
5564 if (S->getCond()) {
5565 // Convert the condition to a boolean value.
Chad Rosier1dcde962012-08-08 18:46:20 +00005566 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005567 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005568 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005569 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005570
John McCallb268a282010-08-23 23:25:46 +00005571 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005572 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005573 }
Mike Stump11289f42009-09-09 15:08:12 +00005574
Chad Rosier1dcde962012-08-08 18:46:20 +00005575 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCallb268a282010-08-23 23:25:46 +00005576 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005577 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005578
Douglas Gregorebe10102009-08-20 07:17:43 +00005579 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005580 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005581 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005582 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005583
Richard Smith945f8d32013-01-14 22:39:08 +00005584 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00005585 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005586 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005587
Douglas Gregorebe10102009-08-20 07:17:43 +00005588 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005589 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005590 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005591 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005592
Douglas Gregorebe10102009-08-20 07:17:43 +00005593 if (!getDerived().AlwaysRebuild() &&
5594 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005595 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005596 Inc.get() == S->getInc() &&
5597 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005598 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005599
Douglas Gregorebe10102009-08-20 07:17:43 +00005600 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005601 Init.get(), FullCond, ConditionVar,
5602 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005603}
5604
5605template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005606StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005607TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005608 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5609 S->getLabel());
5610 if (!LD)
5611 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005612
Douglas Gregorebe10102009-08-20 07:17:43 +00005613 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005614 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005615 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005616}
5617
5618template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005619StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005620TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005621 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005622 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005623 return StmtError();
Eli Friedman9ccdb1d2012-01-31 22:47:07 +00005624 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump11289f42009-09-09 15:08:12 +00005625
Douglas Gregorebe10102009-08-20 07:17:43 +00005626 if (!getDerived().AlwaysRebuild() &&
5627 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00005628 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005629
5630 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005631 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005632}
5633
5634template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005635StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005636TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005637 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005638}
Mike Stump11289f42009-09-09 15:08:12 +00005639
Douglas Gregorebe10102009-08-20 07:17:43 +00005640template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005641StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005642TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005643 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005644}
Mike Stump11289f42009-09-09 15:08:12 +00005645
Douglas Gregorebe10102009-08-20 07:17:43 +00005646template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005647StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005648TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005649 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005650 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005651 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005652
Mike Stump11289f42009-09-09 15:08:12 +00005653 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005654 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005655 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005656}
Mike Stump11289f42009-09-09 15:08:12 +00005657
Douglas Gregorebe10102009-08-20 07:17:43 +00005658template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005659StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005660TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005661 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005662 SmallVector<Decl *, 4> Decls;
Douglas Gregorebe10102009-08-20 07:17:43 +00005663 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5664 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00005665 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5666 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005667 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005668 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005669
Douglas Gregorebe10102009-08-20 07:17:43 +00005670 if (Transformed != *D)
5671 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005672
Douglas Gregorebe10102009-08-20 07:17:43 +00005673 Decls.push_back(Transformed);
5674 }
Mike Stump11289f42009-09-09 15:08:12 +00005675
Douglas Gregorebe10102009-08-20 07:17:43 +00005676 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00005677 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005678
Rafael Espindolaab417692013-07-09 12:05:01 +00005679 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005680}
Mike Stump11289f42009-09-09 15:08:12 +00005681
Douglas Gregorebe10102009-08-20 07:17:43 +00005682template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005683StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00005684TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005685
Benjamin Kramerf0623432012-08-23 22:51:59 +00005686 SmallVector<Expr*, 8> Constraints;
5687 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005688 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005689
John McCalldadc5752010-08-24 06:29:42 +00005690 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005691 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005692
5693 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00005694
Anders Carlssonaaeef072010-01-24 05:50:09 +00005695 // Go through the outputs.
5696 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005697 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005698
Anders Carlssonaaeef072010-01-24 05:50:09 +00005699 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005700 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005701
Anders Carlssonaaeef072010-01-24 05:50:09 +00005702 // Transform the output expr.
5703 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005704 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005705 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005706 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005707
Anders Carlssonaaeef072010-01-24 05:50:09 +00005708 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005709
John McCallb268a282010-08-23 23:25:46 +00005710 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005711 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005712
Anders Carlssonaaeef072010-01-24 05:50:09 +00005713 // Go through the inputs.
5714 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005715 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005716
Anders Carlssonaaeef072010-01-24 05:50:09 +00005717 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005718 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005719
Anders Carlssonaaeef072010-01-24 05:50:09 +00005720 // Transform the input expr.
5721 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005722 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005723 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005724 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005725
Anders Carlssonaaeef072010-01-24 05:50:09 +00005726 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005727
John McCallb268a282010-08-23 23:25:46 +00005728 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005729 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005730
Anders Carlssonaaeef072010-01-24 05:50:09 +00005731 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00005732 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005733
5734 // Go through the clobbers.
5735 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00005736 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005737
5738 // No need to transform the asm string literal.
5739 AsmString = SemaRef.Owned(S->getAsmString());
Chad Rosierde70e0e2012-08-25 00:11:56 +00005740 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5741 S->isVolatile(), S->getNumOutputs(),
5742 S->getNumInputs(), Names.data(),
5743 Constraints, Exprs, AsmString.get(),
5744 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005745}
5746
Chad Rosier32503022012-06-11 20:47:18 +00005747template<typename Derived>
5748StmtResult
5749TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00005750 ArrayRef<Token> AsmToks =
5751 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00005752
John McCallf413f5e2013-05-03 00:10:13 +00005753 bool HadError = false, HadChange = false;
5754
5755 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5756 SmallVector<Expr*, 8> TransformedExprs;
5757 TransformedExprs.reserve(SrcExprs.size());
5758 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5759 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5760 if (!Result.isUsable()) {
5761 HadError = true;
5762 } else {
5763 HadChange |= (Result.get() != SrcExprs[i]);
5764 TransformedExprs.push_back(Result.take());
5765 }
5766 }
5767
5768 if (HadError) return StmtError();
5769 if (!HadChange && !getDerived().AlwaysRebuild())
5770 return Owned(S);
5771
Chad Rosierb6f46c12012-08-15 16:53:30 +00005772 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00005773 AsmToks, S->getAsmString(),
5774 S->getNumOutputs(), S->getNumInputs(),
5775 S->getAllConstraints(), S->getClobbers(),
5776 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00005777}
Douglas Gregorebe10102009-08-20 07:17:43 +00005778
5779template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005780StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005781TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005782 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005783 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005784 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005785 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005786
Douglas Gregor96c79492010-04-23 22:50:49 +00005787 // Transform the @catch statements (if present).
5788 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005789 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00005790 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005791 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005792 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005793 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005794 if (Catch.get() != S->getCatchStmt(I))
5795 AnyCatchChanged = true;
5796 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005797 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005798
Douglas Gregor306de2f2010-04-22 23:59:56 +00005799 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005800 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005801 if (S->getFinallyStmt()) {
5802 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5803 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005804 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005805 }
5806
5807 // If nothing changed, just retain this statement.
5808 if (!getDerived().AlwaysRebuild() &&
5809 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005810 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005811 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00005812 return SemaRef.Owned(S);
Chad Rosier1dcde962012-08-08 18:46:20 +00005813
Douglas Gregor306de2f2010-04-22 23:59:56 +00005814 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005815 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005816 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005817}
Mike Stump11289f42009-09-09 15:08:12 +00005818
Douglas Gregorebe10102009-08-20 07:17:43 +00005819template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005820StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005821TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005822 // Transform the @catch parameter, if there is one.
5823 VarDecl *Var = 0;
5824 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5825 TypeSourceInfo *TSInfo = 0;
5826 if (FromVar->getTypeSourceInfo()) {
5827 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5828 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005829 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005830 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005831
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005832 QualType T;
5833 if (TSInfo)
5834 T = TSInfo->getType();
5835 else {
5836 T = getDerived().TransformType(FromVar->getType());
5837 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00005838 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005839 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005840
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005841 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5842 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005843 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005844 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005845
John McCalldadc5752010-08-24 06:29:42 +00005846 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005847 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005848 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005849
5850 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005851 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005852 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005853}
Mike Stump11289f42009-09-09 15:08:12 +00005854
Douglas Gregorebe10102009-08-20 07:17:43 +00005855template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005856StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005857TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005858 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005859 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005860 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005861 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005862
Douglas Gregor306de2f2010-04-22 23:59:56 +00005863 // If nothing changed, just retain this statement.
5864 if (!getDerived().AlwaysRebuild() &&
5865 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00005866 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00005867
5868 // Build a new statement.
5869 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005870 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005871}
Mike Stump11289f42009-09-09 15:08:12 +00005872
Douglas Gregorebe10102009-08-20 07:17:43 +00005873template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005874StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005875TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005876 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005877 if (S->getThrowExpr()) {
5878 Operand = getDerived().TransformExpr(S->getThrowExpr());
5879 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005880 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005881 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005882
Douglas Gregor2900c162010-04-22 21:44:01 +00005883 if (!getDerived().AlwaysRebuild() &&
5884 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005885 return getSema().Owned(S);
Chad Rosier1dcde962012-08-08 18:46:20 +00005886
John McCallb268a282010-08-23 23:25:46 +00005887 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005888}
Mike Stump11289f42009-09-09 15:08:12 +00005889
Douglas Gregorebe10102009-08-20 07:17:43 +00005890template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005891StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005892TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005893 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005894 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005895 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005896 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005897 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00005898 Object =
5899 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5900 Object.get());
5901 if (Object.isInvalid())
5902 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005903
Douglas Gregor6148de72010-04-22 22:01:21 +00005904 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005905 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005906 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005907 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005908
Douglas Gregor6148de72010-04-22 22:01:21 +00005909 // If nothing change, just retain the current statement.
5910 if (!getDerived().AlwaysRebuild() &&
5911 Object.get() == S->getSynchExpr() &&
5912 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005913 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005914
5915 // Build a new statement.
5916 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005917 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005918}
5919
5920template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005921StmtResult
John McCall31168b02011-06-15 23:02:42 +00005922TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5923 ObjCAutoreleasePoolStmt *S) {
5924 // Transform the body.
5925 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5926 if (Body.isInvalid())
5927 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005928
John McCall31168b02011-06-15 23:02:42 +00005929 // If nothing changed, just retain this statement.
5930 if (!getDerived().AlwaysRebuild() &&
5931 Body.get() == S->getSubStmt())
5932 return SemaRef.Owned(S);
5933
5934 // Build a new statement.
5935 return getDerived().RebuildObjCAutoreleasePoolStmt(
5936 S->getAtLoc(), Body.get());
5937}
5938
5939template<typename Derived>
5940StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005941TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005942 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005943 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005944 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005945 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005946 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005947
Douglas Gregorf68a5082010-04-22 23:10:45 +00005948 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00005949 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005950 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005951 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005952
Douglas Gregorf68a5082010-04-22 23:10:45 +00005953 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005954 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005955 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005956 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005957
Douglas Gregorf68a5082010-04-22 23:10:45 +00005958 // If nothing changed, just retain this statement.
5959 if (!getDerived().AlwaysRebuild() &&
5960 Element.get() == S->getElement() &&
5961 Collection.get() == S->getCollection() &&
5962 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005963 return SemaRef.Owned(S);
Chad Rosier1dcde962012-08-08 18:46:20 +00005964
Douglas Gregorf68a5082010-04-22 23:10:45 +00005965 // Build a new statement.
5966 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00005967 Element.get(),
5968 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00005969 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005970 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005971}
5972
David Majnemer5f7efef2013-10-15 09:50:08 +00005973template <typename Derived>
5974StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005975 // Transform the exception declaration, if any.
5976 VarDecl *Var = 0;
David Majnemer5f7efef2013-10-15 09:50:08 +00005977 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
5978 TypeSourceInfo *T =
5979 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005980 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005981 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005982
David Majnemer5f7efef2013-10-15 09:50:08 +00005983 Var = getDerived().RebuildExceptionDecl(
5984 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
5985 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00005986 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00005987 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005988 }
Mike Stump11289f42009-09-09 15:08:12 +00005989
Douglas Gregorebe10102009-08-20 07:17:43 +00005990 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00005991 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00005992 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005993 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005994
David Majnemer5f7efef2013-10-15 09:50:08 +00005995 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005996 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00005997 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005998
David Majnemer5f7efef2013-10-15 09:50:08 +00005999 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006000}
Mike Stump11289f42009-09-09 15:08:12 +00006001
David Majnemer5f7efef2013-10-15 09:50:08 +00006002template <typename Derived>
6003StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006004 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006005 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006006 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006007 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006008
Douglas Gregorebe10102009-08-20 07:17:43 +00006009 // Transform the handlers.
6010 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006011 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006012 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006013 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006014 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006015 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006016
Douglas Gregorebe10102009-08-20 07:17:43 +00006017 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
6018 Handlers.push_back(Handler.takeAs<Stmt>());
6019 }
Mike Stump11289f42009-09-09 15:08:12 +00006020
David Majnemer5f7efef2013-10-15 09:50:08 +00006021 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006022 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00006023 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00006024
John McCallb268a282010-08-23 23:25:46 +00006025 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006026 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006027}
Mike Stump11289f42009-09-09 15:08:12 +00006028
Richard Smith02e85f32011-04-14 22:09:26 +00006029template<typename Derived>
6030StmtResult
6031TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6032 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6033 if (Range.isInvalid())
6034 return StmtError();
6035
6036 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6037 if (BeginEnd.isInvalid())
6038 return StmtError();
6039
6040 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6041 if (Cond.isInvalid())
6042 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006043 if (Cond.get())
6044 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
6045 if (Cond.isInvalid())
6046 return StmtError();
6047 if (Cond.get())
6048 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smith02e85f32011-04-14 22:09:26 +00006049
6050 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6051 if (Inc.isInvalid())
6052 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006053 if (Inc.get())
6054 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smith02e85f32011-04-14 22:09:26 +00006055
6056 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6057 if (LoopVar.isInvalid())
6058 return StmtError();
6059
6060 StmtResult NewStmt = S;
6061 if (getDerived().AlwaysRebuild() ||
6062 Range.get() != S->getRangeStmt() ||
6063 BeginEnd.get() != S->getBeginEndStmt() ||
6064 Cond.get() != S->getCond() ||
6065 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006066 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006067 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6068 S->getColonLoc(), Range.get(),
6069 BeginEnd.get(), Cond.get(),
6070 Inc.get(), LoopVar.get(),
6071 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006072 if (NewStmt.isInvalid())
6073 return StmtError();
6074 }
Richard Smith02e85f32011-04-14 22:09:26 +00006075
6076 StmtResult Body = getDerived().TransformStmt(S->getBody());
6077 if (Body.isInvalid())
6078 return StmtError();
6079
6080 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6081 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006082 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006083 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6084 S->getColonLoc(), Range.get(),
6085 BeginEnd.get(), Cond.get(),
6086 Inc.get(), LoopVar.get(),
6087 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006088 if (NewStmt.isInvalid())
6089 return StmtError();
6090 }
Richard Smith02e85f32011-04-14 22:09:26 +00006091
6092 if (NewStmt.get() == S)
6093 return SemaRef.Owned(S);
6094
6095 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6096}
6097
John Wiegley1c0675e2011-04-28 01:08:34 +00006098template<typename Derived>
6099StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006100TreeTransform<Derived>::TransformMSDependentExistsStmt(
6101 MSDependentExistsStmt *S) {
6102 // Transform the nested-name-specifier, if any.
6103 NestedNameSpecifierLoc QualifierLoc;
6104 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006105 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006106 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6107 if (!QualifierLoc)
6108 return StmtError();
6109 }
6110
6111 // Transform the declaration name.
6112 DeclarationNameInfo NameInfo = S->getNameInfo();
6113 if (NameInfo.getName()) {
6114 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6115 if (!NameInfo.getName())
6116 return StmtError();
6117 }
6118
6119 // Check whether anything changed.
6120 if (!getDerived().AlwaysRebuild() &&
6121 QualifierLoc == S->getQualifierLoc() &&
6122 NameInfo.getName() == S->getNameInfo().getName())
6123 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006124
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006125 // Determine whether this name exists, if we can.
6126 CXXScopeSpec SS;
6127 SS.Adopt(QualifierLoc);
6128 bool Dependent = false;
6129 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
6130 case Sema::IER_Exists:
6131 if (S->isIfExists())
6132 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006133
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006134 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6135
6136 case Sema::IER_DoesNotExist:
6137 if (S->isIfNotExists())
6138 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006139
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006140 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006141
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006142 case Sema::IER_Dependent:
6143 Dependent = true;
6144 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006145
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006146 case Sema::IER_Error:
6147 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006148 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006149
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006150 // We need to continue with the instantiation, so do so now.
6151 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6152 if (SubStmt.isInvalid())
6153 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006154
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006155 // If we have resolved the name, just transform to the substatement.
6156 if (!Dependent)
6157 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006158
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006159 // The name is still dependent, so build a dependent expression again.
6160 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6161 S->isIfExists(),
6162 QualifierLoc,
6163 NameInfo,
6164 SubStmt.get());
6165}
6166
6167template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006168ExprResult
6169TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6170 NestedNameSpecifierLoc QualifierLoc;
6171 if (E->getQualifierLoc()) {
6172 QualifierLoc
6173 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6174 if (!QualifierLoc)
6175 return ExprError();
6176 }
6177
6178 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6179 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6180 if (!PD)
6181 return ExprError();
6182
6183 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6184 if (Base.isInvalid())
6185 return ExprError();
6186
6187 return new (SemaRef.getASTContext())
6188 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6189 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6190 QualifierLoc, E->getMemberLoc());
6191}
6192
David Majnemerfad8f482013-10-15 09:33:02 +00006193template <typename Derived>
6194StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006195 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006196 if (TryBlock.isInvalid())
6197 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006198
6199 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006200 if (Handler.isInvalid())
6201 return StmtError();
6202
David Majnemerfad8f482013-10-15 09:33:02 +00006203 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6204 Handler.get() == S->getHandler())
John Wiegley1c0675e2011-04-28 01:08:34 +00006205 return SemaRef.Owned(S);
6206
David Majnemerfad8f482013-10-15 09:33:02 +00006207 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
6208 TryBlock.take(), Handler.take());
John Wiegley1c0675e2011-04-28 01:08:34 +00006209}
6210
David Majnemerfad8f482013-10-15 09:33:02 +00006211template <typename Derived>
6212StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006213 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006214 if (Block.isInvalid())
6215 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006216
David Majnemerfad8f482013-10-15 09:33:02 +00006217 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.take());
John Wiegley1c0675e2011-04-28 01:08:34 +00006218}
6219
David Majnemerfad8f482013-10-15 09:33:02 +00006220template <typename Derived>
6221StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00006222 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00006223 if (FilterExpr.isInvalid())
6224 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006225
David Majnemer7e755502013-10-15 09:30:14 +00006226 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006227 if (Block.isInvalid())
6228 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006229
David Majnemerfad8f482013-10-15 09:33:02 +00006230 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.take(),
John Wiegley1c0675e2011-04-28 01:08:34 +00006231 Block.take());
6232}
6233
David Majnemerfad8f482013-10-15 09:33:02 +00006234template <typename Derived>
6235StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6236 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00006237 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6238 else
6239 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6240}
6241
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006242template<typename Derived>
6243StmtResult
6244TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006245 DeclarationNameInfo DirName;
6246 getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, 0);
6247
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006248 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00006249 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006250 ArrayRef<OMPClause *> Clauses = D->clauses();
6251 TClauses.reserve(Clauses.size());
6252 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6253 I != E; ++I) {
6254 if (*I) {
6255 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataev758e55e2013-09-06 18:03:48 +00006256 if (!Clause) {
6257 getSema().EndOpenMPDSABlock(0);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006258 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006259 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006260 TClauses.push_back(Clause);
6261 }
6262 else {
6263 TClauses.push_back(0);
6264 }
6265 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00006266 if (!D->getAssociatedStmt()) {
6267 getSema().EndOpenMPDSABlock(0);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006268 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006269 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006270 StmtResult AssociatedStmt =
6271 getDerived().TransformStmt(D->getAssociatedStmt());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006272 if (AssociatedStmt.isInvalid()) {
6273 getSema().EndOpenMPDSABlock(0);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006274 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006275 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006276
Alexey Bataev758e55e2013-09-06 18:03:48 +00006277 StmtResult Res = getDerived().RebuildOMPParallelDirective(TClauses,
6278 AssociatedStmt.take(),
6279 D->getLocStart(),
6280 D->getLocEnd());
6281 getSema().EndOpenMPDSABlock(Res.get());
6282 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006283}
6284
6285template<typename Derived>
6286OMPClause *
6287TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
6288 return getDerived().RebuildOMPDefaultClause(C->getDefaultKind(),
6289 C->getDefaultKindKwLoc(),
6290 C->getLocStart(),
6291 C->getLParenLoc(),
6292 C->getLocEnd());
6293}
6294
6295template<typename Derived>
6296OMPClause *
6297TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006298 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006299 Vars.reserve(C->varlist_size());
Alexey Bataev756c1962013-09-24 03:17:45 +00006300 for (OMPPrivateClause::varlist_iterator I = C->varlist_begin(),
6301 E = C->varlist_end();
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006302 I != E; ++I) {
6303 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6304 if (EVar.isInvalid())
6305 return 0;
6306 Vars.push_back(EVar.take());
6307 }
6308 return getDerived().RebuildOMPPrivateClause(Vars,
6309 C->getLocStart(),
6310 C->getLParenLoc(),
6311 C->getLocEnd());
6312}
6313
Alexey Bataev758e55e2013-09-06 18:03:48 +00006314template<typename Derived>
6315OMPClause *
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006316TreeTransform<Derived>::TransformOMPFirstprivateClause(
6317 OMPFirstprivateClause *C) {
6318 llvm::SmallVector<Expr *, 16> Vars;
6319 Vars.reserve(C->varlist_size());
6320 for (OMPFirstprivateClause::varlist_iterator I = C->varlist_begin(),
6321 E = C->varlist_end();
6322 I != E; ++I) {
6323 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6324 if (EVar.isInvalid())
6325 return 0;
6326 Vars.push_back(EVar.take());
6327 }
6328 return getDerived().RebuildOMPFirstprivateClause(Vars,
6329 C->getLocStart(),
6330 C->getLParenLoc(),
6331 C->getLocEnd());
6332}
6333
6334template<typename Derived>
6335OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00006336TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
6337 llvm::SmallVector<Expr *, 16> Vars;
6338 Vars.reserve(C->varlist_size());
Alexey Bataev756c1962013-09-24 03:17:45 +00006339 for (OMPSharedClause::varlist_iterator I = C->varlist_begin(),
6340 E = C->varlist_end();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006341 I != E; ++I) {
6342 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6343 if (EVar.isInvalid())
6344 return 0;
6345 Vars.push_back(EVar.take());
6346 }
6347 return getDerived().RebuildOMPSharedClause(Vars,
6348 C->getLocStart(),
6349 C->getLParenLoc(),
6350 C->getLocEnd());
6351}
6352
Douglas Gregorebe10102009-08-20 07:17:43 +00006353//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00006354// Expression transformation
6355//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00006356template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006357ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006358TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006359 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006360}
Mike Stump11289f42009-09-09 15:08:12 +00006361
6362template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006363ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006364TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006365 NestedNameSpecifierLoc QualifierLoc;
6366 if (E->getQualifierLoc()) {
6367 QualifierLoc
6368 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6369 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006370 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006371 }
John McCallce546572009-12-08 09:08:17 +00006372
6373 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006374 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6375 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006376 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00006377 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006378
John McCall815039a2010-08-17 21:27:17 +00006379 DeclarationNameInfo NameInfo = E->getNameInfo();
6380 if (NameInfo.getName()) {
6381 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6382 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006383 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00006384 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006385
6386 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006387 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006388 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006389 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00006390 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006391
6392 // Mark it referenced in the new context regardless.
6393 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00006394 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00006395
John McCallc3007a22010-10-26 07:05:15 +00006396 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006397 }
John McCallce546572009-12-08 09:08:17 +00006398
6399 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00006400 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006401 TemplateArgs = &TransArgs;
6402 TransArgs.setLAngleLoc(E->getLAngleLoc());
6403 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006404 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6405 E->getNumTemplateArgs(),
6406 TransArgs))
6407 return ExprError();
John McCallce546572009-12-08 09:08:17 +00006408 }
6409
Chad Rosier1dcde962012-08-08 18:46:20 +00006410 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00006411 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006412}
Mike Stump11289f42009-09-09 15:08:12 +00006413
Douglas Gregora16548e2009-08-11 05:31:07 +00006414template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006415ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006416TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006417 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006418}
Mike Stump11289f42009-09-09 15:08:12 +00006419
Douglas Gregora16548e2009-08-11 05:31:07 +00006420template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006421ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006422TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006423 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006424}
Mike Stump11289f42009-09-09 15:08:12 +00006425
Douglas Gregora16548e2009-08-11 05:31:07 +00006426template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006427ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006428TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006429 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006430}
Mike Stump11289f42009-09-09 15:08:12 +00006431
Douglas Gregora16548e2009-08-11 05:31:07 +00006432template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006433ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006434TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006435 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006436}
Mike Stump11289f42009-09-09 15:08:12 +00006437
Douglas Gregora16548e2009-08-11 05:31:07 +00006438template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006439ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006440TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006441 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006442}
6443
6444template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006445ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00006446TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00006447 if (FunctionDecl *FD = E->getDirectCallee())
6448 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00006449 return SemaRef.MaybeBindToTemporary(E);
6450}
6451
6452template<typename Derived>
6453ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00006454TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6455 ExprResult ControllingExpr =
6456 getDerived().TransformExpr(E->getControllingExpr());
6457 if (ControllingExpr.isInvalid())
6458 return ExprError();
6459
Chris Lattner01cf8db2011-07-20 06:58:45 +00006460 SmallVector<Expr *, 4> AssocExprs;
6461 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00006462 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6463 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6464 if (TS) {
6465 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6466 if (!AssocType)
6467 return ExprError();
6468 AssocTypes.push_back(AssocType);
6469 } else {
6470 AssocTypes.push_back(0);
6471 }
6472
6473 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6474 if (AssocExpr.isInvalid())
6475 return ExprError();
6476 AssocExprs.push_back(AssocExpr.release());
6477 }
6478
6479 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6480 E->getDefaultLoc(),
6481 E->getRParenLoc(),
6482 ControllingExpr.release(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00006483 AssocTypes,
6484 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00006485}
6486
6487template<typename Derived>
6488ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006489TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006490 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006491 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006492 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006493
Douglas Gregora16548e2009-08-11 05:31:07 +00006494 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006495 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006496
John McCallb268a282010-08-23 23:25:46 +00006497 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006498 E->getRParen());
6499}
6500
Richard Smithdb2630f2012-10-21 03:28:35 +00006501/// \brief The operand of a unary address-of operator has special rules: it's
6502/// allowed to refer to a non-static member of a class even if there's no 'this'
6503/// object available.
6504template<typename Derived>
6505ExprResult
6506TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6507 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6508 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6509 else
6510 return getDerived().TransformExpr(E);
6511}
6512
Mike Stump11289f42009-09-09 15:08:12 +00006513template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006514ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006515TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00006516 ExprResult SubExpr;
6517 if (E->getOpcode() == UO_AddrOf)
6518 SubExpr = TransformAddressOfOperand(E->getSubExpr());
6519 else
6520 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006521 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006522 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006523
Douglas Gregora16548e2009-08-11 05:31:07 +00006524 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006525 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006526
Douglas Gregora16548e2009-08-11 05:31:07 +00006527 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6528 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006529 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006530}
Mike Stump11289f42009-09-09 15:08:12 +00006531
Douglas Gregora16548e2009-08-11 05:31:07 +00006532template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006533ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00006534TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6535 // Transform the type.
6536 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6537 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00006538 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006539
Douglas Gregor882211c2010-04-28 22:16:22 +00006540 // Transform all of the components into components similar to what the
6541 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00006542 // FIXME: It would be slightly more efficient in the non-dependent case to
6543 // just map FieldDecls, rather than requiring the rebuilder to look for
6544 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00006545 // template code that we don't care.
6546 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00006547 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00006548 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006549 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00006550 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6551 const Node &ON = E->getComponent(I);
6552 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00006553 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00006554 Comp.LocStart = ON.getSourceRange().getBegin();
6555 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00006556 switch (ON.getKind()) {
6557 case Node::Array: {
6558 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00006559 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00006560 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006561 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006562
Douglas Gregor882211c2010-04-28 22:16:22 +00006563 ExprChanged = ExprChanged || Index.get() != FromIndex;
6564 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00006565 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00006566 break;
6567 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006568
Douglas Gregor882211c2010-04-28 22:16:22 +00006569 case Node::Field:
6570 case Node::Identifier:
6571 Comp.isBrackets = false;
6572 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00006573 if (!Comp.U.IdentInfo)
6574 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00006575
Douglas Gregor882211c2010-04-28 22:16:22 +00006576 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006577
Douglas Gregord1702062010-04-29 00:18:15 +00006578 case Node::Base:
6579 // Will be recomputed during the rebuild.
6580 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00006581 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006582
Douglas Gregor882211c2010-04-28 22:16:22 +00006583 Components.push_back(Comp);
6584 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006585
Douglas Gregor882211c2010-04-28 22:16:22 +00006586 // If nothing changed, retain the existing expression.
6587 if (!getDerived().AlwaysRebuild() &&
6588 Type == E->getTypeSourceInfo() &&
6589 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00006590 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00006591
Douglas Gregor882211c2010-04-28 22:16:22 +00006592 // Build a new offsetof expression.
6593 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6594 Components.data(), Components.size(),
6595 E->getRParenLoc());
6596}
6597
6598template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006599ExprResult
John McCall8d69a212010-11-15 23:31:06 +00006600TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6601 assert(getDerived().AlreadyTransformed(E->getType()) &&
6602 "opaque value expression requires transformation");
6603 return SemaRef.Owned(E);
6604}
6605
6606template<typename Derived>
6607ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00006608TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00006609 // Rebuild the syntactic form. The original syntactic form has
6610 // opaque-value expressions in it, so strip those away and rebuild
6611 // the result. This is a really awful way of doing this, but the
6612 // better solution (rebuilding the semantic expressions and
6613 // rebinding OVEs as necessary) doesn't work; we'd need
6614 // TreeTransform to not strip away implicit conversions.
6615 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6616 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00006617 if (result.isInvalid()) return ExprError();
6618
6619 // If that gives us a pseudo-object result back, the pseudo-object
6620 // expression must have been an lvalue-to-rvalue conversion which we
6621 // should reapply.
6622 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6623 result = SemaRef.checkPseudoObjectRValue(result.take());
6624
6625 return result;
6626}
6627
6628template<typename Derived>
6629ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00006630TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6631 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006632 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00006633 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00006634
John McCallbcd03502009-12-07 02:54:59 +00006635 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00006636 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006637 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006638
John McCall4c98fd82009-11-04 07:28:41 +00006639 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00006640 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006641
Peter Collingbournee190dee2011-03-11 19:24:49 +00006642 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6643 E->getKind(),
6644 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006645 }
Mike Stump11289f42009-09-09 15:08:12 +00006646
Eli Friedmane4f22df2012-02-29 04:03:55 +00006647 // C++0x [expr.sizeof]p1:
6648 // The operand is either an expression, which is an unevaluated operand
6649 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00006650 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6651 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00006652
Eli Friedmane4f22df2012-02-29 04:03:55 +00006653 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6654 if (SubExpr.isInvalid())
6655 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006656
Eli Friedmane4f22df2012-02-29 04:03:55 +00006657 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6658 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006659
Peter Collingbournee190dee2011-03-11 19:24:49 +00006660 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6661 E->getOperatorLoc(),
6662 E->getKind(),
6663 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006664}
Mike Stump11289f42009-09-09 15:08:12 +00006665
Douglas Gregora16548e2009-08-11 05:31:07 +00006666template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006667ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006668TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006669 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006670 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006671 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006672
John McCalldadc5752010-08-24 06:29:42 +00006673 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006674 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006675 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006676
6677
Douglas Gregora16548e2009-08-11 05:31:07 +00006678 if (!getDerived().AlwaysRebuild() &&
6679 LHS.get() == E->getLHS() &&
6680 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006681 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006682
John McCallb268a282010-08-23 23:25:46 +00006683 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006684 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006685 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006686 E->getRBracketLoc());
6687}
Mike Stump11289f42009-09-09 15:08:12 +00006688
6689template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006690ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006691TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006692 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00006693 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006694 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006695 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006696
6697 // Transform arguments.
6698 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006699 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00006700 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00006701 &ArgChanged))
6702 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006703
Douglas Gregora16548e2009-08-11 05:31:07 +00006704 if (!getDerived().AlwaysRebuild() &&
6705 Callee.get() == E->getCallee() &&
6706 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00006707 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00006708
Douglas Gregora16548e2009-08-11 05:31:07 +00006709 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00006710 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006711 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00006712 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006713 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00006714 E->getRParenLoc());
6715}
Mike Stump11289f42009-09-09 15:08:12 +00006716
6717template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006718ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006719TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006720 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006721 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006722 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006723
Douglas Gregorea972d32011-02-28 21:54:11 +00006724 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006725 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006726 QualifierLoc
6727 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006728
Douglas Gregorea972d32011-02-28 21:54:11 +00006729 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006730 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006731 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00006732 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00006733
Eli Friedman2cfcef62009-12-04 06:40:45 +00006734 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006735 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6736 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006737 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00006738 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006739
John McCall16df1e52010-03-30 21:47:33 +00006740 NamedDecl *FoundDecl = E->getFoundDecl();
6741 if (FoundDecl == E->getMemberDecl()) {
6742 FoundDecl = Member;
6743 } else {
6744 FoundDecl = cast_or_null<NamedDecl>(
6745 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6746 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00006747 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00006748 }
6749
Douglas Gregora16548e2009-08-11 05:31:07 +00006750 if (!getDerived().AlwaysRebuild() &&
6751 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006752 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006753 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00006754 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00006755 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006756
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006757 // Mark it referenced in the new context regardless.
6758 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00006759 SemaRef.MarkMemberReferenced(E);
6760
John McCallc3007a22010-10-26 07:05:15 +00006761 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006762 }
Douglas Gregora16548e2009-08-11 05:31:07 +00006763
John McCall6b51f282009-11-23 01:53:49 +00006764 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00006765 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00006766 TransArgs.setLAngleLoc(E->getLAngleLoc());
6767 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006768 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6769 E->getNumTemplateArgs(),
6770 TransArgs))
6771 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006772 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006773
Douglas Gregora16548e2009-08-11 05:31:07 +00006774 // FIXME: Bogus source location for the operator
6775 SourceLocation FakeOperatorLoc
6776 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6777
John McCall38836f02010-01-15 08:34:02 +00006778 // FIXME: to do this check properly, we will need to preserve the
6779 // first-qualifier-in-scope here, just in case we had a dependent
6780 // base (and therefore couldn't do the check) and a
6781 // nested-name-qualifier (and therefore could do the lookup).
6782 NamedDecl *FirstQualifierInScope = 0;
6783
John McCallb268a282010-08-23 23:25:46 +00006784 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006785 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00006786 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00006787 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006788 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006789 Member,
John McCall16df1e52010-03-30 21:47:33 +00006790 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00006791 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00006792 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00006793 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00006794}
Mike Stump11289f42009-09-09 15:08:12 +00006795
Douglas Gregora16548e2009-08-11 05:31:07 +00006796template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006797ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006798TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006799 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006800 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006801 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006802
John McCalldadc5752010-08-24 06:29:42 +00006803 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006804 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006805 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006806
Douglas Gregora16548e2009-08-11 05:31:07 +00006807 if (!getDerived().AlwaysRebuild() &&
6808 LHS.get() == E->getLHS() &&
6809 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006810 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006811
Lang Hames5de91cc2012-10-02 04:45:10 +00006812 Sema::FPContractStateRAII FPContractState(getSema());
6813 getSema().FPFeatures.fp_contract = E->isFPContractable();
6814
Douglas Gregora16548e2009-08-11 05:31:07 +00006815 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006816 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006817}
6818
Mike Stump11289f42009-09-09 15:08:12 +00006819template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006820ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006821TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00006822 CompoundAssignOperator *E) {
6823 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006824}
Mike Stump11289f42009-09-09 15:08:12 +00006825
Douglas Gregora16548e2009-08-11 05:31:07 +00006826template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00006827ExprResult TreeTransform<Derived>::
6828TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6829 // Just rebuild the common and RHS expressions and see whether we
6830 // get any changes.
6831
6832 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6833 if (commonExpr.isInvalid())
6834 return ExprError();
6835
6836 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6837 if (rhs.isInvalid())
6838 return ExprError();
6839
6840 if (!getDerived().AlwaysRebuild() &&
6841 commonExpr.get() == e->getCommon() &&
6842 rhs.get() == e->getFalseExpr())
6843 return SemaRef.Owned(e);
6844
6845 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6846 e->getQuestionLoc(),
6847 0,
6848 e->getColonLoc(),
6849 rhs.get());
6850}
6851
6852template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006853ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006854TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006855 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006856 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006857 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006858
John McCalldadc5752010-08-24 06:29:42 +00006859 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006860 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006861 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006862
John McCalldadc5752010-08-24 06:29:42 +00006863 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006864 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006865 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006866
Douglas Gregora16548e2009-08-11 05:31:07 +00006867 if (!getDerived().AlwaysRebuild() &&
6868 Cond.get() == E->getCond() &&
6869 LHS.get() == E->getLHS() &&
6870 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006871 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006872
John McCallb268a282010-08-23 23:25:46 +00006873 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006874 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00006875 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006876 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006877 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006878}
Mike Stump11289f42009-09-09 15:08:12 +00006879
6880template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006881ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006882TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00006883 // Implicit casts are eliminated during transformation, since they
6884 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00006885 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006886}
Mike Stump11289f42009-09-09 15:08:12 +00006887
Douglas Gregora16548e2009-08-11 05:31:07 +00006888template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006889ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006890TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006891 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6892 if (!Type)
6893 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006894
John McCalldadc5752010-08-24 06:29:42 +00006895 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006896 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006897 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006898 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006899
Douglas Gregora16548e2009-08-11 05:31:07 +00006900 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006901 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006902 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006903 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006904
John McCall97513962010-01-15 18:39:57 +00006905 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006906 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006907 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006908 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006909}
Mike Stump11289f42009-09-09 15:08:12 +00006910
Douglas Gregora16548e2009-08-11 05:31:07 +00006911template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006912ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006913TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00006914 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6915 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6916 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006917 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006918
John McCalldadc5752010-08-24 06:29:42 +00006919 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00006920 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006921 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006922
Douglas Gregora16548e2009-08-11 05:31:07 +00006923 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00006924 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006925 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00006926 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006927
John McCall5d7aa7f2010-01-19 22:33:45 +00006928 // Note: the expression type doesn't necessarily match the
6929 // type-as-written, but that's okay, because it should always be
6930 // derivable from the initializer.
6931
John McCalle15bbff2010-01-18 19:35:47 +00006932 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00006933 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00006934 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006935}
Mike Stump11289f42009-09-09 15:08:12 +00006936
Douglas Gregora16548e2009-08-11 05:31:07 +00006937template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006938ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006939TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006940 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006941 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006942 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006943
Douglas Gregora16548e2009-08-11 05:31:07 +00006944 if (!getDerived().AlwaysRebuild() &&
6945 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006946 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006947
Douglas Gregora16548e2009-08-11 05:31:07 +00006948 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00006949 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006950 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00006951 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006952 E->getAccessorLoc(),
6953 E->getAccessor());
6954}
Mike Stump11289f42009-09-09 15:08:12 +00006955
Douglas Gregora16548e2009-08-11 05:31:07 +00006956template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006957ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006958TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006959 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00006960
Benjamin Kramerf0623432012-08-23 22:51:59 +00006961 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00006962 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00006963 Inits, &InitChanged))
6964 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006965
Douglas Gregora16548e2009-08-11 05:31:07 +00006966 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00006967 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006968
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006969 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00006970 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00006971}
Mike Stump11289f42009-09-09 15:08:12 +00006972
Douglas Gregora16548e2009-08-11 05:31:07 +00006973template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006974ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006975TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006976 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00006977
Douglas Gregorebe10102009-08-20 07:17:43 +00006978 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00006979 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006980 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006981 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006982
Douglas Gregorebe10102009-08-20 07:17:43 +00006983 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00006984 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00006985 bool ExprChanged = false;
6986 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6987 DEnd = E->designators_end();
6988 D != DEnd; ++D) {
6989 if (D->isFieldDesignator()) {
6990 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6991 D->getDotLoc(),
6992 D->getFieldLoc()));
6993 continue;
6994 }
Mike Stump11289f42009-09-09 15:08:12 +00006995
Douglas Gregora16548e2009-08-11 05:31:07 +00006996 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00006997 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00006998 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006999 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007000
7001 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007002 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007003
Douglas Gregora16548e2009-08-11 05:31:07 +00007004 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
7005 ArrayExprs.push_back(Index.release());
7006 continue;
7007 }
Mike Stump11289f42009-09-09 15:08:12 +00007008
Douglas Gregora16548e2009-08-11 05:31:07 +00007009 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00007010 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00007011 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7012 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007013 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007014
John McCalldadc5752010-08-24 06:29:42 +00007015 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007016 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007017 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007018
7019 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007020 End.get(),
7021 D->getLBracketLoc(),
7022 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007023
Douglas Gregora16548e2009-08-11 05:31:07 +00007024 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7025 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00007026
Douglas Gregora16548e2009-08-11 05:31:07 +00007027 ArrayExprs.push_back(Start.release());
7028 ArrayExprs.push_back(End.release());
7029 }
Mike Stump11289f42009-09-09 15:08:12 +00007030
Douglas Gregora16548e2009-08-11 05:31:07 +00007031 if (!getDerived().AlwaysRebuild() &&
7032 Init.get() == E->getInit() &&
7033 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00007034 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007035
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007036 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007037 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007038 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007039}
Mike Stump11289f42009-09-09 15:08:12 +00007040
Douglas Gregora16548e2009-08-11 05:31:07 +00007041template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007042ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007043TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007044 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00007045 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00007046
Douglas Gregor3da3c062009-10-28 00:29:27 +00007047 // FIXME: Will we ever have proper type location here? Will we actually
7048 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00007049 QualType T = getDerived().TransformType(E->getType());
7050 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007051 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007052
Douglas Gregora16548e2009-08-11 05:31:07 +00007053 if (!getDerived().AlwaysRebuild() &&
7054 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00007055 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007056
Douglas Gregora16548e2009-08-11 05:31:07 +00007057 return getDerived().RebuildImplicitValueInitExpr(T);
7058}
Mike Stump11289f42009-09-09 15:08:12 +00007059
Douglas Gregora16548e2009-08-11 05:31:07 +00007060template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007061ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007062TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00007063 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7064 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007065 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007066
John McCalldadc5752010-08-24 06:29:42 +00007067 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007068 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007069 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007070
Douglas Gregora16548e2009-08-11 05:31:07 +00007071 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00007072 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007073 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007074 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007075
John McCallb268a282010-08-23 23:25:46 +00007076 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00007077 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007078}
7079
7080template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007081ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007082TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007083 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007084 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00007085 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7086 &ArgumentChanged))
7087 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007088
Douglas Gregora16548e2009-08-11 05:31:07 +00007089 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007090 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00007091 E->getRParenLoc());
7092}
Mike Stump11289f42009-09-09 15:08:12 +00007093
Douglas Gregora16548e2009-08-11 05:31:07 +00007094/// \brief Transform an address-of-label expression.
7095///
7096/// By default, the transformation of an address-of-label expression always
7097/// rebuilds the expression, so that the label identifier can be resolved to
7098/// the corresponding label statement by semantic analysis.
7099template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007100ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007101TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00007102 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7103 E->getLabel());
7104 if (!LD)
7105 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007106
Douglas Gregora16548e2009-08-11 05:31:07 +00007107 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00007108 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00007109}
Mike Stump11289f42009-09-09 15:08:12 +00007110
7111template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00007112ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007113TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00007114 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00007115 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00007116 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00007117 if (SubStmt.isInvalid()) {
7118 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00007119 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00007120 }
Mike Stump11289f42009-09-09 15:08:12 +00007121
Douglas Gregora16548e2009-08-11 05:31:07 +00007122 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00007123 SubStmt.get() == E->getSubStmt()) {
7124 // Calling this an 'error' is unintuitive, but it does the right thing.
7125 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007126 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00007127 }
Mike Stump11289f42009-09-09 15:08:12 +00007128
7129 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007130 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007131 E->getRParenLoc());
7132}
Mike Stump11289f42009-09-09 15:08:12 +00007133
Douglas Gregora16548e2009-08-11 05:31:07 +00007134template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007135ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007136TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007137 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007138 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007139 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007140
John McCalldadc5752010-08-24 06:29:42 +00007141 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007142 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007143 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007144
John McCalldadc5752010-08-24 06:29:42 +00007145 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007146 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007147 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007148
Douglas Gregora16548e2009-08-11 05:31:07 +00007149 if (!getDerived().AlwaysRebuild() &&
7150 Cond.get() == E->getCond() &&
7151 LHS.get() == E->getLHS() &&
7152 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00007153 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007154
Douglas Gregora16548e2009-08-11 05:31:07 +00007155 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00007156 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007157 E->getRParenLoc());
7158}
Mike Stump11289f42009-09-09 15:08:12 +00007159
Douglas Gregora16548e2009-08-11 05:31:07 +00007160template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007161ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007162TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007163 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007164}
7165
7166template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007167ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007168TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007169 switch (E->getOperator()) {
7170 case OO_New:
7171 case OO_Delete:
7172 case OO_Array_New:
7173 case OO_Array_Delete:
7174 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00007175
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007176 case OO_Call: {
7177 // This is a call to an object's operator().
7178 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7179
7180 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00007181 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007182 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007183 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007184
7185 // FIXME: Poor location information
7186 SourceLocation FakeLParenLoc
7187 = SemaRef.PP.getLocForEndOfToken(
7188 static_cast<Expr *>(Object.get())->getLocEnd());
7189
7190 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007191 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007192 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00007193 Args))
7194 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007195
John McCallb268a282010-08-23 23:25:46 +00007196 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007197 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007198 E->getLocEnd());
7199 }
7200
7201#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7202 case OO_##Name:
7203#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7204#include "clang/Basic/OperatorKinds.def"
7205 case OO_Subscript:
7206 // Handled below.
7207 break;
7208
7209 case OO_Conditional:
7210 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007211
7212 case OO_None:
7213 case NUM_OVERLOADED_OPERATORS:
7214 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007215 }
7216
John McCalldadc5752010-08-24 06:29:42 +00007217 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007218 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007219 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007220
Richard Smithdb2630f2012-10-21 03:28:35 +00007221 ExprResult First;
7222 if (E->getOperator() == OO_Amp)
7223 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7224 else
7225 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007226 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007227 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007228
John McCalldadc5752010-08-24 06:29:42 +00007229 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00007230 if (E->getNumArgs() == 2) {
7231 Second = getDerived().TransformExpr(E->getArg(1));
7232 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007233 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007234 }
Mike Stump11289f42009-09-09 15:08:12 +00007235
Douglas Gregora16548e2009-08-11 05:31:07 +00007236 if (!getDerived().AlwaysRebuild() &&
7237 Callee.get() == E->getCallee() &&
7238 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00007239 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007240 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007241
Lang Hames5de91cc2012-10-02 04:45:10 +00007242 Sema::FPContractStateRAII FPContractState(getSema());
7243 getSema().FPFeatures.fp_contract = E->isFPContractable();
7244
Douglas Gregora16548e2009-08-11 05:31:07 +00007245 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7246 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00007247 Callee.get(),
7248 First.get(),
7249 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007250}
Mike Stump11289f42009-09-09 15:08:12 +00007251
Douglas Gregora16548e2009-08-11 05:31:07 +00007252template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007253ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007254TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7255 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007256}
Mike Stump11289f42009-09-09 15:08:12 +00007257
Douglas Gregora16548e2009-08-11 05:31:07 +00007258template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007259ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00007260TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7261 // Transform the callee.
7262 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7263 if (Callee.isInvalid())
7264 return ExprError();
7265
7266 // Transform exec config.
7267 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7268 if (EC.isInvalid())
7269 return ExprError();
7270
7271 // Transform arguments.
7272 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007273 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007274 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007275 &ArgChanged))
7276 return ExprError();
7277
7278 if (!getDerived().AlwaysRebuild() &&
7279 Callee.get() == E->getCallee() &&
7280 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007281 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00007282
7283 // FIXME: Wrong source location information for the '('.
7284 SourceLocation FakeLParenLoc
7285 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7286 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007287 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007288 E->getRParenLoc(), EC.get());
7289}
7290
7291template<typename Derived>
7292ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007293TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007294 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7295 if (!Type)
7296 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007297
John McCalldadc5752010-08-24 06:29:42 +00007298 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007299 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007300 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007301 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007302
Douglas Gregora16548e2009-08-11 05:31:07 +00007303 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007304 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007305 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007306 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007307 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00007308 E->getStmtClass(),
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007309 E->getAngleBrackets().getBegin(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007310 Type,
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007311 E->getAngleBrackets().getEnd(),
7312 // FIXME. this should be '(' location
7313 E->getAngleBrackets().getEnd(),
John McCallb268a282010-08-23 23:25:46 +00007314 SubExpr.get(),
Abramo Bagnara9fb43862012-10-15 21:08:58 +00007315 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007316}
Mike Stump11289f42009-09-09 15:08:12 +00007317
Douglas Gregora16548e2009-08-11 05:31:07 +00007318template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007319ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007320TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7321 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007322}
Mike Stump11289f42009-09-09 15:08:12 +00007323
7324template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007325ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007326TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7327 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00007328}
7329
Douglas Gregora16548e2009-08-11 05:31:07 +00007330template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007331ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007332TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007333 CXXReinterpretCastExpr *E) {
7334 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007335}
Mike Stump11289f42009-09-09 15:08:12 +00007336
Douglas Gregora16548e2009-08-11 05:31:07 +00007337template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007338ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007339TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7340 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007341}
Mike Stump11289f42009-09-09 15:08:12 +00007342
Douglas Gregora16548e2009-08-11 05:31:07 +00007343template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007344ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007345TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007346 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007347 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7348 if (!Type)
7349 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007350
John McCalldadc5752010-08-24 06:29:42 +00007351 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007352 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007353 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007354 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007355
Douglas Gregora16548e2009-08-11 05:31:07 +00007356 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007357 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007358 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007359 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007360
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007361 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00007362 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007363 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007364 E->getRParenLoc());
7365}
Mike Stump11289f42009-09-09 15:08:12 +00007366
Douglas Gregora16548e2009-08-11 05:31:07 +00007367template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007368ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007369TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007370 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00007371 TypeSourceInfo *TInfo
7372 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7373 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007374 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007375
Douglas Gregora16548e2009-08-11 05:31:07 +00007376 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00007377 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007378 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007379
Douglas Gregor9da64192010-04-26 22:37:10 +00007380 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7381 E->getLocStart(),
7382 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007383 E->getLocEnd());
7384 }
Mike Stump11289f42009-09-09 15:08:12 +00007385
Eli Friedman456f0182012-01-20 01:26:23 +00007386 // We don't know whether the subexpression is potentially evaluated until
7387 // after we perform semantic analysis. We speculatively assume it is
7388 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00007389 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00007390 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7391 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007392
John McCalldadc5752010-08-24 06:29:42 +00007393 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00007394 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007395 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007396
Douglas Gregora16548e2009-08-11 05:31:07 +00007397 if (!getDerived().AlwaysRebuild() &&
7398 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00007399 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007400
Douglas Gregor9da64192010-04-26 22:37:10 +00007401 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7402 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007403 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007404 E->getLocEnd());
7405}
7406
7407template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007408ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00007409TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7410 if (E->isTypeOperand()) {
7411 TypeSourceInfo *TInfo
7412 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7413 if (!TInfo)
7414 return ExprError();
7415
7416 if (!getDerived().AlwaysRebuild() &&
7417 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007418 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00007419
Douglas Gregor69735112011-03-06 17:40:41 +00007420 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00007421 E->getLocStart(),
7422 TInfo,
7423 E->getLocEnd());
7424 }
7425
Francois Pichet9f4f2072010-09-08 12:20:18 +00007426 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7427
7428 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7429 if (SubExpr.isInvalid())
7430 return ExprError();
7431
7432 if (!getDerived().AlwaysRebuild() &&
7433 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00007434 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00007435
7436 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7437 E->getLocStart(),
7438 SubExpr.get(),
7439 E->getLocEnd());
7440}
7441
7442template<typename Derived>
7443ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007444TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007445 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007446}
Mike Stump11289f42009-09-09 15:08:12 +00007447
Douglas Gregora16548e2009-08-11 05:31:07 +00007448template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007449ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007450TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007451 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007452 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007453}
Mike Stump11289f42009-09-09 15:08:12 +00007454
Douglas Gregora16548e2009-08-11 05:31:07 +00007455template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007456ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007457TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00007458 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00007459
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007460 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7461 // Make sure that we capture 'this'.
7462 getSema().CheckCXXThisCapture(E->getLocStart());
John McCallc3007a22010-10-26 07:05:15 +00007463 return SemaRef.Owned(E);
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007464 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007465
Douglas Gregorb15af892010-01-07 23:12:05 +00007466 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007467}
Mike Stump11289f42009-09-09 15:08:12 +00007468
Douglas Gregora16548e2009-08-11 05:31:07 +00007469template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007470ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007471TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007472 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007473 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007474 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007475
Douglas Gregora16548e2009-08-11 05:31:07 +00007476 if (!getDerived().AlwaysRebuild() &&
7477 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007478 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007479
Douglas Gregor53e191ed2011-07-06 22:04:06 +00007480 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7481 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00007482}
Mike Stump11289f42009-09-09 15:08:12 +00007483
Douglas Gregora16548e2009-08-11 05:31:07 +00007484template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007485ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007486TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00007487 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007488 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7489 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007490 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00007491 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007492
Chandler Carruth794da4c2010-02-08 06:42:49 +00007493 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007494 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00007495 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007496
Douglas Gregor033f6752009-12-23 23:03:06 +00007497 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00007498}
Mike Stump11289f42009-09-09 15:08:12 +00007499
Douglas Gregora16548e2009-08-11 05:31:07 +00007500template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007501ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00007502TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
7503 FieldDecl *Field
7504 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
7505 E->getField()));
7506 if (!Field)
7507 return ExprError();
7508
7509 if (!getDerived().AlwaysRebuild() && Field == E->getField())
7510 return SemaRef.Owned(E);
7511
7512 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
7513}
7514
7515template<typename Derived>
7516ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00007517TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7518 CXXScalarValueInitExpr *E) {
7519 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7520 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007521 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007522
Douglas Gregora16548e2009-08-11 05:31:07 +00007523 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007524 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007525 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007526
Chad Rosier1dcde962012-08-08 18:46:20 +00007527 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00007528 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00007529 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007530}
Mike Stump11289f42009-09-09 15:08:12 +00007531
Douglas Gregora16548e2009-08-11 05:31:07 +00007532template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007533ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007534TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007535 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00007536 TypeSourceInfo *AllocTypeInfo
7537 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7538 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007539 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007540
Douglas Gregora16548e2009-08-11 05:31:07 +00007541 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00007542 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00007543 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007544 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007545
Douglas Gregora16548e2009-08-11 05:31:07 +00007546 // Transform the placement arguments (if any).
7547 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007548 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00007549 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00007550 E->getNumPlacementArgs(), true,
7551 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00007552 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007553
Sebastian Redl6047f072012-02-16 12:22:20 +00007554 // Transform the initializer (if any).
7555 Expr *OldInit = E->getInitializer();
7556 ExprResult NewInit;
7557 if (OldInit)
7558 NewInit = getDerived().TransformExpr(OldInit);
7559 if (NewInit.isInvalid())
7560 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007561
Sebastian Redl6047f072012-02-16 12:22:20 +00007562 // Transform new operator and delete operator.
Douglas Gregord2d9da02010-02-26 00:38:10 +00007563 FunctionDecl *OperatorNew = 0;
7564 if (E->getOperatorNew()) {
7565 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007566 getDerived().TransformDecl(E->getLocStart(),
7567 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007568 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00007569 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007570 }
7571
7572 FunctionDecl *OperatorDelete = 0;
7573 if (E->getOperatorDelete()) {
7574 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007575 getDerived().TransformDecl(E->getLocStart(),
7576 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007577 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007578 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007579 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007580
Douglas Gregora16548e2009-08-11 05:31:07 +00007581 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00007582 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007583 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00007584 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007585 OperatorNew == E->getOperatorNew() &&
7586 OperatorDelete == E->getOperatorDelete() &&
7587 !ArgumentChanged) {
7588 // Mark any declarations we need as referenced.
7589 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00007590 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007591 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007592 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007593 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00007594
Sebastian Redl6047f072012-02-16 12:22:20 +00007595 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00007596 QualType ElementType
7597 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7598 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7599 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7600 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00007601 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00007602 }
7603 }
7604 }
Sebastian Redl6047f072012-02-16 12:22:20 +00007605
John McCallc3007a22010-10-26 07:05:15 +00007606 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007607 }
Mike Stump11289f42009-09-09 15:08:12 +00007608
Douglas Gregor0744ef62010-09-07 21:49:58 +00007609 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007610 if (!ArraySize.get()) {
7611 // If no array size was specified, but the new expression was
7612 // instantiated with an array type (e.g., "new T" where T is
7613 // instantiated with "int[4]"), extract the outer bound from the
7614 // array type as our array size. We do this with constant and
7615 // dependently-sized array types.
7616 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7617 if (!ArrayT) {
7618 // Do nothing
7619 } else if (const ConstantArrayType *ConsArrayT
7620 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007621 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007622 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier1dcde962012-08-08 18:46:20 +00007623 ConsArrayT->getSize(),
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007624 SemaRef.Context.getSizeType(),
7625 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007626 AllocType = ConsArrayT->getElementType();
7627 } else if (const DependentSizedArrayType *DepArrayT
7628 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7629 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00007630 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007631 AllocType = DepArrayT->getElementType();
7632 }
7633 }
7634 }
Sebastian Redl6047f072012-02-16 12:22:20 +00007635
Douglas Gregora16548e2009-08-11 05:31:07 +00007636 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7637 E->isGlobalNew(),
7638 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007639 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007640 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00007641 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007642 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00007643 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00007644 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00007645 E->getDirectInitRange(),
7646 NewInit.take());
Douglas Gregora16548e2009-08-11 05:31:07 +00007647}
Mike Stump11289f42009-09-09 15:08:12 +00007648
Douglas Gregora16548e2009-08-11 05:31:07 +00007649template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007650ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007651TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007652 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00007653 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007654 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007655
Douglas Gregord2d9da02010-02-26 00:38:10 +00007656 // Transform the delete operator, if known.
7657 FunctionDecl *OperatorDelete = 0;
7658 if (E->getOperatorDelete()) {
7659 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007660 getDerived().TransformDecl(E->getLocStart(),
7661 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007662 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007663 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007664 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007665
Douglas Gregora16548e2009-08-11 05:31:07 +00007666 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007667 Operand.get() == E->getArgument() &&
7668 OperatorDelete == E->getOperatorDelete()) {
7669 // Mark any declarations we need as referenced.
7670 // FIXME: instantiation-specific.
7671 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007672 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00007673
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00007674 if (!E->getArgument()->isTypeDependent()) {
7675 QualType Destroyed = SemaRef.Context.getBaseElementType(
7676 E->getDestroyedType());
7677 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7678 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00007679 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00007680 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00007681 }
7682 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007683
John McCallc3007a22010-10-26 07:05:15 +00007684 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007685 }
Mike Stump11289f42009-09-09 15:08:12 +00007686
Douglas Gregora16548e2009-08-11 05:31:07 +00007687 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7688 E->isGlobalDelete(),
7689 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00007690 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007691}
Mike Stump11289f42009-09-09 15:08:12 +00007692
Douglas Gregora16548e2009-08-11 05:31:07 +00007693template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007694ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00007695TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007696 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007697 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00007698 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007699 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007700
John McCallba7bf592010-08-24 05:47:05 +00007701 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00007702 bool MayBePseudoDestructor = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00007703 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007704 E->getOperatorLoc(),
7705 E->isArrow()? tok::arrow : tok::period,
7706 ObjectTypePtr,
7707 MayBePseudoDestructor);
7708 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007709 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007710
John McCallba7bf592010-08-24 05:47:05 +00007711 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00007712 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7713 if (QualifierLoc) {
7714 QualifierLoc
7715 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7716 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00007717 return ExprError();
7718 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00007719 CXXScopeSpec SS;
7720 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00007721
Douglas Gregor678f90d2010-02-25 01:56:36 +00007722 PseudoDestructorTypeStorage Destroyed;
7723 if (E->getDestroyedTypeInfo()) {
7724 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00007725 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00007726 ObjectType, 0, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00007727 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007728 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00007729 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00007730 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00007731 // We aren't likely to be able to resolve the identifier down to a type
7732 // now anyway, so just retain the identifier.
7733 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7734 E->getDestroyedTypeLoc());
7735 } else {
7736 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00007737 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007738 *E->getDestroyedTypeIdentifier(),
7739 E->getDestroyedTypeLoc(),
7740 /*Scope=*/0,
7741 SS, ObjectTypePtr,
7742 false);
7743 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007744 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007745
Douglas Gregor678f90d2010-02-25 01:56:36 +00007746 Destroyed
7747 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7748 E->getDestroyedTypeLoc());
7749 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007750
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007751 TypeSourceInfo *ScopeTypeInfo = 0;
7752 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00007753 CXXScopeSpec EmptySS;
7754 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
7755 E->getScopeTypeInfo(), ObjectType, 0, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007756 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007757 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00007758 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007759
John McCallb268a282010-08-23 23:25:46 +00007760 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00007761 E->getOperatorLoc(),
7762 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00007763 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007764 ScopeTypeInfo,
7765 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007766 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007767 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00007768}
Mike Stump11289f42009-09-09 15:08:12 +00007769
Douglas Gregorad8a3362009-09-04 17:36:40 +00007770template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007771ExprResult
John McCalld14a8642009-11-21 08:51:07 +00007772TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007773 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00007774 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7775 Sema::LookupOrdinaryName);
7776
7777 // Transform all the decls.
7778 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7779 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007780 NamedDecl *InstD = static_cast<NamedDecl*>(
7781 getDerived().TransformDecl(Old->getNameLoc(),
7782 *I));
John McCall84d87672009-12-10 09:41:52 +00007783 if (!InstD) {
7784 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7785 // This can happen because of dependent hiding.
7786 if (isa<UsingShadowDecl>(*I))
7787 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00007788 else {
7789 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007790 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00007791 }
John McCall84d87672009-12-10 09:41:52 +00007792 }
John McCalle66edc12009-11-24 19:00:30 +00007793
7794 // Expand using declarations.
7795 if (isa<UsingDecl>(InstD)) {
7796 UsingDecl *UD = cast<UsingDecl>(InstD);
7797 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7798 E = UD->shadow_end(); I != E; ++I)
7799 R.addDecl(*I);
7800 continue;
7801 }
7802
7803 R.addDecl(InstD);
7804 }
7805
7806 // Resolve a kind, but don't do any further analysis. If it's
7807 // ambiguous, the callee needs to deal with it.
7808 R.resolveKind();
7809
7810 // Rebuild the nested-name qualifier, if present.
7811 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00007812 if (Old->getQualifierLoc()) {
7813 NestedNameSpecifierLoc QualifierLoc
7814 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7815 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007816 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007817
Douglas Gregor0da1d432011-02-28 20:01:57 +00007818 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00007819 }
7820
Douglas Gregor9262f472010-04-27 18:19:34 +00007821 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00007822 CXXRecordDecl *NamingClass
7823 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7824 Old->getNameLoc(),
7825 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00007826 if (!NamingClass) {
7827 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007828 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00007829 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007830
Douglas Gregorda7be082010-04-27 16:10:10 +00007831 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00007832 }
7833
Abramo Bagnara7945c982012-01-27 09:46:47 +00007834 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7835
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00007836 // If we have neither explicit template arguments, nor the template keyword,
7837 // it's a normal declaration name.
7838 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCalle66edc12009-11-24 19:00:30 +00007839 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7840
7841 // If we have template arguments, rebuild them, then rebuild the
7842 // templateid expression.
7843 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00007844 if (Old->hasExplicitTemplateArgs() &&
7845 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00007846 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00007847 TransArgs)) {
7848 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00007849 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00007850 }
John McCalle66edc12009-11-24 19:00:30 +00007851
Abramo Bagnara7945c982012-01-27 09:46:47 +00007852 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00007853 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007854}
Mike Stump11289f42009-09-09 15:08:12 +00007855
Douglas Gregora16548e2009-08-11 05:31:07 +00007856template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007857ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00007858TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7859 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00007860 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00007861 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7862 TypeSourceInfo *From = E->getArg(I);
7863 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00007864 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00007865 TypeLocBuilder TLB;
7866 TLB.reserve(FromTL.getFullDataSize());
7867 QualType To = getDerived().TransformType(TLB, FromTL);
7868 if (To.isNull())
7869 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007870
Douglas Gregor29c42f22012-02-24 07:38:34 +00007871 if (To == From->getType())
7872 Args.push_back(From);
7873 else {
7874 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7875 ArgChanged = true;
7876 }
7877 continue;
7878 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007879
Douglas Gregor29c42f22012-02-24 07:38:34 +00007880 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00007881
Douglas Gregor29c42f22012-02-24 07:38:34 +00007882 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00007883 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00007884 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7885 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7886 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00007887
Douglas Gregor29c42f22012-02-24 07:38:34 +00007888 // Determine whether the set of unexpanded parameter packs can and should
7889 // be expanded.
7890 bool Expand = true;
7891 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00007892 Optional<unsigned> OrigNumExpansions =
7893 ExpansionTL.getTypePtr()->getNumExpansions();
7894 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00007895 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7896 PatternTL.getSourceRange(),
7897 Unexpanded,
7898 Expand, RetainExpansion,
7899 NumExpansions))
7900 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007901
Douglas Gregor29c42f22012-02-24 07:38:34 +00007902 if (!Expand) {
7903 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00007904 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00007905 // expansion.
7906 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00007907
Douglas Gregor29c42f22012-02-24 07:38:34 +00007908 TypeLocBuilder TLB;
7909 TLB.reserve(From->getTypeLoc().getFullDataSize());
7910
7911 QualType To = getDerived().TransformType(TLB, PatternTL);
7912 if (To.isNull())
7913 return ExprError();
7914
Chad Rosier1dcde962012-08-08 18:46:20 +00007915 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00007916 PatternTL.getSourceRange(),
7917 ExpansionTL.getEllipsisLoc(),
7918 NumExpansions);
7919 if (To.isNull())
7920 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007921
Douglas Gregor29c42f22012-02-24 07:38:34 +00007922 PackExpansionTypeLoc ToExpansionTL
7923 = TLB.push<PackExpansionTypeLoc>(To);
7924 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7925 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7926 continue;
7927 }
7928
7929 // Expand the pack expansion by substituting for each argument in the
7930 // pack(s).
7931 for (unsigned I = 0; I != *NumExpansions; ++I) {
7932 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7933 TypeLocBuilder TLB;
7934 TLB.reserve(PatternTL.getFullDataSize());
7935 QualType To = getDerived().TransformType(TLB, PatternTL);
7936 if (To.isNull())
7937 return ExprError();
7938
Eli Friedman5e05c4a2013-07-19 21:49:32 +00007939 if (To->containsUnexpandedParameterPack()) {
7940 To = getDerived().RebuildPackExpansionType(To,
7941 PatternTL.getSourceRange(),
7942 ExpansionTL.getEllipsisLoc(),
7943 NumExpansions);
7944 if (To.isNull())
7945 return ExprError();
7946
7947 PackExpansionTypeLoc ToExpansionTL
7948 = TLB.push<PackExpansionTypeLoc>(To);
7949 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7950 }
7951
Douglas Gregor29c42f22012-02-24 07:38:34 +00007952 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7953 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007954
Douglas Gregor29c42f22012-02-24 07:38:34 +00007955 if (!RetainExpansion)
7956 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00007957
Douglas Gregor29c42f22012-02-24 07:38:34 +00007958 // If we're supposed to retain a pack expansion, do so by temporarily
7959 // forgetting the partially-substituted parameter pack.
7960 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7961
7962 TypeLocBuilder TLB;
7963 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00007964
Douglas Gregor29c42f22012-02-24 07:38:34 +00007965 QualType To = getDerived().TransformType(TLB, PatternTL);
7966 if (To.isNull())
7967 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007968
7969 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00007970 PatternTL.getSourceRange(),
7971 ExpansionTL.getEllipsisLoc(),
7972 NumExpansions);
7973 if (To.isNull())
7974 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007975
Douglas Gregor29c42f22012-02-24 07:38:34 +00007976 PackExpansionTypeLoc ToExpansionTL
7977 = TLB.push<PackExpansionTypeLoc>(To);
7978 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7979 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7980 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007981
Douglas Gregor29c42f22012-02-24 07:38:34 +00007982 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7983 return SemaRef.Owned(E);
7984
7985 return getDerived().RebuildTypeTrait(E->getTrait(),
7986 E->getLocStart(),
7987 Args,
7988 E->getLocEnd());
7989}
7990
7991template<typename Derived>
7992ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00007993TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7994 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7995 if (!T)
7996 return ExprError();
7997
7998 if (!getDerived().AlwaysRebuild() &&
7999 T == E->getQueriedTypeSourceInfo())
8000 return SemaRef.Owned(E);
8001
8002 ExprResult SubExpr;
8003 {
8004 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8005 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8006 if (SubExpr.isInvalid())
8007 return ExprError();
8008
8009 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
8010 return SemaRef.Owned(E);
8011 }
8012
8013 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8014 E->getLocStart(),
8015 T,
8016 SubExpr.get(),
8017 E->getLocEnd());
8018}
8019
8020template<typename Derived>
8021ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00008022TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8023 ExprResult SubExpr;
8024 {
8025 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8026 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8027 if (SubExpr.isInvalid())
8028 return ExprError();
8029
8030 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
8031 return SemaRef.Owned(E);
8032 }
8033
8034 return getDerived().RebuildExpressionTrait(
8035 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8036}
8037
8038template<typename Derived>
8039ExprResult
John McCall8cd78132009-11-19 22:55:06 +00008040TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008041 DependentScopeDeclRefExpr *E) {
Richard Smithdb2630f2012-10-21 03:28:35 +00008042 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
8043}
8044
8045template<typename Derived>
8046ExprResult
8047TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8048 DependentScopeDeclRefExpr *E,
8049 bool IsAddressOfOperand) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00008050 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008051 NestedNameSpecifierLoc QualifierLoc
8052 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8053 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008054 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00008055 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008056
John McCall31f82722010-11-12 08:19:04 +00008057 // TODO: If this is a conversion-function-id, verify that the
8058 // destination type name (if present) resolves the same way after
8059 // instantiation as it did in the local scope.
8060
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008061 DeclarationNameInfo NameInfo
8062 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8063 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008064 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008065
John McCalle66edc12009-11-24 19:00:30 +00008066 if (!E->hasExplicitTemplateArgs()) {
8067 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008068 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008069 // Note: it is sufficient to compare the Name component of NameInfo:
8070 // if name has not changed, DNLoc has not changed either.
8071 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00008072 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00008073
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008074 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008075 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008076 NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00008077 /*TemplateArgs*/ 0,
8078 IsAddressOfOperand);
Douglas Gregord019ff62009-10-22 17:20:55 +00008079 }
John McCall6b51f282009-11-23 01:53:49 +00008080
8081 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008082 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8083 E->getNumTemplateArgs(),
8084 TransArgs))
8085 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008086
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008087 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008088 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008089 NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00008090 &TransArgs,
8091 IsAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00008092}
8093
8094template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008095ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008096TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00008097 // CXXConstructExprs other than for list-initialization and
8098 // CXXTemporaryObjectExpr are always implicit, so when we have
8099 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00008100 if ((E->getNumArgs() == 1 ||
8101 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00008102 (!getDerived().DropCallArgument(E->getArg(0))) &&
8103 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00008104 return getDerived().TransformExpr(E->getArg(0));
8105
Douglas Gregora16548e2009-08-11 05:31:07 +00008106 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8107
8108 QualType T = getDerived().TransformType(E->getType());
8109 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008110 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008111
8112 CXXConstructorDecl *Constructor
8113 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008114 getDerived().TransformDecl(E->getLocStart(),
8115 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008116 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008117 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008118
Douglas Gregora16548e2009-08-11 05:31:07 +00008119 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008120 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008121 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008122 &ArgumentChanged))
8123 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008124
Douglas Gregora16548e2009-08-11 05:31:07 +00008125 if (!getDerived().AlwaysRebuild() &&
8126 T == E->getType() &&
8127 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00008128 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00008129 // Mark the constructor as referenced.
8130 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008131 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00008132 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00008133 }
Mike Stump11289f42009-09-09 15:08:12 +00008134
Douglas Gregordb121ba2009-12-14 16:27:04 +00008135 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8136 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008137 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00008138 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00008139 E->isListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00008140 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00008141 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00008142 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008143}
Mike Stump11289f42009-09-09 15:08:12 +00008144
Douglas Gregora16548e2009-08-11 05:31:07 +00008145/// \brief Transform a C++ temporary-binding expression.
8146///
Douglas Gregor363b1512009-12-24 18:51:59 +00008147/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8148/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008149template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008150ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008151TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008152 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008153}
Mike Stump11289f42009-09-09 15:08:12 +00008154
John McCall5d413782010-12-06 08:20:24 +00008155/// \brief Transform a C++ expression that contains cleanups that should
8156/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00008157///
John McCall5d413782010-12-06 08:20:24 +00008158/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00008159/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008160template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008161ExprResult
John McCall5d413782010-12-06 08:20:24 +00008162TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008163 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008164}
Mike Stump11289f42009-09-09 15:08:12 +00008165
Douglas Gregora16548e2009-08-11 05:31:07 +00008166template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008167ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008168TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00008169 CXXTemporaryObjectExpr *E) {
8170 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8171 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008172 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008173
Douglas Gregora16548e2009-08-11 05:31:07 +00008174 CXXConstructorDecl *Constructor
8175 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00008176 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008177 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008178 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008179 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008180
Douglas Gregora16548e2009-08-11 05:31:07 +00008181 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008182 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00008183 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00008184 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008185 &ArgumentChanged))
8186 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008187
Douglas Gregora16548e2009-08-11 05:31:07 +00008188 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008189 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008190 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008191 !ArgumentChanged) {
8192 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008193 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00008194 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008195 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008196
Richard Smithd59b8322012-12-19 01:39:02 +00008197 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00008198 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8199 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008200 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008201 E->getLocEnd());
8202}
Mike Stump11289f42009-09-09 15:08:12 +00008203
Douglas Gregora16548e2009-08-11 05:31:07 +00008204template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008205ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00008206TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008207
8208 // Transform any init-capture expressions before entering the scope of the
8209 // lambda body, because they are not semantically within that scope.
8210 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
8211 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
8212 E->explicit_capture_begin());
8213
8214 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8215 CEnd = E->capture_end();
8216 C != CEnd; ++C) {
8217 if (!C->isInitCapture())
8218 continue;
8219 EnterExpressionEvaluationContext EEEC(getSema(),
8220 Sema::PotentiallyEvaluated);
8221 ExprResult NewExprInitResult = getDerived().TransformInitializer(
8222 C->getCapturedVar()->getInit(),
8223 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
8224
8225 if (NewExprInitResult.isInvalid())
8226 return ExprError();
8227 Expr *NewExprInit = NewExprInitResult.get();
8228
8229 VarDecl *OldVD = C->getCapturedVar();
8230 QualType NewInitCaptureType =
8231 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
8232 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
8233 NewExprInit);
8234 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008235 InitCaptureExprsAndTypes[C - E->capture_begin()] =
8236 std::make_pair(NewExprInitResult, NewInitCaptureType);
8237
8238 }
8239
Faisal Vali524ca282013-11-12 01:40:44 +00008240 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
Faisal Vali2cba1332013-10-23 06:44:28 +00008241 // Transform the template parameters, and add them to the current
8242 // instantiation scope. The null case is handled correctly.
8243 LSI->GLTemplateParameterList = getDerived().TransformTemplateParameterList(
8244 E->getTemplateParameterList());
8245
8246 // Check to see if the TypeSourceInfo of the call operator needs to
8247 // be transformed, and if so do the transformation in the
8248 // CurrentInstantiationScope.
8249
8250 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
8251 FunctionProtoTypeLoc OldCallOpFPTL =
8252 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
8253 TypeSourceInfo *NewCallOpTSI = 0;
8254
8255 const bool CallOpWasAlreadyTransformed =
8256 getDerived().AlreadyTransformed(OldCallOpTSI->getType());
8257
8258 // Use the Old Call Operator's TypeSourceInfo if it is already transformed.
8259 if (CallOpWasAlreadyTransformed)
8260 NewCallOpTSI = OldCallOpTSI;
8261 else {
8262 // Transform the TypeSourceInfo of the Original Lambda's Call Operator.
8263 // The transformation MUST be done in the CurrentInstantiationScope since
8264 // it introduces a mapping of the original to the newly created
8265 // transformed parameters.
8266
8267 TypeLocBuilder NewCallOpTLBuilder;
8268 QualType NewCallOpType = TransformFunctionProtoType(NewCallOpTLBuilder,
8269 OldCallOpFPTL,
8270 0, 0);
8271 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
8272 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00008273 }
Faisal Vali2cba1332013-10-23 06:44:28 +00008274 // Extract the ParmVarDecls from the NewCallOpTSI and add them to
8275 // the vector below - this will be used to synthesize the
8276 // NewCallOperator. Additionally, add the parameters of the untransformed
8277 // lambda call operator to the CurrentInstantiationScope.
8278 SmallVector<ParmVarDecl *, 4> Params;
8279 {
8280 FunctionProtoTypeLoc NewCallOpFPTL =
8281 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>();
8282 ParmVarDecl **NewParamDeclArray = NewCallOpFPTL.getParmArray();
8283 const unsigned NewNumArgs = NewCallOpFPTL.getNumArgs();
8284
8285 for (unsigned I = 0; I < NewNumArgs; ++I) {
8286 // If this call operator's type does not require transformation,
8287 // the parameters do not get added to the current instantiation scope,
8288 // - so ADD them! This allows the following to compile when the enclosing
8289 // template is specialized and the entire lambda expression has to be
8290 // transformed.
8291 // template<class T> void foo(T t) {
8292 // auto L = [](auto a) {
8293 // auto M = [](char b) { <-- note: non-generic lambda
8294 // auto N = [](auto c) {
8295 // int x = sizeof(a);
8296 // x = sizeof(b); <-- specifically this line
8297 // x = sizeof(c);
8298 // };
8299 // };
8300 // };
8301 // }
8302 // foo('a')
8303 if (CallOpWasAlreadyTransformed)
8304 getDerived().transformedLocalDecl(NewParamDeclArray[I],
8305 NewParamDeclArray[I]);
8306 // Add to Params array, so these parameters can be used to create
8307 // the newly transformed call operator.
8308 Params.push_back(NewParamDeclArray[I]);
8309 }
8310 }
8311
8312 if (!NewCallOpTSI)
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008313 return ExprError();
8314
Eli Friedmand564afb2012-09-19 01:18:11 +00008315 // Create the local class that will describe the lambda.
8316 CXXRecordDecl *Class
8317 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008318 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00008319 /*KnownDependent=*/false,
8320 E->getCaptureDefault());
8321
Eli Friedmand564afb2012-09-19 01:18:11 +00008322 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8323
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008324 // Build the call operator.
Faisal Vali2cba1332013-10-23 06:44:28 +00008325 CXXMethodDecl *NewCallOperator
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008326 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008327 NewCallOpTSI,
Douglas Gregoradb376e2012-02-14 22:28:59 +00008328 E->getCallOperator()->getLocEnd(),
Richard Smith505df232012-07-22 23:45:10 +00008329 Params);
Faisal Vali2cba1332013-10-23 06:44:28 +00008330 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00008331
Faisal Vali2cba1332013-10-23 06:44:28 +00008332 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
8333
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008334 return getDerived().TransformLambdaScope(E, NewCallOperator,
8335 InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +00008336}
8337
8338template<typename Derived>
8339ExprResult
8340TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008341 CXXMethodDecl *CallOperator,
8342 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes) {
Richard Smithba71c082013-05-16 06:20:58 +00008343 bool Invalid = false;
8344
Douglas Gregorb4328232012-02-14 00:00:48 +00008345 // Introduce the context of the call operator.
8346 Sema::ContextRAII SavedContext(getSema(), CallOperator);
8347
Faisal Vali2b391ab2013-09-26 19:54:12 +00008348 LambdaScopeInfo *const LSI = getSema().getCurLambda();
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008349 // Enter the scope of the lambda.
Faisal Vali2b391ab2013-09-26 19:54:12 +00008350 getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008351 E->getCaptureDefault(),
James Dennettddd36ff2013-08-09 23:08:25 +00008352 E->getCaptureDefaultLoc(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008353 E->hasExplicitParameters(),
8354 E->hasExplicitResultType(),
8355 E->isMutable());
Chad Rosier1dcde962012-08-08 18:46:20 +00008356
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008357 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008358 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00008359 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008360 CEnd = E->capture_end();
8361 C != CEnd; ++C) {
8362 // When we hit the first implicit capture, tell Sema that we've finished
8363 // the list of explicit captures.
8364 if (!FinishedExplicitCaptures && C->isImplicit()) {
8365 getSema().finishLambdaExplicitCaptures(LSI);
8366 FinishedExplicitCaptures = true;
8367 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008368
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008369 // Capturing 'this' is trivial.
8370 if (C->capturesThis()) {
8371 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8372 continue;
8373 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008374
Richard Smithba71c082013-05-16 06:20:58 +00008375 // Rebuild init-captures, including the implied field declaration.
8376 if (C->isInitCapture()) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008377
8378 InitCaptureInfoTy InitExprTypePair =
8379 InitCaptureExprsAndTypes[C - E->capture_begin()];
8380 ExprResult Init = InitExprTypePair.first;
8381 QualType InitQualType = InitExprTypePair.second;
8382 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00008383 Invalid = true;
8384 continue;
8385 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00008386 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008387 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
8388 OldVD->getLocation(), InitExprTypePair.second,
8389 OldVD->getIdentifier(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00008390 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00008391 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008392 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00008393 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008394 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00008395 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00008396 continue;
8397 }
8398
8399 assert(C->capturesVariable() && "unexpected kind of lambda capture");
8400
Douglas Gregor3e308b12012-02-14 19:27:52 +00008401 // Determine the capture kind for Sema.
8402 Sema::TryCaptureKind Kind
8403 = C->isImplicit()? Sema::TryCapture_Implicit
8404 : C->getCaptureKind() == LCK_ByCopy
8405 ? Sema::TryCapture_ExplicitByVal
8406 : Sema::TryCapture_ExplicitByRef;
8407 SourceLocation EllipsisLoc;
8408 if (C->isPackExpansion()) {
8409 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8410 bool ShouldExpand = false;
8411 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008412 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00008413 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8414 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008415 Unexpanded,
8416 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00008417 NumExpansions)) {
8418 Invalid = true;
8419 continue;
8420 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008421
Douglas Gregor3e308b12012-02-14 19:27:52 +00008422 if (ShouldExpand) {
8423 // The transform has determined that we should perform an expansion;
8424 // transform and capture each of the arguments.
8425 // expansion of the pattern. Do so.
8426 VarDecl *Pack = C->getCapturedVar();
8427 for (unsigned I = 0; I != *NumExpansions; ++I) {
8428 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8429 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008430 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008431 Pack));
8432 if (!CapturedVar) {
8433 Invalid = true;
8434 continue;
8435 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008436
Douglas Gregor3e308b12012-02-14 19:27:52 +00008437 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00008438 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8439 }
Douglas Gregor3e308b12012-02-14 19:27:52 +00008440 continue;
8441 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008442
Douglas Gregor3e308b12012-02-14 19:27:52 +00008443 EllipsisLoc = C->getEllipsisLoc();
8444 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008445
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008446 // Transform the captured variable.
8447 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008448 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008449 C->getCapturedVar()));
8450 if (!CapturedVar) {
8451 Invalid = true;
8452 continue;
8453 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008454
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008455 // Capture the transformed variable.
Douglas Gregorfdf598e2012-02-18 09:37:24 +00008456 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008457 }
8458 if (!FinishedExplicitCaptures)
8459 getSema().finishLambdaExplicitCaptures(LSI);
8460
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008461
8462 // Enter a new evaluation context to insulate the lambda from any
8463 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00008464 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008465
8466 if (Invalid) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008467 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008468 /*IsInstantiation=*/true);
8469 return ExprError();
8470 }
8471
8472 // Instantiate the body of the lambda expression.
Douglas Gregorb4328232012-02-14 00:00:48 +00008473 StmtResult Body = getDerived().TransformStmt(E->getBody());
8474 if (Body.isInvalid()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008475 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregorb4328232012-02-14 00:00:48 +00008476 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00008477 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00008478 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00008479
Chad Rosier1dcde962012-08-08 18:46:20 +00008480 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorb61e8092012-04-04 17:40:10 +00008481 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregore31e6062012-02-07 10:09:13 +00008482}
8483
8484template<typename Derived>
8485ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008486TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008487 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00008488 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8489 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008490 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008491
Douglas Gregora16548e2009-08-11 05:31:07 +00008492 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008493 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00008494 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00008495 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008496 &ArgumentChanged))
8497 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008498
Douglas Gregora16548e2009-08-11 05:31:07 +00008499 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008500 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008501 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00008502 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00008503
Douglas Gregora16548e2009-08-11 05:31:07 +00008504 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00008505 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00008506 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008507 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008508 E->getRParenLoc());
8509}
Mike Stump11289f42009-09-09 15:08:12 +00008510
Douglas Gregora16548e2009-08-11 05:31:07 +00008511template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008512ExprResult
John McCall8cd78132009-11-19 22:55:06 +00008513TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008514 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008515 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00008516 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00008517 Expr *OldBase;
8518 QualType BaseType;
8519 QualType ObjectType;
8520 if (!E->isImplicitAccess()) {
8521 OldBase = E->getBase();
8522 Base = getDerived().TransformExpr(OldBase);
8523 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008524 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008525
John McCall2d74de92009-12-01 22:10:20 +00008526 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00008527 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00008528 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00008529 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008530 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008531 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00008532 ObjectTy,
8533 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00008534 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008535 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00008536
John McCallba7bf592010-08-24 05:47:05 +00008537 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00008538 BaseType = ((Expr*) Base.get())->getType();
8539 } else {
8540 OldBase = 0;
8541 BaseType = getDerived().TransformType(E->getBaseType());
8542 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8543 }
Mike Stump11289f42009-09-09 15:08:12 +00008544
Douglas Gregora5cb6da2009-10-20 05:58:46 +00008545 // Transform the first part of the nested-name-specifier that qualifies
8546 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00008547 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00008548 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00008549 E->getFirstQualifierFoundInScope(),
8550 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00008551
Douglas Gregore16af532011-02-28 18:50:33 +00008552 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008553 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00008554 QualifierLoc
8555 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8556 ObjectType,
8557 FirstQualifierInScope);
8558 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008559 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008560 }
Mike Stump11289f42009-09-09 15:08:12 +00008561
Abramo Bagnara7945c982012-01-27 09:46:47 +00008562 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8563
John McCall31f82722010-11-12 08:19:04 +00008564 // TODO: If this is a conversion-function-id, verify that the
8565 // destination type name (if present) resolves the same way after
8566 // instantiation as it did in the local scope.
8567
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008568 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00008569 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008570 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008571 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008572
John McCall2d74de92009-12-01 22:10:20 +00008573 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00008574 // This is a reference to a member without an explicitly-specified
8575 // template argument list. Optimize for this common case.
8576 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00008577 Base.get() == OldBase &&
8578 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00008579 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008580 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00008581 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00008582 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00008583
John McCallb268a282010-08-23 23:25:46 +00008584 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008585 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00008586 E->isArrow(),
8587 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00008588 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008589 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00008590 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008591 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00008592 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00008593 }
8594
John McCall6b51f282009-11-23 01:53:49 +00008595 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008596 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8597 E->getNumTemplateArgs(),
8598 TransArgs))
8599 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008600
John McCallb268a282010-08-23 23:25:46 +00008601 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008602 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00008603 E->isArrow(),
8604 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00008605 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008606 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00008607 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008608 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00008609 &TransArgs);
8610}
8611
8612template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008613ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008614TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00008615 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00008616 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00008617 QualType BaseType;
8618 if (!Old->isImplicitAccess()) {
8619 Base = getDerived().TransformExpr(Old->getBase());
8620 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008621 return ExprError();
Richard Smithcab9a7d2011-10-26 19:06:56 +00008622 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8623 Old->isArrow());
8624 if (Base.isInvalid())
8625 return ExprError();
8626 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +00008627 } else {
8628 BaseType = getDerived().TransformType(Old->getBaseType());
8629 }
John McCall10eae182009-11-30 22:42:35 +00008630
Douglas Gregor0da1d432011-02-28 20:01:57 +00008631 NestedNameSpecifierLoc QualifierLoc;
8632 if (Old->getQualifierLoc()) {
8633 QualifierLoc
8634 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8635 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008636 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00008637 }
8638
Abramo Bagnara7945c982012-01-27 09:46:47 +00008639 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8640
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008641 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00008642 Sema::LookupOrdinaryName);
8643
8644 // Transform all the decls.
8645 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8646 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008647 NamedDecl *InstD = static_cast<NamedDecl*>(
8648 getDerived().TransformDecl(Old->getMemberLoc(),
8649 *I));
John McCall84d87672009-12-10 09:41:52 +00008650 if (!InstD) {
8651 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8652 // This can happen because of dependent hiding.
8653 if (isa<UsingShadowDecl>(*I))
8654 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00008655 else {
8656 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008657 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00008658 }
John McCall84d87672009-12-10 09:41:52 +00008659 }
John McCall10eae182009-11-30 22:42:35 +00008660
8661 // Expand using declarations.
8662 if (isa<UsingDecl>(InstD)) {
8663 UsingDecl *UD = cast<UsingDecl>(InstD);
8664 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8665 E = UD->shadow_end(); I != E; ++I)
8666 R.addDecl(*I);
8667 continue;
8668 }
8669
8670 R.addDecl(InstD);
8671 }
8672
8673 R.resolveKind();
8674
Douglas Gregor9262f472010-04-27 18:19:34 +00008675 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00008676 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008677 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00008678 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00008679 Old->getMemberLoc(),
8680 Old->getNamingClass()));
8681 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00008682 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008683
Douglas Gregorda7be082010-04-27 16:10:10 +00008684 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00008685 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008686
John McCall10eae182009-11-30 22:42:35 +00008687 TemplateArgumentListInfo TransArgs;
8688 if (Old->hasExplicitTemplateArgs()) {
8689 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8690 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008691 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8692 Old->getNumTemplateArgs(),
8693 TransArgs))
8694 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00008695 }
John McCall38836f02010-01-15 08:34:02 +00008696
8697 // FIXME: to do this check properly, we will need to preserve the
8698 // first-qualifier-in-scope here, just in case we had a dependent
8699 // base (and therefore couldn't do the check) and a
8700 // nested-name-qualifier (and therefore could do the lookup).
8701 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00008702
John McCallb268a282010-08-23 23:25:46 +00008703 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008704 BaseType,
John McCall10eae182009-11-30 22:42:35 +00008705 Old->getOperatorLoc(),
8706 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00008707 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008708 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +00008709 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00008710 R,
8711 (Old->hasExplicitTemplateArgs()
8712 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00008713}
8714
8715template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008716ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008717TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00008718 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008719 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8720 if (SubExpr.isInvalid())
8721 return ExprError();
8722
8723 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00008724 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008725
8726 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8727}
8728
8729template<typename Derived>
8730ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008731TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00008732 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8733 if (Pattern.isInvalid())
8734 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008735
Douglas Gregor0f836ea2011-01-13 00:19:55 +00008736 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8737 return SemaRef.Owned(E);
8738
Douglas Gregorb8840002011-01-14 21:20:45 +00008739 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8740 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008741}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008742
8743template<typename Derived>
8744ExprResult
8745TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8746 // If E is not value-dependent, then nothing will change when we transform it.
8747 // Note: This is an instantiation-centric view.
8748 if (!E->isValueDependent())
8749 return SemaRef.Owned(E);
8750
8751 // Note: None of the implementations of TryExpandParameterPacks can ever
8752 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00008753 // so
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008754 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8755 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00008756 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008757 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00008758 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +00008759 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00008760 ShouldExpand, RetainExpansion,
8761 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008762 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008763
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008764 if (RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008765 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00008766
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008767 NamedDecl *Pack = E->getPack();
8768 if (!ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008769 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008770 Pack));
8771 if (!Pack)
8772 return ExprError();
8773 }
8774
Chad Rosier1dcde962012-08-08 18:46:20 +00008775
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008776 // We now know the length of the parameter pack, so build a new expression
8777 // that stores that length.
Chad Rosier1dcde962012-08-08 18:46:20 +00008778 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8779 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008780 NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008781}
8782
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008783template<typename Derived>
8784ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00008785TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8786 SubstNonTypeTemplateParmPackExpr *E) {
8787 // Default behavior is to do nothing with this transformation.
8788 return SemaRef.Owned(E);
8789}
8790
8791template<typename Derived>
8792ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00008793TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8794 SubstNonTypeTemplateParmExpr *E) {
8795 // Default behavior is to do nothing with this transformation.
8796 return SemaRef.Owned(E);
8797}
8798
8799template<typename Derived>
8800ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +00008801TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8802 // Default behavior is to do nothing with this transformation.
8803 return SemaRef.Owned(E);
8804}
8805
8806template<typename Derived>
8807ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00008808TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8809 MaterializeTemporaryExpr *E) {
8810 return getDerived().TransformExpr(E->GetTemporaryExpr());
8811}
Chad Rosier1dcde962012-08-08 18:46:20 +00008812
Douglas Gregorfe314812011-06-21 17:03:29 +00008813template<typename Derived>
8814ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +00008815TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
8816 CXXStdInitializerListExpr *E) {
8817 return getDerived().TransformExpr(E->getSubExpr());
8818}
8819
8820template<typename Derived>
8821ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008822TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00008823 return SemaRef.MaybeBindToTemporary(E);
8824}
8825
8826template<typename Derived>
8827ExprResult
8828TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rose8986c5992012-03-12 17:53:02 +00008829 return SemaRef.Owned(E);
Ted Kremeneke65b0862012-03-06 20:05:56 +00008830}
8831
8832template<typename Derived>
8833ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +00008834TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8835 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8836 if (SubExpr.isInvalid())
8837 return ExprError();
8838
8839 if (!getDerived().AlwaysRebuild() &&
8840 SubExpr.get() == E->getSubExpr())
8841 return SemaRef.Owned(E);
8842
8843 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +00008844}
8845
8846template<typename Derived>
8847ExprResult
8848TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8849 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008850 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00008851 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00008852 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00008853 /*IsCall=*/false, Elements, &ArgChanged))
8854 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008855
Ted Kremeneke65b0862012-03-06 20:05:56 +00008856 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8857 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00008858
Ted Kremeneke65b0862012-03-06 20:05:56 +00008859 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8860 Elements.data(),
8861 Elements.size());
8862}
8863
8864template<typename Derived>
8865ExprResult
8866TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +00008867 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00008868 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008869 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00008870 bool ArgChanged = false;
8871 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8872 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +00008873
Ted Kremeneke65b0862012-03-06 20:05:56 +00008874 if (OrigElement.isPackExpansion()) {
8875 // This key/value element is a pack expansion.
8876 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8877 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8878 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8879 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8880
8881 // Determine whether the set of unexpanded parameter packs can
8882 // and should be expanded.
8883 bool Expand = true;
8884 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008885 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8886 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +00008887 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8888 OrigElement.Value->getLocEnd());
8889 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8890 PatternRange,
8891 Unexpanded,
8892 Expand, RetainExpansion,
8893 NumExpansions))
8894 return ExprError();
8895
8896 if (!Expand) {
8897 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00008898 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +00008899 // expansion.
8900 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8901 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8902 if (Key.isInvalid())
8903 return ExprError();
8904
8905 if (Key.get() != OrigElement.Key)
8906 ArgChanged = true;
8907
8908 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8909 if (Value.isInvalid())
8910 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008911
Ted Kremeneke65b0862012-03-06 20:05:56 +00008912 if (Value.get() != OrigElement.Value)
8913 ArgChanged = true;
8914
Chad Rosier1dcde962012-08-08 18:46:20 +00008915 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00008916 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8917 };
8918 Elements.push_back(Expansion);
8919 continue;
8920 }
8921
8922 // Record right away that the argument was changed. This needs
8923 // to happen even if the array expands to nothing.
8924 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00008925
Ted Kremeneke65b0862012-03-06 20:05:56 +00008926 // The transform has determined that we should perform an elementwise
8927 // expansion of the pattern. Do so.
8928 for (unsigned I = 0; I != *NumExpansions; ++I) {
8929 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8930 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8931 if (Key.isInvalid())
8932 return ExprError();
8933
8934 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8935 if (Value.isInvalid())
8936 return ExprError();
8937
Chad Rosier1dcde962012-08-08 18:46:20 +00008938 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00008939 Key.get(), Value.get(), SourceLocation(), NumExpansions
8940 };
8941
8942 // If any unexpanded parameter packs remain, we still have a
8943 // pack expansion.
8944 if (Key.get()->containsUnexpandedParameterPack() ||
8945 Value.get()->containsUnexpandedParameterPack())
8946 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +00008947
Ted Kremeneke65b0862012-03-06 20:05:56 +00008948 Elements.push_back(Element);
8949 }
8950
8951 // We've finished with this pack expansion.
8952 continue;
8953 }
8954
8955 // Transform and check key.
8956 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8957 if (Key.isInvalid())
8958 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008959
Ted Kremeneke65b0862012-03-06 20:05:56 +00008960 if (Key.get() != OrigElement.Key)
8961 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00008962
Ted Kremeneke65b0862012-03-06 20:05:56 +00008963 // Transform and check value.
8964 ExprResult Value
8965 = getDerived().TransformExpr(OrigElement.Value);
8966 if (Value.isInvalid())
8967 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008968
Ted Kremeneke65b0862012-03-06 20:05:56 +00008969 if (Value.get() != OrigElement.Value)
8970 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00008971
8972 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +00008973 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +00008974 };
8975 Elements.push_back(Element);
8976 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008977
Ted Kremeneke65b0862012-03-06 20:05:56 +00008978 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8979 return SemaRef.MaybeBindToTemporary(E);
8980
8981 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8982 Elements.data(),
8983 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +00008984}
8985
Mike Stump11289f42009-09-09 15:08:12 +00008986template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008987ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008988TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00008989 TypeSourceInfo *EncodedTypeInfo
8990 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8991 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008992 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008993
Douglas Gregora16548e2009-08-11 05:31:07 +00008994 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00008995 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00008996 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008997
8998 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00008999 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009000 E->getRParenLoc());
9001}
Mike Stump11289f42009-09-09 15:08:12 +00009002
Douglas Gregora16548e2009-08-11 05:31:07 +00009003template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +00009004ExprResult TreeTransform<Derived>::
9005TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +00009006 // This is a kind of implicit conversion, and it needs to get dropped
9007 // and recomputed for the same general reasons that ImplicitCastExprs
9008 // do, as well a more specific one: this expression is only valid when
9009 // it appears *immediately* as an argument expression.
9010 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +00009011}
9012
9013template<typename Derived>
9014ExprResult TreeTransform<Derived>::
9015TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009016 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +00009017 = getDerived().TransformType(E->getTypeInfoAsWritten());
9018 if (!TSInfo)
9019 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009020
John McCall31168b02011-06-15 23:02:42 +00009021 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +00009022 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +00009023 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009024
John McCall31168b02011-06-15 23:02:42 +00009025 if (!getDerived().AlwaysRebuild() &&
9026 TSInfo == E->getTypeInfoAsWritten() &&
9027 Result.get() == E->getSubExpr())
9028 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009029
John McCall31168b02011-06-15 23:02:42 +00009030 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +00009031 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +00009032 Result.get());
9033}
9034
9035template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009036ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009037TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009038 // Transform arguments.
9039 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009040 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009041 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009042 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009043 &ArgChanged))
9044 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009045
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009046 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
9047 // Class message: transform the receiver type.
9048 TypeSourceInfo *ReceiverTypeInfo
9049 = getDerived().TransformType(E->getClassReceiverTypeInfo());
9050 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009051 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009052
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009053 // If nothing changed, just retain the existing message send.
9054 if (!getDerived().AlwaysRebuild() &&
9055 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009056 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009057
9058 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009059 SmallVector<SourceLocation, 16> SelLocs;
9060 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009061 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
9062 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009063 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009064 E->getMethodDecl(),
9065 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009066 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009067 E->getRightLoc());
9068 }
9069
9070 // Instance message: transform the receiver
9071 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
9072 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00009073 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009074 = getDerived().TransformExpr(E->getInstanceReceiver());
9075 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009076 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009077
9078 // If nothing changed, just retain the existing message send.
9079 if (!getDerived().AlwaysRebuild() &&
9080 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009081 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009082
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009083 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009084 SmallVector<SourceLocation, 16> SelLocs;
9085 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +00009086 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009087 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009088 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009089 E->getMethodDecl(),
9090 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009091 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009092 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009093}
9094
Mike Stump11289f42009-09-09 15:08:12 +00009095template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009096ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009097TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00009098 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009099}
9100
Mike Stump11289f42009-09-09 15:08:12 +00009101template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009102ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009103TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00009104 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009105}
9106
Mike Stump11289f42009-09-09 15:08:12 +00009107template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009108ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009109TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009110 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009111 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009112 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009113 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00009114
9115 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009116
Douglas Gregord51d90d2010-04-26 20:11:03 +00009117 // If nothing changed, just retain the existing expression.
9118 if (!getDerived().AlwaysRebuild() &&
9119 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00009120 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009121
John McCallb268a282010-08-23 23:25:46 +00009122 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009123 E->getLocation(),
9124 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00009125}
9126
Mike Stump11289f42009-09-09 15:08:12 +00009127template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009128ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009129TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00009130 // 'super' and types never change. Property never changes. Just
9131 // retain the existing expression.
9132 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00009133 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009134
Douglas Gregor9faee212010-04-26 20:47:02 +00009135 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009136 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00009137 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009138 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009139
Douglas Gregor9faee212010-04-26 20:47:02 +00009140 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009141
Douglas Gregor9faee212010-04-26 20:47:02 +00009142 // If nothing changed, just retain the existing expression.
9143 if (!getDerived().AlwaysRebuild() &&
9144 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00009145 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009146
John McCallb7bd14f2010-12-02 01:19:52 +00009147 if (E->isExplicitProperty())
9148 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9149 E->getExplicitProperty(),
9150 E->getLocation());
9151
9152 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +00009153 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +00009154 E->getImplicitPropertyGetter(),
9155 E->getImplicitPropertySetter(),
9156 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00009157}
9158
Mike Stump11289f42009-09-09 15:08:12 +00009159template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009160ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +00009161TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
9162 // Transform the base expression.
9163 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9164 if (Base.isInvalid())
9165 return ExprError();
9166
9167 // Transform the key expression.
9168 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
9169 if (Key.isInvalid())
9170 return ExprError();
9171
9172 // If nothing changed, just retain the existing expression.
9173 if (!getDerived().AlwaysRebuild() &&
9174 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
9175 return SemaRef.Owned(E);
9176
Chad Rosier1dcde962012-08-08 18:46:20 +00009177 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009178 Base.get(), Key.get(),
9179 E->getAtIndexMethodDecl(),
9180 E->setAtIndexMethodDecl());
9181}
9182
9183template<typename Derived>
9184ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009185TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009186 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009187 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009188 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009189 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009190
Douglas Gregord51d90d2010-04-26 20:11:03 +00009191 // If nothing changed, just retain the existing expression.
9192 if (!getDerived().AlwaysRebuild() &&
9193 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00009194 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009195
John McCallb268a282010-08-23 23:25:46 +00009196 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00009197 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009198 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00009199}
9200
Mike Stump11289f42009-09-09 15:08:12 +00009201template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009202ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009203TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009204 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009205 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +00009206 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009207 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00009208 SubExprs, &ArgumentChanged))
9209 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009210
Douglas Gregora16548e2009-08-11 05:31:07 +00009211 if (!getDerived().AlwaysRebuild() &&
9212 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00009213 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00009214
Douglas Gregora16548e2009-08-11 05:31:07 +00009215 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009216 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009217 E->getRParenLoc());
9218}
9219
Mike Stump11289f42009-09-09 15:08:12 +00009220template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009221ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +00009222TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
9223 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
9224 if (SrcExpr.isInvalid())
9225 return ExprError();
9226
9227 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9228 if (!Type)
9229 return ExprError();
9230
9231 if (!getDerived().AlwaysRebuild() &&
9232 Type == E->getTypeSourceInfo() &&
9233 SrcExpr.get() == E->getSrcExpr())
9234 return SemaRef.Owned(E);
9235
9236 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
9237 SrcExpr.get(), Type,
9238 E->getRParenLoc());
9239}
9240
9241template<typename Derived>
9242ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009243TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00009244 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +00009245
John McCall490112f2011-02-04 18:33:18 +00009246 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
9247 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
9248
9249 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +00009250 blockScope->TheDecl->setBlockMissingReturnType(
9251 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +00009252
Chris Lattner01cf8db2011-07-20 06:58:45 +00009253 SmallVector<ParmVarDecl*, 4> params;
9254 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +00009255
Fariborz Jahanian1babe772010-07-09 18:44:02 +00009256 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00009257 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
9258 oldBlock->param_begin(),
9259 oldBlock->param_size(),
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009260 0, paramTypes, &params)) {
9261 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009262 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009263 }
John McCall490112f2011-02-04 18:33:18 +00009264
Jordan Rosea0a86be2013-03-08 22:25:36 +00009265 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +00009266 QualType exprResultType =
9267 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregor476e3022011-01-19 21:32:01 +00009268
Jordan Rose5c382722013-03-08 21:51:21 +00009269 QualType functionType =
9270 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009271 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +00009272 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00009273
9274 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00009275 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +00009276 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +00009277
9278 if (!oldBlock->blockMissingReturnType()) {
9279 blockScope->HasImplicitReturnType = false;
9280 blockScope->ReturnType = exprResultType;
9281 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009282
John McCall3882ace2011-01-05 12:14:39 +00009283 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00009284 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009285 if (body.isInvalid()) {
9286 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall3882ace2011-01-05 12:14:39 +00009287 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009288 }
John McCall3882ace2011-01-05 12:14:39 +00009289
John McCall490112f2011-02-04 18:33:18 +00009290#ifndef NDEBUG
9291 // In builds with assertions, make sure that we captured everything we
9292 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009293 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
9294 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
9295 e = oldBlock->capture_end(); i != e; ++i) {
9296 VarDecl *oldCapture = i->getVariable();
John McCall490112f2011-02-04 18:33:18 +00009297
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009298 // Ignore parameter packs.
9299 if (isa<ParmVarDecl>(oldCapture) &&
9300 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9301 continue;
John McCall490112f2011-02-04 18:33:18 +00009302
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009303 VarDecl *newCapture =
9304 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9305 oldCapture));
9306 assert(blockScope->CaptureMap.count(newCapture));
9307 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009308 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +00009309 }
9310#endif
9311
9312 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
9313 /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00009314}
9315
Mike Stump11289f42009-09-09 15:08:12 +00009316template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009317ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +00009318TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +00009319 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +00009320}
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009321
9322template<typename Derived>
9323ExprResult
9324TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009325 QualType RetTy = getDerived().TransformType(E->getType());
9326 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009327 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009328 SubExprs.reserve(E->getNumSubExprs());
9329 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9330 SubExprs, &ArgumentChanged))
9331 return ExprError();
9332
9333 if (!getDerived().AlwaysRebuild() &&
9334 !ArgumentChanged)
9335 return SemaRef.Owned(E);
9336
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009337 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009338 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009339}
Chad Rosier1dcde962012-08-08 18:46:20 +00009340
Douglas Gregora16548e2009-08-11 05:31:07 +00009341//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00009342// Type reconstruction
9343//===----------------------------------------------------------------------===//
9344
Mike Stump11289f42009-09-09 15:08:12 +00009345template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009346QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9347 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009348 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009349 getDerived().getBaseEntity());
9350}
9351
Mike Stump11289f42009-09-09 15:08:12 +00009352template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009353QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9354 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009355 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009356 getDerived().getBaseEntity());
9357}
9358
Mike Stump11289f42009-09-09 15:08:12 +00009359template<typename Derived>
9360QualType
John McCall70dd5f62009-10-30 00:06:24 +00009361TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9362 bool WrittenAsLValue,
9363 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00009364 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00009365 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009366}
9367
9368template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009369QualType
John McCall70dd5f62009-10-30 00:06:24 +00009370TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9371 QualType ClassType,
9372 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +00009373 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
9374 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009375}
9376
9377template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009378QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00009379TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9380 ArrayType::ArraySizeModifier SizeMod,
9381 const llvm::APInt *Size,
9382 Expr *SizeExpr,
9383 unsigned IndexTypeQuals,
9384 SourceRange BracketsRange) {
9385 if (SizeExpr || !Size)
9386 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9387 IndexTypeQuals, BracketsRange,
9388 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00009389
9390 QualType Types[] = {
9391 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9392 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9393 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00009394 };
Craig Toppere5ce8312013-07-15 03:38:40 +00009395 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009396 QualType SizeType;
9397 for (unsigned I = 0; I != NumTypes; ++I)
9398 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9399 SizeType = Types[I];
9400 break;
9401 }
Mike Stump11289f42009-09-09 15:08:12 +00009402
Eli Friedman9562f392012-01-25 23:20:27 +00009403 // Note that we can return a VariableArrayType here in the case where
9404 // the element type was a dependent VariableArrayType.
9405 IntegerLiteral *ArraySize
9406 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9407 /*FIXME*/BracketsRange.getBegin());
9408 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009409 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00009410 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009411}
Mike Stump11289f42009-09-09 15:08:12 +00009412
Douglas Gregord6ff3322009-08-04 16:50:30 +00009413template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009414QualType
9415TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009416 ArrayType::ArraySizeModifier SizeMod,
9417 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00009418 unsigned IndexTypeQuals,
9419 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009420 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00009421 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009422}
9423
9424template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009425QualType
Mike Stump11289f42009-09-09 15:08:12 +00009426TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009427 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00009428 unsigned IndexTypeQuals,
9429 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009430 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00009431 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009432}
Mike Stump11289f42009-09-09 15:08:12 +00009433
Douglas Gregord6ff3322009-08-04 16:50:30 +00009434template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009435QualType
9436TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009437 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009438 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009439 unsigned IndexTypeQuals,
9440 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009441 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00009442 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009443 IndexTypeQuals, BracketsRange);
9444}
9445
9446template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009447QualType
9448TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009449 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009450 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009451 unsigned IndexTypeQuals,
9452 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009453 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00009454 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009455 IndexTypeQuals, BracketsRange);
9456}
9457
9458template<typename Derived>
9459QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00009460 unsigned NumElements,
9461 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00009462 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00009463 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009464}
Mike Stump11289f42009-09-09 15:08:12 +00009465
Douglas Gregord6ff3322009-08-04 16:50:30 +00009466template<typename Derived>
9467QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9468 unsigned NumElements,
9469 SourceLocation AttributeLoc) {
9470 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9471 NumElements, true);
9472 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00009473 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9474 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00009475 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009476}
Mike Stump11289f42009-09-09 15:08:12 +00009477
Douglas Gregord6ff3322009-08-04 16:50:30 +00009478template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009479QualType
9480TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00009481 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009482 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00009483 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009484}
Mike Stump11289f42009-09-09 15:08:12 +00009485
Douglas Gregord6ff3322009-08-04 16:50:30 +00009486template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +00009487QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9488 QualType T,
9489 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009490 const FunctionProtoType::ExtProtoInfo &EPI) {
9491 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009492 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00009493 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +00009494 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009495}
Mike Stump11289f42009-09-09 15:08:12 +00009496
Douglas Gregord6ff3322009-08-04 16:50:30 +00009497template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00009498QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9499 return SemaRef.Context.getFunctionNoProtoType(T);
9500}
9501
9502template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00009503QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9504 assert(D && "no decl found");
9505 if (D->isInvalidDecl()) return QualType();
9506
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009507 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00009508 TypeDecl *Ty;
9509 if (isa<UsingDecl>(D)) {
9510 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +00009511 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +00009512 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9513
9514 // A valid resolved using typename decl points to exactly one type decl.
9515 assert(++Using->shadow_begin() == Using->shadow_end());
9516 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00009517
John McCallb96ec562009-12-04 22:46:56 +00009518 } else {
9519 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9520 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9521 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9522 }
9523
9524 return SemaRef.Context.getTypeDeclType(Ty);
9525}
9526
9527template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00009528QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9529 SourceLocation Loc) {
9530 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009531}
9532
9533template<typename Derived>
9534QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9535 return SemaRef.Context.getTypeOfType(Underlying);
9536}
9537
9538template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00009539QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9540 SourceLocation Loc) {
9541 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009542}
9543
9544template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00009545QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9546 UnaryTransformType::UTTKind UKind,
9547 SourceLocation Loc) {
9548 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9549}
9550
9551template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00009552QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00009553 TemplateName Template,
9554 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +00009555 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +00009556 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009557}
Mike Stump11289f42009-09-09 15:08:12 +00009558
Douglas Gregor1135c352009-08-06 05:28:30 +00009559template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +00009560QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9561 SourceLocation KWLoc) {
9562 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9563}
9564
9565template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009566TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009567TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00009568 bool TemplateKW,
9569 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +00009570 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00009571 Template);
9572}
9573
9574template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009575TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009576TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9577 const IdentifierInfo &Name,
9578 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00009579 QualType ObjectType,
9580 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +00009581 UnqualifiedId TemplateName;
9582 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +00009583 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +00009584 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +00009585 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009586 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +00009587 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00009588 /*EnteringContext=*/false,
9589 Template);
John McCall31f82722010-11-12 08:19:04 +00009590 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00009591}
Mike Stump11289f42009-09-09 15:08:12 +00009592
Douglas Gregora16548e2009-08-11 05:31:07 +00009593template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00009594TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009595TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00009596 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00009597 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00009598 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +00009599 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +00009600 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +00009601 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +00009602 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +00009603 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +00009604 Sema::TemplateTy Template;
9605 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009606 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +00009607 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00009608 /*EnteringContext=*/false,
9609 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +00009610 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +00009611}
Chad Rosier1dcde962012-08-08 18:46:20 +00009612
Douglas Gregor71395fa2009-11-04 00:56:37 +00009613template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009614ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009615TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9616 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00009617 Expr *OrigCallee,
9618 Expr *First,
9619 Expr *Second) {
9620 Expr *Callee = OrigCallee->IgnoreParenCasts();
9621 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00009622
Douglas Gregora16548e2009-08-11 05:31:07 +00009623 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00009624 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00009625 if (!First->getType()->isOverloadableType() &&
9626 !Second->getType()->isOverloadableType())
9627 return getSema().CreateBuiltinArraySubscriptExpr(First,
9628 Callee->getLocStart(),
9629 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00009630 } else if (Op == OO_Arrow) {
9631 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00009632 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9633 } else if (Second == 0 || isPostIncDec) {
9634 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009635 // The argument is not of overloadable type, so try to create a
9636 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00009637 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00009638 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00009639
John McCallb268a282010-08-23 23:25:46 +00009640 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00009641 }
9642 } else {
John McCallb268a282010-08-23 23:25:46 +00009643 if (!First->getType()->isOverloadableType() &&
9644 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009645 // Neither of the arguments is an overloadable type, so try to
9646 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00009647 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00009648 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00009649 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00009650 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009651 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009652
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009653 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00009654 }
9655 }
Mike Stump11289f42009-09-09 15:08:12 +00009656
9657 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00009658 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00009659 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00009660
John McCallb268a282010-08-23 23:25:46 +00009661 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00009662 assert(ULE->requiresADL());
9663
9664 // FIXME: Do we have to check
9665 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00009666 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00009667 } else {
Richard Smith58db83d2012-11-28 21:47:39 +00009668 // If we've resolved this to a particular non-member function, just call
9669 // that function. If we resolved it to a member function,
9670 // CreateOverloaded* will find that function for us.
9671 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9672 if (!isa<CXXMethodDecl>(ND))
9673 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +00009674 }
Mike Stump11289f42009-09-09 15:08:12 +00009675
Douglas Gregora16548e2009-08-11 05:31:07 +00009676 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00009677 Expr *Args[2] = { First, Second };
9678 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00009679
Douglas Gregora16548e2009-08-11 05:31:07 +00009680 // Create the overloaded operator invocation for unary operators.
9681 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00009682 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00009683 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00009684 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00009685 }
Mike Stump11289f42009-09-09 15:08:12 +00009686
Douglas Gregore9d62932011-07-15 16:25:15 +00009687 if (Op == OO_Subscript) {
9688 SourceLocation LBrace;
9689 SourceLocation RBrace;
9690
9691 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9692 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9693 LBrace = SourceLocation::getFromRawEncoding(
9694 NameLoc.CXXOperatorName.BeginOpNameLoc);
9695 RBrace = SourceLocation::getFromRawEncoding(
9696 NameLoc.CXXOperatorName.EndOpNameLoc);
9697 } else {
9698 LBrace = Callee->getLocStart();
9699 RBrace = OpLoc;
9700 }
9701
9702 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9703 First, Second);
9704 }
Sebastian Redladba46e2009-10-29 20:17:01 +00009705
Douglas Gregora16548e2009-08-11 05:31:07 +00009706 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00009707 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00009708 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00009709 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9710 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009711 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009712
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009713 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00009714}
Mike Stump11289f42009-09-09 15:08:12 +00009715
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009716template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00009717ExprResult
John McCallb268a282010-08-23 23:25:46 +00009718TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009719 SourceLocation OperatorLoc,
9720 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +00009721 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009722 TypeSourceInfo *ScopeType,
9723 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009724 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009725 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +00009726 QualType BaseType = Base->getType();
9727 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009728 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +00009729 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00009730 !BaseType->getAs<PointerType>()->getPointeeType()
9731 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009732 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00009733 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009734 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009735 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009736 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009737 /*FIXME?*/true);
9738 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009739
Douglas Gregor678f90d2010-02-25 01:56:36 +00009740 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009741 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9742 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9743 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9744 NameInfo.setNamedTypeInfo(DestroyedType);
9745
Richard Smith8e4a3862012-05-15 06:15:11 +00009746 // The scope type is now known to be a valid nested name specifier
9747 // component. Tack it on to the end of the nested name specifier.
9748 if (ScopeType)
9749 SS.Extend(SemaRef.Context, SourceLocation(),
9750 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009751
Abramo Bagnara7945c982012-01-27 09:46:47 +00009752 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +00009753 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009754 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009755 SS, TemplateKWLoc,
9756 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009757 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009758 /*TemplateArgs*/ 0);
9759}
9760
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00009761template<typename Derived>
9762StmtResult
9763TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +00009764 SourceLocation Loc = S->getLocStart();
9765 unsigned NumParams = S->getCapturedDecl()->getNumParams();
9766 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/0,
9767 S->getCapturedRegionKind(), NumParams);
9768 StmtResult Body = getDerived().TransformStmt(S->getCapturedStmt());
9769
9770 if (Body.isInvalid()) {
9771 getSema().ActOnCapturedRegionError();
9772 return StmtError();
9773 }
9774
9775 return getSema().ActOnCapturedRegionEnd(Body.take());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00009776}
9777
Douglas Gregord6ff3322009-08-04 16:50:30 +00009778} // end namespace clang
9779
9780#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H