blob: d9ed6f5f027dec4f1ae633ac66c475d1085792ec [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
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001301 /// \brief Build a new OpenMP 'if' 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 *RebuildOMPIfClause(Expr *Condition,
1306 SourceLocation StartLoc,
1307 SourceLocation LParenLoc,
1308 SourceLocation EndLoc) {
1309 return getSema().ActOnOpenMPIfClause(Condition, StartLoc,
1310 LParenLoc, EndLoc);
1311 }
1312
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001313 /// \brief Build a new OpenMP 'default' clause.
1314 ///
1315 /// By default, performs semantic analysis to build the new statement.
1316 /// Subclasses may override this routine to provide different behavior.
1317 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1318 SourceLocation KindKwLoc,
1319 SourceLocation StartLoc,
1320 SourceLocation LParenLoc,
1321 SourceLocation EndLoc) {
1322 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1323 StartLoc, LParenLoc, EndLoc);
1324 }
1325
1326 /// \brief Build a new OpenMP 'private' 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 *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1331 SourceLocation StartLoc,
1332 SourceLocation LParenLoc,
1333 SourceLocation EndLoc) {
1334 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1335 EndLoc);
1336 }
1337
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001338 /// \brief Build a new OpenMP 'firstprivate' clause.
1339 ///
1340 /// By default, performs semantic analysis to build the new statement.
1341 /// Subclasses may override this routine to provide different behavior.
1342 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1343 SourceLocation StartLoc,
1344 SourceLocation LParenLoc,
1345 SourceLocation EndLoc) {
1346 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1347 EndLoc);
1348 }
1349
Alexey Bataev758e55e2013-09-06 18:03:48 +00001350 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1351 SourceLocation StartLoc,
1352 SourceLocation LParenLoc,
1353 SourceLocation EndLoc) {
1354 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1355 EndLoc);
1356 }
1357
James Dennett2a4d13c2012-06-15 07:13:21 +00001358 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001359 ///
1360 /// By default, performs semantic analysis to build the new statement.
1361 /// Subclasses may override this routine to provide different behavior.
1362 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1363 Expr *object) {
1364 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1365 }
1366
James Dennett2a4d13c2012-06-15 07:13:21 +00001367 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001368 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001369 /// By default, performs semantic analysis to build the new statement.
1370 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001371 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001372 Expr *Object, Stmt *Body) {
1373 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001374 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001375
James Dennett2a4d13c2012-06-15 07:13:21 +00001376 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001377 ///
1378 /// By default, performs semantic analysis to build the new statement.
1379 /// Subclasses may override this routine to provide different behavior.
1380 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1381 Stmt *Body) {
1382 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1383 }
John McCall53848232011-07-27 01:07:15 +00001384
Douglas Gregorf68a5082010-04-22 23:10:45 +00001385 /// \brief Build a new Objective-C fast enumeration statement.
1386 ///
1387 /// By default, performs semantic analysis to build the new statement.
1388 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001389 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001390 Stmt *Element,
1391 Expr *Collection,
1392 SourceLocation RParenLoc,
1393 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001394 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001395 Element,
John McCallb268a282010-08-23 23:25:46 +00001396 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001397 RParenLoc);
1398 if (ForEachStmt.isInvalid())
1399 return StmtError();
1400
1401 return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001402 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001403
Douglas Gregorebe10102009-08-20 07:17:43 +00001404 /// \brief Build a new C++ exception declaration.
1405 ///
1406 /// By default, performs semantic analysis to build the new decaration.
1407 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001408 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001409 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001410 SourceLocation StartLoc,
1411 SourceLocation IdLoc,
1412 IdentifierInfo *Id) {
Douglas Gregor40965fa2011-04-14 22:32:28 +00001413 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1414 StartLoc, IdLoc, Id);
1415 if (Var)
1416 getSema().CurContext->addDecl(Var);
1417 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001418 }
1419
1420 /// \brief Build a new C++ catch statement.
1421 ///
1422 /// By default, performs semantic analysis to build the new statement.
1423 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001424 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001425 VarDecl *ExceptionDecl,
1426 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001427 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1428 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001429 }
Mike Stump11289f42009-09-09 15:08:12 +00001430
Douglas Gregorebe10102009-08-20 07:17:43 +00001431 /// \brief Build a new C++ try statement.
1432 ///
1433 /// By default, performs semantic analysis to build the new statement.
1434 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001435 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1436 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001437 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001438 }
Mike Stump11289f42009-09-09 15:08:12 +00001439
Richard Smith02e85f32011-04-14 22:09:26 +00001440 /// \brief Build a new C++0x range-based for statement.
1441 ///
1442 /// By default, performs semantic analysis to build the new statement.
1443 /// Subclasses may override this routine to provide different behavior.
1444 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1445 SourceLocation ColonLoc,
1446 Stmt *Range, Stmt *BeginEnd,
1447 Expr *Cond, Expr *Inc,
1448 Stmt *LoopVar,
1449 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001450 // If we've just learned that the range is actually an Objective-C
1451 // collection, treat this as an Objective-C fast enumeration loop.
1452 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1453 if (RangeStmt->isSingleDecl()) {
1454 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001455 if (RangeVar->isInvalidDecl())
1456 return StmtError();
1457
Douglas Gregorf7106af2013-04-08 18:40:13 +00001458 Expr *RangeExpr = RangeVar->getInit();
1459 if (!RangeExpr->isTypeDependent() &&
1460 RangeExpr->getType()->isObjCObjectPointerType())
1461 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1462 RParenLoc);
1463 }
1464 }
1465 }
1466
Richard Smith02e85f32011-04-14 22:09:26 +00001467 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001468 Cond, Inc, LoopVar, RParenLoc,
1469 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001470 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001471
1472 /// \brief Build a new C++0x range-based for statement.
1473 ///
1474 /// By default, performs semantic analysis to build the new statement.
1475 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001476 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001477 bool IsIfExists,
1478 NestedNameSpecifierLoc QualifierLoc,
1479 DeclarationNameInfo NameInfo,
1480 Stmt *Nested) {
1481 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1482 QualifierLoc, NameInfo, Nested);
1483 }
1484
Richard Smith02e85f32011-04-14 22:09:26 +00001485 /// \brief Attach body to a C++0x range-based for statement.
1486 ///
1487 /// By default, performs semantic analysis to finish the new statement.
1488 /// Subclasses may override this routine to provide different behavior.
1489 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1490 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1491 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001492
David Majnemerfad8f482013-10-15 09:33:02 +00001493 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
1494 Stmt *TryBlock, Stmt *Handler) {
1495 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001496 }
1497
David Majnemerfad8f482013-10-15 09:33:02 +00001498 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001499 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001500 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001501 }
1502
David Majnemerfad8f482013-10-15 09:33:02 +00001503 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
1504 return getSema().ActOnSEHFinallyBlock(Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001505 }
1506
Douglas Gregora16548e2009-08-11 05:31:07 +00001507 /// \brief Build a new expression that references a declaration.
1508 ///
1509 /// By default, performs semantic analysis to build the new expression.
1510 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001511 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001512 LookupResult &R,
1513 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001514 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1515 }
1516
1517
1518 /// \brief Build a new expression that references a declaration.
1519 ///
1520 /// By default, performs semantic analysis to build the new expression.
1521 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001522 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001523 ValueDecl *VD,
1524 const DeclarationNameInfo &NameInfo,
1525 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001526 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001527 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001528
1529 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001530
1531 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001532 }
Mike Stump11289f42009-09-09 15:08:12 +00001533
Douglas Gregora16548e2009-08-11 05:31:07 +00001534 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001535 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001536 /// By default, performs semantic analysis to build the new expression.
1537 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001538 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001539 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001540 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001541 }
1542
Douglas Gregorad8a3362009-09-04 17:36:40 +00001543 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001544 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001545 /// By default, performs semantic analysis to build the new expression.
1546 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001547 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001548 SourceLocation OperatorLoc,
1549 bool isArrow,
1550 CXXScopeSpec &SS,
1551 TypeSourceInfo *ScopeType,
1552 SourceLocation CCLoc,
1553 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001554 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001555
Douglas Gregora16548e2009-08-11 05:31:07 +00001556 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001557 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001558 /// By default, performs semantic analysis to build the new expression.
1559 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001560 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001561 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001562 Expr *SubExpr) {
1563 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001564 }
Mike Stump11289f42009-09-09 15:08:12 +00001565
Douglas Gregor882211c2010-04-28 22:16:22 +00001566 /// \brief Build a new builtin offsetof expression.
1567 ///
1568 /// By default, performs semantic analysis to build the new expression.
1569 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001570 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001571 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001572 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001573 unsigned NumComponents,
1574 SourceLocation RParenLoc) {
1575 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1576 NumComponents, RParenLoc);
1577 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001578
1579 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001580 /// type 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(TypeSourceInfo *TInfo,
1585 SourceLocation OpLoc,
1586 UnaryExprOrTypeTrait ExprKind,
1587 SourceRange R) {
1588 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001589 }
1590
Peter Collingbournee190dee2011-03-11 19:24:49 +00001591 /// \brief Build a new sizeof, alignof or vec step expression with an
1592 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001593 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001594 /// By default, performs semantic analysis to build the new expression.
1595 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001596 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1597 UnaryExprOrTypeTrait ExprKind,
1598 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001599 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001600 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001601 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001602 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001603
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001604 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001605 }
Mike Stump11289f42009-09-09 15:08:12 +00001606
Douglas Gregora16548e2009-08-11 05:31:07 +00001607 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001608 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001609 /// By default, performs semantic analysis to build the new expression.
1610 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001611 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001612 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001613 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001614 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001615 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1616 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001617 RBracketLoc);
1618 }
1619
1620 /// \brief Build a new call 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 RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001625 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001626 SourceLocation RParenLoc,
1627 Expr *ExecConfig = 0) {
John McCallb268a282010-08-23 23:25:46 +00001628 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001629 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001630 }
1631
1632 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001633 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001634 /// By default, performs semantic analysis to build the new expression.
1635 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001636 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001637 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001638 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001639 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001640 const DeclarationNameInfo &MemberNameInfo,
1641 ValueDecl *Member,
1642 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001643 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001644 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00001645 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1646 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00001647 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001648 // We have a reference to an unnamed field. This is always the
1649 // base of an anonymous struct/union member access, i.e. the
1650 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001651 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001652 assert(Member->getType()->isRecordType() &&
1653 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001654
Richard Smithcab9a7d2011-10-26 19:06:56 +00001655 BaseResult =
1656 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley01296292011-04-08 18:41:53 +00001657 QualifierLoc.getNestedNameSpecifier(),
1658 FoundDecl, Member);
1659 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001660 return ExprError();
John Wiegley01296292011-04-08 18:41:53 +00001661 Base = BaseResult.take();
John McCall7decc9e2010-11-18 06:31:45 +00001662 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001663 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001664 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001665 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001666 cast<FieldDecl>(Member)->getType(),
1667 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001668 return getSema().Owned(ME);
1669 }
Mike Stump11289f42009-09-09 15:08:12 +00001670
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001671 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001672 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001673
John Wiegley01296292011-04-08 18:41:53 +00001674 Base = BaseResult.take();
John McCallb268a282010-08-23 23:25:46 +00001675 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001676
John McCall16df1e52010-03-30 21:47:33 +00001677 // FIXME: this involves duplicating earlier analysis in a lot of
1678 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001679 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001680 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001681 R.resolveKind();
1682
John McCallb268a282010-08-23 23:25:46 +00001683 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001684 SS, TemplateKWLoc,
1685 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001686 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001687 }
Mike Stump11289f42009-09-09 15:08:12 +00001688
Douglas Gregora16548e2009-08-11 05:31:07 +00001689 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001690 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001691 /// By default, performs semantic analysis to build the new expression.
1692 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001693 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001694 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001695 Expr *LHS, Expr *RHS) {
1696 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001697 }
1698
1699 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001700 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001701 /// By default, performs semantic analysis to build the new expression.
1702 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001703 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001704 SourceLocation QuestionLoc,
1705 Expr *LHS,
1706 SourceLocation ColonLoc,
1707 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001708 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1709 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001710 }
1711
Douglas Gregora16548e2009-08-11 05:31:07 +00001712 /// \brief Build a new C-style cast 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 RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001717 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001718 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001719 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001720 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001721 SubExpr);
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 compound literal 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 RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001729 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001730 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001731 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001732 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001733 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001734 }
Mike Stump11289f42009-09-09 15:08:12 +00001735
Douglas Gregora16548e2009-08-11 05:31:07 +00001736 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001737 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001738 /// By default, performs semantic analysis to build the new expression.
1739 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001740 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001741 SourceLocation OpLoc,
1742 SourceLocation AccessorLoc,
1743 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001744
John McCall10eae182009-11-30 22:42:35 +00001745 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001746 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001747 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001748 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001749 SS, SourceLocation(),
1750 /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001751 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001752 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001753 }
Mike Stump11289f42009-09-09 15:08:12 +00001754
Douglas Gregora16548e2009-08-11 05:31:07 +00001755 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001756 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001757 /// By default, performs semantic analysis to build the new expression.
1758 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001759 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00001760 MultiExprArg Inits,
1761 SourceLocation RBraceLoc,
1762 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001763 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001764 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00001765 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001766 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00001767
Douglas Gregord3d93062009-11-09 17:16:50 +00001768 // Patch in the result type we were given, which may have been computed
1769 // when the initial InitListExpr was built.
1770 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1771 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001772 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001773 }
Mike Stump11289f42009-09-09 15:08:12 +00001774
Douglas Gregora16548e2009-08-11 05:31:07 +00001775 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001776 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001777 /// By default, performs semantic analysis to build the new expression.
1778 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001779 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001780 MultiExprArg ArrayExprs,
1781 SourceLocation EqualOrColonLoc,
1782 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001783 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001784 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001785 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001786 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001787 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001788 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001789
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001790 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001791 }
Mike Stump11289f42009-09-09 15:08:12 +00001792
Douglas Gregora16548e2009-08-11 05:31:07 +00001793 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001794 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001795 /// By default, builds the implicit value initialization without performing
1796 /// any semantic analysis. Subclasses may override this routine to provide
1797 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001798 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001799 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1800 }
Mike Stump11289f42009-09-09 15:08:12 +00001801
Douglas Gregora16548e2009-08-11 05:31:07 +00001802 /// \brief Build a new \c va_arg expression.
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 RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001807 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001808 SourceLocation RParenLoc) {
1809 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001810 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001811 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001812 }
1813
1814 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001815 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001816 /// By default, performs semantic analysis to build the new expression.
1817 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001818 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00001819 MultiExprArg SubExprs,
1820 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001821 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001822 }
Mike Stump11289f42009-09-09 15:08:12 +00001823
Douglas Gregora16548e2009-08-11 05:31:07 +00001824 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001825 ///
1826 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001827 /// rather than attempting to map the label statement itself.
1828 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001829 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001830 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001831 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001832 }
Mike Stump11289f42009-09-09 15:08:12 +00001833
Douglas Gregora16548e2009-08-11 05:31:07 +00001834 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001835 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001836 /// By default, performs semantic analysis to build the new expression.
1837 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001838 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001839 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001840 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001841 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001842 }
Mike Stump11289f42009-09-09 15:08:12 +00001843
Douglas Gregora16548e2009-08-11 05:31:07 +00001844 /// \brief Build a new __builtin_choose_expr expression.
1845 ///
1846 /// By default, performs semantic analysis to build the new expression.
1847 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001848 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001849 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001850 SourceLocation RParenLoc) {
1851 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001852 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001853 RParenLoc);
1854 }
Mike Stump11289f42009-09-09 15:08:12 +00001855
Peter Collingbourne91147592011-04-15 00:35:48 +00001856 /// \brief Build a new generic selection expression.
1857 ///
1858 /// By default, performs semantic analysis to build the new expression.
1859 /// Subclasses may override this routine to provide different behavior.
1860 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1861 SourceLocation DefaultLoc,
1862 SourceLocation RParenLoc,
1863 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00001864 ArrayRef<TypeSourceInfo *> Types,
1865 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00001866 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00001867 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00001868 }
1869
Douglas Gregora16548e2009-08-11 05:31:07 +00001870 /// \brief Build a new overloaded operator call expression.
1871 ///
1872 /// By default, performs semantic analysis to build the new expression.
1873 /// The semantic analysis provides the behavior of template instantiation,
1874 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001875 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001876 /// argument-dependent lookup, etc. Subclasses may override this routine to
1877 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001878 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001879 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001880 Expr *Callee,
1881 Expr *First,
1882 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001883
1884 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001885 /// reinterpret_cast.
1886 ///
1887 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001888 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001889 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001890 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001891 Stmt::StmtClass Class,
1892 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001893 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001894 SourceLocation RAngleLoc,
1895 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001896 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001897 SourceLocation RParenLoc) {
1898 switch (Class) {
1899 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001900 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001901 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001902 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001903
1904 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001905 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001906 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001907 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001908
Douglas Gregora16548e2009-08-11 05:31:07 +00001909 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001910 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001911 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001912 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001913 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001914
Douglas Gregora16548e2009-08-11 05:31:07 +00001915 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001916 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001917 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001918 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001919
Douglas Gregora16548e2009-08-11 05:31:07 +00001920 default:
David Blaikie83d382b2011-09-23 05:06:16 +00001921 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00001922 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001923 }
Mike Stump11289f42009-09-09 15:08:12 +00001924
Douglas Gregora16548e2009-08-11 05:31:07 +00001925 /// \brief Build a new C++ static_cast expression.
1926 ///
1927 /// By default, performs semantic analysis to build the new expression.
1928 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001929 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001930 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001931 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001932 SourceLocation RAngleLoc,
1933 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001934 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001935 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001936 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001937 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001938 SourceRange(LAngleLoc, RAngleLoc),
1939 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001940 }
1941
1942 /// \brief Build a new C++ dynamic_cast expression.
1943 ///
1944 /// By default, performs semantic analysis to build the new expression.
1945 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001946 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001947 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001948 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001949 SourceLocation RAngleLoc,
1950 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001951 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001952 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001953 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001954 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001955 SourceRange(LAngleLoc, RAngleLoc),
1956 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001957 }
1958
1959 /// \brief Build a new C++ reinterpret_cast expression.
1960 ///
1961 /// By default, performs semantic analysis to build the new expression.
1962 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001963 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001964 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001965 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001966 SourceLocation RAngleLoc,
1967 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001968 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001969 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001970 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001971 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001972 SourceRange(LAngleLoc, RAngleLoc),
1973 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001974 }
1975
1976 /// \brief Build a new C++ const_cast expression.
1977 ///
1978 /// By default, performs semantic analysis to build the new expression.
1979 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001980 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001981 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001982 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001983 SourceLocation RAngleLoc,
1984 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001985 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001986 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001987 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001988 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001989 SourceRange(LAngleLoc, RAngleLoc),
1990 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001991 }
Mike Stump11289f42009-09-09 15:08:12 +00001992
Douglas Gregora16548e2009-08-11 05:31:07 +00001993 /// \brief Build a new C++ functional-style cast expression.
1994 ///
1995 /// By default, performs semantic analysis to build the new expression.
1996 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001997 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1998 SourceLocation LParenLoc,
1999 Expr *Sub,
2000 SourceLocation RParenLoc) {
2001 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002002 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002003 RParenLoc);
2004 }
Mike Stump11289f42009-09-09 15:08:12 +00002005
Douglas Gregora16548e2009-08-11 05:31:07 +00002006 /// \brief Build a new C++ typeid(type) expression.
2007 ///
2008 /// By default, performs semantic analysis to build the new expression.
2009 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002010 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002011 SourceLocation TypeidLoc,
2012 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002013 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002014 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002015 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002016 }
Mike Stump11289f42009-09-09 15:08:12 +00002017
Francois Pichet9f4f2072010-09-08 12:20:18 +00002018
Douglas Gregora16548e2009-08-11 05:31:07 +00002019 /// \brief Build a new C++ typeid(expr) expression.
2020 ///
2021 /// By default, performs semantic analysis to build the new expression.
2022 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002023 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002024 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002025 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002026 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002027 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002028 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002029 }
2030
Francois Pichet9f4f2072010-09-08 12:20:18 +00002031 /// \brief Build a new C++ __uuidof(type) 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 TypeSourceInfo *Operand,
2038 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002039 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002040 RParenLoc);
2041 }
2042
2043 /// \brief Build a new C++ __uuidof(expr) expression.
2044 ///
2045 /// By default, performs semantic analysis to build the new expression.
2046 /// Subclasses may override this routine to provide different behavior.
2047 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2048 SourceLocation TypeidLoc,
2049 Expr *Operand,
2050 SourceLocation RParenLoc) {
2051 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2052 RParenLoc);
2053 }
2054
Douglas Gregora16548e2009-08-11 05:31:07 +00002055 /// \brief Build a new C++ "this" expression.
2056 ///
2057 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002058 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002059 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002060 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002061 QualType ThisType,
2062 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002063 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002064 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00002065 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
2066 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00002067 }
2068
2069 /// \brief Build a new C++ throw expression.
2070 ///
2071 /// By default, performs semantic analysis to build the new expression.
2072 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002073 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2074 bool IsThrownVariableInScope) {
2075 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002076 }
2077
2078 /// \brief Build a new C++ default-argument expression.
2079 ///
2080 /// By default, builds a new default-argument expression, which does not
2081 /// require any semantic analysis. Subclasses may override this routine to
2082 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002083 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002084 ParmVarDecl *Param) {
2085 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
2086 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00002087 }
2088
Richard Smith852c9db2013-04-20 22:23:05 +00002089 /// \brief Build a new C++11 default-initialization expression.
2090 ///
2091 /// By default, builds a new default field initialization expression, which
2092 /// does not require any semantic analysis. Subclasses may override this
2093 /// routine to provide different behavior.
2094 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2095 FieldDecl *Field) {
2096 return getSema().Owned(CXXDefaultInitExpr::Create(getSema().Context, Loc,
2097 Field));
2098 }
2099
Douglas Gregora16548e2009-08-11 05:31:07 +00002100 /// \brief Build a new C++ zero-initialization expression.
2101 ///
2102 /// By default, performs semantic analysis to build the new expression.
2103 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002104 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2105 SourceLocation LParenLoc,
2106 SourceLocation RParenLoc) {
2107 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002108 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002109 }
Mike Stump11289f42009-09-09 15:08:12 +00002110
Douglas Gregora16548e2009-08-11 05:31:07 +00002111 /// \brief Build a new C++ "new" expression.
2112 ///
2113 /// By default, performs semantic analysis to build the new expression.
2114 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002115 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002116 bool UseGlobal,
2117 SourceLocation PlacementLParen,
2118 MultiExprArg PlacementArgs,
2119 SourceLocation PlacementRParen,
2120 SourceRange TypeIdParens,
2121 QualType AllocatedType,
2122 TypeSourceInfo *AllocatedTypeInfo,
2123 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002124 SourceRange DirectInitRange,
2125 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002126 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002127 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002128 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002129 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002130 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002131 AllocatedType,
2132 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002133 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002134 DirectInitRange,
2135 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002136 }
Mike Stump11289f42009-09-09 15:08:12 +00002137
Douglas Gregora16548e2009-08-11 05:31:07 +00002138 /// \brief Build a new C++ "delete" expression.
2139 ///
2140 /// By default, performs semantic analysis to build the new expression.
2141 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002142 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002143 bool IsGlobalDelete,
2144 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002145 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002146 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002147 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002148 }
Mike Stump11289f42009-09-09 15:08:12 +00002149
Douglas Gregor29c42f22012-02-24 07:38:34 +00002150 /// \brief Build a new type trait expression.
2151 ///
2152 /// By default, performs semantic analysis to build the new expression.
2153 /// Subclasses may override this routine to provide different behavior.
2154 ExprResult RebuildTypeTrait(TypeTrait Trait,
2155 SourceLocation StartLoc,
2156 ArrayRef<TypeSourceInfo *> Args,
2157 SourceLocation RParenLoc) {
2158 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2159 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002160
John Wiegley6242b6a2011-04-28 00:16:57 +00002161 /// \brief Build a new array type 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 RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2166 SourceLocation StartLoc,
2167 TypeSourceInfo *TSInfo,
2168 Expr *DimExpr,
2169 SourceLocation RParenLoc) {
2170 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2171 }
2172
John Wiegleyf9f65842011-04-25 06:54:41 +00002173 /// \brief Build a new expression trait expression.
2174 ///
2175 /// By default, performs semantic analysis to build the new expression.
2176 /// Subclasses may override this routine to provide different behavior.
2177 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2178 SourceLocation StartLoc,
2179 Expr *Queried,
2180 SourceLocation RParenLoc) {
2181 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2182 }
2183
Mike Stump11289f42009-09-09 15:08:12 +00002184 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002185 /// expression.
2186 ///
2187 /// By default, performs semantic analysis to build the new expression.
2188 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002189 ExprResult RebuildDependentScopeDeclRefExpr(
2190 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002191 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002192 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002193 const TemplateArgumentListInfo *TemplateArgs,
2194 bool IsAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002195 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002196 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002197
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002198 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnara7945c982012-01-27 09:46:47 +00002199 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002200 NameInfo, TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002201
Richard Smithdb2630f2012-10-21 03:28:35 +00002202 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo,
2203 IsAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002204 }
2205
2206 /// \brief Build a new template-id expression.
2207 ///
2208 /// By default, performs semantic analysis to build the new expression.
2209 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002210 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002211 SourceLocation TemplateKWLoc,
2212 LookupResult &R,
2213 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002214 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002215 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2216 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002217 }
2218
2219 /// \brief Build a new object-construction expression.
2220 ///
2221 /// By default, performs semantic analysis to build the new expression.
2222 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002223 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002224 SourceLocation Loc,
2225 CXXConstructorDecl *Constructor,
2226 bool IsElidable,
2227 MultiExprArg Args,
2228 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002229 bool ListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002230 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002231 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002232 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002233 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002234 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002235 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002236 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002237
Douglas Gregordb121ba2009-12-14 16:27:04 +00002238 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002239 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002240 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002241 ListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002242 RequiresZeroInit, ConstructKind,
2243 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002244 }
2245
2246 /// \brief Build a new object-construction expression.
2247 ///
2248 /// By default, performs semantic analysis to build the new expression.
2249 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002250 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2251 SourceLocation LParenLoc,
2252 MultiExprArg Args,
2253 SourceLocation RParenLoc) {
2254 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002255 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002256 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002257 RParenLoc);
2258 }
2259
2260 /// \brief Build a new object-construction expression.
2261 ///
2262 /// By default, performs semantic analysis to build the new expression.
2263 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002264 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2265 SourceLocation LParenLoc,
2266 MultiExprArg Args,
2267 SourceLocation RParenLoc) {
2268 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002269 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002270 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002271 RParenLoc);
2272 }
Mike Stump11289f42009-09-09 15:08:12 +00002273
Douglas Gregora16548e2009-08-11 05:31:07 +00002274 /// \brief Build a new member reference expression.
2275 ///
2276 /// By default, performs semantic analysis to build the new expression.
2277 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002278 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002279 QualType BaseType,
2280 bool IsArrow,
2281 SourceLocation OperatorLoc,
2282 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002283 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002284 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002285 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002286 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002287 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002288 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002289
John McCallb268a282010-08-23 23:25:46 +00002290 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002291 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002292 SS, TemplateKWLoc,
2293 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002294 MemberNameInfo,
2295 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002296 }
2297
John McCall10eae182009-11-30 22:42:35 +00002298 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002299 ///
2300 /// By default, performs semantic analysis to build the new expression.
2301 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002302 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2303 SourceLocation OperatorLoc,
2304 bool IsArrow,
2305 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002306 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002307 NamedDecl *FirstQualifierInScope,
2308 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002309 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002310 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002311 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002312
John McCallb268a282010-08-23 23:25:46 +00002313 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002314 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002315 SS, TemplateKWLoc,
2316 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00002317 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002318 }
Mike Stump11289f42009-09-09 15:08:12 +00002319
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002320 /// \brief Build a new noexcept expression.
2321 ///
2322 /// By default, performs semantic analysis to build the new expression.
2323 /// Subclasses may override this routine to provide different behavior.
2324 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2325 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2326 }
2327
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002328 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00002329 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2330 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002331 SourceLocation RParenLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002332 Optional<unsigned> Length) {
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002333 if (Length)
Chad Rosier1dcde962012-08-08 18:46:20 +00002334 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2335 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002336 RParenLoc, *Length);
Chad Rosier1dcde962012-08-08 18:46:20 +00002337
2338 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2339 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002340 RParenLoc);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002341 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002342
Patrick Beard0caa3942012-04-19 00:25:12 +00002343 /// \brief Build a new Objective-C boxed expression.
2344 ///
2345 /// By default, performs semantic analysis to build the new expression.
2346 /// Subclasses may override this routine to provide different behavior.
2347 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2348 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2349 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002350
Ted Kremeneke65b0862012-03-06 20:05:56 +00002351 /// \brief Build a new Objective-C array literal.
2352 ///
2353 /// By default, performs semantic analysis to build the new expression.
2354 /// Subclasses may override this routine to provide different behavior.
2355 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2356 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002357 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002358 MultiExprArg(Elements, NumElements));
2359 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002360
2361 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002362 Expr *Base, Expr *Key,
2363 ObjCMethodDecl *getterMethod,
2364 ObjCMethodDecl *setterMethod) {
2365 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2366 getterMethod, setterMethod);
2367 }
2368
2369 /// \brief Build a new Objective-C dictionary literal.
2370 ///
2371 /// By default, performs semantic analysis to build the new expression.
2372 /// Subclasses may override this routine to provide different behavior.
2373 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2374 ObjCDictionaryElement *Elements,
2375 unsigned NumElements) {
2376 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2377 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002378
James Dennett2a4d13c2012-06-15 07:13:21 +00002379 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002380 ///
2381 /// By default, performs semantic analysis to build the new expression.
2382 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002383 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002384 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002385 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00002386 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002387 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002388 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002389
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002390 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002391 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002392 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002393 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002394 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002395 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002396 MultiExprArg Args,
2397 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002398 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2399 ReceiverTypeInfo->getType(),
2400 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002401 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002402 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002403 }
2404
2405 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002406 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002407 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002408 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002409 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002410 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002411 MultiExprArg Args,
2412 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002413 return SemaRef.BuildInstanceMessage(Receiver,
2414 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002415 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002416 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002417 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002418 }
2419
Douglas Gregord51d90d2010-04-26 20:11:03 +00002420 /// \brief Build a new Objective-C ivar reference expression.
2421 ///
2422 /// By default, performs semantic analysis to build the new expression.
2423 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002424 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002425 SourceLocation IvarLoc,
2426 bool IsArrow, bool IsFreeIvar) {
2427 // FIXME: We lose track of the IsFreeIvar bit.
2428 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002429 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002430 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2431 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002432 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002433 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00002434 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00002435 false);
John Wiegley01296292011-04-08 18:41:53 +00002436 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002437 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002438
Douglas Gregord51d90d2010-04-26 20:11:03 +00002439 if (Result.get())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002440 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002441
John Wiegley01296292011-04-08 18:41:53 +00002442 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002443 /*FIXME:*/IvarLoc, IsArrow,
2444 SS, SourceLocation(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00002445 /*FirstQualifierInScope=*/0,
Chad Rosier1dcde962012-08-08 18:46:20 +00002446 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002447 /*TemplateArgs=*/0);
2448 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002449
2450 /// \brief Build a new Objective-C property reference expression.
2451 ///
2452 /// By default, performs semantic analysis to build the new expression.
2453 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002454 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002455 ObjCPropertyDecl *Property,
2456 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002457 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002458 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregor9faee212010-04-26 20:47:02 +00002459 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2460 Sema::LookupMemberName);
2461 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002462 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002463 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002464 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002465 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002466 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002467
Douglas Gregor9faee212010-04-26 20:47:02 +00002468 if (Result.get())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002469 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002470
John Wiegley01296292011-04-08 18:41:53 +00002471 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Chad Rosier1dcde962012-08-08 18:46:20 +00002472 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002473 SS, SourceLocation(),
Douglas Gregor9faee212010-04-26 20:47:02 +00002474 /*FirstQualifierInScope=*/0,
Chad Rosier1dcde962012-08-08 18:46:20 +00002475 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002476 /*TemplateArgs=*/0);
2477 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002478
John McCallb7bd14f2010-12-02 01:19:52 +00002479 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002480 ///
2481 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002482 /// Subclasses may override this routine to provide different behavior.
2483 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2484 ObjCMethodDecl *Getter,
2485 ObjCMethodDecl *Setter,
2486 SourceLocation PropertyLoc) {
2487 // Since these expressions can only be value-dependent, we do not
2488 // need to perform semantic analysis again.
2489 return Owned(
2490 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2491 VK_LValue, OK_ObjCProperty,
2492 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002493 }
2494
Douglas Gregord51d90d2010-04-26 20:11:03 +00002495 /// \brief Build a new Objective-C "isa" expression.
2496 ///
2497 /// By default, performs semantic analysis to build the new expression.
2498 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002499 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002500 SourceLocation OpLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002501 bool IsArrow) {
2502 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002503 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002504 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2505 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002506 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002507 OpLoc,
John McCall48871652010-08-21 09:40:31 +00002508 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002509 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002510 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002511
Douglas Gregord51d90d2010-04-26 20:11:03 +00002512 if (Result.get())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002513 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002514
John Wiegley01296292011-04-08 18:41:53 +00002515 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002516 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002517 SS, SourceLocation(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00002518 /*FirstQualifierInScope=*/0,
Chad Rosier1dcde962012-08-08 18:46:20 +00002519 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002520 /*TemplateArgs=*/0);
2521 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002522
Douglas Gregora16548e2009-08-11 05:31:07 +00002523 /// \brief Build a new shuffle vector expression.
2524 ///
2525 /// By default, performs semantic analysis to build the new expression.
2526 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002527 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002528 MultiExprArg SubExprs,
2529 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002530 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002531 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002532 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2533 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2534 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002535 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002536
Douglas Gregora16548e2009-08-11 05:31:07 +00002537 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002538 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002539 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2540 SemaRef.Context.BuiltinFnTy,
2541 VK_RValue, BuiltinLoc);
2542 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2543 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
2544 CK_BuiltinFnToFnPtr).take();
Mike Stump11289f42009-09-09 15:08:12 +00002545
2546 // Build the CallExpr
Alp Toker314cc812014-01-25 16:55:45 +00002547 ExprResult TheCall = SemaRef.Owned(new (SemaRef.Context) CallExpr(
2548 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
2549 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002550
Douglas Gregora16548e2009-08-11 05:31:07 +00002551 // Type-check the __builtin_shufflevector expression.
John Wiegley01296292011-04-08 18:41:53 +00002552 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002553 }
John McCall31f82722010-11-12 08:19:04 +00002554
Hal Finkelc4d7c822013-09-18 03:29:45 +00002555 /// \brief Build a new convert vector expression.
2556 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2557 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2558 SourceLocation RParenLoc) {
2559 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2560 BuiltinLoc, RParenLoc);
2561 }
2562
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002563 /// \brief Build a new template argument pack expansion.
2564 ///
2565 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002566 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002567 /// different behavior.
2568 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002569 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002570 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002571 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002572 case TemplateArgument::Expression: {
2573 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002574 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2575 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002576 if (Result.isInvalid())
2577 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002578
Douglas Gregor98318c22011-01-03 21:37:45 +00002579 return TemplateArgumentLoc(Result.get(), Result.get());
2580 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002581
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002582 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002583 return TemplateArgumentLoc(TemplateArgument(
2584 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002585 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002586 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002587 Pattern.getTemplateNameLoc(),
2588 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002589
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002590 case TemplateArgument::Null:
2591 case TemplateArgument::Integral:
2592 case TemplateArgument::Declaration:
2593 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002594 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002595 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002596 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002597
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002598 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002599 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002600 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002601 EllipsisLoc,
2602 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002603 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2604 Expansion);
2605 break;
2606 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002607
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002608 return TemplateArgumentLoc();
2609 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002610
Douglas Gregor968f23a2011-01-03 19:31:53 +00002611 /// \brief Build a new expression pack expansion.
2612 ///
2613 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002614 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002615 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002616 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002617 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002618 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002619 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002620
2621 /// \brief Build a new atomic operation expression.
2622 ///
2623 /// By default, performs semantic analysis to build the new expression.
2624 /// Subclasses may override this routine to provide different behavior.
2625 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2626 MultiExprArg SubExprs,
2627 QualType RetTy,
2628 AtomicExpr::AtomicOp Op,
2629 SourceLocation RParenLoc) {
2630 // Just create the expression; there is not any interesting semantic
2631 // analysis here because we can't actually build an AtomicExpr until
2632 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00002633 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002634 RParenLoc);
2635 }
2636
John McCall31f82722010-11-12 08:19:04 +00002637private:
Douglas Gregor14454802011-02-25 02:25:35 +00002638 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2639 QualType ObjectType,
2640 NamedDecl *FirstQualifierInScope,
2641 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002642
2643 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2644 QualType ObjectType,
2645 NamedDecl *FirstQualifierInScope,
2646 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00002647
2648 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
2649 NamedDecl *FirstQualifierInScope,
2650 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002651};
Douglas Gregora16548e2009-08-11 05:31:07 +00002652
Douglas Gregorebe10102009-08-20 07:17:43 +00002653template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002654StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002655 if (!S)
2656 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002657
Douglas Gregorebe10102009-08-20 07:17:43 +00002658 switch (S->getStmtClass()) {
2659 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002660
Douglas Gregorebe10102009-08-20 07:17:43 +00002661 // Transform individual statement nodes
2662#define STMT(Node, Parent) \
2663 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002664#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002665#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002666#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002667
Douglas Gregorebe10102009-08-20 07:17:43 +00002668 // Transform expressions by calling TransformExpr.
2669#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002670#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002671#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002672#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002673 {
John McCalldadc5752010-08-24 06:29:42 +00002674 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002675 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002676 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002677
Richard Smith945f8d32013-01-14 22:39:08 +00002678 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00002679 }
Mike Stump11289f42009-09-09 15:08:12 +00002680 }
2681
John McCallc3007a22010-10-26 07:05:15 +00002682 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002683}
Mike Stump11289f42009-09-09 15:08:12 +00002684
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002685template<typename Derived>
2686OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2687 if (!S)
2688 return S;
2689
2690 switch (S->getClauseKind()) {
2691 default: break;
2692 // Transform individual clause nodes
2693#define OPENMP_CLAUSE(Name, Class) \
2694 case OMPC_ ## Name : \
2695 return getDerived().Transform ## Class(cast<Class>(S));
2696#include "clang/Basic/OpenMPKinds.def"
2697 }
2698
2699 return S;
2700}
2701
Mike Stump11289f42009-09-09 15:08:12 +00002702
Douglas Gregore922c772009-08-04 22:27:00 +00002703template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002704ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002705 if (!E)
2706 return SemaRef.Owned(E);
2707
2708 switch (E->getStmtClass()) {
2709 case Stmt::NoStmtClass: break;
2710#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002711#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002712#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002713 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002714#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002715 }
2716
John McCallc3007a22010-10-26 07:05:15 +00002717 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002718}
2719
2720template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00002721ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2722 bool CXXDirectInit) {
2723 // Initializers are instantiated like expressions, except that various outer
2724 // layers are stripped.
2725 if (!Init)
2726 return SemaRef.Owned(Init);
2727
2728 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2729 Init = ExprTemp->getSubExpr();
2730
Richard Smithe6ca4752013-05-30 22:40:16 +00002731 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2732 Init = MTE->GetTemporaryExpr();
2733
Richard Smithd59b8322012-12-19 01:39:02 +00002734 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2735 Init = Binder->getSubExpr();
2736
2737 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2738 Init = ICE->getSubExprAsWritten();
2739
Richard Smithcc1b96d2013-06-12 22:31:48 +00002740 if (CXXStdInitializerListExpr *ILE =
2741 dyn_cast<CXXStdInitializerListExpr>(Init))
2742 return TransformInitializer(ILE->getSubExpr(), CXXDirectInit);
2743
Richard Smith38a549b2012-12-21 08:13:35 +00002744 // If this is not a direct-initializer, we only need to reconstruct
2745 // InitListExprs. Other forms of copy-initialization will be a no-op if
2746 // the initializer is already the right type.
2747 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2748 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2749 return getDerived().TransformExpr(Init);
2750
2751 // Revert value-initialization back to empty parens.
2752 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2753 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002754 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002755 Parens.getEnd());
2756 }
2757
2758 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2759 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002760 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002761 SourceLocation());
2762
2763 // Revert initialization by constructor back to a parenthesized or braced list
2764 // of expressions. Any other form of initializer can just be reused directly.
2765 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00002766 return getDerived().TransformExpr(Init);
2767
2768 SmallVector<Expr*, 8> NewArgs;
2769 bool ArgChanged = false;
2770 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2771 /*IsCall*/true, NewArgs, &ArgChanged))
2772 return ExprError();
2773
2774 // If this was list initialization, revert to list form.
2775 if (Construct->isListInitialization())
2776 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2777 Construct->getLocEnd(),
2778 Construct->getType());
2779
Richard Smithd59b8322012-12-19 01:39:02 +00002780 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00002781 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smithd59b8322012-12-19 01:39:02 +00002782 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2783 Parens.getEnd());
2784}
2785
2786template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00002787bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2788 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002789 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00002790 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002791 bool *ArgChanged) {
2792 for (unsigned I = 0; I != NumInputs; ++I) {
2793 // If requested, drop call arguments that need to be dropped.
2794 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2795 if (ArgChanged)
2796 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002797
Douglas Gregora3efea12011-01-03 19:04:46 +00002798 break;
2799 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002800
Douglas Gregor968f23a2011-01-03 19:31:53 +00002801 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2802 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00002803
Chris Lattner01cf8db2011-07-20 06:58:45 +00002804 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002805 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2806 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00002807
Douglas Gregor968f23a2011-01-03 19:31:53 +00002808 // Determine whether the set of unexpanded parameter packs can and should
2809 // be expanded.
2810 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002811 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00002812 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2813 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002814 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2815 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00002816 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002817 Expand, RetainExpansion,
2818 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002819 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002820
Douglas Gregor968f23a2011-01-03 19:31:53 +00002821 if (!Expand) {
2822 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00002823 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00002824 // expansion.
2825 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2826 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2827 if (OutPattern.isInvalid())
2828 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002829
2830 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002831 Expansion->getEllipsisLoc(),
2832 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002833 if (Out.isInvalid())
2834 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002835
Douglas Gregor968f23a2011-01-03 19:31:53 +00002836 if (ArgChanged)
2837 *ArgChanged = true;
2838 Outputs.push_back(Out.get());
2839 continue;
2840 }
John McCall542e7c62011-07-06 07:30:07 +00002841
2842 // Record right away that the argument was changed. This needs
2843 // to happen even if the array expands to nothing.
2844 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002845
Douglas Gregor968f23a2011-01-03 19:31:53 +00002846 // The transform has determined that we should perform an elementwise
2847 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002848 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002849 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2850 ExprResult Out = getDerived().TransformExpr(Pattern);
2851 if (Out.isInvalid())
2852 return true;
2853
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002854 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002855 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2856 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002857 if (Out.isInvalid())
2858 return true;
2859 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002860
Douglas Gregor968f23a2011-01-03 19:31:53 +00002861 Outputs.push_back(Out.get());
2862 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002863
Douglas Gregor968f23a2011-01-03 19:31:53 +00002864 continue;
2865 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002866
Richard Smithd59b8322012-12-19 01:39:02 +00002867 ExprResult Result =
2868 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
2869 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00002870 if (Result.isInvalid())
2871 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002872
Douglas Gregora3efea12011-01-03 19:04:46 +00002873 if (Result.get() != Inputs[I] && ArgChanged)
2874 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002875
2876 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00002877 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002878
Douglas Gregora3efea12011-01-03 19:04:46 +00002879 return false;
2880}
2881
2882template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00002883NestedNameSpecifierLoc
2884TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2885 NestedNameSpecifierLoc NNS,
2886 QualType ObjectType,
2887 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00002888 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00002889 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00002890 Qualifier = Qualifier.getPrefix())
2891 Qualifiers.push_back(Qualifier);
2892
2893 CXXScopeSpec SS;
2894 while (!Qualifiers.empty()) {
2895 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2896 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00002897
Douglas Gregor14454802011-02-25 02:25:35 +00002898 switch (QNNS->getKind()) {
2899 case NestedNameSpecifier::Identifier:
Chad Rosier1dcde962012-08-08 18:46:20 +00002900 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregor14454802011-02-25 02:25:35 +00002901 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00002902 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00002903 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00002904 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00002905 FirstQualifierInScope, false))
2906 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002907
Douglas Gregor14454802011-02-25 02:25:35 +00002908 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00002909
Douglas Gregor14454802011-02-25 02:25:35 +00002910 case NestedNameSpecifier::Namespace: {
2911 NamespaceDecl *NS
2912 = cast_or_null<NamespaceDecl>(
2913 getDerived().TransformDecl(
2914 Q.getLocalBeginLoc(),
2915 QNNS->getAsNamespace()));
2916 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2917 break;
2918 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002919
Douglas Gregor14454802011-02-25 02:25:35 +00002920 case NestedNameSpecifier::NamespaceAlias: {
2921 NamespaceAliasDecl *Alias
2922 = cast_or_null<NamespaceAliasDecl>(
2923 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2924 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00002925 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00002926 Q.getLocalEndLoc());
2927 break;
2928 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002929
Douglas Gregor14454802011-02-25 02:25:35 +00002930 case NestedNameSpecifier::Global:
2931 // There is no meaningful transformation that one could perform on the
2932 // global scope.
2933 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2934 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00002935
Douglas Gregor14454802011-02-25 02:25:35 +00002936 case NestedNameSpecifier::TypeSpecWithTemplate:
2937 case NestedNameSpecifier::TypeSpec: {
2938 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2939 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00002940
Douglas Gregor14454802011-02-25 02:25:35 +00002941 if (!TL)
2942 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002943
Douglas Gregor14454802011-02-25 02:25:35 +00002944 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00002945 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00002946 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002947 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00002948 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00002949 if (TL.getType()->isEnumeralType())
2950 SemaRef.Diag(TL.getBeginLoc(),
2951 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00002952 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2953 Q.getLocalEndLoc());
2954 break;
2955 }
Richard Trieude756fb2011-05-07 01:36:37 +00002956 // If the nested-name-specifier is an invalid type def, don't emit an
2957 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00002958 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
2959 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002960 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00002961 << TL.getType() << SS.getRange();
2962 }
Douglas Gregor14454802011-02-25 02:25:35 +00002963 return NestedNameSpecifierLoc();
2964 }
Douglas Gregore16af532011-02-28 18:50:33 +00002965 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002966
Douglas Gregore16af532011-02-28 18:50:33 +00002967 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregor14454802011-02-25 02:25:35 +00002968 FirstQualifierInScope = 0;
Douglas Gregore16af532011-02-28 18:50:33 +00002969 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00002970 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002971
Douglas Gregor14454802011-02-25 02:25:35 +00002972 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00002973 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00002974 !getDerived().AlwaysRebuild())
2975 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00002976
2977 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00002978 // nested-name-specifier, do so.
2979 if (SS.location_size() == NNS.getDataLength() &&
2980 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2981 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2982
2983 // Allocate new nested-name-specifier location information.
2984 return SS.getWithLocInContext(SemaRef.Context);
2985}
2986
2987template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002988DeclarationNameInfo
2989TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002990::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002991 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002992 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002993 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002994
2995 switch (Name.getNameKind()) {
2996 case DeclarationName::Identifier:
2997 case DeclarationName::ObjCZeroArgSelector:
2998 case DeclarationName::ObjCOneArgSelector:
2999 case DeclarationName::ObjCMultiArgSelector:
3000 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003001 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003002 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003003 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003004
Douglas Gregorf816bd72009-09-03 22:13:48 +00003005 case DeclarationName::CXXConstructorName:
3006 case DeclarationName::CXXDestructorName:
3007 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003008 TypeSourceInfo *NewTInfo;
3009 CanQualType NewCanTy;
3010 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003011 NewTInfo = getDerived().TransformType(OldTInfo);
3012 if (!NewTInfo)
3013 return DeclarationNameInfo();
3014 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003015 }
3016 else {
3017 NewTInfo = 0;
3018 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003019 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003020 if (NewT.isNull())
3021 return DeclarationNameInfo();
3022 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3023 }
Mike Stump11289f42009-09-09 15:08:12 +00003024
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003025 DeclarationName NewName
3026 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3027 NewCanTy);
3028 DeclarationNameInfo NewNameInfo(NameInfo);
3029 NewNameInfo.setName(NewName);
3030 NewNameInfo.setNamedTypeInfo(NewTInfo);
3031 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003032 }
Mike Stump11289f42009-09-09 15:08:12 +00003033 }
3034
David Blaikie83d382b2011-09-23 05:06:16 +00003035 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003036}
3037
3038template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003039TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003040TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3041 TemplateName Name,
3042 SourceLocation NameLoc,
3043 QualType ObjectType,
3044 NamedDecl *FirstQualifierInScope) {
3045 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3046 TemplateDecl *Template = QTN->getTemplateDecl();
3047 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003048
Douglas Gregor9db53502011-03-02 18:07:45 +00003049 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003050 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003051 Template));
3052 if (!TransTemplate)
3053 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003054
Douglas Gregor9db53502011-03-02 18:07:45 +00003055 if (!getDerived().AlwaysRebuild() &&
3056 SS.getScopeRep() == QTN->getQualifier() &&
3057 TransTemplate == Template)
3058 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003059
Douglas Gregor9db53502011-03-02 18:07:45 +00003060 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3061 TransTemplate);
3062 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003063
Douglas Gregor9db53502011-03-02 18:07:45 +00003064 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3065 if (SS.getScopeRep()) {
3066 // These apply to the scope specifier, not the template.
3067 ObjectType = QualType();
3068 FirstQualifierInScope = 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00003069 }
3070
Douglas Gregor9db53502011-03-02 18:07:45 +00003071 if (!getDerived().AlwaysRebuild() &&
3072 SS.getScopeRep() == DTN->getQualifier() &&
3073 ObjectType.isNull())
3074 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003075
Douglas Gregor9db53502011-03-02 18:07:45 +00003076 if (DTN->isIdentifier()) {
3077 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003078 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003079 NameLoc,
3080 ObjectType,
3081 FirstQualifierInScope);
3082 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003083
Douglas Gregor9db53502011-03-02 18:07:45 +00003084 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3085 ObjectType);
3086 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003087
Douglas Gregor9db53502011-03-02 18:07:45 +00003088 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3089 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003090 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003091 Template));
3092 if (!TransTemplate)
3093 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003094
Douglas Gregor9db53502011-03-02 18:07:45 +00003095 if (!getDerived().AlwaysRebuild() &&
3096 TransTemplate == Template)
3097 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003098
Douglas Gregor9db53502011-03-02 18:07:45 +00003099 return TemplateName(TransTemplate);
3100 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003101
Douglas Gregor9db53502011-03-02 18:07:45 +00003102 if (SubstTemplateTemplateParmPackStorage *SubstPack
3103 = Name.getAsSubstTemplateTemplateParmPack()) {
3104 TemplateTemplateParmDecl *TransParam
3105 = cast_or_null<TemplateTemplateParmDecl>(
3106 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3107 if (!TransParam)
3108 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003109
Douglas Gregor9db53502011-03-02 18:07:45 +00003110 if (!getDerived().AlwaysRebuild() &&
3111 TransParam == SubstPack->getParameterPack())
3112 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003113
3114 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003115 SubstPack->getArgumentPack());
3116 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003117
Douglas Gregor9db53502011-03-02 18:07:45 +00003118 // These should be getting filtered out before they reach the AST.
3119 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003120}
3121
3122template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003123void TreeTransform<Derived>::InventTemplateArgumentLoc(
3124 const TemplateArgument &Arg,
3125 TemplateArgumentLoc &Output) {
3126 SourceLocation Loc = getDerived().getBaseLocation();
3127 switch (Arg.getKind()) {
3128 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003129 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003130 break;
3131
3132 case TemplateArgument::Type:
3133 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003134 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003135
John McCall0ad16662009-10-29 08:12:44 +00003136 break;
3137
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003138 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003139 case TemplateArgument::TemplateExpansion: {
3140 NestedNameSpecifierLocBuilder Builder;
3141 TemplateName Template = Arg.getAsTemplate();
3142 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3143 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3144 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3145 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003146
Douglas Gregor9d802122011-03-02 17:09:35 +00003147 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003148 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003149 Builder.getWithLocInContext(SemaRef.Context),
3150 Loc);
3151 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003152 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003153 Builder.getWithLocInContext(SemaRef.Context),
3154 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003155
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003156 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003157 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003158
John McCall0ad16662009-10-29 08:12:44 +00003159 case TemplateArgument::Expression:
3160 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3161 break;
3162
3163 case TemplateArgument::Declaration:
3164 case TemplateArgument::Integral:
3165 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003166 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003167 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003168 break;
3169 }
3170}
3171
3172template<typename Derived>
3173bool TreeTransform<Derived>::TransformTemplateArgument(
3174 const TemplateArgumentLoc &Input,
3175 TemplateArgumentLoc &Output) {
3176 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003177 switch (Arg.getKind()) {
3178 case TemplateArgument::Null:
3179 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003180 case TemplateArgument::Pack:
3181 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003182 case TemplateArgument::NullPtr:
3183 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003184
Douglas Gregore922c772009-08-04 22:27:00 +00003185 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003186 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00003187 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00003188 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003189
3190 DI = getDerived().TransformType(DI);
3191 if (!DI) return true;
3192
3193 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3194 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003195 }
Mike Stump11289f42009-09-09 15:08:12 +00003196
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003197 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003198 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3199 if (QualifierLoc) {
3200 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3201 if (!QualifierLoc)
3202 return true;
3203 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003204
Douglas Gregordf846d12011-03-02 18:46:51 +00003205 CXXScopeSpec SS;
3206 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003207 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003208 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3209 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003210 if (Template.isNull())
3211 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003212
Douglas Gregor9d802122011-03-02 17:09:35 +00003213 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003214 Input.getTemplateNameLoc());
3215 return false;
3216 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003217
3218 case TemplateArgument::TemplateExpansion:
3219 llvm_unreachable("Caller should expand pack expansions");
3220
Douglas Gregore922c772009-08-04 22:27:00 +00003221 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003222 // Template argument expressions are constant expressions.
Mike Stump11289f42009-09-09 15:08:12 +00003223 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smith764d2fe2011-12-20 02:08:33 +00003224 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003225
John McCall0ad16662009-10-29 08:12:44 +00003226 Expr *InputExpr = Input.getSourceExpression();
3227 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3228
Chris Lattnercdb591a2011-04-25 20:37:58 +00003229 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003230 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003231 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00003232 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00003233 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003234 }
Douglas Gregore922c772009-08-04 22:27:00 +00003235 }
Mike Stump11289f42009-09-09 15:08:12 +00003236
Douglas Gregore922c772009-08-04 22:27:00 +00003237 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003238 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003239}
3240
Douglas Gregorfe921a72010-12-20 23:36:19 +00003241/// \brief Iterator adaptor that invents template argument location information
3242/// for each of the template arguments in its underlying iterator.
3243template<typename Derived, typename InputIterator>
3244class TemplateArgumentLocInventIterator {
3245 TreeTransform<Derived> &Self;
3246 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003247
Douglas Gregorfe921a72010-12-20 23:36:19 +00003248public:
3249 typedef TemplateArgumentLoc value_type;
3250 typedef TemplateArgumentLoc reference;
3251 typedef typename std::iterator_traits<InputIterator>::difference_type
3252 difference_type;
3253 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003254
Douglas Gregorfe921a72010-12-20 23:36:19 +00003255 class pointer {
3256 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003257
Douglas Gregorfe921a72010-12-20 23:36:19 +00003258 public:
3259 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003260
Douglas Gregorfe921a72010-12-20 23:36:19 +00003261 const TemplateArgumentLoc *operator->() const { return &Arg; }
3262 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003263
Douglas Gregorfe921a72010-12-20 23:36:19 +00003264 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003265
Douglas Gregorfe921a72010-12-20 23:36:19 +00003266 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3267 InputIterator Iter)
3268 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003269
Douglas Gregorfe921a72010-12-20 23:36:19 +00003270 TemplateArgumentLocInventIterator &operator++() {
3271 ++Iter;
3272 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003273 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003274
Douglas Gregorfe921a72010-12-20 23:36:19 +00003275 TemplateArgumentLocInventIterator operator++(int) {
3276 TemplateArgumentLocInventIterator Old(*this);
3277 ++(*this);
3278 return Old;
3279 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003280
Douglas Gregorfe921a72010-12-20 23:36:19 +00003281 reference operator*() const {
3282 TemplateArgumentLoc Result;
3283 Self.InventTemplateArgumentLoc(*Iter, Result);
3284 return Result;
3285 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003286
Douglas Gregorfe921a72010-12-20 23:36:19 +00003287 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003288
Douglas Gregorfe921a72010-12-20 23:36:19 +00003289 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3290 const TemplateArgumentLocInventIterator &Y) {
3291 return X.Iter == Y.Iter;
3292 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003293
Douglas Gregorfe921a72010-12-20 23:36:19 +00003294 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3295 const TemplateArgumentLocInventIterator &Y) {
3296 return X.Iter != Y.Iter;
3297 }
3298};
Chad Rosier1dcde962012-08-08 18:46:20 +00003299
Douglas Gregor42cafa82010-12-20 17:42:22 +00003300template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003301template<typename InputIterator>
3302bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3303 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00003304 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003305 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003306 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003307 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003308
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003309 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3310 // Unpack argument packs, which we translate them into separate
3311 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003312 // FIXME: We could do much better if we could guarantee that the
3313 // TemplateArgumentLocInfo for the pack expansion would be usable for
3314 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003315 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003316 TemplateArgument::pack_iterator>
3317 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003318 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003319 In.getArgument().pack_begin()),
3320 PackLocIterator(*this,
3321 In.getArgument().pack_end()),
3322 Outputs))
3323 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003324
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003325 continue;
3326 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003327
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003328 if (In.getArgument().isPackExpansion()) {
3329 // We have a pack expansion, for which we will be substituting into
3330 // the pattern.
3331 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003332 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003333 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003334 = getSema().getTemplateArgumentPackExpansionPattern(
3335 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003336
Chris Lattner01cf8db2011-07-20 06:58:45 +00003337 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003338 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3339 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003340
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003341 // Determine whether the set of unexpanded parameter packs can and should
3342 // be expanded.
3343 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003344 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003345 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003346 if (getDerived().TryExpandParameterPacks(Ellipsis,
3347 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003348 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003349 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003350 RetainExpansion,
3351 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003352 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003353
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003354 if (!Expand) {
3355 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003356 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003357 // expansion.
3358 TemplateArgumentLoc OutPattern;
3359 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3360 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3361 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003362
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003363 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3364 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003365 if (Out.getArgument().isNull())
3366 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003367
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003368 Outputs.addArgument(Out);
3369 continue;
3370 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003371
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003372 // The transform has determined that we should perform an elementwise
3373 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003374 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003375 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3376
3377 if (getDerived().TransformTemplateArgument(Pattern, Out))
3378 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003379
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003380 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003381 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3382 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003383 if (Out.getArgument().isNull())
3384 return true;
3385 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003386
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003387 Outputs.addArgument(Out);
3388 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003389
Douglas Gregor48d24112011-01-10 20:53:55 +00003390 // If we're supposed to retain a pack expansion, do so by temporarily
3391 // forgetting the partially-substituted parameter pack.
3392 if (RetainExpansion) {
3393 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003394
Douglas Gregor48d24112011-01-10 20:53:55 +00003395 if (getDerived().TransformTemplateArgument(Pattern, Out))
3396 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003397
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003398 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3399 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003400 if (Out.getArgument().isNull())
3401 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003402
Douglas Gregor48d24112011-01-10 20:53:55 +00003403 Outputs.addArgument(Out);
3404 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003405
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003406 continue;
3407 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003408
3409 // The simple case:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003410 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003411 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003412
Douglas Gregor42cafa82010-12-20 17:42:22 +00003413 Outputs.addArgument(Out);
3414 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003415
Douglas Gregor42cafa82010-12-20 17:42:22 +00003416 return false;
3417
3418}
3419
Douglas Gregord6ff3322009-08-04 16:50:30 +00003420//===----------------------------------------------------------------------===//
3421// Type transformation
3422//===----------------------------------------------------------------------===//
3423
3424template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003425QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003426 if (getDerived().AlreadyTransformed(T))
3427 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003428
John McCall550e0c22009-10-21 00:40:46 +00003429 // Temporary workaround. All of these transformations should
3430 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003431 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3432 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003433
John McCall31f82722010-11-12 08:19:04 +00003434 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003435
John McCall550e0c22009-10-21 00:40:46 +00003436 if (!NewDI)
3437 return QualType();
3438
3439 return NewDI->getType();
3440}
3441
3442template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003443TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003444 // Refine the base location to the type's location.
3445 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3446 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003447 if (getDerived().AlreadyTransformed(DI->getType()))
3448 return DI;
3449
3450 TypeLocBuilder TLB;
3451
3452 TypeLoc TL = DI->getTypeLoc();
3453 TLB.reserve(TL.getFullDataSize());
3454
John McCall31f82722010-11-12 08:19:04 +00003455 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003456 if (Result.isNull())
3457 return 0;
3458
John McCallbcd03502009-12-07 02:54:59 +00003459 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003460}
3461
3462template<typename Derived>
3463QualType
John McCall31f82722010-11-12 08:19:04 +00003464TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003465 switch (T.getTypeLocClass()) {
3466#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003467#define TYPELOC(CLASS, PARENT) \
3468 case TypeLoc::CLASS: \
3469 return getDerived().Transform##CLASS##Type(TLB, \
3470 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003471#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003472 }
Mike Stump11289f42009-09-09 15:08:12 +00003473
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003474 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003475}
3476
3477/// FIXME: By default, this routine adds type qualifiers only to types
3478/// that can have qualifiers, and silently suppresses those qualifiers
3479/// that are not permitted (e.g., qualifiers on reference or function
3480/// types). This is the right thing for template instantiation, but
3481/// probably not for other clients.
3482template<typename Derived>
3483QualType
3484TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003485 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003486 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003487
John McCall31f82722010-11-12 08:19:04 +00003488 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003489 if (Result.isNull())
3490 return QualType();
3491
3492 // Silently suppress qualifiers if the result type can't be qualified.
3493 // FIXME: this is the right thing for template instantiation, but
3494 // probably not for other clients.
3495 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003496 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003497
John McCall31168b02011-06-15 23:02:42 +00003498 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003499 // resulting type.
3500 if (Quals.hasObjCLifetime()) {
3501 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3502 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003503 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003504 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003505 // A lifetime qualifier applied to a substituted template parameter
3506 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003507 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003508 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003509 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3510 QualType Replacement = SubstTypeParam->getReplacementType();
3511 Qualifiers Qs = Replacement.getQualifiers();
3512 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003513 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003514 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3515 Qs);
3516 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003517 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003518 Replacement);
3519 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003520 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3521 // 'auto' types behave the same way as template parameters.
3522 QualType Deduced = AutoTy->getDeducedType();
3523 Qualifiers Qs = Deduced.getQualifiers();
3524 Qs.removeObjCLifetime();
3525 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3526 Qs);
Faisal Vali2b391ab2013-09-26 19:54:12 +00003527 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3528 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003529 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003530 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003531 // Otherwise, complain about the addition of a qualifier to an
3532 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003533 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003534 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003535 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003536
Douglas Gregore46db902011-06-17 22:11:49 +00003537 Quals.removeObjCLifetime();
3538 }
3539 }
3540 }
John McCallcb0f89a2010-06-05 06:41:15 +00003541 if (!Quals.empty()) {
3542 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003543 // BuildQualifiedType might not add qualifiers if they are invalid.
3544 if (Result.hasLocalQualifiers())
3545 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003546 // No location information to preserve.
3547 }
John McCall550e0c22009-10-21 00:40:46 +00003548
3549 return Result;
3550}
3551
Douglas Gregor14454802011-02-25 02:25:35 +00003552template<typename Derived>
3553TypeLoc
3554TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3555 QualType ObjectType,
3556 NamedDecl *UnqualLookup,
3557 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003558 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00003559 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00003560
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003561 TypeSourceInfo *TSI =
3562 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3563 if (TSI)
3564 return TSI->getTypeLoc();
3565 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00003566}
3567
Douglas Gregor579c15f2011-03-02 18:32:08 +00003568template<typename Derived>
3569TypeSourceInfo *
3570TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3571 QualType ObjectType,
3572 NamedDecl *UnqualLookup,
3573 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003574 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00003575 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00003576
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003577 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
3578 UnqualLookup, SS);
3579}
3580
3581template <typename Derived>
3582TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
3583 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
3584 CXXScopeSpec &SS) {
3585 QualType T = TL.getType();
3586 assert(!getDerived().AlreadyTransformed(T));
3587
Douglas Gregor579c15f2011-03-02 18:32:08 +00003588 TypeLocBuilder TLB;
3589 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00003590
Douglas Gregor579c15f2011-03-02 18:32:08 +00003591 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003592 TemplateSpecializationTypeLoc SpecTL =
3593 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003594
Douglas Gregor579c15f2011-03-02 18:32:08 +00003595 TemplateName Template
3596 = getDerived().TransformTemplateName(SS,
3597 SpecTL.getTypePtr()->getTemplateName(),
3598 SpecTL.getTemplateNameLoc(),
3599 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00003600 if (Template.isNull())
Douglas Gregor579c15f2011-03-02 18:32:08 +00003601 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00003602
3603 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003604 Template);
3605 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003606 DependentTemplateSpecializationTypeLoc SpecTL =
3607 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003608
Douglas Gregor579c15f2011-03-02 18:32:08 +00003609 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00003610 = getDerived().RebuildTemplateName(SS,
3611 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00003612 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00003613 ObjectType, UnqualLookup);
3614 if (Template.isNull())
3615 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00003616
3617 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003618 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003619 Template,
3620 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003621 } else {
3622 // Nothing special needs to be done for these.
3623 Result = getDerived().TransformType(TLB, TL);
3624 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003625
3626 if (Result.isNull())
Douglas Gregor579c15f2011-03-02 18:32:08 +00003627 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00003628
Douglas Gregor579c15f2011-03-02 18:32:08 +00003629 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3630}
3631
John McCall550e0c22009-10-21 00:40:46 +00003632template <class TyLoc> static inline
3633QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3634 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3635 NewT.setNameLoc(T.getNameLoc());
3636 return T.getType();
3637}
3638
John McCall550e0c22009-10-21 00:40:46 +00003639template<typename Derived>
3640QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003641 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003642 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3643 NewT.setBuiltinLoc(T.getBuiltinLoc());
3644 if (T.needsExtraLocalData())
3645 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3646 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003647}
Mike Stump11289f42009-09-09 15:08:12 +00003648
Douglas Gregord6ff3322009-08-04 16:50:30 +00003649template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003650QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003651 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003652 // FIXME: recurse?
3653 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003654}
Mike Stump11289f42009-09-09 15:08:12 +00003655
Reid Kleckner0503a872013-12-05 01:23:43 +00003656template <typename Derived>
3657QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
3658 AdjustedTypeLoc TL) {
3659 // Adjustments applied during transformation are handled elsewhere.
3660 return getDerived().TransformType(TLB, TL.getOriginalLoc());
3661}
3662
Douglas Gregord6ff3322009-08-04 16:50:30 +00003663template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00003664QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3665 DecayedTypeLoc TL) {
3666 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3667 if (OriginalType.isNull())
3668 return QualType();
3669
3670 QualType Result = TL.getType();
3671 if (getDerived().AlwaysRebuild() ||
3672 OriginalType != TL.getOriginalLoc().getType())
3673 Result = SemaRef.Context.getDecayedType(OriginalType);
3674 TLB.push<DecayedTypeLoc>(Result);
3675 // Nothing to set for DecayedTypeLoc.
3676 return Result;
3677}
3678
3679template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003680QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003681 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003682 QualType PointeeType
3683 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003684 if (PointeeType.isNull())
3685 return QualType();
3686
3687 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003688 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003689 // A dependent pointer type 'T *' has is being transformed such
3690 // that an Objective-C class type is being replaced for 'T'. The
3691 // resulting pointer type is an ObjCObjectPointerType, not a
3692 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003693 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00003694
John McCall8b07ec22010-05-15 11:32:37 +00003695 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3696 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003697 return Result;
3698 }
John McCall31f82722010-11-12 08:19:04 +00003699
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003700 if (getDerived().AlwaysRebuild() ||
3701 PointeeType != TL.getPointeeLoc().getType()) {
3702 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3703 if (Result.isNull())
3704 return QualType();
3705 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003706
John McCall31168b02011-06-15 23:02:42 +00003707 // Objective-C ARC can add lifetime qualifiers to the type that we're
3708 // pointing to.
3709 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00003710
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003711 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3712 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00003713 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003714}
Mike Stump11289f42009-09-09 15:08:12 +00003715
3716template<typename Derived>
3717QualType
John McCall550e0c22009-10-21 00:40:46 +00003718TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003719 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003720 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00003721 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3722 if (PointeeType.isNull())
3723 return QualType();
3724
3725 QualType Result = TL.getType();
3726 if (getDerived().AlwaysRebuild() ||
3727 PointeeType != TL.getPointeeLoc().getType()) {
3728 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003729 TL.getSigilLoc());
3730 if (Result.isNull())
3731 return QualType();
3732 }
3733
Douglas Gregor049211a2010-04-22 16:50:51 +00003734 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003735 NewT.setSigilLoc(TL.getSigilLoc());
3736 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003737}
3738
John McCall70dd5f62009-10-30 00:06:24 +00003739/// Transforms a reference type. Note that somewhat paradoxically we
3740/// don't care whether the type itself is an l-value type or an r-value
3741/// type; we only care if the type was *written* as an l-value type
3742/// or an r-value type.
3743template<typename Derived>
3744QualType
3745TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003746 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003747 const ReferenceType *T = TL.getTypePtr();
3748
3749 // Note that this works with the pointee-as-written.
3750 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3751 if (PointeeType.isNull())
3752 return QualType();
3753
3754 QualType Result = TL.getType();
3755 if (getDerived().AlwaysRebuild() ||
3756 PointeeType != T->getPointeeTypeAsWritten()) {
3757 Result = getDerived().RebuildReferenceType(PointeeType,
3758 T->isSpelledAsLValue(),
3759 TL.getSigilLoc());
3760 if (Result.isNull())
3761 return QualType();
3762 }
3763
John McCall31168b02011-06-15 23:02:42 +00003764 // Objective-C ARC can add lifetime qualifiers to the type that we're
3765 // referring to.
3766 TLB.TypeWasModifiedSafely(
3767 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3768
John McCall70dd5f62009-10-30 00:06:24 +00003769 // r-value references can be rebuilt as l-value references.
3770 ReferenceTypeLoc NewTL;
3771 if (isa<LValueReferenceType>(Result))
3772 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3773 else
3774 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3775 NewTL.setSigilLoc(TL.getSigilLoc());
3776
3777 return Result;
3778}
3779
Mike Stump11289f42009-09-09 15:08:12 +00003780template<typename Derived>
3781QualType
John McCall550e0c22009-10-21 00:40:46 +00003782TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003783 LValueReferenceTypeLoc TL) {
3784 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003785}
3786
Mike Stump11289f42009-09-09 15:08:12 +00003787template<typename Derived>
3788QualType
John McCall550e0c22009-10-21 00:40:46 +00003789TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003790 RValueReferenceTypeLoc TL) {
3791 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003792}
Mike Stump11289f42009-09-09 15:08:12 +00003793
Douglas Gregord6ff3322009-08-04 16:50:30 +00003794template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003795QualType
John McCall550e0c22009-10-21 00:40:46 +00003796TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003797 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003798 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003799 if (PointeeType.isNull())
3800 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003801
Abramo Bagnara509357842011-03-05 14:42:21 +00003802 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3803 TypeSourceInfo* NewClsTInfo = 0;
3804 if (OldClsTInfo) {
3805 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3806 if (!NewClsTInfo)
3807 return QualType();
3808 }
3809
3810 const MemberPointerType *T = TL.getTypePtr();
3811 QualType OldClsType = QualType(T->getClass(), 0);
3812 QualType NewClsType;
3813 if (NewClsTInfo)
3814 NewClsType = NewClsTInfo->getType();
3815 else {
3816 NewClsType = getDerived().TransformType(OldClsType);
3817 if (NewClsType.isNull())
3818 return QualType();
3819 }
Mike Stump11289f42009-09-09 15:08:12 +00003820
John McCall550e0c22009-10-21 00:40:46 +00003821 QualType Result = TL.getType();
3822 if (getDerived().AlwaysRebuild() ||
3823 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00003824 NewClsType != OldClsType) {
3825 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00003826 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003827 if (Result.isNull())
3828 return QualType();
3829 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003830
Reid Kleckner0503a872013-12-05 01:23:43 +00003831 // If we had to adjust the pointee type when building a member pointer, make
3832 // sure to push TypeLoc info for it.
3833 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
3834 if (MPT && PointeeType != MPT->getPointeeType()) {
3835 assert(isa<AdjustedType>(MPT->getPointeeType()));
3836 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
3837 }
3838
John McCall550e0c22009-10-21 00:40:46 +00003839 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3840 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00003841 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00003842
3843 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003844}
3845
Mike Stump11289f42009-09-09 15:08:12 +00003846template<typename Derived>
3847QualType
John McCall550e0c22009-10-21 00:40:46 +00003848TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003849 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003850 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003851 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003852 if (ElementType.isNull())
3853 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003854
John McCall550e0c22009-10-21 00:40:46 +00003855 QualType Result = TL.getType();
3856 if (getDerived().AlwaysRebuild() ||
3857 ElementType != T->getElementType()) {
3858 Result = getDerived().RebuildConstantArrayType(ElementType,
3859 T->getSizeModifier(),
3860 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003861 T->getIndexTypeCVRQualifiers(),
3862 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003863 if (Result.isNull())
3864 return QualType();
3865 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00003866
3867 // We might have either a ConstantArrayType or a VariableArrayType now:
3868 // a ConstantArrayType is allowed to have an element type which is a
3869 // VariableArrayType if the type is dependent. Fortunately, all array
3870 // types have the same location layout.
3871 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00003872 NewTL.setLBracketLoc(TL.getLBracketLoc());
3873 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003874
John McCall550e0c22009-10-21 00:40:46 +00003875 Expr *Size = TL.getSizeExpr();
3876 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003877 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3878 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00003879 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanc6237c62012-02-29 03:16:56 +00003880 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCall550e0c22009-10-21 00:40:46 +00003881 }
3882 NewTL.setSizeExpr(Size);
3883
3884 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003885}
Mike Stump11289f42009-09-09 15:08:12 +00003886
Douglas Gregord6ff3322009-08-04 16:50:30 +00003887template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003888QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003889 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003890 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003891 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003892 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003893 if (ElementType.isNull())
3894 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003895
John McCall550e0c22009-10-21 00:40:46 +00003896 QualType Result = TL.getType();
3897 if (getDerived().AlwaysRebuild() ||
3898 ElementType != T->getElementType()) {
3899 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003900 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003901 T->getIndexTypeCVRQualifiers(),
3902 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003903 if (Result.isNull())
3904 return QualType();
3905 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003906
John McCall550e0c22009-10-21 00:40:46 +00003907 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3908 NewTL.setLBracketLoc(TL.getLBracketLoc());
3909 NewTL.setRBracketLoc(TL.getRBracketLoc());
3910 NewTL.setSizeExpr(0);
3911
3912 return Result;
3913}
3914
3915template<typename Derived>
3916QualType
3917TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003918 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003919 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003920 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3921 if (ElementType.isNull())
3922 return QualType();
3923
John McCalldadc5752010-08-24 06:29:42 +00003924 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003925 = getDerived().TransformExpr(T->getSizeExpr());
3926 if (SizeResult.isInvalid())
3927 return QualType();
3928
John McCallb268a282010-08-23 23:25:46 +00003929 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003930
3931 QualType Result = TL.getType();
3932 if (getDerived().AlwaysRebuild() ||
3933 ElementType != T->getElementType() ||
3934 Size != T->getSizeExpr()) {
3935 Result = getDerived().RebuildVariableArrayType(ElementType,
3936 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003937 Size,
John McCall550e0c22009-10-21 00:40:46 +00003938 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003939 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003940 if (Result.isNull())
3941 return QualType();
3942 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003943
Serge Pavlov774c6d02014-02-06 03:49:11 +00003944 // We might have constant size array now, but fortunately it has the same
3945 // location layout.
3946 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00003947 NewTL.setLBracketLoc(TL.getLBracketLoc());
3948 NewTL.setRBracketLoc(TL.getRBracketLoc());
3949 NewTL.setSizeExpr(Size);
3950
3951 return Result;
3952}
3953
3954template<typename Derived>
3955QualType
3956TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003957 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003958 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003959 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3960 if (ElementType.isNull())
3961 return QualType();
3962
Richard Smith764d2fe2011-12-20 02:08:33 +00003963 // Array bounds are constant expressions.
3964 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3965 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00003966
John McCall33ddac02011-01-19 10:06:00 +00003967 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3968 Expr *origSize = TL.getSizeExpr();
3969 if (!origSize) origSize = T->getSizeExpr();
3970
3971 ExprResult sizeResult
3972 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003973 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00003974 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00003975 return QualType();
3976
John McCall33ddac02011-01-19 10:06:00 +00003977 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00003978
3979 QualType Result = TL.getType();
3980 if (getDerived().AlwaysRebuild() ||
3981 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00003982 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00003983 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3984 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00003985 size,
John McCall550e0c22009-10-21 00:40:46 +00003986 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003987 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003988 if (Result.isNull())
3989 return QualType();
3990 }
John McCall550e0c22009-10-21 00:40:46 +00003991
3992 // We might have any sort of array type now, but fortunately they
3993 // all have the same location layout.
3994 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3995 NewTL.setLBracketLoc(TL.getLBracketLoc());
3996 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00003997 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00003998
3999 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004000}
Mike Stump11289f42009-09-09 15:08:12 +00004001
4002template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004003QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004004 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004005 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004006 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004007
4008 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004009 QualType ElementType = getDerived().TransformType(T->getElementType());
4010 if (ElementType.isNull())
4011 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004012
Richard Smith764d2fe2011-12-20 02:08:33 +00004013 // Vector sizes are constant expressions.
4014 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4015 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004016
John McCalldadc5752010-08-24 06:29:42 +00004017 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004018 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004019 if (Size.isInvalid())
4020 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004021
John McCall550e0c22009-10-21 00:40:46 +00004022 QualType Result = TL.getType();
4023 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004024 ElementType != T->getElementType() ||
4025 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004026 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00004027 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004028 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004029 if (Result.isNull())
4030 return QualType();
4031 }
John McCall550e0c22009-10-21 00:40:46 +00004032
4033 // Result might be dependent or not.
4034 if (isa<DependentSizedExtVectorType>(Result)) {
4035 DependentSizedExtVectorTypeLoc NewTL
4036 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4037 NewTL.setNameLoc(TL.getNameLoc());
4038 } else {
4039 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4040 NewTL.setNameLoc(TL.getNameLoc());
4041 }
4042
4043 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004044}
Mike Stump11289f42009-09-09 15:08:12 +00004045
4046template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004047QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004048 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004049 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004050 QualType ElementType = getDerived().TransformType(T->getElementType());
4051 if (ElementType.isNull())
4052 return QualType();
4053
John McCall550e0c22009-10-21 00:40:46 +00004054 QualType Result = TL.getType();
4055 if (getDerived().AlwaysRebuild() ||
4056 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004057 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004058 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004059 if (Result.isNull())
4060 return QualType();
4061 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004062
John McCall550e0c22009-10-21 00:40:46 +00004063 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4064 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004065
John McCall550e0c22009-10-21 00:40:46 +00004066 return Result;
4067}
4068
4069template<typename Derived>
4070QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004071 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004072 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004073 QualType ElementType = getDerived().TransformType(T->getElementType());
4074 if (ElementType.isNull())
4075 return QualType();
4076
4077 QualType Result = TL.getType();
4078 if (getDerived().AlwaysRebuild() ||
4079 ElementType != T->getElementType()) {
4080 Result = getDerived().RebuildExtVectorType(ElementType,
4081 T->getNumElements(),
4082 /*FIXME*/ SourceLocation());
4083 if (Result.isNull())
4084 return QualType();
4085 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004086
John McCall550e0c22009-10-21 00:40:46 +00004087 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4088 NewTL.setNameLoc(TL.getNameLoc());
4089
4090 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004091}
Mike Stump11289f42009-09-09 15:08:12 +00004092
David Blaikie05785d12013-02-20 22:23:23 +00004093template <typename Derived>
4094ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4095 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4096 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004097 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor715e4612011-01-14 22:40:04 +00004098 TypeSourceInfo *NewDI = 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00004099
Douglas Gregor715e4612011-01-14 22:40:04 +00004100 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004101 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004102 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004103 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004104 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004105
Douglas Gregor715e4612011-01-14 22:40:04 +00004106 TypeLocBuilder TLB;
4107 TypeLoc NewTL = OldDI->getTypeLoc();
4108 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004109
4110 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004111 OldExpansionTL.getPatternLoc());
4112 if (Result.isNull())
4113 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00004114
4115 Result = RebuildPackExpansionType(Result,
4116 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004117 OldExpansionTL.getEllipsisLoc(),
4118 NumExpansions);
4119 if (Result.isNull())
4120 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00004121
Douglas Gregor715e4612011-01-14 22:40:04 +00004122 PackExpansionTypeLoc NewExpansionTL
4123 = TLB.push<PackExpansionTypeLoc>(Result);
4124 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4125 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4126 } else
4127 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004128 if (!NewDI)
4129 return 0;
4130
John McCall8fb0d9d2011-05-01 22:35:37 +00004131 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004132 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004133
4134 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4135 OldParm->getDeclContext(),
4136 OldParm->getInnerLocStart(),
4137 OldParm->getLocation(),
4138 OldParm->getIdentifier(),
4139 NewDI->getType(),
4140 NewDI,
4141 OldParm->getStorageClass(),
John McCall8fb0d9d2011-05-01 22:35:37 +00004142 /* DefArg */ NULL);
4143 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4144 OldParm->getFunctionScopeIndex() + indexAdjustment);
4145 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004146}
4147
4148template<typename Derived>
4149bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004150 TransformFunctionTypeParams(SourceLocation Loc,
4151 ParmVarDecl **Params, unsigned NumParams,
4152 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004153 SmallVectorImpl<QualType> &OutParamTypes,
4154 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004155 int indexAdjustment = 0;
4156
Douglas Gregordd472162011-01-07 00:20:55 +00004157 for (unsigned i = 0; i != NumParams; ++i) {
4158 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004159 assert(OldParm->getFunctionScopeIndex() == i);
4160
David Blaikie05785d12013-02-20 22:23:23 +00004161 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004162 ParmVarDecl *NewParm = 0;
Douglas Gregor5499af42011-01-05 23:12:31 +00004163 if (OldParm->isParameterPack()) {
4164 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004165 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004166
Douglas Gregor5499af42011-01-05 23:12:31 +00004167 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004168 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004169 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004170 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4171 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004172 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4173
Douglas Gregor5499af42011-01-05 23:12:31 +00004174 // Determine whether we should expand the parameter packs.
4175 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004176 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004177 Optional<unsigned> OrigNumExpansions =
4178 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004179 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004180 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4181 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004182 Unexpanded,
4183 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004184 RetainExpansion,
4185 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004186 return true;
4187 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004188
Douglas Gregor5499af42011-01-05 23:12:31 +00004189 if (ShouldExpand) {
4190 // Expand the function parameter pack into multiple, separate
4191 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004192 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004193 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004194 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004195 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004196 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004197 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004198 OrigNumExpansions,
4199 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004200 if (!NewParm)
4201 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004202
Douglas Gregordd472162011-01-07 00:20:55 +00004203 OutParamTypes.push_back(NewParm->getType());
4204 if (PVars)
4205 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004206 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004207
4208 // If we're supposed to retain a pack expansion, do so by temporarily
4209 // forgetting the partially-substituted parameter pack.
4210 if (RetainExpansion) {
4211 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004212 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004213 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004214 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004215 OrigNumExpansions,
4216 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004217 if (!NewParm)
4218 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004219
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004220 OutParamTypes.push_back(NewParm->getType());
4221 if (PVars)
4222 PVars->push_back(NewParm);
4223 }
4224
John McCall8fb0d9d2011-05-01 22:35:37 +00004225 // The next parameter should have the same adjustment as the
4226 // last thing we pushed, but we post-incremented indexAdjustment
4227 // on every push. Also, if we push nothing, the adjustment should
4228 // go down by one.
4229 indexAdjustment--;
4230
Douglas Gregor5499af42011-01-05 23:12:31 +00004231 // We're done with the pack expansion.
4232 continue;
4233 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004234
4235 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004236 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004237 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4238 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004239 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004240 NumExpansions,
4241 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004242 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004243 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004244 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004245 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004246
John McCall58f10c32010-03-11 09:03:00 +00004247 if (!NewParm)
4248 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004249
Douglas Gregordd472162011-01-07 00:20:55 +00004250 OutParamTypes.push_back(NewParm->getType());
4251 if (PVars)
4252 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004253 continue;
4254 }
John McCall58f10c32010-03-11 09:03:00 +00004255
4256 // Deal with the possibility that we don't have a parameter
4257 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004258 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004259 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004260 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004261 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004262 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004263 = dyn_cast<PackExpansionType>(OldType)) {
4264 // We have a function parameter pack that may need to be expanded.
4265 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004266 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004267 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004268
Douglas Gregor5499af42011-01-05 23:12:31 +00004269 // Determine whether we should expand the parameter packs.
4270 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004271 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004272 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004273 Unexpanded,
4274 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004275 RetainExpansion,
4276 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004277 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004278 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004279
Douglas Gregor5499af42011-01-05 23:12:31 +00004280 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004281 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004282 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004283 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004284 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4285 QualType NewType = getDerived().TransformType(Pattern);
4286 if (NewType.isNull())
4287 return true;
John McCall58f10c32010-03-11 09:03:00 +00004288
Douglas Gregordd472162011-01-07 00:20:55 +00004289 OutParamTypes.push_back(NewType);
4290 if (PVars)
4291 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00004292 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004293
Douglas Gregor5499af42011-01-05 23:12:31 +00004294 // We're done with the pack expansion.
4295 continue;
4296 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004297
Douglas Gregor48d24112011-01-10 20:53:55 +00004298 // If we're supposed to retain a pack expansion, do so by temporarily
4299 // forgetting the partially-substituted parameter pack.
4300 if (RetainExpansion) {
4301 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4302 QualType NewType = getDerived().TransformType(Pattern);
4303 if (NewType.isNull())
4304 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004305
Douglas Gregor48d24112011-01-10 20:53:55 +00004306 OutParamTypes.push_back(NewType);
4307 if (PVars)
4308 PVars->push_back(0);
4309 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004310
Chad Rosier1dcde962012-08-08 18:46:20 +00004311 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004312 // expansion.
4313 OldType = Expansion->getPattern();
4314 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004315 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4316 NewType = getDerived().TransformType(OldType);
4317 } else {
4318 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004319 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004320
Douglas Gregor5499af42011-01-05 23:12:31 +00004321 if (NewType.isNull())
4322 return true;
4323
4324 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004325 NewType = getSema().Context.getPackExpansionType(NewType,
4326 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004327
Douglas Gregordd472162011-01-07 00:20:55 +00004328 OutParamTypes.push_back(NewType);
4329 if (PVars)
4330 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00004331 }
4332
John McCall8fb0d9d2011-05-01 22:35:37 +00004333#ifndef NDEBUG
4334 if (PVars) {
4335 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4336 if (ParmVarDecl *parm = (*PVars)[i])
4337 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004338 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004339#endif
4340
4341 return false;
4342}
John McCall58f10c32010-03-11 09:03:00 +00004343
4344template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004345QualType
John McCall550e0c22009-10-21 00:40:46 +00004346TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004347 FunctionProtoTypeLoc TL) {
Douglas Gregor3024f072012-04-16 07:05:22 +00004348 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4349}
4350
4351template<typename Derived>
4352QualType
4353TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4354 FunctionProtoTypeLoc TL,
4355 CXXRecordDecl *ThisContext,
4356 unsigned ThisTypeQuals) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004357 // Transform the parameters and return type.
4358 //
Richard Smithf623c962012-04-17 00:58:00 +00004359 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004360 // When the function has a trailing return type, we instantiate the
4361 // parameters before the return type, since the return type can then refer
4362 // to the parameters themselves (via decltype, sizeof, etc.).
4363 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004364 SmallVector<QualType, 4> ParamTypes;
4365 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004366 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004367
Douglas Gregor7fb25412010-10-01 18:44:50 +00004368 QualType ResultType;
4369
Richard Smith1226c602012-08-14 22:51:13 +00004370 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004371 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004372 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004373 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004374 return QualType();
4375
Douglas Gregor3024f072012-04-16 07:05:22 +00004376 {
4377 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004378 // If a declaration declares a member function or member function
4379 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004380 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004381 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004382 // declarator.
4383 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004384
Alp Toker42a16a62014-01-25 23:51:36 +00004385 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004386 if (ResultType.isNull())
4387 return QualType();
4388 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004389 }
4390 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004391 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004392 if (ResultType.isNull())
4393 return QualType();
4394
Alp Toker9cacbab2014-01-20 20:26:09 +00004395 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004396 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004397 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004398 return QualType();
4399 }
4400
Richard Smithf623c962012-04-17 00:58:00 +00004401 // FIXME: Need to transform the exception-specification too.
4402
John McCall550e0c22009-10-21 00:40:46 +00004403 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004404 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Alp Toker9cacbab2014-01-20 20:26:09 +00004405 T->getNumParams() != ParamTypes.size() ||
4406 !std::equal(T->param_type_begin(), T->param_type_end(),
4407 ParamTypes.begin())) {
Jordan Rose5c382722013-03-08 21:51:21 +00004408 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00004409 T->getExtProtoInfo());
John McCall550e0c22009-10-21 00:40:46 +00004410 if (Result.isNull())
4411 return QualType();
4412 }
Mike Stump11289f42009-09-09 15:08:12 +00004413
John McCall550e0c22009-10-21 00:40:46 +00004414 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004415 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004416 NewTL.setLParenLoc(TL.getLParenLoc());
4417 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004418 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004419 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4420 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004421
4422 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004423}
Mike Stump11289f42009-09-09 15:08:12 +00004424
Douglas Gregord6ff3322009-08-04 16:50:30 +00004425template<typename Derived>
4426QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004427 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004428 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004429 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00004430 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00004431 if (ResultType.isNull())
4432 return QualType();
4433
4434 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004435 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00004436 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4437
4438 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004439 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004440 NewTL.setLParenLoc(TL.getLParenLoc());
4441 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004442 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004443
4444 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004445}
Mike Stump11289f42009-09-09 15:08:12 +00004446
John McCallb96ec562009-12-04 22:46:56 +00004447template<typename Derived> QualType
4448TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004449 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004450 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004451 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004452 if (!D)
4453 return QualType();
4454
4455 QualType Result = TL.getType();
4456 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4457 Result = getDerived().RebuildUnresolvedUsingType(D);
4458 if (Result.isNull())
4459 return QualType();
4460 }
4461
4462 // We might get an arbitrary type spec type back. We should at
4463 // least always get a type spec type, though.
4464 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4465 NewTL.setNameLoc(TL.getNameLoc());
4466
4467 return Result;
4468}
4469
Douglas Gregord6ff3322009-08-04 16:50:30 +00004470template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004471QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004472 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004473 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004474 TypedefNameDecl *Typedef
4475 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4476 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004477 if (!Typedef)
4478 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004479
John McCall550e0c22009-10-21 00:40:46 +00004480 QualType Result = TL.getType();
4481 if (getDerived().AlwaysRebuild() ||
4482 Typedef != T->getDecl()) {
4483 Result = getDerived().RebuildTypedefType(Typedef);
4484 if (Result.isNull())
4485 return QualType();
4486 }
Mike Stump11289f42009-09-09 15:08:12 +00004487
John McCall550e0c22009-10-21 00:40:46 +00004488 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4489 NewTL.setNameLoc(TL.getNameLoc());
4490
4491 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004492}
Mike Stump11289f42009-09-09 15:08:12 +00004493
Douglas Gregord6ff3322009-08-04 16:50:30 +00004494template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004495QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004496 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004497 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00004498 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4499 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00004500
John McCalldadc5752010-08-24 06:29:42 +00004501 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004502 if (E.isInvalid())
4503 return QualType();
4504
Eli Friedmane4f22df2012-02-29 04:03:55 +00004505 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4506 if (E.isInvalid())
4507 return QualType();
4508
John McCall550e0c22009-10-21 00:40:46 +00004509 QualType Result = TL.getType();
4510 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004511 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004512 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004513 if (Result.isNull())
4514 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004515 }
John McCall550e0c22009-10-21 00:40:46 +00004516 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004517
John McCall550e0c22009-10-21 00:40:46 +00004518 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004519 NewTL.setTypeofLoc(TL.getTypeofLoc());
4520 NewTL.setLParenLoc(TL.getLParenLoc());
4521 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004522
4523 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004524}
Mike Stump11289f42009-09-09 15:08:12 +00004525
4526template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004527QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004528 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004529 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4530 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4531 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004532 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004533
John McCall550e0c22009-10-21 00:40:46 +00004534 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004535 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4536 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004537 if (Result.isNull())
4538 return QualType();
4539 }
Mike Stump11289f42009-09-09 15:08:12 +00004540
John McCall550e0c22009-10-21 00:40:46 +00004541 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004542 NewTL.setTypeofLoc(TL.getTypeofLoc());
4543 NewTL.setLParenLoc(TL.getLParenLoc());
4544 NewTL.setRParenLoc(TL.getRParenLoc());
4545 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004546
4547 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004548}
Mike Stump11289f42009-09-09 15:08:12 +00004549
4550template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004551QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004552 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004553 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004554
Douglas Gregore922c772009-08-04 22:27:00 +00004555 // decltype expressions are not potentially evaluated contexts
Richard Smithfd555f62012-02-22 02:04:18 +00004556 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4557 /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00004558
John McCalldadc5752010-08-24 06:29:42 +00004559 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004560 if (E.isInvalid())
4561 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004562
Richard Smithfd555f62012-02-22 02:04:18 +00004563 E = getSema().ActOnDecltypeExpression(E.take());
4564 if (E.isInvalid())
4565 return QualType();
4566
John McCall550e0c22009-10-21 00:40:46 +00004567 QualType Result = TL.getType();
4568 if (getDerived().AlwaysRebuild() ||
4569 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004570 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004571 if (Result.isNull())
4572 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004573 }
John McCall550e0c22009-10-21 00:40:46 +00004574 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004575
John McCall550e0c22009-10-21 00:40:46 +00004576 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4577 NewTL.setNameLoc(TL.getNameLoc());
4578
4579 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004580}
4581
4582template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004583QualType TreeTransform<Derived>::TransformUnaryTransformType(
4584 TypeLocBuilder &TLB,
4585 UnaryTransformTypeLoc TL) {
4586 QualType Result = TL.getType();
4587 if (Result->isDependentType()) {
4588 const UnaryTransformType *T = TL.getTypePtr();
4589 QualType NewBase =
4590 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4591 Result = getDerived().RebuildUnaryTransformType(NewBase,
4592 T->getUTTKind(),
4593 TL.getKWLoc());
4594 if (Result.isNull())
4595 return QualType();
4596 }
4597
4598 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4599 NewTL.setKWLoc(TL.getKWLoc());
4600 NewTL.setParensRange(TL.getParensRange());
4601 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4602 return Result;
4603}
4604
4605template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004606QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4607 AutoTypeLoc TL) {
4608 const AutoType *T = TL.getTypePtr();
4609 QualType OldDeduced = T->getDeducedType();
4610 QualType NewDeduced;
4611 if (!OldDeduced.isNull()) {
4612 NewDeduced = getDerived().TransformType(OldDeduced);
4613 if (NewDeduced.isNull())
4614 return QualType();
4615 }
4616
4617 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00004618 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4619 T->isDependentType()) {
Richard Smith74aeef52013-04-26 16:15:35 +00004620 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith30482bc2011-02-20 03:19:35 +00004621 if (Result.isNull())
4622 return QualType();
4623 }
4624
4625 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4626 NewTL.setNameLoc(TL.getNameLoc());
4627
4628 return Result;
4629}
4630
4631template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004632QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004633 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004634 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004635 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004636 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4637 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004638 if (!Record)
4639 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004640
John McCall550e0c22009-10-21 00:40:46 +00004641 QualType Result = TL.getType();
4642 if (getDerived().AlwaysRebuild() ||
4643 Record != T->getDecl()) {
4644 Result = getDerived().RebuildRecordType(Record);
4645 if (Result.isNull())
4646 return QualType();
4647 }
Mike Stump11289f42009-09-09 15:08:12 +00004648
John McCall550e0c22009-10-21 00:40:46 +00004649 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4650 NewTL.setNameLoc(TL.getNameLoc());
4651
4652 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004653}
Mike Stump11289f42009-09-09 15:08:12 +00004654
4655template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004656QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004657 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004658 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004659 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004660 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4661 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004662 if (!Enum)
4663 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004664
John McCall550e0c22009-10-21 00:40:46 +00004665 QualType Result = TL.getType();
4666 if (getDerived().AlwaysRebuild() ||
4667 Enum != T->getDecl()) {
4668 Result = getDerived().RebuildEnumType(Enum);
4669 if (Result.isNull())
4670 return QualType();
4671 }
Mike Stump11289f42009-09-09 15:08:12 +00004672
John McCall550e0c22009-10-21 00:40:46 +00004673 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4674 NewTL.setNameLoc(TL.getNameLoc());
4675
4676 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004677}
John McCallfcc33b02009-09-05 00:15:47 +00004678
John McCalle78aac42010-03-10 03:28:59 +00004679template<typename Derived>
4680QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4681 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004682 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004683 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4684 TL.getTypePtr()->getDecl());
4685 if (!D) return QualType();
4686
4687 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4688 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4689 return T;
4690}
4691
Douglas Gregord6ff3322009-08-04 16:50:30 +00004692template<typename Derived>
4693QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004694 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004695 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004696 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004697}
4698
Mike Stump11289f42009-09-09 15:08:12 +00004699template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004700QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004701 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004702 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004703 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00004704
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004705 // Substitute into the replacement type, which itself might involve something
4706 // that needs to be transformed. This only tends to occur with default
4707 // template arguments of template template parameters.
4708 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4709 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4710 if (Replacement.isNull())
4711 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00004712
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004713 // Always canonicalize the replacement type.
4714 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4715 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00004716 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004717 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00004718
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004719 // Propagate type-source information.
4720 SubstTemplateTypeParmTypeLoc NewTL
4721 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4722 NewTL.setNameLoc(TL.getNameLoc());
4723 return Result;
4724
John McCallcebee162009-10-18 09:09:24 +00004725}
4726
4727template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004728QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4729 TypeLocBuilder &TLB,
4730 SubstTemplateTypeParmPackTypeLoc TL) {
4731 return TransformTypeSpecType(TLB, TL);
4732}
4733
4734template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004735QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004736 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004737 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004738 const TemplateSpecializationType *T = TL.getTypePtr();
4739
Douglas Gregordf846d12011-03-02 18:46:51 +00004740 // The nested-name-specifier never matters in a TemplateSpecializationType,
4741 // because we can't have a dependent nested-name-specifier anyway.
4742 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004743 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004744 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4745 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004746 if (Template.isNull())
4747 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004748
John McCall31f82722010-11-12 08:19:04 +00004749 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4750}
4751
Eli Friedman0dfb8892011-10-06 23:00:33 +00004752template<typename Derived>
4753QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4754 AtomicTypeLoc TL) {
4755 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4756 if (ValueType.isNull())
4757 return QualType();
4758
4759 QualType Result = TL.getType();
4760 if (getDerived().AlwaysRebuild() ||
4761 ValueType != TL.getValueLoc().getType()) {
4762 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4763 if (Result.isNull())
4764 return QualType();
4765 }
4766
4767 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4768 NewTL.setKWLoc(TL.getKWLoc());
4769 NewTL.setLParenLoc(TL.getLParenLoc());
4770 NewTL.setRParenLoc(TL.getRParenLoc());
4771
4772 return Result;
4773}
4774
Chad Rosier1dcde962012-08-08 18:46:20 +00004775 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00004776 /// container that provides a \c getArgLoc() member function.
4777 ///
4778 /// This iterator is intended to be used with the iterator form of
4779 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4780 template<typename ArgLocContainer>
4781 class TemplateArgumentLocContainerIterator {
4782 ArgLocContainer *Container;
4783 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00004784
Douglas Gregorfe921a72010-12-20 23:36:19 +00004785 public:
4786 typedef TemplateArgumentLoc value_type;
4787 typedef TemplateArgumentLoc reference;
4788 typedef int difference_type;
4789 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00004790
Douglas Gregorfe921a72010-12-20 23:36:19 +00004791 class pointer {
4792 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00004793
Douglas Gregorfe921a72010-12-20 23:36:19 +00004794 public:
4795 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004796
Douglas Gregorfe921a72010-12-20 23:36:19 +00004797 const TemplateArgumentLoc *operator->() const {
4798 return &Arg;
4799 }
4800 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004801
4802
Douglas Gregorfe921a72010-12-20 23:36:19 +00004803 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00004804
Douglas Gregorfe921a72010-12-20 23:36:19 +00004805 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4806 unsigned Index)
4807 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004808
Douglas Gregorfe921a72010-12-20 23:36:19 +00004809 TemplateArgumentLocContainerIterator &operator++() {
4810 ++Index;
4811 return *this;
4812 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004813
Douglas Gregorfe921a72010-12-20 23:36:19 +00004814 TemplateArgumentLocContainerIterator operator++(int) {
4815 TemplateArgumentLocContainerIterator Old(*this);
4816 ++(*this);
4817 return Old;
4818 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004819
Douglas Gregorfe921a72010-12-20 23:36:19 +00004820 TemplateArgumentLoc operator*() const {
4821 return Container->getArgLoc(Index);
4822 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004823
Douglas Gregorfe921a72010-12-20 23:36:19 +00004824 pointer operator->() const {
4825 return pointer(Container->getArgLoc(Index));
4826 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004827
Douglas Gregorfe921a72010-12-20 23:36:19 +00004828 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004829 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004830 return X.Container == Y.Container && X.Index == Y.Index;
4831 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004832
Douglas Gregorfe921a72010-12-20 23:36:19 +00004833 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004834 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004835 return !(X == Y);
4836 }
4837 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004838
4839
John McCall31f82722010-11-12 08:19:04 +00004840template <typename Derived>
4841QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4842 TypeLocBuilder &TLB,
4843 TemplateSpecializationTypeLoc TL,
4844 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004845 TemplateArgumentListInfo NewTemplateArgs;
4846 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4847 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004848 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4849 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004850 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00004851 ArgIterator(TL, TL.getNumArgs()),
4852 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004853 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004854
John McCall0ad16662009-10-29 08:12:44 +00004855 // FIXME: maybe don't rebuild if all the template arguments are the same.
4856
4857 QualType Result =
4858 getDerived().RebuildTemplateSpecializationType(Template,
4859 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004860 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004861
4862 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00004863 // Specializations of template template parameters are represented as
4864 // TemplateSpecializationTypes, and substitution of type alias templates
4865 // within a dependent context can transform them into
4866 // DependentTemplateSpecializationTypes.
4867 if (isa<DependentTemplateSpecializationType>(Result)) {
4868 DependentTemplateSpecializationTypeLoc NewTL
4869 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004870 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00004871 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00004872 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004873 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00004874 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());
4878 return Result;
4879 }
4880
John McCall0ad16662009-10-29 08:12:44 +00004881 TemplateSpecializationTypeLoc NewTL
4882 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004883 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00004884 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4885 NewTL.setLAngleLoc(TL.getLAngleLoc());
4886 NewTL.setRAngleLoc(TL.getRAngleLoc());
4887 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4888 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004889 }
Mike Stump11289f42009-09-09 15:08:12 +00004890
John McCall0ad16662009-10-29 08:12:44 +00004891 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004892}
Mike Stump11289f42009-09-09 15:08:12 +00004893
Douglas Gregor5a064722011-02-28 17:23:35 +00004894template <typename Derived>
4895QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4896 TypeLocBuilder &TLB,
4897 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004898 TemplateName Template,
4899 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00004900 TemplateArgumentListInfo NewTemplateArgs;
4901 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4902 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4903 typedef TemplateArgumentLocContainerIterator<
4904 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004905 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00004906 ArgIterator(TL, TL.getNumArgs()),
4907 NewTemplateArgs))
4908 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00004909
Douglas Gregor5a064722011-02-28 17:23:35 +00004910 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00004911
Douglas Gregor5a064722011-02-28 17:23:35 +00004912 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4913 QualType Result
4914 = getSema().Context.getDependentTemplateSpecializationType(
4915 TL.getTypePtr()->getKeyword(),
4916 DTN->getQualifier(),
4917 DTN->getIdentifier(),
4918 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00004919
Douglas Gregor5a064722011-02-28 17:23:35 +00004920 DependentTemplateSpecializationTypeLoc NewTL
4921 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004922 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004923 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00004924 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004925 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00004926 NewTL.setLAngleLoc(TL.getLAngleLoc());
4927 NewTL.setRAngleLoc(TL.getRAngleLoc());
4928 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4929 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4930 return Result;
4931 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004932
4933 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00004934 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004935 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00004936 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00004937
Douglas Gregor5a064722011-02-28 17:23:35 +00004938 if (!Result.isNull()) {
4939 /// FIXME: Wrap this in an elaborated-type-specifier?
4940 TemplateSpecializationTypeLoc NewTL
4941 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00004942 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004943 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00004944 NewTL.setLAngleLoc(TL.getLAngleLoc());
4945 NewTL.setRAngleLoc(TL.getRAngleLoc());
4946 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4947 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4948 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004949
Douglas Gregor5a064722011-02-28 17:23:35 +00004950 return Result;
4951}
4952
Mike Stump11289f42009-09-09 15:08:12 +00004953template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004954QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00004955TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004956 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004957 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00004958
Douglas Gregor844cb502011-03-01 18:12:44 +00004959 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00004960 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00004961 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004962 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00004963 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4964 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00004965 return QualType();
4966 }
Mike Stump11289f42009-09-09 15:08:12 +00004967
John McCall31f82722010-11-12 08:19:04 +00004968 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4969 if (NamedT.isNull())
4970 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00004971
Richard Smith3f1b5d02011-05-05 21:57:07 +00004972 // C++0x [dcl.type.elab]p2:
4973 // If the identifier resolves to a typedef-name or the simple-template-id
4974 // resolves to an alias template specialization, the
4975 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00004976 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4977 if (const TemplateSpecializationType *TST =
4978 NamedT->getAs<TemplateSpecializationType>()) {
4979 TemplateName Template = TST->getTemplateName();
4980 if (TypeAliasTemplateDecl *TAT =
4981 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4982 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4983 diag::err_tag_reference_non_tag) << 4;
4984 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4985 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00004986 }
4987 }
4988
John McCall550e0c22009-10-21 00:40:46 +00004989 QualType Result = TL.getType();
4990 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00004991 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00004992 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00004993 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004994 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00004995 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00004996 if (Result.isNull())
4997 return QualType();
4998 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004999
Abramo Bagnara6150c882010-05-11 21:36:43 +00005000 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005001 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005002 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005003 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005004}
Mike Stump11289f42009-09-09 15:08:12 +00005005
5006template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005007QualType TreeTransform<Derived>::TransformAttributedType(
5008 TypeLocBuilder &TLB,
5009 AttributedTypeLoc TL) {
5010 const AttributedType *oldType = TL.getTypePtr();
5011 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5012 if (modifiedType.isNull())
5013 return QualType();
5014
5015 QualType result = TL.getType();
5016
5017 // FIXME: dependent operand expressions?
5018 if (getDerived().AlwaysRebuild() ||
5019 modifiedType != oldType->getModifiedType()) {
5020 // TODO: this is really lame; we should really be rebuilding the
5021 // equivalent type from first principles.
5022 QualType equivalentType
5023 = getDerived().TransformType(oldType->getEquivalentType());
5024 if (equivalentType.isNull())
5025 return QualType();
5026 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5027 modifiedType,
5028 equivalentType);
5029 }
5030
5031 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5032 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5033 if (TL.hasAttrOperand())
5034 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5035 if (TL.hasAttrExprOperand())
5036 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5037 else if (TL.hasAttrEnumOperand())
5038 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5039
5040 return result;
5041}
5042
5043template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005044QualType
5045TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5046 ParenTypeLoc TL) {
5047 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5048 if (Inner.isNull())
5049 return QualType();
5050
5051 QualType Result = TL.getType();
5052 if (getDerived().AlwaysRebuild() ||
5053 Inner != TL.getInnerLoc().getType()) {
5054 Result = getDerived().RebuildParenType(Inner);
5055 if (Result.isNull())
5056 return QualType();
5057 }
5058
5059 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5060 NewTL.setLParenLoc(TL.getLParenLoc());
5061 NewTL.setRParenLoc(TL.getRParenLoc());
5062 return Result;
5063}
5064
5065template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005066QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005067 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005068 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005069
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005070 NestedNameSpecifierLoc QualifierLoc
5071 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5072 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005073 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005074
John McCallc392f372010-06-11 00:33:02 +00005075 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005076 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005077 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005078 QualifierLoc,
5079 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005080 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005081 if (Result.isNull())
5082 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005083
Abramo Bagnarad7548482010-05-19 21:37:53 +00005084 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5085 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005086 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5087
Abramo Bagnarad7548482010-05-19 21:37:53 +00005088 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005089 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005090 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005091 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005092 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005093 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005094 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005095 NewTL.setNameLoc(TL.getNameLoc());
5096 }
John McCall550e0c22009-10-21 00:40:46 +00005097 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005098}
Mike Stump11289f42009-09-09 15:08:12 +00005099
Douglas Gregord6ff3322009-08-04 16:50:30 +00005100template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005101QualType TreeTransform<Derived>::
5102 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005103 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005104 NestedNameSpecifierLoc QualifierLoc;
5105 if (TL.getQualifierLoc()) {
5106 QualifierLoc
5107 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5108 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005109 return QualType();
5110 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005111
John McCall31f82722010-11-12 08:19:04 +00005112 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005113 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005114}
5115
5116template<typename Derived>
5117QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005118TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5119 DependentTemplateSpecializationTypeLoc TL,
5120 NestedNameSpecifierLoc QualifierLoc) {
5121 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005122
Douglas Gregora7a795b2011-03-01 20:11:18 +00005123 TemplateArgumentListInfo NewTemplateArgs;
5124 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5125 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005126
Douglas Gregora7a795b2011-03-01 20:11:18 +00005127 typedef TemplateArgumentLocContainerIterator<
5128 DependentTemplateSpecializationTypeLoc> ArgIterator;
5129 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5130 ArgIterator(TL, TL.getNumArgs()),
5131 NewTemplateArgs))
5132 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005133
Douglas Gregora7a795b2011-03-01 20:11:18 +00005134 QualType Result
5135 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5136 QualifierLoc,
5137 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005138 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005139 NewTemplateArgs);
5140 if (Result.isNull())
5141 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005142
Douglas Gregora7a795b2011-03-01 20:11:18 +00005143 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5144 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005145
Douglas Gregora7a795b2011-03-01 20:11:18 +00005146 // Copy information relevant to the template specialization.
5147 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005148 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005149 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005150 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005151 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5152 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005153 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005154 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005155
Douglas Gregora7a795b2011-03-01 20:11:18 +00005156 // Copy information relevant to the elaborated type.
5157 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005158 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005159 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005160 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5161 DependentTemplateSpecializationTypeLoc SpecTL
5162 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005163 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005164 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005165 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005166 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005167 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5168 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005169 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005170 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005171 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005172 TemplateSpecializationTypeLoc SpecTL
5173 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005174 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005175 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005176 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5177 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005178 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005179 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005180 }
5181 return Result;
5182}
5183
5184template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005185QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5186 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005187 QualType Pattern
5188 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005189 if (Pattern.isNull())
5190 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005191
5192 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005193 if (getDerived().AlwaysRebuild() ||
5194 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005195 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005196 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005197 TL.getEllipsisLoc(),
5198 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005199 if (Result.isNull())
5200 return QualType();
5201 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005202
Douglas Gregor822d0302011-01-12 17:07:58 +00005203 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5204 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5205 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005206}
5207
5208template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005209QualType
5210TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005211 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005212 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005213 TLB.pushFullCopy(TL);
5214 return TL.getType();
5215}
5216
5217template<typename Derived>
5218QualType
5219TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005220 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00005221 // ObjCObjectType is never dependent.
5222 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005223 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005224}
Mike Stump11289f42009-09-09 15:08:12 +00005225
5226template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005227QualType
5228TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005229 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005230 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005231 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005232 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005233}
5234
Douglas Gregord6ff3322009-08-04 16:50:30 +00005235//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005236// Statement transformation
5237//===----------------------------------------------------------------------===//
5238template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005239StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005240TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005241 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005242}
5243
5244template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005245StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005246TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5247 return getDerived().TransformCompoundStmt(S, false);
5248}
5249
5250template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005251StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005252TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005253 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005254 Sema::CompoundScopeRAII CompoundScope(getSema());
5255
John McCall1ababa62010-08-27 19:56:05 +00005256 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005257 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005258 SmallVector<Stmt*, 8> Statements;
Douglas Gregorebe10102009-08-20 07:17:43 +00005259 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5260 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00005261 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00005262 if (Result.isInvalid()) {
5263 // Immediately fail if this was a DeclStmt, since it's very
5264 // likely that this will cause problems for future statements.
5265 if (isa<DeclStmt>(*B))
5266 return StmtError();
5267
5268 // Otherwise, just keep processing substatements and fail later.
5269 SubStmtInvalid = true;
5270 continue;
5271 }
Mike Stump11289f42009-09-09 15:08:12 +00005272
Douglas Gregorebe10102009-08-20 07:17:43 +00005273 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5274 Statements.push_back(Result.takeAs<Stmt>());
5275 }
Mike Stump11289f42009-09-09 15:08:12 +00005276
John McCall1ababa62010-08-27 19:56:05 +00005277 if (SubStmtInvalid)
5278 return StmtError();
5279
Douglas Gregorebe10102009-08-20 07:17:43 +00005280 if (!getDerived().AlwaysRebuild() &&
5281 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00005282 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005283
5284 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005285 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005286 S->getRBracLoc(),
5287 IsStmtExpr);
5288}
Mike Stump11289f42009-09-09 15:08:12 +00005289
Douglas Gregorebe10102009-08-20 07:17:43 +00005290template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005291StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005292TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005293 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005294 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005295 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5296 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005297
Eli Friedman06577382009-11-19 03:14:00 +00005298 // Transform the left-hand case value.
5299 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005300 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005301 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005302 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005303
Eli Friedman06577382009-11-19 03:14:00 +00005304 // Transform the right-hand case value (for the GNU case-range extension).
5305 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005306 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005307 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005308 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005309 }
Mike Stump11289f42009-09-09 15:08:12 +00005310
Douglas Gregorebe10102009-08-20 07:17:43 +00005311 // Build the case statement.
5312 // Case statements are always rebuilt so that they will attached to their
5313 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005314 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005315 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005316 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005317 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005318 S->getColonLoc());
5319 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005320 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005321
Douglas Gregorebe10102009-08-20 07:17:43 +00005322 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005323 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005324 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005325 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005326
Douglas Gregorebe10102009-08-20 07:17:43 +00005327 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005328 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005329}
5330
5331template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005332StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005333TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005334 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005335 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005336 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005337 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005338
Douglas Gregorebe10102009-08-20 07:17:43 +00005339 // Default statements are always rebuilt
5340 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005341 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005342}
Mike Stump11289f42009-09-09 15:08:12 +00005343
Douglas Gregorebe10102009-08-20 07:17:43 +00005344template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005345StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005346TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005347 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005348 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005349 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005350
Chris Lattnercab02a62011-02-17 20:34:02 +00005351 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5352 S->getDecl());
5353 if (!LD)
5354 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00005355
5356
Douglas Gregorebe10102009-08-20 07:17:43 +00005357 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005358 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005359 cast<LabelDecl>(LD), SourceLocation(),
5360 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005361}
Mike Stump11289f42009-09-09 15:08:12 +00005362
Douglas Gregorebe10102009-08-20 07:17:43 +00005363template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005364StmtResult
Richard Smithc202b282012-04-14 00:33:13 +00005365TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5366 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5367 if (SubStmt.isInvalid())
5368 return StmtError();
5369
5370 // TODO: transform attributes
5371 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5372 return S;
5373
5374 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5375 S->getAttrs(),
5376 SubStmt.get());
5377}
5378
5379template<typename Derived>
5380StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005381TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005382 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005383 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00005384 VarDecl *ConditionVar = 0;
5385 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005386 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00005387 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005388 getDerived().TransformDefinition(
5389 S->getConditionVariable()->getLocation(),
5390 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00005391 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005392 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005393 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00005394 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005395
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005396 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005397 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005398
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005399 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005400 if (S->getCond()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005401 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005402 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005403 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005404 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005405
John McCallb268a282010-08-23 23:25:46 +00005406 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005407 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005408 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005409
John McCallb268a282010-08-23 23:25:46 +00005410 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5411 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005412 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005413
Douglas Gregorebe10102009-08-20 07:17:43 +00005414 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005415 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005416 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005417 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005418
Douglas Gregorebe10102009-08-20 07:17:43 +00005419 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005420 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005421 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005422 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005423
Douglas Gregorebe10102009-08-20 07:17:43 +00005424 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005425 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005426 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005427 Then.get() == S->getThen() &&
5428 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00005429 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005430
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005431 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005432 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00005433 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005434}
5435
5436template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005437StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005438TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005439 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005440 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00005441 VarDecl *ConditionVar = 0;
5442 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005443 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005444 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005445 getDerived().TransformDefinition(
5446 S->getConditionVariable()->getLocation(),
5447 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005448 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005449 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005450 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005451 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005452
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005453 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005454 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005455 }
Mike Stump11289f42009-09-09 15:08:12 +00005456
Douglas Gregorebe10102009-08-20 07:17:43 +00005457 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005458 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005459 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005460 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005461 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005462 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005463
Douglas Gregorebe10102009-08-20 07:17:43 +00005464 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005465 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005466 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005467 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005468
Douglas Gregorebe10102009-08-20 07:17:43 +00005469 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005470 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5471 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005472}
Mike Stump11289f42009-09-09 15:08:12 +00005473
Douglas Gregorebe10102009-08-20 07:17:43 +00005474template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005475StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005476TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005477 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005478 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00005479 VarDecl *ConditionVar = 0;
5480 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005481 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005482 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005483 getDerived().TransformDefinition(
5484 S->getConditionVariable()->getLocation(),
5485 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005486 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005487 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005488 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005489 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005490
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005491 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005492 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005493
5494 if (S->getCond()) {
5495 // Convert the condition to a boolean value.
Chad Rosier1dcde962012-08-08 18:46:20 +00005496 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005497 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005498 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005499 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005500 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005501 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005502 }
Mike Stump11289f42009-09-09 15:08:12 +00005503
John McCallb268a282010-08-23 23:25:46 +00005504 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5505 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005506 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005507
Douglas Gregorebe10102009-08-20 07:17:43 +00005508 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005509 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005510 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005511 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005512
Douglas Gregorebe10102009-08-20 07:17:43 +00005513 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005514 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005515 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005516 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005517 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005518
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005519 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005520 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005521}
Mike Stump11289f42009-09-09 15:08:12 +00005522
Douglas Gregorebe10102009-08-20 07:17:43 +00005523template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005524StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005525TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005526 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005527 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005528 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005529 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005530
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005531 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005532 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005533 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005534 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005535
Douglas Gregorebe10102009-08-20 07:17:43 +00005536 if (!getDerived().AlwaysRebuild() &&
5537 Cond.get() == S->getCond() &&
5538 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005539 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005540
John McCallb268a282010-08-23 23:25:46 +00005541 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5542 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005543 S->getRParenLoc());
5544}
Mike Stump11289f42009-09-09 15:08:12 +00005545
Douglas Gregorebe10102009-08-20 07:17:43 +00005546template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005547StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005548TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005549 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005550 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005551 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005552 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005553
Douglas Gregorebe10102009-08-20 07:17:43 +00005554 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005555 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005556 VarDecl *ConditionVar = 0;
5557 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005558 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005559 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005560 getDerived().TransformDefinition(
5561 S->getConditionVariable()->getLocation(),
5562 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005563 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005564 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005565 } else {
5566 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005567
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005568 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005569 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005570
5571 if (S->getCond()) {
5572 // Convert the condition to a boolean value.
Chad Rosier1dcde962012-08-08 18:46:20 +00005573 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005574 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005575 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005576 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005577
John McCallb268a282010-08-23 23:25:46 +00005578 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005579 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005580 }
Mike Stump11289f42009-09-09 15:08:12 +00005581
Chad Rosier1dcde962012-08-08 18:46:20 +00005582 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCallb268a282010-08-23 23:25:46 +00005583 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005584 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005585
Douglas Gregorebe10102009-08-20 07:17:43 +00005586 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005587 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005588 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005589 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005590
Richard Smith945f8d32013-01-14 22:39:08 +00005591 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00005592 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005593 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005594
Douglas Gregorebe10102009-08-20 07:17:43 +00005595 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005596 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005597 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005598 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005599
Douglas Gregorebe10102009-08-20 07:17:43 +00005600 if (!getDerived().AlwaysRebuild() &&
5601 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005602 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005603 Inc.get() == S->getInc() &&
5604 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005605 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005606
Douglas Gregorebe10102009-08-20 07:17:43 +00005607 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005608 Init.get(), FullCond, ConditionVar,
5609 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005610}
5611
5612template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005613StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005614TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005615 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5616 S->getLabel());
5617 if (!LD)
5618 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005619
Douglas Gregorebe10102009-08-20 07:17:43 +00005620 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005621 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005622 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005623}
5624
5625template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005626StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005627TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005628 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005629 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005630 return StmtError();
Eli Friedman9ccdb1d2012-01-31 22:47:07 +00005631 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump11289f42009-09-09 15:08:12 +00005632
Douglas Gregorebe10102009-08-20 07:17:43 +00005633 if (!getDerived().AlwaysRebuild() &&
5634 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00005635 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005636
5637 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005638 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005639}
5640
5641template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005642StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005643TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005644 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005645}
Mike Stump11289f42009-09-09 15:08:12 +00005646
Douglas Gregorebe10102009-08-20 07:17:43 +00005647template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005648StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005649TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005650 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005651}
Mike Stump11289f42009-09-09 15:08:12 +00005652
Douglas Gregorebe10102009-08-20 07:17:43 +00005653template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005654StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005655TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005656 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005657 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005658 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005659
Mike Stump11289f42009-09-09 15:08:12 +00005660 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005661 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005662 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005663}
Mike Stump11289f42009-09-09 15:08:12 +00005664
Douglas Gregorebe10102009-08-20 07:17:43 +00005665template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005666StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005667TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005668 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005669 SmallVector<Decl *, 4> Decls;
Douglas Gregorebe10102009-08-20 07:17:43 +00005670 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5671 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00005672 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5673 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005674 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005675 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005676
Douglas Gregorebe10102009-08-20 07:17:43 +00005677 if (Transformed != *D)
5678 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005679
Douglas Gregorebe10102009-08-20 07:17:43 +00005680 Decls.push_back(Transformed);
5681 }
Mike Stump11289f42009-09-09 15:08:12 +00005682
Douglas Gregorebe10102009-08-20 07:17:43 +00005683 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00005684 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005685
Rafael Espindolaab417692013-07-09 12:05:01 +00005686 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005687}
Mike Stump11289f42009-09-09 15:08:12 +00005688
Douglas Gregorebe10102009-08-20 07:17:43 +00005689template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005690StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00005691TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005692
Benjamin Kramerf0623432012-08-23 22:51:59 +00005693 SmallVector<Expr*, 8> Constraints;
5694 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005695 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005696
John McCalldadc5752010-08-24 06:29:42 +00005697 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005698 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005699
5700 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00005701
Anders Carlssonaaeef072010-01-24 05:50:09 +00005702 // Go through the outputs.
5703 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005704 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005705
Anders Carlssonaaeef072010-01-24 05:50:09 +00005706 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005707 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005708
Anders Carlssonaaeef072010-01-24 05:50:09 +00005709 // Transform the output expr.
5710 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005711 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005712 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005713 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005714
Anders Carlssonaaeef072010-01-24 05:50:09 +00005715 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005716
John McCallb268a282010-08-23 23:25:46 +00005717 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005718 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005719
Anders Carlssonaaeef072010-01-24 05:50:09 +00005720 // Go through the inputs.
5721 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005722 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005723
Anders Carlssonaaeef072010-01-24 05:50:09 +00005724 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005725 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005726
Anders Carlssonaaeef072010-01-24 05:50:09 +00005727 // Transform the input expr.
5728 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005729 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005730 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005731 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005732
Anders Carlssonaaeef072010-01-24 05:50:09 +00005733 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005734
John McCallb268a282010-08-23 23:25:46 +00005735 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005736 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005737
Anders Carlssonaaeef072010-01-24 05:50:09 +00005738 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00005739 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005740
5741 // Go through the clobbers.
5742 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00005743 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005744
5745 // No need to transform the asm string literal.
5746 AsmString = SemaRef.Owned(S->getAsmString());
Chad Rosierde70e0e2012-08-25 00:11:56 +00005747 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5748 S->isVolatile(), S->getNumOutputs(),
5749 S->getNumInputs(), Names.data(),
5750 Constraints, Exprs, AsmString.get(),
5751 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005752}
5753
Chad Rosier32503022012-06-11 20:47:18 +00005754template<typename Derived>
5755StmtResult
5756TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00005757 ArrayRef<Token> AsmToks =
5758 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00005759
John McCallf413f5e2013-05-03 00:10:13 +00005760 bool HadError = false, HadChange = false;
5761
5762 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5763 SmallVector<Expr*, 8> TransformedExprs;
5764 TransformedExprs.reserve(SrcExprs.size());
5765 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5766 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5767 if (!Result.isUsable()) {
5768 HadError = true;
5769 } else {
5770 HadChange |= (Result.get() != SrcExprs[i]);
5771 TransformedExprs.push_back(Result.take());
5772 }
5773 }
5774
5775 if (HadError) return StmtError();
5776 if (!HadChange && !getDerived().AlwaysRebuild())
5777 return Owned(S);
5778
Chad Rosierb6f46c12012-08-15 16:53:30 +00005779 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00005780 AsmToks, S->getAsmString(),
5781 S->getNumOutputs(), S->getNumInputs(),
5782 S->getAllConstraints(), S->getClobbers(),
5783 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00005784}
Douglas Gregorebe10102009-08-20 07:17:43 +00005785
5786template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005787StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005788TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005789 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005790 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005791 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005792 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005793
Douglas Gregor96c79492010-04-23 22:50:49 +00005794 // Transform the @catch statements (if present).
5795 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005796 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00005797 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005798 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005799 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005800 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005801 if (Catch.get() != S->getCatchStmt(I))
5802 AnyCatchChanged = true;
5803 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005804 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005805
Douglas Gregor306de2f2010-04-22 23:59:56 +00005806 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005807 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005808 if (S->getFinallyStmt()) {
5809 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5810 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005811 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005812 }
5813
5814 // If nothing changed, just retain this statement.
5815 if (!getDerived().AlwaysRebuild() &&
5816 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005817 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005818 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00005819 return SemaRef.Owned(S);
Chad Rosier1dcde962012-08-08 18:46:20 +00005820
Douglas Gregor306de2f2010-04-22 23:59:56 +00005821 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005822 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005823 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005824}
Mike Stump11289f42009-09-09 15:08:12 +00005825
Douglas Gregorebe10102009-08-20 07:17:43 +00005826template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005827StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005828TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005829 // Transform the @catch parameter, if there is one.
5830 VarDecl *Var = 0;
5831 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5832 TypeSourceInfo *TSInfo = 0;
5833 if (FromVar->getTypeSourceInfo()) {
5834 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5835 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005836 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005837 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005838
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005839 QualType T;
5840 if (TSInfo)
5841 T = TSInfo->getType();
5842 else {
5843 T = getDerived().TransformType(FromVar->getType());
5844 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00005845 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005846 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005847
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005848 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5849 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005850 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005851 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005852
John McCalldadc5752010-08-24 06:29:42 +00005853 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005854 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005855 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005856
5857 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005858 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005859 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005860}
Mike Stump11289f42009-09-09 15:08:12 +00005861
Douglas Gregorebe10102009-08-20 07:17:43 +00005862template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005863StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005864TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005865 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005866 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005867 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005868 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005869
Douglas Gregor306de2f2010-04-22 23:59:56 +00005870 // If nothing changed, just retain this statement.
5871 if (!getDerived().AlwaysRebuild() &&
5872 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00005873 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00005874
5875 // Build a new statement.
5876 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005877 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005878}
Mike Stump11289f42009-09-09 15:08:12 +00005879
Douglas Gregorebe10102009-08-20 07:17:43 +00005880template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005881StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005882TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005883 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005884 if (S->getThrowExpr()) {
5885 Operand = getDerived().TransformExpr(S->getThrowExpr());
5886 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005887 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005888 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005889
Douglas Gregor2900c162010-04-22 21:44:01 +00005890 if (!getDerived().AlwaysRebuild() &&
5891 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005892 return getSema().Owned(S);
Chad Rosier1dcde962012-08-08 18:46:20 +00005893
John McCallb268a282010-08-23 23:25:46 +00005894 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005895}
Mike Stump11289f42009-09-09 15:08:12 +00005896
Douglas Gregorebe10102009-08-20 07:17:43 +00005897template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005898StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005899TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005900 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005901 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005902 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005903 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005904 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00005905 Object =
5906 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5907 Object.get());
5908 if (Object.isInvalid())
5909 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005910
Douglas Gregor6148de72010-04-22 22:01:21 +00005911 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005912 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005913 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005914 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005915
Douglas Gregor6148de72010-04-22 22:01:21 +00005916 // If nothing change, just retain the current statement.
5917 if (!getDerived().AlwaysRebuild() &&
5918 Object.get() == S->getSynchExpr() &&
5919 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005920 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005921
5922 // Build a new statement.
5923 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005924 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005925}
5926
5927template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005928StmtResult
John McCall31168b02011-06-15 23:02:42 +00005929TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5930 ObjCAutoreleasePoolStmt *S) {
5931 // Transform the body.
5932 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5933 if (Body.isInvalid())
5934 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005935
John McCall31168b02011-06-15 23:02:42 +00005936 // If nothing changed, just retain this statement.
5937 if (!getDerived().AlwaysRebuild() &&
5938 Body.get() == S->getSubStmt())
5939 return SemaRef.Owned(S);
5940
5941 // Build a new statement.
5942 return getDerived().RebuildObjCAutoreleasePoolStmt(
5943 S->getAtLoc(), Body.get());
5944}
5945
5946template<typename Derived>
5947StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005948TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005949 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005950 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005951 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005952 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005953 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005954
Douglas Gregorf68a5082010-04-22 23:10:45 +00005955 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00005956 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005957 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005958 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005959
Douglas Gregorf68a5082010-04-22 23:10:45 +00005960 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005961 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005962 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005963 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005964
Douglas Gregorf68a5082010-04-22 23:10:45 +00005965 // If nothing changed, just retain this statement.
5966 if (!getDerived().AlwaysRebuild() &&
5967 Element.get() == S->getElement() &&
5968 Collection.get() == S->getCollection() &&
5969 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005970 return SemaRef.Owned(S);
Chad Rosier1dcde962012-08-08 18:46:20 +00005971
Douglas Gregorf68a5082010-04-22 23:10:45 +00005972 // Build a new statement.
5973 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00005974 Element.get(),
5975 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00005976 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005977 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005978}
5979
David Majnemer5f7efef2013-10-15 09:50:08 +00005980template <typename Derived>
5981StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005982 // Transform the exception declaration, if any.
5983 VarDecl *Var = 0;
David Majnemer5f7efef2013-10-15 09:50:08 +00005984 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
5985 TypeSourceInfo *T =
5986 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005987 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005988 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005989
David Majnemer5f7efef2013-10-15 09:50:08 +00005990 Var = getDerived().RebuildExceptionDecl(
5991 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
5992 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00005993 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00005994 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005995 }
Mike Stump11289f42009-09-09 15:08:12 +00005996
Douglas Gregorebe10102009-08-20 07:17:43 +00005997 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00005998 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00005999 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006000 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006001
David Majnemer5f7efef2013-10-15 09:50:08 +00006002 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006003 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00006004 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00006005
David Majnemer5f7efef2013-10-15 09:50:08 +00006006 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006007}
Mike Stump11289f42009-09-09 15:08:12 +00006008
David Majnemer5f7efef2013-10-15 09:50:08 +00006009template <typename Derived>
6010StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006011 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006012 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006013 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006014 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006015
Douglas Gregorebe10102009-08-20 07:17:43 +00006016 // Transform the handlers.
6017 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006018 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006019 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006020 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006021 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006022 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006023
Douglas Gregorebe10102009-08-20 07:17:43 +00006024 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
6025 Handlers.push_back(Handler.takeAs<Stmt>());
6026 }
Mike Stump11289f42009-09-09 15:08:12 +00006027
David Majnemer5f7efef2013-10-15 09:50:08 +00006028 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006029 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00006030 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00006031
John McCallb268a282010-08-23 23:25:46 +00006032 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006033 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006034}
Mike Stump11289f42009-09-09 15:08:12 +00006035
Richard Smith02e85f32011-04-14 22:09:26 +00006036template<typename Derived>
6037StmtResult
6038TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6039 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6040 if (Range.isInvalid())
6041 return StmtError();
6042
6043 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6044 if (BeginEnd.isInvalid())
6045 return StmtError();
6046
6047 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6048 if (Cond.isInvalid())
6049 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006050 if (Cond.get())
6051 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
6052 if (Cond.isInvalid())
6053 return StmtError();
6054 if (Cond.get())
6055 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smith02e85f32011-04-14 22:09:26 +00006056
6057 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6058 if (Inc.isInvalid())
6059 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006060 if (Inc.get())
6061 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smith02e85f32011-04-14 22:09:26 +00006062
6063 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6064 if (LoopVar.isInvalid())
6065 return StmtError();
6066
6067 StmtResult NewStmt = S;
6068 if (getDerived().AlwaysRebuild() ||
6069 Range.get() != S->getRangeStmt() ||
6070 BeginEnd.get() != S->getBeginEndStmt() ||
6071 Cond.get() != S->getCond() ||
6072 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006073 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006074 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6075 S->getColonLoc(), Range.get(),
6076 BeginEnd.get(), Cond.get(),
6077 Inc.get(), LoopVar.get(),
6078 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006079 if (NewStmt.isInvalid())
6080 return StmtError();
6081 }
Richard Smith02e85f32011-04-14 22:09:26 +00006082
6083 StmtResult Body = getDerived().TransformStmt(S->getBody());
6084 if (Body.isInvalid())
6085 return StmtError();
6086
6087 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6088 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006089 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006090 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6091 S->getColonLoc(), Range.get(),
6092 BeginEnd.get(), Cond.get(),
6093 Inc.get(), LoopVar.get(),
6094 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006095 if (NewStmt.isInvalid())
6096 return StmtError();
6097 }
Richard Smith02e85f32011-04-14 22:09:26 +00006098
6099 if (NewStmt.get() == S)
6100 return SemaRef.Owned(S);
6101
6102 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6103}
6104
John Wiegley1c0675e2011-04-28 01:08:34 +00006105template<typename Derived>
6106StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006107TreeTransform<Derived>::TransformMSDependentExistsStmt(
6108 MSDependentExistsStmt *S) {
6109 // Transform the nested-name-specifier, if any.
6110 NestedNameSpecifierLoc QualifierLoc;
6111 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006112 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006113 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6114 if (!QualifierLoc)
6115 return StmtError();
6116 }
6117
6118 // Transform the declaration name.
6119 DeclarationNameInfo NameInfo = S->getNameInfo();
6120 if (NameInfo.getName()) {
6121 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6122 if (!NameInfo.getName())
6123 return StmtError();
6124 }
6125
6126 // Check whether anything changed.
6127 if (!getDerived().AlwaysRebuild() &&
6128 QualifierLoc == S->getQualifierLoc() &&
6129 NameInfo.getName() == S->getNameInfo().getName())
6130 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006131
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006132 // Determine whether this name exists, if we can.
6133 CXXScopeSpec SS;
6134 SS.Adopt(QualifierLoc);
6135 bool Dependent = false;
6136 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
6137 case Sema::IER_Exists:
6138 if (S->isIfExists())
6139 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006140
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006141 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6142
6143 case Sema::IER_DoesNotExist:
6144 if (S->isIfNotExists())
6145 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006146
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006147 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006148
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006149 case Sema::IER_Dependent:
6150 Dependent = true;
6151 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006152
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006153 case Sema::IER_Error:
6154 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006155 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006156
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006157 // We need to continue with the instantiation, so do so now.
6158 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6159 if (SubStmt.isInvalid())
6160 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006161
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006162 // If we have resolved the name, just transform to the substatement.
6163 if (!Dependent)
6164 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006165
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006166 // The name is still dependent, so build a dependent expression again.
6167 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6168 S->isIfExists(),
6169 QualifierLoc,
6170 NameInfo,
6171 SubStmt.get());
6172}
6173
6174template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006175ExprResult
6176TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6177 NestedNameSpecifierLoc QualifierLoc;
6178 if (E->getQualifierLoc()) {
6179 QualifierLoc
6180 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6181 if (!QualifierLoc)
6182 return ExprError();
6183 }
6184
6185 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6186 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6187 if (!PD)
6188 return ExprError();
6189
6190 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6191 if (Base.isInvalid())
6192 return ExprError();
6193
6194 return new (SemaRef.getASTContext())
6195 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6196 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6197 QualifierLoc, E->getMemberLoc());
6198}
6199
David Majnemerfad8f482013-10-15 09:33:02 +00006200template <typename Derived>
6201StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006202 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006203 if (TryBlock.isInvalid())
6204 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006205
6206 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006207 if (Handler.isInvalid())
6208 return StmtError();
6209
David Majnemerfad8f482013-10-15 09:33:02 +00006210 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6211 Handler.get() == S->getHandler())
John Wiegley1c0675e2011-04-28 01:08:34 +00006212 return SemaRef.Owned(S);
6213
David Majnemerfad8f482013-10-15 09:33:02 +00006214 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
6215 TryBlock.take(), Handler.take());
John Wiegley1c0675e2011-04-28 01:08:34 +00006216}
6217
David Majnemerfad8f482013-10-15 09:33:02 +00006218template <typename Derived>
6219StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006220 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006221 if (Block.isInvalid())
6222 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006223
David Majnemerfad8f482013-10-15 09:33:02 +00006224 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.take());
John Wiegley1c0675e2011-04-28 01:08:34 +00006225}
6226
David Majnemerfad8f482013-10-15 09:33:02 +00006227template <typename Derived>
6228StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00006229 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00006230 if (FilterExpr.isInvalid())
6231 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006232
David Majnemer7e755502013-10-15 09:30:14 +00006233 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006234 if (Block.isInvalid())
6235 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006236
David Majnemerfad8f482013-10-15 09:33:02 +00006237 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.take(),
John Wiegley1c0675e2011-04-28 01:08:34 +00006238 Block.take());
6239}
6240
David Majnemerfad8f482013-10-15 09:33:02 +00006241template <typename Derived>
6242StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6243 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00006244 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6245 else
6246 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6247}
6248
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006249template<typename Derived>
6250StmtResult
6251TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006252 DeclarationNameInfo DirName;
6253 getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, 0);
6254
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006255 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00006256 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006257 ArrayRef<OMPClause *> Clauses = D->clauses();
6258 TClauses.reserve(Clauses.size());
6259 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6260 I != E; ++I) {
6261 if (*I) {
6262 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataev758e55e2013-09-06 18:03:48 +00006263 if (!Clause) {
6264 getSema().EndOpenMPDSABlock(0);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006265 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006266 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006267 TClauses.push_back(Clause);
6268 }
6269 else {
6270 TClauses.push_back(0);
6271 }
6272 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00006273 if (!D->getAssociatedStmt()) {
6274 getSema().EndOpenMPDSABlock(0);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006275 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006276 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006277 StmtResult AssociatedStmt =
6278 getDerived().TransformStmt(D->getAssociatedStmt());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006279 if (AssociatedStmt.isInvalid()) {
6280 getSema().EndOpenMPDSABlock(0);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006281 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006282 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006283
Alexey Bataev758e55e2013-09-06 18:03:48 +00006284 StmtResult Res = getDerived().RebuildOMPParallelDirective(TClauses,
6285 AssociatedStmt.take(),
6286 D->getLocStart(),
6287 D->getLocEnd());
6288 getSema().EndOpenMPDSABlock(Res.get());
6289 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006290}
6291
6292template<typename Derived>
6293OMPClause *
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006294TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
6295 return getDerived().RebuildOMPIfClause(C->getCondition(), C->getLocStart(),
6296 C->getLParenLoc(), C->getLocEnd());
6297}
6298
6299template<typename Derived>
6300OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006301TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
6302 return getDerived().RebuildOMPDefaultClause(C->getDefaultKind(),
6303 C->getDefaultKindKwLoc(),
6304 C->getLocStart(),
6305 C->getLParenLoc(),
6306 C->getLocEnd());
6307}
6308
6309template<typename Derived>
6310OMPClause *
6311TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006312 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006313 Vars.reserve(C->varlist_size());
Alexey Bataev756c1962013-09-24 03:17:45 +00006314 for (OMPPrivateClause::varlist_iterator I = C->varlist_begin(),
6315 E = C->varlist_end();
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006316 I != E; ++I) {
6317 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6318 if (EVar.isInvalid())
6319 return 0;
6320 Vars.push_back(EVar.take());
6321 }
6322 return getDerived().RebuildOMPPrivateClause(Vars,
6323 C->getLocStart(),
6324 C->getLParenLoc(),
6325 C->getLocEnd());
6326}
6327
Alexey Bataev758e55e2013-09-06 18:03:48 +00006328template<typename Derived>
6329OMPClause *
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006330TreeTransform<Derived>::TransformOMPFirstprivateClause(
6331 OMPFirstprivateClause *C) {
6332 llvm::SmallVector<Expr *, 16> Vars;
6333 Vars.reserve(C->varlist_size());
6334 for (OMPFirstprivateClause::varlist_iterator I = C->varlist_begin(),
6335 E = C->varlist_end();
6336 I != E; ++I) {
6337 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6338 if (EVar.isInvalid())
6339 return 0;
6340 Vars.push_back(EVar.take());
6341 }
6342 return getDerived().RebuildOMPFirstprivateClause(Vars,
6343 C->getLocStart(),
6344 C->getLParenLoc(),
6345 C->getLocEnd());
6346}
6347
6348template<typename Derived>
6349OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00006350TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
6351 llvm::SmallVector<Expr *, 16> Vars;
6352 Vars.reserve(C->varlist_size());
Alexey Bataev756c1962013-09-24 03:17:45 +00006353 for (OMPSharedClause::varlist_iterator I = C->varlist_begin(),
6354 E = C->varlist_end();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006355 I != E; ++I) {
6356 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6357 if (EVar.isInvalid())
6358 return 0;
6359 Vars.push_back(EVar.take());
6360 }
6361 return getDerived().RebuildOMPSharedClause(Vars,
6362 C->getLocStart(),
6363 C->getLParenLoc(),
6364 C->getLocEnd());
6365}
6366
Douglas Gregorebe10102009-08-20 07:17:43 +00006367//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00006368// Expression transformation
6369//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00006370template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006371ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006372TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006373 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006374}
Mike Stump11289f42009-09-09 15:08:12 +00006375
6376template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006377ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006378TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006379 NestedNameSpecifierLoc QualifierLoc;
6380 if (E->getQualifierLoc()) {
6381 QualifierLoc
6382 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6383 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006384 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006385 }
John McCallce546572009-12-08 09:08:17 +00006386
6387 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006388 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6389 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006390 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00006391 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006392
John McCall815039a2010-08-17 21:27:17 +00006393 DeclarationNameInfo NameInfo = E->getNameInfo();
6394 if (NameInfo.getName()) {
6395 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6396 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006397 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00006398 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006399
6400 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006401 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006402 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006403 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00006404 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006405
6406 // Mark it referenced in the new context regardless.
6407 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00006408 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00006409
John McCallc3007a22010-10-26 07:05:15 +00006410 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006411 }
John McCallce546572009-12-08 09:08:17 +00006412
6413 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00006414 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006415 TemplateArgs = &TransArgs;
6416 TransArgs.setLAngleLoc(E->getLAngleLoc());
6417 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006418 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6419 E->getNumTemplateArgs(),
6420 TransArgs))
6421 return ExprError();
John McCallce546572009-12-08 09:08:17 +00006422 }
6423
Chad Rosier1dcde962012-08-08 18:46:20 +00006424 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00006425 TemplateArgs);
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>::TransformIntegerLiteral(IntegerLiteral *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>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006437 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006438}
Mike Stump11289f42009-09-09 15:08:12 +00006439
Douglas Gregora16548e2009-08-11 05:31:07 +00006440template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006441ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006442TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006443 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006444}
Mike Stump11289f42009-09-09 15:08:12 +00006445
Douglas Gregora16548e2009-08-11 05:31:07 +00006446template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006447ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006448TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006449 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006450}
Mike Stump11289f42009-09-09 15:08:12 +00006451
Douglas Gregora16548e2009-08-11 05:31:07 +00006452template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006453ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006454TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006455 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006456}
6457
6458template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006459ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00006460TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00006461 if (FunctionDecl *FD = E->getDirectCallee())
6462 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00006463 return SemaRef.MaybeBindToTemporary(E);
6464}
6465
6466template<typename Derived>
6467ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00006468TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6469 ExprResult ControllingExpr =
6470 getDerived().TransformExpr(E->getControllingExpr());
6471 if (ControllingExpr.isInvalid())
6472 return ExprError();
6473
Chris Lattner01cf8db2011-07-20 06:58:45 +00006474 SmallVector<Expr *, 4> AssocExprs;
6475 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00006476 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6477 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6478 if (TS) {
6479 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6480 if (!AssocType)
6481 return ExprError();
6482 AssocTypes.push_back(AssocType);
6483 } else {
6484 AssocTypes.push_back(0);
6485 }
6486
6487 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6488 if (AssocExpr.isInvalid())
6489 return ExprError();
6490 AssocExprs.push_back(AssocExpr.release());
6491 }
6492
6493 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6494 E->getDefaultLoc(),
6495 E->getRParenLoc(),
6496 ControllingExpr.release(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00006497 AssocTypes,
6498 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00006499}
6500
6501template<typename Derived>
6502ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006503TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006504 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006505 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006506 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006507
Douglas Gregora16548e2009-08-11 05:31:07 +00006508 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006509 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006510
John McCallb268a282010-08-23 23:25:46 +00006511 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006512 E->getRParen());
6513}
6514
Richard Smithdb2630f2012-10-21 03:28:35 +00006515/// \brief The operand of a unary address-of operator has special rules: it's
6516/// allowed to refer to a non-static member of a class even if there's no 'this'
6517/// object available.
6518template<typename Derived>
6519ExprResult
6520TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6521 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6522 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6523 else
6524 return getDerived().TransformExpr(E);
6525}
6526
Mike Stump11289f42009-09-09 15:08:12 +00006527template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006528ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006529TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00006530 ExprResult SubExpr;
6531 if (E->getOpcode() == UO_AddrOf)
6532 SubExpr = TransformAddressOfOperand(E->getSubExpr());
6533 else
6534 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006535 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006536 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006537
Douglas Gregora16548e2009-08-11 05:31:07 +00006538 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006539 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006540
Douglas Gregora16548e2009-08-11 05:31:07 +00006541 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6542 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006543 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006544}
Mike Stump11289f42009-09-09 15:08:12 +00006545
Douglas Gregora16548e2009-08-11 05:31:07 +00006546template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006547ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00006548TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6549 // Transform the type.
6550 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6551 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00006552 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006553
Douglas Gregor882211c2010-04-28 22:16:22 +00006554 // Transform all of the components into components similar to what the
6555 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00006556 // FIXME: It would be slightly more efficient in the non-dependent case to
6557 // just map FieldDecls, rather than requiring the rebuilder to look for
6558 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00006559 // template code that we don't care.
6560 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00006561 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00006562 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006563 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00006564 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6565 const Node &ON = E->getComponent(I);
6566 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00006567 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00006568 Comp.LocStart = ON.getSourceRange().getBegin();
6569 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00006570 switch (ON.getKind()) {
6571 case Node::Array: {
6572 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00006573 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00006574 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006575 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006576
Douglas Gregor882211c2010-04-28 22:16:22 +00006577 ExprChanged = ExprChanged || Index.get() != FromIndex;
6578 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00006579 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00006580 break;
6581 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006582
Douglas Gregor882211c2010-04-28 22:16:22 +00006583 case Node::Field:
6584 case Node::Identifier:
6585 Comp.isBrackets = false;
6586 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00006587 if (!Comp.U.IdentInfo)
6588 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00006589
Douglas Gregor882211c2010-04-28 22:16:22 +00006590 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006591
Douglas Gregord1702062010-04-29 00:18:15 +00006592 case Node::Base:
6593 // Will be recomputed during the rebuild.
6594 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00006595 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006596
Douglas Gregor882211c2010-04-28 22:16:22 +00006597 Components.push_back(Comp);
6598 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006599
Douglas Gregor882211c2010-04-28 22:16:22 +00006600 // If nothing changed, retain the existing expression.
6601 if (!getDerived().AlwaysRebuild() &&
6602 Type == E->getTypeSourceInfo() &&
6603 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00006604 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00006605
Douglas Gregor882211c2010-04-28 22:16:22 +00006606 // Build a new offsetof expression.
6607 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6608 Components.data(), Components.size(),
6609 E->getRParenLoc());
6610}
6611
6612template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006613ExprResult
John McCall8d69a212010-11-15 23:31:06 +00006614TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6615 assert(getDerived().AlreadyTransformed(E->getType()) &&
6616 "opaque value expression requires transformation");
6617 return SemaRef.Owned(E);
6618}
6619
6620template<typename Derived>
6621ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00006622TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00006623 // Rebuild the syntactic form. The original syntactic form has
6624 // opaque-value expressions in it, so strip those away and rebuild
6625 // the result. This is a really awful way of doing this, but the
6626 // better solution (rebuilding the semantic expressions and
6627 // rebinding OVEs as necessary) doesn't work; we'd need
6628 // TreeTransform to not strip away implicit conversions.
6629 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6630 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00006631 if (result.isInvalid()) return ExprError();
6632
6633 // If that gives us a pseudo-object result back, the pseudo-object
6634 // expression must have been an lvalue-to-rvalue conversion which we
6635 // should reapply.
6636 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6637 result = SemaRef.checkPseudoObjectRValue(result.take());
6638
6639 return result;
6640}
6641
6642template<typename Derived>
6643ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00006644TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6645 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006646 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00006647 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00006648
John McCallbcd03502009-12-07 02:54:59 +00006649 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00006650 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006651 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006652
John McCall4c98fd82009-11-04 07:28:41 +00006653 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00006654 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006655
Peter Collingbournee190dee2011-03-11 19:24:49 +00006656 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6657 E->getKind(),
6658 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006659 }
Mike Stump11289f42009-09-09 15:08:12 +00006660
Eli Friedmane4f22df2012-02-29 04:03:55 +00006661 // C++0x [expr.sizeof]p1:
6662 // The operand is either an expression, which is an unevaluated operand
6663 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00006664 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6665 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00006666
Eli Friedmane4f22df2012-02-29 04:03:55 +00006667 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6668 if (SubExpr.isInvalid())
6669 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006670
Eli Friedmane4f22df2012-02-29 04:03:55 +00006671 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6672 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006673
Peter Collingbournee190dee2011-03-11 19:24:49 +00006674 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6675 E->getOperatorLoc(),
6676 E->getKind(),
6677 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006678}
Mike Stump11289f42009-09-09 15:08:12 +00006679
Douglas Gregora16548e2009-08-11 05:31:07 +00006680template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006681ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006682TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006683 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006684 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006685 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006686
John McCalldadc5752010-08-24 06:29:42 +00006687 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006688 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006689 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006690
6691
Douglas Gregora16548e2009-08-11 05:31:07 +00006692 if (!getDerived().AlwaysRebuild() &&
6693 LHS.get() == E->getLHS() &&
6694 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006695 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006696
John McCallb268a282010-08-23 23:25:46 +00006697 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006698 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006699 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006700 E->getRBracketLoc());
6701}
Mike Stump11289f42009-09-09 15:08:12 +00006702
6703template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006704ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006705TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006706 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00006707 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006708 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006709 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006710
6711 // Transform arguments.
6712 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006713 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00006714 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00006715 &ArgChanged))
6716 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006717
Douglas Gregora16548e2009-08-11 05:31:07 +00006718 if (!getDerived().AlwaysRebuild() &&
6719 Callee.get() == E->getCallee() &&
6720 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00006721 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00006722
Douglas Gregora16548e2009-08-11 05:31:07 +00006723 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00006724 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006725 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00006726 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006727 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00006728 E->getRParenLoc());
6729}
Mike Stump11289f42009-09-09 15:08:12 +00006730
6731template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006732ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006733TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006734 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006735 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006736 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006737
Douglas Gregorea972d32011-02-28 21:54:11 +00006738 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006739 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006740 QualifierLoc
6741 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006742
Douglas Gregorea972d32011-02-28 21:54:11 +00006743 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006744 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006745 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00006746 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00006747
Eli Friedman2cfcef62009-12-04 06:40:45 +00006748 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006749 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6750 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006751 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00006752 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006753
John McCall16df1e52010-03-30 21:47:33 +00006754 NamedDecl *FoundDecl = E->getFoundDecl();
6755 if (FoundDecl == E->getMemberDecl()) {
6756 FoundDecl = Member;
6757 } else {
6758 FoundDecl = cast_or_null<NamedDecl>(
6759 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6760 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00006761 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00006762 }
6763
Douglas Gregora16548e2009-08-11 05:31:07 +00006764 if (!getDerived().AlwaysRebuild() &&
6765 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006766 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006767 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00006768 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00006769 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006770
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006771 // Mark it referenced in the new context regardless.
6772 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00006773 SemaRef.MarkMemberReferenced(E);
6774
John McCallc3007a22010-10-26 07:05:15 +00006775 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006776 }
Douglas Gregora16548e2009-08-11 05:31:07 +00006777
John McCall6b51f282009-11-23 01:53:49 +00006778 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00006779 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00006780 TransArgs.setLAngleLoc(E->getLAngleLoc());
6781 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006782 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6783 E->getNumTemplateArgs(),
6784 TransArgs))
6785 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006786 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006787
Douglas Gregora16548e2009-08-11 05:31:07 +00006788 // FIXME: Bogus source location for the operator
6789 SourceLocation FakeOperatorLoc
6790 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6791
John McCall38836f02010-01-15 08:34:02 +00006792 // FIXME: to do this check properly, we will need to preserve the
6793 // first-qualifier-in-scope here, just in case we had a dependent
6794 // base (and therefore couldn't do the check) and a
6795 // nested-name-qualifier (and therefore could do the lookup).
6796 NamedDecl *FirstQualifierInScope = 0;
6797
John McCallb268a282010-08-23 23:25:46 +00006798 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006799 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00006800 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00006801 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006802 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006803 Member,
John McCall16df1e52010-03-30 21:47:33 +00006804 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00006805 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00006806 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00006807 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00006808}
Mike Stump11289f42009-09-09 15:08:12 +00006809
Douglas Gregora16548e2009-08-11 05:31:07 +00006810template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006811ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006812TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006813 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006814 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006815 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006816
John McCalldadc5752010-08-24 06:29:42 +00006817 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006818 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006819 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006820
Douglas Gregora16548e2009-08-11 05:31:07 +00006821 if (!getDerived().AlwaysRebuild() &&
6822 LHS.get() == E->getLHS() &&
6823 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006824 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006825
Lang Hames5de91cc2012-10-02 04:45:10 +00006826 Sema::FPContractStateRAII FPContractState(getSema());
6827 getSema().FPFeatures.fp_contract = E->isFPContractable();
6828
Douglas Gregora16548e2009-08-11 05:31:07 +00006829 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006830 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006831}
6832
Mike Stump11289f42009-09-09 15:08:12 +00006833template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006834ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006835TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00006836 CompoundAssignOperator *E) {
6837 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006838}
Mike Stump11289f42009-09-09 15:08:12 +00006839
Douglas Gregora16548e2009-08-11 05:31:07 +00006840template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00006841ExprResult TreeTransform<Derived>::
6842TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6843 // Just rebuild the common and RHS expressions and see whether we
6844 // get any changes.
6845
6846 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6847 if (commonExpr.isInvalid())
6848 return ExprError();
6849
6850 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6851 if (rhs.isInvalid())
6852 return ExprError();
6853
6854 if (!getDerived().AlwaysRebuild() &&
6855 commonExpr.get() == e->getCommon() &&
6856 rhs.get() == e->getFalseExpr())
6857 return SemaRef.Owned(e);
6858
6859 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6860 e->getQuestionLoc(),
6861 0,
6862 e->getColonLoc(),
6863 rhs.get());
6864}
6865
6866template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006867ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006868TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006869 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006870 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006871 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006872
John McCalldadc5752010-08-24 06:29:42 +00006873 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006874 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006875 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006876
John McCalldadc5752010-08-24 06:29:42 +00006877 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006878 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006879 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006880
Douglas Gregora16548e2009-08-11 05:31:07 +00006881 if (!getDerived().AlwaysRebuild() &&
6882 Cond.get() == E->getCond() &&
6883 LHS.get() == E->getLHS() &&
6884 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006885 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006886
John McCallb268a282010-08-23 23:25:46 +00006887 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006888 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00006889 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006890 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006891 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006892}
Mike Stump11289f42009-09-09 15:08:12 +00006893
6894template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006895ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006896TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00006897 // Implicit casts are eliminated during transformation, since they
6898 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00006899 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006900}
Mike Stump11289f42009-09-09 15:08:12 +00006901
Douglas Gregora16548e2009-08-11 05:31:07 +00006902template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006903ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006904TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006905 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6906 if (!Type)
6907 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006908
John McCalldadc5752010-08-24 06:29:42 +00006909 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006910 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006911 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006912 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006913
Douglas Gregora16548e2009-08-11 05:31:07 +00006914 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006915 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006916 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006917 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006918
John McCall97513962010-01-15 18:39:57 +00006919 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006920 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006921 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006922 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006923}
Mike Stump11289f42009-09-09 15:08:12 +00006924
Douglas Gregora16548e2009-08-11 05:31:07 +00006925template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006926ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006927TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00006928 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6929 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6930 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006931 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006932
John McCalldadc5752010-08-24 06:29:42 +00006933 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00006934 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006935 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006936
Douglas Gregora16548e2009-08-11 05:31:07 +00006937 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00006938 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006939 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00006940 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006941
John McCall5d7aa7f2010-01-19 22:33:45 +00006942 // Note: the expression type doesn't necessarily match the
6943 // type-as-written, but that's okay, because it should always be
6944 // derivable from the initializer.
6945
John McCalle15bbff2010-01-18 19:35:47 +00006946 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00006947 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00006948 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006949}
Mike Stump11289f42009-09-09 15:08:12 +00006950
Douglas Gregora16548e2009-08-11 05:31:07 +00006951template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006952ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006953TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006954 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006955 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006956 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006957
Douglas Gregora16548e2009-08-11 05:31:07 +00006958 if (!getDerived().AlwaysRebuild() &&
6959 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006960 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006961
Douglas Gregora16548e2009-08-11 05:31:07 +00006962 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00006963 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006964 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00006965 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006966 E->getAccessorLoc(),
6967 E->getAccessor());
6968}
Mike Stump11289f42009-09-09 15:08:12 +00006969
Douglas Gregora16548e2009-08-11 05:31:07 +00006970template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006971ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006972TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006973 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00006974
Benjamin Kramerf0623432012-08-23 22:51:59 +00006975 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00006976 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00006977 Inits, &InitChanged))
6978 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006979
Douglas Gregora16548e2009-08-11 05:31:07 +00006980 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00006981 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006982
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006983 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00006984 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00006985}
Mike Stump11289f42009-09-09 15:08:12 +00006986
Douglas Gregora16548e2009-08-11 05:31:07 +00006987template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006988ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006989TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006990 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00006991
Douglas Gregorebe10102009-08-20 07:17:43 +00006992 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00006993 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006994 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006995 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006996
Douglas Gregorebe10102009-08-20 07:17:43 +00006997 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00006998 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00006999 bool ExprChanged = false;
7000 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
7001 DEnd = E->designators_end();
7002 D != DEnd; ++D) {
7003 if (D->isFieldDesignator()) {
7004 Desig.AddDesignator(Designator::getField(D->getFieldName(),
7005 D->getDotLoc(),
7006 D->getFieldLoc()));
7007 continue;
7008 }
Mike Stump11289f42009-09-09 15:08:12 +00007009
Douglas Gregora16548e2009-08-11 05:31:07 +00007010 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00007011 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007012 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007013 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007014
7015 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007016 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007017
Douglas Gregora16548e2009-08-11 05:31:07 +00007018 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
7019 ArrayExprs.push_back(Index.release());
7020 continue;
7021 }
Mike Stump11289f42009-09-09 15:08:12 +00007022
Douglas Gregora16548e2009-08-11 05:31:07 +00007023 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00007024 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00007025 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7026 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007027 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007028
John McCalldadc5752010-08-24 06:29:42 +00007029 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007030 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007031 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007032
7033 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007034 End.get(),
7035 D->getLBracketLoc(),
7036 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007037
Douglas Gregora16548e2009-08-11 05:31:07 +00007038 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7039 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00007040
Douglas Gregora16548e2009-08-11 05:31:07 +00007041 ArrayExprs.push_back(Start.release());
7042 ArrayExprs.push_back(End.release());
7043 }
Mike Stump11289f42009-09-09 15:08:12 +00007044
Douglas Gregora16548e2009-08-11 05:31:07 +00007045 if (!getDerived().AlwaysRebuild() &&
7046 Init.get() == E->getInit() &&
7047 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00007048 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007049
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007050 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007051 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007052 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007053}
Mike Stump11289f42009-09-09 15:08:12 +00007054
Douglas Gregora16548e2009-08-11 05:31:07 +00007055template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007056ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007057TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007058 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00007059 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00007060
Douglas Gregor3da3c062009-10-28 00:29:27 +00007061 // FIXME: Will we ever have proper type location here? Will we actually
7062 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00007063 QualType T = getDerived().TransformType(E->getType());
7064 if (T.isNull())
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() &&
7068 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00007069 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007070
Douglas Gregora16548e2009-08-11 05:31:07 +00007071 return getDerived().RebuildImplicitValueInitExpr(T);
7072}
Mike Stump11289f42009-09-09 15:08:12 +00007073
Douglas Gregora16548e2009-08-11 05:31:07 +00007074template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007075ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007076TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00007077 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7078 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007079 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007080
John McCalldadc5752010-08-24 06:29:42 +00007081 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007082 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007083 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007084
Douglas Gregora16548e2009-08-11 05:31:07 +00007085 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00007086 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007087 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007088 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007089
John McCallb268a282010-08-23 23:25:46 +00007090 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00007091 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007092}
7093
7094template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007095ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007096TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007097 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007098 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00007099 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7100 &ArgumentChanged))
7101 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007102
Douglas Gregora16548e2009-08-11 05:31:07 +00007103 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007104 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00007105 E->getRParenLoc());
7106}
Mike Stump11289f42009-09-09 15:08:12 +00007107
Douglas Gregora16548e2009-08-11 05:31:07 +00007108/// \brief Transform an address-of-label expression.
7109///
7110/// By default, the transformation of an address-of-label expression always
7111/// rebuilds the expression, so that the label identifier can be resolved to
7112/// the corresponding label statement by semantic analysis.
7113template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007114ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007115TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00007116 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7117 E->getLabel());
7118 if (!LD)
7119 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007120
Douglas Gregora16548e2009-08-11 05:31:07 +00007121 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00007122 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00007123}
Mike Stump11289f42009-09-09 15:08:12 +00007124
7125template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00007126ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007127TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00007128 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00007129 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00007130 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00007131 if (SubStmt.isInvalid()) {
7132 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00007133 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00007134 }
Mike Stump11289f42009-09-09 15:08:12 +00007135
Douglas Gregora16548e2009-08-11 05:31:07 +00007136 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00007137 SubStmt.get() == E->getSubStmt()) {
7138 // Calling this an 'error' is unintuitive, but it does the right thing.
7139 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007140 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00007141 }
Mike Stump11289f42009-09-09 15:08:12 +00007142
7143 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007144 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007145 E->getRParenLoc());
7146}
Mike Stump11289f42009-09-09 15:08:12 +00007147
Douglas Gregora16548e2009-08-11 05:31:07 +00007148template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007149ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007150TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007151 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007152 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007153 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007154
John McCalldadc5752010-08-24 06:29:42 +00007155 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007156 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007157 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007158
John McCalldadc5752010-08-24 06:29:42 +00007159 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007160 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007161 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007162
Douglas Gregora16548e2009-08-11 05:31:07 +00007163 if (!getDerived().AlwaysRebuild() &&
7164 Cond.get() == E->getCond() &&
7165 LHS.get() == E->getLHS() &&
7166 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00007167 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007168
Douglas Gregora16548e2009-08-11 05:31:07 +00007169 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00007170 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007171 E->getRParenLoc());
7172}
Mike Stump11289f42009-09-09 15:08:12 +00007173
Douglas Gregora16548e2009-08-11 05:31:07 +00007174template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007175ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007176TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007177 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007178}
7179
7180template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007181ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007182TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007183 switch (E->getOperator()) {
7184 case OO_New:
7185 case OO_Delete:
7186 case OO_Array_New:
7187 case OO_Array_Delete:
7188 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00007189
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007190 case OO_Call: {
7191 // This is a call to an object's operator().
7192 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7193
7194 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00007195 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007196 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007197 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007198
7199 // FIXME: Poor location information
7200 SourceLocation FakeLParenLoc
7201 = SemaRef.PP.getLocForEndOfToken(
7202 static_cast<Expr *>(Object.get())->getLocEnd());
7203
7204 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007205 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007206 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00007207 Args))
7208 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007209
John McCallb268a282010-08-23 23:25:46 +00007210 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007211 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007212 E->getLocEnd());
7213 }
7214
7215#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7216 case OO_##Name:
7217#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7218#include "clang/Basic/OperatorKinds.def"
7219 case OO_Subscript:
7220 // Handled below.
7221 break;
7222
7223 case OO_Conditional:
7224 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007225
7226 case OO_None:
7227 case NUM_OVERLOADED_OPERATORS:
7228 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007229 }
7230
John McCalldadc5752010-08-24 06:29:42 +00007231 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007232 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007233 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007234
Richard Smithdb2630f2012-10-21 03:28:35 +00007235 ExprResult First;
7236 if (E->getOperator() == OO_Amp)
7237 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7238 else
7239 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007240 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007241 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007242
John McCalldadc5752010-08-24 06:29:42 +00007243 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00007244 if (E->getNumArgs() == 2) {
7245 Second = getDerived().TransformExpr(E->getArg(1));
7246 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007247 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007248 }
Mike Stump11289f42009-09-09 15:08:12 +00007249
Douglas Gregora16548e2009-08-11 05:31:07 +00007250 if (!getDerived().AlwaysRebuild() &&
7251 Callee.get() == E->getCallee() &&
7252 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00007253 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007254 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007255
Lang Hames5de91cc2012-10-02 04:45:10 +00007256 Sema::FPContractStateRAII FPContractState(getSema());
7257 getSema().FPFeatures.fp_contract = E->isFPContractable();
7258
Douglas Gregora16548e2009-08-11 05:31:07 +00007259 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7260 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00007261 Callee.get(),
7262 First.get(),
7263 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007264}
Mike Stump11289f42009-09-09 15:08:12 +00007265
Douglas Gregora16548e2009-08-11 05:31:07 +00007266template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007267ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007268TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7269 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007270}
Mike Stump11289f42009-09-09 15:08:12 +00007271
Douglas Gregora16548e2009-08-11 05:31:07 +00007272template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007273ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00007274TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7275 // Transform the callee.
7276 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7277 if (Callee.isInvalid())
7278 return ExprError();
7279
7280 // Transform exec config.
7281 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7282 if (EC.isInvalid())
7283 return ExprError();
7284
7285 // Transform arguments.
7286 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007287 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007288 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007289 &ArgChanged))
7290 return ExprError();
7291
7292 if (!getDerived().AlwaysRebuild() &&
7293 Callee.get() == E->getCallee() &&
7294 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007295 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00007296
7297 // FIXME: Wrong source location information for the '('.
7298 SourceLocation FakeLParenLoc
7299 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7300 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007301 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007302 E->getRParenLoc(), EC.get());
7303}
7304
7305template<typename Derived>
7306ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007307TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007308 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7309 if (!Type)
7310 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007311
John McCalldadc5752010-08-24 06:29:42 +00007312 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007313 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007314 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007315 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007316
Douglas Gregora16548e2009-08-11 05:31:07 +00007317 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007318 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007319 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007320 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007321 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00007322 E->getStmtClass(),
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007323 E->getAngleBrackets().getBegin(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007324 Type,
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007325 E->getAngleBrackets().getEnd(),
7326 // FIXME. this should be '(' location
7327 E->getAngleBrackets().getEnd(),
John McCallb268a282010-08-23 23:25:46 +00007328 SubExpr.get(),
Abramo Bagnara9fb43862012-10-15 21:08:58 +00007329 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007330}
Mike Stump11289f42009-09-09 15:08:12 +00007331
Douglas Gregora16548e2009-08-11 05:31:07 +00007332template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007333ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007334TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7335 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007336}
Mike Stump11289f42009-09-09 15:08:12 +00007337
7338template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007339ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007340TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7341 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00007342}
7343
Douglas Gregora16548e2009-08-11 05:31:07 +00007344template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007345ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007346TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007347 CXXReinterpretCastExpr *E) {
7348 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007349}
Mike Stump11289f42009-09-09 15:08:12 +00007350
Douglas Gregora16548e2009-08-11 05:31:07 +00007351template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007352ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007353TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7354 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007355}
Mike Stump11289f42009-09-09 15:08:12 +00007356
Douglas Gregora16548e2009-08-11 05:31:07 +00007357template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007358ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007359TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007360 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007361 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7362 if (!Type)
7363 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007364
John McCalldadc5752010-08-24 06:29:42 +00007365 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007366 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007367 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007368 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007369
Douglas Gregora16548e2009-08-11 05:31:07 +00007370 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007371 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007372 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007373 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007374
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007375 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00007376 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007377 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007378 E->getRParenLoc());
7379}
Mike Stump11289f42009-09-09 15:08:12 +00007380
Douglas Gregora16548e2009-08-11 05:31:07 +00007381template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007382ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007383TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007384 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00007385 TypeSourceInfo *TInfo
7386 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7387 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007388 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007389
Douglas Gregora16548e2009-08-11 05:31:07 +00007390 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00007391 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007392 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007393
Douglas Gregor9da64192010-04-26 22:37:10 +00007394 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7395 E->getLocStart(),
7396 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007397 E->getLocEnd());
7398 }
Mike Stump11289f42009-09-09 15:08:12 +00007399
Eli Friedman456f0182012-01-20 01:26:23 +00007400 // We don't know whether the subexpression is potentially evaluated until
7401 // after we perform semantic analysis. We speculatively assume it is
7402 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00007403 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00007404 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7405 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007406
John McCalldadc5752010-08-24 06:29:42 +00007407 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00007408 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007409 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007410
Douglas Gregora16548e2009-08-11 05:31:07 +00007411 if (!getDerived().AlwaysRebuild() &&
7412 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00007413 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007414
Douglas Gregor9da64192010-04-26 22:37:10 +00007415 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7416 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007417 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007418 E->getLocEnd());
7419}
7420
7421template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007422ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00007423TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7424 if (E->isTypeOperand()) {
7425 TypeSourceInfo *TInfo
7426 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7427 if (!TInfo)
7428 return ExprError();
7429
7430 if (!getDerived().AlwaysRebuild() &&
7431 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007432 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00007433
Douglas Gregor69735112011-03-06 17:40:41 +00007434 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00007435 E->getLocStart(),
7436 TInfo,
7437 E->getLocEnd());
7438 }
7439
Francois Pichet9f4f2072010-09-08 12:20:18 +00007440 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7441
7442 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7443 if (SubExpr.isInvalid())
7444 return ExprError();
7445
7446 if (!getDerived().AlwaysRebuild() &&
7447 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00007448 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00007449
7450 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7451 E->getLocStart(),
7452 SubExpr.get(),
7453 E->getLocEnd());
7454}
7455
7456template<typename Derived>
7457ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007458TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007459 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007460}
Mike Stump11289f42009-09-09 15:08:12 +00007461
Douglas Gregora16548e2009-08-11 05:31:07 +00007462template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007463ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007464TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007465 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007466 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007467}
Mike Stump11289f42009-09-09 15:08:12 +00007468
Douglas Gregora16548e2009-08-11 05:31:07 +00007469template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007470ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007471TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00007472 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00007473
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007474 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7475 // Make sure that we capture 'this'.
7476 getSema().CheckCXXThisCapture(E->getLocStart());
John McCallc3007a22010-10-26 07:05:15 +00007477 return SemaRef.Owned(E);
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007478 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007479
Douglas Gregorb15af892010-01-07 23:12:05 +00007480 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007481}
Mike Stump11289f42009-09-09 15:08:12 +00007482
Douglas Gregora16548e2009-08-11 05:31:07 +00007483template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007484ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007485TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007486 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007487 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007488 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007489
Douglas Gregora16548e2009-08-11 05:31:07 +00007490 if (!getDerived().AlwaysRebuild() &&
7491 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007492 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007493
Douglas Gregor53e191ed2011-07-06 22:04:06 +00007494 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7495 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00007496}
Mike Stump11289f42009-09-09 15:08:12 +00007497
Douglas Gregora16548e2009-08-11 05:31:07 +00007498template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007499ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007500TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00007501 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007502 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7503 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007504 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00007505 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007506
Chandler Carruth794da4c2010-02-08 06:42:49 +00007507 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007508 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00007509 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007510
Douglas Gregor033f6752009-12-23 23:03:06 +00007511 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00007512}
Mike Stump11289f42009-09-09 15:08:12 +00007513
Douglas Gregora16548e2009-08-11 05:31:07 +00007514template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007515ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00007516TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
7517 FieldDecl *Field
7518 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
7519 E->getField()));
7520 if (!Field)
7521 return ExprError();
7522
7523 if (!getDerived().AlwaysRebuild() && Field == E->getField())
7524 return SemaRef.Owned(E);
7525
7526 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
7527}
7528
7529template<typename Derived>
7530ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00007531TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7532 CXXScalarValueInitExpr *E) {
7533 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7534 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007535 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007536
Douglas Gregora16548e2009-08-11 05:31:07 +00007537 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007538 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007539 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007540
Chad Rosier1dcde962012-08-08 18:46:20 +00007541 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00007542 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00007543 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007544}
Mike Stump11289f42009-09-09 15:08:12 +00007545
Douglas Gregora16548e2009-08-11 05:31:07 +00007546template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007547ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007548TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007549 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00007550 TypeSourceInfo *AllocTypeInfo
7551 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7552 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007553 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007554
Douglas Gregora16548e2009-08-11 05:31:07 +00007555 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00007556 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00007557 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007558 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007559
Douglas Gregora16548e2009-08-11 05:31:07 +00007560 // Transform the placement arguments (if any).
7561 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007562 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00007563 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00007564 E->getNumPlacementArgs(), true,
7565 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00007566 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007567
Sebastian Redl6047f072012-02-16 12:22:20 +00007568 // Transform the initializer (if any).
7569 Expr *OldInit = E->getInitializer();
7570 ExprResult NewInit;
7571 if (OldInit)
7572 NewInit = getDerived().TransformExpr(OldInit);
7573 if (NewInit.isInvalid())
7574 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007575
Sebastian Redl6047f072012-02-16 12:22:20 +00007576 // Transform new operator and delete operator.
Douglas Gregord2d9da02010-02-26 00:38:10 +00007577 FunctionDecl *OperatorNew = 0;
7578 if (E->getOperatorNew()) {
7579 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007580 getDerived().TransformDecl(E->getLocStart(),
7581 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007582 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00007583 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007584 }
7585
7586 FunctionDecl *OperatorDelete = 0;
7587 if (E->getOperatorDelete()) {
7588 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007589 getDerived().TransformDecl(E->getLocStart(),
7590 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007591 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007592 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007593 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007594
Douglas Gregora16548e2009-08-11 05:31:07 +00007595 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00007596 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007597 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00007598 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007599 OperatorNew == E->getOperatorNew() &&
7600 OperatorDelete == E->getOperatorDelete() &&
7601 !ArgumentChanged) {
7602 // Mark any declarations we need as referenced.
7603 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00007604 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007605 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007606 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007607 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00007608
Sebastian Redl6047f072012-02-16 12:22:20 +00007609 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00007610 QualType ElementType
7611 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7612 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7613 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7614 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00007615 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00007616 }
7617 }
7618 }
Sebastian Redl6047f072012-02-16 12:22:20 +00007619
John McCallc3007a22010-10-26 07:05:15 +00007620 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007621 }
Mike Stump11289f42009-09-09 15:08:12 +00007622
Douglas Gregor0744ef62010-09-07 21:49:58 +00007623 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007624 if (!ArraySize.get()) {
7625 // If no array size was specified, but the new expression was
7626 // instantiated with an array type (e.g., "new T" where T is
7627 // instantiated with "int[4]"), extract the outer bound from the
7628 // array type as our array size. We do this with constant and
7629 // dependently-sized array types.
7630 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7631 if (!ArrayT) {
7632 // Do nothing
7633 } else if (const ConstantArrayType *ConsArrayT
7634 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007635 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007636 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier1dcde962012-08-08 18:46:20 +00007637 ConsArrayT->getSize(),
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007638 SemaRef.Context.getSizeType(),
7639 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007640 AllocType = ConsArrayT->getElementType();
7641 } else if (const DependentSizedArrayType *DepArrayT
7642 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7643 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00007644 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007645 AllocType = DepArrayT->getElementType();
7646 }
7647 }
7648 }
Sebastian Redl6047f072012-02-16 12:22:20 +00007649
Douglas Gregora16548e2009-08-11 05:31:07 +00007650 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7651 E->isGlobalNew(),
7652 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007653 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007654 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00007655 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007656 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00007657 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00007658 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00007659 E->getDirectInitRange(),
7660 NewInit.take());
Douglas Gregora16548e2009-08-11 05:31:07 +00007661}
Mike Stump11289f42009-09-09 15:08:12 +00007662
Douglas Gregora16548e2009-08-11 05:31:07 +00007663template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007664ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007665TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007666 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00007667 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007668 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007669
Douglas Gregord2d9da02010-02-26 00:38:10 +00007670 // Transform the delete operator, if known.
7671 FunctionDecl *OperatorDelete = 0;
7672 if (E->getOperatorDelete()) {
7673 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007674 getDerived().TransformDecl(E->getLocStart(),
7675 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007676 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007677 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007678 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007679
Douglas Gregora16548e2009-08-11 05:31:07 +00007680 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007681 Operand.get() == E->getArgument() &&
7682 OperatorDelete == E->getOperatorDelete()) {
7683 // Mark any declarations we need as referenced.
7684 // FIXME: instantiation-specific.
7685 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007686 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00007687
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00007688 if (!E->getArgument()->isTypeDependent()) {
7689 QualType Destroyed = SemaRef.Context.getBaseElementType(
7690 E->getDestroyedType());
7691 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7692 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00007693 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00007694 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00007695 }
7696 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007697
John McCallc3007a22010-10-26 07:05:15 +00007698 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007699 }
Mike Stump11289f42009-09-09 15:08:12 +00007700
Douglas Gregora16548e2009-08-11 05:31:07 +00007701 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7702 E->isGlobalDelete(),
7703 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00007704 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007705}
Mike Stump11289f42009-09-09 15:08:12 +00007706
Douglas Gregora16548e2009-08-11 05:31:07 +00007707template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007708ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00007709TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007710 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007711 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00007712 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007713 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007714
John McCallba7bf592010-08-24 05:47:05 +00007715 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00007716 bool MayBePseudoDestructor = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00007717 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007718 E->getOperatorLoc(),
7719 E->isArrow()? tok::arrow : tok::period,
7720 ObjectTypePtr,
7721 MayBePseudoDestructor);
7722 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007723 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007724
John McCallba7bf592010-08-24 05:47:05 +00007725 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00007726 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7727 if (QualifierLoc) {
7728 QualifierLoc
7729 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7730 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00007731 return ExprError();
7732 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00007733 CXXScopeSpec SS;
7734 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00007735
Douglas Gregor678f90d2010-02-25 01:56:36 +00007736 PseudoDestructorTypeStorage Destroyed;
7737 if (E->getDestroyedTypeInfo()) {
7738 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00007739 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00007740 ObjectType, 0, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00007741 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007742 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00007743 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00007744 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00007745 // We aren't likely to be able to resolve the identifier down to a type
7746 // now anyway, so just retain the identifier.
7747 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7748 E->getDestroyedTypeLoc());
7749 } else {
7750 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00007751 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007752 *E->getDestroyedTypeIdentifier(),
7753 E->getDestroyedTypeLoc(),
7754 /*Scope=*/0,
7755 SS, ObjectTypePtr,
7756 false);
7757 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007758 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007759
Douglas Gregor678f90d2010-02-25 01:56:36 +00007760 Destroyed
7761 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7762 E->getDestroyedTypeLoc());
7763 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007764
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007765 TypeSourceInfo *ScopeTypeInfo = 0;
7766 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00007767 CXXScopeSpec EmptySS;
7768 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
7769 E->getScopeTypeInfo(), ObjectType, 0, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007770 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007771 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00007772 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007773
John McCallb268a282010-08-23 23:25:46 +00007774 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00007775 E->getOperatorLoc(),
7776 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00007777 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007778 ScopeTypeInfo,
7779 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007780 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007781 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00007782}
Mike Stump11289f42009-09-09 15:08:12 +00007783
Douglas Gregorad8a3362009-09-04 17:36:40 +00007784template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007785ExprResult
John McCalld14a8642009-11-21 08:51:07 +00007786TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007787 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00007788 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7789 Sema::LookupOrdinaryName);
7790
7791 // Transform all the decls.
7792 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7793 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007794 NamedDecl *InstD = static_cast<NamedDecl*>(
7795 getDerived().TransformDecl(Old->getNameLoc(),
7796 *I));
John McCall84d87672009-12-10 09:41:52 +00007797 if (!InstD) {
7798 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7799 // This can happen because of dependent hiding.
7800 if (isa<UsingShadowDecl>(*I))
7801 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00007802 else {
7803 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007804 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00007805 }
John McCall84d87672009-12-10 09:41:52 +00007806 }
John McCalle66edc12009-11-24 19:00:30 +00007807
7808 // Expand using declarations.
7809 if (isa<UsingDecl>(InstD)) {
7810 UsingDecl *UD = cast<UsingDecl>(InstD);
7811 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7812 E = UD->shadow_end(); I != E; ++I)
7813 R.addDecl(*I);
7814 continue;
7815 }
7816
7817 R.addDecl(InstD);
7818 }
7819
7820 // Resolve a kind, but don't do any further analysis. If it's
7821 // ambiguous, the callee needs to deal with it.
7822 R.resolveKind();
7823
7824 // Rebuild the nested-name qualifier, if present.
7825 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00007826 if (Old->getQualifierLoc()) {
7827 NestedNameSpecifierLoc QualifierLoc
7828 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7829 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007830 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007831
Douglas Gregor0da1d432011-02-28 20:01:57 +00007832 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00007833 }
7834
Douglas Gregor9262f472010-04-27 18:19:34 +00007835 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00007836 CXXRecordDecl *NamingClass
7837 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7838 Old->getNameLoc(),
7839 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00007840 if (!NamingClass) {
7841 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007842 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00007843 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007844
Douglas Gregorda7be082010-04-27 16:10:10 +00007845 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00007846 }
7847
Abramo Bagnara7945c982012-01-27 09:46:47 +00007848 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7849
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00007850 // If we have neither explicit template arguments, nor the template keyword,
7851 // it's a normal declaration name.
7852 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCalle66edc12009-11-24 19:00:30 +00007853 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7854
7855 // If we have template arguments, rebuild them, then rebuild the
7856 // templateid expression.
7857 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00007858 if (Old->hasExplicitTemplateArgs() &&
7859 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00007860 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00007861 TransArgs)) {
7862 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00007863 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00007864 }
John McCalle66edc12009-11-24 19:00:30 +00007865
Abramo Bagnara7945c982012-01-27 09:46:47 +00007866 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00007867 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007868}
Mike Stump11289f42009-09-09 15:08:12 +00007869
Douglas Gregora16548e2009-08-11 05:31:07 +00007870template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007871ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00007872TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7873 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00007874 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00007875 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7876 TypeSourceInfo *From = E->getArg(I);
7877 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00007878 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00007879 TypeLocBuilder TLB;
7880 TLB.reserve(FromTL.getFullDataSize());
7881 QualType To = getDerived().TransformType(TLB, FromTL);
7882 if (To.isNull())
7883 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007884
Douglas Gregor29c42f22012-02-24 07:38:34 +00007885 if (To == From->getType())
7886 Args.push_back(From);
7887 else {
7888 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7889 ArgChanged = true;
7890 }
7891 continue;
7892 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007893
Douglas Gregor29c42f22012-02-24 07:38:34 +00007894 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00007895
Douglas Gregor29c42f22012-02-24 07:38:34 +00007896 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00007897 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00007898 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7899 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7900 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00007901
Douglas Gregor29c42f22012-02-24 07:38:34 +00007902 // Determine whether the set of unexpanded parameter packs can and should
7903 // be expanded.
7904 bool Expand = true;
7905 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00007906 Optional<unsigned> OrigNumExpansions =
7907 ExpansionTL.getTypePtr()->getNumExpansions();
7908 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00007909 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7910 PatternTL.getSourceRange(),
7911 Unexpanded,
7912 Expand, RetainExpansion,
7913 NumExpansions))
7914 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007915
Douglas Gregor29c42f22012-02-24 07:38:34 +00007916 if (!Expand) {
7917 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00007918 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00007919 // expansion.
7920 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00007921
Douglas Gregor29c42f22012-02-24 07:38:34 +00007922 TypeLocBuilder TLB;
7923 TLB.reserve(From->getTypeLoc().getFullDataSize());
7924
7925 QualType To = getDerived().TransformType(TLB, PatternTL);
7926 if (To.isNull())
7927 return ExprError();
7928
Chad Rosier1dcde962012-08-08 18:46:20 +00007929 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00007930 PatternTL.getSourceRange(),
7931 ExpansionTL.getEllipsisLoc(),
7932 NumExpansions);
7933 if (To.isNull())
7934 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007935
Douglas Gregor29c42f22012-02-24 07:38:34 +00007936 PackExpansionTypeLoc ToExpansionTL
7937 = TLB.push<PackExpansionTypeLoc>(To);
7938 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7939 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7940 continue;
7941 }
7942
7943 // Expand the pack expansion by substituting for each argument in the
7944 // pack(s).
7945 for (unsigned I = 0; I != *NumExpansions; ++I) {
7946 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7947 TypeLocBuilder TLB;
7948 TLB.reserve(PatternTL.getFullDataSize());
7949 QualType To = getDerived().TransformType(TLB, PatternTL);
7950 if (To.isNull())
7951 return ExprError();
7952
Eli Friedman5e05c4a2013-07-19 21:49:32 +00007953 if (To->containsUnexpandedParameterPack()) {
7954 To = getDerived().RebuildPackExpansionType(To,
7955 PatternTL.getSourceRange(),
7956 ExpansionTL.getEllipsisLoc(),
7957 NumExpansions);
7958 if (To.isNull())
7959 return ExprError();
7960
7961 PackExpansionTypeLoc ToExpansionTL
7962 = TLB.push<PackExpansionTypeLoc>(To);
7963 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7964 }
7965
Douglas Gregor29c42f22012-02-24 07:38:34 +00007966 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7967 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007968
Douglas Gregor29c42f22012-02-24 07:38:34 +00007969 if (!RetainExpansion)
7970 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00007971
Douglas Gregor29c42f22012-02-24 07:38:34 +00007972 // If we're supposed to retain a pack expansion, do so by temporarily
7973 // forgetting the partially-substituted parameter pack.
7974 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7975
7976 TypeLocBuilder TLB;
7977 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00007978
Douglas Gregor29c42f22012-02-24 07:38:34 +00007979 QualType To = getDerived().TransformType(TLB, PatternTL);
7980 if (To.isNull())
7981 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007982
7983 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00007984 PatternTL.getSourceRange(),
7985 ExpansionTL.getEllipsisLoc(),
7986 NumExpansions);
7987 if (To.isNull())
7988 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007989
Douglas Gregor29c42f22012-02-24 07:38:34 +00007990 PackExpansionTypeLoc ToExpansionTL
7991 = TLB.push<PackExpansionTypeLoc>(To);
7992 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7993 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7994 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007995
Douglas Gregor29c42f22012-02-24 07:38:34 +00007996 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7997 return SemaRef.Owned(E);
7998
7999 return getDerived().RebuildTypeTrait(E->getTrait(),
8000 E->getLocStart(),
8001 Args,
8002 E->getLocEnd());
8003}
8004
8005template<typename Derived>
8006ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00008007TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8008 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
8009 if (!T)
8010 return ExprError();
8011
8012 if (!getDerived().AlwaysRebuild() &&
8013 T == E->getQueriedTypeSourceInfo())
8014 return SemaRef.Owned(E);
8015
8016 ExprResult SubExpr;
8017 {
8018 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8019 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8020 if (SubExpr.isInvalid())
8021 return ExprError();
8022
8023 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
8024 return SemaRef.Owned(E);
8025 }
8026
8027 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8028 E->getLocStart(),
8029 T,
8030 SubExpr.get(),
8031 E->getLocEnd());
8032}
8033
8034template<typename Derived>
8035ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00008036TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8037 ExprResult SubExpr;
8038 {
8039 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8040 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8041 if (SubExpr.isInvalid())
8042 return ExprError();
8043
8044 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
8045 return SemaRef.Owned(E);
8046 }
8047
8048 return getDerived().RebuildExpressionTrait(
8049 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8050}
8051
8052template<typename Derived>
8053ExprResult
John McCall8cd78132009-11-19 22:55:06 +00008054TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008055 DependentScopeDeclRefExpr *E) {
Richard Smithdb2630f2012-10-21 03:28:35 +00008056 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
8057}
8058
8059template<typename Derived>
8060ExprResult
8061TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8062 DependentScopeDeclRefExpr *E,
8063 bool IsAddressOfOperand) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00008064 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008065 NestedNameSpecifierLoc QualifierLoc
8066 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8067 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008068 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00008069 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008070
John McCall31f82722010-11-12 08:19:04 +00008071 // TODO: If this is a conversion-function-id, verify that the
8072 // destination type name (if present) resolves the same way after
8073 // instantiation as it did in the local scope.
8074
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008075 DeclarationNameInfo NameInfo
8076 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8077 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008078 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008079
John McCalle66edc12009-11-24 19:00:30 +00008080 if (!E->hasExplicitTemplateArgs()) {
8081 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008082 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008083 // Note: it is sufficient to compare the Name component of NameInfo:
8084 // if name has not changed, DNLoc has not changed either.
8085 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00008086 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00008087
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008088 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008089 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008090 NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00008091 /*TemplateArgs*/ 0,
8092 IsAddressOfOperand);
Douglas Gregord019ff62009-10-22 17:20:55 +00008093 }
John McCall6b51f282009-11-23 01:53:49 +00008094
8095 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008096 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8097 E->getNumTemplateArgs(),
8098 TransArgs))
8099 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008100
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008101 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008102 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008103 NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00008104 &TransArgs,
8105 IsAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00008106}
8107
8108template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008109ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008110TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00008111 // CXXConstructExprs other than for list-initialization and
8112 // CXXTemporaryObjectExpr are always implicit, so when we have
8113 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00008114 if ((E->getNumArgs() == 1 ||
8115 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00008116 (!getDerived().DropCallArgument(E->getArg(0))) &&
8117 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00008118 return getDerived().TransformExpr(E->getArg(0));
8119
Douglas Gregora16548e2009-08-11 05:31:07 +00008120 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8121
8122 QualType T = getDerived().TransformType(E->getType());
8123 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008124 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008125
8126 CXXConstructorDecl *Constructor
8127 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008128 getDerived().TransformDecl(E->getLocStart(),
8129 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008130 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008131 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008132
Douglas Gregora16548e2009-08-11 05:31:07 +00008133 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008134 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008135 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008136 &ArgumentChanged))
8137 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008138
Douglas Gregora16548e2009-08-11 05:31:07 +00008139 if (!getDerived().AlwaysRebuild() &&
8140 T == E->getType() &&
8141 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00008142 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00008143 // Mark the constructor as referenced.
8144 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008145 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00008146 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00008147 }
Mike Stump11289f42009-09-09 15:08:12 +00008148
Douglas Gregordb121ba2009-12-14 16:27:04 +00008149 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8150 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008151 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00008152 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00008153 E->isListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00008154 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00008155 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00008156 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008157}
Mike Stump11289f42009-09-09 15:08:12 +00008158
Douglas Gregora16548e2009-08-11 05:31:07 +00008159/// \brief Transform a C++ temporary-binding expression.
8160///
Douglas Gregor363b1512009-12-24 18:51:59 +00008161/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8162/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008163template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008164ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008165TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008166 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008167}
Mike Stump11289f42009-09-09 15:08:12 +00008168
John McCall5d413782010-12-06 08:20:24 +00008169/// \brief Transform a C++ expression that contains cleanups that should
8170/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00008171///
John McCall5d413782010-12-06 08:20:24 +00008172/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00008173/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008174template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008175ExprResult
John McCall5d413782010-12-06 08:20:24 +00008176TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008177 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008178}
Mike Stump11289f42009-09-09 15:08:12 +00008179
Douglas Gregora16548e2009-08-11 05:31:07 +00008180template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008181ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008182TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00008183 CXXTemporaryObjectExpr *E) {
8184 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8185 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008186 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008187
Douglas Gregora16548e2009-08-11 05:31:07 +00008188 CXXConstructorDecl *Constructor
8189 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00008190 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008191 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008192 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008193 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008194
Douglas Gregora16548e2009-08-11 05:31:07 +00008195 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008196 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00008197 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00008198 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008199 &ArgumentChanged))
8200 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008201
Douglas Gregora16548e2009-08-11 05:31:07 +00008202 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008203 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008204 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008205 !ArgumentChanged) {
8206 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008207 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00008208 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008209 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008210
Richard Smithd59b8322012-12-19 01:39:02 +00008211 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00008212 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8213 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008214 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008215 E->getLocEnd());
8216}
Mike Stump11289f42009-09-09 15:08:12 +00008217
Douglas Gregora16548e2009-08-11 05:31:07 +00008218template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008219ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00008220TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008221
8222 // Transform any init-capture expressions before entering the scope of the
8223 // lambda body, because they are not semantically within that scope.
8224 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
8225 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
8226 E->explicit_capture_begin());
8227
8228 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8229 CEnd = E->capture_end();
8230 C != CEnd; ++C) {
8231 if (!C->isInitCapture())
8232 continue;
8233 EnterExpressionEvaluationContext EEEC(getSema(),
8234 Sema::PotentiallyEvaluated);
8235 ExprResult NewExprInitResult = getDerived().TransformInitializer(
8236 C->getCapturedVar()->getInit(),
8237 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
8238
8239 if (NewExprInitResult.isInvalid())
8240 return ExprError();
8241 Expr *NewExprInit = NewExprInitResult.get();
8242
8243 VarDecl *OldVD = C->getCapturedVar();
8244 QualType NewInitCaptureType =
8245 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
8246 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
8247 NewExprInit);
8248 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008249 InitCaptureExprsAndTypes[C - E->capture_begin()] =
8250 std::make_pair(NewExprInitResult, NewInitCaptureType);
8251
8252 }
8253
Faisal Vali524ca282013-11-12 01:40:44 +00008254 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
Faisal Vali2cba1332013-10-23 06:44:28 +00008255 // Transform the template parameters, and add them to the current
8256 // instantiation scope. The null case is handled correctly.
8257 LSI->GLTemplateParameterList = getDerived().TransformTemplateParameterList(
8258 E->getTemplateParameterList());
8259
8260 // Check to see if the TypeSourceInfo of the call operator needs to
8261 // be transformed, and if so do the transformation in the
8262 // CurrentInstantiationScope.
8263
8264 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
8265 FunctionProtoTypeLoc OldCallOpFPTL =
8266 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
8267 TypeSourceInfo *NewCallOpTSI = 0;
8268
8269 const bool CallOpWasAlreadyTransformed =
8270 getDerived().AlreadyTransformed(OldCallOpTSI->getType());
8271
8272 // Use the Old Call Operator's TypeSourceInfo if it is already transformed.
8273 if (CallOpWasAlreadyTransformed)
8274 NewCallOpTSI = OldCallOpTSI;
8275 else {
8276 // Transform the TypeSourceInfo of the Original Lambda's Call Operator.
8277 // The transformation MUST be done in the CurrentInstantiationScope since
8278 // it introduces a mapping of the original to the newly created
8279 // transformed parameters.
8280
8281 TypeLocBuilder NewCallOpTLBuilder;
8282 QualType NewCallOpType = TransformFunctionProtoType(NewCallOpTLBuilder,
8283 OldCallOpFPTL,
8284 0, 0);
8285 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
8286 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00008287 }
Faisal Vali2cba1332013-10-23 06:44:28 +00008288 // Extract the ParmVarDecls from the NewCallOpTSI and add them to
8289 // the vector below - this will be used to synthesize the
8290 // NewCallOperator. Additionally, add the parameters of the untransformed
8291 // lambda call operator to the CurrentInstantiationScope.
8292 SmallVector<ParmVarDecl *, 4> Params;
8293 {
8294 FunctionProtoTypeLoc NewCallOpFPTL =
8295 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>();
8296 ParmVarDecl **NewParamDeclArray = NewCallOpFPTL.getParmArray();
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00008297 const unsigned NewNumArgs = NewCallOpFPTL.getNumParams();
Faisal Vali2cba1332013-10-23 06:44:28 +00008298
8299 for (unsigned I = 0; I < NewNumArgs; ++I) {
8300 // If this call operator's type does not require transformation,
8301 // the parameters do not get added to the current instantiation scope,
8302 // - so ADD them! This allows the following to compile when the enclosing
8303 // template is specialized and the entire lambda expression has to be
8304 // transformed.
8305 // template<class T> void foo(T t) {
8306 // auto L = [](auto a) {
8307 // auto M = [](char b) { <-- note: non-generic lambda
8308 // auto N = [](auto c) {
8309 // int x = sizeof(a);
8310 // x = sizeof(b); <-- specifically this line
8311 // x = sizeof(c);
8312 // };
8313 // };
8314 // };
8315 // }
8316 // foo('a')
8317 if (CallOpWasAlreadyTransformed)
8318 getDerived().transformedLocalDecl(NewParamDeclArray[I],
8319 NewParamDeclArray[I]);
8320 // Add to Params array, so these parameters can be used to create
8321 // the newly transformed call operator.
8322 Params.push_back(NewParamDeclArray[I]);
8323 }
8324 }
8325
8326 if (!NewCallOpTSI)
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008327 return ExprError();
8328
Eli Friedmand564afb2012-09-19 01:18:11 +00008329 // Create the local class that will describe the lambda.
8330 CXXRecordDecl *Class
8331 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008332 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00008333 /*KnownDependent=*/false,
8334 E->getCaptureDefault());
8335
Eli Friedmand564afb2012-09-19 01:18:11 +00008336 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8337
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008338 // Build the call operator.
Faisal Vali2cba1332013-10-23 06:44:28 +00008339 CXXMethodDecl *NewCallOperator
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008340 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008341 NewCallOpTSI,
Douglas Gregoradb376e2012-02-14 22:28:59 +00008342 E->getCallOperator()->getLocEnd(),
Richard Smith505df232012-07-22 23:45:10 +00008343 Params);
Faisal Vali2cba1332013-10-23 06:44:28 +00008344 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00008345
Faisal Vali2cba1332013-10-23 06:44:28 +00008346 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
8347
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008348 return getDerived().TransformLambdaScope(E, NewCallOperator,
8349 InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +00008350}
8351
8352template<typename Derived>
8353ExprResult
8354TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008355 CXXMethodDecl *CallOperator,
8356 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes) {
Richard Smithba71c082013-05-16 06:20:58 +00008357 bool Invalid = false;
8358
Douglas Gregorb4328232012-02-14 00:00:48 +00008359 // Introduce the context of the call operator.
Richard Smith7ff2bcb2014-01-24 01:54:52 +00008360 Sema::ContextRAII SavedContext(getSema(), CallOperator,
8361 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00008362
Faisal Vali2b391ab2013-09-26 19:54:12 +00008363 LambdaScopeInfo *const LSI = getSema().getCurLambda();
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008364 // Enter the scope of the lambda.
Faisal Vali2b391ab2013-09-26 19:54:12 +00008365 getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008366 E->getCaptureDefault(),
James Dennettddd36ff2013-08-09 23:08:25 +00008367 E->getCaptureDefaultLoc(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008368 E->hasExplicitParameters(),
8369 E->hasExplicitResultType(),
8370 E->isMutable());
Chad Rosier1dcde962012-08-08 18:46:20 +00008371
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008372 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008373 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00008374 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008375 CEnd = E->capture_end();
8376 C != CEnd; ++C) {
8377 // When we hit the first implicit capture, tell Sema that we've finished
8378 // the list of explicit captures.
8379 if (!FinishedExplicitCaptures && C->isImplicit()) {
8380 getSema().finishLambdaExplicitCaptures(LSI);
8381 FinishedExplicitCaptures = true;
8382 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008383
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008384 // Capturing 'this' is trivial.
8385 if (C->capturesThis()) {
8386 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8387 continue;
8388 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008389
Richard Smithba71c082013-05-16 06:20:58 +00008390 // Rebuild init-captures, including the implied field declaration.
8391 if (C->isInitCapture()) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008392
8393 InitCaptureInfoTy InitExprTypePair =
8394 InitCaptureExprsAndTypes[C - E->capture_begin()];
8395 ExprResult Init = InitExprTypePair.first;
8396 QualType InitQualType = InitExprTypePair.second;
8397 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00008398 Invalid = true;
8399 continue;
8400 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00008401 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008402 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
8403 OldVD->getLocation(), InitExprTypePair.second,
8404 OldVD->getIdentifier(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00008405 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00008406 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008407 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00008408 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008409 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00008410 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00008411 continue;
8412 }
8413
8414 assert(C->capturesVariable() && "unexpected kind of lambda capture");
8415
Douglas Gregor3e308b12012-02-14 19:27:52 +00008416 // Determine the capture kind for Sema.
8417 Sema::TryCaptureKind Kind
8418 = C->isImplicit()? Sema::TryCapture_Implicit
8419 : C->getCaptureKind() == LCK_ByCopy
8420 ? Sema::TryCapture_ExplicitByVal
8421 : Sema::TryCapture_ExplicitByRef;
8422 SourceLocation EllipsisLoc;
8423 if (C->isPackExpansion()) {
8424 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8425 bool ShouldExpand = false;
8426 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008427 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00008428 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8429 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008430 Unexpanded,
8431 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00008432 NumExpansions)) {
8433 Invalid = true;
8434 continue;
8435 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008436
Douglas Gregor3e308b12012-02-14 19:27:52 +00008437 if (ShouldExpand) {
8438 // The transform has determined that we should perform an expansion;
8439 // transform and capture each of the arguments.
8440 // expansion of the pattern. Do so.
8441 VarDecl *Pack = C->getCapturedVar();
8442 for (unsigned I = 0; I != *NumExpansions; ++I) {
8443 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8444 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008445 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008446 Pack));
8447 if (!CapturedVar) {
8448 Invalid = true;
8449 continue;
8450 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008451
Douglas Gregor3e308b12012-02-14 19:27:52 +00008452 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00008453 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8454 }
Douglas Gregor3e308b12012-02-14 19:27:52 +00008455 continue;
8456 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008457
Douglas Gregor3e308b12012-02-14 19:27:52 +00008458 EllipsisLoc = C->getEllipsisLoc();
8459 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008460
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008461 // Transform the captured variable.
8462 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008463 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008464 C->getCapturedVar()));
8465 if (!CapturedVar) {
8466 Invalid = true;
8467 continue;
8468 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008469
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008470 // Capture the transformed variable.
Douglas Gregorfdf598e2012-02-18 09:37:24 +00008471 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008472 }
8473 if (!FinishedExplicitCaptures)
8474 getSema().finishLambdaExplicitCaptures(LSI);
8475
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008476
8477 // Enter a new evaluation context to insulate the lambda from any
8478 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00008479 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008480
8481 if (Invalid) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008482 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008483 /*IsInstantiation=*/true);
8484 return ExprError();
8485 }
8486
8487 // Instantiate the body of the lambda expression.
Douglas Gregorb4328232012-02-14 00:00:48 +00008488 StmtResult Body = getDerived().TransformStmt(E->getBody());
8489 if (Body.isInvalid()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008490 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregorb4328232012-02-14 00:00:48 +00008491 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00008492 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00008493 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00008494
Chad Rosier1dcde962012-08-08 18:46:20 +00008495 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorb61e8092012-04-04 17:40:10 +00008496 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregore31e6062012-02-07 10:09:13 +00008497}
8498
8499template<typename Derived>
8500ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008501TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008502 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00008503 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8504 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008505 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008506
Douglas Gregora16548e2009-08-11 05:31:07 +00008507 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008508 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00008509 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00008510 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008511 &ArgumentChanged))
8512 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008513
Douglas Gregora16548e2009-08-11 05:31:07 +00008514 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008515 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008516 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00008517 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00008518
Douglas Gregora16548e2009-08-11 05:31:07 +00008519 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00008520 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00008521 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008522 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008523 E->getRParenLoc());
8524}
Mike Stump11289f42009-09-09 15:08:12 +00008525
Douglas Gregora16548e2009-08-11 05:31:07 +00008526template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008527ExprResult
John McCall8cd78132009-11-19 22:55:06 +00008528TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008529 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008530 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00008531 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00008532 Expr *OldBase;
8533 QualType BaseType;
8534 QualType ObjectType;
8535 if (!E->isImplicitAccess()) {
8536 OldBase = E->getBase();
8537 Base = getDerived().TransformExpr(OldBase);
8538 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008539 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008540
John McCall2d74de92009-12-01 22:10:20 +00008541 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00008542 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00008543 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00008544 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008545 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008546 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00008547 ObjectTy,
8548 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00008549 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008550 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00008551
John McCallba7bf592010-08-24 05:47:05 +00008552 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00008553 BaseType = ((Expr*) Base.get())->getType();
8554 } else {
8555 OldBase = 0;
8556 BaseType = getDerived().TransformType(E->getBaseType());
8557 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8558 }
Mike Stump11289f42009-09-09 15:08:12 +00008559
Douglas Gregora5cb6da2009-10-20 05:58:46 +00008560 // Transform the first part of the nested-name-specifier that qualifies
8561 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00008562 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00008563 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00008564 E->getFirstQualifierFoundInScope(),
8565 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00008566
Douglas Gregore16af532011-02-28 18:50:33 +00008567 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008568 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00008569 QualifierLoc
8570 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8571 ObjectType,
8572 FirstQualifierInScope);
8573 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008574 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008575 }
Mike Stump11289f42009-09-09 15:08:12 +00008576
Abramo Bagnara7945c982012-01-27 09:46:47 +00008577 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8578
John McCall31f82722010-11-12 08:19:04 +00008579 // TODO: If this is a conversion-function-id, verify that the
8580 // destination type name (if present) resolves the same way after
8581 // instantiation as it did in the local scope.
8582
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008583 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00008584 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008585 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008586 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008587
John McCall2d74de92009-12-01 22:10:20 +00008588 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00008589 // This is a reference to a member without an explicitly-specified
8590 // template argument list. Optimize for this common case.
8591 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00008592 Base.get() == OldBase &&
8593 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00008594 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008595 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00008596 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00008597 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00008598
John McCallb268a282010-08-23 23:25:46 +00008599 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008600 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00008601 E->isArrow(),
8602 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00008603 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008604 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00008605 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008606 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00008607 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00008608 }
8609
John McCall6b51f282009-11-23 01:53:49 +00008610 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008611 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8612 E->getNumTemplateArgs(),
8613 TransArgs))
8614 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008615
John McCallb268a282010-08-23 23:25:46 +00008616 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008617 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00008618 E->isArrow(),
8619 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00008620 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008621 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00008622 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008623 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00008624 &TransArgs);
8625}
8626
8627template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008628ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008629TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00008630 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00008631 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00008632 QualType BaseType;
8633 if (!Old->isImplicitAccess()) {
8634 Base = getDerived().TransformExpr(Old->getBase());
8635 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008636 return ExprError();
Richard Smithcab9a7d2011-10-26 19:06:56 +00008637 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8638 Old->isArrow());
8639 if (Base.isInvalid())
8640 return ExprError();
8641 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +00008642 } else {
8643 BaseType = getDerived().TransformType(Old->getBaseType());
8644 }
John McCall10eae182009-11-30 22:42:35 +00008645
Douglas Gregor0da1d432011-02-28 20:01:57 +00008646 NestedNameSpecifierLoc QualifierLoc;
8647 if (Old->getQualifierLoc()) {
8648 QualifierLoc
8649 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8650 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008651 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00008652 }
8653
Abramo Bagnara7945c982012-01-27 09:46:47 +00008654 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8655
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008656 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00008657 Sema::LookupOrdinaryName);
8658
8659 // Transform all the decls.
8660 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8661 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008662 NamedDecl *InstD = static_cast<NamedDecl*>(
8663 getDerived().TransformDecl(Old->getMemberLoc(),
8664 *I));
John McCall84d87672009-12-10 09:41:52 +00008665 if (!InstD) {
8666 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8667 // This can happen because of dependent hiding.
8668 if (isa<UsingShadowDecl>(*I))
8669 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00008670 else {
8671 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008672 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00008673 }
John McCall84d87672009-12-10 09:41:52 +00008674 }
John McCall10eae182009-11-30 22:42:35 +00008675
8676 // Expand using declarations.
8677 if (isa<UsingDecl>(InstD)) {
8678 UsingDecl *UD = cast<UsingDecl>(InstD);
8679 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8680 E = UD->shadow_end(); I != E; ++I)
8681 R.addDecl(*I);
8682 continue;
8683 }
8684
8685 R.addDecl(InstD);
8686 }
8687
8688 R.resolveKind();
8689
Douglas Gregor9262f472010-04-27 18:19:34 +00008690 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00008691 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008692 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00008693 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00008694 Old->getMemberLoc(),
8695 Old->getNamingClass()));
8696 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00008697 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008698
Douglas Gregorda7be082010-04-27 16:10:10 +00008699 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00008700 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008701
John McCall10eae182009-11-30 22:42:35 +00008702 TemplateArgumentListInfo TransArgs;
8703 if (Old->hasExplicitTemplateArgs()) {
8704 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8705 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008706 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8707 Old->getNumTemplateArgs(),
8708 TransArgs))
8709 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00008710 }
John McCall38836f02010-01-15 08:34:02 +00008711
8712 // FIXME: to do this check properly, we will need to preserve the
8713 // first-qualifier-in-scope here, just in case we had a dependent
8714 // base (and therefore couldn't do the check) and a
8715 // nested-name-qualifier (and therefore could do the lookup).
8716 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00008717
John McCallb268a282010-08-23 23:25:46 +00008718 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008719 BaseType,
John McCall10eae182009-11-30 22:42:35 +00008720 Old->getOperatorLoc(),
8721 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00008722 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008723 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +00008724 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00008725 R,
8726 (Old->hasExplicitTemplateArgs()
8727 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00008728}
8729
8730template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008731ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008732TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00008733 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008734 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8735 if (SubExpr.isInvalid())
8736 return ExprError();
8737
8738 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00008739 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008740
8741 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8742}
8743
8744template<typename Derived>
8745ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008746TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00008747 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8748 if (Pattern.isInvalid())
8749 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008750
Douglas Gregor0f836ea2011-01-13 00:19:55 +00008751 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8752 return SemaRef.Owned(E);
8753
Douglas Gregorb8840002011-01-14 21:20:45 +00008754 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8755 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008756}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008757
8758template<typename Derived>
8759ExprResult
8760TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8761 // If E is not value-dependent, then nothing will change when we transform it.
8762 // Note: This is an instantiation-centric view.
8763 if (!E->isValueDependent())
8764 return SemaRef.Owned(E);
8765
8766 // Note: None of the implementations of TryExpandParameterPacks can ever
8767 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00008768 // so
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008769 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8770 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00008771 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008772 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00008773 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +00008774 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00008775 ShouldExpand, RetainExpansion,
8776 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008777 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008778
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008779 if (RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008780 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00008781
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008782 NamedDecl *Pack = E->getPack();
8783 if (!ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008784 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008785 Pack));
8786 if (!Pack)
8787 return ExprError();
8788 }
8789
Chad Rosier1dcde962012-08-08 18:46:20 +00008790
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008791 // We now know the length of the parameter pack, so build a new expression
8792 // that stores that length.
Chad Rosier1dcde962012-08-08 18:46:20 +00008793 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8794 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008795 NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008796}
8797
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008798template<typename Derived>
8799ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00008800TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8801 SubstNonTypeTemplateParmPackExpr *E) {
8802 // Default behavior is to do nothing with this transformation.
8803 return SemaRef.Owned(E);
8804}
8805
8806template<typename Derived>
8807ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00008808TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8809 SubstNonTypeTemplateParmExpr *E) {
8810 // Default behavior is to do nothing with this transformation.
8811 return SemaRef.Owned(E);
8812}
8813
8814template<typename Derived>
8815ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +00008816TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8817 // Default behavior is to do nothing with this transformation.
8818 return SemaRef.Owned(E);
8819}
8820
8821template<typename Derived>
8822ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00008823TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8824 MaterializeTemporaryExpr *E) {
8825 return getDerived().TransformExpr(E->GetTemporaryExpr());
8826}
Chad Rosier1dcde962012-08-08 18:46:20 +00008827
Douglas Gregorfe314812011-06-21 17:03:29 +00008828template<typename Derived>
8829ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +00008830TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
8831 CXXStdInitializerListExpr *E) {
8832 return getDerived().TransformExpr(E->getSubExpr());
8833}
8834
8835template<typename Derived>
8836ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008837TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00008838 return SemaRef.MaybeBindToTemporary(E);
8839}
8840
8841template<typename Derived>
8842ExprResult
8843TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rose8986c5992012-03-12 17:53:02 +00008844 return SemaRef.Owned(E);
Ted Kremeneke65b0862012-03-06 20:05:56 +00008845}
8846
8847template<typename Derived>
8848ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +00008849TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8850 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8851 if (SubExpr.isInvalid())
8852 return ExprError();
8853
8854 if (!getDerived().AlwaysRebuild() &&
8855 SubExpr.get() == E->getSubExpr())
8856 return SemaRef.Owned(E);
8857
8858 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +00008859}
8860
8861template<typename Derived>
8862ExprResult
8863TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8864 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008865 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00008866 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00008867 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00008868 /*IsCall=*/false, Elements, &ArgChanged))
8869 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008870
Ted Kremeneke65b0862012-03-06 20:05:56 +00008871 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8872 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00008873
Ted Kremeneke65b0862012-03-06 20:05:56 +00008874 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8875 Elements.data(),
8876 Elements.size());
8877}
8878
8879template<typename Derived>
8880ExprResult
8881TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +00008882 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00008883 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008884 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00008885 bool ArgChanged = false;
8886 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8887 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +00008888
Ted Kremeneke65b0862012-03-06 20:05:56 +00008889 if (OrigElement.isPackExpansion()) {
8890 // This key/value element is a pack expansion.
8891 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8892 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8893 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8894 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8895
8896 // Determine whether the set of unexpanded parameter packs can
8897 // and should be expanded.
8898 bool Expand = true;
8899 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008900 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8901 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +00008902 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8903 OrigElement.Value->getLocEnd());
8904 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8905 PatternRange,
8906 Unexpanded,
8907 Expand, RetainExpansion,
8908 NumExpansions))
8909 return ExprError();
8910
8911 if (!Expand) {
8912 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00008913 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +00008914 // expansion.
8915 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8916 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8917 if (Key.isInvalid())
8918 return ExprError();
8919
8920 if (Key.get() != OrigElement.Key)
8921 ArgChanged = true;
8922
8923 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8924 if (Value.isInvalid())
8925 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008926
Ted Kremeneke65b0862012-03-06 20:05:56 +00008927 if (Value.get() != OrigElement.Value)
8928 ArgChanged = true;
8929
Chad Rosier1dcde962012-08-08 18:46:20 +00008930 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00008931 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8932 };
8933 Elements.push_back(Expansion);
8934 continue;
8935 }
8936
8937 // Record right away that the argument was changed. This needs
8938 // to happen even if the array expands to nothing.
8939 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00008940
Ted Kremeneke65b0862012-03-06 20:05:56 +00008941 // The transform has determined that we should perform an elementwise
8942 // expansion of the pattern. Do so.
8943 for (unsigned I = 0; I != *NumExpansions; ++I) {
8944 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8945 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8946 if (Key.isInvalid())
8947 return ExprError();
8948
8949 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8950 if (Value.isInvalid())
8951 return ExprError();
8952
Chad Rosier1dcde962012-08-08 18:46:20 +00008953 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00008954 Key.get(), Value.get(), SourceLocation(), NumExpansions
8955 };
8956
8957 // If any unexpanded parameter packs remain, we still have a
8958 // pack expansion.
8959 if (Key.get()->containsUnexpandedParameterPack() ||
8960 Value.get()->containsUnexpandedParameterPack())
8961 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +00008962
Ted Kremeneke65b0862012-03-06 20:05:56 +00008963 Elements.push_back(Element);
8964 }
8965
8966 // We've finished with this pack expansion.
8967 continue;
8968 }
8969
8970 // Transform and check key.
8971 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8972 if (Key.isInvalid())
8973 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008974
Ted Kremeneke65b0862012-03-06 20:05:56 +00008975 if (Key.get() != OrigElement.Key)
8976 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00008977
Ted Kremeneke65b0862012-03-06 20:05:56 +00008978 // Transform and check value.
8979 ExprResult Value
8980 = getDerived().TransformExpr(OrigElement.Value);
8981 if (Value.isInvalid())
8982 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008983
Ted Kremeneke65b0862012-03-06 20:05:56 +00008984 if (Value.get() != OrigElement.Value)
8985 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00008986
8987 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +00008988 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +00008989 };
8990 Elements.push_back(Element);
8991 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008992
Ted Kremeneke65b0862012-03-06 20:05:56 +00008993 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8994 return SemaRef.MaybeBindToTemporary(E);
8995
8996 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8997 Elements.data(),
8998 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +00008999}
9000
Mike Stump11289f42009-09-09 15:08:12 +00009001template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009002ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009003TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00009004 TypeSourceInfo *EncodedTypeInfo
9005 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
9006 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009007 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009008
Douglas Gregora16548e2009-08-11 05:31:07 +00009009 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00009010 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00009011 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009012
9013 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00009014 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009015 E->getRParenLoc());
9016}
Mike Stump11289f42009-09-09 15:08:12 +00009017
Douglas Gregora16548e2009-08-11 05:31:07 +00009018template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +00009019ExprResult TreeTransform<Derived>::
9020TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +00009021 // This is a kind of implicit conversion, and it needs to get dropped
9022 // and recomputed for the same general reasons that ImplicitCastExprs
9023 // do, as well a more specific one: this expression is only valid when
9024 // it appears *immediately* as an argument expression.
9025 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +00009026}
9027
9028template<typename Derived>
9029ExprResult TreeTransform<Derived>::
9030TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009031 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +00009032 = getDerived().TransformType(E->getTypeInfoAsWritten());
9033 if (!TSInfo)
9034 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009035
John McCall31168b02011-06-15 23:02:42 +00009036 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +00009037 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +00009038 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009039
John McCall31168b02011-06-15 23:02:42 +00009040 if (!getDerived().AlwaysRebuild() &&
9041 TSInfo == E->getTypeInfoAsWritten() &&
9042 Result.get() == E->getSubExpr())
9043 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009044
John McCall31168b02011-06-15 23:02:42 +00009045 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +00009046 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +00009047 Result.get());
9048}
9049
9050template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009051ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009052TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009053 // Transform arguments.
9054 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009055 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009056 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009057 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009058 &ArgChanged))
9059 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009060
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009061 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
9062 // Class message: transform the receiver type.
9063 TypeSourceInfo *ReceiverTypeInfo
9064 = getDerived().TransformType(E->getClassReceiverTypeInfo());
9065 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009066 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009067
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009068 // If nothing changed, just retain the existing message send.
9069 if (!getDerived().AlwaysRebuild() &&
9070 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009071 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009072
9073 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009074 SmallVector<SourceLocation, 16> SelLocs;
9075 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009076 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
9077 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009078 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009079 E->getMethodDecl(),
9080 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009081 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009082 E->getRightLoc());
9083 }
9084
9085 // Instance message: transform the receiver
9086 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
9087 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00009088 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009089 = getDerived().TransformExpr(E->getInstanceReceiver());
9090 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009091 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009092
9093 // If nothing changed, just retain the existing message send.
9094 if (!getDerived().AlwaysRebuild() &&
9095 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009096 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009097
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009098 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009099 SmallVector<SourceLocation, 16> SelLocs;
9100 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +00009101 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009102 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009103 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009104 E->getMethodDecl(),
9105 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009106 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009107 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009108}
9109
Mike Stump11289f42009-09-09 15:08:12 +00009110template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009111ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009112TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00009113 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009114}
9115
Mike Stump11289f42009-09-09 15:08:12 +00009116template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009117ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009118TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00009119 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009120}
9121
Mike Stump11289f42009-09-09 15:08:12 +00009122template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009123ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009124TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009125 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009126 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009127 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009128 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00009129
9130 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009131
Douglas Gregord51d90d2010-04-26 20:11:03 +00009132 // If nothing changed, just retain the existing expression.
9133 if (!getDerived().AlwaysRebuild() &&
9134 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00009135 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009136
John McCallb268a282010-08-23 23:25:46 +00009137 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009138 E->getLocation(),
9139 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00009140}
9141
Mike Stump11289f42009-09-09 15:08:12 +00009142template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009143ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009144TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00009145 // 'super' and types never change. Property never changes. Just
9146 // retain the existing expression.
9147 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00009148 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009149
Douglas Gregor9faee212010-04-26 20:47:02 +00009150 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009151 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00009152 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009153 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009154
Douglas Gregor9faee212010-04-26 20:47:02 +00009155 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009156
Douglas Gregor9faee212010-04-26 20:47:02 +00009157 // If nothing changed, just retain the existing expression.
9158 if (!getDerived().AlwaysRebuild() &&
9159 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00009160 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009161
John McCallb7bd14f2010-12-02 01:19:52 +00009162 if (E->isExplicitProperty())
9163 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9164 E->getExplicitProperty(),
9165 E->getLocation());
9166
9167 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +00009168 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +00009169 E->getImplicitPropertyGetter(),
9170 E->getImplicitPropertySetter(),
9171 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00009172}
9173
Mike Stump11289f42009-09-09 15:08:12 +00009174template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009175ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +00009176TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
9177 // Transform the base expression.
9178 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9179 if (Base.isInvalid())
9180 return ExprError();
9181
9182 // Transform the key expression.
9183 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
9184 if (Key.isInvalid())
9185 return ExprError();
9186
9187 // If nothing changed, just retain the existing expression.
9188 if (!getDerived().AlwaysRebuild() &&
9189 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
9190 return SemaRef.Owned(E);
9191
Chad Rosier1dcde962012-08-08 18:46:20 +00009192 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009193 Base.get(), Key.get(),
9194 E->getAtIndexMethodDecl(),
9195 E->setAtIndexMethodDecl());
9196}
9197
9198template<typename Derived>
9199ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009200TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009201 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009202 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009203 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009204 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009205
Douglas Gregord51d90d2010-04-26 20:11:03 +00009206 // If nothing changed, just retain the existing expression.
9207 if (!getDerived().AlwaysRebuild() &&
9208 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00009209 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009210
John McCallb268a282010-08-23 23:25:46 +00009211 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00009212 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009213 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00009214}
9215
Mike Stump11289f42009-09-09 15:08:12 +00009216template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009217ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009218TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009219 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009220 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +00009221 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009222 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00009223 SubExprs, &ArgumentChanged))
9224 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009225
Douglas Gregora16548e2009-08-11 05:31:07 +00009226 if (!getDerived().AlwaysRebuild() &&
9227 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00009228 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00009229
Douglas Gregora16548e2009-08-11 05:31:07 +00009230 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009231 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009232 E->getRParenLoc());
9233}
9234
Mike Stump11289f42009-09-09 15:08:12 +00009235template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009236ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +00009237TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
9238 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
9239 if (SrcExpr.isInvalid())
9240 return ExprError();
9241
9242 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9243 if (!Type)
9244 return ExprError();
9245
9246 if (!getDerived().AlwaysRebuild() &&
9247 Type == E->getTypeSourceInfo() &&
9248 SrcExpr.get() == E->getSrcExpr())
9249 return SemaRef.Owned(E);
9250
9251 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
9252 SrcExpr.get(), Type,
9253 E->getRParenLoc());
9254}
9255
9256template<typename Derived>
9257ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009258TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00009259 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +00009260
John McCall490112f2011-02-04 18:33:18 +00009261 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
9262 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
9263
9264 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +00009265 blockScope->TheDecl->setBlockMissingReturnType(
9266 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +00009267
Chris Lattner01cf8db2011-07-20 06:58:45 +00009268 SmallVector<ParmVarDecl*, 4> params;
9269 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +00009270
Fariborz Jahanian1babe772010-07-09 18:44:02 +00009271 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00009272 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
9273 oldBlock->param_begin(),
9274 oldBlock->param_size(),
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009275 0, paramTypes, &params)) {
9276 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009277 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009278 }
John McCall490112f2011-02-04 18:33:18 +00009279
Jordan Rosea0a86be2013-03-08 22:25:36 +00009280 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +00009281 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +00009282 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +00009283
Jordan Rose5c382722013-03-08 21:51:21 +00009284 QualType functionType =
9285 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009286 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +00009287 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00009288
9289 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00009290 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +00009291 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +00009292
9293 if (!oldBlock->blockMissingReturnType()) {
9294 blockScope->HasImplicitReturnType = false;
9295 blockScope->ReturnType = exprResultType;
9296 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009297
John McCall3882ace2011-01-05 12:14:39 +00009298 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00009299 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009300 if (body.isInvalid()) {
9301 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall3882ace2011-01-05 12:14:39 +00009302 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009303 }
John McCall3882ace2011-01-05 12:14:39 +00009304
John McCall490112f2011-02-04 18:33:18 +00009305#ifndef NDEBUG
9306 // In builds with assertions, make sure that we captured everything we
9307 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009308 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
9309 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
9310 e = oldBlock->capture_end(); i != e; ++i) {
9311 VarDecl *oldCapture = i->getVariable();
John McCall490112f2011-02-04 18:33:18 +00009312
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009313 // Ignore parameter packs.
9314 if (isa<ParmVarDecl>(oldCapture) &&
9315 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9316 continue;
John McCall490112f2011-02-04 18:33:18 +00009317
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009318 VarDecl *newCapture =
9319 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9320 oldCapture));
9321 assert(blockScope->CaptureMap.count(newCapture));
9322 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009323 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +00009324 }
9325#endif
9326
9327 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
9328 /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00009329}
9330
Mike Stump11289f42009-09-09 15:08:12 +00009331template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009332ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +00009333TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +00009334 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +00009335}
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009336
9337template<typename Derived>
9338ExprResult
9339TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009340 QualType RetTy = getDerived().TransformType(E->getType());
9341 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009342 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009343 SubExprs.reserve(E->getNumSubExprs());
9344 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9345 SubExprs, &ArgumentChanged))
9346 return ExprError();
9347
9348 if (!getDerived().AlwaysRebuild() &&
9349 !ArgumentChanged)
9350 return SemaRef.Owned(E);
9351
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009352 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009353 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009354}
Chad Rosier1dcde962012-08-08 18:46:20 +00009355
Douglas Gregora16548e2009-08-11 05:31:07 +00009356//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00009357// Type reconstruction
9358//===----------------------------------------------------------------------===//
9359
Mike Stump11289f42009-09-09 15:08:12 +00009360template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009361QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9362 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009363 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009364 getDerived().getBaseEntity());
9365}
9366
Mike Stump11289f42009-09-09 15:08:12 +00009367template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009368QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9369 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009370 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009371 getDerived().getBaseEntity());
9372}
9373
Mike Stump11289f42009-09-09 15:08:12 +00009374template<typename Derived>
9375QualType
John McCall70dd5f62009-10-30 00:06:24 +00009376TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9377 bool WrittenAsLValue,
9378 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00009379 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00009380 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009381}
9382
9383template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009384QualType
John McCall70dd5f62009-10-30 00:06:24 +00009385TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9386 QualType ClassType,
9387 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +00009388 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
9389 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009390}
9391
9392template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009393QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00009394TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9395 ArrayType::ArraySizeModifier SizeMod,
9396 const llvm::APInt *Size,
9397 Expr *SizeExpr,
9398 unsigned IndexTypeQuals,
9399 SourceRange BracketsRange) {
9400 if (SizeExpr || !Size)
9401 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9402 IndexTypeQuals, BracketsRange,
9403 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00009404
9405 QualType Types[] = {
9406 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9407 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9408 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00009409 };
Craig Toppere5ce8312013-07-15 03:38:40 +00009410 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009411 QualType SizeType;
9412 for (unsigned I = 0; I != NumTypes; ++I)
9413 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9414 SizeType = Types[I];
9415 break;
9416 }
Mike Stump11289f42009-09-09 15:08:12 +00009417
Eli Friedman9562f392012-01-25 23:20:27 +00009418 // Note that we can return a VariableArrayType here in the case where
9419 // the element type was a dependent VariableArrayType.
9420 IntegerLiteral *ArraySize
9421 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9422 /*FIXME*/BracketsRange.getBegin());
9423 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009424 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00009425 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009426}
Mike Stump11289f42009-09-09 15:08:12 +00009427
Douglas Gregord6ff3322009-08-04 16:50:30 +00009428template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009429QualType
9430TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009431 ArrayType::ArraySizeModifier SizeMod,
9432 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00009433 unsigned IndexTypeQuals,
9434 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009435 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00009436 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009437}
9438
9439template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009440QualType
Mike Stump11289f42009-09-09 15:08:12 +00009441TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009442 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00009443 unsigned IndexTypeQuals,
9444 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009445 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00009446 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009447}
Mike Stump11289f42009-09-09 15:08:12 +00009448
Douglas Gregord6ff3322009-08-04 16:50:30 +00009449template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009450QualType
9451TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009452 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009453 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009454 unsigned IndexTypeQuals,
9455 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009456 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00009457 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009458 IndexTypeQuals, BracketsRange);
9459}
9460
9461template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009462QualType
9463TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009464 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009465 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009466 unsigned IndexTypeQuals,
9467 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009468 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00009469 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009470 IndexTypeQuals, BracketsRange);
9471}
9472
9473template<typename Derived>
9474QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00009475 unsigned NumElements,
9476 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00009477 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00009478 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009479}
Mike Stump11289f42009-09-09 15:08:12 +00009480
Douglas Gregord6ff3322009-08-04 16:50:30 +00009481template<typename Derived>
9482QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9483 unsigned NumElements,
9484 SourceLocation AttributeLoc) {
9485 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9486 NumElements, true);
9487 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00009488 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9489 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00009490 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
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>
Mike Stump11289f42009-09-09 15:08:12 +00009494QualType
9495TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00009496 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009497 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00009498 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009499}
Mike Stump11289f42009-09-09 15:08:12 +00009500
Douglas Gregord6ff3322009-08-04 16:50:30 +00009501template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +00009502QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9503 QualType T,
9504 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009505 const FunctionProtoType::ExtProtoInfo &EPI) {
9506 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009507 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00009508 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +00009509 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009510}
Mike Stump11289f42009-09-09 15:08:12 +00009511
Douglas Gregord6ff3322009-08-04 16:50:30 +00009512template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00009513QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9514 return SemaRef.Context.getFunctionNoProtoType(T);
9515}
9516
9517template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00009518QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9519 assert(D && "no decl found");
9520 if (D->isInvalidDecl()) return QualType();
9521
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009522 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00009523 TypeDecl *Ty;
9524 if (isa<UsingDecl>(D)) {
9525 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +00009526 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +00009527 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9528
9529 // A valid resolved using typename decl points to exactly one type decl.
9530 assert(++Using->shadow_begin() == Using->shadow_end());
9531 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00009532
John McCallb96ec562009-12-04 22:46:56 +00009533 } else {
9534 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9535 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9536 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9537 }
9538
9539 return SemaRef.Context.getTypeDeclType(Ty);
9540}
9541
9542template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00009543QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9544 SourceLocation Loc) {
9545 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009546}
9547
9548template<typename Derived>
9549QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9550 return SemaRef.Context.getTypeOfType(Underlying);
9551}
9552
9553template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00009554QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9555 SourceLocation Loc) {
9556 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009557}
9558
9559template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00009560QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9561 UnaryTransformType::UTTKind UKind,
9562 SourceLocation Loc) {
9563 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9564}
9565
9566template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00009567QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00009568 TemplateName Template,
9569 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +00009570 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +00009571 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009572}
Mike Stump11289f42009-09-09 15:08:12 +00009573
Douglas Gregor1135c352009-08-06 05:28:30 +00009574template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +00009575QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9576 SourceLocation KWLoc) {
9577 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9578}
9579
9580template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009581TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009582TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00009583 bool TemplateKW,
9584 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +00009585 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00009586 Template);
9587}
9588
9589template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009590TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009591TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9592 const IdentifierInfo &Name,
9593 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00009594 QualType ObjectType,
9595 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +00009596 UnqualifiedId TemplateName;
9597 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +00009598 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +00009599 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +00009600 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009601 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +00009602 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00009603 /*EnteringContext=*/false,
9604 Template);
John McCall31f82722010-11-12 08:19:04 +00009605 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00009606}
Mike Stump11289f42009-09-09 15:08:12 +00009607
Douglas Gregora16548e2009-08-11 05:31:07 +00009608template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00009609TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009610TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00009611 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00009612 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00009613 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +00009614 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +00009615 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +00009616 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +00009617 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +00009618 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +00009619 Sema::TemplateTy Template;
9620 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009621 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +00009622 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00009623 /*EnteringContext=*/false,
9624 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +00009625 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +00009626}
Chad Rosier1dcde962012-08-08 18:46:20 +00009627
Douglas Gregor71395fa2009-11-04 00:56:37 +00009628template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009629ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009630TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9631 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00009632 Expr *OrigCallee,
9633 Expr *First,
9634 Expr *Second) {
9635 Expr *Callee = OrigCallee->IgnoreParenCasts();
9636 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00009637
Douglas Gregora16548e2009-08-11 05:31:07 +00009638 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00009639 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00009640 if (!First->getType()->isOverloadableType() &&
9641 !Second->getType()->isOverloadableType())
9642 return getSema().CreateBuiltinArraySubscriptExpr(First,
9643 Callee->getLocStart(),
9644 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00009645 } else if (Op == OO_Arrow) {
9646 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00009647 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9648 } else if (Second == 0 || isPostIncDec) {
9649 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009650 // The argument is not of overloadable type, so try to create a
9651 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00009652 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00009653 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00009654
John McCallb268a282010-08-23 23:25:46 +00009655 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00009656 }
9657 } else {
John McCallb268a282010-08-23 23:25:46 +00009658 if (!First->getType()->isOverloadableType() &&
9659 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009660 // Neither of the arguments is an overloadable type, so try to
9661 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00009662 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00009663 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00009664 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00009665 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009666 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009667
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009668 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00009669 }
9670 }
Mike Stump11289f42009-09-09 15:08:12 +00009671
9672 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00009673 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00009674 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00009675
John McCallb268a282010-08-23 23:25:46 +00009676 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00009677 assert(ULE->requiresADL());
9678
9679 // FIXME: Do we have to check
9680 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00009681 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00009682 } else {
Richard Smith58db83d2012-11-28 21:47:39 +00009683 // If we've resolved this to a particular non-member function, just call
9684 // that function. If we resolved it to a member function,
9685 // CreateOverloaded* will find that function for us.
9686 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9687 if (!isa<CXXMethodDecl>(ND))
9688 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +00009689 }
Mike Stump11289f42009-09-09 15:08:12 +00009690
Douglas Gregora16548e2009-08-11 05:31:07 +00009691 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00009692 Expr *Args[2] = { First, Second };
9693 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00009694
Douglas Gregora16548e2009-08-11 05:31:07 +00009695 // Create the overloaded operator invocation for unary operators.
9696 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00009697 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00009698 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00009699 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00009700 }
Mike Stump11289f42009-09-09 15:08:12 +00009701
Douglas Gregore9d62932011-07-15 16:25:15 +00009702 if (Op == OO_Subscript) {
9703 SourceLocation LBrace;
9704 SourceLocation RBrace;
9705
9706 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9707 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9708 LBrace = SourceLocation::getFromRawEncoding(
9709 NameLoc.CXXOperatorName.BeginOpNameLoc);
9710 RBrace = SourceLocation::getFromRawEncoding(
9711 NameLoc.CXXOperatorName.EndOpNameLoc);
9712 } else {
9713 LBrace = Callee->getLocStart();
9714 RBrace = OpLoc;
9715 }
9716
9717 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9718 First, Second);
9719 }
Sebastian Redladba46e2009-10-29 20:17:01 +00009720
Douglas Gregora16548e2009-08-11 05:31:07 +00009721 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00009722 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00009723 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00009724 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9725 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009726 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009727
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009728 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00009729}
Mike Stump11289f42009-09-09 15:08:12 +00009730
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009731template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00009732ExprResult
John McCallb268a282010-08-23 23:25:46 +00009733TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009734 SourceLocation OperatorLoc,
9735 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +00009736 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009737 TypeSourceInfo *ScopeType,
9738 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009739 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009740 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +00009741 QualType BaseType = Base->getType();
9742 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009743 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +00009744 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00009745 !BaseType->getAs<PointerType>()->getPointeeType()
9746 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009747 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00009748 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009749 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009750 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009751 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009752 /*FIXME?*/true);
9753 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009754
Douglas Gregor678f90d2010-02-25 01:56:36 +00009755 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009756 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9757 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9758 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9759 NameInfo.setNamedTypeInfo(DestroyedType);
9760
Richard Smith8e4a3862012-05-15 06:15:11 +00009761 // The scope type is now known to be a valid nested name specifier
9762 // component. Tack it on to the end of the nested name specifier.
9763 if (ScopeType)
9764 SS.Extend(SemaRef.Context, SourceLocation(),
9765 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009766
Abramo Bagnara7945c982012-01-27 09:46:47 +00009767 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +00009768 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009769 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009770 SS, TemplateKWLoc,
9771 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009772 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009773 /*TemplateArgs*/ 0);
9774}
9775
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00009776template<typename Derived>
9777StmtResult
9778TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +00009779 SourceLocation Loc = S->getLocStart();
9780 unsigned NumParams = S->getCapturedDecl()->getNumParams();
9781 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/0,
9782 S->getCapturedRegionKind(), NumParams);
9783 StmtResult Body = getDerived().TransformStmt(S->getCapturedStmt());
9784
9785 if (Body.isInvalid()) {
9786 getSema().ActOnCapturedRegionError();
9787 return StmtError();
9788 }
9789
9790 return getSema().ActOnCapturedRegionEnd(Body.take());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00009791}
9792
Douglas Gregord6ff3322009-08-04 16:50:30 +00009793} // end namespace clang
9794
9795#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H