blob: 97f4a4f45481c2ae5e0c88ace8f42680bd47b86b [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()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004359 if (getDerived().TransformFunctionTypeParams(
4360 TL.getBeginLoc(), TL.getParmArray(), TL.getNumArgs(),
4361 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004362 return QualType();
4363
Douglas Gregor3024f072012-04-16 07:05:22 +00004364 {
4365 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004366 // If a declaration declares a member function or member function
4367 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004368 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004369 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004370 // declarator.
4371 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004372
Douglas Gregor3024f072012-04-16 07:05:22 +00004373 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4374 if (ResultType.isNull())
4375 return QualType();
4376 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004377 }
4378 else {
4379 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4380 if (ResultType.isNull())
4381 return QualType();
4382
Alp Toker9cacbab2014-01-20 20:26:09 +00004383 if (getDerived().TransformFunctionTypeParams(
4384 TL.getBeginLoc(), TL.getParmArray(), TL.getNumArgs(),
4385 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004386 return QualType();
4387 }
4388
Richard Smithf623c962012-04-17 00:58:00 +00004389 // FIXME: Need to transform the exception-specification too.
4390
John McCall550e0c22009-10-21 00:40:46 +00004391 QualType Result = TL.getType();
Alp Toker9cacbab2014-01-20 20:26:09 +00004392 if (getDerived().AlwaysRebuild() || ResultType != T->getResultType() ||
4393 T->getNumParams() != ParamTypes.size() ||
4394 !std::equal(T->param_type_begin(), T->param_type_end(),
4395 ParamTypes.begin())) {
Jordan Rose5c382722013-03-08 21:51:21 +00004396 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00004397 T->getExtProtoInfo());
John McCall550e0c22009-10-21 00:40:46 +00004398 if (Result.isNull())
4399 return QualType();
4400 }
Mike Stump11289f42009-09-09 15:08:12 +00004401
John McCall550e0c22009-10-21 00:40:46 +00004402 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004403 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004404 NewTL.setLParenLoc(TL.getLParenLoc());
4405 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004406 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004407 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4408 NewTL.setArg(i, ParamDecls[i]);
4409
4410 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004411}
Mike Stump11289f42009-09-09 15:08:12 +00004412
Douglas Gregord6ff3322009-08-04 16:50:30 +00004413template<typename Derived>
4414QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004415 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004416 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004417 const FunctionNoProtoType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004418 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4419 if (ResultType.isNull())
4420 return QualType();
4421
4422 QualType Result = TL.getType();
4423 if (getDerived().AlwaysRebuild() ||
4424 ResultType != T->getResultType())
4425 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4426
4427 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004428 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004429 NewTL.setLParenLoc(TL.getLParenLoc());
4430 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004431 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004432
4433 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004434}
Mike Stump11289f42009-09-09 15:08:12 +00004435
John McCallb96ec562009-12-04 22:46:56 +00004436template<typename Derived> QualType
4437TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004438 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004439 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004440 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004441 if (!D)
4442 return QualType();
4443
4444 QualType Result = TL.getType();
4445 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4446 Result = getDerived().RebuildUnresolvedUsingType(D);
4447 if (Result.isNull())
4448 return QualType();
4449 }
4450
4451 // We might get an arbitrary type spec type back. We should at
4452 // least always get a type spec type, though.
4453 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4454 NewTL.setNameLoc(TL.getNameLoc());
4455
4456 return Result;
4457}
4458
Douglas Gregord6ff3322009-08-04 16:50:30 +00004459template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004460QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004461 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004462 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004463 TypedefNameDecl *Typedef
4464 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4465 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004466 if (!Typedef)
4467 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004468
John McCall550e0c22009-10-21 00:40:46 +00004469 QualType Result = TL.getType();
4470 if (getDerived().AlwaysRebuild() ||
4471 Typedef != T->getDecl()) {
4472 Result = getDerived().RebuildTypedefType(Typedef);
4473 if (Result.isNull())
4474 return QualType();
4475 }
Mike Stump11289f42009-09-09 15:08:12 +00004476
John McCall550e0c22009-10-21 00:40:46 +00004477 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4478 NewTL.setNameLoc(TL.getNameLoc());
4479
4480 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004481}
Mike Stump11289f42009-09-09 15:08:12 +00004482
Douglas Gregord6ff3322009-08-04 16:50:30 +00004483template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004484QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004485 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004486 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00004487 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4488 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00004489
John McCalldadc5752010-08-24 06:29:42 +00004490 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004491 if (E.isInvalid())
4492 return QualType();
4493
Eli Friedmane4f22df2012-02-29 04:03:55 +00004494 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4495 if (E.isInvalid())
4496 return QualType();
4497
John McCall550e0c22009-10-21 00:40:46 +00004498 QualType Result = TL.getType();
4499 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004500 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004501 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004502 if (Result.isNull())
4503 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004504 }
John McCall550e0c22009-10-21 00:40:46 +00004505 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004506
John McCall550e0c22009-10-21 00:40:46 +00004507 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004508 NewTL.setTypeofLoc(TL.getTypeofLoc());
4509 NewTL.setLParenLoc(TL.getLParenLoc());
4510 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004511
4512 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004513}
Mike Stump11289f42009-09-09 15:08:12 +00004514
4515template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004516QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004517 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004518 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4519 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4520 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004521 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004522
John McCall550e0c22009-10-21 00:40:46 +00004523 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004524 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4525 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004526 if (Result.isNull())
4527 return QualType();
4528 }
Mike Stump11289f42009-09-09 15:08:12 +00004529
John McCall550e0c22009-10-21 00:40:46 +00004530 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004531 NewTL.setTypeofLoc(TL.getTypeofLoc());
4532 NewTL.setLParenLoc(TL.getLParenLoc());
4533 NewTL.setRParenLoc(TL.getRParenLoc());
4534 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004535
4536 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004537}
Mike Stump11289f42009-09-09 15:08:12 +00004538
4539template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004540QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004541 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004542 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004543
Douglas Gregore922c772009-08-04 22:27:00 +00004544 // decltype expressions are not potentially evaluated contexts
Richard Smithfd555f62012-02-22 02:04:18 +00004545 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4546 /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00004547
John McCalldadc5752010-08-24 06:29:42 +00004548 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004549 if (E.isInvalid())
4550 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004551
Richard Smithfd555f62012-02-22 02:04:18 +00004552 E = getSema().ActOnDecltypeExpression(E.take());
4553 if (E.isInvalid())
4554 return QualType();
4555
John McCall550e0c22009-10-21 00:40:46 +00004556 QualType Result = TL.getType();
4557 if (getDerived().AlwaysRebuild() ||
4558 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004559 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004560 if (Result.isNull())
4561 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004562 }
John McCall550e0c22009-10-21 00:40:46 +00004563 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004564
John McCall550e0c22009-10-21 00:40:46 +00004565 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4566 NewTL.setNameLoc(TL.getNameLoc());
4567
4568 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004569}
4570
4571template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004572QualType TreeTransform<Derived>::TransformUnaryTransformType(
4573 TypeLocBuilder &TLB,
4574 UnaryTransformTypeLoc TL) {
4575 QualType Result = TL.getType();
4576 if (Result->isDependentType()) {
4577 const UnaryTransformType *T = TL.getTypePtr();
4578 QualType NewBase =
4579 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4580 Result = getDerived().RebuildUnaryTransformType(NewBase,
4581 T->getUTTKind(),
4582 TL.getKWLoc());
4583 if (Result.isNull())
4584 return QualType();
4585 }
4586
4587 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4588 NewTL.setKWLoc(TL.getKWLoc());
4589 NewTL.setParensRange(TL.getParensRange());
4590 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4591 return Result;
4592}
4593
4594template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004595QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4596 AutoTypeLoc TL) {
4597 const AutoType *T = TL.getTypePtr();
4598 QualType OldDeduced = T->getDeducedType();
4599 QualType NewDeduced;
4600 if (!OldDeduced.isNull()) {
4601 NewDeduced = getDerived().TransformType(OldDeduced);
4602 if (NewDeduced.isNull())
4603 return QualType();
4604 }
4605
4606 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00004607 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4608 T->isDependentType()) {
Richard Smith74aeef52013-04-26 16:15:35 +00004609 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith30482bc2011-02-20 03:19:35 +00004610 if (Result.isNull())
4611 return QualType();
4612 }
4613
4614 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4615 NewTL.setNameLoc(TL.getNameLoc());
4616
4617 return Result;
4618}
4619
4620template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004621QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004622 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004623 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004624 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004625 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4626 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004627 if (!Record)
4628 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004629
John McCall550e0c22009-10-21 00:40:46 +00004630 QualType Result = TL.getType();
4631 if (getDerived().AlwaysRebuild() ||
4632 Record != T->getDecl()) {
4633 Result = getDerived().RebuildRecordType(Record);
4634 if (Result.isNull())
4635 return QualType();
4636 }
Mike Stump11289f42009-09-09 15:08:12 +00004637
John McCall550e0c22009-10-21 00:40:46 +00004638 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4639 NewTL.setNameLoc(TL.getNameLoc());
4640
4641 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004642}
Mike Stump11289f42009-09-09 15:08:12 +00004643
4644template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004645QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004646 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004647 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004648 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004649 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4650 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004651 if (!Enum)
4652 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004653
John McCall550e0c22009-10-21 00:40:46 +00004654 QualType Result = TL.getType();
4655 if (getDerived().AlwaysRebuild() ||
4656 Enum != T->getDecl()) {
4657 Result = getDerived().RebuildEnumType(Enum);
4658 if (Result.isNull())
4659 return QualType();
4660 }
Mike Stump11289f42009-09-09 15:08:12 +00004661
John McCall550e0c22009-10-21 00:40:46 +00004662 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4663 NewTL.setNameLoc(TL.getNameLoc());
4664
4665 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004666}
John McCallfcc33b02009-09-05 00:15:47 +00004667
John McCalle78aac42010-03-10 03:28:59 +00004668template<typename Derived>
4669QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4670 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004671 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004672 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4673 TL.getTypePtr()->getDecl());
4674 if (!D) return QualType();
4675
4676 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4677 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4678 return T;
4679}
4680
Douglas Gregord6ff3322009-08-04 16:50:30 +00004681template<typename Derived>
4682QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004683 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004684 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004685 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004686}
4687
Mike Stump11289f42009-09-09 15:08:12 +00004688template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004689QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004690 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004691 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004692 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00004693
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004694 // Substitute into the replacement type, which itself might involve something
4695 // that needs to be transformed. This only tends to occur with default
4696 // template arguments of template template parameters.
4697 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4698 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4699 if (Replacement.isNull())
4700 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00004701
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004702 // Always canonicalize the replacement type.
4703 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4704 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00004705 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004706 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00004707
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004708 // Propagate type-source information.
4709 SubstTemplateTypeParmTypeLoc NewTL
4710 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4711 NewTL.setNameLoc(TL.getNameLoc());
4712 return Result;
4713
John McCallcebee162009-10-18 09:09:24 +00004714}
4715
4716template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004717QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4718 TypeLocBuilder &TLB,
4719 SubstTemplateTypeParmPackTypeLoc TL) {
4720 return TransformTypeSpecType(TLB, TL);
4721}
4722
4723template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004724QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004725 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004726 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004727 const TemplateSpecializationType *T = TL.getTypePtr();
4728
Douglas Gregordf846d12011-03-02 18:46:51 +00004729 // The nested-name-specifier never matters in a TemplateSpecializationType,
4730 // because we can't have a dependent nested-name-specifier anyway.
4731 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004732 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004733 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4734 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004735 if (Template.isNull())
4736 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004737
John McCall31f82722010-11-12 08:19:04 +00004738 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4739}
4740
Eli Friedman0dfb8892011-10-06 23:00:33 +00004741template<typename Derived>
4742QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4743 AtomicTypeLoc TL) {
4744 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4745 if (ValueType.isNull())
4746 return QualType();
4747
4748 QualType Result = TL.getType();
4749 if (getDerived().AlwaysRebuild() ||
4750 ValueType != TL.getValueLoc().getType()) {
4751 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4752 if (Result.isNull())
4753 return QualType();
4754 }
4755
4756 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4757 NewTL.setKWLoc(TL.getKWLoc());
4758 NewTL.setLParenLoc(TL.getLParenLoc());
4759 NewTL.setRParenLoc(TL.getRParenLoc());
4760
4761 return Result;
4762}
4763
Chad Rosier1dcde962012-08-08 18:46:20 +00004764 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00004765 /// container that provides a \c getArgLoc() member function.
4766 ///
4767 /// This iterator is intended to be used with the iterator form of
4768 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4769 template<typename ArgLocContainer>
4770 class TemplateArgumentLocContainerIterator {
4771 ArgLocContainer *Container;
4772 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00004773
Douglas Gregorfe921a72010-12-20 23:36:19 +00004774 public:
4775 typedef TemplateArgumentLoc value_type;
4776 typedef TemplateArgumentLoc reference;
4777 typedef int difference_type;
4778 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00004779
Douglas Gregorfe921a72010-12-20 23:36:19 +00004780 class pointer {
4781 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00004782
Douglas Gregorfe921a72010-12-20 23:36:19 +00004783 public:
4784 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004785
Douglas Gregorfe921a72010-12-20 23:36:19 +00004786 const TemplateArgumentLoc *operator->() const {
4787 return &Arg;
4788 }
4789 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004790
4791
Douglas Gregorfe921a72010-12-20 23:36:19 +00004792 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00004793
Douglas Gregorfe921a72010-12-20 23:36:19 +00004794 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4795 unsigned Index)
4796 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004797
Douglas Gregorfe921a72010-12-20 23:36:19 +00004798 TemplateArgumentLocContainerIterator &operator++() {
4799 ++Index;
4800 return *this;
4801 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004802
Douglas Gregorfe921a72010-12-20 23:36:19 +00004803 TemplateArgumentLocContainerIterator operator++(int) {
4804 TemplateArgumentLocContainerIterator Old(*this);
4805 ++(*this);
4806 return Old;
4807 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004808
Douglas Gregorfe921a72010-12-20 23:36:19 +00004809 TemplateArgumentLoc operator*() const {
4810 return Container->getArgLoc(Index);
4811 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004812
Douglas Gregorfe921a72010-12-20 23:36:19 +00004813 pointer operator->() const {
4814 return pointer(Container->getArgLoc(Index));
4815 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004816
Douglas Gregorfe921a72010-12-20 23:36:19 +00004817 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004818 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004819 return X.Container == Y.Container && X.Index == Y.Index;
4820 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004821
Douglas Gregorfe921a72010-12-20 23:36:19 +00004822 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004823 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004824 return !(X == Y);
4825 }
4826 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004827
4828
John McCall31f82722010-11-12 08:19:04 +00004829template <typename Derived>
4830QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4831 TypeLocBuilder &TLB,
4832 TemplateSpecializationTypeLoc TL,
4833 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004834 TemplateArgumentListInfo NewTemplateArgs;
4835 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4836 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004837 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4838 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004839 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00004840 ArgIterator(TL, TL.getNumArgs()),
4841 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004842 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004843
John McCall0ad16662009-10-29 08:12:44 +00004844 // FIXME: maybe don't rebuild if all the template arguments are the same.
4845
4846 QualType Result =
4847 getDerived().RebuildTemplateSpecializationType(Template,
4848 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004849 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004850
4851 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00004852 // Specializations of template template parameters are represented as
4853 // TemplateSpecializationTypes, and substitution of type alias templates
4854 // within a dependent context can transform them into
4855 // DependentTemplateSpecializationTypes.
4856 if (isa<DependentTemplateSpecializationType>(Result)) {
4857 DependentTemplateSpecializationTypeLoc NewTL
4858 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004859 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00004860 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00004861 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004862 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00004863 NewTL.setLAngleLoc(TL.getLAngleLoc());
4864 NewTL.setRAngleLoc(TL.getRAngleLoc());
4865 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4866 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4867 return Result;
4868 }
4869
John McCall0ad16662009-10-29 08:12:44 +00004870 TemplateSpecializationTypeLoc NewTL
4871 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004872 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00004873 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4874 NewTL.setLAngleLoc(TL.getLAngleLoc());
4875 NewTL.setRAngleLoc(TL.getRAngleLoc());
4876 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4877 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004878 }
Mike Stump11289f42009-09-09 15:08:12 +00004879
John McCall0ad16662009-10-29 08:12:44 +00004880 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004881}
Mike Stump11289f42009-09-09 15:08:12 +00004882
Douglas Gregor5a064722011-02-28 17:23:35 +00004883template <typename Derived>
4884QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4885 TypeLocBuilder &TLB,
4886 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004887 TemplateName Template,
4888 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00004889 TemplateArgumentListInfo NewTemplateArgs;
4890 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4891 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4892 typedef TemplateArgumentLocContainerIterator<
4893 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004894 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00004895 ArgIterator(TL, TL.getNumArgs()),
4896 NewTemplateArgs))
4897 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00004898
Douglas Gregor5a064722011-02-28 17:23:35 +00004899 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00004900
Douglas Gregor5a064722011-02-28 17:23:35 +00004901 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4902 QualType Result
4903 = getSema().Context.getDependentTemplateSpecializationType(
4904 TL.getTypePtr()->getKeyword(),
4905 DTN->getQualifier(),
4906 DTN->getIdentifier(),
4907 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00004908
Douglas Gregor5a064722011-02-28 17:23:35 +00004909 DependentTemplateSpecializationTypeLoc NewTL
4910 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004911 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004912 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00004913 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004914 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00004915 NewTL.setLAngleLoc(TL.getLAngleLoc());
4916 NewTL.setRAngleLoc(TL.getRAngleLoc());
4917 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4918 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4919 return Result;
4920 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004921
4922 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00004923 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004924 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00004925 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00004926
Douglas Gregor5a064722011-02-28 17:23:35 +00004927 if (!Result.isNull()) {
4928 /// FIXME: Wrap this in an elaborated-type-specifier?
4929 TemplateSpecializationTypeLoc NewTL
4930 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00004931 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004932 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00004933 NewTL.setLAngleLoc(TL.getLAngleLoc());
4934 NewTL.setRAngleLoc(TL.getRAngleLoc());
4935 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4936 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4937 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004938
Douglas Gregor5a064722011-02-28 17:23:35 +00004939 return Result;
4940}
4941
Mike Stump11289f42009-09-09 15:08:12 +00004942template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004943QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00004944TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004945 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004946 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00004947
Douglas Gregor844cb502011-03-01 18:12:44 +00004948 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00004949 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00004950 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004951 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00004952 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4953 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00004954 return QualType();
4955 }
Mike Stump11289f42009-09-09 15:08:12 +00004956
John McCall31f82722010-11-12 08:19:04 +00004957 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4958 if (NamedT.isNull())
4959 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00004960
Richard Smith3f1b5d02011-05-05 21:57:07 +00004961 // C++0x [dcl.type.elab]p2:
4962 // If the identifier resolves to a typedef-name or the simple-template-id
4963 // resolves to an alias template specialization, the
4964 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00004965 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4966 if (const TemplateSpecializationType *TST =
4967 NamedT->getAs<TemplateSpecializationType>()) {
4968 TemplateName Template = TST->getTemplateName();
4969 if (TypeAliasTemplateDecl *TAT =
4970 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4971 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4972 diag::err_tag_reference_non_tag) << 4;
4973 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4974 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00004975 }
4976 }
4977
John McCall550e0c22009-10-21 00:40:46 +00004978 QualType Result = TL.getType();
4979 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00004980 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00004981 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00004982 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004983 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00004984 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00004985 if (Result.isNull())
4986 return QualType();
4987 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004988
Abramo Bagnara6150c882010-05-11 21:36:43 +00004989 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00004990 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004991 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00004992 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004993}
Mike Stump11289f42009-09-09 15:08:12 +00004994
4995template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00004996QualType TreeTransform<Derived>::TransformAttributedType(
4997 TypeLocBuilder &TLB,
4998 AttributedTypeLoc TL) {
4999 const AttributedType *oldType = TL.getTypePtr();
5000 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5001 if (modifiedType.isNull())
5002 return QualType();
5003
5004 QualType result = TL.getType();
5005
5006 // FIXME: dependent operand expressions?
5007 if (getDerived().AlwaysRebuild() ||
5008 modifiedType != oldType->getModifiedType()) {
5009 // TODO: this is really lame; we should really be rebuilding the
5010 // equivalent type from first principles.
5011 QualType equivalentType
5012 = getDerived().TransformType(oldType->getEquivalentType());
5013 if (equivalentType.isNull())
5014 return QualType();
5015 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5016 modifiedType,
5017 equivalentType);
5018 }
5019
5020 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5021 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5022 if (TL.hasAttrOperand())
5023 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5024 if (TL.hasAttrExprOperand())
5025 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5026 else if (TL.hasAttrEnumOperand())
5027 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5028
5029 return result;
5030}
5031
5032template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005033QualType
5034TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5035 ParenTypeLoc TL) {
5036 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5037 if (Inner.isNull())
5038 return QualType();
5039
5040 QualType Result = TL.getType();
5041 if (getDerived().AlwaysRebuild() ||
5042 Inner != TL.getInnerLoc().getType()) {
5043 Result = getDerived().RebuildParenType(Inner);
5044 if (Result.isNull())
5045 return QualType();
5046 }
5047
5048 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5049 NewTL.setLParenLoc(TL.getLParenLoc());
5050 NewTL.setRParenLoc(TL.getRParenLoc());
5051 return Result;
5052}
5053
5054template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005055QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005056 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005057 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005058
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005059 NestedNameSpecifierLoc QualifierLoc
5060 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5061 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005062 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005063
John McCallc392f372010-06-11 00:33:02 +00005064 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005065 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005066 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005067 QualifierLoc,
5068 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005069 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005070 if (Result.isNull())
5071 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005072
Abramo Bagnarad7548482010-05-19 21:37:53 +00005073 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5074 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005075 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5076
Abramo Bagnarad7548482010-05-19 21:37:53 +00005077 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005078 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005079 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005080 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005081 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005082 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005083 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005084 NewTL.setNameLoc(TL.getNameLoc());
5085 }
John McCall550e0c22009-10-21 00:40:46 +00005086 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005087}
Mike Stump11289f42009-09-09 15:08:12 +00005088
Douglas Gregord6ff3322009-08-04 16:50:30 +00005089template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005090QualType TreeTransform<Derived>::
5091 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005092 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005093 NestedNameSpecifierLoc QualifierLoc;
5094 if (TL.getQualifierLoc()) {
5095 QualifierLoc
5096 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5097 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005098 return QualType();
5099 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005100
John McCall31f82722010-11-12 08:19:04 +00005101 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005102 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005103}
5104
5105template<typename Derived>
5106QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005107TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5108 DependentTemplateSpecializationTypeLoc TL,
5109 NestedNameSpecifierLoc QualifierLoc) {
5110 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005111
Douglas Gregora7a795b2011-03-01 20:11:18 +00005112 TemplateArgumentListInfo NewTemplateArgs;
5113 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5114 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005115
Douglas Gregora7a795b2011-03-01 20:11:18 +00005116 typedef TemplateArgumentLocContainerIterator<
5117 DependentTemplateSpecializationTypeLoc> ArgIterator;
5118 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5119 ArgIterator(TL, TL.getNumArgs()),
5120 NewTemplateArgs))
5121 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005122
Douglas Gregora7a795b2011-03-01 20:11:18 +00005123 QualType Result
5124 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5125 QualifierLoc,
5126 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005127 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005128 NewTemplateArgs);
5129 if (Result.isNull())
5130 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005131
Douglas Gregora7a795b2011-03-01 20:11:18 +00005132 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5133 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005134
Douglas Gregora7a795b2011-03-01 20:11:18 +00005135 // Copy information relevant to the template specialization.
5136 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005137 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005138 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005139 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005140 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5141 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005142 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005143 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005144
Douglas Gregora7a795b2011-03-01 20:11:18 +00005145 // Copy information relevant to the elaborated type.
5146 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005147 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005148 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005149 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5150 DependentTemplateSpecializationTypeLoc SpecTL
5151 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005152 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005153 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005154 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005155 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005156 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5157 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005158 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005159 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005160 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005161 TemplateSpecializationTypeLoc SpecTL
5162 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005163 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005164 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005165 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5166 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005167 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005168 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005169 }
5170 return Result;
5171}
5172
5173template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005174QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5175 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005176 QualType Pattern
5177 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005178 if (Pattern.isNull())
5179 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005180
5181 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005182 if (getDerived().AlwaysRebuild() ||
5183 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005184 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005185 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005186 TL.getEllipsisLoc(),
5187 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005188 if (Result.isNull())
5189 return QualType();
5190 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005191
Douglas Gregor822d0302011-01-12 17:07:58 +00005192 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5193 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5194 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005195}
5196
5197template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005198QualType
5199TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005200 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005201 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005202 TLB.pushFullCopy(TL);
5203 return TL.getType();
5204}
5205
5206template<typename Derived>
5207QualType
5208TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005209 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00005210 // ObjCObjectType is never dependent.
5211 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005212 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005213}
Mike Stump11289f42009-09-09 15:08:12 +00005214
5215template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005216QualType
5217TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005218 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005219 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005220 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005221 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005222}
5223
Douglas Gregord6ff3322009-08-04 16:50:30 +00005224//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005225// Statement transformation
5226//===----------------------------------------------------------------------===//
5227template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005228StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005229TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005230 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005231}
5232
5233template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005234StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005235TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5236 return getDerived().TransformCompoundStmt(S, false);
5237}
5238
5239template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005240StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005241TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005242 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005243 Sema::CompoundScopeRAII CompoundScope(getSema());
5244
John McCall1ababa62010-08-27 19:56:05 +00005245 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005246 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005247 SmallVector<Stmt*, 8> Statements;
Douglas Gregorebe10102009-08-20 07:17:43 +00005248 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5249 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00005250 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00005251 if (Result.isInvalid()) {
5252 // Immediately fail if this was a DeclStmt, since it's very
5253 // likely that this will cause problems for future statements.
5254 if (isa<DeclStmt>(*B))
5255 return StmtError();
5256
5257 // Otherwise, just keep processing substatements and fail later.
5258 SubStmtInvalid = true;
5259 continue;
5260 }
Mike Stump11289f42009-09-09 15:08:12 +00005261
Douglas Gregorebe10102009-08-20 07:17:43 +00005262 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5263 Statements.push_back(Result.takeAs<Stmt>());
5264 }
Mike Stump11289f42009-09-09 15:08:12 +00005265
John McCall1ababa62010-08-27 19:56:05 +00005266 if (SubStmtInvalid)
5267 return StmtError();
5268
Douglas Gregorebe10102009-08-20 07:17:43 +00005269 if (!getDerived().AlwaysRebuild() &&
5270 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00005271 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005272
5273 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005274 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005275 S->getRBracLoc(),
5276 IsStmtExpr);
5277}
Mike Stump11289f42009-09-09 15:08:12 +00005278
Douglas Gregorebe10102009-08-20 07:17:43 +00005279template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005280StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005281TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005282 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005283 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005284 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5285 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005286
Eli Friedman06577382009-11-19 03:14:00 +00005287 // Transform the left-hand case value.
5288 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005289 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005290 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005291 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005292
Eli Friedman06577382009-11-19 03:14:00 +00005293 // Transform the right-hand case value (for the GNU case-range extension).
5294 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005295 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005296 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005297 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005298 }
Mike Stump11289f42009-09-09 15:08:12 +00005299
Douglas Gregorebe10102009-08-20 07:17:43 +00005300 // Build the case statement.
5301 // Case statements are always rebuilt so that they will attached to their
5302 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005303 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005304 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005305 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005306 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005307 S->getColonLoc());
5308 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005309 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005310
Douglas Gregorebe10102009-08-20 07:17:43 +00005311 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005312 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005313 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005314 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005315
Douglas Gregorebe10102009-08-20 07:17:43 +00005316 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005317 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005318}
5319
5320template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005321StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005322TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005323 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005324 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005325 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005326 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005327
Douglas Gregorebe10102009-08-20 07:17:43 +00005328 // Default statements are always rebuilt
5329 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005330 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005331}
Mike Stump11289f42009-09-09 15:08:12 +00005332
Douglas Gregorebe10102009-08-20 07:17:43 +00005333template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005334StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005335TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005336 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005337 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005338 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005339
Chris Lattnercab02a62011-02-17 20:34:02 +00005340 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5341 S->getDecl());
5342 if (!LD)
5343 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00005344
5345
Douglas Gregorebe10102009-08-20 07:17:43 +00005346 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005347 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005348 cast<LabelDecl>(LD), SourceLocation(),
5349 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005350}
Mike Stump11289f42009-09-09 15:08:12 +00005351
Douglas Gregorebe10102009-08-20 07:17:43 +00005352template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005353StmtResult
Richard Smithc202b282012-04-14 00:33:13 +00005354TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5355 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5356 if (SubStmt.isInvalid())
5357 return StmtError();
5358
5359 // TODO: transform attributes
5360 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5361 return S;
5362
5363 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5364 S->getAttrs(),
5365 SubStmt.get());
5366}
5367
5368template<typename Derived>
5369StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005370TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005371 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005372 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00005373 VarDecl *ConditionVar = 0;
5374 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005375 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00005376 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005377 getDerived().TransformDefinition(
5378 S->getConditionVariable()->getLocation(),
5379 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00005380 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005381 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005382 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00005383 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005384
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005385 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005386 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005387
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005388 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005389 if (S->getCond()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005390 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005391 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005392 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005393 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005394
John McCallb268a282010-08-23 23:25:46 +00005395 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005396 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005397 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005398
John McCallb268a282010-08-23 23:25:46 +00005399 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5400 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005401 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005402
Douglas Gregorebe10102009-08-20 07:17:43 +00005403 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005404 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005405 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005406 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005407
Douglas Gregorebe10102009-08-20 07:17:43 +00005408 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005409 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005410 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005411 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005412
Douglas Gregorebe10102009-08-20 07:17:43 +00005413 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005414 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005415 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005416 Then.get() == S->getThen() &&
5417 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00005418 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005419
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005420 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005421 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00005422 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005423}
5424
5425template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005426StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005427TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005428 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005429 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00005430 VarDecl *ConditionVar = 0;
5431 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005432 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005433 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005434 getDerived().TransformDefinition(
5435 S->getConditionVariable()->getLocation(),
5436 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005437 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005438 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005439 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005440 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005441
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005442 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005443 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005444 }
Mike Stump11289f42009-09-09 15:08:12 +00005445
Douglas Gregorebe10102009-08-20 07:17:43 +00005446 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005447 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005448 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005449 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005450 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005451 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005452
Douglas Gregorebe10102009-08-20 07:17:43 +00005453 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005454 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005455 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005456 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005457
Douglas Gregorebe10102009-08-20 07:17:43 +00005458 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005459 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5460 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005461}
Mike Stump11289f42009-09-09 15:08:12 +00005462
Douglas Gregorebe10102009-08-20 07:17:43 +00005463template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005464StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005465TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005466 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005467 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00005468 VarDecl *ConditionVar = 0;
5469 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005470 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005471 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005472 getDerived().TransformDefinition(
5473 S->getConditionVariable()->getLocation(),
5474 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005475 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005476 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005477 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005478 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005479
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005480 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005481 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005482
5483 if (S->getCond()) {
5484 // Convert the condition to a boolean value.
Chad Rosier1dcde962012-08-08 18:46:20 +00005485 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005486 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005487 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005488 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005489 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005490 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005491 }
Mike Stump11289f42009-09-09 15:08:12 +00005492
John McCallb268a282010-08-23 23:25:46 +00005493 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5494 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005495 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005496
Douglas Gregorebe10102009-08-20 07:17:43 +00005497 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005498 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005499 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005500 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005501
Douglas Gregorebe10102009-08-20 07:17:43 +00005502 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005503 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005504 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005505 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005506 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005507
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005508 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005509 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005510}
Mike Stump11289f42009-09-09 15:08:12 +00005511
Douglas Gregorebe10102009-08-20 07:17:43 +00005512template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005513StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005514TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005515 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005516 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005517 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005518 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005519
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005520 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005521 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005522 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005523 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005524
Douglas Gregorebe10102009-08-20 07:17:43 +00005525 if (!getDerived().AlwaysRebuild() &&
5526 Cond.get() == S->getCond() &&
5527 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005528 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005529
John McCallb268a282010-08-23 23:25:46 +00005530 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5531 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005532 S->getRParenLoc());
5533}
Mike Stump11289f42009-09-09 15:08:12 +00005534
Douglas Gregorebe10102009-08-20 07:17:43 +00005535template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005536StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005537TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005538 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005539 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005540 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005541 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005542
Douglas Gregorebe10102009-08-20 07:17:43 +00005543 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005544 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005545 VarDecl *ConditionVar = 0;
5546 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005547 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005548 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005549 getDerived().TransformDefinition(
5550 S->getConditionVariable()->getLocation(),
5551 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005552 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005553 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005554 } else {
5555 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005556
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005557 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005558 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005559
5560 if (S->getCond()) {
5561 // Convert the condition to a boolean value.
Chad Rosier1dcde962012-08-08 18:46:20 +00005562 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005563 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005564 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005565 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005566
John McCallb268a282010-08-23 23:25:46 +00005567 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005568 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005569 }
Mike Stump11289f42009-09-09 15:08:12 +00005570
Chad Rosier1dcde962012-08-08 18:46:20 +00005571 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCallb268a282010-08-23 23:25:46 +00005572 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005573 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005574
Douglas Gregorebe10102009-08-20 07:17:43 +00005575 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005576 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005577 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005578 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005579
Richard Smith945f8d32013-01-14 22:39:08 +00005580 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00005581 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005582 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005583
Douglas Gregorebe10102009-08-20 07:17:43 +00005584 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005585 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005586 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005587 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005588
Douglas Gregorebe10102009-08-20 07:17:43 +00005589 if (!getDerived().AlwaysRebuild() &&
5590 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005591 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005592 Inc.get() == S->getInc() &&
5593 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005594 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005595
Douglas Gregorebe10102009-08-20 07:17:43 +00005596 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005597 Init.get(), FullCond, ConditionVar,
5598 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005599}
5600
5601template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005602StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005603TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005604 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5605 S->getLabel());
5606 if (!LD)
5607 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005608
Douglas Gregorebe10102009-08-20 07:17:43 +00005609 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005610 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005611 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005612}
5613
5614template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005615StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005616TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005617 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005618 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005619 return StmtError();
Eli Friedman9ccdb1d2012-01-31 22:47:07 +00005620 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump11289f42009-09-09 15:08:12 +00005621
Douglas Gregorebe10102009-08-20 07:17:43 +00005622 if (!getDerived().AlwaysRebuild() &&
5623 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00005624 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005625
5626 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005627 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005628}
5629
5630template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005631StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005632TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005633 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005634}
Mike Stump11289f42009-09-09 15:08:12 +00005635
Douglas Gregorebe10102009-08-20 07:17:43 +00005636template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005637StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005638TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005639 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005640}
Mike Stump11289f42009-09-09 15:08:12 +00005641
Douglas Gregorebe10102009-08-20 07:17:43 +00005642template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005643StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005644TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005645 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005646 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005647 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005648
Mike Stump11289f42009-09-09 15:08:12 +00005649 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005650 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005651 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005652}
Mike Stump11289f42009-09-09 15:08:12 +00005653
Douglas Gregorebe10102009-08-20 07:17:43 +00005654template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005655StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005656TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005657 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005658 SmallVector<Decl *, 4> Decls;
Douglas Gregorebe10102009-08-20 07:17:43 +00005659 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5660 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00005661 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5662 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005663 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005664 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005665
Douglas Gregorebe10102009-08-20 07:17:43 +00005666 if (Transformed != *D)
5667 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005668
Douglas Gregorebe10102009-08-20 07:17:43 +00005669 Decls.push_back(Transformed);
5670 }
Mike Stump11289f42009-09-09 15:08:12 +00005671
Douglas Gregorebe10102009-08-20 07:17:43 +00005672 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00005673 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005674
Rafael Espindolaab417692013-07-09 12:05:01 +00005675 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005676}
Mike Stump11289f42009-09-09 15:08:12 +00005677
Douglas Gregorebe10102009-08-20 07:17:43 +00005678template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005679StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00005680TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005681
Benjamin Kramerf0623432012-08-23 22:51:59 +00005682 SmallVector<Expr*, 8> Constraints;
5683 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005684 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005685
John McCalldadc5752010-08-24 06:29:42 +00005686 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005687 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005688
5689 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00005690
Anders Carlssonaaeef072010-01-24 05:50:09 +00005691 // Go through the outputs.
5692 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005693 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005694
Anders Carlssonaaeef072010-01-24 05:50:09 +00005695 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005696 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005697
Anders Carlssonaaeef072010-01-24 05:50:09 +00005698 // Transform the output expr.
5699 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005700 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005701 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005702 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005703
Anders Carlssonaaeef072010-01-24 05:50:09 +00005704 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005705
John McCallb268a282010-08-23 23:25:46 +00005706 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005707 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005708
Anders Carlssonaaeef072010-01-24 05:50:09 +00005709 // Go through the inputs.
5710 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005711 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005712
Anders Carlssonaaeef072010-01-24 05:50:09 +00005713 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005714 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005715
Anders Carlssonaaeef072010-01-24 05:50:09 +00005716 // Transform the input expr.
5717 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005718 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005719 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005720 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005721
Anders Carlssonaaeef072010-01-24 05:50:09 +00005722 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005723
John McCallb268a282010-08-23 23:25:46 +00005724 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005725 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005726
Anders Carlssonaaeef072010-01-24 05:50:09 +00005727 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00005728 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005729
5730 // Go through the clobbers.
5731 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00005732 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005733
5734 // No need to transform the asm string literal.
5735 AsmString = SemaRef.Owned(S->getAsmString());
Chad Rosierde70e0e2012-08-25 00:11:56 +00005736 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5737 S->isVolatile(), S->getNumOutputs(),
5738 S->getNumInputs(), Names.data(),
5739 Constraints, Exprs, AsmString.get(),
5740 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005741}
5742
Chad Rosier32503022012-06-11 20:47:18 +00005743template<typename Derived>
5744StmtResult
5745TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00005746 ArrayRef<Token> AsmToks =
5747 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00005748
John McCallf413f5e2013-05-03 00:10:13 +00005749 bool HadError = false, HadChange = false;
5750
5751 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5752 SmallVector<Expr*, 8> TransformedExprs;
5753 TransformedExprs.reserve(SrcExprs.size());
5754 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5755 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5756 if (!Result.isUsable()) {
5757 HadError = true;
5758 } else {
5759 HadChange |= (Result.get() != SrcExprs[i]);
5760 TransformedExprs.push_back(Result.take());
5761 }
5762 }
5763
5764 if (HadError) return StmtError();
5765 if (!HadChange && !getDerived().AlwaysRebuild())
5766 return Owned(S);
5767
Chad Rosierb6f46c12012-08-15 16:53:30 +00005768 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00005769 AsmToks, S->getAsmString(),
5770 S->getNumOutputs(), S->getNumInputs(),
5771 S->getAllConstraints(), S->getClobbers(),
5772 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00005773}
Douglas Gregorebe10102009-08-20 07:17:43 +00005774
5775template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005776StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005777TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005778 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005779 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005780 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005781 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005782
Douglas Gregor96c79492010-04-23 22:50:49 +00005783 // Transform the @catch statements (if present).
5784 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005785 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00005786 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005787 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005788 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005789 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005790 if (Catch.get() != S->getCatchStmt(I))
5791 AnyCatchChanged = true;
5792 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005793 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005794
Douglas Gregor306de2f2010-04-22 23:59:56 +00005795 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005796 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005797 if (S->getFinallyStmt()) {
5798 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5799 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005800 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005801 }
5802
5803 // If nothing changed, just retain this statement.
5804 if (!getDerived().AlwaysRebuild() &&
5805 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005806 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005807 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00005808 return SemaRef.Owned(S);
Chad Rosier1dcde962012-08-08 18:46:20 +00005809
Douglas Gregor306de2f2010-04-22 23:59:56 +00005810 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005811 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005812 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005813}
Mike Stump11289f42009-09-09 15:08:12 +00005814
Douglas Gregorebe10102009-08-20 07:17:43 +00005815template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005816StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005817TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005818 // Transform the @catch parameter, if there is one.
5819 VarDecl *Var = 0;
5820 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5821 TypeSourceInfo *TSInfo = 0;
5822 if (FromVar->getTypeSourceInfo()) {
5823 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5824 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005825 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005826 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005827
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005828 QualType T;
5829 if (TSInfo)
5830 T = TSInfo->getType();
5831 else {
5832 T = getDerived().TransformType(FromVar->getType());
5833 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00005834 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005835 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005836
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005837 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5838 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005839 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005840 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005841
John McCalldadc5752010-08-24 06:29:42 +00005842 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005843 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005844 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005845
5846 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005847 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005848 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005849}
Mike Stump11289f42009-09-09 15:08:12 +00005850
Douglas Gregorebe10102009-08-20 07:17:43 +00005851template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005852StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005853TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005854 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005855 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005856 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005857 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005858
Douglas Gregor306de2f2010-04-22 23:59:56 +00005859 // If nothing changed, just retain this statement.
5860 if (!getDerived().AlwaysRebuild() &&
5861 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00005862 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00005863
5864 // Build a new statement.
5865 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005866 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005867}
Mike Stump11289f42009-09-09 15:08:12 +00005868
Douglas Gregorebe10102009-08-20 07:17:43 +00005869template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005870StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005871TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005872 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005873 if (S->getThrowExpr()) {
5874 Operand = getDerived().TransformExpr(S->getThrowExpr());
5875 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005876 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005877 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005878
Douglas Gregor2900c162010-04-22 21:44:01 +00005879 if (!getDerived().AlwaysRebuild() &&
5880 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005881 return getSema().Owned(S);
Chad Rosier1dcde962012-08-08 18:46:20 +00005882
John McCallb268a282010-08-23 23:25:46 +00005883 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005884}
Mike Stump11289f42009-09-09 15:08:12 +00005885
Douglas Gregorebe10102009-08-20 07:17:43 +00005886template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005887StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005888TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005889 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005890 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005891 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005892 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005893 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00005894 Object =
5895 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5896 Object.get());
5897 if (Object.isInvalid())
5898 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005899
Douglas Gregor6148de72010-04-22 22:01:21 +00005900 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005901 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005902 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005903 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005904
Douglas Gregor6148de72010-04-22 22:01:21 +00005905 // If nothing change, just retain the current statement.
5906 if (!getDerived().AlwaysRebuild() &&
5907 Object.get() == S->getSynchExpr() &&
5908 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005909 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005910
5911 // Build a new statement.
5912 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005913 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005914}
5915
5916template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005917StmtResult
John McCall31168b02011-06-15 23:02:42 +00005918TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5919 ObjCAutoreleasePoolStmt *S) {
5920 // Transform the body.
5921 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5922 if (Body.isInvalid())
5923 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005924
John McCall31168b02011-06-15 23:02:42 +00005925 // If nothing changed, just retain this statement.
5926 if (!getDerived().AlwaysRebuild() &&
5927 Body.get() == S->getSubStmt())
5928 return SemaRef.Owned(S);
5929
5930 // Build a new statement.
5931 return getDerived().RebuildObjCAutoreleasePoolStmt(
5932 S->getAtLoc(), Body.get());
5933}
5934
5935template<typename Derived>
5936StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005937TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005938 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005939 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005940 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005941 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005942 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005943
Douglas Gregorf68a5082010-04-22 23:10:45 +00005944 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00005945 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005946 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005947 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005948
Douglas Gregorf68a5082010-04-22 23:10:45 +00005949 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005950 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005951 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005952 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005953
Douglas Gregorf68a5082010-04-22 23:10:45 +00005954 // If nothing changed, just retain this statement.
5955 if (!getDerived().AlwaysRebuild() &&
5956 Element.get() == S->getElement() &&
5957 Collection.get() == S->getCollection() &&
5958 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005959 return SemaRef.Owned(S);
Chad Rosier1dcde962012-08-08 18:46:20 +00005960
Douglas Gregorf68a5082010-04-22 23:10:45 +00005961 // Build a new statement.
5962 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00005963 Element.get(),
5964 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00005965 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005966 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005967}
5968
David Majnemer5f7efef2013-10-15 09:50:08 +00005969template <typename Derived>
5970StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005971 // Transform the exception declaration, if any.
5972 VarDecl *Var = 0;
David Majnemer5f7efef2013-10-15 09:50:08 +00005973 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
5974 TypeSourceInfo *T =
5975 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005976 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005977 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005978
David Majnemer5f7efef2013-10-15 09:50:08 +00005979 Var = getDerived().RebuildExceptionDecl(
5980 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
5981 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00005982 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00005983 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005984 }
Mike Stump11289f42009-09-09 15:08:12 +00005985
Douglas Gregorebe10102009-08-20 07:17:43 +00005986 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00005987 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00005988 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005989 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005990
David Majnemer5f7efef2013-10-15 09:50:08 +00005991 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005992 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00005993 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005994
David Majnemer5f7efef2013-10-15 09:50:08 +00005995 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005996}
Mike Stump11289f42009-09-09 15:08:12 +00005997
David Majnemer5f7efef2013-10-15 09:50:08 +00005998template <typename Derived>
5999StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006000 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006001 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006002 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006003 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006004
Douglas Gregorebe10102009-08-20 07:17:43 +00006005 // Transform the handlers.
6006 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006007 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006008 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006009 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006010 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006011 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006012
Douglas Gregorebe10102009-08-20 07:17:43 +00006013 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
6014 Handlers.push_back(Handler.takeAs<Stmt>());
6015 }
Mike Stump11289f42009-09-09 15:08:12 +00006016
David Majnemer5f7efef2013-10-15 09:50:08 +00006017 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006018 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00006019 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00006020
John McCallb268a282010-08-23 23:25:46 +00006021 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006022 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006023}
Mike Stump11289f42009-09-09 15:08:12 +00006024
Richard Smith02e85f32011-04-14 22:09:26 +00006025template<typename Derived>
6026StmtResult
6027TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6028 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6029 if (Range.isInvalid())
6030 return StmtError();
6031
6032 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6033 if (BeginEnd.isInvalid())
6034 return StmtError();
6035
6036 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6037 if (Cond.isInvalid())
6038 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006039 if (Cond.get())
6040 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
6041 if (Cond.isInvalid())
6042 return StmtError();
6043 if (Cond.get())
6044 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smith02e85f32011-04-14 22:09:26 +00006045
6046 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6047 if (Inc.isInvalid())
6048 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006049 if (Inc.get())
6050 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smith02e85f32011-04-14 22:09:26 +00006051
6052 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6053 if (LoopVar.isInvalid())
6054 return StmtError();
6055
6056 StmtResult NewStmt = S;
6057 if (getDerived().AlwaysRebuild() ||
6058 Range.get() != S->getRangeStmt() ||
6059 BeginEnd.get() != S->getBeginEndStmt() ||
6060 Cond.get() != S->getCond() ||
6061 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006062 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006063 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6064 S->getColonLoc(), Range.get(),
6065 BeginEnd.get(), Cond.get(),
6066 Inc.get(), LoopVar.get(),
6067 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006068 if (NewStmt.isInvalid())
6069 return StmtError();
6070 }
Richard Smith02e85f32011-04-14 22:09:26 +00006071
6072 StmtResult Body = getDerived().TransformStmt(S->getBody());
6073 if (Body.isInvalid())
6074 return StmtError();
6075
6076 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6077 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006078 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006079 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6080 S->getColonLoc(), Range.get(),
6081 BeginEnd.get(), Cond.get(),
6082 Inc.get(), LoopVar.get(),
6083 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006084 if (NewStmt.isInvalid())
6085 return StmtError();
6086 }
Richard Smith02e85f32011-04-14 22:09:26 +00006087
6088 if (NewStmt.get() == S)
6089 return SemaRef.Owned(S);
6090
6091 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6092}
6093
John Wiegley1c0675e2011-04-28 01:08:34 +00006094template<typename Derived>
6095StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006096TreeTransform<Derived>::TransformMSDependentExistsStmt(
6097 MSDependentExistsStmt *S) {
6098 // Transform the nested-name-specifier, if any.
6099 NestedNameSpecifierLoc QualifierLoc;
6100 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006101 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006102 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6103 if (!QualifierLoc)
6104 return StmtError();
6105 }
6106
6107 // Transform the declaration name.
6108 DeclarationNameInfo NameInfo = S->getNameInfo();
6109 if (NameInfo.getName()) {
6110 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6111 if (!NameInfo.getName())
6112 return StmtError();
6113 }
6114
6115 // Check whether anything changed.
6116 if (!getDerived().AlwaysRebuild() &&
6117 QualifierLoc == S->getQualifierLoc() &&
6118 NameInfo.getName() == S->getNameInfo().getName())
6119 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006120
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006121 // Determine whether this name exists, if we can.
6122 CXXScopeSpec SS;
6123 SS.Adopt(QualifierLoc);
6124 bool Dependent = false;
6125 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
6126 case Sema::IER_Exists:
6127 if (S->isIfExists())
6128 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006129
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006130 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6131
6132 case Sema::IER_DoesNotExist:
6133 if (S->isIfNotExists())
6134 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006135
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006136 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006137
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006138 case Sema::IER_Dependent:
6139 Dependent = true;
6140 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006141
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006142 case Sema::IER_Error:
6143 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006144 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006145
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006146 // We need to continue with the instantiation, so do so now.
6147 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6148 if (SubStmt.isInvalid())
6149 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006150
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006151 // If we have resolved the name, just transform to the substatement.
6152 if (!Dependent)
6153 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006154
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006155 // The name is still dependent, so build a dependent expression again.
6156 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6157 S->isIfExists(),
6158 QualifierLoc,
6159 NameInfo,
6160 SubStmt.get());
6161}
6162
6163template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006164ExprResult
6165TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6166 NestedNameSpecifierLoc QualifierLoc;
6167 if (E->getQualifierLoc()) {
6168 QualifierLoc
6169 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6170 if (!QualifierLoc)
6171 return ExprError();
6172 }
6173
6174 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6175 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6176 if (!PD)
6177 return ExprError();
6178
6179 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6180 if (Base.isInvalid())
6181 return ExprError();
6182
6183 return new (SemaRef.getASTContext())
6184 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6185 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6186 QualifierLoc, E->getMemberLoc());
6187}
6188
David Majnemerfad8f482013-10-15 09:33:02 +00006189template <typename Derived>
6190StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006191 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006192 if (TryBlock.isInvalid())
6193 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006194
6195 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006196 if (Handler.isInvalid())
6197 return StmtError();
6198
David Majnemerfad8f482013-10-15 09:33:02 +00006199 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6200 Handler.get() == S->getHandler())
John Wiegley1c0675e2011-04-28 01:08:34 +00006201 return SemaRef.Owned(S);
6202
David Majnemerfad8f482013-10-15 09:33:02 +00006203 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
6204 TryBlock.take(), Handler.take());
John Wiegley1c0675e2011-04-28 01:08:34 +00006205}
6206
David Majnemerfad8f482013-10-15 09:33:02 +00006207template <typename Derived>
6208StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006209 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006210 if (Block.isInvalid())
6211 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006212
David Majnemerfad8f482013-10-15 09:33:02 +00006213 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.take());
John Wiegley1c0675e2011-04-28 01:08:34 +00006214}
6215
David Majnemerfad8f482013-10-15 09:33:02 +00006216template <typename Derived>
6217StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00006218 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00006219 if (FilterExpr.isInvalid())
6220 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006221
David Majnemer7e755502013-10-15 09:30:14 +00006222 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006223 if (Block.isInvalid())
6224 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006225
David Majnemerfad8f482013-10-15 09:33:02 +00006226 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.take(),
John Wiegley1c0675e2011-04-28 01:08:34 +00006227 Block.take());
6228}
6229
David Majnemerfad8f482013-10-15 09:33:02 +00006230template <typename Derived>
6231StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6232 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00006233 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6234 else
6235 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6236}
6237
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006238template<typename Derived>
6239StmtResult
6240TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006241 DeclarationNameInfo DirName;
6242 getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, 0);
6243
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006244 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00006245 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006246 ArrayRef<OMPClause *> Clauses = D->clauses();
6247 TClauses.reserve(Clauses.size());
6248 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6249 I != E; ++I) {
6250 if (*I) {
6251 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataev758e55e2013-09-06 18:03:48 +00006252 if (!Clause) {
6253 getSema().EndOpenMPDSABlock(0);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006254 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006255 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006256 TClauses.push_back(Clause);
6257 }
6258 else {
6259 TClauses.push_back(0);
6260 }
6261 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00006262 if (!D->getAssociatedStmt()) {
6263 getSema().EndOpenMPDSABlock(0);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006264 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006265 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006266 StmtResult AssociatedStmt =
6267 getDerived().TransformStmt(D->getAssociatedStmt());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006268 if (AssociatedStmt.isInvalid()) {
6269 getSema().EndOpenMPDSABlock(0);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006270 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006271 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006272
Alexey Bataev758e55e2013-09-06 18:03:48 +00006273 StmtResult Res = getDerived().RebuildOMPParallelDirective(TClauses,
6274 AssociatedStmt.take(),
6275 D->getLocStart(),
6276 D->getLocEnd());
6277 getSema().EndOpenMPDSABlock(Res.get());
6278 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006279}
6280
6281template<typename Derived>
6282OMPClause *
6283TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
6284 return getDerived().RebuildOMPDefaultClause(C->getDefaultKind(),
6285 C->getDefaultKindKwLoc(),
6286 C->getLocStart(),
6287 C->getLParenLoc(),
6288 C->getLocEnd());
6289}
6290
6291template<typename Derived>
6292OMPClause *
6293TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006294 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006295 Vars.reserve(C->varlist_size());
Alexey Bataev756c1962013-09-24 03:17:45 +00006296 for (OMPPrivateClause::varlist_iterator I = C->varlist_begin(),
6297 E = C->varlist_end();
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006298 I != E; ++I) {
6299 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6300 if (EVar.isInvalid())
6301 return 0;
6302 Vars.push_back(EVar.take());
6303 }
6304 return getDerived().RebuildOMPPrivateClause(Vars,
6305 C->getLocStart(),
6306 C->getLParenLoc(),
6307 C->getLocEnd());
6308}
6309
Alexey Bataev758e55e2013-09-06 18:03:48 +00006310template<typename Derived>
6311OMPClause *
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006312TreeTransform<Derived>::TransformOMPFirstprivateClause(
6313 OMPFirstprivateClause *C) {
6314 llvm::SmallVector<Expr *, 16> Vars;
6315 Vars.reserve(C->varlist_size());
6316 for (OMPFirstprivateClause::varlist_iterator I = C->varlist_begin(),
6317 E = C->varlist_end();
6318 I != E; ++I) {
6319 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6320 if (EVar.isInvalid())
6321 return 0;
6322 Vars.push_back(EVar.take());
6323 }
6324 return getDerived().RebuildOMPFirstprivateClause(Vars,
6325 C->getLocStart(),
6326 C->getLParenLoc(),
6327 C->getLocEnd());
6328}
6329
6330template<typename Derived>
6331OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00006332TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
6333 llvm::SmallVector<Expr *, 16> Vars;
6334 Vars.reserve(C->varlist_size());
Alexey Bataev756c1962013-09-24 03:17:45 +00006335 for (OMPSharedClause::varlist_iterator I = C->varlist_begin(),
6336 E = C->varlist_end();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006337 I != E; ++I) {
6338 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6339 if (EVar.isInvalid())
6340 return 0;
6341 Vars.push_back(EVar.take());
6342 }
6343 return getDerived().RebuildOMPSharedClause(Vars,
6344 C->getLocStart(),
6345 C->getLParenLoc(),
6346 C->getLocEnd());
6347}
6348
Douglas Gregorebe10102009-08-20 07:17:43 +00006349//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00006350// Expression transformation
6351//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00006352template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006353ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006354TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006355 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006356}
Mike Stump11289f42009-09-09 15:08:12 +00006357
6358template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006359ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006360TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006361 NestedNameSpecifierLoc QualifierLoc;
6362 if (E->getQualifierLoc()) {
6363 QualifierLoc
6364 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6365 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006366 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006367 }
John McCallce546572009-12-08 09:08:17 +00006368
6369 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006370 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6371 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006372 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00006373 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006374
John McCall815039a2010-08-17 21:27:17 +00006375 DeclarationNameInfo NameInfo = E->getNameInfo();
6376 if (NameInfo.getName()) {
6377 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6378 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006379 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00006380 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006381
6382 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006383 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006384 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006385 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00006386 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006387
6388 // Mark it referenced in the new context regardless.
6389 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00006390 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00006391
John McCallc3007a22010-10-26 07:05:15 +00006392 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006393 }
John McCallce546572009-12-08 09:08:17 +00006394
6395 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00006396 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006397 TemplateArgs = &TransArgs;
6398 TransArgs.setLAngleLoc(E->getLAngleLoc());
6399 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006400 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6401 E->getNumTemplateArgs(),
6402 TransArgs))
6403 return ExprError();
John McCallce546572009-12-08 09:08:17 +00006404 }
6405
Chad Rosier1dcde962012-08-08 18:46:20 +00006406 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00006407 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006408}
Mike Stump11289f42009-09-09 15:08:12 +00006409
Douglas Gregora16548e2009-08-11 05:31:07 +00006410template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006411ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006412TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006413 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006414}
Mike Stump11289f42009-09-09 15:08:12 +00006415
Douglas Gregora16548e2009-08-11 05:31:07 +00006416template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006417ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006418TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006419 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006420}
Mike Stump11289f42009-09-09 15:08:12 +00006421
Douglas Gregora16548e2009-08-11 05:31:07 +00006422template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006423ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006424TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006425 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006426}
Mike Stump11289f42009-09-09 15:08:12 +00006427
Douglas Gregora16548e2009-08-11 05:31:07 +00006428template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006429ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006430TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006431 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006432}
Mike Stump11289f42009-09-09 15:08:12 +00006433
Douglas Gregora16548e2009-08-11 05:31:07 +00006434template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006435ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006436TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006437 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006438}
6439
6440template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006441ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00006442TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00006443 if (FunctionDecl *FD = E->getDirectCallee())
6444 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00006445 return SemaRef.MaybeBindToTemporary(E);
6446}
6447
6448template<typename Derived>
6449ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00006450TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6451 ExprResult ControllingExpr =
6452 getDerived().TransformExpr(E->getControllingExpr());
6453 if (ControllingExpr.isInvalid())
6454 return ExprError();
6455
Chris Lattner01cf8db2011-07-20 06:58:45 +00006456 SmallVector<Expr *, 4> AssocExprs;
6457 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00006458 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6459 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6460 if (TS) {
6461 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6462 if (!AssocType)
6463 return ExprError();
6464 AssocTypes.push_back(AssocType);
6465 } else {
6466 AssocTypes.push_back(0);
6467 }
6468
6469 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6470 if (AssocExpr.isInvalid())
6471 return ExprError();
6472 AssocExprs.push_back(AssocExpr.release());
6473 }
6474
6475 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6476 E->getDefaultLoc(),
6477 E->getRParenLoc(),
6478 ControllingExpr.release(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00006479 AssocTypes,
6480 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00006481}
6482
6483template<typename Derived>
6484ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006485TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006486 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006487 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006488 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006489
Douglas Gregora16548e2009-08-11 05:31:07 +00006490 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006491 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006492
John McCallb268a282010-08-23 23:25:46 +00006493 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006494 E->getRParen());
6495}
6496
Richard Smithdb2630f2012-10-21 03:28:35 +00006497/// \brief The operand of a unary address-of operator has special rules: it's
6498/// allowed to refer to a non-static member of a class even if there's no 'this'
6499/// object available.
6500template<typename Derived>
6501ExprResult
6502TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6503 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6504 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6505 else
6506 return getDerived().TransformExpr(E);
6507}
6508
Mike Stump11289f42009-09-09 15:08:12 +00006509template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006510ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006511TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00006512 ExprResult SubExpr;
6513 if (E->getOpcode() == UO_AddrOf)
6514 SubExpr = TransformAddressOfOperand(E->getSubExpr());
6515 else
6516 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006517 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006518 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006519
Douglas Gregora16548e2009-08-11 05:31:07 +00006520 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006521 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006522
Douglas Gregora16548e2009-08-11 05:31:07 +00006523 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6524 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006525 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006526}
Mike Stump11289f42009-09-09 15:08:12 +00006527
Douglas Gregora16548e2009-08-11 05:31:07 +00006528template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006529ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00006530TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6531 // Transform the type.
6532 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6533 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00006534 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006535
Douglas Gregor882211c2010-04-28 22:16:22 +00006536 // Transform all of the components into components similar to what the
6537 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00006538 // FIXME: It would be slightly more efficient in the non-dependent case to
6539 // just map FieldDecls, rather than requiring the rebuilder to look for
6540 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00006541 // template code that we don't care.
6542 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00006543 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00006544 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006545 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00006546 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6547 const Node &ON = E->getComponent(I);
6548 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00006549 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00006550 Comp.LocStart = ON.getSourceRange().getBegin();
6551 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00006552 switch (ON.getKind()) {
6553 case Node::Array: {
6554 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00006555 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00006556 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006557 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006558
Douglas Gregor882211c2010-04-28 22:16:22 +00006559 ExprChanged = ExprChanged || Index.get() != FromIndex;
6560 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00006561 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00006562 break;
6563 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006564
Douglas Gregor882211c2010-04-28 22:16:22 +00006565 case Node::Field:
6566 case Node::Identifier:
6567 Comp.isBrackets = false;
6568 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00006569 if (!Comp.U.IdentInfo)
6570 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00006571
Douglas Gregor882211c2010-04-28 22:16:22 +00006572 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006573
Douglas Gregord1702062010-04-29 00:18:15 +00006574 case Node::Base:
6575 // Will be recomputed during the rebuild.
6576 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00006577 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006578
Douglas Gregor882211c2010-04-28 22:16:22 +00006579 Components.push_back(Comp);
6580 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006581
Douglas Gregor882211c2010-04-28 22:16:22 +00006582 // If nothing changed, retain the existing expression.
6583 if (!getDerived().AlwaysRebuild() &&
6584 Type == E->getTypeSourceInfo() &&
6585 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00006586 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00006587
Douglas Gregor882211c2010-04-28 22:16:22 +00006588 // Build a new offsetof expression.
6589 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6590 Components.data(), Components.size(),
6591 E->getRParenLoc());
6592}
6593
6594template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006595ExprResult
John McCall8d69a212010-11-15 23:31:06 +00006596TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6597 assert(getDerived().AlreadyTransformed(E->getType()) &&
6598 "opaque value expression requires transformation");
6599 return SemaRef.Owned(E);
6600}
6601
6602template<typename Derived>
6603ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00006604TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00006605 // Rebuild the syntactic form. The original syntactic form has
6606 // opaque-value expressions in it, so strip those away and rebuild
6607 // the result. This is a really awful way of doing this, but the
6608 // better solution (rebuilding the semantic expressions and
6609 // rebinding OVEs as necessary) doesn't work; we'd need
6610 // TreeTransform to not strip away implicit conversions.
6611 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6612 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00006613 if (result.isInvalid()) return ExprError();
6614
6615 // If that gives us a pseudo-object result back, the pseudo-object
6616 // expression must have been an lvalue-to-rvalue conversion which we
6617 // should reapply.
6618 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6619 result = SemaRef.checkPseudoObjectRValue(result.take());
6620
6621 return result;
6622}
6623
6624template<typename Derived>
6625ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00006626TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6627 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006628 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00006629 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00006630
John McCallbcd03502009-12-07 02:54:59 +00006631 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00006632 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006633 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006634
John McCall4c98fd82009-11-04 07:28:41 +00006635 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00006636 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006637
Peter Collingbournee190dee2011-03-11 19:24:49 +00006638 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6639 E->getKind(),
6640 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006641 }
Mike Stump11289f42009-09-09 15:08:12 +00006642
Eli Friedmane4f22df2012-02-29 04:03:55 +00006643 // C++0x [expr.sizeof]p1:
6644 // The operand is either an expression, which is an unevaluated operand
6645 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00006646 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6647 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00006648
Eli Friedmane4f22df2012-02-29 04:03:55 +00006649 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6650 if (SubExpr.isInvalid())
6651 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006652
Eli Friedmane4f22df2012-02-29 04:03:55 +00006653 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6654 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006655
Peter Collingbournee190dee2011-03-11 19:24:49 +00006656 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6657 E->getOperatorLoc(),
6658 E->getKind(),
6659 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006660}
Mike Stump11289f42009-09-09 15:08:12 +00006661
Douglas Gregora16548e2009-08-11 05:31:07 +00006662template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006663ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006664TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006665 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006666 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006667 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006668
John McCalldadc5752010-08-24 06:29:42 +00006669 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006670 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006671 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006672
6673
Douglas Gregora16548e2009-08-11 05:31:07 +00006674 if (!getDerived().AlwaysRebuild() &&
6675 LHS.get() == E->getLHS() &&
6676 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006677 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006678
John McCallb268a282010-08-23 23:25:46 +00006679 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006680 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006681 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006682 E->getRBracketLoc());
6683}
Mike Stump11289f42009-09-09 15:08:12 +00006684
6685template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006686ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006687TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006688 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00006689 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006690 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006691 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006692
6693 // Transform arguments.
6694 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006695 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00006696 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00006697 &ArgChanged))
6698 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006699
Douglas Gregora16548e2009-08-11 05:31:07 +00006700 if (!getDerived().AlwaysRebuild() &&
6701 Callee.get() == E->getCallee() &&
6702 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00006703 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00006704
Douglas Gregora16548e2009-08-11 05:31:07 +00006705 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00006706 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006707 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00006708 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006709 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00006710 E->getRParenLoc());
6711}
Mike Stump11289f42009-09-09 15:08:12 +00006712
6713template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006714ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006715TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006716 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006717 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006718 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006719
Douglas Gregorea972d32011-02-28 21:54:11 +00006720 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006721 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006722 QualifierLoc
6723 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006724
Douglas Gregorea972d32011-02-28 21:54:11 +00006725 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006726 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006727 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00006728 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00006729
Eli Friedman2cfcef62009-12-04 06:40:45 +00006730 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006731 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6732 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006733 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00006734 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006735
John McCall16df1e52010-03-30 21:47:33 +00006736 NamedDecl *FoundDecl = E->getFoundDecl();
6737 if (FoundDecl == E->getMemberDecl()) {
6738 FoundDecl = Member;
6739 } else {
6740 FoundDecl = cast_or_null<NamedDecl>(
6741 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6742 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00006743 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00006744 }
6745
Douglas Gregora16548e2009-08-11 05:31:07 +00006746 if (!getDerived().AlwaysRebuild() &&
6747 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006748 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006749 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00006750 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00006751 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006752
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006753 // Mark it referenced in the new context regardless.
6754 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00006755 SemaRef.MarkMemberReferenced(E);
6756
John McCallc3007a22010-10-26 07:05:15 +00006757 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006758 }
Douglas Gregora16548e2009-08-11 05:31:07 +00006759
John McCall6b51f282009-11-23 01:53:49 +00006760 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00006761 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00006762 TransArgs.setLAngleLoc(E->getLAngleLoc());
6763 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006764 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6765 E->getNumTemplateArgs(),
6766 TransArgs))
6767 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006768 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006769
Douglas Gregora16548e2009-08-11 05:31:07 +00006770 // FIXME: Bogus source location for the operator
6771 SourceLocation FakeOperatorLoc
6772 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6773
John McCall38836f02010-01-15 08:34:02 +00006774 // FIXME: to do this check properly, we will need to preserve the
6775 // first-qualifier-in-scope here, just in case we had a dependent
6776 // base (and therefore couldn't do the check) and a
6777 // nested-name-qualifier (and therefore could do the lookup).
6778 NamedDecl *FirstQualifierInScope = 0;
6779
John McCallb268a282010-08-23 23:25:46 +00006780 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006781 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00006782 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00006783 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006784 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006785 Member,
John McCall16df1e52010-03-30 21:47:33 +00006786 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00006787 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00006788 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00006789 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00006790}
Mike Stump11289f42009-09-09 15:08:12 +00006791
Douglas Gregora16548e2009-08-11 05:31:07 +00006792template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006793ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006794TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006795 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006796 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006797 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006798
John McCalldadc5752010-08-24 06:29:42 +00006799 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006800 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006801 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006802
Douglas Gregora16548e2009-08-11 05:31:07 +00006803 if (!getDerived().AlwaysRebuild() &&
6804 LHS.get() == E->getLHS() &&
6805 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006806 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006807
Lang Hames5de91cc2012-10-02 04:45:10 +00006808 Sema::FPContractStateRAII FPContractState(getSema());
6809 getSema().FPFeatures.fp_contract = E->isFPContractable();
6810
Douglas Gregora16548e2009-08-11 05:31:07 +00006811 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006812 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006813}
6814
Mike Stump11289f42009-09-09 15:08:12 +00006815template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006816ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006817TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00006818 CompoundAssignOperator *E) {
6819 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006820}
Mike Stump11289f42009-09-09 15:08:12 +00006821
Douglas Gregora16548e2009-08-11 05:31:07 +00006822template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00006823ExprResult TreeTransform<Derived>::
6824TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6825 // Just rebuild the common and RHS expressions and see whether we
6826 // get any changes.
6827
6828 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6829 if (commonExpr.isInvalid())
6830 return ExprError();
6831
6832 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6833 if (rhs.isInvalid())
6834 return ExprError();
6835
6836 if (!getDerived().AlwaysRebuild() &&
6837 commonExpr.get() == e->getCommon() &&
6838 rhs.get() == e->getFalseExpr())
6839 return SemaRef.Owned(e);
6840
6841 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6842 e->getQuestionLoc(),
6843 0,
6844 e->getColonLoc(),
6845 rhs.get());
6846}
6847
6848template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006849ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006850TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006851 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006852 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006853 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006854
John McCalldadc5752010-08-24 06:29:42 +00006855 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006856 if (LHS.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 RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006860 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006861 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006862
Douglas Gregora16548e2009-08-11 05:31:07 +00006863 if (!getDerived().AlwaysRebuild() &&
6864 Cond.get() == E->getCond() &&
6865 LHS.get() == E->getLHS() &&
6866 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006867 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006868
John McCallb268a282010-08-23 23:25:46 +00006869 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006870 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00006871 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006872 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006873 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006874}
Mike Stump11289f42009-09-09 15:08:12 +00006875
6876template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006877ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006878TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00006879 // Implicit casts are eliminated during transformation, since they
6880 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00006881 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006882}
Mike Stump11289f42009-09-09 15:08:12 +00006883
Douglas Gregora16548e2009-08-11 05:31:07 +00006884template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006885ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006886TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006887 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6888 if (!Type)
6889 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006890
John McCalldadc5752010-08-24 06:29:42 +00006891 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006892 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006893 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006894 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006895
Douglas Gregora16548e2009-08-11 05:31:07 +00006896 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006897 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006898 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006899 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006900
John McCall97513962010-01-15 18:39:57 +00006901 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006902 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006903 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006904 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006905}
Mike Stump11289f42009-09-09 15:08:12 +00006906
Douglas Gregora16548e2009-08-11 05:31:07 +00006907template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006908ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006909TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00006910 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6911 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6912 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006913 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006914
John McCalldadc5752010-08-24 06:29:42 +00006915 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00006916 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006917 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006918
Douglas Gregora16548e2009-08-11 05:31:07 +00006919 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00006920 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006921 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00006922 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006923
John McCall5d7aa7f2010-01-19 22:33:45 +00006924 // Note: the expression type doesn't necessarily match the
6925 // type-as-written, but that's okay, because it should always be
6926 // derivable from the initializer.
6927
John McCalle15bbff2010-01-18 19:35:47 +00006928 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00006929 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00006930 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006931}
Mike Stump11289f42009-09-09 15:08:12 +00006932
Douglas Gregora16548e2009-08-11 05:31:07 +00006933template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006934ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006935TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006936 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006937 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006938 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006939
Douglas Gregora16548e2009-08-11 05:31:07 +00006940 if (!getDerived().AlwaysRebuild() &&
6941 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006942 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006943
Douglas Gregora16548e2009-08-11 05:31:07 +00006944 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00006945 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006946 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00006947 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006948 E->getAccessorLoc(),
6949 E->getAccessor());
6950}
Mike Stump11289f42009-09-09 15:08:12 +00006951
Douglas Gregora16548e2009-08-11 05:31:07 +00006952template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006953ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006954TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006955 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00006956
Benjamin Kramerf0623432012-08-23 22:51:59 +00006957 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00006958 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00006959 Inits, &InitChanged))
6960 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006961
Douglas Gregora16548e2009-08-11 05:31:07 +00006962 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00006963 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006964
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006965 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00006966 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00006967}
Mike Stump11289f42009-09-09 15:08:12 +00006968
Douglas Gregora16548e2009-08-11 05:31:07 +00006969template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006970ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006971TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006972 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00006973
Douglas Gregorebe10102009-08-20 07:17:43 +00006974 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00006975 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006976 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006977 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006978
Douglas Gregorebe10102009-08-20 07:17:43 +00006979 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00006980 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00006981 bool ExprChanged = false;
6982 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6983 DEnd = E->designators_end();
6984 D != DEnd; ++D) {
6985 if (D->isFieldDesignator()) {
6986 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6987 D->getDotLoc(),
6988 D->getFieldLoc()));
6989 continue;
6990 }
Mike Stump11289f42009-09-09 15:08:12 +00006991
Douglas Gregora16548e2009-08-11 05:31:07 +00006992 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00006993 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00006994 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006995 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006996
6997 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006998 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00006999
Douglas Gregora16548e2009-08-11 05:31:07 +00007000 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
7001 ArrayExprs.push_back(Index.release());
7002 continue;
7003 }
Mike Stump11289f42009-09-09 15:08:12 +00007004
Douglas Gregora16548e2009-08-11 05:31:07 +00007005 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00007006 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00007007 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7008 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007009 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007010
John McCalldadc5752010-08-24 06:29:42 +00007011 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007012 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007013 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007014
7015 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007016 End.get(),
7017 D->getLBracketLoc(),
7018 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007019
Douglas Gregora16548e2009-08-11 05:31:07 +00007020 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7021 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00007022
Douglas Gregora16548e2009-08-11 05:31:07 +00007023 ArrayExprs.push_back(Start.release());
7024 ArrayExprs.push_back(End.release());
7025 }
Mike Stump11289f42009-09-09 15:08:12 +00007026
Douglas Gregora16548e2009-08-11 05:31:07 +00007027 if (!getDerived().AlwaysRebuild() &&
7028 Init.get() == E->getInit() &&
7029 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00007030 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007031
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007032 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007033 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007034 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007035}
Mike Stump11289f42009-09-09 15:08:12 +00007036
Douglas Gregora16548e2009-08-11 05:31:07 +00007037template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007038ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007039TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007040 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00007041 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00007042
Douglas Gregor3da3c062009-10-28 00:29:27 +00007043 // FIXME: Will we ever have proper type location here? Will we actually
7044 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00007045 QualType T = getDerived().TransformType(E->getType());
7046 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007047 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007048
Douglas Gregora16548e2009-08-11 05:31:07 +00007049 if (!getDerived().AlwaysRebuild() &&
7050 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00007051 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007052
Douglas Gregora16548e2009-08-11 05:31:07 +00007053 return getDerived().RebuildImplicitValueInitExpr(T);
7054}
Mike Stump11289f42009-09-09 15:08:12 +00007055
Douglas Gregora16548e2009-08-11 05:31:07 +00007056template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007057ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007058TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00007059 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7060 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007061 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007062
John McCalldadc5752010-08-24 06:29:42 +00007063 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007064 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007065 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007066
Douglas Gregora16548e2009-08-11 05:31:07 +00007067 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00007068 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007069 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007070 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007071
John McCallb268a282010-08-23 23:25:46 +00007072 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00007073 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007074}
7075
7076template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007077ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007078TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007079 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007080 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00007081 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7082 &ArgumentChanged))
7083 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007084
Douglas Gregora16548e2009-08-11 05:31:07 +00007085 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007086 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00007087 E->getRParenLoc());
7088}
Mike Stump11289f42009-09-09 15:08:12 +00007089
Douglas Gregora16548e2009-08-11 05:31:07 +00007090/// \brief Transform an address-of-label expression.
7091///
7092/// By default, the transformation of an address-of-label expression always
7093/// rebuilds the expression, so that the label identifier can be resolved to
7094/// the corresponding label statement by semantic analysis.
7095template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007096ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007097TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00007098 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7099 E->getLabel());
7100 if (!LD)
7101 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007102
Douglas Gregora16548e2009-08-11 05:31:07 +00007103 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00007104 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00007105}
Mike Stump11289f42009-09-09 15:08:12 +00007106
7107template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00007108ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007109TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00007110 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00007111 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00007112 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00007113 if (SubStmt.isInvalid()) {
7114 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00007115 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00007116 }
Mike Stump11289f42009-09-09 15:08:12 +00007117
Douglas Gregora16548e2009-08-11 05:31:07 +00007118 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00007119 SubStmt.get() == E->getSubStmt()) {
7120 // Calling this an 'error' is unintuitive, but it does the right thing.
7121 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007122 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00007123 }
Mike Stump11289f42009-09-09 15:08:12 +00007124
7125 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007126 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007127 E->getRParenLoc());
7128}
Mike Stump11289f42009-09-09 15:08:12 +00007129
Douglas Gregora16548e2009-08-11 05:31:07 +00007130template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007131ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007132TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007133 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007134 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007135 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007136
John McCalldadc5752010-08-24 06:29:42 +00007137 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007138 if (LHS.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 RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007142 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007143 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007144
Douglas Gregora16548e2009-08-11 05:31:07 +00007145 if (!getDerived().AlwaysRebuild() &&
7146 Cond.get() == E->getCond() &&
7147 LHS.get() == E->getLHS() &&
7148 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00007149 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007150
Douglas Gregora16548e2009-08-11 05:31:07 +00007151 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00007152 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007153 E->getRParenLoc());
7154}
Mike Stump11289f42009-09-09 15:08:12 +00007155
Douglas Gregora16548e2009-08-11 05:31:07 +00007156template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007157ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007158TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007159 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007160}
7161
7162template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007163ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007164TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007165 switch (E->getOperator()) {
7166 case OO_New:
7167 case OO_Delete:
7168 case OO_Array_New:
7169 case OO_Array_Delete:
7170 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00007171
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007172 case OO_Call: {
7173 // This is a call to an object's operator().
7174 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7175
7176 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00007177 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007178 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007179 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007180
7181 // FIXME: Poor location information
7182 SourceLocation FakeLParenLoc
7183 = SemaRef.PP.getLocForEndOfToken(
7184 static_cast<Expr *>(Object.get())->getLocEnd());
7185
7186 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007187 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007188 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00007189 Args))
7190 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007191
John McCallb268a282010-08-23 23:25:46 +00007192 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007193 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007194 E->getLocEnd());
7195 }
7196
7197#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7198 case OO_##Name:
7199#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7200#include "clang/Basic/OperatorKinds.def"
7201 case OO_Subscript:
7202 // Handled below.
7203 break;
7204
7205 case OO_Conditional:
7206 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007207
7208 case OO_None:
7209 case NUM_OVERLOADED_OPERATORS:
7210 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007211 }
7212
John McCalldadc5752010-08-24 06:29:42 +00007213 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007214 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007215 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007216
Richard Smithdb2630f2012-10-21 03:28:35 +00007217 ExprResult First;
7218 if (E->getOperator() == OO_Amp)
7219 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7220 else
7221 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007222 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007223 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007224
John McCalldadc5752010-08-24 06:29:42 +00007225 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00007226 if (E->getNumArgs() == 2) {
7227 Second = getDerived().TransformExpr(E->getArg(1));
7228 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007229 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007230 }
Mike Stump11289f42009-09-09 15:08:12 +00007231
Douglas Gregora16548e2009-08-11 05:31:07 +00007232 if (!getDerived().AlwaysRebuild() &&
7233 Callee.get() == E->getCallee() &&
7234 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00007235 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007236 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007237
Lang Hames5de91cc2012-10-02 04:45:10 +00007238 Sema::FPContractStateRAII FPContractState(getSema());
7239 getSema().FPFeatures.fp_contract = E->isFPContractable();
7240
Douglas Gregora16548e2009-08-11 05:31:07 +00007241 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7242 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00007243 Callee.get(),
7244 First.get(),
7245 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007246}
Mike Stump11289f42009-09-09 15:08:12 +00007247
Douglas Gregora16548e2009-08-11 05:31:07 +00007248template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007249ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007250TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7251 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007252}
Mike Stump11289f42009-09-09 15:08:12 +00007253
Douglas Gregora16548e2009-08-11 05:31:07 +00007254template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007255ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00007256TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7257 // Transform the callee.
7258 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7259 if (Callee.isInvalid())
7260 return ExprError();
7261
7262 // Transform exec config.
7263 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7264 if (EC.isInvalid())
7265 return ExprError();
7266
7267 // Transform arguments.
7268 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007269 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007270 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007271 &ArgChanged))
7272 return ExprError();
7273
7274 if (!getDerived().AlwaysRebuild() &&
7275 Callee.get() == E->getCallee() &&
7276 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007277 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00007278
7279 // FIXME: Wrong source location information for the '('.
7280 SourceLocation FakeLParenLoc
7281 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7282 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007283 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007284 E->getRParenLoc(), EC.get());
7285}
7286
7287template<typename Derived>
7288ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007289TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007290 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7291 if (!Type)
7292 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007293
John McCalldadc5752010-08-24 06:29:42 +00007294 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007295 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007296 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007297 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007298
Douglas Gregora16548e2009-08-11 05:31:07 +00007299 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007300 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007301 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007302 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007303 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00007304 E->getStmtClass(),
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007305 E->getAngleBrackets().getBegin(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007306 Type,
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007307 E->getAngleBrackets().getEnd(),
7308 // FIXME. this should be '(' location
7309 E->getAngleBrackets().getEnd(),
John McCallb268a282010-08-23 23:25:46 +00007310 SubExpr.get(),
Abramo Bagnara9fb43862012-10-15 21:08:58 +00007311 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007312}
Mike Stump11289f42009-09-09 15:08:12 +00007313
Douglas Gregora16548e2009-08-11 05:31:07 +00007314template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007315ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007316TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7317 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007318}
Mike Stump11289f42009-09-09 15:08:12 +00007319
7320template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007321ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007322TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7323 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00007324}
7325
Douglas Gregora16548e2009-08-11 05:31:07 +00007326template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007327ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007328TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007329 CXXReinterpretCastExpr *E) {
7330 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007331}
Mike Stump11289f42009-09-09 15:08:12 +00007332
Douglas Gregora16548e2009-08-11 05:31:07 +00007333template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007334ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007335TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7336 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007337}
Mike Stump11289f42009-09-09 15:08:12 +00007338
Douglas Gregora16548e2009-08-11 05:31:07 +00007339template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007340ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007341TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007342 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007343 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7344 if (!Type)
7345 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007346
John McCalldadc5752010-08-24 06:29:42 +00007347 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007348 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007349 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007350 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007351
Douglas Gregora16548e2009-08-11 05:31:07 +00007352 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007353 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007354 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007355 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007356
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007357 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00007358 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007359 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007360 E->getRParenLoc());
7361}
Mike Stump11289f42009-09-09 15:08:12 +00007362
Douglas Gregora16548e2009-08-11 05:31:07 +00007363template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007364ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007365TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007366 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00007367 TypeSourceInfo *TInfo
7368 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7369 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007370 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007371
Douglas Gregora16548e2009-08-11 05:31:07 +00007372 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00007373 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007374 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007375
Douglas Gregor9da64192010-04-26 22:37:10 +00007376 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7377 E->getLocStart(),
7378 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007379 E->getLocEnd());
7380 }
Mike Stump11289f42009-09-09 15:08:12 +00007381
Eli Friedman456f0182012-01-20 01:26:23 +00007382 // We don't know whether the subexpression is potentially evaluated until
7383 // after we perform semantic analysis. We speculatively assume it is
7384 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00007385 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00007386 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7387 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007388
John McCalldadc5752010-08-24 06:29:42 +00007389 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00007390 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007391 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007392
Douglas Gregora16548e2009-08-11 05:31:07 +00007393 if (!getDerived().AlwaysRebuild() &&
7394 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00007395 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007396
Douglas Gregor9da64192010-04-26 22:37:10 +00007397 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7398 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007399 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007400 E->getLocEnd());
7401}
7402
7403template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007404ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00007405TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7406 if (E->isTypeOperand()) {
7407 TypeSourceInfo *TInfo
7408 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7409 if (!TInfo)
7410 return ExprError();
7411
7412 if (!getDerived().AlwaysRebuild() &&
7413 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007414 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00007415
Douglas Gregor69735112011-03-06 17:40:41 +00007416 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00007417 E->getLocStart(),
7418 TInfo,
7419 E->getLocEnd());
7420 }
7421
Francois Pichet9f4f2072010-09-08 12:20:18 +00007422 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7423
7424 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7425 if (SubExpr.isInvalid())
7426 return ExprError();
7427
7428 if (!getDerived().AlwaysRebuild() &&
7429 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00007430 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00007431
7432 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7433 E->getLocStart(),
7434 SubExpr.get(),
7435 E->getLocEnd());
7436}
7437
7438template<typename Derived>
7439ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007440TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007441 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007442}
Mike Stump11289f42009-09-09 15:08:12 +00007443
Douglas Gregora16548e2009-08-11 05:31:07 +00007444template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007445ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007446TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007447 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007448 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007449}
Mike Stump11289f42009-09-09 15:08:12 +00007450
Douglas Gregora16548e2009-08-11 05:31:07 +00007451template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007452ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007453TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00007454 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00007455
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007456 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7457 // Make sure that we capture 'this'.
7458 getSema().CheckCXXThisCapture(E->getLocStart());
John McCallc3007a22010-10-26 07:05:15 +00007459 return SemaRef.Owned(E);
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007460 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007461
Douglas Gregorb15af892010-01-07 23:12:05 +00007462 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007463}
Mike Stump11289f42009-09-09 15:08:12 +00007464
Douglas Gregora16548e2009-08-11 05:31:07 +00007465template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007466ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007467TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007468 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007469 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007470 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007471
Douglas Gregora16548e2009-08-11 05:31:07 +00007472 if (!getDerived().AlwaysRebuild() &&
7473 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007474 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007475
Douglas Gregor53e191ed2011-07-06 22:04:06 +00007476 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7477 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00007478}
Mike Stump11289f42009-09-09 15:08:12 +00007479
Douglas Gregora16548e2009-08-11 05:31:07 +00007480template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007481ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007482TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00007483 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007484 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7485 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007486 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00007487 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007488
Chandler Carruth794da4c2010-02-08 06:42:49 +00007489 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007490 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00007491 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007492
Douglas Gregor033f6752009-12-23 23:03:06 +00007493 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00007494}
Mike Stump11289f42009-09-09 15:08:12 +00007495
Douglas Gregora16548e2009-08-11 05:31:07 +00007496template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007497ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00007498TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
7499 FieldDecl *Field
7500 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
7501 E->getField()));
7502 if (!Field)
7503 return ExprError();
7504
7505 if (!getDerived().AlwaysRebuild() && Field == E->getField())
7506 return SemaRef.Owned(E);
7507
7508 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
7509}
7510
7511template<typename Derived>
7512ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00007513TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7514 CXXScalarValueInitExpr *E) {
7515 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7516 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007517 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007518
Douglas Gregora16548e2009-08-11 05:31:07 +00007519 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007520 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007521 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007522
Chad Rosier1dcde962012-08-08 18:46:20 +00007523 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00007524 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00007525 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007526}
Mike Stump11289f42009-09-09 15:08:12 +00007527
Douglas Gregora16548e2009-08-11 05:31:07 +00007528template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007529ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007530TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007531 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00007532 TypeSourceInfo *AllocTypeInfo
7533 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7534 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007535 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007536
Douglas Gregora16548e2009-08-11 05:31:07 +00007537 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00007538 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00007539 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007540 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007541
Douglas Gregora16548e2009-08-11 05:31:07 +00007542 // Transform the placement arguments (if any).
7543 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007544 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00007545 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00007546 E->getNumPlacementArgs(), true,
7547 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00007548 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007549
Sebastian Redl6047f072012-02-16 12:22:20 +00007550 // Transform the initializer (if any).
7551 Expr *OldInit = E->getInitializer();
7552 ExprResult NewInit;
7553 if (OldInit)
7554 NewInit = getDerived().TransformExpr(OldInit);
7555 if (NewInit.isInvalid())
7556 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007557
Sebastian Redl6047f072012-02-16 12:22:20 +00007558 // Transform new operator and delete operator.
Douglas Gregord2d9da02010-02-26 00:38:10 +00007559 FunctionDecl *OperatorNew = 0;
7560 if (E->getOperatorNew()) {
7561 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007562 getDerived().TransformDecl(E->getLocStart(),
7563 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007564 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00007565 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007566 }
7567
7568 FunctionDecl *OperatorDelete = 0;
7569 if (E->getOperatorDelete()) {
7570 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007571 getDerived().TransformDecl(E->getLocStart(),
7572 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007573 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007574 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007575 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007576
Douglas Gregora16548e2009-08-11 05:31:07 +00007577 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00007578 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007579 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00007580 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007581 OperatorNew == E->getOperatorNew() &&
7582 OperatorDelete == E->getOperatorDelete() &&
7583 !ArgumentChanged) {
7584 // Mark any declarations we need as referenced.
7585 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00007586 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007587 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007588 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007589 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00007590
Sebastian Redl6047f072012-02-16 12:22:20 +00007591 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00007592 QualType ElementType
7593 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7594 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7595 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7596 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00007597 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00007598 }
7599 }
7600 }
Sebastian Redl6047f072012-02-16 12:22:20 +00007601
John McCallc3007a22010-10-26 07:05:15 +00007602 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007603 }
Mike Stump11289f42009-09-09 15:08:12 +00007604
Douglas Gregor0744ef62010-09-07 21:49:58 +00007605 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007606 if (!ArraySize.get()) {
7607 // If no array size was specified, but the new expression was
7608 // instantiated with an array type (e.g., "new T" where T is
7609 // instantiated with "int[4]"), extract the outer bound from the
7610 // array type as our array size. We do this with constant and
7611 // dependently-sized array types.
7612 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7613 if (!ArrayT) {
7614 // Do nothing
7615 } else if (const ConstantArrayType *ConsArrayT
7616 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007617 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007618 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier1dcde962012-08-08 18:46:20 +00007619 ConsArrayT->getSize(),
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007620 SemaRef.Context.getSizeType(),
7621 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007622 AllocType = ConsArrayT->getElementType();
7623 } else if (const DependentSizedArrayType *DepArrayT
7624 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7625 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00007626 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007627 AllocType = DepArrayT->getElementType();
7628 }
7629 }
7630 }
Sebastian Redl6047f072012-02-16 12:22:20 +00007631
Douglas Gregora16548e2009-08-11 05:31:07 +00007632 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7633 E->isGlobalNew(),
7634 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007635 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007636 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00007637 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007638 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00007639 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00007640 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00007641 E->getDirectInitRange(),
7642 NewInit.take());
Douglas Gregora16548e2009-08-11 05:31:07 +00007643}
Mike Stump11289f42009-09-09 15:08:12 +00007644
Douglas Gregora16548e2009-08-11 05:31:07 +00007645template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007646ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007647TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007648 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00007649 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007650 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007651
Douglas Gregord2d9da02010-02-26 00:38:10 +00007652 // Transform the delete operator, if known.
7653 FunctionDecl *OperatorDelete = 0;
7654 if (E->getOperatorDelete()) {
7655 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007656 getDerived().TransformDecl(E->getLocStart(),
7657 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007658 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007659 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007660 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007661
Douglas Gregora16548e2009-08-11 05:31:07 +00007662 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007663 Operand.get() == E->getArgument() &&
7664 OperatorDelete == E->getOperatorDelete()) {
7665 // Mark any declarations we need as referenced.
7666 // FIXME: instantiation-specific.
7667 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007668 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00007669
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00007670 if (!E->getArgument()->isTypeDependent()) {
7671 QualType Destroyed = SemaRef.Context.getBaseElementType(
7672 E->getDestroyedType());
7673 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7674 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00007675 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00007676 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00007677 }
7678 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007679
John McCallc3007a22010-10-26 07:05:15 +00007680 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007681 }
Mike Stump11289f42009-09-09 15:08:12 +00007682
Douglas Gregora16548e2009-08-11 05:31:07 +00007683 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7684 E->isGlobalDelete(),
7685 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00007686 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007687}
Mike Stump11289f42009-09-09 15:08:12 +00007688
Douglas Gregora16548e2009-08-11 05:31:07 +00007689template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007690ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00007691TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007692 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007693 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00007694 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007695 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007696
John McCallba7bf592010-08-24 05:47:05 +00007697 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00007698 bool MayBePseudoDestructor = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00007699 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007700 E->getOperatorLoc(),
7701 E->isArrow()? tok::arrow : tok::period,
7702 ObjectTypePtr,
7703 MayBePseudoDestructor);
7704 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007705 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007706
John McCallba7bf592010-08-24 05:47:05 +00007707 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00007708 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7709 if (QualifierLoc) {
7710 QualifierLoc
7711 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7712 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00007713 return ExprError();
7714 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00007715 CXXScopeSpec SS;
7716 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00007717
Douglas Gregor678f90d2010-02-25 01:56:36 +00007718 PseudoDestructorTypeStorage Destroyed;
7719 if (E->getDestroyedTypeInfo()) {
7720 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00007721 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00007722 ObjectType, 0, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00007723 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007724 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00007725 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00007726 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00007727 // We aren't likely to be able to resolve the identifier down to a type
7728 // now anyway, so just retain the identifier.
7729 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7730 E->getDestroyedTypeLoc());
7731 } else {
7732 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00007733 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007734 *E->getDestroyedTypeIdentifier(),
7735 E->getDestroyedTypeLoc(),
7736 /*Scope=*/0,
7737 SS, ObjectTypePtr,
7738 false);
7739 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007740 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007741
Douglas Gregor678f90d2010-02-25 01:56:36 +00007742 Destroyed
7743 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7744 E->getDestroyedTypeLoc());
7745 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007746
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007747 TypeSourceInfo *ScopeTypeInfo = 0;
7748 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00007749 CXXScopeSpec EmptySS;
7750 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
7751 E->getScopeTypeInfo(), ObjectType, 0, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007752 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007753 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00007754 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007755
John McCallb268a282010-08-23 23:25:46 +00007756 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00007757 E->getOperatorLoc(),
7758 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00007759 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007760 ScopeTypeInfo,
7761 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007762 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007763 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00007764}
Mike Stump11289f42009-09-09 15:08:12 +00007765
Douglas Gregorad8a3362009-09-04 17:36:40 +00007766template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007767ExprResult
John McCalld14a8642009-11-21 08:51:07 +00007768TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007769 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00007770 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7771 Sema::LookupOrdinaryName);
7772
7773 // Transform all the decls.
7774 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7775 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007776 NamedDecl *InstD = static_cast<NamedDecl*>(
7777 getDerived().TransformDecl(Old->getNameLoc(),
7778 *I));
John McCall84d87672009-12-10 09:41:52 +00007779 if (!InstD) {
7780 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7781 // This can happen because of dependent hiding.
7782 if (isa<UsingShadowDecl>(*I))
7783 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00007784 else {
7785 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007786 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00007787 }
John McCall84d87672009-12-10 09:41:52 +00007788 }
John McCalle66edc12009-11-24 19:00:30 +00007789
7790 // Expand using declarations.
7791 if (isa<UsingDecl>(InstD)) {
7792 UsingDecl *UD = cast<UsingDecl>(InstD);
7793 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7794 E = UD->shadow_end(); I != E; ++I)
7795 R.addDecl(*I);
7796 continue;
7797 }
7798
7799 R.addDecl(InstD);
7800 }
7801
7802 // Resolve a kind, but don't do any further analysis. If it's
7803 // ambiguous, the callee needs to deal with it.
7804 R.resolveKind();
7805
7806 // Rebuild the nested-name qualifier, if present.
7807 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00007808 if (Old->getQualifierLoc()) {
7809 NestedNameSpecifierLoc QualifierLoc
7810 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7811 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007812 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007813
Douglas Gregor0da1d432011-02-28 20:01:57 +00007814 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00007815 }
7816
Douglas Gregor9262f472010-04-27 18:19:34 +00007817 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00007818 CXXRecordDecl *NamingClass
7819 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7820 Old->getNameLoc(),
7821 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00007822 if (!NamingClass) {
7823 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007824 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00007825 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007826
Douglas Gregorda7be082010-04-27 16:10:10 +00007827 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00007828 }
7829
Abramo Bagnara7945c982012-01-27 09:46:47 +00007830 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7831
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00007832 // If we have neither explicit template arguments, nor the template keyword,
7833 // it's a normal declaration name.
7834 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCalle66edc12009-11-24 19:00:30 +00007835 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7836
7837 // If we have template arguments, rebuild them, then rebuild the
7838 // templateid expression.
7839 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00007840 if (Old->hasExplicitTemplateArgs() &&
7841 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00007842 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00007843 TransArgs)) {
7844 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00007845 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00007846 }
John McCalle66edc12009-11-24 19:00:30 +00007847
Abramo Bagnara7945c982012-01-27 09:46:47 +00007848 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00007849 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007850}
Mike Stump11289f42009-09-09 15:08:12 +00007851
Douglas Gregora16548e2009-08-11 05:31:07 +00007852template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007853ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00007854TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7855 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00007856 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00007857 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7858 TypeSourceInfo *From = E->getArg(I);
7859 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00007860 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00007861 TypeLocBuilder TLB;
7862 TLB.reserve(FromTL.getFullDataSize());
7863 QualType To = getDerived().TransformType(TLB, FromTL);
7864 if (To.isNull())
7865 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007866
Douglas Gregor29c42f22012-02-24 07:38:34 +00007867 if (To == From->getType())
7868 Args.push_back(From);
7869 else {
7870 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7871 ArgChanged = true;
7872 }
7873 continue;
7874 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007875
Douglas Gregor29c42f22012-02-24 07:38:34 +00007876 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00007877
Douglas Gregor29c42f22012-02-24 07:38:34 +00007878 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00007879 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00007880 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7881 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7882 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00007883
Douglas Gregor29c42f22012-02-24 07:38:34 +00007884 // Determine whether the set of unexpanded parameter packs can and should
7885 // be expanded.
7886 bool Expand = true;
7887 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00007888 Optional<unsigned> OrigNumExpansions =
7889 ExpansionTL.getTypePtr()->getNumExpansions();
7890 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00007891 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7892 PatternTL.getSourceRange(),
7893 Unexpanded,
7894 Expand, RetainExpansion,
7895 NumExpansions))
7896 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007897
Douglas Gregor29c42f22012-02-24 07:38:34 +00007898 if (!Expand) {
7899 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00007900 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00007901 // expansion.
7902 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00007903
Douglas Gregor29c42f22012-02-24 07:38:34 +00007904 TypeLocBuilder TLB;
7905 TLB.reserve(From->getTypeLoc().getFullDataSize());
7906
7907 QualType To = getDerived().TransformType(TLB, PatternTL);
7908 if (To.isNull())
7909 return ExprError();
7910
Chad Rosier1dcde962012-08-08 18:46:20 +00007911 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00007912 PatternTL.getSourceRange(),
7913 ExpansionTL.getEllipsisLoc(),
7914 NumExpansions);
7915 if (To.isNull())
7916 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007917
Douglas Gregor29c42f22012-02-24 07:38:34 +00007918 PackExpansionTypeLoc ToExpansionTL
7919 = TLB.push<PackExpansionTypeLoc>(To);
7920 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7921 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7922 continue;
7923 }
7924
7925 // Expand the pack expansion by substituting for each argument in the
7926 // pack(s).
7927 for (unsigned I = 0; I != *NumExpansions; ++I) {
7928 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7929 TypeLocBuilder TLB;
7930 TLB.reserve(PatternTL.getFullDataSize());
7931 QualType To = getDerived().TransformType(TLB, PatternTL);
7932 if (To.isNull())
7933 return ExprError();
7934
Eli Friedman5e05c4a2013-07-19 21:49:32 +00007935 if (To->containsUnexpandedParameterPack()) {
7936 To = getDerived().RebuildPackExpansionType(To,
7937 PatternTL.getSourceRange(),
7938 ExpansionTL.getEllipsisLoc(),
7939 NumExpansions);
7940 if (To.isNull())
7941 return ExprError();
7942
7943 PackExpansionTypeLoc ToExpansionTL
7944 = TLB.push<PackExpansionTypeLoc>(To);
7945 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7946 }
7947
Douglas Gregor29c42f22012-02-24 07:38:34 +00007948 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7949 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007950
Douglas Gregor29c42f22012-02-24 07:38:34 +00007951 if (!RetainExpansion)
7952 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00007953
Douglas Gregor29c42f22012-02-24 07:38:34 +00007954 // If we're supposed to retain a pack expansion, do so by temporarily
7955 // forgetting the partially-substituted parameter pack.
7956 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7957
7958 TypeLocBuilder TLB;
7959 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00007960
Douglas Gregor29c42f22012-02-24 07:38:34 +00007961 QualType To = getDerived().TransformType(TLB, PatternTL);
7962 if (To.isNull())
7963 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007964
7965 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00007966 PatternTL.getSourceRange(),
7967 ExpansionTL.getEllipsisLoc(),
7968 NumExpansions);
7969 if (To.isNull())
7970 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007971
Douglas Gregor29c42f22012-02-24 07:38:34 +00007972 PackExpansionTypeLoc ToExpansionTL
7973 = TLB.push<PackExpansionTypeLoc>(To);
7974 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7975 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7976 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007977
Douglas Gregor29c42f22012-02-24 07:38:34 +00007978 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7979 return SemaRef.Owned(E);
7980
7981 return getDerived().RebuildTypeTrait(E->getTrait(),
7982 E->getLocStart(),
7983 Args,
7984 E->getLocEnd());
7985}
7986
7987template<typename Derived>
7988ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00007989TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7990 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7991 if (!T)
7992 return ExprError();
7993
7994 if (!getDerived().AlwaysRebuild() &&
7995 T == E->getQueriedTypeSourceInfo())
7996 return SemaRef.Owned(E);
7997
7998 ExprResult SubExpr;
7999 {
8000 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8001 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8002 if (SubExpr.isInvalid())
8003 return ExprError();
8004
8005 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
8006 return SemaRef.Owned(E);
8007 }
8008
8009 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8010 E->getLocStart(),
8011 T,
8012 SubExpr.get(),
8013 E->getLocEnd());
8014}
8015
8016template<typename Derived>
8017ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00008018TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8019 ExprResult SubExpr;
8020 {
8021 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8022 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8023 if (SubExpr.isInvalid())
8024 return ExprError();
8025
8026 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
8027 return SemaRef.Owned(E);
8028 }
8029
8030 return getDerived().RebuildExpressionTrait(
8031 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8032}
8033
8034template<typename Derived>
8035ExprResult
John McCall8cd78132009-11-19 22:55:06 +00008036TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008037 DependentScopeDeclRefExpr *E) {
Richard Smithdb2630f2012-10-21 03:28:35 +00008038 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
8039}
8040
8041template<typename Derived>
8042ExprResult
8043TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8044 DependentScopeDeclRefExpr *E,
8045 bool IsAddressOfOperand) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00008046 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008047 NestedNameSpecifierLoc QualifierLoc
8048 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8049 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008050 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00008051 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008052
John McCall31f82722010-11-12 08:19:04 +00008053 // TODO: If this is a conversion-function-id, verify that the
8054 // destination type name (if present) resolves the same way after
8055 // instantiation as it did in the local scope.
8056
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008057 DeclarationNameInfo NameInfo
8058 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8059 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008060 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008061
John McCalle66edc12009-11-24 19:00:30 +00008062 if (!E->hasExplicitTemplateArgs()) {
8063 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008064 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008065 // Note: it is sufficient to compare the Name component of NameInfo:
8066 // if name has not changed, DNLoc has not changed either.
8067 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00008068 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00008069
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008070 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008071 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008072 NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00008073 /*TemplateArgs*/ 0,
8074 IsAddressOfOperand);
Douglas Gregord019ff62009-10-22 17:20:55 +00008075 }
John McCall6b51f282009-11-23 01:53:49 +00008076
8077 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008078 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8079 E->getNumTemplateArgs(),
8080 TransArgs))
8081 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008082
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008083 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008084 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008085 NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00008086 &TransArgs,
8087 IsAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00008088}
8089
8090template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008091ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008092TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00008093 // CXXConstructExprs other than for list-initialization and
8094 // CXXTemporaryObjectExpr are always implicit, so when we have
8095 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00008096 if ((E->getNumArgs() == 1 ||
8097 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00008098 (!getDerived().DropCallArgument(E->getArg(0))) &&
8099 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00008100 return getDerived().TransformExpr(E->getArg(0));
8101
Douglas Gregora16548e2009-08-11 05:31:07 +00008102 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8103
8104 QualType T = getDerived().TransformType(E->getType());
8105 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008106 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008107
8108 CXXConstructorDecl *Constructor
8109 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008110 getDerived().TransformDecl(E->getLocStart(),
8111 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008112 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008113 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008114
Douglas Gregora16548e2009-08-11 05:31:07 +00008115 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008116 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008117 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008118 &ArgumentChanged))
8119 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008120
Douglas Gregora16548e2009-08-11 05:31:07 +00008121 if (!getDerived().AlwaysRebuild() &&
8122 T == E->getType() &&
8123 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00008124 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00008125 // Mark the constructor as referenced.
8126 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008127 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00008128 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00008129 }
Mike Stump11289f42009-09-09 15:08:12 +00008130
Douglas Gregordb121ba2009-12-14 16:27:04 +00008131 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8132 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008133 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00008134 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00008135 E->isListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00008136 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00008137 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00008138 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008139}
Mike Stump11289f42009-09-09 15:08:12 +00008140
Douglas Gregora16548e2009-08-11 05:31:07 +00008141/// \brief Transform a C++ temporary-binding expression.
8142///
Douglas Gregor363b1512009-12-24 18:51:59 +00008143/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8144/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008145template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008146ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008147TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008148 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008149}
Mike Stump11289f42009-09-09 15:08:12 +00008150
John McCall5d413782010-12-06 08:20:24 +00008151/// \brief Transform a C++ expression that contains cleanups that should
8152/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00008153///
John McCall5d413782010-12-06 08:20:24 +00008154/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00008155/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008156template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008157ExprResult
John McCall5d413782010-12-06 08:20:24 +00008158TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008159 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008160}
Mike Stump11289f42009-09-09 15:08:12 +00008161
Douglas Gregora16548e2009-08-11 05:31:07 +00008162template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008163ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008164TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00008165 CXXTemporaryObjectExpr *E) {
8166 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8167 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008168 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008169
Douglas Gregora16548e2009-08-11 05:31:07 +00008170 CXXConstructorDecl *Constructor
8171 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00008172 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008173 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008174 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008175 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008176
Douglas Gregora16548e2009-08-11 05:31:07 +00008177 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008178 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00008179 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00008180 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008181 &ArgumentChanged))
8182 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008183
Douglas Gregora16548e2009-08-11 05:31:07 +00008184 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008185 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008186 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008187 !ArgumentChanged) {
8188 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008189 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00008190 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008191 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008192
Richard Smithd59b8322012-12-19 01:39:02 +00008193 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00008194 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8195 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008196 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008197 E->getLocEnd());
8198}
Mike Stump11289f42009-09-09 15:08:12 +00008199
Douglas Gregora16548e2009-08-11 05:31:07 +00008200template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008201ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00008202TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008203
8204 // Transform any init-capture expressions before entering the scope of the
8205 // lambda body, because they are not semantically within that scope.
8206 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
8207 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
8208 E->explicit_capture_begin());
8209
8210 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8211 CEnd = E->capture_end();
8212 C != CEnd; ++C) {
8213 if (!C->isInitCapture())
8214 continue;
8215 EnterExpressionEvaluationContext EEEC(getSema(),
8216 Sema::PotentiallyEvaluated);
8217 ExprResult NewExprInitResult = getDerived().TransformInitializer(
8218 C->getCapturedVar()->getInit(),
8219 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
8220
8221 if (NewExprInitResult.isInvalid())
8222 return ExprError();
8223 Expr *NewExprInit = NewExprInitResult.get();
8224
8225 VarDecl *OldVD = C->getCapturedVar();
8226 QualType NewInitCaptureType =
8227 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
8228 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
8229 NewExprInit);
8230 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008231 InitCaptureExprsAndTypes[C - E->capture_begin()] =
8232 std::make_pair(NewExprInitResult, NewInitCaptureType);
8233
8234 }
8235
Faisal Vali524ca282013-11-12 01:40:44 +00008236 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
Faisal Vali2cba1332013-10-23 06:44:28 +00008237 // Transform the template parameters, and add them to the current
8238 // instantiation scope. The null case is handled correctly.
8239 LSI->GLTemplateParameterList = getDerived().TransformTemplateParameterList(
8240 E->getTemplateParameterList());
8241
8242 // Check to see if the TypeSourceInfo of the call operator needs to
8243 // be transformed, and if so do the transformation in the
8244 // CurrentInstantiationScope.
8245
8246 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
8247 FunctionProtoTypeLoc OldCallOpFPTL =
8248 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
8249 TypeSourceInfo *NewCallOpTSI = 0;
8250
8251 const bool CallOpWasAlreadyTransformed =
8252 getDerived().AlreadyTransformed(OldCallOpTSI->getType());
8253
8254 // Use the Old Call Operator's TypeSourceInfo if it is already transformed.
8255 if (CallOpWasAlreadyTransformed)
8256 NewCallOpTSI = OldCallOpTSI;
8257 else {
8258 // Transform the TypeSourceInfo of the Original Lambda's Call Operator.
8259 // The transformation MUST be done in the CurrentInstantiationScope since
8260 // it introduces a mapping of the original to the newly created
8261 // transformed parameters.
8262
8263 TypeLocBuilder NewCallOpTLBuilder;
8264 QualType NewCallOpType = TransformFunctionProtoType(NewCallOpTLBuilder,
8265 OldCallOpFPTL,
8266 0, 0);
8267 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
8268 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00008269 }
Faisal Vali2cba1332013-10-23 06:44:28 +00008270 // Extract the ParmVarDecls from the NewCallOpTSI and add them to
8271 // the vector below - this will be used to synthesize the
8272 // NewCallOperator. Additionally, add the parameters of the untransformed
8273 // lambda call operator to the CurrentInstantiationScope.
8274 SmallVector<ParmVarDecl *, 4> Params;
8275 {
8276 FunctionProtoTypeLoc NewCallOpFPTL =
8277 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>();
8278 ParmVarDecl **NewParamDeclArray = NewCallOpFPTL.getParmArray();
8279 const unsigned NewNumArgs = NewCallOpFPTL.getNumArgs();
8280
8281 for (unsigned I = 0; I < NewNumArgs; ++I) {
8282 // If this call operator's type does not require transformation,
8283 // the parameters do not get added to the current instantiation scope,
8284 // - so ADD them! This allows the following to compile when the enclosing
8285 // template is specialized and the entire lambda expression has to be
8286 // transformed.
8287 // template<class T> void foo(T t) {
8288 // auto L = [](auto a) {
8289 // auto M = [](char b) { <-- note: non-generic lambda
8290 // auto N = [](auto c) {
8291 // int x = sizeof(a);
8292 // x = sizeof(b); <-- specifically this line
8293 // x = sizeof(c);
8294 // };
8295 // };
8296 // };
8297 // }
8298 // foo('a')
8299 if (CallOpWasAlreadyTransformed)
8300 getDerived().transformedLocalDecl(NewParamDeclArray[I],
8301 NewParamDeclArray[I]);
8302 // Add to Params array, so these parameters can be used to create
8303 // the newly transformed call operator.
8304 Params.push_back(NewParamDeclArray[I]);
8305 }
8306 }
8307
8308 if (!NewCallOpTSI)
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008309 return ExprError();
8310
Eli Friedmand564afb2012-09-19 01:18:11 +00008311 // Create the local class that will describe the lambda.
8312 CXXRecordDecl *Class
8313 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008314 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00008315 /*KnownDependent=*/false,
8316 E->getCaptureDefault());
8317
Eli Friedmand564afb2012-09-19 01:18:11 +00008318 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8319
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008320 // Build the call operator.
Faisal Vali2cba1332013-10-23 06:44:28 +00008321 CXXMethodDecl *NewCallOperator
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008322 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008323 NewCallOpTSI,
Douglas Gregoradb376e2012-02-14 22:28:59 +00008324 E->getCallOperator()->getLocEnd(),
Richard Smith505df232012-07-22 23:45:10 +00008325 Params);
Faisal Vali2cba1332013-10-23 06:44:28 +00008326 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00008327
Faisal Vali2cba1332013-10-23 06:44:28 +00008328 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
8329
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008330 return getDerived().TransformLambdaScope(E, NewCallOperator,
8331 InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +00008332}
8333
8334template<typename Derived>
8335ExprResult
8336TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008337 CXXMethodDecl *CallOperator,
8338 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes) {
Richard Smithba71c082013-05-16 06:20:58 +00008339 bool Invalid = false;
8340
Douglas Gregorb4328232012-02-14 00:00:48 +00008341 // Introduce the context of the call operator.
8342 Sema::ContextRAII SavedContext(getSema(), CallOperator);
8343
Faisal Vali2b391ab2013-09-26 19:54:12 +00008344 LambdaScopeInfo *const LSI = getSema().getCurLambda();
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008345 // Enter the scope of the lambda.
Faisal Vali2b391ab2013-09-26 19:54:12 +00008346 getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008347 E->getCaptureDefault(),
James Dennettddd36ff2013-08-09 23:08:25 +00008348 E->getCaptureDefaultLoc(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008349 E->hasExplicitParameters(),
8350 E->hasExplicitResultType(),
8351 E->isMutable());
Chad Rosier1dcde962012-08-08 18:46:20 +00008352
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008353 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008354 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00008355 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008356 CEnd = E->capture_end();
8357 C != CEnd; ++C) {
8358 // When we hit the first implicit capture, tell Sema that we've finished
8359 // the list of explicit captures.
8360 if (!FinishedExplicitCaptures && C->isImplicit()) {
8361 getSema().finishLambdaExplicitCaptures(LSI);
8362 FinishedExplicitCaptures = true;
8363 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008364
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008365 // Capturing 'this' is trivial.
8366 if (C->capturesThis()) {
8367 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8368 continue;
8369 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008370
Richard Smithba71c082013-05-16 06:20:58 +00008371 // Rebuild init-captures, including the implied field declaration.
8372 if (C->isInitCapture()) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008373
8374 InitCaptureInfoTy InitExprTypePair =
8375 InitCaptureExprsAndTypes[C - E->capture_begin()];
8376 ExprResult Init = InitExprTypePair.first;
8377 QualType InitQualType = InitExprTypePair.second;
8378 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00008379 Invalid = true;
8380 continue;
8381 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00008382 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008383 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
8384 OldVD->getLocation(), InitExprTypePair.second,
8385 OldVD->getIdentifier(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00008386 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00008387 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008388 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00008389 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008390 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00008391 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00008392 continue;
8393 }
8394
8395 assert(C->capturesVariable() && "unexpected kind of lambda capture");
8396
Douglas Gregor3e308b12012-02-14 19:27:52 +00008397 // Determine the capture kind for Sema.
8398 Sema::TryCaptureKind Kind
8399 = C->isImplicit()? Sema::TryCapture_Implicit
8400 : C->getCaptureKind() == LCK_ByCopy
8401 ? Sema::TryCapture_ExplicitByVal
8402 : Sema::TryCapture_ExplicitByRef;
8403 SourceLocation EllipsisLoc;
8404 if (C->isPackExpansion()) {
8405 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8406 bool ShouldExpand = false;
8407 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008408 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00008409 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8410 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008411 Unexpanded,
8412 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00008413 NumExpansions)) {
8414 Invalid = true;
8415 continue;
8416 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008417
Douglas Gregor3e308b12012-02-14 19:27:52 +00008418 if (ShouldExpand) {
8419 // The transform has determined that we should perform an expansion;
8420 // transform and capture each of the arguments.
8421 // expansion of the pattern. Do so.
8422 VarDecl *Pack = C->getCapturedVar();
8423 for (unsigned I = 0; I != *NumExpansions; ++I) {
8424 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8425 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008426 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008427 Pack));
8428 if (!CapturedVar) {
8429 Invalid = true;
8430 continue;
8431 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008432
Douglas Gregor3e308b12012-02-14 19:27:52 +00008433 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00008434 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8435 }
Douglas Gregor3e308b12012-02-14 19:27:52 +00008436 continue;
8437 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008438
Douglas Gregor3e308b12012-02-14 19:27:52 +00008439 EllipsisLoc = C->getEllipsisLoc();
8440 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008441
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008442 // Transform the captured variable.
8443 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008444 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008445 C->getCapturedVar()));
8446 if (!CapturedVar) {
8447 Invalid = true;
8448 continue;
8449 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008450
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008451 // Capture the transformed variable.
Douglas Gregorfdf598e2012-02-18 09:37:24 +00008452 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008453 }
8454 if (!FinishedExplicitCaptures)
8455 getSema().finishLambdaExplicitCaptures(LSI);
8456
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008457
8458 // Enter a new evaluation context to insulate the lambda from any
8459 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00008460 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008461
8462 if (Invalid) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008463 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008464 /*IsInstantiation=*/true);
8465 return ExprError();
8466 }
8467
8468 // Instantiate the body of the lambda expression.
Douglas Gregorb4328232012-02-14 00:00:48 +00008469 StmtResult Body = getDerived().TransformStmt(E->getBody());
8470 if (Body.isInvalid()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008471 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregorb4328232012-02-14 00:00:48 +00008472 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00008473 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00008474 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00008475
Chad Rosier1dcde962012-08-08 18:46:20 +00008476 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorb61e8092012-04-04 17:40:10 +00008477 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregore31e6062012-02-07 10:09:13 +00008478}
8479
8480template<typename Derived>
8481ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008482TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008483 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00008484 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8485 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008486 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008487
Douglas Gregora16548e2009-08-11 05:31:07 +00008488 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008489 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00008490 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00008491 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008492 &ArgumentChanged))
8493 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008494
Douglas Gregora16548e2009-08-11 05:31:07 +00008495 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008496 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008497 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00008498 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00008499
Douglas Gregora16548e2009-08-11 05:31:07 +00008500 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00008501 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00008502 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008503 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008504 E->getRParenLoc());
8505}
Mike Stump11289f42009-09-09 15:08:12 +00008506
Douglas Gregora16548e2009-08-11 05:31:07 +00008507template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008508ExprResult
John McCall8cd78132009-11-19 22:55:06 +00008509TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008510 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008511 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00008512 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00008513 Expr *OldBase;
8514 QualType BaseType;
8515 QualType ObjectType;
8516 if (!E->isImplicitAccess()) {
8517 OldBase = E->getBase();
8518 Base = getDerived().TransformExpr(OldBase);
8519 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008520 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008521
John McCall2d74de92009-12-01 22:10:20 +00008522 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00008523 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00008524 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00008525 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008526 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008527 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00008528 ObjectTy,
8529 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00008530 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008531 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00008532
John McCallba7bf592010-08-24 05:47:05 +00008533 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00008534 BaseType = ((Expr*) Base.get())->getType();
8535 } else {
8536 OldBase = 0;
8537 BaseType = getDerived().TransformType(E->getBaseType());
8538 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8539 }
Mike Stump11289f42009-09-09 15:08:12 +00008540
Douglas Gregora5cb6da2009-10-20 05:58:46 +00008541 // Transform the first part of the nested-name-specifier that qualifies
8542 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00008543 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00008544 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00008545 E->getFirstQualifierFoundInScope(),
8546 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00008547
Douglas Gregore16af532011-02-28 18:50:33 +00008548 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008549 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00008550 QualifierLoc
8551 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8552 ObjectType,
8553 FirstQualifierInScope);
8554 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008555 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008556 }
Mike Stump11289f42009-09-09 15:08:12 +00008557
Abramo Bagnara7945c982012-01-27 09:46:47 +00008558 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8559
John McCall31f82722010-11-12 08:19:04 +00008560 // TODO: If this is a conversion-function-id, verify that the
8561 // destination type name (if present) resolves the same way after
8562 // instantiation as it did in the local scope.
8563
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008564 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00008565 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008566 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008567 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008568
John McCall2d74de92009-12-01 22:10:20 +00008569 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00008570 // This is a reference to a member without an explicitly-specified
8571 // template argument list. Optimize for this common case.
8572 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00008573 Base.get() == OldBase &&
8574 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00008575 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008576 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00008577 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00008578 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00008579
John McCallb268a282010-08-23 23:25:46 +00008580 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008581 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00008582 E->isArrow(),
8583 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00008584 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008585 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00008586 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008587 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00008588 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00008589 }
8590
John McCall6b51f282009-11-23 01:53:49 +00008591 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008592 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8593 E->getNumTemplateArgs(),
8594 TransArgs))
8595 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008596
John McCallb268a282010-08-23 23:25:46 +00008597 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008598 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00008599 E->isArrow(),
8600 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00008601 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008602 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00008603 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008604 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00008605 &TransArgs);
8606}
8607
8608template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008609ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008610TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00008611 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00008612 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00008613 QualType BaseType;
8614 if (!Old->isImplicitAccess()) {
8615 Base = getDerived().TransformExpr(Old->getBase());
8616 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008617 return ExprError();
Richard Smithcab9a7d2011-10-26 19:06:56 +00008618 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8619 Old->isArrow());
8620 if (Base.isInvalid())
8621 return ExprError();
8622 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +00008623 } else {
8624 BaseType = getDerived().TransformType(Old->getBaseType());
8625 }
John McCall10eae182009-11-30 22:42:35 +00008626
Douglas Gregor0da1d432011-02-28 20:01:57 +00008627 NestedNameSpecifierLoc QualifierLoc;
8628 if (Old->getQualifierLoc()) {
8629 QualifierLoc
8630 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8631 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008632 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00008633 }
8634
Abramo Bagnara7945c982012-01-27 09:46:47 +00008635 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8636
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008637 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00008638 Sema::LookupOrdinaryName);
8639
8640 // Transform all the decls.
8641 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8642 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008643 NamedDecl *InstD = static_cast<NamedDecl*>(
8644 getDerived().TransformDecl(Old->getMemberLoc(),
8645 *I));
John McCall84d87672009-12-10 09:41:52 +00008646 if (!InstD) {
8647 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8648 // This can happen because of dependent hiding.
8649 if (isa<UsingShadowDecl>(*I))
8650 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00008651 else {
8652 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008653 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00008654 }
John McCall84d87672009-12-10 09:41:52 +00008655 }
John McCall10eae182009-11-30 22:42:35 +00008656
8657 // Expand using declarations.
8658 if (isa<UsingDecl>(InstD)) {
8659 UsingDecl *UD = cast<UsingDecl>(InstD);
8660 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8661 E = UD->shadow_end(); I != E; ++I)
8662 R.addDecl(*I);
8663 continue;
8664 }
8665
8666 R.addDecl(InstD);
8667 }
8668
8669 R.resolveKind();
8670
Douglas Gregor9262f472010-04-27 18:19:34 +00008671 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00008672 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008673 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00008674 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00008675 Old->getMemberLoc(),
8676 Old->getNamingClass()));
8677 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00008678 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008679
Douglas Gregorda7be082010-04-27 16:10:10 +00008680 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00008681 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008682
John McCall10eae182009-11-30 22:42:35 +00008683 TemplateArgumentListInfo TransArgs;
8684 if (Old->hasExplicitTemplateArgs()) {
8685 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8686 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008687 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8688 Old->getNumTemplateArgs(),
8689 TransArgs))
8690 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00008691 }
John McCall38836f02010-01-15 08:34:02 +00008692
8693 // FIXME: to do this check properly, we will need to preserve the
8694 // first-qualifier-in-scope here, just in case we had a dependent
8695 // base (and therefore couldn't do the check) and a
8696 // nested-name-qualifier (and therefore could do the lookup).
8697 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00008698
John McCallb268a282010-08-23 23:25:46 +00008699 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008700 BaseType,
John McCall10eae182009-11-30 22:42:35 +00008701 Old->getOperatorLoc(),
8702 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00008703 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008704 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +00008705 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00008706 R,
8707 (Old->hasExplicitTemplateArgs()
8708 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00008709}
8710
8711template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008712ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008713TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00008714 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008715 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8716 if (SubExpr.isInvalid())
8717 return ExprError();
8718
8719 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00008720 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008721
8722 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8723}
8724
8725template<typename Derived>
8726ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008727TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00008728 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8729 if (Pattern.isInvalid())
8730 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008731
Douglas Gregor0f836ea2011-01-13 00:19:55 +00008732 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8733 return SemaRef.Owned(E);
8734
Douglas Gregorb8840002011-01-14 21:20:45 +00008735 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8736 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008737}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008738
8739template<typename Derived>
8740ExprResult
8741TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8742 // If E is not value-dependent, then nothing will change when we transform it.
8743 // Note: This is an instantiation-centric view.
8744 if (!E->isValueDependent())
8745 return SemaRef.Owned(E);
8746
8747 // Note: None of the implementations of TryExpandParameterPacks can ever
8748 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00008749 // so
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008750 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8751 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00008752 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008753 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00008754 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +00008755 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00008756 ShouldExpand, RetainExpansion,
8757 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008758 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008759
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008760 if (RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008761 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00008762
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008763 NamedDecl *Pack = E->getPack();
8764 if (!ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008765 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008766 Pack));
8767 if (!Pack)
8768 return ExprError();
8769 }
8770
Chad Rosier1dcde962012-08-08 18:46:20 +00008771
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008772 // We now know the length of the parameter pack, so build a new expression
8773 // that stores that length.
Chad Rosier1dcde962012-08-08 18:46:20 +00008774 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8775 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008776 NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008777}
8778
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008779template<typename Derived>
8780ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00008781TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8782 SubstNonTypeTemplateParmPackExpr *E) {
8783 // Default behavior is to do nothing with this transformation.
8784 return SemaRef.Owned(E);
8785}
8786
8787template<typename Derived>
8788ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00008789TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8790 SubstNonTypeTemplateParmExpr *E) {
8791 // Default behavior is to do nothing with this transformation.
8792 return SemaRef.Owned(E);
8793}
8794
8795template<typename Derived>
8796ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +00008797TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8798 // Default behavior is to do nothing with this transformation.
8799 return SemaRef.Owned(E);
8800}
8801
8802template<typename Derived>
8803ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00008804TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8805 MaterializeTemporaryExpr *E) {
8806 return getDerived().TransformExpr(E->GetTemporaryExpr());
8807}
Chad Rosier1dcde962012-08-08 18:46:20 +00008808
Douglas Gregorfe314812011-06-21 17:03:29 +00008809template<typename Derived>
8810ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +00008811TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
8812 CXXStdInitializerListExpr *E) {
8813 return getDerived().TransformExpr(E->getSubExpr());
8814}
8815
8816template<typename Derived>
8817ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008818TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00008819 return SemaRef.MaybeBindToTemporary(E);
8820}
8821
8822template<typename Derived>
8823ExprResult
8824TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rose8986c5992012-03-12 17:53:02 +00008825 return SemaRef.Owned(E);
Ted Kremeneke65b0862012-03-06 20:05:56 +00008826}
8827
8828template<typename Derived>
8829ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +00008830TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8831 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8832 if (SubExpr.isInvalid())
8833 return ExprError();
8834
8835 if (!getDerived().AlwaysRebuild() &&
8836 SubExpr.get() == E->getSubExpr())
8837 return SemaRef.Owned(E);
8838
8839 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +00008840}
8841
8842template<typename Derived>
8843ExprResult
8844TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8845 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008846 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00008847 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00008848 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00008849 /*IsCall=*/false, Elements, &ArgChanged))
8850 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008851
Ted Kremeneke65b0862012-03-06 20:05:56 +00008852 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8853 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00008854
Ted Kremeneke65b0862012-03-06 20:05:56 +00008855 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8856 Elements.data(),
8857 Elements.size());
8858}
8859
8860template<typename Derived>
8861ExprResult
8862TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +00008863 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00008864 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008865 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00008866 bool ArgChanged = false;
8867 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8868 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +00008869
Ted Kremeneke65b0862012-03-06 20:05:56 +00008870 if (OrigElement.isPackExpansion()) {
8871 // This key/value element is a pack expansion.
8872 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8873 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8874 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8875 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8876
8877 // Determine whether the set of unexpanded parameter packs can
8878 // and should be expanded.
8879 bool Expand = true;
8880 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008881 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8882 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +00008883 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8884 OrigElement.Value->getLocEnd());
8885 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8886 PatternRange,
8887 Unexpanded,
8888 Expand, RetainExpansion,
8889 NumExpansions))
8890 return ExprError();
8891
8892 if (!Expand) {
8893 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00008894 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +00008895 // expansion.
8896 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8897 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8898 if (Key.isInvalid())
8899 return ExprError();
8900
8901 if (Key.get() != OrigElement.Key)
8902 ArgChanged = true;
8903
8904 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8905 if (Value.isInvalid())
8906 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008907
Ted Kremeneke65b0862012-03-06 20:05:56 +00008908 if (Value.get() != OrigElement.Value)
8909 ArgChanged = true;
8910
Chad Rosier1dcde962012-08-08 18:46:20 +00008911 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00008912 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8913 };
8914 Elements.push_back(Expansion);
8915 continue;
8916 }
8917
8918 // Record right away that the argument was changed. This needs
8919 // to happen even if the array expands to nothing.
8920 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00008921
Ted Kremeneke65b0862012-03-06 20:05:56 +00008922 // The transform has determined that we should perform an elementwise
8923 // expansion of the pattern. Do so.
8924 for (unsigned I = 0; I != *NumExpansions; ++I) {
8925 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8926 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8927 if (Key.isInvalid())
8928 return ExprError();
8929
8930 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8931 if (Value.isInvalid())
8932 return ExprError();
8933
Chad Rosier1dcde962012-08-08 18:46:20 +00008934 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00008935 Key.get(), Value.get(), SourceLocation(), NumExpansions
8936 };
8937
8938 // If any unexpanded parameter packs remain, we still have a
8939 // pack expansion.
8940 if (Key.get()->containsUnexpandedParameterPack() ||
8941 Value.get()->containsUnexpandedParameterPack())
8942 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +00008943
Ted Kremeneke65b0862012-03-06 20:05:56 +00008944 Elements.push_back(Element);
8945 }
8946
8947 // We've finished with this pack expansion.
8948 continue;
8949 }
8950
8951 // Transform and check key.
8952 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8953 if (Key.isInvalid())
8954 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008955
Ted Kremeneke65b0862012-03-06 20:05:56 +00008956 if (Key.get() != OrigElement.Key)
8957 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00008958
Ted Kremeneke65b0862012-03-06 20:05:56 +00008959 // Transform and check value.
8960 ExprResult Value
8961 = getDerived().TransformExpr(OrigElement.Value);
8962 if (Value.isInvalid())
8963 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008964
Ted Kremeneke65b0862012-03-06 20:05:56 +00008965 if (Value.get() != OrigElement.Value)
8966 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00008967
8968 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +00008969 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +00008970 };
8971 Elements.push_back(Element);
8972 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008973
Ted Kremeneke65b0862012-03-06 20:05:56 +00008974 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8975 return SemaRef.MaybeBindToTemporary(E);
8976
8977 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8978 Elements.data(),
8979 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +00008980}
8981
Mike Stump11289f42009-09-09 15:08:12 +00008982template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008983ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008984TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00008985 TypeSourceInfo *EncodedTypeInfo
8986 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8987 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008988 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008989
Douglas Gregora16548e2009-08-11 05:31:07 +00008990 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00008991 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00008992 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008993
8994 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00008995 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00008996 E->getRParenLoc());
8997}
Mike Stump11289f42009-09-09 15:08:12 +00008998
Douglas Gregora16548e2009-08-11 05:31:07 +00008999template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +00009000ExprResult TreeTransform<Derived>::
9001TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +00009002 // This is a kind of implicit conversion, and it needs to get dropped
9003 // and recomputed for the same general reasons that ImplicitCastExprs
9004 // do, as well a more specific one: this expression is only valid when
9005 // it appears *immediately* as an argument expression.
9006 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +00009007}
9008
9009template<typename Derived>
9010ExprResult TreeTransform<Derived>::
9011TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009012 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +00009013 = getDerived().TransformType(E->getTypeInfoAsWritten());
9014 if (!TSInfo)
9015 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009016
John McCall31168b02011-06-15 23:02:42 +00009017 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +00009018 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +00009019 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009020
John McCall31168b02011-06-15 23:02:42 +00009021 if (!getDerived().AlwaysRebuild() &&
9022 TSInfo == E->getTypeInfoAsWritten() &&
9023 Result.get() == E->getSubExpr())
9024 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009025
John McCall31168b02011-06-15 23:02:42 +00009026 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +00009027 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +00009028 Result.get());
9029}
9030
9031template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009032ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009033TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009034 // Transform arguments.
9035 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009036 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009037 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009038 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009039 &ArgChanged))
9040 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009041
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009042 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
9043 // Class message: transform the receiver type.
9044 TypeSourceInfo *ReceiverTypeInfo
9045 = getDerived().TransformType(E->getClassReceiverTypeInfo());
9046 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009047 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009048
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009049 // If nothing changed, just retain the existing message send.
9050 if (!getDerived().AlwaysRebuild() &&
9051 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009052 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009053
9054 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009055 SmallVector<SourceLocation, 16> SelLocs;
9056 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009057 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
9058 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009059 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009060 E->getMethodDecl(),
9061 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009062 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009063 E->getRightLoc());
9064 }
9065
9066 // Instance message: transform the receiver
9067 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
9068 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00009069 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009070 = getDerived().TransformExpr(E->getInstanceReceiver());
9071 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009072 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009073
9074 // If nothing changed, just retain the existing message send.
9075 if (!getDerived().AlwaysRebuild() &&
9076 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009077 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009078
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009079 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009080 SmallVector<SourceLocation, 16> SelLocs;
9081 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +00009082 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009083 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009084 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009085 E->getMethodDecl(),
9086 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009087 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009088 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009089}
9090
Mike Stump11289f42009-09-09 15:08:12 +00009091template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009092ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009093TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00009094 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009095}
9096
Mike Stump11289f42009-09-09 15:08:12 +00009097template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009098ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009099TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00009100 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009101}
9102
Mike Stump11289f42009-09-09 15:08:12 +00009103template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009104ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009105TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009106 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009107 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009108 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009109 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00009110
9111 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009112
Douglas Gregord51d90d2010-04-26 20:11:03 +00009113 // If nothing changed, just retain the existing expression.
9114 if (!getDerived().AlwaysRebuild() &&
9115 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00009116 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009117
John McCallb268a282010-08-23 23:25:46 +00009118 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009119 E->getLocation(),
9120 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00009121}
9122
Mike Stump11289f42009-09-09 15:08:12 +00009123template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009124ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009125TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00009126 // 'super' and types never change. Property never changes. Just
9127 // retain the existing expression.
9128 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00009129 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009130
Douglas Gregor9faee212010-04-26 20:47:02 +00009131 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009132 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00009133 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009134 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009135
Douglas Gregor9faee212010-04-26 20:47:02 +00009136 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009137
Douglas Gregor9faee212010-04-26 20:47:02 +00009138 // If nothing changed, just retain the existing expression.
9139 if (!getDerived().AlwaysRebuild() &&
9140 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00009141 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009142
John McCallb7bd14f2010-12-02 01:19:52 +00009143 if (E->isExplicitProperty())
9144 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9145 E->getExplicitProperty(),
9146 E->getLocation());
9147
9148 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +00009149 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +00009150 E->getImplicitPropertyGetter(),
9151 E->getImplicitPropertySetter(),
9152 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00009153}
9154
Mike Stump11289f42009-09-09 15:08:12 +00009155template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009156ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +00009157TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
9158 // Transform the base expression.
9159 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9160 if (Base.isInvalid())
9161 return ExprError();
9162
9163 // Transform the key expression.
9164 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
9165 if (Key.isInvalid())
9166 return ExprError();
9167
9168 // If nothing changed, just retain the existing expression.
9169 if (!getDerived().AlwaysRebuild() &&
9170 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
9171 return SemaRef.Owned(E);
9172
Chad Rosier1dcde962012-08-08 18:46:20 +00009173 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009174 Base.get(), Key.get(),
9175 E->getAtIndexMethodDecl(),
9176 E->setAtIndexMethodDecl());
9177}
9178
9179template<typename Derived>
9180ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009181TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009182 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009183 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009184 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009185 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009186
Douglas Gregord51d90d2010-04-26 20:11:03 +00009187 // If nothing changed, just retain the existing expression.
9188 if (!getDerived().AlwaysRebuild() &&
9189 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00009190 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009191
John McCallb268a282010-08-23 23:25:46 +00009192 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00009193 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009194 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00009195}
9196
Mike Stump11289f42009-09-09 15:08:12 +00009197template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009198ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009199TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009200 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009201 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +00009202 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009203 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00009204 SubExprs, &ArgumentChanged))
9205 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009206
Douglas Gregora16548e2009-08-11 05:31:07 +00009207 if (!getDerived().AlwaysRebuild() &&
9208 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00009209 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00009210
Douglas Gregora16548e2009-08-11 05:31:07 +00009211 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009212 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009213 E->getRParenLoc());
9214}
9215
Mike Stump11289f42009-09-09 15:08:12 +00009216template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009217ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +00009218TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
9219 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
9220 if (SrcExpr.isInvalid())
9221 return ExprError();
9222
9223 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9224 if (!Type)
9225 return ExprError();
9226
9227 if (!getDerived().AlwaysRebuild() &&
9228 Type == E->getTypeSourceInfo() &&
9229 SrcExpr.get() == E->getSrcExpr())
9230 return SemaRef.Owned(E);
9231
9232 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
9233 SrcExpr.get(), Type,
9234 E->getRParenLoc());
9235}
9236
9237template<typename Derived>
9238ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009239TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00009240 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +00009241
John McCall490112f2011-02-04 18:33:18 +00009242 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
9243 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
9244
9245 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +00009246 blockScope->TheDecl->setBlockMissingReturnType(
9247 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +00009248
Chris Lattner01cf8db2011-07-20 06:58:45 +00009249 SmallVector<ParmVarDecl*, 4> params;
9250 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +00009251
Fariborz Jahanian1babe772010-07-09 18:44:02 +00009252 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00009253 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
9254 oldBlock->param_begin(),
9255 oldBlock->param_size(),
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009256 0, paramTypes, &params)) {
9257 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009258 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009259 }
John McCall490112f2011-02-04 18:33:18 +00009260
Jordan Rosea0a86be2013-03-08 22:25:36 +00009261 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +00009262 QualType exprResultType =
9263 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregor476e3022011-01-19 21:32:01 +00009264
Jordan Rose5c382722013-03-08 21:51:21 +00009265 QualType functionType =
9266 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009267 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +00009268 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00009269
9270 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00009271 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +00009272 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +00009273
9274 if (!oldBlock->blockMissingReturnType()) {
9275 blockScope->HasImplicitReturnType = false;
9276 blockScope->ReturnType = exprResultType;
9277 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009278
John McCall3882ace2011-01-05 12:14:39 +00009279 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00009280 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009281 if (body.isInvalid()) {
9282 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall3882ace2011-01-05 12:14:39 +00009283 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009284 }
John McCall3882ace2011-01-05 12:14:39 +00009285
John McCall490112f2011-02-04 18:33:18 +00009286#ifndef NDEBUG
9287 // In builds with assertions, make sure that we captured everything we
9288 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009289 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
9290 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
9291 e = oldBlock->capture_end(); i != e; ++i) {
9292 VarDecl *oldCapture = i->getVariable();
John McCall490112f2011-02-04 18:33:18 +00009293
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009294 // Ignore parameter packs.
9295 if (isa<ParmVarDecl>(oldCapture) &&
9296 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9297 continue;
John McCall490112f2011-02-04 18:33:18 +00009298
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009299 VarDecl *newCapture =
9300 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9301 oldCapture));
9302 assert(blockScope->CaptureMap.count(newCapture));
9303 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009304 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +00009305 }
9306#endif
9307
9308 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
9309 /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00009310}
9311
Mike Stump11289f42009-09-09 15:08:12 +00009312template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009313ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +00009314TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +00009315 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +00009316}
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009317
9318template<typename Derived>
9319ExprResult
9320TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009321 QualType RetTy = getDerived().TransformType(E->getType());
9322 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009323 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009324 SubExprs.reserve(E->getNumSubExprs());
9325 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9326 SubExprs, &ArgumentChanged))
9327 return ExprError();
9328
9329 if (!getDerived().AlwaysRebuild() &&
9330 !ArgumentChanged)
9331 return SemaRef.Owned(E);
9332
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009333 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009334 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009335}
Chad Rosier1dcde962012-08-08 18:46:20 +00009336
Douglas Gregora16548e2009-08-11 05:31:07 +00009337//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00009338// Type reconstruction
9339//===----------------------------------------------------------------------===//
9340
Mike Stump11289f42009-09-09 15:08:12 +00009341template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009342QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9343 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009344 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009345 getDerived().getBaseEntity());
9346}
9347
Mike Stump11289f42009-09-09 15:08:12 +00009348template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009349QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9350 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009351 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009352 getDerived().getBaseEntity());
9353}
9354
Mike Stump11289f42009-09-09 15:08:12 +00009355template<typename Derived>
9356QualType
John McCall70dd5f62009-10-30 00:06:24 +00009357TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9358 bool WrittenAsLValue,
9359 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00009360 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00009361 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009362}
9363
9364template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009365QualType
John McCall70dd5f62009-10-30 00:06:24 +00009366TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9367 QualType ClassType,
9368 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +00009369 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
9370 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009371}
9372
9373template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009374QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00009375TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9376 ArrayType::ArraySizeModifier SizeMod,
9377 const llvm::APInt *Size,
9378 Expr *SizeExpr,
9379 unsigned IndexTypeQuals,
9380 SourceRange BracketsRange) {
9381 if (SizeExpr || !Size)
9382 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9383 IndexTypeQuals, BracketsRange,
9384 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00009385
9386 QualType Types[] = {
9387 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9388 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9389 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00009390 };
Craig Toppere5ce8312013-07-15 03:38:40 +00009391 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009392 QualType SizeType;
9393 for (unsigned I = 0; I != NumTypes; ++I)
9394 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9395 SizeType = Types[I];
9396 break;
9397 }
Mike Stump11289f42009-09-09 15:08:12 +00009398
Eli Friedman9562f392012-01-25 23:20:27 +00009399 // Note that we can return a VariableArrayType here in the case where
9400 // the element type was a dependent VariableArrayType.
9401 IntegerLiteral *ArraySize
9402 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9403 /*FIXME*/BracketsRange.getBegin());
9404 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009405 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00009406 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009407}
Mike Stump11289f42009-09-09 15:08:12 +00009408
Douglas Gregord6ff3322009-08-04 16:50:30 +00009409template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009410QualType
9411TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009412 ArrayType::ArraySizeModifier SizeMod,
9413 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00009414 unsigned IndexTypeQuals,
9415 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009416 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00009417 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009418}
9419
9420template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009421QualType
Mike Stump11289f42009-09-09 15:08:12 +00009422TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009423 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00009424 unsigned IndexTypeQuals,
9425 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009426 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00009427 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009428}
Mike Stump11289f42009-09-09 15:08:12 +00009429
Douglas Gregord6ff3322009-08-04 16:50:30 +00009430template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009431QualType
9432TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009433 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009434 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009435 unsigned IndexTypeQuals,
9436 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009437 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00009438 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009439 IndexTypeQuals, BracketsRange);
9440}
9441
9442template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009443QualType
9444TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009445 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009446 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009447 unsigned IndexTypeQuals,
9448 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009449 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00009450 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009451 IndexTypeQuals, BracketsRange);
9452}
9453
9454template<typename Derived>
9455QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00009456 unsigned NumElements,
9457 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00009458 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00009459 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009460}
Mike Stump11289f42009-09-09 15:08:12 +00009461
Douglas Gregord6ff3322009-08-04 16:50:30 +00009462template<typename Derived>
9463QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9464 unsigned NumElements,
9465 SourceLocation AttributeLoc) {
9466 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9467 NumElements, true);
9468 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00009469 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9470 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00009471 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009472}
Mike Stump11289f42009-09-09 15:08:12 +00009473
Douglas Gregord6ff3322009-08-04 16:50:30 +00009474template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009475QualType
9476TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00009477 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009478 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00009479 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009480}
Mike Stump11289f42009-09-09 15:08:12 +00009481
Douglas Gregord6ff3322009-08-04 16:50:30 +00009482template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +00009483QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9484 QualType T,
9485 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009486 const FunctionProtoType::ExtProtoInfo &EPI) {
9487 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009488 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00009489 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +00009490 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009491}
Mike Stump11289f42009-09-09 15:08:12 +00009492
Douglas Gregord6ff3322009-08-04 16:50:30 +00009493template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00009494QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9495 return SemaRef.Context.getFunctionNoProtoType(T);
9496}
9497
9498template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00009499QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9500 assert(D && "no decl found");
9501 if (D->isInvalidDecl()) return QualType();
9502
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009503 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00009504 TypeDecl *Ty;
9505 if (isa<UsingDecl>(D)) {
9506 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +00009507 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +00009508 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9509
9510 // A valid resolved using typename decl points to exactly one type decl.
9511 assert(++Using->shadow_begin() == Using->shadow_end());
9512 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00009513
John McCallb96ec562009-12-04 22:46:56 +00009514 } else {
9515 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9516 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9517 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9518 }
9519
9520 return SemaRef.Context.getTypeDeclType(Ty);
9521}
9522
9523template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00009524QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9525 SourceLocation Loc) {
9526 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009527}
9528
9529template<typename Derived>
9530QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9531 return SemaRef.Context.getTypeOfType(Underlying);
9532}
9533
9534template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00009535QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9536 SourceLocation Loc) {
9537 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009538}
9539
9540template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00009541QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9542 UnaryTransformType::UTTKind UKind,
9543 SourceLocation Loc) {
9544 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9545}
9546
9547template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00009548QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00009549 TemplateName Template,
9550 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +00009551 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +00009552 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009553}
Mike Stump11289f42009-09-09 15:08:12 +00009554
Douglas Gregor1135c352009-08-06 05:28:30 +00009555template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +00009556QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9557 SourceLocation KWLoc) {
9558 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9559}
9560
9561template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009562TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009563TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00009564 bool TemplateKW,
9565 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +00009566 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00009567 Template);
9568}
9569
9570template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009571TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009572TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9573 const IdentifierInfo &Name,
9574 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00009575 QualType ObjectType,
9576 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +00009577 UnqualifiedId TemplateName;
9578 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +00009579 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +00009580 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +00009581 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009582 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +00009583 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00009584 /*EnteringContext=*/false,
9585 Template);
John McCall31f82722010-11-12 08:19:04 +00009586 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00009587}
Mike Stump11289f42009-09-09 15:08:12 +00009588
Douglas Gregora16548e2009-08-11 05:31:07 +00009589template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00009590TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009591TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00009592 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00009593 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00009594 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +00009595 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +00009596 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +00009597 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +00009598 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +00009599 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +00009600 Sema::TemplateTy Template;
9601 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009602 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +00009603 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00009604 /*EnteringContext=*/false,
9605 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +00009606 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +00009607}
Chad Rosier1dcde962012-08-08 18:46:20 +00009608
Douglas Gregor71395fa2009-11-04 00:56:37 +00009609template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009610ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009611TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9612 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00009613 Expr *OrigCallee,
9614 Expr *First,
9615 Expr *Second) {
9616 Expr *Callee = OrigCallee->IgnoreParenCasts();
9617 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00009618
Douglas Gregora16548e2009-08-11 05:31:07 +00009619 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00009620 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00009621 if (!First->getType()->isOverloadableType() &&
9622 !Second->getType()->isOverloadableType())
9623 return getSema().CreateBuiltinArraySubscriptExpr(First,
9624 Callee->getLocStart(),
9625 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00009626 } else if (Op == OO_Arrow) {
9627 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00009628 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9629 } else if (Second == 0 || isPostIncDec) {
9630 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009631 // The argument is not of overloadable type, so try to create a
9632 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00009633 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00009634 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00009635
John McCallb268a282010-08-23 23:25:46 +00009636 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00009637 }
9638 } else {
John McCallb268a282010-08-23 23:25:46 +00009639 if (!First->getType()->isOverloadableType() &&
9640 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009641 // Neither of the arguments is an overloadable type, so try to
9642 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00009643 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00009644 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00009645 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00009646 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009647 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009648
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009649 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00009650 }
9651 }
Mike Stump11289f42009-09-09 15:08:12 +00009652
9653 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00009654 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00009655 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00009656
John McCallb268a282010-08-23 23:25:46 +00009657 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00009658 assert(ULE->requiresADL());
9659
9660 // FIXME: Do we have to check
9661 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00009662 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00009663 } else {
Richard Smith58db83d2012-11-28 21:47:39 +00009664 // If we've resolved this to a particular non-member function, just call
9665 // that function. If we resolved it to a member function,
9666 // CreateOverloaded* will find that function for us.
9667 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9668 if (!isa<CXXMethodDecl>(ND))
9669 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +00009670 }
Mike Stump11289f42009-09-09 15:08:12 +00009671
Douglas Gregora16548e2009-08-11 05:31:07 +00009672 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00009673 Expr *Args[2] = { First, Second };
9674 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00009675
Douglas Gregora16548e2009-08-11 05:31:07 +00009676 // Create the overloaded operator invocation for unary operators.
9677 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00009678 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00009679 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00009680 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00009681 }
Mike Stump11289f42009-09-09 15:08:12 +00009682
Douglas Gregore9d62932011-07-15 16:25:15 +00009683 if (Op == OO_Subscript) {
9684 SourceLocation LBrace;
9685 SourceLocation RBrace;
9686
9687 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9688 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9689 LBrace = SourceLocation::getFromRawEncoding(
9690 NameLoc.CXXOperatorName.BeginOpNameLoc);
9691 RBrace = SourceLocation::getFromRawEncoding(
9692 NameLoc.CXXOperatorName.EndOpNameLoc);
9693 } else {
9694 LBrace = Callee->getLocStart();
9695 RBrace = OpLoc;
9696 }
9697
9698 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9699 First, Second);
9700 }
Sebastian Redladba46e2009-10-29 20:17:01 +00009701
Douglas Gregora16548e2009-08-11 05:31:07 +00009702 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00009703 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00009704 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00009705 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9706 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009707 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009708
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009709 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00009710}
Mike Stump11289f42009-09-09 15:08:12 +00009711
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009712template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00009713ExprResult
John McCallb268a282010-08-23 23:25:46 +00009714TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009715 SourceLocation OperatorLoc,
9716 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +00009717 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009718 TypeSourceInfo *ScopeType,
9719 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009720 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009721 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +00009722 QualType BaseType = Base->getType();
9723 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009724 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +00009725 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00009726 !BaseType->getAs<PointerType>()->getPointeeType()
9727 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009728 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00009729 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009730 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009731 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009732 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009733 /*FIXME?*/true);
9734 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009735
Douglas Gregor678f90d2010-02-25 01:56:36 +00009736 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009737 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9738 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9739 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9740 NameInfo.setNamedTypeInfo(DestroyedType);
9741
Richard Smith8e4a3862012-05-15 06:15:11 +00009742 // The scope type is now known to be a valid nested name specifier
9743 // component. Tack it on to the end of the nested name specifier.
9744 if (ScopeType)
9745 SS.Extend(SemaRef.Context, SourceLocation(),
9746 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009747
Abramo Bagnara7945c982012-01-27 09:46:47 +00009748 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +00009749 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009750 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009751 SS, TemplateKWLoc,
9752 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009753 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009754 /*TemplateArgs*/ 0);
9755}
9756
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00009757template<typename Derived>
9758StmtResult
9759TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +00009760 SourceLocation Loc = S->getLocStart();
9761 unsigned NumParams = S->getCapturedDecl()->getNumParams();
9762 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/0,
9763 S->getCapturedRegionKind(), NumParams);
9764 StmtResult Body = getDerived().TransformStmt(S->getCapturedStmt());
9765
9766 if (Body.isInvalid()) {
9767 getSema().ActOnCapturedRegionError();
9768 return StmtError();
9769 }
9770
9771 return getSema().ActOnCapturedRegionEnd(Body.take());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00009772}
9773
Douglas Gregord6ff3322009-08-04 16:50:30 +00009774} // end namespace clang
9775
9776#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H