blob: 44581fd4153320ab85a80ff5b09ea4469d70f983 [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);
Mike Stump11289f42009-09-09 15:08:12 +0000596
Richard Smith2589b9802012-07-25 03:56:55 +0000597 /// \brief Transform the captures and body of a lambda expression.
598 ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator);
599
Faisal Vali2cba1332013-10-23 06:44:28 +0000600 TemplateParameterList *TransformTemplateParameterList(
601 TemplateParameterList *TPL) {
602 return TPL;
603 }
604
Richard Smithdb2630f2012-10-21 03:28:35 +0000605 ExprResult TransformAddressOfOperand(Expr *E);
606 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
607 bool IsAddressOfOperand);
608
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000609// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
610// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000611#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000612 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000613 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000614#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000615 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000616 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000617#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000618#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000619
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000620#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000621 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000622 OMPClause *Transform ## Class(Class *S);
623#include "clang/Basic/OpenMPKinds.def"
624
Douglas Gregord6ff3322009-08-04 16:50:30 +0000625 /// \brief Build a new pointer type given its pointee type.
626 ///
627 /// By default, performs semantic analysis when building the pointer type.
628 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000629 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000630
631 /// \brief Build a new block pointer type given its pointee type.
632 ///
Mike Stump11289f42009-09-09 15:08:12 +0000633 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000634 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000635 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000636
John McCall70dd5f62009-10-30 00:06:24 +0000637 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000638 ///
John McCall70dd5f62009-10-30 00:06:24 +0000639 /// By default, performs semantic analysis when building the
640 /// reference type. Subclasses may override this routine to provide
641 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000642 ///
John McCall70dd5f62009-10-30 00:06:24 +0000643 /// \param LValue whether the type was written with an lvalue sigil
644 /// or an rvalue sigil.
645 QualType RebuildReferenceType(QualType ReferentType,
646 bool LValue,
647 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000648
Douglas Gregord6ff3322009-08-04 16:50:30 +0000649 /// \brief Build a new member pointer type given the pointee type and the
650 /// class type it refers into.
651 ///
652 /// By default, performs semantic analysis when building the member pointer
653 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000654 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
655 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000656
Douglas Gregord6ff3322009-08-04 16:50:30 +0000657 /// \brief Build a new array type given the element type, size
658 /// modifier, size of the array (if known), size expression, and index type
659 /// qualifiers.
660 ///
661 /// By default, performs semantic analysis when building the array type.
662 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000663 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000664 QualType RebuildArrayType(QualType ElementType,
665 ArrayType::ArraySizeModifier SizeMod,
666 const llvm::APInt *Size,
667 Expr *SizeExpr,
668 unsigned IndexTypeQuals,
669 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000670
Douglas Gregord6ff3322009-08-04 16:50:30 +0000671 /// \brief Build a new constant array type given the element type, size
672 /// modifier, (known) size of the array, and index type qualifiers.
673 ///
674 /// By default, performs semantic analysis when building the array type.
675 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000676 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000677 ArrayType::ArraySizeModifier SizeMod,
678 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000679 unsigned IndexTypeQuals,
680 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000681
Douglas Gregord6ff3322009-08-04 16:50:30 +0000682 /// \brief Build a new incomplete array type given the element type, size
683 /// modifier, and index type qualifiers.
684 ///
685 /// By default, performs semantic analysis when building the array type.
686 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000687 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000688 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000689 unsigned IndexTypeQuals,
690 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000691
Mike Stump11289f42009-09-09 15:08:12 +0000692 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000693 /// size modifier, size expression, and index type qualifiers.
694 ///
695 /// By default, performs semantic analysis when building the array type.
696 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000697 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000698 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000699 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000700 unsigned IndexTypeQuals,
701 SourceRange BracketsRange);
702
Mike Stump11289f42009-09-09 15:08:12 +0000703 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000704 /// size modifier, size expression, and index type qualifiers.
705 ///
706 /// By default, performs semantic analysis when building the array type.
707 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000708 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000709 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000710 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000711 unsigned IndexTypeQuals,
712 SourceRange BracketsRange);
713
714 /// \brief Build a new vector type given the element type and
715 /// number of elements.
716 ///
717 /// By default, performs semantic analysis when building the vector type.
718 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000719 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000720 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000721
Douglas Gregord6ff3322009-08-04 16:50:30 +0000722 /// \brief Build a new extended vector type given the element type and
723 /// number of elements.
724 ///
725 /// By default, performs semantic analysis when building the vector type.
726 /// Subclasses may override this routine to provide different behavior.
727 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
728 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000729
730 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000731 /// given the element type and number of elements.
732 ///
733 /// By default, performs semantic analysis when building the vector type.
734 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000735 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000736 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000737 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000738
Douglas Gregord6ff3322009-08-04 16:50:30 +0000739 /// \brief Build a new function type.
740 ///
741 /// By default, performs semantic analysis when building the function type.
742 /// Subclasses may override this routine to provide different behavior.
743 QualType RebuildFunctionProtoType(QualType T,
Jordan Rose5c382722013-03-08 21:51:21 +0000744 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000745 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000746
John McCall550e0c22009-10-21 00:40:46 +0000747 /// \brief Build a new unprototyped function type.
748 QualType RebuildFunctionNoProtoType(QualType ResultType);
749
John McCallb96ec562009-12-04 22:46:56 +0000750 /// \brief Rebuild an unresolved typename type, given the decl that
751 /// the UnresolvedUsingTypenameDecl was transformed to.
752 QualType RebuildUnresolvedUsingType(Decl *D);
753
Douglas Gregord6ff3322009-08-04 16:50:30 +0000754 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000755 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000756 return SemaRef.Context.getTypeDeclType(Typedef);
757 }
758
759 /// \brief Build a new class/struct/union type.
760 QualType RebuildRecordType(RecordDecl *Record) {
761 return SemaRef.Context.getTypeDeclType(Record);
762 }
763
764 /// \brief Build a new Enum type.
765 QualType RebuildEnumType(EnumDecl *Enum) {
766 return SemaRef.Context.getTypeDeclType(Enum);
767 }
John McCallfcc33b02009-09-05 00:15:47 +0000768
Mike Stump11289f42009-09-09 15:08:12 +0000769 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000770 ///
771 /// By default, performs semantic analysis when building the typeof type.
772 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000773 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000774
Mike Stump11289f42009-09-09 15:08:12 +0000775 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000776 ///
777 /// By default, builds a new TypeOfType with the given underlying type.
778 QualType RebuildTypeOfType(QualType Underlying);
779
Alexis Hunte852b102011-05-24 22:41:36 +0000780 /// \brief Build a new unary transform type.
781 QualType RebuildUnaryTransformType(QualType BaseType,
782 UnaryTransformType::UTTKind UKind,
783 SourceLocation Loc);
784
Richard Smith74aeef52013-04-26 16:15:35 +0000785 /// \brief Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000786 ///
787 /// By default, performs semantic analysis when building the decltype type.
788 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000789 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000790
Richard Smith74aeef52013-04-26 16:15:35 +0000791 /// \brief Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000792 ///
793 /// By default, builds a new AutoType with the given deduced type.
Richard Smith74aeef52013-04-26 16:15:35 +0000794 QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) {
Richard Smith27d807c2013-04-30 13:56:41 +0000795 // Note, IsDependent is always false here: we implicitly convert an 'auto'
796 // which has been deduced to a dependent type into an undeduced 'auto', so
797 // that we'll retry deduction after the transformation.
Faisal Vali2b391ab2013-09-26 19:54:12 +0000798 return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto,
799 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000800 }
801
Douglas Gregord6ff3322009-08-04 16:50:30 +0000802 /// \brief Build a new template specialization type.
803 ///
804 /// By default, performs semantic analysis when building the template
805 /// specialization type. Subclasses may override this routine to provide
806 /// different behavior.
807 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000808 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000809 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000810
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000811 /// \brief Build a new parenthesized type.
812 ///
813 /// By default, builds a new ParenType type from the inner type.
814 /// Subclasses may override this routine to provide different behavior.
815 QualType RebuildParenType(QualType InnerType) {
816 return SemaRef.Context.getParenType(InnerType);
817 }
818
Douglas Gregord6ff3322009-08-04 16:50:30 +0000819 /// \brief Build a new qualified name type.
820 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000821 /// By default, builds a new ElaboratedType type from the keyword,
822 /// the nested-name-specifier and the named type.
823 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000824 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
825 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000826 NestedNameSpecifierLoc QualifierLoc,
827 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000828 return SemaRef.Context.getElaboratedType(Keyword,
829 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000830 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000831 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000832
833 /// \brief Build a new typename type that refers to a template-id.
834 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000835 /// By default, builds a new DependentNameType type from the
836 /// nested-name-specifier and the given type. Subclasses may override
837 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000838 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000839 ElaboratedTypeKeyword Keyword,
840 NestedNameSpecifierLoc QualifierLoc,
841 const IdentifierInfo *Name,
842 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000843 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000844 // Rebuild the template name.
845 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000846 CXXScopeSpec SS;
847 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +0000848 TemplateName InstName
Douglas Gregor9db53502011-03-02 18:07:45 +0000849 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Chad Rosier1dcde962012-08-08 18:46:20 +0000850
Douglas Gregora7a795b2011-03-01 20:11:18 +0000851 if (InstName.isNull())
852 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000853
Douglas Gregora7a795b2011-03-01 20:11:18 +0000854 // If it's still dependent, make a dependent specialization.
855 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000856 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
857 QualifierLoc.getNestedNameSpecifier(),
858 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000859 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000860
Douglas Gregora7a795b2011-03-01 20:11:18 +0000861 // Otherwise, make an elaborated type wrapping a non-dependent
862 // specialization.
863 QualType T =
864 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
865 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000866
Douglas Gregora7a795b2011-03-01 20:11:18 +0000867 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
868 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +0000869
870 return SemaRef.Context.getElaboratedType(Keyword,
871 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +0000872 T);
873 }
874
Douglas Gregord6ff3322009-08-04 16:50:30 +0000875 /// \brief Build a new typename type that refers to an identifier.
876 ///
877 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000878 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000879 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000880 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000881 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000882 NestedNameSpecifierLoc QualifierLoc,
883 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000884 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000885 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000886 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000887
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000888 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000889 // If the name is still dependent, just build a new dependent name type.
890 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +0000891 return SemaRef.Context.getDependentNameType(Keyword,
892 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000893 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000894 }
895
Abramo Bagnara6150c882010-05-11 21:36:43 +0000896 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000897 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000898 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000899
900 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
901
Abramo Bagnarad7548482010-05-19 21:37:53 +0000902 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000903 // into a non-dependent elaborated-type-specifier. Find the tag we're
904 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000905 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000906 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
907 if (!DC)
908 return QualType();
909
John McCallbf8c5192010-05-27 06:40:31 +0000910 if (SemaRef.RequireCompleteDeclContext(SS, DC))
911 return QualType();
912
Douglas Gregore677daf2010-03-31 22:19:08 +0000913 TagDecl *Tag = 0;
914 SemaRef.LookupQualifiedName(Result, DC);
915 switch (Result.getResultKind()) {
916 case LookupResult::NotFound:
917 case LookupResult::NotFoundInCurrentInstantiation:
918 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000919
Douglas Gregore677daf2010-03-31 22:19:08 +0000920 case LookupResult::Found:
921 Tag = Result.getAsSingle<TagDecl>();
922 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000923
Douglas Gregore677daf2010-03-31 22:19:08 +0000924 case LookupResult::FoundOverloaded:
925 case LookupResult::FoundUnresolvedValue:
926 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +0000927
Douglas Gregore677daf2010-03-31 22:19:08 +0000928 case LookupResult::Ambiguous:
929 // Let the LookupResult structure handle ambiguities.
930 return QualType();
931 }
932
933 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000934 // Check where the name exists but isn't a tag type and use that to emit
935 // better diagnostics.
936 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
937 SemaRef.LookupQualifiedName(Result, DC);
938 switch (Result.getResultKind()) {
939 case LookupResult::Found:
940 case LookupResult::FoundOverloaded:
941 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +0000942 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky0c438082011-01-24 19:01:04 +0000943 unsigned Kind = 0;
944 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smithdda56e42011-04-15 14:24:37 +0000945 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
946 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky0c438082011-01-24 19:01:04 +0000947 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
948 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
949 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +0000950 }
Nick Lewycky0c438082011-01-24 19:01:04 +0000951 default:
952 // FIXME: Would be nice to highlight just the source range.
953 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
954 << Kind << Id << DC;
955 break;
956 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000957 return QualType();
958 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000959
Richard Trieucaa33d32011-06-10 03:11:26 +0000960 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
961 IdLoc, *Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +0000962 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000963 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
964 return QualType();
965 }
966
967 // Build the elaborated-type-specifier type.
968 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +0000969 return SemaRef.Context.getElaboratedType(Keyword,
970 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000971 T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000972 }
Mike Stump11289f42009-09-09 15:08:12 +0000973
Douglas Gregor822d0302011-01-12 17:07:58 +0000974 /// \brief Build a new pack expansion type.
975 ///
976 /// By default, builds a new PackExpansionType type from the given pattern.
977 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000978 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +0000979 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000980 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +0000981 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000982 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
983 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +0000984 }
985
Eli Friedman0dfb8892011-10-06 23:00:33 +0000986 /// \brief Build a new atomic type given its value type.
987 ///
988 /// By default, performs semantic analysis when building the atomic type.
989 /// Subclasses may override this routine to provide different behavior.
990 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
991
Douglas Gregor71dc5092009-08-06 06:41:21 +0000992 /// \brief Build a new template name given a nested name specifier, a flag
993 /// indicating whether the "template" keyword was provided, and the template
994 /// that the template name refers to.
995 ///
996 /// By default, builds the new template name directly. Subclasses may override
997 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000998 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +0000999 bool TemplateKW,
1000 TemplateDecl *Template);
1001
Douglas Gregor71dc5092009-08-06 06:41:21 +00001002 /// \brief Build a new template name given a nested name specifier and the
1003 /// name that is referred to as a template.
1004 ///
1005 /// By default, performs semantic analysis to determine whether the name can
1006 /// be resolved to a specific template, then builds the appropriate kind of
1007 /// template name. Subclasses may override this routine to provide different
1008 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001009 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1010 const IdentifierInfo &Name,
1011 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00001012 QualType ObjectType,
1013 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001014
Douglas Gregor71395fa2009-11-04 00:56:37 +00001015 /// \brief Build a new template name given a nested name specifier and the
1016 /// overloaded operator name that is referred to as a template.
1017 ///
1018 /// By default, performs semantic analysis to determine whether the name can
1019 /// be resolved to a specific template, then builds the appropriate kind of
1020 /// template name. Subclasses may override this routine to provide different
1021 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001022 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001023 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00001024 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001025 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +00001026
1027 /// \brief Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001028 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001029 ///
1030 /// By default, performs semantic analysis to determine whether the name can
1031 /// be resolved to a specific template, then builds the appropriate kind of
1032 /// template name. Subclasses may override this routine to provide different
1033 /// behavior.
1034 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1035 const TemplateArgument &ArgPack) {
1036 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1037 }
1038
Douglas Gregorebe10102009-08-20 07:17:43 +00001039 /// \brief Build a new compound statement.
1040 ///
1041 /// By default, performs semantic analysis to build the new statement.
1042 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001043 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001044 MultiStmtArg Statements,
1045 SourceLocation RBraceLoc,
1046 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001047 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001048 IsStmtExpr);
1049 }
1050
1051 /// \brief Build a new case statement.
1052 ///
1053 /// By default, performs semantic analysis to build the new statement.
1054 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001055 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001056 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001057 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001058 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001059 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001060 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001061 ColonLoc);
1062 }
Mike Stump11289f42009-09-09 15:08:12 +00001063
Douglas Gregorebe10102009-08-20 07:17:43 +00001064 /// \brief Attach the body to a new case statement.
1065 ///
1066 /// By default, performs semantic analysis to build the new statement.
1067 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001068 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001069 getSema().ActOnCaseStmtBody(S, Body);
1070 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001071 }
Mike Stump11289f42009-09-09 15:08:12 +00001072
Douglas Gregorebe10102009-08-20 07:17:43 +00001073 /// \brief Build a new default statement.
1074 ///
1075 /// By default, performs semantic analysis to build the new statement.
1076 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001077 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001078 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001079 Stmt *SubStmt) {
1080 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +00001081 /*CurScope=*/0);
1082 }
Mike Stump11289f42009-09-09 15:08:12 +00001083
Douglas Gregorebe10102009-08-20 07:17:43 +00001084 /// \brief Build a new label statement.
1085 ///
1086 /// By default, performs semantic analysis to build the new statement.
1087 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001088 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1089 SourceLocation ColonLoc, Stmt *SubStmt) {
1090 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001091 }
Mike Stump11289f42009-09-09 15:08:12 +00001092
Richard Smithc202b282012-04-14 00:33:13 +00001093 /// \brief Build a new label statement.
1094 ///
1095 /// By default, performs semantic analysis to build the new statement.
1096 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001097 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1098 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001099 Stmt *SubStmt) {
1100 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1101 }
1102
Douglas Gregorebe10102009-08-20 07:17:43 +00001103 /// \brief Build a new "if" statement.
1104 ///
1105 /// By default, performs semantic analysis to build the new statement.
1106 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001107 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier1dcde962012-08-08 18:46:20 +00001108 VarDecl *CondVar, Stmt *Then,
Chris Lattnercab02a62011-02-17 20:34:02 +00001109 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001110 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001111 }
Mike Stump11289f42009-09-09 15:08:12 +00001112
Douglas Gregorebe10102009-08-20 07:17:43 +00001113 /// \brief Start building a new switch statement.
1114 ///
1115 /// By default, performs semantic analysis to build the new statement.
1116 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001117 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001118 Expr *Cond, VarDecl *CondVar) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001119 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001120 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001121 }
Mike Stump11289f42009-09-09 15:08:12 +00001122
Douglas Gregorebe10102009-08-20 07:17:43 +00001123 /// \brief Attach the body to the switch statement.
1124 ///
1125 /// By default, performs semantic analysis to build the new statement.
1126 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001127 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001128 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001129 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001130 }
1131
1132 /// \brief Build a new while statement.
1133 ///
1134 /// By default, performs semantic analysis to build the new statement.
1135 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001136 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1137 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001138 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001139 }
Mike Stump11289f42009-09-09 15:08:12 +00001140
Douglas Gregorebe10102009-08-20 07:17:43 +00001141 /// \brief Build a new do-while statement.
1142 ///
1143 /// By default, performs semantic analysis to build the new statement.
1144 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001145 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001146 SourceLocation WhileLoc, SourceLocation LParenLoc,
1147 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001148 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1149 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001150 }
1151
1152 /// \brief Build a new for statement.
1153 ///
1154 /// By default, performs semantic analysis to build the new statement.
1155 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001156 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier1dcde962012-08-08 18:46:20 +00001157 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001158 VarDecl *CondVar, Sema::FullExprArg Inc,
1159 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001160 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001161 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001162 }
Mike Stump11289f42009-09-09 15:08:12 +00001163
Douglas Gregorebe10102009-08-20 07:17:43 +00001164 /// \brief Build a new goto statement.
1165 ///
1166 /// By default, performs semantic analysis to build the new statement.
1167 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001168 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1169 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001170 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001171 }
1172
1173 /// \brief Build a new indirect goto statement.
1174 ///
1175 /// By default, performs semantic analysis to build the new statement.
1176 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001177 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001178 SourceLocation StarLoc,
1179 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001180 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001181 }
Mike Stump11289f42009-09-09 15:08:12 +00001182
Douglas Gregorebe10102009-08-20 07:17:43 +00001183 /// \brief Build a new return statement.
1184 ///
1185 /// By default, performs semantic analysis to build the new statement.
1186 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001187 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCallb268a282010-08-23 23:25:46 +00001188 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001189 }
Mike Stump11289f42009-09-09 15:08:12 +00001190
Douglas Gregorebe10102009-08-20 07:17:43 +00001191 /// \brief Build a new declaration statement.
1192 ///
1193 /// By default, performs semantic analysis to build the new statement.
1194 /// Subclasses may override this routine to provide different behavior.
Rafael Espindolaab417692013-07-09 12:05:01 +00001195 StmtResult RebuildDeclStmt(llvm::MutableArrayRef<Decl *> Decls,
1196 SourceLocation StartLoc, SourceLocation EndLoc) {
1197 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001198 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001199 }
Mike Stump11289f42009-09-09 15:08:12 +00001200
Anders Carlssonaaeef072010-01-24 05:50:09 +00001201 /// \brief Build a new inline asm statement.
1202 ///
1203 /// By default, performs semantic analysis to build the new statement.
1204 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001205 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1206 bool IsVolatile, unsigned NumOutputs,
1207 unsigned NumInputs, IdentifierInfo **Names,
1208 MultiExprArg Constraints, MultiExprArg Exprs,
1209 Expr *AsmString, MultiExprArg Clobbers,
1210 SourceLocation RParenLoc) {
1211 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1212 NumInputs, Names, Constraints, Exprs,
1213 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001214 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001215
Chad Rosier32503022012-06-11 20:47:18 +00001216 /// \brief Build a new MS style inline asm statement.
1217 ///
1218 /// By default, performs semantic analysis to build the new statement.
1219 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001220 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001221 ArrayRef<Token> AsmToks,
1222 StringRef AsmString,
1223 unsigned NumOutputs, unsigned NumInputs,
1224 ArrayRef<StringRef> Constraints,
1225 ArrayRef<StringRef> Clobbers,
1226 ArrayRef<Expr*> Exprs,
1227 SourceLocation EndLoc) {
1228 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1229 NumOutputs, NumInputs,
1230 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001231 }
1232
James Dennett2a4d13c2012-06-15 07:13:21 +00001233 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001234 ///
1235 /// By default, performs semantic analysis to build the new statement.
1236 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001237 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001238 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001239 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001240 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001241 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001242 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001243 }
1244
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001245 /// \brief Rebuild an Objective-C exception declaration.
1246 ///
1247 /// By default, performs semantic analysis to build the new declaration.
1248 /// Subclasses may override this routine to provide different behavior.
1249 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1250 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001251 return getSema().BuildObjCExceptionDecl(TInfo, T,
1252 ExceptionDecl->getInnerLocStart(),
1253 ExceptionDecl->getLocation(),
1254 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001255 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001256
James Dennett2a4d13c2012-06-15 07:13:21 +00001257 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001258 ///
1259 /// By default, performs semantic analysis to build the new statement.
1260 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001261 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001262 SourceLocation RParenLoc,
1263 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001264 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001265 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001266 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001267 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001268
James Dennett2a4d13c2012-06-15 07:13:21 +00001269 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001270 ///
1271 /// By default, performs semantic analysis to build the new statement.
1272 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001273 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001274 Stmt *Body) {
1275 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001276 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001277
James Dennett2a4d13c2012-06-15 07:13:21 +00001278 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001279 ///
1280 /// By default, performs semantic analysis to build the new statement.
1281 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001282 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001283 Expr *Operand) {
1284 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001285 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001286
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001287 /// \brief Build a new OpenMP parallel directive.
1288 ///
1289 /// By default, performs semantic analysis to build the new statement.
1290 /// Subclasses may override this routine to provide different behavior.
1291 StmtResult RebuildOMPParallelDirective(ArrayRef<OMPClause *> Clauses,
1292 Stmt *AStmt,
1293 SourceLocation StartLoc,
1294 SourceLocation EndLoc) {
1295 return getSema().ActOnOpenMPParallelDirective(Clauses, AStmt,
1296 StartLoc, EndLoc);
1297 }
1298
1299 /// \brief Build a new OpenMP 'default' clause.
1300 ///
1301 /// By default, performs semantic analysis to build the new statement.
1302 /// Subclasses may override this routine to provide different behavior.
1303 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1304 SourceLocation KindKwLoc,
1305 SourceLocation StartLoc,
1306 SourceLocation LParenLoc,
1307 SourceLocation EndLoc) {
1308 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1309 StartLoc, LParenLoc, EndLoc);
1310 }
1311
1312 /// \brief Build a new OpenMP 'private' clause.
1313 ///
1314 /// By default, performs semantic analysis to build the new statement.
1315 /// Subclasses may override this routine to provide different behavior.
1316 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1317 SourceLocation StartLoc,
1318 SourceLocation LParenLoc,
1319 SourceLocation EndLoc) {
1320 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1321 EndLoc);
1322 }
1323
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001324 /// \brief Build a new OpenMP 'firstprivate' clause.
1325 ///
1326 /// By default, performs semantic analysis to build the new statement.
1327 /// Subclasses may override this routine to provide different behavior.
1328 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1329 SourceLocation StartLoc,
1330 SourceLocation LParenLoc,
1331 SourceLocation EndLoc) {
1332 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1333 EndLoc);
1334 }
1335
Alexey Bataev758e55e2013-09-06 18:03:48 +00001336 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1337 SourceLocation StartLoc,
1338 SourceLocation LParenLoc,
1339 SourceLocation EndLoc) {
1340 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1341 EndLoc);
1342 }
1343
James Dennett2a4d13c2012-06-15 07:13:21 +00001344 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001345 ///
1346 /// By default, performs semantic analysis to build the new statement.
1347 /// Subclasses may override this routine to provide different behavior.
1348 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1349 Expr *object) {
1350 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1351 }
1352
James Dennett2a4d13c2012-06-15 07:13:21 +00001353 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001354 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001355 /// By default, performs semantic analysis to build the new statement.
1356 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001357 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001358 Expr *Object, Stmt *Body) {
1359 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001360 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001361
James Dennett2a4d13c2012-06-15 07:13:21 +00001362 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001363 ///
1364 /// By default, performs semantic analysis to build the new statement.
1365 /// Subclasses may override this routine to provide different behavior.
1366 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1367 Stmt *Body) {
1368 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1369 }
John McCall53848232011-07-27 01:07:15 +00001370
Douglas Gregorf68a5082010-04-22 23:10:45 +00001371 /// \brief Build a new Objective-C fast enumeration statement.
1372 ///
1373 /// By default, performs semantic analysis to build the new statement.
1374 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001375 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001376 Stmt *Element,
1377 Expr *Collection,
1378 SourceLocation RParenLoc,
1379 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001380 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001381 Element,
John McCallb268a282010-08-23 23:25:46 +00001382 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001383 RParenLoc);
1384 if (ForEachStmt.isInvalid())
1385 return StmtError();
1386
1387 return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001388 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001389
Douglas Gregorebe10102009-08-20 07:17:43 +00001390 /// \brief Build a new C++ exception declaration.
1391 ///
1392 /// By default, performs semantic analysis to build the new decaration.
1393 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001394 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001395 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001396 SourceLocation StartLoc,
1397 SourceLocation IdLoc,
1398 IdentifierInfo *Id) {
Douglas Gregor40965fa2011-04-14 22:32:28 +00001399 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1400 StartLoc, IdLoc, Id);
1401 if (Var)
1402 getSema().CurContext->addDecl(Var);
1403 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001404 }
1405
1406 /// \brief Build a new C++ catch statement.
1407 ///
1408 /// By default, performs semantic analysis to build the new statement.
1409 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001410 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001411 VarDecl *ExceptionDecl,
1412 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001413 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1414 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001415 }
Mike Stump11289f42009-09-09 15:08:12 +00001416
Douglas Gregorebe10102009-08-20 07:17:43 +00001417 /// \brief Build a new C++ try statement.
1418 ///
1419 /// By default, performs semantic analysis to build the new statement.
1420 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001421 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1422 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001423 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001424 }
Mike Stump11289f42009-09-09 15:08:12 +00001425
Richard Smith02e85f32011-04-14 22:09:26 +00001426 /// \brief Build a new C++0x range-based for statement.
1427 ///
1428 /// By default, performs semantic analysis to build the new statement.
1429 /// Subclasses may override this routine to provide different behavior.
1430 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1431 SourceLocation ColonLoc,
1432 Stmt *Range, Stmt *BeginEnd,
1433 Expr *Cond, Expr *Inc,
1434 Stmt *LoopVar,
1435 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001436 // If we've just learned that the range is actually an Objective-C
1437 // collection, treat this as an Objective-C fast enumeration loop.
1438 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1439 if (RangeStmt->isSingleDecl()) {
1440 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001441 if (RangeVar->isInvalidDecl())
1442 return StmtError();
1443
Douglas Gregorf7106af2013-04-08 18:40:13 +00001444 Expr *RangeExpr = RangeVar->getInit();
1445 if (!RangeExpr->isTypeDependent() &&
1446 RangeExpr->getType()->isObjCObjectPointerType())
1447 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1448 RParenLoc);
1449 }
1450 }
1451 }
1452
Richard Smith02e85f32011-04-14 22:09:26 +00001453 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001454 Cond, Inc, LoopVar, RParenLoc,
1455 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001456 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001457
1458 /// \brief Build a new C++0x range-based for statement.
1459 ///
1460 /// By default, performs semantic analysis to build the new statement.
1461 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001462 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001463 bool IsIfExists,
1464 NestedNameSpecifierLoc QualifierLoc,
1465 DeclarationNameInfo NameInfo,
1466 Stmt *Nested) {
1467 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1468 QualifierLoc, NameInfo, Nested);
1469 }
1470
Richard Smith02e85f32011-04-14 22:09:26 +00001471 /// \brief Attach body to a C++0x range-based for statement.
1472 ///
1473 /// By default, performs semantic analysis to finish the new statement.
1474 /// Subclasses may override this routine to provide different behavior.
1475 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1476 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1477 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001478
David Majnemerfad8f482013-10-15 09:33:02 +00001479 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
1480 Stmt *TryBlock, Stmt *Handler) {
1481 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001482 }
1483
David Majnemerfad8f482013-10-15 09:33:02 +00001484 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001485 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001486 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001487 }
1488
David Majnemerfad8f482013-10-15 09:33:02 +00001489 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
1490 return getSema().ActOnSEHFinallyBlock(Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001491 }
1492
Douglas Gregora16548e2009-08-11 05:31:07 +00001493 /// \brief Build a new expression that references a declaration.
1494 ///
1495 /// By default, performs semantic analysis to build the new expression.
1496 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001497 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001498 LookupResult &R,
1499 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001500 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1501 }
1502
1503
1504 /// \brief Build a new expression that references a declaration.
1505 ///
1506 /// By default, performs semantic analysis to build the new expression.
1507 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001508 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001509 ValueDecl *VD,
1510 const DeclarationNameInfo &NameInfo,
1511 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001512 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001513 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001514
1515 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001516
1517 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001518 }
Mike Stump11289f42009-09-09 15:08:12 +00001519
Douglas Gregora16548e2009-08-11 05:31:07 +00001520 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001521 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001522 /// By default, performs semantic analysis to build the new expression.
1523 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001524 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001525 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001526 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001527 }
1528
Douglas Gregorad8a3362009-09-04 17:36:40 +00001529 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001530 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001531 /// By default, performs semantic analysis to build the new expression.
1532 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001533 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001534 SourceLocation OperatorLoc,
1535 bool isArrow,
1536 CXXScopeSpec &SS,
1537 TypeSourceInfo *ScopeType,
1538 SourceLocation CCLoc,
1539 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001540 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001541
Douglas Gregora16548e2009-08-11 05:31:07 +00001542 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001543 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001544 /// By default, performs semantic analysis to build the new expression.
1545 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001546 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001547 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001548 Expr *SubExpr) {
1549 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001550 }
Mike Stump11289f42009-09-09 15:08:12 +00001551
Douglas Gregor882211c2010-04-28 22:16:22 +00001552 /// \brief Build a new builtin offsetof expression.
1553 ///
1554 /// By default, performs semantic analysis to build the new expression.
1555 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001556 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001557 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001558 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001559 unsigned NumComponents,
1560 SourceLocation RParenLoc) {
1561 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1562 NumComponents, RParenLoc);
1563 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001564
1565 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001566 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001567 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001568 /// By default, performs semantic analysis to build the new expression.
1569 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001570 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1571 SourceLocation OpLoc,
1572 UnaryExprOrTypeTrait ExprKind,
1573 SourceRange R) {
1574 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001575 }
1576
Peter Collingbournee190dee2011-03-11 19:24:49 +00001577 /// \brief Build a new sizeof, alignof or vec step expression with an
1578 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001579 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001580 /// By default, performs semantic analysis to build the new expression.
1581 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001582 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1583 UnaryExprOrTypeTrait ExprKind,
1584 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001585 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001586 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001587 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001588 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001589
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001590 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001591 }
Mike Stump11289f42009-09-09 15:08:12 +00001592
Douglas Gregora16548e2009-08-11 05:31:07 +00001593 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001594 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001595 /// By default, performs semantic analysis to build the new expression.
1596 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001597 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001598 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001599 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001600 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001601 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1602 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001603 RBracketLoc);
1604 }
1605
1606 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001607 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001608 /// By default, performs semantic analysis to build the new expression.
1609 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001610 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001611 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001612 SourceLocation RParenLoc,
1613 Expr *ExecConfig = 0) {
John McCallb268a282010-08-23 23:25:46 +00001614 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001615 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001616 }
1617
1618 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001619 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001620 /// By default, performs semantic analysis to build the new expression.
1621 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001622 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001623 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001624 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001625 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001626 const DeclarationNameInfo &MemberNameInfo,
1627 ValueDecl *Member,
1628 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001629 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001630 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00001631 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1632 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00001633 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001634 // We have a reference to an unnamed field. This is always the
1635 // base of an anonymous struct/union member access, i.e. the
1636 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001637 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001638 assert(Member->getType()->isRecordType() &&
1639 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001640
Richard Smithcab9a7d2011-10-26 19:06:56 +00001641 BaseResult =
1642 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley01296292011-04-08 18:41:53 +00001643 QualifierLoc.getNestedNameSpecifier(),
1644 FoundDecl, Member);
1645 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001646 return ExprError();
John Wiegley01296292011-04-08 18:41:53 +00001647 Base = BaseResult.take();
John McCall7decc9e2010-11-18 06:31:45 +00001648 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001649 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001650 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001651 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001652 cast<FieldDecl>(Member)->getType(),
1653 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001654 return getSema().Owned(ME);
1655 }
Mike Stump11289f42009-09-09 15:08:12 +00001656
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001657 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001658 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001659
John Wiegley01296292011-04-08 18:41:53 +00001660 Base = BaseResult.take();
John McCallb268a282010-08-23 23:25:46 +00001661 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001662
John McCall16df1e52010-03-30 21:47:33 +00001663 // FIXME: this involves duplicating earlier analysis in a lot of
1664 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001665 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001666 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001667 R.resolveKind();
1668
John McCallb268a282010-08-23 23:25:46 +00001669 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001670 SS, TemplateKWLoc,
1671 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001672 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001673 }
Mike Stump11289f42009-09-09 15:08:12 +00001674
Douglas Gregora16548e2009-08-11 05:31:07 +00001675 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001676 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001677 /// By default, performs semantic analysis to build the new expression.
1678 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001679 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001680 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001681 Expr *LHS, Expr *RHS) {
1682 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001683 }
1684
1685 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001686 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001687 /// By default, performs semantic analysis to build the new expression.
1688 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001689 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001690 SourceLocation QuestionLoc,
1691 Expr *LHS,
1692 SourceLocation ColonLoc,
1693 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001694 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1695 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001696 }
1697
Douglas Gregora16548e2009-08-11 05:31:07 +00001698 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001699 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001700 /// By default, performs semantic analysis to build the new expression.
1701 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001702 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001703 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001704 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001705 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001706 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001707 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001708 }
Mike Stump11289f42009-09-09 15:08:12 +00001709
Douglas Gregora16548e2009-08-11 05:31:07 +00001710 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001711 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001712 /// By default, performs semantic analysis to build the new expression.
1713 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001714 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001715 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001716 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001717 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001718 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001719 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001720 }
Mike Stump11289f42009-09-09 15:08:12 +00001721
Douglas Gregora16548e2009-08-11 05:31:07 +00001722 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001723 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001724 /// By default, performs semantic analysis to build the new expression.
1725 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001726 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001727 SourceLocation OpLoc,
1728 SourceLocation AccessorLoc,
1729 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001730
John McCall10eae182009-11-30 22:42:35 +00001731 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001732 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001733 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001734 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001735 SS, SourceLocation(),
1736 /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001737 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001738 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001739 }
Mike Stump11289f42009-09-09 15:08:12 +00001740
Douglas Gregora16548e2009-08-11 05:31:07 +00001741 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001742 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001743 /// By default, performs semantic analysis to build the new expression.
1744 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001745 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00001746 MultiExprArg Inits,
1747 SourceLocation RBraceLoc,
1748 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001749 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001750 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00001751 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001752 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00001753
Douglas Gregord3d93062009-11-09 17:16:50 +00001754 // Patch in the result type we were given, which may have been computed
1755 // when the initial InitListExpr was built.
1756 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1757 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001758 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001759 }
Mike Stump11289f42009-09-09 15:08:12 +00001760
Douglas Gregora16548e2009-08-11 05:31:07 +00001761 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001762 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001763 /// By default, performs semantic analysis to build the new expression.
1764 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001765 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001766 MultiExprArg ArrayExprs,
1767 SourceLocation EqualOrColonLoc,
1768 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001769 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001770 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001771 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001772 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001773 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001774 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001775
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001776 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001777 }
Mike Stump11289f42009-09-09 15:08:12 +00001778
Douglas Gregora16548e2009-08-11 05:31:07 +00001779 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001780 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001781 /// By default, builds the implicit value initialization without performing
1782 /// any semantic analysis. Subclasses may override this routine to provide
1783 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001784 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001785 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1786 }
Mike Stump11289f42009-09-09 15:08:12 +00001787
Douglas Gregora16548e2009-08-11 05:31:07 +00001788 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001789 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001790 /// By default, performs semantic analysis to build the new expression.
1791 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001792 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001793 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001794 SourceLocation RParenLoc) {
1795 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001796 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001797 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001798 }
1799
1800 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001801 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001802 /// By default, performs semantic analysis to build the new expression.
1803 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001804 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00001805 MultiExprArg SubExprs,
1806 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001807 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001808 }
Mike Stump11289f42009-09-09 15:08:12 +00001809
Douglas Gregora16548e2009-08-11 05:31:07 +00001810 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001811 ///
1812 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001813 /// rather than attempting to map the label statement itself.
1814 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001815 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001816 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001817 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001818 }
Mike Stump11289f42009-09-09 15:08:12 +00001819
Douglas Gregora16548e2009-08-11 05:31:07 +00001820 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001821 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001822 /// By default, performs semantic analysis to build the new expression.
1823 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001824 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001825 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001826 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001827 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001828 }
Mike Stump11289f42009-09-09 15:08:12 +00001829
Douglas Gregora16548e2009-08-11 05:31:07 +00001830 /// \brief Build a new __builtin_choose_expr expression.
1831 ///
1832 /// By default, performs semantic analysis to build the new expression.
1833 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001834 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001835 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001836 SourceLocation RParenLoc) {
1837 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001838 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001839 RParenLoc);
1840 }
Mike Stump11289f42009-09-09 15:08:12 +00001841
Peter Collingbourne91147592011-04-15 00:35:48 +00001842 /// \brief Build a new generic selection expression.
1843 ///
1844 /// By default, performs semantic analysis to build the new expression.
1845 /// Subclasses may override this routine to provide different behavior.
1846 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1847 SourceLocation DefaultLoc,
1848 SourceLocation RParenLoc,
1849 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00001850 ArrayRef<TypeSourceInfo *> Types,
1851 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00001852 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00001853 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00001854 }
1855
Douglas Gregora16548e2009-08-11 05:31:07 +00001856 /// \brief Build a new overloaded operator call expression.
1857 ///
1858 /// By default, performs semantic analysis to build the new expression.
1859 /// The semantic analysis provides the behavior of template instantiation,
1860 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001861 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001862 /// argument-dependent lookup, etc. Subclasses may override this routine to
1863 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001864 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001865 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001866 Expr *Callee,
1867 Expr *First,
1868 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001869
1870 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001871 /// reinterpret_cast.
1872 ///
1873 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001874 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001875 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001876 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001877 Stmt::StmtClass Class,
1878 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001879 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001880 SourceLocation RAngleLoc,
1881 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001882 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001883 SourceLocation RParenLoc) {
1884 switch (Class) {
1885 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001886 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001887 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001888 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001889
1890 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001891 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001892 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001893 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001894
Douglas Gregora16548e2009-08-11 05:31:07 +00001895 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001896 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001897 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001898 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001899 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001900
Douglas Gregora16548e2009-08-11 05:31:07 +00001901 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001902 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001903 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001904 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001905
Douglas Gregora16548e2009-08-11 05:31:07 +00001906 default:
David Blaikie83d382b2011-09-23 05:06:16 +00001907 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00001908 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001909 }
Mike Stump11289f42009-09-09 15:08:12 +00001910
Douglas Gregora16548e2009-08-11 05:31:07 +00001911 /// \brief Build a new C++ static_cast expression.
1912 ///
1913 /// By default, performs semantic analysis to build the new expression.
1914 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001915 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001916 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001917 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001918 SourceLocation RAngleLoc,
1919 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001920 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001921 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001922 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001923 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001924 SourceRange(LAngleLoc, RAngleLoc),
1925 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001926 }
1927
1928 /// \brief Build a new C++ dynamic_cast expression.
1929 ///
1930 /// By default, performs semantic analysis to build the new expression.
1931 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001932 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001933 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001934 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001935 SourceLocation RAngleLoc,
1936 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001937 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001938 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001939 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001940 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001941 SourceRange(LAngleLoc, RAngleLoc),
1942 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001943 }
1944
1945 /// \brief Build a new C++ reinterpret_cast expression.
1946 ///
1947 /// By default, performs semantic analysis to build the new expression.
1948 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001949 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001950 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001951 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001952 SourceLocation RAngleLoc,
1953 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001954 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001955 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001956 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001957 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001958 SourceRange(LAngleLoc, RAngleLoc),
1959 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001960 }
1961
1962 /// \brief Build a new C++ const_cast expression.
1963 ///
1964 /// By default, performs semantic analysis to build the new expression.
1965 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001966 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001967 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001968 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001969 SourceLocation RAngleLoc,
1970 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001971 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001972 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001973 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001974 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001975 SourceRange(LAngleLoc, RAngleLoc),
1976 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001977 }
Mike Stump11289f42009-09-09 15:08:12 +00001978
Douglas Gregora16548e2009-08-11 05:31:07 +00001979 /// \brief Build a new C++ functional-style cast expression.
1980 ///
1981 /// By default, performs semantic analysis to build the new expression.
1982 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001983 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1984 SourceLocation LParenLoc,
1985 Expr *Sub,
1986 SourceLocation RParenLoc) {
1987 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001988 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001989 RParenLoc);
1990 }
Mike Stump11289f42009-09-09 15:08:12 +00001991
Douglas Gregora16548e2009-08-11 05:31:07 +00001992 /// \brief Build a new C++ typeid(type) expression.
1993 ///
1994 /// By default, performs semantic analysis to build the new expression.
1995 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001996 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001997 SourceLocation TypeidLoc,
1998 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001999 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002000 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002001 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002002 }
Mike Stump11289f42009-09-09 15:08:12 +00002003
Francois Pichet9f4f2072010-09-08 12:20:18 +00002004
Douglas Gregora16548e2009-08-11 05:31:07 +00002005 /// \brief Build a new C++ typeid(expr) expression.
2006 ///
2007 /// By default, performs semantic analysis to build the new expression.
2008 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002009 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002010 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002011 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002012 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002013 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002014 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002015 }
2016
Francois Pichet9f4f2072010-09-08 12:20:18 +00002017 /// \brief Build a new C++ __uuidof(type) expression.
2018 ///
2019 /// By default, performs semantic analysis to build the new expression.
2020 /// Subclasses may override this routine to provide different behavior.
2021 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2022 SourceLocation TypeidLoc,
2023 TypeSourceInfo *Operand,
2024 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002025 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002026 RParenLoc);
2027 }
2028
2029 /// \brief Build a new C++ __uuidof(expr) expression.
2030 ///
2031 /// By default, performs semantic analysis to build the new expression.
2032 /// Subclasses may override this routine to provide different behavior.
2033 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2034 SourceLocation TypeidLoc,
2035 Expr *Operand,
2036 SourceLocation RParenLoc) {
2037 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2038 RParenLoc);
2039 }
2040
Douglas Gregora16548e2009-08-11 05:31:07 +00002041 /// \brief Build a new C++ "this" expression.
2042 ///
2043 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002044 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002045 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002046 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002047 QualType ThisType,
2048 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002049 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002050 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00002051 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
2052 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00002053 }
2054
2055 /// \brief Build a new C++ throw expression.
2056 ///
2057 /// By default, performs semantic analysis to build the new expression.
2058 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002059 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2060 bool IsThrownVariableInScope) {
2061 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002062 }
2063
2064 /// \brief Build a new C++ default-argument expression.
2065 ///
2066 /// By default, builds a new default-argument expression, which does not
2067 /// require any semantic analysis. Subclasses may override this routine to
2068 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002069 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002070 ParmVarDecl *Param) {
2071 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
2072 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00002073 }
2074
Richard Smith852c9db2013-04-20 22:23:05 +00002075 /// \brief Build a new C++11 default-initialization expression.
2076 ///
2077 /// By default, builds a new default field initialization expression, which
2078 /// does not require any semantic analysis. Subclasses may override this
2079 /// routine to provide different behavior.
2080 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2081 FieldDecl *Field) {
2082 return getSema().Owned(CXXDefaultInitExpr::Create(getSema().Context, Loc,
2083 Field));
2084 }
2085
Douglas Gregora16548e2009-08-11 05:31:07 +00002086 /// \brief Build a new C++ zero-initialization expression.
2087 ///
2088 /// By default, performs semantic analysis to build the new expression.
2089 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002090 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2091 SourceLocation LParenLoc,
2092 SourceLocation RParenLoc) {
2093 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002094 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002095 }
Mike Stump11289f42009-09-09 15:08:12 +00002096
Douglas Gregora16548e2009-08-11 05:31:07 +00002097 /// \brief Build a new C++ "new" expression.
2098 ///
2099 /// By default, performs semantic analysis to build the new expression.
2100 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002101 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002102 bool UseGlobal,
2103 SourceLocation PlacementLParen,
2104 MultiExprArg PlacementArgs,
2105 SourceLocation PlacementRParen,
2106 SourceRange TypeIdParens,
2107 QualType AllocatedType,
2108 TypeSourceInfo *AllocatedTypeInfo,
2109 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002110 SourceRange DirectInitRange,
2111 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002112 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002113 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002114 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002115 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002116 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002117 AllocatedType,
2118 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002119 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002120 DirectInitRange,
2121 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002122 }
Mike Stump11289f42009-09-09 15:08:12 +00002123
Douglas Gregora16548e2009-08-11 05:31:07 +00002124 /// \brief Build a new C++ "delete" expression.
2125 ///
2126 /// By default, performs semantic analysis to build the new expression.
2127 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002128 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002129 bool IsGlobalDelete,
2130 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002131 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002132 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002133 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002134 }
Mike Stump11289f42009-09-09 15:08:12 +00002135
Douglas Gregora16548e2009-08-11 05:31:07 +00002136 /// \brief Build a new unary type trait expression.
2137 ///
2138 /// By default, performs semantic analysis to build the new expression.
2139 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002140 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00002141 SourceLocation StartLoc,
2142 TypeSourceInfo *T,
2143 SourceLocation RParenLoc) {
2144 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002145 }
2146
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00002147 /// \brief Build a new binary type trait expression.
2148 ///
2149 /// By default, performs semantic analysis to build the new expression.
2150 /// Subclasses may override this routine to provide different behavior.
2151 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
2152 SourceLocation StartLoc,
2153 TypeSourceInfo *LhsT,
2154 TypeSourceInfo *RhsT,
2155 SourceLocation RParenLoc) {
2156 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
2157 }
2158
Douglas Gregor29c42f22012-02-24 07:38:34 +00002159 /// \brief Build a new type trait expression.
2160 ///
2161 /// By default, performs semantic analysis to build the new expression.
2162 /// Subclasses may override this routine to provide different behavior.
2163 ExprResult RebuildTypeTrait(TypeTrait Trait,
2164 SourceLocation StartLoc,
2165 ArrayRef<TypeSourceInfo *> Args,
2166 SourceLocation RParenLoc) {
2167 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2168 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002169
John Wiegley6242b6a2011-04-28 00:16:57 +00002170 /// \brief Build a new array type trait expression.
2171 ///
2172 /// By default, performs semantic analysis to build the new expression.
2173 /// Subclasses may override this routine to provide different behavior.
2174 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2175 SourceLocation StartLoc,
2176 TypeSourceInfo *TSInfo,
2177 Expr *DimExpr,
2178 SourceLocation RParenLoc) {
2179 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2180 }
2181
John Wiegleyf9f65842011-04-25 06:54:41 +00002182 /// \brief Build a new expression trait expression.
2183 ///
2184 /// By default, performs semantic analysis to build the new expression.
2185 /// Subclasses may override this routine to provide different behavior.
2186 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2187 SourceLocation StartLoc,
2188 Expr *Queried,
2189 SourceLocation RParenLoc) {
2190 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2191 }
2192
Mike Stump11289f42009-09-09 15:08:12 +00002193 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002194 /// expression.
2195 ///
2196 /// By default, performs semantic analysis to build the new expression.
2197 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002198 ExprResult RebuildDependentScopeDeclRefExpr(
2199 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002200 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002201 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002202 const TemplateArgumentListInfo *TemplateArgs,
2203 bool IsAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002204 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002205 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002206
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002207 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnara7945c982012-01-27 09:46:47 +00002208 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002209 NameInfo, TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002210
Richard Smithdb2630f2012-10-21 03:28:35 +00002211 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo,
2212 IsAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002213 }
2214
2215 /// \brief Build a new template-id expression.
2216 ///
2217 /// By default, performs semantic analysis to build the new expression.
2218 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002219 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002220 SourceLocation TemplateKWLoc,
2221 LookupResult &R,
2222 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002223 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002224 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2225 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002226 }
2227
2228 /// \brief Build a new object-construction expression.
2229 ///
2230 /// By default, performs semantic analysis to build the new expression.
2231 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002232 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002233 SourceLocation Loc,
2234 CXXConstructorDecl *Constructor,
2235 bool IsElidable,
2236 MultiExprArg Args,
2237 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002238 bool ListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002239 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002240 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002241 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002242 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002243 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002244 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002245 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002246
Douglas Gregordb121ba2009-12-14 16:27:04 +00002247 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002248 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002249 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002250 ListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002251 RequiresZeroInit, ConstructKind,
2252 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002253 }
2254
2255 /// \brief Build a new object-construction expression.
2256 ///
2257 /// By default, performs semantic analysis to build the new expression.
2258 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002259 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2260 SourceLocation LParenLoc,
2261 MultiExprArg Args,
2262 SourceLocation RParenLoc) {
2263 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002264 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002265 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002266 RParenLoc);
2267 }
2268
2269 /// \brief Build a new object-construction expression.
2270 ///
2271 /// By default, performs semantic analysis to build the new expression.
2272 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002273 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2274 SourceLocation LParenLoc,
2275 MultiExprArg Args,
2276 SourceLocation RParenLoc) {
2277 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002278 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002279 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002280 RParenLoc);
2281 }
Mike Stump11289f42009-09-09 15:08:12 +00002282
Douglas Gregora16548e2009-08-11 05:31:07 +00002283 /// \brief Build a new member reference expression.
2284 ///
2285 /// By default, performs semantic analysis to build the new expression.
2286 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002287 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002288 QualType BaseType,
2289 bool IsArrow,
2290 SourceLocation OperatorLoc,
2291 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002292 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002293 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002294 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002295 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002296 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002297 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002298
John McCallb268a282010-08-23 23:25:46 +00002299 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002300 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002301 SS, TemplateKWLoc,
2302 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002303 MemberNameInfo,
2304 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002305 }
2306
John McCall10eae182009-11-30 22:42:35 +00002307 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002308 ///
2309 /// By default, performs semantic analysis to build the new expression.
2310 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002311 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2312 SourceLocation OperatorLoc,
2313 bool IsArrow,
2314 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002315 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002316 NamedDecl *FirstQualifierInScope,
2317 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002318 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002319 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002320 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002321
John McCallb268a282010-08-23 23:25:46 +00002322 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002323 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002324 SS, TemplateKWLoc,
2325 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00002326 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002327 }
Mike Stump11289f42009-09-09 15:08:12 +00002328
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002329 /// \brief Build a new noexcept expression.
2330 ///
2331 /// By default, performs semantic analysis to build the new expression.
2332 /// Subclasses may override this routine to provide different behavior.
2333 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2334 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2335 }
2336
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002337 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00002338 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2339 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002340 SourceLocation RParenLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002341 Optional<unsigned> Length) {
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002342 if (Length)
Chad Rosier1dcde962012-08-08 18:46:20 +00002343 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2344 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002345 RParenLoc, *Length);
Chad Rosier1dcde962012-08-08 18:46:20 +00002346
2347 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2348 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002349 RParenLoc);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002350 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002351
Patrick Beard0caa3942012-04-19 00:25:12 +00002352 /// \brief Build a new Objective-C boxed expression.
2353 ///
2354 /// By default, performs semantic analysis to build the new expression.
2355 /// Subclasses may override this routine to provide different behavior.
2356 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2357 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2358 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002359
Ted Kremeneke65b0862012-03-06 20:05:56 +00002360 /// \brief Build a new Objective-C array literal.
2361 ///
2362 /// By default, performs semantic analysis to build the new expression.
2363 /// Subclasses may override this routine to provide different behavior.
2364 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2365 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002366 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002367 MultiExprArg(Elements, NumElements));
2368 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002369
2370 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002371 Expr *Base, Expr *Key,
2372 ObjCMethodDecl *getterMethod,
2373 ObjCMethodDecl *setterMethod) {
2374 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2375 getterMethod, setterMethod);
2376 }
2377
2378 /// \brief Build a new Objective-C dictionary literal.
2379 ///
2380 /// By default, performs semantic analysis to build the new expression.
2381 /// Subclasses may override this routine to provide different behavior.
2382 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2383 ObjCDictionaryElement *Elements,
2384 unsigned NumElements) {
2385 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2386 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002387
James Dennett2a4d13c2012-06-15 07:13:21 +00002388 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002389 ///
2390 /// By default, performs semantic analysis to build the new expression.
2391 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002392 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002393 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002394 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00002395 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002396 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002397 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002398
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002399 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002400 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002401 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002402 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002403 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002404 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002405 MultiExprArg Args,
2406 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002407 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2408 ReceiverTypeInfo->getType(),
2409 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002410 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002411 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002412 }
2413
2414 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002415 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002416 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002417 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002418 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002419 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002420 MultiExprArg Args,
2421 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002422 return SemaRef.BuildInstanceMessage(Receiver,
2423 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002424 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002425 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002426 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002427 }
2428
Douglas Gregord51d90d2010-04-26 20:11:03 +00002429 /// \brief Build a new Objective-C ivar reference expression.
2430 ///
2431 /// By default, performs semantic analysis to build the new expression.
2432 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002433 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002434 SourceLocation IvarLoc,
2435 bool IsArrow, bool IsFreeIvar) {
2436 // FIXME: We lose track of the IsFreeIvar bit.
2437 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002438 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002439 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2440 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002441 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002442 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00002443 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00002444 false);
John Wiegley01296292011-04-08 18:41:53 +00002445 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002446 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002447
Douglas Gregord51d90d2010-04-26 20:11:03 +00002448 if (Result.get())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002449 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002450
John Wiegley01296292011-04-08 18:41:53 +00002451 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002452 /*FIXME:*/IvarLoc, IsArrow,
2453 SS, SourceLocation(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00002454 /*FirstQualifierInScope=*/0,
Chad Rosier1dcde962012-08-08 18:46:20 +00002455 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002456 /*TemplateArgs=*/0);
2457 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002458
2459 /// \brief Build a new Objective-C property reference expression.
2460 ///
2461 /// By default, performs semantic analysis to build the new expression.
2462 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002463 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002464 ObjCPropertyDecl *Property,
2465 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002466 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002467 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregor9faee212010-04-26 20:47:02 +00002468 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2469 Sema::LookupMemberName);
2470 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002471 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002472 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002473 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002474 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002475 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002476
Douglas Gregor9faee212010-04-26 20:47:02 +00002477 if (Result.get())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002478 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002479
John Wiegley01296292011-04-08 18:41:53 +00002480 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Chad Rosier1dcde962012-08-08 18:46:20 +00002481 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002482 SS, SourceLocation(),
Douglas Gregor9faee212010-04-26 20:47:02 +00002483 /*FirstQualifierInScope=*/0,
Chad Rosier1dcde962012-08-08 18:46:20 +00002484 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002485 /*TemplateArgs=*/0);
2486 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002487
John McCallb7bd14f2010-12-02 01:19:52 +00002488 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002489 ///
2490 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002491 /// Subclasses may override this routine to provide different behavior.
2492 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2493 ObjCMethodDecl *Getter,
2494 ObjCMethodDecl *Setter,
2495 SourceLocation PropertyLoc) {
2496 // Since these expressions can only be value-dependent, we do not
2497 // need to perform semantic analysis again.
2498 return Owned(
2499 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2500 VK_LValue, OK_ObjCProperty,
2501 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002502 }
2503
Douglas Gregord51d90d2010-04-26 20:11:03 +00002504 /// \brief Build a new Objective-C "isa" expression.
2505 ///
2506 /// By default, performs semantic analysis to build the new expression.
2507 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002508 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002509 SourceLocation OpLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002510 bool IsArrow) {
2511 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002512 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002513 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2514 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002515 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002516 OpLoc,
John McCall48871652010-08-21 09:40:31 +00002517 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002518 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002519 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002520
Douglas Gregord51d90d2010-04-26 20:11:03 +00002521 if (Result.get())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002522 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002523
John Wiegley01296292011-04-08 18:41:53 +00002524 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002525 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002526 SS, SourceLocation(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00002527 /*FirstQualifierInScope=*/0,
Chad Rosier1dcde962012-08-08 18:46:20 +00002528 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002529 /*TemplateArgs=*/0);
2530 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002531
Douglas Gregora16548e2009-08-11 05:31:07 +00002532 /// \brief Build a new shuffle vector expression.
2533 ///
2534 /// By default, performs semantic analysis to build the new expression.
2535 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002536 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002537 MultiExprArg SubExprs,
2538 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002539 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002540 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002541 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2542 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2543 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002544 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002545
Douglas Gregora16548e2009-08-11 05:31:07 +00002546 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002547 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002548 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2549 SemaRef.Context.BuiltinFnTy,
2550 VK_RValue, BuiltinLoc);
2551 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2552 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
2553 CK_BuiltinFnToFnPtr).take();
Mike Stump11289f42009-09-09 15:08:12 +00002554
2555 // Build the CallExpr
John Wiegley01296292011-04-08 18:41:53 +00002556 ExprResult TheCall = SemaRef.Owned(
Eli Friedman34866c72012-08-31 00:14:07 +00002557 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, SubExprs,
Benjamin Kramerc215e762012-08-24 11:54:20 +00002558 Builtin->getCallResultType(),
John McCall7decc9e2010-11-18 06:31:45 +00002559 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley01296292011-04-08 18:41:53 +00002560 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002561
Douglas Gregora16548e2009-08-11 05:31:07 +00002562 // Type-check the __builtin_shufflevector expression.
John Wiegley01296292011-04-08 18:41:53 +00002563 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002564 }
John McCall31f82722010-11-12 08:19:04 +00002565
Hal Finkelc4d7c822013-09-18 03:29:45 +00002566 /// \brief Build a new convert vector expression.
2567 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2568 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2569 SourceLocation RParenLoc) {
2570 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2571 BuiltinLoc, RParenLoc);
2572 }
2573
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002574 /// \brief Build a new template argument pack expansion.
2575 ///
2576 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002577 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002578 /// different behavior.
2579 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002580 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002581 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002582 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002583 case TemplateArgument::Expression: {
2584 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002585 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2586 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002587 if (Result.isInvalid())
2588 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002589
Douglas Gregor98318c22011-01-03 21:37:45 +00002590 return TemplateArgumentLoc(Result.get(), Result.get());
2591 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002592
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002593 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002594 return TemplateArgumentLoc(TemplateArgument(
2595 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002596 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002597 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002598 Pattern.getTemplateNameLoc(),
2599 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002600
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002601 case TemplateArgument::Null:
2602 case TemplateArgument::Integral:
2603 case TemplateArgument::Declaration:
2604 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002605 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002606 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002607 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002608
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002609 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002610 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002611 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002612 EllipsisLoc,
2613 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002614 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2615 Expansion);
2616 break;
2617 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002618
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002619 return TemplateArgumentLoc();
2620 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002621
Douglas Gregor968f23a2011-01-03 19:31:53 +00002622 /// \brief Build a new expression pack expansion.
2623 ///
2624 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002625 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002626 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002627 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002628 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002629 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002630 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002631
2632 /// \brief Build a new atomic operation expression.
2633 ///
2634 /// By default, performs semantic analysis to build the new expression.
2635 /// Subclasses may override this routine to provide different behavior.
2636 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2637 MultiExprArg SubExprs,
2638 QualType RetTy,
2639 AtomicExpr::AtomicOp Op,
2640 SourceLocation RParenLoc) {
2641 // Just create the expression; there is not any interesting semantic
2642 // analysis here because we can't actually build an AtomicExpr until
2643 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00002644 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002645 RParenLoc);
2646 }
2647
John McCall31f82722010-11-12 08:19:04 +00002648private:
Douglas Gregor14454802011-02-25 02:25:35 +00002649 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2650 QualType ObjectType,
2651 NamedDecl *FirstQualifierInScope,
2652 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002653
2654 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2655 QualType ObjectType,
2656 NamedDecl *FirstQualifierInScope,
2657 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00002658
2659 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
2660 NamedDecl *FirstQualifierInScope,
2661 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002662};
Douglas Gregora16548e2009-08-11 05:31:07 +00002663
Douglas Gregorebe10102009-08-20 07:17:43 +00002664template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002665StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002666 if (!S)
2667 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002668
Douglas Gregorebe10102009-08-20 07:17:43 +00002669 switch (S->getStmtClass()) {
2670 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002671
Douglas Gregorebe10102009-08-20 07:17:43 +00002672 // Transform individual statement nodes
2673#define STMT(Node, Parent) \
2674 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002675#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002676#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002677#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002678
Douglas Gregorebe10102009-08-20 07:17:43 +00002679 // Transform expressions by calling TransformExpr.
2680#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002681#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002682#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002683#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002684 {
John McCalldadc5752010-08-24 06:29:42 +00002685 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002686 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002687 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002688
Richard Smith945f8d32013-01-14 22:39:08 +00002689 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00002690 }
Mike Stump11289f42009-09-09 15:08:12 +00002691 }
2692
John McCallc3007a22010-10-26 07:05:15 +00002693 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002694}
Mike Stump11289f42009-09-09 15:08:12 +00002695
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002696template<typename Derived>
2697OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2698 if (!S)
2699 return S;
2700
2701 switch (S->getClauseKind()) {
2702 default: break;
2703 // Transform individual clause nodes
2704#define OPENMP_CLAUSE(Name, Class) \
2705 case OMPC_ ## Name : \
2706 return getDerived().Transform ## Class(cast<Class>(S));
2707#include "clang/Basic/OpenMPKinds.def"
2708 }
2709
2710 return S;
2711}
2712
Mike Stump11289f42009-09-09 15:08:12 +00002713
Douglas Gregore922c772009-08-04 22:27:00 +00002714template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002715ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002716 if (!E)
2717 return SemaRef.Owned(E);
2718
2719 switch (E->getStmtClass()) {
2720 case Stmt::NoStmtClass: break;
2721#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002722#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002723#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002724 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002725#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002726 }
2727
John McCallc3007a22010-10-26 07:05:15 +00002728 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002729}
2730
2731template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00002732ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2733 bool CXXDirectInit) {
2734 // Initializers are instantiated like expressions, except that various outer
2735 // layers are stripped.
2736 if (!Init)
2737 return SemaRef.Owned(Init);
2738
2739 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2740 Init = ExprTemp->getSubExpr();
2741
Richard Smithe6ca4752013-05-30 22:40:16 +00002742 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2743 Init = MTE->GetTemporaryExpr();
2744
Richard Smithd59b8322012-12-19 01:39:02 +00002745 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2746 Init = Binder->getSubExpr();
2747
2748 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2749 Init = ICE->getSubExprAsWritten();
2750
Richard Smithcc1b96d2013-06-12 22:31:48 +00002751 if (CXXStdInitializerListExpr *ILE =
2752 dyn_cast<CXXStdInitializerListExpr>(Init))
2753 return TransformInitializer(ILE->getSubExpr(), CXXDirectInit);
2754
Richard Smith38a549b2012-12-21 08:13:35 +00002755 // If this is not a direct-initializer, we only need to reconstruct
2756 // InitListExprs. Other forms of copy-initialization will be a no-op if
2757 // the initializer is already the right type.
2758 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2759 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2760 return getDerived().TransformExpr(Init);
2761
2762 // Revert value-initialization back to empty parens.
2763 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2764 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002765 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002766 Parens.getEnd());
2767 }
2768
2769 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2770 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002771 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002772 SourceLocation());
2773
2774 // Revert initialization by constructor back to a parenthesized or braced list
2775 // of expressions. Any other form of initializer can just be reused directly.
2776 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00002777 return getDerived().TransformExpr(Init);
2778
2779 SmallVector<Expr*, 8> NewArgs;
2780 bool ArgChanged = false;
2781 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2782 /*IsCall*/true, NewArgs, &ArgChanged))
2783 return ExprError();
2784
2785 // If this was list initialization, revert to list form.
2786 if (Construct->isListInitialization())
2787 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2788 Construct->getLocEnd(),
2789 Construct->getType());
2790
Richard Smithd59b8322012-12-19 01:39:02 +00002791 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00002792 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smithd59b8322012-12-19 01:39:02 +00002793 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2794 Parens.getEnd());
2795}
2796
2797template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00002798bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2799 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002800 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00002801 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002802 bool *ArgChanged) {
2803 for (unsigned I = 0; I != NumInputs; ++I) {
2804 // If requested, drop call arguments that need to be dropped.
2805 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2806 if (ArgChanged)
2807 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002808
Douglas Gregora3efea12011-01-03 19:04:46 +00002809 break;
2810 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002811
Douglas Gregor968f23a2011-01-03 19:31:53 +00002812 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2813 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00002814
Chris Lattner01cf8db2011-07-20 06:58:45 +00002815 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002816 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2817 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00002818
Douglas Gregor968f23a2011-01-03 19:31:53 +00002819 // Determine whether the set of unexpanded parameter packs can and should
2820 // be expanded.
2821 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002822 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00002823 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2824 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002825 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2826 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00002827 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002828 Expand, RetainExpansion,
2829 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002830 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002831
Douglas Gregor968f23a2011-01-03 19:31:53 +00002832 if (!Expand) {
2833 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00002834 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00002835 // expansion.
2836 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2837 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2838 if (OutPattern.isInvalid())
2839 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002840
2841 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002842 Expansion->getEllipsisLoc(),
2843 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002844 if (Out.isInvalid())
2845 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002846
Douglas Gregor968f23a2011-01-03 19:31:53 +00002847 if (ArgChanged)
2848 *ArgChanged = true;
2849 Outputs.push_back(Out.get());
2850 continue;
2851 }
John McCall542e7c62011-07-06 07:30:07 +00002852
2853 // Record right away that the argument was changed. This needs
2854 // to happen even if the array expands to nothing.
2855 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002856
Douglas Gregor968f23a2011-01-03 19:31:53 +00002857 // The transform has determined that we should perform an elementwise
2858 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002859 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002860 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2861 ExprResult Out = getDerived().TransformExpr(Pattern);
2862 if (Out.isInvalid())
2863 return true;
2864
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002865 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002866 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2867 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002868 if (Out.isInvalid())
2869 return true;
2870 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002871
Douglas Gregor968f23a2011-01-03 19:31:53 +00002872 Outputs.push_back(Out.get());
2873 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002874
Douglas Gregor968f23a2011-01-03 19:31:53 +00002875 continue;
2876 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002877
Richard Smithd59b8322012-12-19 01:39:02 +00002878 ExprResult Result =
2879 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
2880 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00002881 if (Result.isInvalid())
2882 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002883
Douglas Gregora3efea12011-01-03 19:04:46 +00002884 if (Result.get() != Inputs[I] && ArgChanged)
2885 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002886
2887 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00002888 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002889
Douglas Gregora3efea12011-01-03 19:04:46 +00002890 return false;
2891}
2892
2893template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00002894NestedNameSpecifierLoc
2895TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2896 NestedNameSpecifierLoc NNS,
2897 QualType ObjectType,
2898 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00002899 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00002900 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00002901 Qualifier = Qualifier.getPrefix())
2902 Qualifiers.push_back(Qualifier);
2903
2904 CXXScopeSpec SS;
2905 while (!Qualifiers.empty()) {
2906 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2907 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00002908
Douglas Gregor14454802011-02-25 02:25:35 +00002909 switch (QNNS->getKind()) {
2910 case NestedNameSpecifier::Identifier:
Chad Rosier1dcde962012-08-08 18:46:20 +00002911 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregor14454802011-02-25 02:25:35 +00002912 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00002913 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00002914 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00002915 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00002916 FirstQualifierInScope, false))
2917 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002918
Douglas Gregor14454802011-02-25 02:25:35 +00002919 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00002920
Douglas Gregor14454802011-02-25 02:25:35 +00002921 case NestedNameSpecifier::Namespace: {
2922 NamespaceDecl *NS
2923 = cast_or_null<NamespaceDecl>(
2924 getDerived().TransformDecl(
2925 Q.getLocalBeginLoc(),
2926 QNNS->getAsNamespace()));
2927 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2928 break;
2929 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002930
Douglas Gregor14454802011-02-25 02:25:35 +00002931 case NestedNameSpecifier::NamespaceAlias: {
2932 NamespaceAliasDecl *Alias
2933 = cast_or_null<NamespaceAliasDecl>(
2934 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2935 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00002936 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00002937 Q.getLocalEndLoc());
2938 break;
2939 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002940
Douglas Gregor14454802011-02-25 02:25:35 +00002941 case NestedNameSpecifier::Global:
2942 // There is no meaningful transformation that one could perform on the
2943 // global scope.
2944 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2945 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00002946
Douglas Gregor14454802011-02-25 02:25:35 +00002947 case NestedNameSpecifier::TypeSpecWithTemplate:
2948 case NestedNameSpecifier::TypeSpec: {
2949 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2950 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00002951
Douglas Gregor14454802011-02-25 02:25:35 +00002952 if (!TL)
2953 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002954
Douglas Gregor14454802011-02-25 02:25:35 +00002955 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00002956 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00002957 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002958 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00002959 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00002960 if (TL.getType()->isEnumeralType())
2961 SemaRef.Diag(TL.getBeginLoc(),
2962 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00002963 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2964 Q.getLocalEndLoc());
2965 break;
2966 }
Richard Trieude756fb2011-05-07 01:36:37 +00002967 // If the nested-name-specifier is an invalid type def, don't emit an
2968 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00002969 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
2970 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002971 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00002972 << TL.getType() << SS.getRange();
2973 }
Douglas Gregor14454802011-02-25 02:25:35 +00002974 return NestedNameSpecifierLoc();
2975 }
Douglas Gregore16af532011-02-28 18:50:33 +00002976 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002977
Douglas Gregore16af532011-02-28 18:50:33 +00002978 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregor14454802011-02-25 02:25:35 +00002979 FirstQualifierInScope = 0;
Douglas Gregore16af532011-02-28 18:50:33 +00002980 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00002981 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002982
Douglas Gregor14454802011-02-25 02:25:35 +00002983 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00002984 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00002985 !getDerived().AlwaysRebuild())
2986 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00002987
2988 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00002989 // nested-name-specifier, do so.
2990 if (SS.location_size() == NNS.getDataLength() &&
2991 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2992 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2993
2994 // Allocate new nested-name-specifier location information.
2995 return SS.getWithLocInContext(SemaRef.Context);
2996}
2997
2998template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002999DeclarationNameInfo
3000TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003001::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003002 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003003 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003004 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003005
3006 switch (Name.getNameKind()) {
3007 case DeclarationName::Identifier:
3008 case DeclarationName::ObjCZeroArgSelector:
3009 case DeclarationName::ObjCOneArgSelector:
3010 case DeclarationName::ObjCMultiArgSelector:
3011 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003012 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003013 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003014 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003015
Douglas Gregorf816bd72009-09-03 22:13:48 +00003016 case DeclarationName::CXXConstructorName:
3017 case DeclarationName::CXXDestructorName:
3018 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003019 TypeSourceInfo *NewTInfo;
3020 CanQualType NewCanTy;
3021 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003022 NewTInfo = getDerived().TransformType(OldTInfo);
3023 if (!NewTInfo)
3024 return DeclarationNameInfo();
3025 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003026 }
3027 else {
3028 NewTInfo = 0;
3029 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003030 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003031 if (NewT.isNull())
3032 return DeclarationNameInfo();
3033 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3034 }
Mike Stump11289f42009-09-09 15:08:12 +00003035
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003036 DeclarationName NewName
3037 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3038 NewCanTy);
3039 DeclarationNameInfo NewNameInfo(NameInfo);
3040 NewNameInfo.setName(NewName);
3041 NewNameInfo.setNamedTypeInfo(NewTInfo);
3042 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003043 }
Mike Stump11289f42009-09-09 15:08:12 +00003044 }
3045
David Blaikie83d382b2011-09-23 05:06:16 +00003046 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003047}
3048
3049template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003050TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003051TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3052 TemplateName Name,
3053 SourceLocation NameLoc,
3054 QualType ObjectType,
3055 NamedDecl *FirstQualifierInScope) {
3056 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3057 TemplateDecl *Template = QTN->getTemplateDecl();
3058 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003059
Douglas Gregor9db53502011-03-02 18:07:45 +00003060 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003061 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003062 Template));
3063 if (!TransTemplate)
3064 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003065
Douglas Gregor9db53502011-03-02 18:07:45 +00003066 if (!getDerived().AlwaysRebuild() &&
3067 SS.getScopeRep() == QTN->getQualifier() &&
3068 TransTemplate == Template)
3069 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003070
Douglas Gregor9db53502011-03-02 18:07:45 +00003071 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3072 TransTemplate);
3073 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003074
Douglas Gregor9db53502011-03-02 18:07:45 +00003075 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3076 if (SS.getScopeRep()) {
3077 // These apply to the scope specifier, not the template.
3078 ObjectType = QualType();
3079 FirstQualifierInScope = 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00003080 }
3081
Douglas Gregor9db53502011-03-02 18:07:45 +00003082 if (!getDerived().AlwaysRebuild() &&
3083 SS.getScopeRep() == DTN->getQualifier() &&
3084 ObjectType.isNull())
3085 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003086
Douglas Gregor9db53502011-03-02 18:07:45 +00003087 if (DTN->isIdentifier()) {
3088 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003089 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003090 NameLoc,
3091 ObjectType,
3092 FirstQualifierInScope);
3093 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003094
Douglas Gregor9db53502011-03-02 18:07:45 +00003095 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3096 ObjectType);
3097 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003098
Douglas Gregor9db53502011-03-02 18:07:45 +00003099 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3100 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003101 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003102 Template));
3103 if (!TransTemplate)
3104 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003105
Douglas Gregor9db53502011-03-02 18:07:45 +00003106 if (!getDerived().AlwaysRebuild() &&
3107 TransTemplate == Template)
3108 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003109
Douglas Gregor9db53502011-03-02 18:07:45 +00003110 return TemplateName(TransTemplate);
3111 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003112
Douglas Gregor9db53502011-03-02 18:07:45 +00003113 if (SubstTemplateTemplateParmPackStorage *SubstPack
3114 = Name.getAsSubstTemplateTemplateParmPack()) {
3115 TemplateTemplateParmDecl *TransParam
3116 = cast_or_null<TemplateTemplateParmDecl>(
3117 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3118 if (!TransParam)
3119 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003120
Douglas Gregor9db53502011-03-02 18:07:45 +00003121 if (!getDerived().AlwaysRebuild() &&
3122 TransParam == SubstPack->getParameterPack())
3123 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003124
3125 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003126 SubstPack->getArgumentPack());
3127 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003128
Douglas Gregor9db53502011-03-02 18:07:45 +00003129 // These should be getting filtered out before they reach the AST.
3130 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003131}
3132
3133template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003134void TreeTransform<Derived>::InventTemplateArgumentLoc(
3135 const TemplateArgument &Arg,
3136 TemplateArgumentLoc &Output) {
3137 SourceLocation Loc = getDerived().getBaseLocation();
3138 switch (Arg.getKind()) {
3139 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003140 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003141 break;
3142
3143 case TemplateArgument::Type:
3144 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003145 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003146
John McCall0ad16662009-10-29 08:12:44 +00003147 break;
3148
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003149 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003150 case TemplateArgument::TemplateExpansion: {
3151 NestedNameSpecifierLocBuilder Builder;
3152 TemplateName Template = Arg.getAsTemplate();
3153 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3154 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3155 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3156 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003157
Douglas Gregor9d802122011-03-02 17:09:35 +00003158 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003159 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003160 Builder.getWithLocInContext(SemaRef.Context),
3161 Loc);
3162 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003163 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003164 Builder.getWithLocInContext(SemaRef.Context),
3165 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003166
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003167 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003168 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003169
John McCall0ad16662009-10-29 08:12:44 +00003170 case TemplateArgument::Expression:
3171 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3172 break;
3173
3174 case TemplateArgument::Declaration:
3175 case TemplateArgument::Integral:
3176 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003177 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003178 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003179 break;
3180 }
3181}
3182
3183template<typename Derived>
3184bool TreeTransform<Derived>::TransformTemplateArgument(
3185 const TemplateArgumentLoc &Input,
3186 TemplateArgumentLoc &Output) {
3187 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003188 switch (Arg.getKind()) {
3189 case TemplateArgument::Null:
3190 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003191 case TemplateArgument::Pack:
3192 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003193 case TemplateArgument::NullPtr:
3194 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003195
Douglas Gregore922c772009-08-04 22:27:00 +00003196 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003197 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00003198 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00003199 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003200
3201 DI = getDerived().TransformType(DI);
3202 if (!DI) return true;
3203
3204 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3205 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003206 }
Mike Stump11289f42009-09-09 15:08:12 +00003207
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003208 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003209 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3210 if (QualifierLoc) {
3211 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3212 if (!QualifierLoc)
3213 return true;
3214 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003215
Douglas Gregordf846d12011-03-02 18:46:51 +00003216 CXXScopeSpec SS;
3217 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003218 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003219 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3220 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003221 if (Template.isNull())
3222 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003223
Douglas Gregor9d802122011-03-02 17:09:35 +00003224 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003225 Input.getTemplateNameLoc());
3226 return false;
3227 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003228
3229 case TemplateArgument::TemplateExpansion:
3230 llvm_unreachable("Caller should expand pack expansions");
3231
Douglas Gregore922c772009-08-04 22:27:00 +00003232 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003233 // Template argument expressions are constant expressions.
Mike Stump11289f42009-09-09 15:08:12 +00003234 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smith764d2fe2011-12-20 02:08:33 +00003235 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003236
John McCall0ad16662009-10-29 08:12:44 +00003237 Expr *InputExpr = Input.getSourceExpression();
3238 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3239
Chris Lattnercdb591a2011-04-25 20:37:58 +00003240 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003241 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003242 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00003243 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00003244 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003245 }
Douglas Gregore922c772009-08-04 22:27:00 +00003246 }
Mike Stump11289f42009-09-09 15:08:12 +00003247
Douglas Gregore922c772009-08-04 22:27:00 +00003248 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003249 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003250}
3251
Douglas Gregorfe921a72010-12-20 23:36:19 +00003252/// \brief Iterator adaptor that invents template argument location information
3253/// for each of the template arguments in its underlying iterator.
3254template<typename Derived, typename InputIterator>
3255class TemplateArgumentLocInventIterator {
3256 TreeTransform<Derived> &Self;
3257 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003258
Douglas Gregorfe921a72010-12-20 23:36:19 +00003259public:
3260 typedef TemplateArgumentLoc value_type;
3261 typedef TemplateArgumentLoc reference;
3262 typedef typename std::iterator_traits<InputIterator>::difference_type
3263 difference_type;
3264 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003265
Douglas Gregorfe921a72010-12-20 23:36:19 +00003266 class pointer {
3267 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003268
Douglas Gregorfe921a72010-12-20 23:36:19 +00003269 public:
3270 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003271
Douglas Gregorfe921a72010-12-20 23:36:19 +00003272 const TemplateArgumentLoc *operator->() const { return &Arg; }
3273 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003274
Douglas Gregorfe921a72010-12-20 23:36:19 +00003275 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003276
Douglas Gregorfe921a72010-12-20 23:36:19 +00003277 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3278 InputIterator Iter)
3279 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003280
Douglas Gregorfe921a72010-12-20 23:36:19 +00003281 TemplateArgumentLocInventIterator &operator++() {
3282 ++Iter;
3283 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003284 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003285
Douglas Gregorfe921a72010-12-20 23:36:19 +00003286 TemplateArgumentLocInventIterator operator++(int) {
3287 TemplateArgumentLocInventIterator Old(*this);
3288 ++(*this);
3289 return Old;
3290 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003291
Douglas Gregorfe921a72010-12-20 23:36:19 +00003292 reference operator*() const {
3293 TemplateArgumentLoc Result;
3294 Self.InventTemplateArgumentLoc(*Iter, Result);
3295 return Result;
3296 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003297
Douglas Gregorfe921a72010-12-20 23:36:19 +00003298 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003299
Douglas Gregorfe921a72010-12-20 23:36:19 +00003300 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3301 const TemplateArgumentLocInventIterator &Y) {
3302 return X.Iter == Y.Iter;
3303 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003304
Douglas Gregorfe921a72010-12-20 23:36:19 +00003305 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3306 const TemplateArgumentLocInventIterator &Y) {
3307 return X.Iter != Y.Iter;
3308 }
3309};
Chad Rosier1dcde962012-08-08 18:46:20 +00003310
Douglas Gregor42cafa82010-12-20 17:42:22 +00003311template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003312template<typename InputIterator>
3313bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3314 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00003315 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003316 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003317 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003318 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003319
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003320 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3321 // Unpack argument packs, which we translate them into separate
3322 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003323 // FIXME: We could do much better if we could guarantee that the
3324 // TemplateArgumentLocInfo for the pack expansion would be usable for
3325 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003326 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003327 TemplateArgument::pack_iterator>
3328 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003329 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003330 In.getArgument().pack_begin()),
3331 PackLocIterator(*this,
3332 In.getArgument().pack_end()),
3333 Outputs))
3334 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003335
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003336 continue;
3337 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003338
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003339 if (In.getArgument().isPackExpansion()) {
3340 // We have a pack expansion, for which we will be substituting into
3341 // the pattern.
3342 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003343 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003344 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003345 = getSema().getTemplateArgumentPackExpansionPattern(
3346 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003347
Chris Lattner01cf8db2011-07-20 06:58:45 +00003348 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003349 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3350 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003351
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003352 // Determine whether the set of unexpanded parameter packs can and should
3353 // be expanded.
3354 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003355 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003356 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003357 if (getDerived().TryExpandParameterPacks(Ellipsis,
3358 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003359 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003360 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003361 RetainExpansion,
3362 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003363 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003364
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003365 if (!Expand) {
3366 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003367 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003368 // expansion.
3369 TemplateArgumentLoc OutPattern;
3370 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3371 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3372 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003373
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003374 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3375 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003376 if (Out.getArgument().isNull())
3377 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003378
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003379 Outputs.addArgument(Out);
3380 continue;
3381 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003382
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003383 // The transform has determined that we should perform an elementwise
3384 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003385 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003386 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3387
3388 if (getDerived().TransformTemplateArgument(Pattern, Out))
3389 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003390
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003391 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003392 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3393 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003394 if (Out.getArgument().isNull())
3395 return true;
3396 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003397
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003398 Outputs.addArgument(Out);
3399 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003400
Douglas Gregor48d24112011-01-10 20:53:55 +00003401 // If we're supposed to retain a pack expansion, do so by temporarily
3402 // forgetting the partially-substituted parameter pack.
3403 if (RetainExpansion) {
3404 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003405
Douglas Gregor48d24112011-01-10 20:53:55 +00003406 if (getDerived().TransformTemplateArgument(Pattern, Out))
3407 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003408
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003409 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3410 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003411 if (Out.getArgument().isNull())
3412 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003413
Douglas Gregor48d24112011-01-10 20:53:55 +00003414 Outputs.addArgument(Out);
3415 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003416
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003417 continue;
3418 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003419
3420 // The simple case:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003421 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003422 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003423
Douglas Gregor42cafa82010-12-20 17:42:22 +00003424 Outputs.addArgument(Out);
3425 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003426
Douglas Gregor42cafa82010-12-20 17:42:22 +00003427 return false;
3428
3429}
3430
Douglas Gregord6ff3322009-08-04 16:50:30 +00003431//===----------------------------------------------------------------------===//
3432// Type transformation
3433//===----------------------------------------------------------------------===//
3434
3435template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003436QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003437 if (getDerived().AlreadyTransformed(T))
3438 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003439
John McCall550e0c22009-10-21 00:40:46 +00003440 // Temporary workaround. All of these transformations should
3441 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003442 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3443 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003444
John McCall31f82722010-11-12 08:19:04 +00003445 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003446
John McCall550e0c22009-10-21 00:40:46 +00003447 if (!NewDI)
3448 return QualType();
3449
3450 return NewDI->getType();
3451}
3452
3453template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003454TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003455 // Refine the base location to the type's location.
3456 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3457 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003458 if (getDerived().AlreadyTransformed(DI->getType()))
3459 return DI;
3460
3461 TypeLocBuilder TLB;
3462
3463 TypeLoc TL = DI->getTypeLoc();
3464 TLB.reserve(TL.getFullDataSize());
3465
John McCall31f82722010-11-12 08:19:04 +00003466 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003467 if (Result.isNull())
3468 return 0;
3469
John McCallbcd03502009-12-07 02:54:59 +00003470 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003471}
3472
3473template<typename Derived>
3474QualType
John McCall31f82722010-11-12 08:19:04 +00003475TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003476 switch (T.getTypeLocClass()) {
3477#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003478#define TYPELOC(CLASS, PARENT) \
3479 case TypeLoc::CLASS: \
3480 return getDerived().Transform##CLASS##Type(TLB, \
3481 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003482#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003483 }
Mike Stump11289f42009-09-09 15:08:12 +00003484
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003485 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003486}
3487
3488/// FIXME: By default, this routine adds type qualifiers only to types
3489/// that can have qualifiers, and silently suppresses those qualifiers
3490/// that are not permitted (e.g., qualifiers on reference or function
3491/// types). This is the right thing for template instantiation, but
3492/// probably not for other clients.
3493template<typename Derived>
3494QualType
3495TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003496 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003497 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003498
John McCall31f82722010-11-12 08:19:04 +00003499 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003500 if (Result.isNull())
3501 return QualType();
3502
3503 // Silently suppress qualifiers if the result type can't be qualified.
3504 // FIXME: this is the right thing for template instantiation, but
3505 // probably not for other clients.
3506 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003507 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003508
John McCall31168b02011-06-15 23:02:42 +00003509 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003510 // resulting type.
3511 if (Quals.hasObjCLifetime()) {
3512 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3513 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003514 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003515 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003516 // A lifetime qualifier applied to a substituted template parameter
3517 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003518 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003519 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003520 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3521 QualType Replacement = SubstTypeParam->getReplacementType();
3522 Qualifiers Qs = Replacement.getQualifiers();
3523 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003524 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003525 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3526 Qs);
3527 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003528 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003529 Replacement);
3530 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003531 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3532 // 'auto' types behave the same way as template parameters.
3533 QualType Deduced = AutoTy->getDeducedType();
3534 Qualifiers Qs = Deduced.getQualifiers();
3535 Qs.removeObjCLifetime();
3536 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3537 Qs);
Faisal Vali2b391ab2013-09-26 19:54:12 +00003538 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3539 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003540 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003541 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003542 // Otherwise, complain about the addition of a qualifier to an
3543 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003544 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003545 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003546 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003547
Douglas Gregore46db902011-06-17 22:11:49 +00003548 Quals.removeObjCLifetime();
3549 }
3550 }
3551 }
John McCallcb0f89a2010-06-05 06:41:15 +00003552 if (!Quals.empty()) {
3553 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003554 // BuildQualifiedType might not add qualifiers if they are invalid.
3555 if (Result.hasLocalQualifiers())
3556 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003557 // No location information to preserve.
3558 }
John McCall550e0c22009-10-21 00:40:46 +00003559
3560 return Result;
3561}
3562
Douglas Gregor14454802011-02-25 02:25:35 +00003563template<typename Derived>
3564TypeLoc
3565TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3566 QualType ObjectType,
3567 NamedDecl *UnqualLookup,
3568 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003569 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00003570 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00003571
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003572 TypeSourceInfo *TSI =
3573 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3574 if (TSI)
3575 return TSI->getTypeLoc();
3576 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00003577}
3578
Douglas Gregor579c15f2011-03-02 18:32:08 +00003579template<typename Derived>
3580TypeSourceInfo *
3581TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3582 QualType ObjectType,
3583 NamedDecl *UnqualLookup,
3584 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003585 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00003586 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00003587
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003588 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
3589 UnqualLookup, SS);
3590}
3591
3592template <typename Derived>
3593TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
3594 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
3595 CXXScopeSpec &SS) {
3596 QualType T = TL.getType();
3597 assert(!getDerived().AlreadyTransformed(T));
3598
Douglas Gregor579c15f2011-03-02 18:32:08 +00003599 TypeLocBuilder TLB;
3600 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00003601
Douglas Gregor579c15f2011-03-02 18:32:08 +00003602 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003603 TemplateSpecializationTypeLoc SpecTL =
3604 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003605
Douglas Gregor579c15f2011-03-02 18:32:08 +00003606 TemplateName Template
3607 = getDerived().TransformTemplateName(SS,
3608 SpecTL.getTypePtr()->getTemplateName(),
3609 SpecTL.getTemplateNameLoc(),
3610 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00003611 if (Template.isNull())
Douglas Gregor579c15f2011-03-02 18:32:08 +00003612 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00003613
3614 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003615 Template);
3616 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003617 DependentTemplateSpecializationTypeLoc SpecTL =
3618 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003619
Douglas Gregor579c15f2011-03-02 18:32:08 +00003620 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00003621 = getDerived().RebuildTemplateName(SS,
3622 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00003623 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00003624 ObjectType, UnqualLookup);
3625 if (Template.isNull())
3626 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00003627
3628 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003629 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003630 Template,
3631 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003632 } else {
3633 // Nothing special needs to be done for these.
3634 Result = getDerived().TransformType(TLB, TL);
3635 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003636
3637 if (Result.isNull())
Douglas Gregor579c15f2011-03-02 18:32:08 +00003638 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00003639
Douglas Gregor579c15f2011-03-02 18:32:08 +00003640 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3641}
3642
John McCall550e0c22009-10-21 00:40:46 +00003643template <class TyLoc> static inline
3644QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3645 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3646 NewT.setNameLoc(T.getNameLoc());
3647 return T.getType();
3648}
3649
John McCall550e0c22009-10-21 00:40:46 +00003650template<typename Derived>
3651QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003652 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003653 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3654 NewT.setBuiltinLoc(T.getBuiltinLoc());
3655 if (T.needsExtraLocalData())
3656 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3657 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003658}
Mike Stump11289f42009-09-09 15:08:12 +00003659
Douglas Gregord6ff3322009-08-04 16:50:30 +00003660template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003661QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003662 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003663 // FIXME: recurse?
3664 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003665}
Mike Stump11289f42009-09-09 15:08:12 +00003666
Douglas Gregord6ff3322009-08-04 16:50:30 +00003667template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00003668QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3669 DecayedTypeLoc TL) {
3670 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3671 if (OriginalType.isNull())
3672 return QualType();
3673
3674 QualType Result = TL.getType();
3675 if (getDerived().AlwaysRebuild() ||
3676 OriginalType != TL.getOriginalLoc().getType())
3677 Result = SemaRef.Context.getDecayedType(OriginalType);
3678 TLB.push<DecayedTypeLoc>(Result);
3679 // Nothing to set for DecayedTypeLoc.
3680 return Result;
3681}
3682
3683template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003684QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003685 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003686 QualType PointeeType
3687 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003688 if (PointeeType.isNull())
3689 return QualType();
3690
3691 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003692 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003693 // A dependent pointer type 'T *' has is being transformed such
3694 // that an Objective-C class type is being replaced for 'T'. The
3695 // resulting pointer type is an ObjCObjectPointerType, not a
3696 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003697 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00003698
John McCall8b07ec22010-05-15 11:32:37 +00003699 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3700 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003701 return Result;
3702 }
John McCall31f82722010-11-12 08:19:04 +00003703
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003704 if (getDerived().AlwaysRebuild() ||
3705 PointeeType != TL.getPointeeLoc().getType()) {
3706 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3707 if (Result.isNull())
3708 return QualType();
3709 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003710
John McCall31168b02011-06-15 23:02:42 +00003711 // Objective-C ARC can add lifetime qualifiers to the type that we're
3712 // pointing to.
3713 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00003714
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003715 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3716 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00003717 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003718}
Mike Stump11289f42009-09-09 15:08:12 +00003719
3720template<typename Derived>
3721QualType
John McCall550e0c22009-10-21 00:40:46 +00003722TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003723 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003724 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00003725 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3726 if (PointeeType.isNull())
3727 return QualType();
3728
3729 QualType Result = TL.getType();
3730 if (getDerived().AlwaysRebuild() ||
3731 PointeeType != TL.getPointeeLoc().getType()) {
3732 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003733 TL.getSigilLoc());
3734 if (Result.isNull())
3735 return QualType();
3736 }
3737
Douglas Gregor049211a2010-04-22 16:50:51 +00003738 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003739 NewT.setSigilLoc(TL.getSigilLoc());
3740 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003741}
3742
John McCall70dd5f62009-10-30 00:06:24 +00003743/// Transforms a reference type. Note that somewhat paradoxically we
3744/// don't care whether the type itself is an l-value type or an r-value
3745/// type; we only care if the type was *written* as an l-value type
3746/// or an r-value type.
3747template<typename Derived>
3748QualType
3749TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003750 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003751 const ReferenceType *T = TL.getTypePtr();
3752
3753 // Note that this works with the pointee-as-written.
3754 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3755 if (PointeeType.isNull())
3756 return QualType();
3757
3758 QualType Result = TL.getType();
3759 if (getDerived().AlwaysRebuild() ||
3760 PointeeType != T->getPointeeTypeAsWritten()) {
3761 Result = getDerived().RebuildReferenceType(PointeeType,
3762 T->isSpelledAsLValue(),
3763 TL.getSigilLoc());
3764 if (Result.isNull())
3765 return QualType();
3766 }
3767
John McCall31168b02011-06-15 23:02:42 +00003768 // Objective-C ARC can add lifetime qualifiers to the type that we're
3769 // referring to.
3770 TLB.TypeWasModifiedSafely(
3771 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3772
John McCall70dd5f62009-10-30 00:06:24 +00003773 // r-value references can be rebuilt as l-value references.
3774 ReferenceTypeLoc NewTL;
3775 if (isa<LValueReferenceType>(Result))
3776 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3777 else
3778 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3779 NewTL.setSigilLoc(TL.getSigilLoc());
3780
3781 return Result;
3782}
3783
Mike Stump11289f42009-09-09 15:08:12 +00003784template<typename Derived>
3785QualType
John McCall550e0c22009-10-21 00:40:46 +00003786TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003787 LValueReferenceTypeLoc TL) {
3788 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003789}
3790
Mike Stump11289f42009-09-09 15:08:12 +00003791template<typename Derived>
3792QualType
John McCall550e0c22009-10-21 00:40:46 +00003793TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003794 RValueReferenceTypeLoc TL) {
3795 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003796}
Mike Stump11289f42009-09-09 15:08:12 +00003797
Douglas Gregord6ff3322009-08-04 16:50:30 +00003798template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003799QualType
John McCall550e0c22009-10-21 00:40:46 +00003800TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003801 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003802 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003803 if (PointeeType.isNull())
3804 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003805
Abramo Bagnara509357842011-03-05 14:42:21 +00003806 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3807 TypeSourceInfo* NewClsTInfo = 0;
3808 if (OldClsTInfo) {
3809 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3810 if (!NewClsTInfo)
3811 return QualType();
3812 }
3813
3814 const MemberPointerType *T = TL.getTypePtr();
3815 QualType OldClsType = QualType(T->getClass(), 0);
3816 QualType NewClsType;
3817 if (NewClsTInfo)
3818 NewClsType = NewClsTInfo->getType();
3819 else {
3820 NewClsType = getDerived().TransformType(OldClsType);
3821 if (NewClsType.isNull())
3822 return QualType();
3823 }
Mike Stump11289f42009-09-09 15:08:12 +00003824
John McCall550e0c22009-10-21 00:40:46 +00003825 QualType Result = TL.getType();
3826 if (getDerived().AlwaysRebuild() ||
3827 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00003828 NewClsType != OldClsType) {
3829 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00003830 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003831 if (Result.isNull())
3832 return QualType();
3833 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003834
John McCall550e0c22009-10-21 00:40:46 +00003835 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3836 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00003837 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00003838
3839 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003840}
3841
Mike Stump11289f42009-09-09 15:08:12 +00003842template<typename Derived>
3843QualType
John McCall550e0c22009-10-21 00:40:46 +00003844TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003845 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003846 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003847 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003848 if (ElementType.isNull())
3849 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003850
John McCall550e0c22009-10-21 00:40:46 +00003851 QualType Result = TL.getType();
3852 if (getDerived().AlwaysRebuild() ||
3853 ElementType != T->getElementType()) {
3854 Result = getDerived().RebuildConstantArrayType(ElementType,
3855 T->getSizeModifier(),
3856 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003857 T->getIndexTypeCVRQualifiers(),
3858 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003859 if (Result.isNull())
3860 return QualType();
3861 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00003862
3863 // We might have either a ConstantArrayType or a VariableArrayType now:
3864 // a ConstantArrayType is allowed to have an element type which is a
3865 // VariableArrayType if the type is dependent. Fortunately, all array
3866 // types have the same location layout.
3867 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00003868 NewTL.setLBracketLoc(TL.getLBracketLoc());
3869 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003870
John McCall550e0c22009-10-21 00:40:46 +00003871 Expr *Size = TL.getSizeExpr();
3872 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003873 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3874 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00003875 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanc6237c62012-02-29 03:16:56 +00003876 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCall550e0c22009-10-21 00:40:46 +00003877 }
3878 NewTL.setSizeExpr(Size);
3879
3880 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003881}
Mike Stump11289f42009-09-09 15:08:12 +00003882
Douglas Gregord6ff3322009-08-04 16:50:30 +00003883template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003884QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003885 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003886 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003887 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003888 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003889 if (ElementType.isNull())
3890 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003891
John McCall550e0c22009-10-21 00:40:46 +00003892 QualType Result = TL.getType();
3893 if (getDerived().AlwaysRebuild() ||
3894 ElementType != T->getElementType()) {
3895 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003896 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003897 T->getIndexTypeCVRQualifiers(),
3898 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003899 if (Result.isNull())
3900 return QualType();
3901 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003902
John McCall550e0c22009-10-21 00:40:46 +00003903 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3904 NewTL.setLBracketLoc(TL.getLBracketLoc());
3905 NewTL.setRBracketLoc(TL.getRBracketLoc());
3906 NewTL.setSizeExpr(0);
3907
3908 return Result;
3909}
3910
3911template<typename Derived>
3912QualType
3913TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003914 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003915 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003916 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3917 if (ElementType.isNull())
3918 return QualType();
3919
John McCalldadc5752010-08-24 06:29:42 +00003920 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003921 = getDerived().TransformExpr(T->getSizeExpr());
3922 if (SizeResult.isInvalid())
3923 return QualType();
3924
John McCallb268a282010-08-23 23:25:46 +00003925 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003926
3927 QualType Result = TL.getType();
3928 if (getDerived().AlwaysRebuild() ||
3929 ElementType != T->getElementType() ||
3930 Size != T->getSizeExpr()) {
3931 Result = getDerived().RebuildVariableArrayType(ElementType,
3932 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003933 Size,
John McCall550e0c22009-10-21 00:40:46 +00003934 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003935 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003936 if (Result.isNull())
3937 return QualType();
3938 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003939
John McCall550e0c22009-10-21 00:40:46 +00003940 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3941 NewTL.setLBracketLoc(TL.getLBracketLoc());
3942 NewTL.setRBracketLoc(TL.getRBracketLoc());
3943 NewTL.setSizeExpr(Size);
3944
3945 return Result;
3946}
3947
3948template<typename Derived>
3949QualType
3950TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003951 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003952 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003953 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3954 if (ElementType.isNull())
3955 return QualType();
3956
Richard Smith764d2fe2011-12-20 02:08:33 +00003957 // Array bounds are constant expressions.
3958 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3959 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00003960
John McCall33ddac02011-01-19 10:06:00 +00003961 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3962 Expr *origSize = TL.getSizeExpr();
3963 if (!origSize) origSize = T->getSizeExpr();
3964
3965 ExprResult sizeResult
3966 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003967 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00003968 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00003969 return QualType();
3970
John McCall33ddac02011-01-19 10:06:00 +00003971 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00003972
3973 QualType Result = TL.getType();
3974 if (getDerived().AlwaysRebuild() ||
3975 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00003976 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00003977 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3978 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00003979 size,
John McCall550e0c22009-10-21 00:40:46 +00003980 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003981 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003982 if (Result.isNull())
3983 return QualType();
3984 }
John McCall550e0c22009-10-21 00:40:46 +00003985
3986 // We might have any sort of array type now, but fortunately they
3987 // all have the same location layout.
3988 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3989 NewTL.setLBracketLoc(TL.getLBracketLoc());
3990 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00003991 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00003992
3993 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003994}
Mike Stump11289f42009-09-09 15:08:12 +00003995
3996template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003997QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00003998 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003999 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004000 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004001
4002 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004003 QualType ElementType = getDerived().TransformType(T->getElementType());
4004 if (ElementType.isNull())
4005 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004006
Richard Smith764d2fe2011-12-20 02:08:33 +00004007 // Vector sizes are constant expressions.
4008 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4009 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004010
John McCalldadc5752010-08-24 06:29:42 +00004011 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004012 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004013 if (Size.isInvalid())
4014 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004015
John McCall550e0c22009-10-21 00:40:46 +00004016 QualType Result = TL.getType();
4017 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004018 ElementType != T->getElementType() ||
4019 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004020 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00004021 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004022 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004023 if (Result.isNull())
4024 return QualType();
4025 }
John McCall550e0c22009-10-21 00:40:46 +00004026
4027 // Result might be dependent or not.
4028 if (isa<DependentSizedExtVectorType>(Result)) {
4029 DependentSizedExtVectorTypeLoc NewTL
4030 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4031 NewTL.setNameLoc(TL.getNameLoc());
4032 } else {
4033 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4034 NewTL.setNameLoc(TL.getNameLoc());
4035 }
4036
4037 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004038}
Mike Stump11289f42009-09-09 15:08:12 +00004039
4040template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004041QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004042 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004043 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004044 QualType ElementType = getDerived().TransformType(T->getElementType());
4045 if (ElementType.isNull())
4046 return QualType();
4047
John McCall550e0c22009-10-21 00:40:46 +00004048 QualType Result = TL.getType();
4049 if (getDerived().AlwaysRebuild() ||
4050 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004051 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004052 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004053 if (Result.isNull())
4054 return QualType();
4055 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004056
John McCall550e0c22009-10-21 00:40:46 +00004057 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4058 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004059
John McCall550e0c22009-10-21 00:40:46 +00004060 return Result;
4061}
4062
4063template<typename Derived>
4064QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004065 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004066 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004067 QualType ElementType = getDerived().TransformType(T->getElementType());
4068 if (ElementType.isNull())
4069 return QualType();
4070
4071 QualType Result = TL.getType();
4072 if (getDerived().AlwaysRebuild() ||
4073 ElementType != T->getElementType()) {
4074 Result = getDerived().RebuildExtVectorType(ElementType,
4075 T->getNumElements(),
4076 /*FIXME*/ SourceLocation());
4077 if (Result.isNull())
4078 return QualType();
4079 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004080
John McCall550e0c22009-10-21 00:40:46 +00004081 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4082 NewTL.setNameLoc(TL.getNameLoc());
4083
4084 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004085}
Mike Stump11289f42009-09-09 15:08:12 +00004086
David Blaikie05785d12013-02-20 22:23:23 +00004087template <typename Derived>
4088ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4089 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4090 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004091 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor715e4612011-01-14 22:40:04 +00004092 TypeSourceInfo *NewDI = 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00004093
Douglas Gregor715e4612011-01-14 22:40:04 +00004094 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004095 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004096 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004097 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004098 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004099
Douglas Gregor715e4612011-01-14 22:40:04 +00004100 TypeLocBuilder TLB;
4101 TypeLoc NewTL = OldDI->getTypeLoc();
4102 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004103
4104 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004105 OldExpansionTL.getPatternLoc());
4106 if (Result.isNull())
4107 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00004108
4109 Result = RebuildPackExpansionType(Result,
4110 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004111 OldExpansionTL.getEllipsisLoc(),
4112 NumExpansions);
4113 if (Result.isNull())
4114 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00004115
Douglas Gregor715e4612011-01-14 22:40:04 +00004116 PackExpansionTypeLoc NewExpansionTL
4117 = TLB.push<PackExpansionTypeLoc>(Result);
4118 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4119 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4120 } else
4121 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004122 if (!NewDI)
4123 return 0;
4124
John McCall8fb0d9d2011-05-01 22:35:37 +00004125 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004126 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004127
4128 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4129 OldParm->getDeclContext(),
4130 OldParm->getInnerLocStart(),
4131 OldParm->getLocation(),
4132 OldParm->getIdentifier(),
4133 NewDI->getType(),
4134 NewDI,
4135 OldParm->getStorageClass(),
John McCall8fb0d9d2011-05-01 22:35:37 +00004136 /* DefArg */ NULL);
4137 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4138 OldParm->getFunctionScopeIndex() + indexAdjustment);
4139 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004140}
4141
4142template<typename Derived>
4143bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004144 TransformFunctionTypeParams(SourceLocation Loc,
4145 ParmVarDecl **Params, unsigned NumParams,
4146 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004147 SmallVectorImpl<QualType> &OutParamTypes,
4148 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004149 int indexAdjustment = 0;
4150
Douglas Gregordd472162011-01-07 00:20:55 +00004151 for (unsigned i = 0; i != NumParams; ++i) {
4152 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004153 assert(OldParm->getFunctionScopeIndex() == i);
4154
David Blaikie05785d12013-02-20 22:23:23 +00004155 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004156 ParmVarDecl *NewParm = 0;
Douglas Gregor5499af42011-01-05 23:12:31 +00004157 if (OldParm->isParameterPack()) {
4158 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004159 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004160
Douglas Gregor5499af42011-01-05 23:12:31 +00004161 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004162 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004163 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004164 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4165 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004166 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4167
Douglas Gregor5499af42011-01-05 23:12:31 +00004168 // Determine whether we should expand the parameter packs.
4169 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004170 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004171 Optional<unsigned> OrigNumExpansions =
4172 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004173 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004174 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4175 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004176 Unexpanded,
4177 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004178 RetainExpansion,
4179 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004180 return true;
4181 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004182
Douglas Gregor5499af42011-01-05 23:12:31 +00004183 if (ShouldExpand) {
4184 // Expand the function parameter pack into multiple, separate
4185 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004186 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004187 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004188 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004189 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004190 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004191 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004192 OrigNumExpansions,
4193 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004194 if (!NewParm)
4195 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004196
Douglas Gregordd472162011-01-07 00:20:55 +00004197 OutParamTypes.push_back(NewParm->getType());
4198 if (PVars)
4199 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004200 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004201
4202 // If we're supposed to retain a pack expansion, do so by temporarily
4203 // forgetting the partially-substituted parameter pack.
4204 if (RetainExpansion) {
4205 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004206 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004207 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004208 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004209 OrigNumExpansions,
4210 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004211 if (!NewParm)
4212 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004213
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004214 OutParamTypes.push_back(NewParm->getType());
4215 if (PVars)
4216 PVars->push_back(NewParm);
4217 }
4218
John McCall8fb0d9d2011-05-01 22:35:37 +00004219 // The next parameter should have the same adjustment as the
4220 // last thing we pushed, but we post-incremented indexAdjustment
4221 // on every push. Also, if we push nothing, the adjustment should
4222 // go down by one.
4223 indexAdjustment--;
4224
Douglas Gregor5499af42011-01-05 23:12:31 +00004225 // We're done with the pack expansion.
4226 continue;
4227 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004228
4229 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004230 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004231 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4232 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004233 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004234 NumExpansions,
4235 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004236 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004237 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004238 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004239 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004240
John McCall58f10c32010-03-11 09:03:00 +00004241 if (!NewParm)
4242 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004243
Douglas Gregordd472162011-01-07 00:20:55 +00004244 OutParamTypes.push_back(NewParm->getType());
4245 if (PVars)
4246 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004247 continue;
4248 }
John McCall58f10c32010-03-11 09:03:00 +00004249
4250 // Deal with the possibility that we don't have a parameter
4251 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004252 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004253 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004254 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004255 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004256 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004257 = dyn_cast<PackExpansionType>(OldType)) {
4258 // We have a function parameter pack that may need to be expanded.
4259 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004260 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004261 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004262
Douglas Gregor5499af42011-01-05 23:12:31 +00004263 // Determine whether we should expand the parameter packs.
4264 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004265 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004266 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004267 Unexpanded,
4268 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004269 RetainExpansion,
4270 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004271 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004272 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004273
Douglas Gregor5499af42011-01-05 23:12:31 +00004274 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004275 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004276 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004277 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004278 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4279 QualType NewType = getDerived().TransformType(Pattern);
4280 if (NewType.isNull())
4281 return true;
John McCall58f10c32010-03-11 09:03:00 +00004282
Douglas Gregordd472162011-01-07 00:20:55 +00004283 OutParamTypes.push_back(NewType);
4284 if (PVars)
4285 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00004286 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004287
Douglas Gregor5499af42011-01-05 23:12:31 +00004288 // We're done with the pack expansion.
4289 continue;
4290 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004291
Douglas Gregor48d24112011-01-10 20:53:55 +00004292 // If we're supposed to retain a pack expansion, do so by temporarily
4293 // forgetting the partially-substituted parameter pack.
4294 if (RetainExpansion) {
4295 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4296 QualType NewType = getDerived().TransformType(Pattern);
4297 if (NewType.isNull())
4298 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004299
Douglas Gregor48d24112011-01-10 20:53:55 +00004300 OutParamTypes.push_back(NewType);
4301 if (PVars)
4302 PVars->push_back(0);
4303 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004304
Chad Rosier1dcde962012-08-08 18:46:20 +00004305 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004306 // expansion.
4307 OldType = Expansion->getPattern();
4308 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004309 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4310 NewType = getDerived().TransformType(OldType);
4311 } else {
4312 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004313 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004314
Douglas Gregor5499af42011-01-05 23:12:31 +00004315 if (NewType.isNull())
4316 return true;
4317
4318 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004319 NewType = getSema().Context.getPackExpansionType(NewType,
4320 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004321
Douglas Gregordd472162011-01-07 00:20:55 +00004322 OutParamTypes.push_back(NewType);
4323 if (PVars)
4324 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00004325 }
4326
John McCall8fb0d9d2011-05-01 22:35:37 +00004327#ifndef NDEBUG
4328 if (PVars) {
4329 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4330 if (ParmVarDecl *parm = (*PVars)[i])
4331 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004332 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004333#endif
4334
4335 return false;
4336}
John McCall58f10c32010-03-11 09:03:00 +00004337
4338template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004339QualType
John McCall550e0c22009-10-21 00:40:46 +00004340TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004341 FunctionProtoTypeLoc TL) {
Douglas Gregor3024f072012-04-16 07:05:22 +00004342 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4343}
4344
4345template<typename Derived>
4346QualType
4347TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4348 FunctionProtoTypeLoc TL,
4349 CXXRecordDecl *ThisContext,
4350 unsigned ThisTypeQuals) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004351 // Transform the parameters and return type.
4352 //
Richard Smithf623c962012-04-17 00:58:00 +00004353 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004354 // When the function has a trailing return type, we instantiate the
4355 // parameters before the return type, since the return type can then refer
4356 // to the parameters themselves (via decltype, sizeof, etc.).
4357 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004358 SmallVector<QualType, 4> ParamTypes;
4359 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004360 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004361
Douglas Gregor7fb25412010-10-01 18:44:50 +00004362 QualType ResultType;
4363
Richard Smith1226c602012-08-14 22:51:13 +00004364 if (T->hasTrailingReturn()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004365 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregordd472162011-01-07 00:20:55 +00004366 TL.getParmArray(),
4367 TL.getNumArgs(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004368 TL.getTypePtr()->arg_type_begin(),
Douglas Gregordd472162011-01-07 00:20:55 +00004369 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004370 return QualType();
4371
Douglas Gregor3024f072012-04-16 07:05:22 +00004372 {
4373 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004374 // If a declaration declares a member function or member function
4375 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004376 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004377 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004378 // declarator.
4379 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004380
Douglas Gregor3024f072012-04-16 07:05:22 +00004381 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4382 if (ResultType.isNull())
4383 return QualType();
4384 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004385 }
4386 else {
4387 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4388 if (ResultType.isNull())
4389 return QualType();
4390
Chad Rosier1dcde962012-08-08 18:46:20 +00004391 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregordd472162011-01-07 00:20:55 +00004392 TL.getParmArray(),
4393 TL.getNumArgs(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004394 TL.getTypePtr()->arg_type_begin(),
Douglas Gregordd472162011-01-07 00:20:55 +00004395 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004396 return QualType();
4397 }
4398
Richard Smithf623c962012-04-17 00:58:00 +00004399 // FIXME: Need to transform the exception-specification too.
4400
John McCall550e0c22009-10-21 00:40:46 +00004401 QualType Result = TL.getType();
4402 if (getDerived().AlwaysRebuild() ||
4403 ResultType != T->getResultType() ||
Douglas Gregor9f627df2011-01-07 19:27:47 +00004404 T->getNumArgs() != ParamTypes.size() ||
John McCall550e0c22009-10-21 00:40:46 +00004405 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
Jordan Rose5c382722013-03-08 21:51:21 +00004406 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00004407 T->getExtProtoInfo());
John McCall550e0c22009-10-21 00:40:46 +00004408 if (Result.isNull())
4409 return QualType();
4410 }
Mike Stump11289f42009-09-09 15:08:12 +00004411
John McCall550e0c22009-10-21 00:40:46 +00004412 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004413 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004414 NewTL.setLParenLoc(TL.getLParenLoc());
4415 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004416 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004417 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4418 NewTL.setArg(i, ParamDecls[i]);
4419
4420 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004421}
Mike Stump11289f42009-09-09 15:08:12 +00004422
Douglas Gregord6ff3322009-08-04 16:50:30 +00004423template<typename Derived>
4424QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004425 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004426 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004427 const FunctionNoProtoType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004428 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4429 if (ResultType.isNull())
4430 return QualType();
4431
4432 QualType Result = TL.getType();
4433 if (getDerived().AlwaysRebuild() ||
4434 ResultType != T->getResultType())
4435 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4436
4437 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004438 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004439 NewTL.setLParenLoc(TL.getLParenLoc());
4440 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004441 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004442
4443 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004444}
Mike Stump11289f42009-09-09 15:08:12 +00004445
John McCallb96ec562009-12-04 22:46:56 +00004446template<typename Derived> QualType
4447TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004448 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004449 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004450 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004451 if (!D)
4452 return QualType();
4453
4454 QualType Result = TL.getType();
4455 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4456 Result = getDerived().RebuildUnresolvedUsingType(D);
4457 if (Result.isNull())
4458 return QualType();
4459 }
4460
4461 // We might get an arbitrary type spec type back. We should at
4462 // least always get a type spec type, though.
4463 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4464 NewTL.setNameLoc(TL.getNameLoc());
4465
4466 return Result;
4467}
4468
Douglas Gregord6ff3322009-08-04 16:50:30 +00004469template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004470QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004471 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004472 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004473 TypedefNameDecl *Typedef
4474 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4475 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004476 if (!Typedef)
4477 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004478
John McCall550e0c22009-10-21 00:40:46 +00004479 QualType Result = TL.getType();
4480 if (getDerived().AlwaysRebuild() ||
4481 Typedef != T->getDecl()) {
4482 Result = getDerived().RebuildTypedefType(Typedef);
4483 if (Result.isNull())
4484 return QualType();
4485 }
Mike Stump11289f42009-09-09 15:08:12 +00004486
John McCall550e0c22009-10-21 00:40:46 +00004487 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4488 NewTL.setNameLoc(TL.getNameLoc());
4489
4490 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004491}
Mike Stump11289f42009-09-09 15:08:12 +00004492
Douglas Gregord6ff3322009-08-04 16:50:30 +00004493template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004494QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004495 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004496 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00004497 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4498 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00004499
John McCalldadc5752010-08-24 06:29:42 +00004500 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004501 if (E.isInvalid())
4502 return QualType();
4503
Eli Friedmane4f22df2012-02-29 04:03:55 +00004504 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4505 if (E.isInvalid())
4506 return QualType();
4507
John McCall550e0c22009-10-21 00:40:46 +00004508 QualType Result = TL.getType();
4509 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004510 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004511 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004512 if (Result.isNull())
4513 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004514 }
John McCall550e0c22009-10-21 00:40:46 +00004515 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004516
John McCall550e0c22009-10-21 00:40:46 +00004517 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004518 NewTL.setTypeofLoc(TL.getTypeofLoc());
4519 NewTL.setLParenLoc(TL.getLParenLoc());
4520 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004521
4522 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004523}
Mike Stump11289f42009-09-09 15:08:12 +00004524
4525template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004526QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004527 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004528 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4529 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4530 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004531 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004532
John McCall550e0c22009-10-21 00:40:46 +00004533 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004534 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4535 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004536 if (Result.isNull())
4537 return QualType();
4538 }
Mike Stump11289f42009-09-09 15:08:12 +00004539
John McCall550e0c22009-10-21 00:40:46 +00004540 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004541 NewTL.setTypeofLoc(TL.getTypeofLoc());
4542 NewTL.setLParenLoc(TL.getLParenLoc());
4543 NewTL.setRParenLoc(TL.getRParenLoc());
4544 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004545
4546 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004547}
Mike Stump11289f42009-09-09 15:08:12 +00004548
4549template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004550QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004551 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004552 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004553
Douglas Gregore922c772009-08-04 22:27:00 +00004554 // decltype expressions are not potentially evaluated contexts
Richard Smithfd555f62012-02-22 02:04:18 +00004555 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4556 /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00004557
John McCalldadc5752010-08-24 06:29:42 +00004558 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004559 if (E.isInvalid())
4560 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004561
Richard Smithfd555f62012-02-22 02:04:18 +00004562 E = getSema().ActOnDecltypeExpression(E.take());
4563 if (E.isInvalid())
4564 return QualType();
4565
John McCall550e0c22009-10-21 00:40:46 +00004566 QualType Result = TL.getType();
4567 if (getDerived().AlwaysRebuild() ||
4568 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004569 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004570 if (Result.isNull())
4571 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004572 }
John McCall550e0c22009-10-21 00:40:46 +00004573 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004574
John McCall550e0c22009-10-21 00:40:46 +00004575 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4576 NewTL.setNameLoc(TL.getNameLoc());
4577
4578 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004579}
4580
4581template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004582QualType TreeTransform<Derived>::TransformUnaryTransformType(
4583 TypeLocBuilder &TLB,
4584 UnaryTransformTypeLoc TL) {
4585 QualType Result = TL.getType();
4586 if (Result->isDependentType()) {
4587 const UnaryTransformType *T = TL.getTypePtr();
4588 QualType NewBase =
4589 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4590 Result = getDerived().RebuildUnaryTransformType(NewBase,
4591 T->getUTTKind(),
4592 TL.getKWLoc());
4593 if (Result.isNull())
4594 return QualType();
4595 }
4596
4597 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4598 NewTL.setKWLoc(TL.getKWLoc());
4599 NewTL.setParensRange(TL.getParensRange());
4600 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4601 return Result;
4602}
4603
4604template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004605QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4606 AutoTypeLoc TL) {
4607 const AutoType *T = TL.getTypePtr();
4608 QualType OldDeduced = T->getDeducedType();
4609 QualType NewDeduced;
4610 if (!OldDeduced.isNull()) {
4611 NewDeduced = getDerived().TransformType(OldDeduced);
4612 if (NewDeduced.isNull())
4613 return QualType();
4614 }
4615
4616 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00004617 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4618 T->isDependentType()) {
Richard Smith74aeef52013-04-26 16:15:35 +00004619 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith30482bc2011-02-20 03:19:35 +00004620 if (Result.isNull())
4621 return QualType();
4622 }
4623
4624 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4625 NewTL.setNameLoc(TL.getNameLoc());
4626
4627 return Result;
4628}
4629
4630template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004631QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004632 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004633 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004634 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004635 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4636 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004637 if (!Record)
4638 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004639
John McCall550e0c22009-10-21 00:40:46 +00004640 QualType Result = TL.getType();
4641 if (getDerived().AlwaysRebuild() ||
4642 Record != T->getDecl()) {
4643 Result = getDerived().RebuildRecordType(Record);
4644 if (Result.isNull())
4645 return QualType();
4646 }
Mike Stump11289f42009-09-09 15:08:12 +00004647
John McCall550e0c22009-10-21 00:40:46 +00004648 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4649 NewTL.setNameLoc(TL.getNameLoc());
4650
4651 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004652}
Mike Stump11289f42009-09-09 15:08:12 +00004653
4654template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004655QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004656 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004657 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004658 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004659 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4660 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004661 if (!Enum)
4662 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004663
John McCall550e0c22009-10-21 00:40:46 +00004664 QualType Result = TL.getType();
4665 if (getDerived().AlwaysRebuild() ||
4666 Enum != T->getDecl()) {
4667 Result = getDerived().RebuildEnumType(Enum);
4668 if (Result.isNull())
4669 return QualType();
4670 }
Mike Stump11289f42009-09-09 15:08:12 +00004671
John McCall550e0c22009-10-21 00:40:46 +00004672 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4673 NewTL.setNameLoc(TL.getNameLoc());
4674
4675 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004676}
John McCallfcc33b02009-09-05 00:15:47 +00004677
John McCalle78aac42010-03-10 03:28:59 +00004678template<typename Derived>
4679QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4680 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004681 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004682 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4683 TL.getTypePtr()->getDecl());
4684 if (!D) return QualType();
4685
4686 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4687 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4688 return T;
4689}
4690
Douglas Gregord6ff3322009-08-04 16:50:30 +00004691template<typename Derived>
4692QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004693 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004694 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004695 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004696}
4697
Mike Stump11289f42009-09-09 15:08:12 +00004698template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004699QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004700 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004701 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004702 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00004703
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004704 // Substitute into the replacement type, which itself might involve something
4705 // that needs to be transformed. This only tends to occur with default
4706 // template arguments of template template parameters.
4707 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4708 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4709 if (Replacement.isNull())
4710 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00004711
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004712 // Always canonicalize the replacement type.
4713 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4714 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00004715 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004716 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00004717
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004718 // Propagate type-source information.
4719 SubstTemplateTypeParmTypeLoc NewTL
4720 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4721 NewTL.setNameLoc(TL.getNameLoc());
4722 return Result;
4723
John McCallcebee162009-10-18 09:09:24 +00004724}
4725
4726template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004727QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4728 TypeLocBuilder &TLB,
4729 SubstTemplateTypeParmPackTypeLoc TL) {
4730 return TransformTypeSpecType(TLB, TL);
4731}
4732
4733template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004734QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004735 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004736 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004737 const TemplateSpecializationType *T = TL.getTypePtr();
4738
Douglas Gregordf846d12011-03-02 18:46:51 +00004739 // The nested-name-specifier never matters in a TemplateSpecializationType,
4740 // because we can't have a dependent nested-name-specifier anyway.
4741 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004742 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004743 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4744 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004745 if (Template.isNull())
4746 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004747
John McCall31f82722010-11-12 08:19:04 +00004748 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4749}
4750
Eli Friedman0dfb8892011-10-06 23:00:33 +00004751template<typename Derived>
4752QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4753 AtomicTypeLoc TL) {
4754 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4755 if (ValueType.isNull())
4756 return QualType();
4757
4758 QualType Result = TL.getType();
4759 if (getDerived().AlwaysRebuild() ||
4760 ValueType != TL.getValueLoc().getType()) {
4761 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4762 if (Result.isNull())
4763 return QualType();
4764 }
4765
4766 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4767 NewTL.setKWLoc(TL.getKWLoc());
4768 NewTL.setLParenLoc(TL.getLParenLoc());
4769 NewTL.setRParenLoc(TL.getRParenLoc());
4770
4771 return Result;
4772}
4773
Chad Rosier1dcde962012-08-08 18:46:20 +00004774 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00004775 /// container that provides a \c getArgLoc() member function.
4776 ///
4777 /// This iterator is intended to be used with the iterator form of
4778 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4779 template<typename ArgLocContainer>
4780 class TemplateArgumentLocContainerIterator {
4781 ArgLocContainer *Container;
4782 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00004783
Douglas Gregorfe921a72010-12-20 23:36:19 +00004784 public:
4785 typedef TemplateArgumentLoc value_type;
4786 typedef TemplateArgumentLoc reference;
4787 typedef int difference_type;
4788 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00004789
Douglas Gregorfe921a72010-12-20 23:36:19 +00004790 class pointer {
4791 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00004792
Douglas Gregorfe921a72010-12-20 23:36:19 +00004793 public:
4794 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004795
Douglas Gregorfe921a72010-12-20 23:36:19 +00004796 const TemplateArgumentLoc *operator->() const {
4797 return &Arg;
4798 }
4799 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004800
4801
Douglas Gregorfe921a72010-12-20 23:36:19 +00004802 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00004803
Douglas Gregorfe921a72010-12-20 23:36:19 +00004804 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4805 unsigned Index)
4806 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004807
Douglas Gregorfe921a72010-12-20 23:36:19 +00004808 TemplateArgumentLocContainerIterator &operator++() {
4809 ++Index;
4810 return *this;
4811 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004812
Douglas Gregorfe921a72010-12-20 23:36:19 +00004813 TemplateArgumentLocContainerIterator operator++(int) {
4814 TemplateArgumentLocContainerIterator Old(*this);
4815 ++(*this);
4816 return Old;
4817 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004818
Douglas Gregorfe921a72010-12-20 23:36:19 +00004819 TemplateArgumentLoc operator*() const {
4820 return Container->getArgLoc(Index);
4821 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004822
Douglas Gregorfe921a72010-12-20 23:36:19 +00004823 pointer operator->() const {
4824 return pointer(Container->getArgLoc(Index));
4825 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004826
Douglas Gregorfe921a72010-12-20 23:36:19 +00004827 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004828 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004829 return X.Container == Y.Container && X.Index == Y.Index;
4830 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004831
Douglas Gregorfe921a72010-12-20 23:36:19 +00004832 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004833 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004834 return !(X == Y);
4835 }
4836 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004837
4838
John McCall31f82722010-11-12 08:19:04 +00004839template <typename Derived>
4840QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4841 TypeLocBuilder &TLB,
4842 TemplateSpecializationTypeLoc TL,
4843 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004844 TemplateArgumentListInfo NewTemplateArgs;
4845 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4846 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004847 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4848 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004849 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00004850 ArgIterator(TL, TL.getNumArgs()),
4851 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004852 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004853
John McCall0ad16662009-10-29 08:12:44 +00004854 // FIXME: maybe don't rebuild if all the template arguments are the same.
4855
4856 QualType Result =
4857 getDerived().RebuildTemplateSpecializationType(Template,
4858 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004859 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004860
4861 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00004862 // Specializations of template template parameters are represented as
4863 // TemplateSpecializationTypes, and substitution of type alias templates
4864 // within a dependent context can transform them into
4865 // DependentTemplateSpecializationTypes.
4866 if (isa<DependentTemplateSpecializationType>(Result)) {
4867 DependentTemplateSpecializationTypeLoc NewTL
4868 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004869 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00004870 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00004871 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004872 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00004873 NewTL.setLAngleLoc(TL.getLAngleLoc());
4874 NewTL.setRAngleLoc(TL.getRAngleLoc());
4875 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4876 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4877 return Result;
4878 }
4879
John McCall0ad16662009-10-29 08:12:44 +00004880 TemplateSpecializationTypeLoc NewTL
4881 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004882 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00004883 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4884 NewTL.setLAngleLoc(TL.getLAngleLoc());
4885 NewTL.setRAngleLoc(TL.getRAngleLoc());
4886 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4887 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004888 }
Mike Stump11289f42009-09-09 15:08:12 +00004889
John McCall0ad16662009-10-29 08:12:44 +00004890 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004891}
Mike Stump11289f42009-09-09 15:08:12 +00004892
Douglas Gregor5a064722011-02-28 17:23:35 +00004893template <typename Derived>
4894QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4895 TypeLocBuilder &TLB,
4896 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004897 TemplateName Template,
4898 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00004899 TemplateArgumentListInfo NewTemplateArgs;
4900 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4901 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4902 typedef TemplateArgumentLocContainerIterator<
4903 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004904 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00004905 ArgIterator(TL, TL.getNumArgs()),
4906 NewTemplateArgs))
4907 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00004908
Douglas Gregor5a064722011-02-28 17:23:35 +00004909 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00004910
Douglas Gregor5a064722011-02-28 17:23:35 +00004911 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4912 QualType Result
4913 = getSema().Context.getDependentTemplateSpecializationType(
4914 TL.getTypePtr()->getKeyword(),
4915 DTN->getQualifier(),
4916 DTN->getIdentifier(),
4917 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00004918
Douglas Gregor5a064722011-02-28 17:23:35 +00004919 DependentTemplateSpecializationTypeLoc NewTL
4920 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004921 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004922 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00004923 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004924 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00004925 NewTL.setLAngleLoc(TL.getLAngleLoc());
4926 NewTL.setRAngleLoc(TL.getRAngleLoc());
4927 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4928 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4929 return Result;
4930 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004931
4932 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00004933 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004934 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00004935 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00004936
Douglas Gregor5a064722011-02-28 17:23:35 +00004937 if (!Result.isNull()) {
4938 /// FIXME: Wrap this in an elaborated-type-specifier?
4939 TemplateSpecializationTypeLoc NewTL
4940 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00004941 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004942 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00004943 NewTL.setLAngleLoc(TL.getLAngleLoc());
4944 NewTL.setRAngleLoc(TL.getRAngleLoc());
4945 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4946 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4947 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004948
Douglas Gregor5a064722011-02-28 17:23:35 +00004949 return Result;
4950}
4951
Mike Stump11289f42009-09-09 15:08:12 +00004952template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004953QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00004954TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004955 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004956 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00004957
Douglas Gregor844cb502011-03-01 18:12:44 +00004958 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00004959 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00004960 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004961 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00004962 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4963 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00004964 return QualType();
4965 }
Mike Stump11289f42009-09-09 15:08:12 +00004966
John McCall31f82722010-11-12 08:19:04 +00004967 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4968 if (NamedT.isNull())
4969 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00004970
Richard Smith3f1b5d02011-05-05 21:57:07 +00004971 // C++0x [dcl.type.elab]p2:
4972 // If the identifier resolves to a typedef-name or the simple-template-id
4973 // resolves to an alias template specialization, the
4974 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00004975 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4976 if (const TemplateSpecializationType *TST =
4977 NamedT->getAs<TemplateSpecializationType>()) {
4978 TemplateName Template = TST->getTemplateName();
4979 if (TypeAliasTemplateDecl *TAT =
4980 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4981 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4982 diag::err_tag_reference_non_tag) << 4;
4983 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4984 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00004985 }
4986 }
4987
John McCall550e0c22009-10-21 00:40:46 +00004988 QualType Result = TL.getType();
4989 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00004990 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00004991 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00004992 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004993 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00004994 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00004995 if (Result.isNull())
4996 return QualType();
4997 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004998
Abramo Bagnara6150c882010-05-11 21:36:43 +00004999 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005000 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005001 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005002 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005003}
Mike Stump11289f42009-09-09 15:08:12 +00005004
5005template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005006QualType TreeTransform<Derived>::TransformAttributedType(
5007 TypeLocBuilder &TLB,
5008 AttributedTypeLoc TL) {
5009 const AttributedType *oldType = TL.getTypePtr();
5010 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5011 if (modifiedType.isNull())
5012 return QualType();
5013
5014 QualType result = TL.getType();
5015
5016 // FIXME: dependent operand expressions?
5017 if (getDerived().AlwaysRebuild() ||
5018 modifiedType != oldType->getModifiedType()) {
5019 // TODO: this is really lame; we should really be rebuilding the
5020 // equivalent type from first principles.
5021 QualType equivalentType
5022 = getDerived().TransformType(oldType->getEquivalentType());
5023 if (equivalentType.isNull())
5024 return QualType();
5025 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5026 modifiedType,
5027 equivalentType);
5028 }
5029
5030 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5031 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5032 if (TL.hasAttrOperand())
5033 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5034 if (TL.hasAttrExprOperand())
5035 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5036 else if (TL.hasAttrEnumOperand())
5037 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5038
5039 return result;
5040}
5041
5042template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005043QualType
5044TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5045 ParenTypeLoc TL) {
5046 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5047 if (Inner.isNull())
5048 return QualType();
5049
5050 QualType Result = TL.getType();
5051 if (getDerived().AlwaysRebuild() ||
5052 Inner != TL.getInnerLoc().getType()) {
5053 Result = getDerived().RebuildParenType(Inner);
5054 if (Result.isNull())
5055 return QualType();
5056 }
5057
5058 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5059 NewTL.setLParenLoc(TL.getLParenLoc());
5060 NewTL.setRParenLoc(TL.getRParenLoc());
5061 return Result;
5062}
5063
5064template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005065QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005066 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005067 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005068
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005069 NestedNameSpecifierLoc QualifierLoc
5070 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5071 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005072 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005073
John McCallc392f372010-06-11 00:33:02 +00005074 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005075 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005076 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005077 QualifierLoc,
5078 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005079 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005080 if (Result.isNull())
5081 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005082
Abramo Bagnarad7548482010-05-19 21:37:53 +00005083 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5084 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005085 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5086
Abramo Bagnarad7548482010-05-19 21:37:53 +00005087 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005088 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005089 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005090 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005091 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005092 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005093 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005094 NewTL.setNameLoc(TL.getNameLoc());
5095 }
John McCall550e0c22009-10-21 00:40:46 +00005096 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005097}
Mike Stump11289f42009-09-09 15:08:12 +00005098
Douglas Gregord6ff3322009-08-04 16:50:30 +00005099template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005100QualType TreeTransform<Derived>::
5101 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005102 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005103 NestedNameSpecifierLoc QualifierLoc;
5104 if (TL.getQualifierLoc()) {
5105 QualifierLoc
5106 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5107 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005108 return QualType();
5109 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005110
John McCall31f82722010-11-12 08:19:04 +00005111 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005112 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005113}
5114
5115template<typename Derived>
5116QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005117TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5118 DependentTemplateSpecializationTypeLoc TL,
5119 NestedNameSpecifierLoc QualifierLoc) {
5120 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005121
Douglas Gregora7a795b2011-03-01 20:11:18 +00005122 TemplateArgumentListInfo NewTemplateArgs;
5123 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5124 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005125
Douglas Gregora7a795b2011-03-01 20:11:18 +00005126 typedef TemplateArgumentLocContainerIterator<
5127 DependentTemplateSpecializationTypeLoc> ArgIterator;
5128 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5129 ArgIterator(TL, TL.getNumArgs()),
5130 NewTemplateArgs))
5131 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005132
Douglas Gregora7a795b2011-03-01 20:11:18 +00005133 QualType Result
5134 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5135 QualifierLoc,
5136 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005137 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005138 NewTemplateArgs);
5139 if (Result.isNull())
5140 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005141
Douglas Gregora7a795b2011-03-01 20:11:18 +00005142 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5143 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005144
Douglas Gregora7a795b2011-03-01 20:11:18 +00005145 // Copy information relevant to the template specialization.
5146 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005147 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005148 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005149 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005150 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5151 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005152 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005153 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005154
Douglas Gregora7a795b2011-03-01 20:11:18 +00005155 // Copy information relevant to the elaborated type.
5156 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005157 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005158 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005159 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5160 DependentTemplateSpecializationTypeLoc SpecTL
5161 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005162 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005163 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005164 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005165 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005166 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5167 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005168 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005169 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005170 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005171 TemplateSpecializationTypeLoc SpecTL
5172 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005173 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005174 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005175 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5176 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005177 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005178 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005179 }
5180 return Result;
5181}
5182
5183template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005184QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5185 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005186 QualType Pattern
5187 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005188 if (Pattern.isNull())
5189 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005190
5191 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005192 if (getDerived().AlwaysRebuild() ||
5193 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005194 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005195 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005196 TL.getEllipsisLoc(),
5197 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005198 if (Result.isNull())
5199 return QualType();
5200 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005201
Douglas Gregor822d0302011-01-12 17:07:58 +00005202 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5203 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5204 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005205}
5206
5207template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005208QualType
5209TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005210 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005211 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005212 TLB.pushFullCopy(TL);
5213 return TL.getType();
5214}
5215
5216template<typename Derived>
5217QualType
5218TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005219 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00005220 // ObjCObjectType is never dependent.
5221 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005222 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005223}
Mike Stump11289f42009-09-09 15:08:12 +00005224
5225template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005226QualType
5227TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005228 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005229 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005230 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005231 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005232}
5233
Douglas Gregord6ff3322009-08-04 16:50:30 +00005234//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005235// Statement transformation
5236//===----------------------------------------------------------------------===//
5237template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005238StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005239TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005240 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005241}
5242
5243template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005244StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005245TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5246 return getDerived().TransformCompoundStmt(S, false);
5247}
5248
5249template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005250StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005251TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005252 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005253 Sema::CompoundScopeRAII CompoundScope(getSema());
5254
John McCall1ababa62010-08-27 19:56:05 +00005255 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005256 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005257 SmallVector<Stmt*, 8> Statements;
Douglas Gregorebe10102009-08-20 07:17:43 +00005258 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5259 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00005260 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00005261 if (Result.isInvalid()) {
5262 // Immediately fail if this was a DeclStmt, since it's very
5263 // likely that this will cause problems for future statements.
5264 if (isa<DeclStmt>(*B))
5265 return StmtError();
5266
5267 // Otherwise, just keep processing substatements and fail later.
5268 SubStmtInvalid = true;
5269 continue;
5270 }
Mike Stump11289f42009-09-09 15:08:12 +00005271
Douglas Gregorebe10102009-08-20 07:17:43 +00005272 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5273 Statements.push_back(Result.takeAs<Stmt>());
5274 }
Mike Stump11289f42009-09-09 15:08:12 +00005275
John McCall1ababa62010-08-27 19:56:05 +00005276 if (SubStmtInvalid)
5277 return StmtError();
5278
Douglas Gregorebe10102009-08-20 07:17:43 +00005279 if (!getDerived().AlwaysRebuild() &&
5280 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00005281 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005282
5283 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005284 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005285 S->getRBracLoc(),
5286 IsStmtExpr);
5287}
Mike Stump11289f42009-09-09 15:08:12 +00005288
Douglas Gregorebe10102009-08-20 07:17:43 +00005289template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005290StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005291TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005292 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005293 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005294 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5295 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005296
Eli Friedman06577382009-11-19 03:14:00 +00005297 // Transform the left-hand case value.
5298 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005299 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005300 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005301 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005302
Eli Friedman06577382009-11-19 03:14:00 +00005303 // Transform the right-hand case value (for the GNU case-range extension).
5304 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005305 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005306 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005307 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005308 }
Mike Stump11289f42009-09-09 15:08:12 +00005309
Douglas Gregorebe10102009-08-20 07:17:43 +00005310 // Build the case statement.
5311 // Case statements are always rebuilt so that they will attached to their
5312 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005313 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005314 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005315 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005316 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005317 S->getColonLoc());
5318 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005319 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005320
Douglas Gregorebe10102009-08-20 07:17:43 +00005321 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005322 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005323 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005324 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005325
Douglas Gregorebe10102009-08-20 07:17:43 +00005326 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005327 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005328}
5329
5330template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005331StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005332TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005333 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005334 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005335 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005336 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005337
Douglas Gregorebe10102009-08-20 07:17:43 +00005338 // Default statements are always rebuilt
5339 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005340 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005341}
Mike Stump11289f42009-09-09 15:08:12 +00005342
Douglas Gregorebe10102009-08-20 07:17:43 +00005343template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005344StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005345TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005346 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005347 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005348 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005349
Chris Lattnercab02a62011-02-17 20:34:02 +00005350 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5351 S->getDecl());
5352 if (!LD)
5353 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00005354
5355
Douglas Gregorebe10102009-08-20 07:17:43 +00005356 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005357 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005358 cast<LabelDecl>(LD), SourceLocation(),
5359 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005360}
Mike Stump11289f42009-09-09 15:08:12 +00005361
Douglas Gregorebe10102009-08-20 07:17:43 +00005362template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005363StmtResult
Richard Smithc202b282012-04-14 00:33:13 +00005364TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5365 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5366 if (SubStmt.isInvalid())
5367 return StmtError();
5368
5369 // TODO: transform attributes
5370 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5371 return S;
5372
5373 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5374 S->getAttrs(),
5375 SubStmt.get());
5376}
5377
5378template<typename Derived>
5379StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005380TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005381 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005382 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00005383 VarDecl *ConditionVar = 0;
5384 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005385 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00005386 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005387 getDerived().TransformDefinition(
5388 S->getConditionVariable()->getLocation(),
5389 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00005390 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005391 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005392 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00005393 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005394
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005395 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005396 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005397
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005398 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005399 if (S->getCond()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005400 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005401 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005402 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005403 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005404
John McCallb268a282010-08-23 23:25:46 +00005405 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005406 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005407 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005408
John McCallb268a282010-08-23 23:25:46 +00005409 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5410 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005411 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005412
Douglas Gregorebe10102009-08-20 07:17:43 +00005413 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005414 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005415 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005416 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005417
Douglas Gregorebe10102009-08-20 07:17:43 +00005418 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005419 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005420 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005421 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005422
Douglas Gregorebe10102009-08-20 07:17:43 +00005423 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005424 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005425 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005426 Then.get() == S->getThen() &&
5427 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00005428 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005429
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005430 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005431 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00005432 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005433}
5434
5435template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005436StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005437TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005438 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005439 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00005440 VarDecl *ConditionVar = 0;
5441 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005442 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005443 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005444 getDerived().TransformDefinition(
5445 S->getConditionVariable()->getLocation(),
5446 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005447 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005448 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005449 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005450 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005451
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005452 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005453 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005454 }
Mike Stump11289f42009-09-09 15:08:12 +00005455
Douglas Gregorebe10102009-08-20 07:17:43 +00005456 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005457 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005458 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005459 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005460 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005461 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005462
Douglas Gregorebe10102009-08-20 07:17:43 +00005463 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005464 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005465 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005466 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005467
Douglas Gregorebe10102009-08-20 07:17:43 +00005468 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005469 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5470 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005471}
Mike Stump11289f42009-09-09 15:08:12 +00005472
Douglas Gregorebe10102009-08-20 07:17:43 +00005473template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005474StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005475TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005476 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005477 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00005478 VarDecl *ConditionVar = 0;
5479 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005480 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005481 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005482 getDerived().TransformDefinition(
5483 S->getConditionVariable()->getLocation(),
5484 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005485 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005486 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005487 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005488 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005489
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005490 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005491 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005492
5493 if (S->getCond()) {
5494 // Convert the condition to a boolean value.
Chad Rosier1dcde962012-08-08 18:46:20 +00005495 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005496 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005497 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005498 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005499 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005500 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005501 }
Mike Stump11289f42009-09-09 15:08:12 +00005502
John McCallb268a282010-08-23 23:25:46 +00005503 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5504 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005505 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005506
Douglas Gregorebe10102009-08-20 07:17:43 +00005507 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005508 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005509 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005510 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005511
Douglas Gregorebe10102009-08-20 07:17:43 +00005512 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005513 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005514 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005515 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005516 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005517
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005518 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005519 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005520}
Mike Stump11289f42009-09-09 15:08:12 +00005521
Douglas Gregorebe10102009-08-20 07:17:43 +00005522template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005523StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005524TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005525 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005526 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005527 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005528 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005529
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005530 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005531 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005532 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005533 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005534
Douglas Gregorebe10102009-08-20 07:17:43 +00005535 if (!getDerived().AlwaysRebuild() &&
5536 Cond.get() == S->getCond() &&
5537 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005538 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005539
John McCallb268a282010-08-23 23:25:46 +00005540 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5541 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005542 S->getRParenLoc());
5543}
Mike Stump11289f42009-09-09 15:08:12 +00005544
Douglas Gregorebe10102009-08-20 07:17:43 +00005545template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005546StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005547TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005548 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005549 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005550 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005551 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005552
Douglas Gregorebe10102009-08-20 07:17:43 +00005553 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005554 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005555 VarDecl *ConditionVar = 0;
5556 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005557 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005558 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005559 getDerived().TransformDefinition(
5560 S->getConditionVariable()->getLocation(),
5561 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005562 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005563 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005564 } else {
5565 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005566
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005567 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005568 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005569
5570 if (S->getCond()) {
5571 // Convert the condition to a boolean value.
Chad Rosier1dcde962012-08-08 18:46:20 +00005572 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005573 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005574 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005575 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005576
John McCallb268a282010-08-23 23:25:46 +00005577 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005578 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005579 }
Mike Stump11289f42009-09-09 15:08:12 +00005580
Chad Rosier1dcde962012-08-08 18:46:20 +00005581 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCallb268a282010-08-23 23:25:46 +00005582 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005583 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005584
Douglas Gregorebe10102009-08-20 07:17:43 +00005585 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005586 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005587 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005588 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005589
Richard Smith945f8d32013-01-14 22:39:08 +00005590 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00005591 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005592 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005593
Douglas Gregorebe10102009-08-20 07:17:43 +00005594 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005595 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005596 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005597 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005598
Douglas Gregorebe10102009-08-20 07:17:43 +00005599 if (!getDerived().AlwaysRebuild() &&
5600 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005601 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005602 Inc.get() == S->getInc() &&
5603 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005604 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005605
Douglas Gregorebe10102009-08-20 07:17:43 +00005606 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005607 Init.get(), FullCond, ConditionVar,
5608 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005609}
5610
5611template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005612StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005613TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005614 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5615 S->getLabel());
5616 if (!LD)
5617 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005618
Douglas Gregorebe10102009-08-20 07:17:43 +00005619 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005620 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005621 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005622}
5623
5624template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005625StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005626TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005627 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005628 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005629 return StmtError();
Eli Friedman9ccdb1d2012-01-31 22:47:07 +00005630 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump11289f42009-09-09 15:08:12 +00005631
Douglas Gregorebe10102009-08-20 07:17:43 +00005632 if (!getDerived().AlwaysRebuild() &&
5633 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00005634 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005635
5636 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005637 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005638}
5639
5640template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005641StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005642TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005643 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005644}
Mike Stump11289f42009-09-09 15:08:12 +00005645
Douglas Gregorebe10102009-08-20 07:17:43 +00005646template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005647StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005648TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005649 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005650}
Mike Stump11289f42009-09-09 15:08:12 +00005651
Douglas Gregorebe10102009-08-20 07:17:43 +00005652template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005653StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005654TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005655 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005656 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005657 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005658
Mike Stump11289f42009-09-09 15:08:12 +00005659 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005660 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005661 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005662}
Mike Stump11289f42009-09-09 15:08:12 +00005663
Douglas Gregorebe10102009-08-20 07:17:43 +00005664template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005665StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005666TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005667 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005668 SmallVector<Decl *, 4> Decls;
Douglas Gregorebe10102009-08-20 07:17:43 +00005669 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5670 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00005671 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5672 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005673 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005674 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005675
Douglas Gregorebe10102009-08-20 07:17:43 +00005676 if (Transformed != *D)
5677 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005678
Douglas Gregorebe10102009-08-20 07:17:43 +00005679 Decls.push_back(Transformed);
5680 }
Mike Stump11289f42009-09-09 15:08:12 +00005681
Douglas Gregorebe10102009-08-20 07:17:43 +00005682 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00005683 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005684
Rafael Espindolaab417692013-07-09 12:05:01 +00005685 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005686}
Mike Stump11289f42009-09-09 15:08:12 +00005687
Douglas Gregorebe10102009-08-20 07:17:43 +00005688template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005689StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00005690TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005691
Benjamin Kramerf0623432012-08-23 22:51:59 +00005692 SmallVector<Expr*, 8> Constraints;
5693 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005694 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005695
John McCalldadc5752010-08-24 06:29:42 +00005696 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005697 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005698
5699 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00005700
Anders Carlssonaaeef072010-01-24 05:50:09 +00005701 // Go through the outputs.
5702 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005703 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005704
Anders Carlssonaaeef072010-01-24 05:50:09 +00005705 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005706 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005707
Anders Carlssonaaeef072010-01-24 05:50:09 +00005708 // Transform the output expr.
5709 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005710 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005711 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005712 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005713
Anders Carlssonaaeef072010-01-24 05:50:09 +00005714 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005715
John McCallb268a282010-08-23 23:25:46 +00005716 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005717 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005718
Anders Carlssonaaeef072010-01-24 05:50:09 +00005719 // Go through the inputs.
5720 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005721 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005722
Anders Carlssonaaeef072010-01-24 05:50:09 +00005723 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005724 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005725
Anders Carlssonaaeef072010-01-24 05:50:09 +00005726 // Transform the input expr.
5727 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005728 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005729 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005730 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005731
Anders Carlssonaaeef072010-01-24 05:50:09 +00005732 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005733
John McCallb268a282010-08-23 23:25:46 +00005734 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005735 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005736
Anders Carlssonaaeef072010-01-24 05:50:09 +00005737 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00005738 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005739
5740 // Go through the clobbers.
5741 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00005742 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005743
5744 // No need to transform the asm string literal.
5745 AsmString = SemaRef.Owned(S->getAsmString());
Chad Rosierde70e0e2012-08-25 00:11:56 +00005746 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5747 S->isVolatile(), S->getNumOutputs(),
5748 S->getNumInputs(), Names.data(),
5749 Constraints, Exprs, AsmString.get(),
5750 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005751}
5752
Chad Rosier32503022012-06-11 20:47:18 +00005753template<typename Derived>
5754StmtResult
5755TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00005756 ArrayRef<Token> AsmToks =
5757 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00005758
John McCallf413f5e2013-05-03 00:10:13 +00005759 bool HadError = false, HadChange = false;
5760
5761 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5762 SmallVector<Expr*, 8> TransformedExprs;
5763 TransformedExprs.reserve(SrcExprs.size());
5764 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5765 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5766 if (!Result.isUsable()) {
5767 HadError = true;
5768 } else {
5769 HadChange |= (Result.get() != SrcExprs[i]);
5770 TransformedExprs.push_back(Result.take());
5771 }
5772 }
5773
5774 if (HadError) return StmtError();
5775 if (!HadChange && !getDerived().AlwaysRebuild())
5776 return Owned(S);
5777
Chad Rosierb6f46c12012-08-15 16:53:30 +00005778 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00005779 AsmToks, S->getAsmString(),
5780 S->getNumOutputs(), S->getNumInputs(),
5781 S->getAllConstraints(), S->getClobbers(),
5782 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00005783}
Douglas Gregorebe10102009-08-20 07:17:43 +00005784
5785template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005786StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005787TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005788 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005789 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005790 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005791 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005792
Douglas Gregor96c79492010-04-23 22:50:49 +00005793 // Transform the @catch statements (if present).
5794 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005795 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00005796 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005797 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005798 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005799 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005800 if (Catch.get() != S->getCatchStmt(I))
5801 AnyCatchChanged = true;
5802 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005803 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005804
Douglas Gregor306de2f2010-04-22 23:59:56 +00005805 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005806 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005807 if (S->getFinallyStmt()) {
5808 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5809 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005810 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005811 }
5812
5813 // If nothing changed, just retain this statement.
5814 if (!getDerived().AlwaysRebuild() &&
5815 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005816 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005817 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00005818 return SemaRef.Owned(S);
Chad Rosier1dcde962012-08-08 18:46:20 +00005819
Douglas Gregor306de2f2010-04-22 23:59:56 +00005820 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005821 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005822 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005823}
Mike Stump11289f42009-09-09 15:08:12 +00005824
Douglas Gregorebe10102009-08-20 07:17:43 +00005825template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005826StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005827TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005828 // Transform the @catch parameter, if there is one.
5829 VarDecl *Var = 0;
5830 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5831 TypeSourceInfo *TSInfo = 0;
5832 if (FromVar->getTypeSourceInfo()) {
5833 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5834 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005835 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005836 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005837
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005838 QualType T;
5839 if (TSInfo)
5840 T = TSInfo->getType();
5841 else {
5842 T = getDerived().TransformType(FromVar->getType());
5843 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00005844 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005845 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005846
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005847 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5848 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005849 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005850 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005851
John McCalldadc5752010-08-24 06:29:42 +00005852 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005853 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005854 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005855
5856 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005857 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005858 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005859}
Mike Stump11289f42009-09-09 15:08:12 +00005860
Douglas Gregorebe10102009-08-20 07:17:43 +00005861template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005862StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005863TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005864 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005865 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005866 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005867 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005868
Douglas Gregor306de2f2010-04-22 23:59:56 +00005869 // If nothing changed, just retain this statement.
5870 if (!getDerived().AlwaysRebuild() &&
5871 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00005872 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00005873
5874 // Build a new statement.
5875 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005876 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005877}
Mike Stump11289f42009-09-09 15:08:12 +00005878
Douglas Gregorebe10102009-08-20 07:17:43 +00005879template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005880StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005881TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005882 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005883 if (S->getThrowExpr()) {
5884 Operand = getDerived().TransformExpr(S->getThrowExpr());
5885 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005886 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005887 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005888
Douglas Gregor2900c162010-04-22 21:44:01 +00005889 if (!getDerived().AlwaysRebuild() &&
5890 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005891 return getSema().Owned(S);
Chad Rosier1dcde962012-08-08 18:46:20 +00005892
John McCallb268a282010-08-23 23:25:46 +00005893 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005894}
Mike Stump11289f42009-09-09 15:08:12 +00005895
Douglas Gregorebe10102009-08-20 07:17:43 +00005896template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005897StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005898TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005899 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005900 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005901 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005902 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005903 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00005904 Object =
5905 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5906 Object.get());
5907 if (Object.isInvalid())
5908 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005909
Douglas Gregor6148de72010-04-22 22:01:21 +00005910 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005911 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005912 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005913 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005914
Douglas Gregor6148de72010-04-22 22:01:21 +00005915 // If nothing change, just retain the current statement.
5916 if (!getDerived().AlwaysRebuild() &&
5917 Object.get() == S->getSynchExpr() &&
5918 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005919 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005920
5921 // Build a new statement.
5922 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005923 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005924}
5925
5926template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005927StmtResult
John McCall31168b02011-06-15 23:02:42 +00005928TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5929 ObjCAutoreleasePoolStmt *S) {
5930 // Transform the body.
5931 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5932 if (Body.isInvalid())
5933 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005934
John McCall31168b02011-06-15 23:02:42 +00005935 // If nothing changed, just retain this statement.
5936 if (!getDerived().AlwaysRebuild() &&
5937 Body.get() == S->getSubStmt())
5938 return SemaRef.Owned(S);
5939
5940 // Build a new statement.
5941 return getDerived().RebuildObjCAutoreleasePoolStmt(
5942 S->getAtLoc(), Body.get());
5943}
5944
5945template<typename Derived>
5946StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005947TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005948 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005949 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005950 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005951 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005952 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005953
Douglas Gregorf68a5082010-04-22 23:10:45 +00005954 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00005955 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005956 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005957 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005958
Douglas Gregorf68a5082010-04-22 23:10:45 +00005959 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005960 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005961 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005962 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005963
Douglas Gregorf68a5082010-04-22 23:10:45 +00005964 // If nothing changed, just retain this statement.
5965 if (!getDerived().AlwaysRebuild() &&
5966 Element.get() == S->getElement() &&
5967 Collection.get() == S->getCollection() &&
5968 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005969 return SemaRef.Owned(S);
Chad Rosier1dcde962012-08-08 18:46:20 +00005970
Douglas Gregorf68a5082010-04-22 23:10:45 +00005971 // Build a new statement.
5972 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00005973 Element.get(),
5974 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00005975 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005976 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005977}
5978
David Majnemer5f7efef2013-10-15 09:50:08 +00005979template <typename Derived>
5980StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005981 // Transform the exception declaration, if any.
5982 VarDecl *Var = 0;
David Majnemer5f7efef2013-10-15 09:50:08 +00005983 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
5984 TypeSourceInfo *T =
5985 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005986 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005987 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005988
David Majnemer5f7efef2013-10-15 09:50:08 +00005989 Var = getDerived().RebuildExceptionDecl(
5990 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
5991 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00005992 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00005993 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005994 }
Mike Stump11289f42009-09-09 15:08:12 +00005995
Douglas Gregorebe10102009-08-20 07:17:43 +00005996 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00005997 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00005998 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005999 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006000
David Majnemer5f7efef2013-10-15 09:50:08 +00006001 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006002 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00006003 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00006004
David Majnemer5f7efef2013-10-15 09:50:08 +00006005 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006006}
Mike Stump11289f42009-09-09 15:08:12 +00006007
David Majnemer5f7efef2013-10-15 09:50:08 +00006008template <typename Derived>
6009StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006010 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006011 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006012 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006013 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006014
Douglas Gregorebe10102009-08-20 07:17:43 +00006015 // Transform the handlers.
6016 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006017 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006018 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006019 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006020 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006021 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006022
Douglas Gregorebe10102009-08-20 07:17:43 +00006023 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
6024 Handlers.push_back(Handler.takeAs<Stmt>());
6025 }
Mike Stump11289f42009-09-09 15:08:12 +00006026
David Majnemer5f7efef2013-10-15 09:50:08 +00006027 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006028 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00006029 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00006030
John McCallb268a282010-08-23 23:25:46 +00006031 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006032 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006033}
Mike Stump11289f42009-09-09 15:08:12 +00006034
Richard Smith02e85f32011-04-14 22:09:26 +00006035template<typename Derived>
6036StmtResult
6037TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6038 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6039 if (Range.isInvalid())
6040 return StmtError();
6041
6042 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6043 if (BeginEnd.isInvalid())
6044 return StmtError();
6045
6046 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6047 if (Cond.isInvalid())
6048 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006049 if (Cond.get())
6050 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
6051 if (Cond.isInvalid())
6052 return StmtError();
6053 if (Cond.get())
6054 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smith02e85f32011-04-14 22:09:26 +00006055
6056 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6057 if (Inc.isInvalid())
6058 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006059 if (Inc.get())
6060 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smith02e85f32011-04-14 22:09:26 +00006061
6062 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6063 if (LoopVar.isInvalid())
6064 return StmtError();
6065
6066 StmtResult NewStmt = S;
6067 if (getDerived().AlwaysRebuild() ||
6068 Range.get() != S->getRangeStmt() ||
6069 BeginEnd.get() != S->getBeginEndStmt() ||
6070 Cond.get() != S->getCond() ||
6071 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006072 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006073 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6074 S->getColonLoc(), Range.get(),
6075 BeginEnd.get(), Cond.get(),
6076 Inc.get(), LoopVar.get(),
6077 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006078 if (NewStmt.isInvalid())
6079 return StmtError();
6080 }
Richard Smith02e85f32011-04-14 22:09:26 +00006081
6082 StmtResult Body = getDerived().TransformStmt(S->getBody());
6083 if (Body.isInvalid())
6084 return StmtError();
6085
6086 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6087 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006088 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006089 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6090 S->getColonLoc(), Range.get(),
6091 BeginEnd.get(), Cond.get(),
6092 Inc.get(), LoopVar.get(),
6093 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006094 if (NewStmt.isInvalid())
6095 return StmtError();
6096 }
Richard Smith02e85f32011-04-14 22:09:26 +00006097
6098 if (NewStmt.get() == S)
6099 return SemaRef.Owned(S);
6100
6101 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6102}
6103
John Wiegley1c0675e2011-04-28 01:08:34 +00006104template<typename Derived>
6105StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006106TreeTransform<Derived>::TransformMSDependentExistsStmt(
6107 MSDependentExistsStmt *S) {
6108 // Transform the nested-name-specifier, if any.
6109 NestedNameSpecifierLoc QualifierLoc;
6110 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006111 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006112 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6113 if (!QualifierLoc)
6114 return StmtError();
6115 }
6116
6117 // Transform the declaration name.
6118 DeclarationNameInfo NameInfo = S->getNameInfo();
6119 if (NameInfo.getName()) {
6120 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6121 if (!NameInfo.getName())
6122 return StmtError();
6123 }
6124
6125 // Check whether anything changed.
6126 if (!getDerived().AlwaysRebuild() &&
6127 QualifierLoc == S->getQualifierLoc() &&
6128 NameInfo.getName() == S->getNameInfo().getName())
6129 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006130
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006131 // Determine whether this name exists, if we can.
6132 CXXScopeSpec SS;
6133 SS.Adopt(QualifierLoc);
6134 bool Dependent = false;
6135 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
6136 case Sema::IER_Exists:
6137 if (S->isIfExists())
6138 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006139
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006140 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6141
6142 case Sema::IER_DoesNotExist:
6143 if (S->isIfNotExists())
6144 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006145
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006146 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006147
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006148 case Sema::IER_Dependent:
6149 Dependent = true;
6150 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006151
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006152 case Sema::IER_Error:
6153 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006154 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006155
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006156 // We need to continue with the instantiation, so do so now.
6157 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6158 if (SubStmt.isInvalid())
6159 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006160
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006161 // If we have resolved the name, just transform to the substatement.
6162 if (!Dependent)
6163 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006164
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006165 // The name is still dependent, so build a dependent expression again.
6166 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6167 S->isIfExists(),
6168 QualifierLoc,
6169 NameInfo,
6170 SubStmt.get());
6171}
6172
6173template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006174ExprResult
6175TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6176 NestedNameSpecifierLoc QualifierLoc;
6177 if (E->getQualifierLoc()) {
6178 QualifierLoc
6179 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6180 if (!QualifierLoc)
6181 return ExprError();
6182 }
6183
6184 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6185 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6186 if (!PD)
6187 return ExprError();
6188
6189 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6190 if (Base.isInvalid())
6191 return ExprError();
6192
6193 return new (SemaRef.getASTContext())
6194 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6195 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6196 QualifierLoc, E->getMemberLoc());
6197}
6198
David Majnemerfad8f482013-10-15 09:33:02 +00006199template <typename Derived>
6200StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006201 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006202 if (TryBlock.isInvalid())
6203 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006204
6205 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006206 if (Handler.isInvalid())
6207 return StmtError();
6208
David Majnemerfad8f482013-10-15 09:33:02 +00006209 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6210 Handler.get() == S->getHandler())
John Wiegley1c0675e2011-04-28 01:08:34 +00006211 return SemaRef.Owned(S);
6212
David Majnemerfad8f482013-10-15 09:33:02 +00006213 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
6214 TryBlock.take(), Handler.take());
John Wiegley1c0675e2011-04-28 01:08:34 +00006215}
6216
David Majnemerfad8f482013-10-15 09:33:02 +00006217template <typename Derived>
6218StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006219 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006220 if (Block.isInvalid())
6221 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006222
David Majnemerfad8f482013-10-15 09:33:02 +00006223 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.take());
John Wiegley1c0675e2011-04-28 01:08:34 +00006224}
6225
David Majnemerfad8f482013-10-15 09:33:02 +00006226template <typename Derived>
6227StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00006228 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00006229 if (FilterExpr.isInvalid())
6230 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006231
David Majnemer7e755502013-10-15 09:30:14 +00006232 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006233 if (Block.isInvalid())
6234 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006235
David Majnemerfad8f482013-10-15 09:33:02 +00006236 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.take(),
John Wiegley1c0675e2011-04-28 01:08:34 +00006237 Block.take());
6238}
6239
David Majnemerfad8f482013-10-15 09:33:02 +00006240template <typename Derived>
6241StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6242 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00006243 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6244 else
6245 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6246}
6247
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006248template<typename Derived>
6249StmtResult
6250TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006251 DeclarationNameInfo DirName;
6252 getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, 0);
6253
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006254 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00006255 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006256 ArrayRef<OMPClause *> Clauses = D->clauses();
6257 TClauses.reserve(Clauses.size());
6258 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6259 I != E; ++I) {
6260 if (*I) {
6261 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataev758e55e2013-09-06 18:03:48 +00006262 if (!Clause) {
6263 getSema().EndOpenMPDSABlock(0);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006264 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006265 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006266 TClauses.push_back(Clause);
6267 }
6268 else {
6269 TClauses.push_back(0);
6270 }
6271 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00006272 if (!D->getAssociatedStmt()) {
6273 getSema().EndOpenMPDSABlock(0);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006274 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006275 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006276 StmtResult AssociatedStmt =
6277 getDerived().TransformStmt(D->getAssociatedStmt());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006278 if (AssociatedStmt.isInvalid()) {
6279 getSema().EndOpenMPDSABlock(0);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006280 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006281 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006282
Alexey Bataev758e55e2013-09-06 18:03:48 +00006283 StmtResult Res = getDerived().RebuildOMPParallelDirective(TClauses,
6284 AssociatedStmt.take(),
6285 D->getLocStart(),
6286 D->getLocEnd());
6287 getSema().EndOpenMPDSABlock(Res.get());
6288 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006289}
6290
6291template<typename Derived>
6292OMPClause *
6293TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
6294 return getDerived().RebuildOMPDefaultClause(C->getDefaultKind(),
6295 C->getDefaultKindKwLoc(),
6296 C->getLocStart(),
6297 C->getLParenLoc(),
6298 C->getLocEnd());
6299}
6300
6301template<typename Derived>
6302OMPClause *
6303TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006304 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006305 Vars.reserve(C->varlist_size());
Alexey Bataev756c1962013-09-24 03:17:45 +00006306 for (OMPPrivateClause::varlist_iterator I = C->varlist_begin(),
6307 E = C->varlist_end();
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006308 I != E; ++I) {
6309 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6310 if (EVar.isInvalid())
6311 return 0;
6312 Vars.push_back(EVar.take());
6313 }
6314 return getDerived().RebuildOMPPrivateClause(Vars,
6315 C->getLocStart(),
6316 C->getLParenLoc(),
6317 C->getLocEnd());
6318}
6319
Alexey Bataev758e55e2013-09-06 18:03:48 +00006320template<typename Derived>
6321OMPClause *
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006322TreeTransform<Derived>::TransformOMPFirstprivateClause(
6323 OMPFirstprivateClause *C) {
6324 llvm::SmallVector<Expr *, 16> Vars;
6325 Vars.reserve(C->varlist_size());
6326 for (OMPFirstprivateClause::varlist_iterator I = C->varlist_begin(),
6327 E = C->varlist_end();
6328 I != E; ++I) {
6329 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6330 if (EVar.isInvalid())
6331 return 0;
6332 Vars.push_back(EVar.take());
6333 }
6334 return getDerived().RebuildOMPFirstprivateClause(Vars,
6335 C->getLocStart(),
6336 C->getLParenLoc(),
6337 C->getLocEnd());
6338}
6339
6340template<typename Derived>
6341OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00006342TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
6343 llvm::SmallVector<Expr *, 16> Vars;
6344 Vars.reserve(C->varlist_size());
Alexey Bataev756c1962013-09-24 03:17:45 +00006345 for (OMPSharedClause::varlist_iterator I = C->varlist_begin(),
6346 E = C->varlist_end();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006347 I != E; ++I) {
6348 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6349 if (EVar.isInvalid())
6350 return 0;
6351 Vars.push_back(EVar.take());
6352 }
6353 return getDerived().RebuildOMPSharedClause(Vars,
6354 C->getLocStart(),
6355 C->getLParenLoc(),
6356 C->getLocEnd());
6357}
6358
Douglas Gregorebe10102009-08-20 07:17:43 +00006359//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00006360// Expression transformation
6361//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00006362template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006363ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006364TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006365 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006366}
Mike Stump11289f42009-09-09 15:08:12 +00006367
6368template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006369ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006370TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006371 NestedNameSpecifierLoc QualifierLoc;
6372 if (E->getQualifierLoc()) {
6373 QualifierLoc
6374 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6375 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006376 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006377 }
John McCallce546572009-12-08 09:08:17 +00006378
6379 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006380 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6381 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006382 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00006383 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006384
John McCall815039a2010-08-17 21:27:17 +00006385 DeclarationNameInfo NameInfo = E->getNameInfo();
6386 if (NameInfo.getName()) {
6387 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6388 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006389 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00006390 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006391
6392 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006393 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006394 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006395 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00006396 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006397
6398 // Mark it referenced in the new context regardless.
6399 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00006400 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00006401
John McCallc3007a22010-10-26 07:05:15 +00006402 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006403 }
John McCallce546572009-12-08 09:08:17 +00006404
6405 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00006406 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006407 TemplateArgs = &TransArgs;
6408 TransArgs.setLAngleLoc(E->getLAngleLoc());
6409 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006410 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6411 E->getNumTemplateArgs(),
6412 TransArgs))
6413 return ExprError();
John McCallce546572009-12-08 09:08:17 +00006414 }
6415
Chad Rosier1dcde962012-08-08 18:46:20 +00006416 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00006417 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006418}
Mike Stump11289f42009-09-09 15:08:12 +00006419
Douglas Gregora16548e2009-08-11 05:31:07 +00006420template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006421ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006422TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006423 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006424}
Mike Stump11289f42009-09-09 15:08:12 +00006425
Douglas Gregora16548e2009-08-11 05:31:07 +00006426template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006427ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006428TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006429 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006430}
Mike Stump11289f42009-09-09 15:08:12 +00006431
Douglas Gregora16548e2009-08-11 05:31:07 +00006432template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006433ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006434TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006435 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006436}
Mike Stump11289f42009-09-09 15:08:12 +00006437
Douglas Gregora16548e2009-08-11 05:31:07 +00006438template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006439ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006440TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006441 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006442}
Mike Stump11289f42009-09-09 15:08:12 +00006443
Douglas Gregora16548e2009-08-11 05:31:07 +00006444template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006445ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006446TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006447 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006448}
6449
6450template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006451ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00006452TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00006453 if (FunctionDecl *FD = E->getDirectCallee())
6454 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00006455 return SemaRef.MaybeBindToTemporary(E);
6456}
6457
6458template<typename Derived>
6459ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00006460TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6461 ExprResult ControllingExpr =
6462 getDerived().TransformExpr(E->getControllingExpr());
6463 if (ControllingExpr.isInvalid())
6464 return ExprError();
6465
Chris Lattner01cf8db2011-07-20 06:58:45 +00006466 SmallVector<Expr *, 4> AssocExprs;
6467 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00006468 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6469 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6470 if (TS) {
6471 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6472 if (!AssocType)
6473 return ExprError();
6474 AssocTypes.push_back(AssocType);
6475 } else {
6476 AssocTypes.push_back(0);
6477 }
6478
6479 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6480 if (AssocExpr.isInvalid())
6481 return ExprError();
6482 AssocExprs.push_back(AssocExpr.release());
6483 }
6484
6485 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6486 E->getDefaultLoc(),
6487 E->getRParenLoc(),
6488 ControllingExpr.release(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00006489 AssocTypes,
6490 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00006491}
6492
6493template<typename Derived>
6494ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006495TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006496 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006497 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006498 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006499
Douglas Gregora16548e2009-08-11 05:31:07 +00006500 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006501 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006502
John McCallb268a282010-08-23 23:25:46 +00006503 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006504 E->getRParen());
6505}
6506
Richard Smithdb2630f2012-10-21 03:28:35 +00006507/// \brief The operand of a unary address-of operator has special rules: it's
6508/// allowed to refer to a non-static member of a class even if there's no 'this'
6509/// object available.
6510template<typename Derived>
6511ExprResult
6512TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6513 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6514 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6515 else
6516 return getDerived().TransformExpr(E);
6517}
6518
Mike Stump11289f42009-09-09 15:08:12 +00006519template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006520ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006521TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00006522 ExprResult SubExpr;
6523 if (E->getOpcode() == UO_AddrOf)
6524 SubExpr = TransformAddressOfOperand(E->getSubExpr());
6525 else
6526 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006527 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006528 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006529
Douglas Gregora16548e2009-08-11 05:31:07 +00006530 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006531 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006532
Douglas Gregora16548e2009-08-11 05:31:07 +00006533 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6534 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006535 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006536}
Mike Stump11289f42009-09-09 15:08:12 +00006537
Douglas Gregora16548e2009-08-11 05:31:07 +00006538template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006539ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00006540TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6541 // Transform the type.
6542 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6543 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00006544 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006545
Douglas Gregor882211c2010-04-28 22:16:22 +00006546 // Transform all of the components into components similar to what the
6547 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00006548 // FIXME: It would be slightly more efficient in the non-dependent case to
6549 // just map FieldDecls, rather than requiring the rebuilder to look for
6550 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00006551 // template code that we don't care.
6552 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00006553 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00006554 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006555 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00006556 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6557 const Node &ON = E->getComponent(I);
6558 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00006559 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00006560 Comp.LocStart = ON.getSourceRange().getBegin();
6561 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00006562 switch (ON.getKind()) {
6563 case Node::Array: {
6564 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00006565 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00006566 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006567 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006568
Douglas Gregor882211c2010-04-28 22:16:22 +00006569 ExprChanged = ExprChanged || Index.get() != FromIndex;
6570 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00006571 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00006572 break;
6573 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006574
Douglas Gregor882211c2010-04-28 22:16:22 +00006575 case Node::Field:
6576 case Node::Identifier:
6577 Comp.isBrackets = false;
6578 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00006579 if (!Comp.U.IdentInfo)
6580 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00006581
Douglas Gregor882211c2010-04-28 22:16:22 +00006582 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006583
Douglas Gregord1702062010-04-29 00:18:15 +00006584 case Node::Base:
6585 // Will be recomputed during the rebuild.
6586 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00006587 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006588
Douglas Gregor882211c2010-04-28 22:16:22 +00006589 Components.push_back(Comp);
6590 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006591
Douglas Gregor882211c2010-04-28 22:16:22 +00006592 // If nothing changed, retain the existing expression.
6593 if (!getDerived().AlwaysRebuild() &&
6594 Type == E->getTypeSourceInfo() &&
6595 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00006596 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00006597
Douglas Gregor882211c2010-04-28 22:16:22 +00006598 // Build a new offsetof expression.
6599 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6600 Components.data(), Components.size(),
6601 E->getRParenLoc());
6602}
6603
6604template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006605ExprResult
John McCall8d69a212010-11-15 23:31:06 +00006606TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6607 assert(getDerived().AlreadyTransformed(E->getType()) &&
6608 "opaque value expression requires transformation");
6609 return SemaRef.Owned(E);
6610}
6611
6612template<typename Derived>
6613ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00006614TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00006615 // Rebuild the syntactic form. The original syntactic form has
6616 // opaque-value expressions in it, so strip those away and rebuild
6617 // the result. This is a really awful way of doing this, but the
6618 // better solution (rebuilding the semantic expressions and
6619 // rebinding OVEs as necessary) doesn't work; we'd need
6620 // TreeTransform to not strip away implicit conversions.
6621 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6622 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00006623 if (result.isInvalid()) return ExprError();
6624
6625 // If that gives us a pseudo-object result back, the pseudo-object
6626 // expression must have been an lvalue-to-rvalue conversion which we
6627 // should reapply.
6628 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6629 result = SemaRef.checkPseudoObjectRValue(result.take());
6630
6631 return result;
6632}
6633
6634template<typename Derived>
6635ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00006636TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6637 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006638 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00006639 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00006640
John McCallbcd03502009-12-07 02:54:59 +00006641 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00006642 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006643 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006644
John McCall4c98fd82009-11-04 07:28:41 +00006645 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00006646 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006647
Peter Collingbournee190dee2011-03-11 19:24:49 +00006648 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6649 E->getKind(),
6650 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006651 }
Mike Stump11289f42009-09-09 15:08:12 +00006652
Eli Friedmane4f22df2012-02-29 04:03:55 +00006653 // C++0x [expr.sizeof]p1:
6654 // The operand is either an expression, which is an unevaluated operand
6655 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00006656 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6657 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00006658
Eli Friedmane4f22df2012-02-29 04:03:55 +00006659 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6660 if (SubExpr.isInvalid())
6661 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006662
Eli Friedmane4f22df2012-02-29 04:03:55 +00006663 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6664 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006665
Peter Collingbournee190dee2011-03-11 19:24:49 +00006666 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6667 E->getOperatorLoc(),
6668 E->getKind(),
6669 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006670}
Mike Stump11289f42009-09-09 15:08:12 +00006671
Douglas Gregora16548e2009-08-11 05:31:07 +00006672template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006673ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006674TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006675 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006676 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006677 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006678
John McCalldadc5752010-08-24 06:29:42 +00006679 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006680 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006681 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006682
6683
Douglas Gregora16548e2009-08-11 05:31:07 +00006684 if (!getDerived().AlwaysRebuild() &&
6685 LHS.get() == E->getLHS() &&
6686 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006687 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006688
John McCallb268a282010-08-23 23:25:46 +00006689 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006690 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006691 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006692 E->getRBracketLoc());
6693}
Mike Stump11289f42009-09-09 15:08:12 +00006694
6695template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006696ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006697TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006698 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00006699 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006700 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006701 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006702
6703 // Transform arguments.
6704 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006705 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00006706 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00006707 &ArgChanged))
6708 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006709
Douglas Gregora16548e2009-08-11 05:31:07 +00006710 if (!getDerived().AlwaysRebuild() &&
6711 Callee.get() == E->getCallee() &&
6712 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00006713 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00006714
Douglas Gregora16548e2009-08-11 05:31:07 +00006715 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00006716 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006717 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00006718 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006719 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00006720 E->getRParenLoc());
6721}
Mike Stump11289f42009-09-09 15:08:12 +00006722
6723template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006724ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006725TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006726 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006727 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006728 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006729
Douglas Gregorea972d32011-02-28 21:54:11 +00006730 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006731 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006732 QualifierLoc
6733 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006734
Douglas Gregorea972d32011-02-28 21:54:11 +00006735 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006736 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006737 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00006738 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00006739
Eli Friedman2cfcef62009-12-04 06:40:45 +00006740 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006741 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6742 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006743 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00006744 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006745
John McCall16df1e52010-03-30 21:47:33 +00006746 NamedDecl *FoundDecl = E->getFoundDecl();
6747 if (FoundDecl == E->getMemberDecl()) {
6748 FoundDecl = Member;
6749 } else {
6750 FoundDecl = cast_or_null<NamedDecl>(
6751 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6752 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00006753 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00006754 }
6755
Douglas Gregora16548e2009-08-11 05:31:07 +00006756 if (!getDerived().AlwaysRebuild() &&
6757 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006758 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006759 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00006760 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00006761 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006762
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006763 // Mark it referenced in the new context regardless.
6764 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00006765 SemaRef.MarkMemberReferenced(E);
6766
John McCallc3007a22010-10-26 07:05:15 +00006767 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006768 }
Douglas Gregora16548e2009-08-11 05:31:07 +00006769
John McCall6b51f282009-11-23 01:53:49 +00006770 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00006771 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00006772 TransArgs.setLAngleLoc(E->getLAngleLoc());
6773 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006774 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6775 E->getNumTemplateArgs(),
6776 TransArgs))
6777 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006778 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006779
Douglas Gregora16548e2009-08-11 05:31:07 +00006780 // FIXME: Bogus source location for the operator
6781 SourceLocation FakeOperatorLoc
6782 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6783
John McCall38836f02010-01-15 08:34:02 +00006784 // FIXME: to do this check properly, we will need to preserve the
6785 // first-qualifier-in-scope here, just in case we had a dependent
6786 // base (and therefore couldn't do the check) and a
6787 // nested-name-qualifier (and therefore could do the lookup).
6788 NamedDecl *FirstQualifierInScope = 0;
6789
John McCallb268a282010-08-23 23:25:46 +00006790 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006791 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00006792 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00006793 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006794 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006795 Member,
John McCall16df1e52010-03-30 21:47:33 +00006796 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00006797 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00006798 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00006799 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00006800}
Mike Stump11289f42009-09-09 15:08:12 +00006801
Douglas Gregora16548e2009-08-11 05:31:07 +00006802template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006803ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006804TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006805 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006806 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006807 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006808
John McCalldadc5752010-08-24 06:29:42 +00006809 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006810 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006811 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006812
Douglas Gregora16548e2009-08-11 05:31:07 +00006813 if (!getDerived().AlwaysRebuild() &&
6814 LHS.get() == E->getLHS() &&
6815 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006816 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006817
Lang Hames5de91cc2012-10-02 04:45:10 +00006818 Sema::FPContractStateRAII FPContractState(getSema());
6819 getSema().FPFeatures.fp_contract = E->isFPContractable();
6820
Douglas Gregora16548e2009-08-11 05:31:07 +00006821 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006822 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006823}
6824
Mike Stump11289f42009-09-09 15:08:12 +00006825template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006826ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006827TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00006828 CompoundAssignOperator *E) {
6829 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006830}
Mike Stump11289f42009-09-09 15:08:12 +00006831
Douglas Gregora16548e2009-08-11 05:31:07 +00006832template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00006833ExprResult TreeTransform<Derived>::
6834TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6835 // Just rebuild the common and RHS expressions and see whether we
6836 // get any changes.
6837
6838 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6839 if (commonExpr.isInvalid())
6840 return ExprError();
6841
6842 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6843 if (rhs.isInvalid())
6844 return ExprError();
6845
6846 if (!getDerived().AlwaysRebuild() &&
6847 commonExpr.get() == e->getCommon() &&
6848 rhs.get() == e->getFalseExpr())
6849 return SemaRef.Owned(e);
6850
6851 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6852 e->getQuestionLoc(),
6853 0,
6854 e->getColonLoc(),
6855 rhs.get());
6856}
6857
6858template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006859ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006860TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006861 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006862 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006863 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006864
John McCalldadc5752010-08-24 06:29:42 +00006865 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006866 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006867 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006868
John McCalldadc5752010-08-24 06:29:42 +00006869 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006870 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006871 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006872
Douglas Gregora16548e2009-08-11 05:31:07 +00006873 if (!getDerived().AlwaysRebuild() &&
6874 Cond.get() == E->getCond() &&
6875 LHS.get() == E->getLHS() &&
6876 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006877 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006878
John McCallb268a282010-08-23 23:25:46 +00006879 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006880 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00006881 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006882 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006883 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006884}
Mike Stump11289f42009-09-09 15:08:12 +00006885
6886template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006887ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006888TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00006889 // Implicit casts are eliminated during transformation, since they
6890 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00006891 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006892}
Mike Stump11289f42009-09-09 15:08:12 +00006893
Douglas Gregora16548e2009-08-11 05:31:07 +00006894template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006895ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006896TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006897 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6898 if (!Type)
6899 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006900
John McCalldadc5752010-08-24 06:29:42 +00006901 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006902 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006903 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006904 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006905
Douglas Gregora16548e2009-08-11 05:31:07 +00006906 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006907 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006908 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006909 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006910
John McCall97513962010-01-15 18:39:57 +00006911 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006912 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006913 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006914 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006915}
Mike Stump11289f42009-09-09 15:08:12 +00006916
Douglas Gregora16548e2009-08-11 05:31:07 +00006917template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006918ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006919TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00006920 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6921 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6922 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006923 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006924
John McCalldadc5752010-08-24 06:29:42 +00006925 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00006926 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006927 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006928
Douglas Gregora16548e2009-08-11 05:31:07 +00006929 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00006930 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006931 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00006932 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006933
John McCall5d7aa7f2010-01-19 22:33:45 +00006934 // Note: the expression type doesn't necessarily match the
6935 // type-as-written, but that's okay, because it should always be
6936 // derivable from the initializer.
6937
John McCalle15bbff2010-01-18 19:35:47 +00006938 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00006939 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00006940 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006941}
Mike Stump11289f42009-09-09 15:08:12 +00006942
Douglas Gregora16548e2009-08-11 05:31:07 +00006943template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006944ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006945TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006946 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006947 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006948 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006949
Douglas Gregora16548e2009-08-11 05:31:07 +00006950 if (!getDerived().AlwaysRebuild() &&
6951 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006952 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006953
Douglas Gregora16548e2009-08-11 05:31:07 +00006954 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00006955 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006956 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00006957 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006958 E->getAccessorLoc(),
6959 E->getAccessor());
6960}
Mike Stump11289f42009-09-09 15:08:12 +00006961
Douglas Gregora16548e2009-08-11 05:31:07 +00006962template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006963ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006964TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006965 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00006966
Benjamin Kramerf0623432012-08-23 22:51:59 +00006967 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00006968 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00006969 Inits, &InitChanged))
6970 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006971
Douglas Gregora16548e2009-08-11 05:31:07 +00006972 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00006973 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006974
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006975 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00006976 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00006977}
Mike Stump11289f42009-09-09 15:08:12 +00006978
Douglas Gregora16548e2009-08-11 05:31:07 +00006979template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006980ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006981TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006982 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00006983
Douglas Gregorebe10102009-08-20 07:17:43 +00006984 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00006985 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006986 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006987 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006988
Douglas Gregorebe10102009-08-20 07:17:43 +00006989 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00006990 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00006991 bool ExprChanged = false;
6992 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6993 DEnd = E->designators_end();
6994 D != DEnd; ++D) {
6995 if (D->isFieldDesignator()) {
6996 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6997 D->getDotLoc(),
6998 D->getFieldLoc()));
6999 continue;
7000 }
Mike Stump11289f42009-09-09 15:08:12 +00007001
Douglas Gregora16548e2009-08-11 05:31:07 +00007002 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00007003 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007004 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007005 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007006
7007 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007008 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007009
Douglas Gregora16548e2009-08-11 05:31:07 +00007010 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
7011 ArrayExprs.push_back(Index.release());
7012 continue;
7013 }
Mike Stump11289f42009-09-09 15:08:12 +00007014
Douglas Gregora16548e2009-08-11 05:31:07 +00007015 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00007016 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00007017 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7018 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007019 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007020
John McCalldadc5752010-08-24 06:29:42 +00007021 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007022 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007023 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007024
7025 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007026 End.get(),
7027 D->getLBracketLoc(),
7028 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007029
Douglas Gregora16548e2009-08-11 05:31:07 +00007030 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7031 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00007032
Douglas Gregora16548e2009-08-11 05:31:07 +00007033 ArrayExprs.push_back(Start.release());
7034 ArrayExprs.push_back(End.release());
7035 }
Mike Stump11289f42009-09-09 15:08:12 +00007036
Douglas Gregora16548e2009-08-11 05:31:07 +00007037 if (!getDerived().AlwaysRebuild() &&
7038 Init.get() == E->getInit() &&
7039 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00007040 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007041
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007042 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007043 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007044 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007045}
Mike Stump11289f42009-09-09 15:08:12 +00007046
Douglas Gregora16548e2009-08-11 05:31:07 +00007047template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007048ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007049TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007050 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00007051 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00007052
Douglas Gregor3da3c062009-10-28 00:29:27 +00007053 // FIXME: Will we ever have proper type location here? Will we actually
7054 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00007055 QualType T = getDerived().TransformType(E->getType());
7056 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007057 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007058
Douglas Gregora16548e2009-08-11 05:31:07 +00007059 if (!getDerived().AlwaysRebuild() &&
7060 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00007061 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007062
Douglas Gregora16548e2009-08-11 05:31:07 +00007063 return getDerived().RebuildImplicitValueInitExpr(T);
7064}
Mike Stump11289f42009-09-09 15:08:12 +00007065
Douglas Gregora16548e2009-08-11 05:31:07 +00007066template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007067ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007068TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00007069 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7070 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007071 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007072
John McCalldadc5752010-08-24 06:29:42 +00007073 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007074 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007075 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007076
Douglas Gregora16548e2009-08-11 05:31:07 +00007077 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00007078 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007079 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007080 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007081
John McCallb268a282010-08-23 23:25:46 +00007082 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00007083 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007084}
7085
7086template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007087ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007088TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007089 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007090 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00007091 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7092 &ArgumentChanged))
7093 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007094
Douglas Gregora16548e2009-08-11 05:31:07 +00007095 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007096 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00007097 E->getRParenLoc());
7098}
Mike Stump11289f42009-09-09 15:08:12 +00007099
Douglas Gregora16548e2009-08-11 05:31:07 +00007100/// \brief Transform an address-of-label expression.
7101///
7102/// By default, the transformation of an address-of-label expression always
7103/// rebuilds the expression, so that the label identifier can be resolved to
7104/// the corresponding label statement by semantic analysis.
7105template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007106ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007107TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00007108 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7109 E->getLabel());
7110 if (!LD)
7111 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007112
Douglas Gregora16548e2009-08-11 05:31:07 +00007113 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00007114 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00007115}
Mike Stump11289f42009-09-09 15:08:12 +00007116
7117template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00007118ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007119TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00007120 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00007121 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00007122 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00007123 if (SubStmt.isInvalid()) {
7124 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00007125 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00007126 }
Mike Stump11289f42009-09-09 15:08:12 +00007127
Douglas Gregora16548e2009-08-11 05:31:07 +00007128 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00007129 SubStmt.get() == E->getSubStmt()) {
7130 // Calling this an 'error' is unintuitive, but it does the right thing.
7131 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007132 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00007133 }
Mike Stump11289f42009-09-09 15:08:12 +00007134
7135 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007136 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007137 E->getRParenLoc());
7138}
Mike Stump11289f42009-09-09 15:08:12 +00007139
Douglas Gregora16548e2009-08-11 05:31:07 +00007140template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007141ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007142TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007143 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007144 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007145 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007146
John McCalldadc5752010-08-24 06:29:42 +00007147 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007148 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007149 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007150
John McCalldadc5752010-08-24 06:29:42 +00007151 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007152 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007153 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007154
Douglas Gregora16548e2009-08-11 05:31:07 +00007155 if (!getDerived().AlwaysRebuild() &&
7156 Cond.get() == E->getCond() &&
7157 LHS.get() == E->getLHS() &&
7158 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00007159 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007160
Douglas Gregora16548e2009-08-11 05:31:07 +00007161 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00007162 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007163 E->getRParenLoc());
7164}
Mike Stump11289f42009-09-09 15:08:12 +00007165
Douglas Gregora16548e2009-08-11 05:31:07 +00007166template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007167ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007168TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007169 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007170}
7171
7172template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007173ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007174TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007175 switch (E->getOperator()) {
7176 case OO_New:
7177 case OO_Delete:
7178 case OO_Array_New:
7179 case OO_Array_Delete:
7180 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00007181
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007182 case OO_Call: {
7183 // This is a call to an object's operator().
7184 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7185
7186 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00007187 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007188 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007189 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007190
7191 // FIXME: Poor location information
7192 SourceLocation FakeLParenLoc
7193 = SemaRef.PP.getLocForEndOfToken(
7194 static_cast<Expr *>(Object.get())->getLocEnd());
7195
7196 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007197 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007198 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00007199 Args))
7200 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007201
John McCallb268a282010-08-23 23:25:46 +00007202 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007203 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007204 E->getLocEnd());
7205 }
7206
7207#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7208 case OO_##Name:
7209#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7210#include "clang/Basic/OperatorKinds.def"
7211 case OO_Subscript:
7212 // Handled below.
7213 break;
7214
7215 case OO_Conditional:
7216 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007217
7218 case OO_None:
7219 case NUM_OVERLOADED_OPERATORS:
7220 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007221 }
7222
John McCalldadc5752010-08-24 06:29:42 +00007223 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007224 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007225 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007226
Richard Smithdb2630f2012-10-21 03:28:35 +00007227 ExprResult First;
7228 if (E->getOperator() == OO_Amp)
7229 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7230 else
7231 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007232 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007233 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007234
John McCalldadc5752010-08-24 06:29:42 +00007235 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00007236 if (E->getNumArgs() == 2) {
7237 Second = getDerived().TransformExpr(E->getArg(1));
7238 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007239 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007240 }
Mike Stump11289f42009-09-09 15:08:12 +00007241
Douglas Gregora16548e2009-08-11 05:31:07 +00007242 if (!getDerived().AlwaysRebuild() &&
7243 Callee.get() == E->getCallee() &&
7244 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00007245 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007246 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007247
Lang Hames5de91cc2012-10-02 04:45:10 +00007248 Sema::FPContractStateRAII FPContractState(getSema());
7249 getSema().FPFeatures.fp_contract = E->isFPContractable();
7250
Douglas Gregora16548e2009-08-11 05:31:07 +00007251 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7252 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00007253 Callee.get(),
7254 First.get(),
7255 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007256}
Mike Stump11289f42009-09-09 15:08:12 +00007257
Douglas Gregora16548e2009-08-11 05:31:07 +00007258template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007259ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007260TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7261 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007262}
Mike Stump11289f42009-09-09 15:08:12 +00007263
Douglas Gregora16548e2009-08-11 05:31:07 +00007264template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007265ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00007266TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7267 // Transform the callee.
7268 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7269 if (Callee.isInvalid())
7270 return ExprError();
7271
7272 // Transform exec config.
7273 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7274 if (EC.isInvalid())
7275 return ExprError();
7276
7277 // Transform arguments.
7278 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007279 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007280 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007281 &ArgChanged))
7282 return ExprError();
7283
7284 if (!getDerived().AlwaysRebuild() &&
7285 Callee.get() == E->getCallee() &&
7286 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007287 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00007288
7289 // FIXME: Wrong source location information for the '('.
7290 SourceLocation FakeLParenLoc
7291 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7292 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007293 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007294 E->getRParenLoc(), EC.get());
7295}
7296
7297template<typename Derived>
7298ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007299TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007300 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7301 if (!Type)
7302 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007303
John McCalldadc5752010-08-24 06:29:42 +00007304 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007305 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007306 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007307 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007308
Douglas Gregora16548e2009-08-11 05:31:07 +00007309 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007310 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007311 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007312 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007313 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00007314 E->getStmtClass(),
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007315 E->getAngleBrackets().getBegin(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007316 Type,
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007317 E->getAngleBrackets().getEnd(),
7318 // FIXME. this should be '(' location
7319 E->getAngleBrackets().getEnd(),
John McCallb268a282010-08-23 23:25:46 +00007320 SubExpr.get(),
Abramo Bagnara9fb43862012-10-15 21:08:58 +00007321 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007322}
Mike Stump11289f42009-09-09 15:08:12 +00007323
Douglas Gregora16548e2009-08-11 05:31:07 +00007324template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007325ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007326TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7327 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007328}
Mike Stump11289f42009-09-09 15:08:12 +00007329
7330template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007331ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007332TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7333 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00007334}
7335
Douglas Gregora16548e2009-08-11 05:31:07 +00007336template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007337ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007338TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007339 CXXReinterpretCastExpr *E) {
7340 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007341}
Mike Stump11289f42009-09-09 15:08:12 +00007342
Douglas Gregora16548e2009-08-11 05:31:07 +00007343template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007344ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007345TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7346 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007347}
Mike Stump11289f42009-09-09 15:08:12 +00007348
Douglas Gregora16548e2009-08-11 05:31:07 +00007349template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007350ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007351TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007352 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007353 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7354 if (!Type)
7355 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007356
John McCalldadc5752010-08-24 06:29:42 +00007357 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007358 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007359 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007360 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007361
Douglas Gregora16548e2009-08-11 05:31:07 +00007362 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007363 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007364 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007365 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007366
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007367 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00007368 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007369 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007370 E->getRParenLoc());
7371}
Mike Stump11289f42009-09-09 15:08:12 +00007372
Douglas Gregora16548e2009-08-11 05:31:07 +00007373template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007374ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007375TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007376 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00007377 TypeSourceInfo *TInfo
7378 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7379 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007380 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007381
Douglas Gregora16548e2009-08-11 05:31:07 +00007382 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00007383 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007384 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007385
Douglas Gregor9da64192010-04-26 22:37:10 +00007386 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7387 E->getLocStart(),
7388 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007389 E->getLocEnd());
7390 }
Mike Stump11289f42009-09-09 15:08:12 +00007391
Eli Friedman456f0182012-01-20 01:26:23 +00007392 // We don't know whether the subexpression is potentially evaluated until
7393 // after we perform semantic analysis. We speculatively assume it is
7394 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00007395 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00007396 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7397 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007398
John McCalldadc5752010-08-24 06:29:42 +00007399 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00007400 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007401 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007402
Douglas Gregora16548e2009-08-11 05:31:07 +00007403 if (!getDerived().AlwaysRebuild() &&
7404 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00007405 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007406
Douglas Gregor9da64192010-04-26 22:37:10 +00007407 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7408 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007409 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007410 E->getLocEnd());
7411}
7412
7413template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007414ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00007415TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7416 if (E->isTypeOperand()) {
7417 TypeSourceInfo *TInfo
7418 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7419 if (!TInfo)
7420 return ExprError();
7421
7422 if (!getDerived().AlwaysRebuild() &&
7423 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007424 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00007425
Douglas Gregor69735112011-03-06 17:40:41 +00007426 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00007427 E->getLocStart(),
7428 TInfo,
7429 E->getLocEnd());
7430 }
7431
Francois Pichet9f4f2072010-09-08 12:20:18 +00007432 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7433
7434 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7435 if (SubExpr.isInvalid())
7436 return ExprError();
7437
7438 if (!getDerived().AlwaysRebuild() &&
7439 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00007440 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00007441
7442 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7443 E->getLocStart(),
7444 SubExpr.get(),
7445 E->getLocEnd());
7446}
7447
7448template<typename Derived>
7449ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007450TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007451 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007452}
Mike Stump11289f42009-09-09 15:08:12 +00007453
Douglas Gregora16548e2009-08-11 05:31:07 +00007454template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007455ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007456TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007457 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007458 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007459}
Mike Stump11289f42009-09-09 15:08:12 +00007460
Douglas Gregora16548e2009-08-11 05:31:07 +00007461template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007462ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007463TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00007464 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00007465
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007466 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7467 // Make sure that we capture 'this'.
7468 getSema().CheckCXXThisCapture(E->getLocStart());
John McCallc3007a22010-10-26 07:05:15 +00007469 return SemaRef.Owned(E);
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007470 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007471
Douglas Gregorb15af892010-01-07 23:12:05 +00007472 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007473}
Mike Stump11289f42009-09-09 15:08:12 +00007474
Douglas Gregora16548e2009-08-11 05:31:07 +00007475template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007476ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007477TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007478 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007479 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007480 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007481
Douglas Gregora16548e2009-08-11 05:31:07 +00007482 if (!getDerived().AlwaysRebuild() &&
7483 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007484 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007485
Douglas Gregor53e191ed2011-07-06 22:04:06 +00007486 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7487 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00007488}
Mike Stump11289f42009-09-09 15:08:12 +00007489
Douglas Gregora16548e2009-08-11 05:31:07 +00007490template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007491ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007492TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00007493 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007494 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7495 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007496 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00007497 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007498
Chandler Carruth794da4c2010-02-08 06:42:49 +00007499 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007500 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00007501 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007502
Douglas Gregor033f6752009-12-23 23:03:06 +00007503 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00007504}
Mike Stump11289f42009-09-09 15:08:12 +00007505
Douglas Gregora16548e2009-08-11 05:31:07 +00007506template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007507ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00007508TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
7509 FieldDecl *Field
7510 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
7511 E->getField()));
7512 if (!Field)
7513 return ExprError();
7514
7515 if (!getDerived().AlwaysRebuild() && Field == E->getField())
7516 return SemaRef.Owned(E);
7517
7518 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
7519}
7520
7521template<typename Derived>
7522ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00007523TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7524 CXXScalarValueInitExpr *E) {
7525 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7526 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007527 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007528
Douglas Gregora16548e2009-08-11 05:31:07 +00007529 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007530 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007531 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007532
Chad Rosier1dcde962012-08-08 18:46:20 +00007533 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00007534 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00007535 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007536}
Mike Stump11289f42009-09-09 15:08:12 +00007537
Douglas Gregora16548e2009-08-11 05:31:07 +00007538template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007539ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007540TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007541 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00007542 TypeSourceInfo *AllocTypeInfo
7543 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7544 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007545 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007546
Douglas Gregora16548e2009-08-11 05:31:07 +00007547 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00007548 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00007549 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007550 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007551
Douglas Gregora16548e2009-08-11 05:31:07 +00007552 // Transform the placement arguments (if any).
7553 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007554 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00007555 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00007556 E->getNumPlacementArgs(), true,
7557 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00007558 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007559
Sebastian Redl6047f072012-02-16 12:22:20 +00007560 // Transform the initializer (if any).
7561 Expr *OldInit = E->getInitializer();
7562 ExprResult NewInit;
7563 if (OldInit)
7564 NewInit = getDerived().TransformExpr(OldInit);
7565 if (NewInit.isInvalid())
7566 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007567
Sebastian Redl6047f072012-02-16 12:22:20 +00007568 // Transform new operator and delete operator.
Douglas Gregord2d9da02010-02-26 00:38:10 +00007569 FunctionDecl *OperatorNew = 0;
7570 if (E->getOperatorNew()) {
7571 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007572 getDerived().TransformDecl(E->getLocStart(),
7573 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007574 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00007575 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007576 }
7577
7578 FunctionDecl *OperatorDelete = 0;
7579 if (E->getOperatorDelete()) {
7580 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007581 getDerived().TransformDecl(E->getLocStart(),
7582 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007583 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007584 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007585 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007586
Douglas Gregora16548e2009-08-11 05:31:07 +00007587 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00007588 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007589 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00007590 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007591 OperatorNew == E->getOperatorNew() &&
7592 OperatorDelete == E->getOperatorDelete() &&
7593 !ArgumentChanged) {
7594 // Mark any declarations we need as referenced.
7595 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00007596 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007597 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007598 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007599 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00007600
Sebastian Redl6047f072012-02-16 12:22:20 +00007601 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00007602 QualType ElementType
7603 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7604 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7605 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7606 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00007607 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00007608 }
7609 }
7610 }
Sebastian Redl6047f072012-02-16 12:22:20 +00007611
John McCallc3007a22010-10-26 07:05:15 +00007612 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007613 }
Mike Stump11289f42009-09-09 15:08:12 +00007614
Douglas Gregor0744ef62010-09-07 21:49:58 +00007615 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007616 if (!ArraySize.get()) {
7617 // If no array size was specified, but the new expression was
7618 // instantiated with an array type (e.g., "new T" where T is
7619 // instantiated with "int[4]"), extract the outer bound from the
7620 // array type as our array size. We do this with constant and
7621 // dependently-sized array types.
7622 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7623 if (!ArrayT) {
7624 // Do nothing
7625 } else if (const ConstantArrayType *ConsArrayT
7626 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007627 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007628 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier1dcde962012-08-08 18:46:20 +00007629 ConsArrayT->getSize(),
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007630 SemaRef.Context.getSizeType(),
7631 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007632 AllocType = ConsArrayT->getElementType();
7633 } else if (const DependentSizedArrayType *DepArrayT
7634 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7635 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00007636 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007637 AllocType = DepArrayT->getElementType();
7638 }
7639 }
7640 }
Sebastian Redl6047f072012-02-16 12:22:20 +00007641
Douglas Gregora16548e2009-08-11 05:31:07 +00007642 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7643 E->isGlobalNew(),
7644 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007645 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007646 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00007647 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007648 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00007649 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00007650 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00007651 E->getDirectInitRange(),
7652 NewInit.take());
Douglas Gregora16548e2009-08-11 05:31:07 +00007653}
Mike Stump11289f42009-09-09 15:08:12 +00007654
Douglas Gregora16548e2009-08-11 05:31:07 +00007655template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007656ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007657TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007658 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00007659 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007660 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007661
Douglas Gregord2d9da02010-02-26 00:38:10 +00007662 // Transform the delete operator, if known.
7663 FunctionDecl *OperatorDelete = 0;
7664 if (E->getOperatorDelete()) {
7665 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007666 getDerived().TransformDecl(E->getLocStart(),
7667 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007668 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007669 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007670 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007671
Douglas Gregora16548e2009-08-11 05:31:07 +00007672 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007673 Operand.get() == E->getArgument() &&
7674 OperatorDelete == E->getOperatorDelete()) {
7675 // Mark any declarations we need as referenced.
7676 // FIXME: instantiation-specific.
7677 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007678 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00007679
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00007680 if (!E->getArgument()->isTypeDependent()) {
7681 QualType Destroyed = SemaRef.Context.getBaseElementType(
7682 E->getDestroyedType());
7683 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7684 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00007685 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00007686 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00007687 }
7688 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007689
John McCallc3007a22010-10-26 07:05:15 +00007690 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007691 }
Mike Stump11289f42009-09-09 15:08:12 +00007692
Douglas Gregora16548e2009-08-11 05:31:07 +00007693 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7694 E->isGlobalDelete(),
7695 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00007696 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007697}
Mike Stump11289f42009-09-09 15:08:12 +00007698
Douglas Gregora16548e2009-08-11 05:31:07 +00007699template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007700ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00007701TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007702 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007703 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00007704 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007705 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007706
John McCallba7bf592010-08-24 05:47:05 +00007707 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00007708 bool MayBePseudoDestructor = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00007709 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007710 E->getOperatorLoc(),
7711 E->isArrow()? tok::arrow : tok::period,
7712 ObjectTypePtr,
7713 MayBePseudoDestructor);
7714 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007715 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007716
John McCallba7bf592010-08-24 05:47:05 +00007717 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00007718 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7719 if (QualifierLoc) {
7720 QualifierLoc
7721 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7722 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00007723 return ExprError();
7724 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00007725 CXXScopeSpec SS;
7726 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00007727
Douglas Gregor678f90d2010-02-25 01:56:36 +00007728 PseudoDestructorTypeStorage Destroyed;
7729 if (E->getDestroyedTypeInfo()) {
7730 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00007731 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00007732 ObjectType, 0, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00007733 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007734 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00007735 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00007736 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00007737 // We aren't likely to be able to resolve the identifier down to a type
7738 // now anyway, so just retain the identifier.
7739 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7740 E->getDestroyedTypeLoc());
7741 } else {
7742 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00007743 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007744 *E->getDestroyedTypeIdentifier(),
7745 E->getDestroyedTypeLoc(),
7746 /*Scope=*/0,
7747 SS, ObjectTypePtr,
7748 false);
7749 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007750 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007751
Douglas Gregor678f90d2010-02-25 01:56:36 +00007752 Destroyed
7753 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7754 E->getDestroyedTypeLoc());
7755 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007756
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007757 TypeSourceInfo *ScopeTypeInfo = 0;
7758 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00007759 CXXScopeSpec EmptySS;
7760 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
7761 E->getScopeTypeInfo(), ObjectType, 0, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007762 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007763 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00007764 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007765
John McCallb268a282010-08-23 23:25:46 +00007766 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00007767 E->getOperatorLoc(),
7768 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00007769 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007770 ScopeTypeInfo,
7771 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007772 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007773 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00007774}
Mike Stump11289f42009-09-09 15:08:12 +00007775
Douglas Gregorad8a3362009-09-04 17:36:40 +00007776template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007777ExprResult
John McCalld14a8642009-11-21 08:51:07 +00007778TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007779 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00007780 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7781 Sema::LookupOrdinaryName);
7782
7783 // Transform all the decls.
7784 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7785 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007786 NamedDecl *InstD = static_cast<NamedDecl*>(
7787 getDerived().TransformDecl(Old->getNameLoc(),
7788 *I));
John McCall84d87672009-12-10 09:41:52 +00007789 if (!InstD) {
7790 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7791 // This can happen because of dependent hiding.
7792 if (isa<UsingShadowDecl>(*I))
7793 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00007794 else {
7795 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007796 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00007797 }
John McCall84d87672009-12-10 09:41:52 +00007798 }
John McCalle66edc12009-11-24 19:00:30 +00007799
7800 // Expand using declarations.
7801 if (isa<UsingDecl>(InstD)) {
7802 UsingDecl *UD = cast<UsingDecl>(InstD);
7803 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7804 E = UD->shadow_end(); I != E; ++I)
7805 R.addDecl(*I);
7806 continue;
7807 }
7808
7809 R.addDecl(InstD);
7810 }
7811
7812 // Resolve a kind, but don't do any further analysis. If it's
7813 // ambiguous, the callee needs to deal with it.
7814 R.resolveKind();
7815
7816 // Rebuild the nested-name qualifier, if present.
7817 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00007818 if (Old->getQualifierLoc()) {
7819 NestedNameSpecifierLoc QualifierLoc
7820 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7821 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007822 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007823
Douglas Gregor0da1d432011-02-28 20:01:57 +00007824 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00007825 }
7826
Douglas Gregor9262f472010-04-27 18:19:34 +00007827 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00007828 CXXRecordDecl *NamingClass
7829 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7830 Old->getNameLoc(),
7831 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00007832 if (!NamingClass) {
7833 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007834 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00007835 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007836
Douglas Gregorda7be082010-04-27 16:10:10 +00007837 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00007838 }
7839
Abramo Bagnara7945c982012-01-27 09:46:47 +00007840 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7841
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00007842 // If we have neither explicit template arguments, nor the template keyword,
7843 // it's a normal declaration name.
7844 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCalle66edc12009-11-24 19:00:30 +00007845 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7846
7847 // If we have template arguments, rebuild them, then rebuild the
7848 // templateid expression.
7849 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00007850 if (Old->hasExplicitTemplateArgs() &&
7851 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00007852 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00007853 TransArgs)) {
7854 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00007855 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00007856 }
John McCalle66edc12009-11-24 19:00:30 +00007857
Abramo Bagnara7945c982012-01-27 09:46:47 +00007858 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00007859 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007860}
Mike Stump11289f42009-09-09 15:08:12 +00007861
Douglas Gregora16548e2009-08-11 05:31:07 +00007862template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007863ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007864TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00007865 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7866 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007867 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007868
Douglas Gregora16548e2009-08-11 05:31:07 +00007869 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00007870 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007871 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007872
Mike Stump11289f42009-09-09 15:08:12 +00007873 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007874 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007875 T,
7876 E->getLocEnd());
7877}
Mike Stump11289f42009-09-09 15:08:12 +00007878
Douglas Gregora16548e2009-08-11 05:31:07 +00007879template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007880ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00007881TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7882 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7883 if (!LhsT)
7884 return ExprError();
7885
7886 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7887 if (!RhsT)
7888 return ExprError();
7889
7890 if (!getDerived().AlwaysRebuild() &&
7891 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7892 return SemaRef.Owned(E);
7893
7894 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7895 E->getLocStart(),
7896 LhsT, RhsT,
7897 E->getLocEnd());
7898}
7899
7900template<typename Derived>
7901ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00007902TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7903 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00007904 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00007905 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7906 TypeSourceInfo *From = E->getArg(I);
7907 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00007908 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00007909 TypeLocBuilder TLB;
7910 TLB.reserve(FromTL.getFullDataSize());
7911 QualType To = getDerived().TransformType(TLB, FromTL);
7912 if (To.isNull())
7913 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007914
Douglas Gregor29c42f22012-02-24 07:38:34 +00007915 if (To == From->getType())
7916 Args.push_back(From);
7917 else {
7918 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7919 ArgChanged = true;
7920 }
7921 continue;
7922 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007923
Douglas Gregor29c42f22012-02-24 07:38:34 +00007924 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00007925
Douglas Gregor29c42f22012-02-24 07:38:34 +00007926 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00007927 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00007928 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7929 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7930 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00007931
Douglas Gregor29c42f22012-02-24 07:38:34 +00007932 // Determine whether the set of unexpanded parameter packs can and should
7933 // be expanded.
7934 bool Expand = true;
7935 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00007936 Optional<unsigned> OrigNumExpansions =
7937 ExpansionTL.getTypePtr()->getNumExpansions();
7938 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00007939 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7940 PatternTL.getSourceRange(),
7941 Unexpanded,
7942 Expand, RetainExpansion,
7943 NumExpansions))
7944 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007945
Douglas Gregor29c42f22012-02-24 07:38:34 +00007946 if (!Expand) {
7947 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00007948 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00007949 // expansion.
7950 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00007951
Douglas Gregor29c42f22012-02-24 07:38:34 +00007952 TypeLocBuilder TLB;
7953 TLB.reserve(From->getTypeLoc().getFullDataSize());
7954
7955 QualType To = getDerived().TransformType(TLB, PatternTL);
7956 if (To.isNull())
7957 return ExprError();
7958
Chad Rosier1dcde962012-08-08 18:46:20 +00007959 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00007960 PatternTL.getSourceRange(),
7961 ExpansionTL.getEllipsisLoc(),
7962 NumExpansions);
7963 if (To.isNull())
7964 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007965
Douglas Gregor29c42f22012-02-24 07:38:34 +00007966 PackExpansionTypeLoc ToExpansionTL
7967 = TLB.push<PackExpansionTypeLoc>(To);
7968 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7969 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7970 continue;
7971 }
7972
7973 // Expand the pack expansion by substituting for each argument in the
7974 // pack(s).
7975 for (unsigned I = 0; I != *NumExpansions; ++I) {
7976 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7977 TypeLocBuilder TLB;
7978 TLB.reserve(PatternTL.getFullDataSize());
7979 QualType To = getDerived().TransformType(TLB, PatternTL);
7980 if (To.isNull())
7981 return ExprError();
7982
Eli Friedman5e05c4a2013-07-19 21:49:32 +00007983 if (To->containsUnexpandedParameterPack()) {
7984 To = getDerived().RebuildPackExpansionType(To,
7985 PatternTL.getSourceRange(),
7986 ExpansionTL.getEllipsisLoc(),
7987 NumExpansions);
7988 if (To.isNull())
7989 return ExprError();
7990
7991 PackExpansionTypeLoc ToExpansionTL
7992 = TLB.push<PackExpansionTypeLoc>(To);
7993 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7994 }
7995
Douglas Gregor29c42f22012-02-24 07:38:34 +00007996 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7997 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007998
Douglas Gregor29c42f22012-02-24 07:38:34 +00007999 if (!RetainExpansion)
8000 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008001
Douglas Gregor29c42f22012-02-24 07:38:34 +00008002 // If we're supposed to retain a pack expansion, do so by temporarily
8003 // forgetting the partially-substituted parameter pack.
8004 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
8005
8006 TypeLocBuilder TLB;
8007 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00008008
Douglas Gregor29c42f22012-02-24 07:38:34 +00008009 QualType To = getDerived().TransformType(TLB, PatternTL);
8010 if (To.isNull())
8011 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008012
8013 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008014 PatternTL.getSourceRange(),
8015 ExpansionTL.getEllipsisLoc(),
8016 NumExpansions);
8017 if (To.isNull())
8018 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008019
Douglas Gregor29c42f22012-02-24 07:38:34 +00008020 PackExpansionTypeLoc ToExpansionTL
8021 = TLB.push<PackExpansionTypeLoc>(To);
8022 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8023 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8024 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008025
Douglas Gregor29c42f22012-02-24 07:38:34 +00008026 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8027 return SemaRef.Owned(E);
8028
8029 return getDerived().RebuildTypeTrait(E->getTrait(),
8030 E->getLocStart(),
8031 Args,
8032 E->getLocEnd());
8033}
8034
8035template<typename Derived>
8036ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00008037TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8038 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
8039 if (!T)
8040 return ExprError();
8041
8042 if (!getDerived().AlwaysRebuild() &&
8043 T == E->getQueriedTypeSourceInfo())
8044 return SemaRef.Owned(E);
8045
8046 ExprResult SubExpr;
8047 {
8048 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8049 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8050 if (SubExpr.isInvalid())
8051 return ExprError();
8052
8053 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
8054 return SemaRef.Owned(E);
8055 }
8056
8057 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8058 E->getLocStart(),
8059 T,
8060 SubExpr.get(),
8061 E->getLocEnd());
8062}
8063
8064template<typename Derived>
8065ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00008066TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8067 ExprResult SubExpr;
8068 {
8069 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8070 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8071 if (SubExpr.isInvalid())
8072 return ExprError();
8073
8074 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
8075 return SemaRef.Owned(E);
8076 }
8077
8078 return getDerived().RebuildExpressionTrait(
8079 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8080}
8081
8082template<typename Derived>
8083ExprResult
John McCall8cd78132009-11-19 22:55:06 +00008084TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008085 DependentScopeDeclRefExpr *E) {
Richard Smithdb2630f2012-10-21 03:28:35 +00008086 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
8087}
8088
8089template<typename Derived>
8090ExprResult
8091TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8092 DependentScopeDeclRefExpr *E,
8093 bool IsAddressOfOperand) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00008094 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008095 NestedNameSpecifierLoc QualifierLoc
8096 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8097 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008098 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00008099 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008100
John McCall31f82722010-11-12 08:19:04 +00008101 // TODO: If this is a conversion-function-id, verify that the
8102 // destination type name (if present) resolves the same way after
8103 // instantiation as it did in the local scope.
8104
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008105 DeclarationNameInfo NameInfo
8106 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8107 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008108 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008109
John McCalle66edc12009-11-24 19:00:30 +00008110 if (!E->hasExplicitTemplateArgs()) {
8111 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008112 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008113 // Note: it is sufficient to compare the Name component of NameInfo:
8114 // if name has not changed, DNLoc has not changed either.
8115 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00008116 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00008117
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008118 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008119 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008120 NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00008121 /*TemplateArgs*/ 0,
8122 IsAddressOfOperand);
Douglas Gregord019ff62009-10-22 17:20:55 +00008123 }
John McCall6b51f282009-11-23 01:53:49 +00008124
8125 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008126 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8127 E->getNumTemplateArgs(),
8128 TransArgs))
8129 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008130
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008131 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008132 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008133 NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00008134 &TransArgs,
8135 IsAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00008136}
8137
8138template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008139ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008140TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00008141 // CXXConstructExprs other than for list-initialization and
8142 // CXXTemporaryObjectExpr are always implicit, so when we have
8143 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00008144 if ((E->getNumArgs() == 1 ||
8145 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00008146 (!getDerived().DropCallArgument(E->getArg(0))) &&
8147 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00008148 return getDerived().TransformExpr(E->getArg(0));
8149
Douglas Gregora16548e2009-08-11 05:31:07 +00008150 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8151
8152 QualType T = getDerived().TransformType(E->getType());
8153 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008154 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008155
8156 CXXConstructorDecl *Constructor
8157 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008158 getDerived().TransformDecl(E->getLocStart(),
8159 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008160 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008161 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008162
Douglas Gregora16548e2009-08-11 05:31:07 +00008163 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008164 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008165 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008166 &ArgumentChanged))
8167 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008168
Douglas Gregora16548e2009-08-11 05:31:07 +00008169 if (!getDerived().AlwaysRebuild() &&
8170 T == E->getType() &&
8171 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00008172 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00008173 // Mark the constructor as referenced.
8174 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008175 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00008176 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00008177 }
Mike Stump11289f42009-09-09 15:08:12 +00008178
Douglas Gregordb121ba2009-12-14 16:27:04 +00008179 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8180 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008181 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00008182 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00008183 E->isListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00008184 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00008185 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00008186 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008187}
Mike Stump11289f42009-09-09 15:08:12 +00008188
Douglas Gregora16548e2009-08-11 05:31:07 +00008189/// \brief Transform a C++ temporary-binding expression.
8190///
Douglas Gregor363b1512009-12-24 18:51:59 +00008191/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8192/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008193template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008194ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008195TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008196 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008197}
Mike Stump11289f42009-09-09 15:08:12 +00008198
John McCall5d413782010-12-06 08:20:24 +00008199/// \brief Transform a C++ expression that contains cleanups that should
8200/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00008201///
John McCall5d413782010-12-06 08:20:24 +00008202/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00008203/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008204template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008205ExprResult
John McCall5d413782010-12-06 08:20:24 +00008206TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008207 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008208}
Mike Stump11289f42009-09-09 15:08:12 +00008209
Douglas Gregora16548e2009-08-11 05:31:07 +00008210template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008211ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008212TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00008213 CXXTemporaryObjectExpr *E) {
8214 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8215 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008216 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008217
Douglas Gregora16548e2009-08-11 05:31:07 +00008218 CXXConstructorDecl *Constructor
8219 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00008220 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008221 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008222 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008223 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008224
Douglas Gregora16548e2009-08-11 05:31:07 +00008225 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008226 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00008227 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00008228 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008229 &ArgumentChanged))
8230 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008231
Douglas Gregora16548e2009-08-11 05:31:07 +00008232 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008233 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008234 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008235 !ArgumentChanged) {
8236 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008237 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00008238 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008239 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008240
Richard Smithd59b8322012-12-19 01:39:02 +00008241 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00008242 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8243 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008244 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008245 E->getLocEnd());
8246}
Mike Stump11289f42009-09-09 15:08:12 +00008247
Douglas Gregora16548e2009-08-11 05:31:07 +00008248template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008249ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00008250TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Faisal Vali2b391ab2013-09-26 19:54:12 +00008251
Faisal Vali524ca282013-11-12 01:40:44 +00008252 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
Faisal Vali2cba1332013-10-23 06:44:28 +00008253 // Transform the template parameters, and add them to the current
8254 // instantiation scope. The null case is handled correctly.
8255 LSI->GLTemplateParameterList = getDerived().TransformTemplateParameterList(
8256 E->getTemplateParameterList());
8257
8258 // Check to see if the TypeSourceInfo of the call operator needs to
8259 // be transformed, and if so do the transformation in the
8260 // CurrentInstantiationScope.
8261
8262 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
8263 FunctionProtoTypeLoc OldCallOpFPTL =
8264 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
8265 TypeSourceInfo *NewCallOpTSI = 0;
8266
8267 const bool CallOpWasAlreadyTransformed =
8268 getDerived().AlreadyTransformed(OldCallOpTSI->getType());
8269
8270 // Use the Old Call Operator's TypeSourceInfo if it is already transformed.
8271 if (CallOpWasAlreadyTransformed)
8272 NewCallOpTSI = OldCallOpTSI;
8273 else {
8274 // Transform the TypeSourceInfo of the Original Lambda's Call Operator.
8275 // The transformation MUST be done in the CurrentInstantiationScope since
8276 // it introduces a mapping of the original to the newly created
8277 // transformed parameters.
8278
8279 TypeLocBuilder NewCallOpTLBuilder;
8280 QualType NewCallOpType = TransformFunctionProtoType(NewCallOpTLBuilder,
8281 OldCallOpFPTL,
8282 0, 0);
8283 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
8284 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00008285 }
Faisal Vali2cba1332013-10-23 06:44:28 +00008286 // Extract the ParmVarDecls from the NewCallOpTSI and add them to
8287 // the vector below - this will be used to synthesize the
8288 // NewCallOperator. Additionally, add the parameters of the untransformed
8289 // lambda call operator to the CurrentInstantiationScope.
8290 SmallVector<ParmVarDecl *, 4> Params;
8291 {
8292 FunctionProtoTypeLoc NewCallOpFPTL =
8293 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>();
8294 ParmVarDecl **NewParamDeclArray = NewCallOpFPTL.getParmArray();
8295 const unsigned NewNumArgs = NewCallOpFPTL.getNumArgs();
8296
8297 for (unsigned I = 0; I < NewNumArgs; ++I) {
8298 // If this call operator's type does not require transformation,
8299 // the parameters do not get added to the current instantiation scope,
8300 // - so ADD them! This allows the following to compile when the enclosing
8301 // template is specialized and the entire lambda expression has to be
8302 // transformed.
8303 // template<class T> void foo(T t) {
8304 // auto L = [](auto a) {
8305 // auto M = [](char b) { <-- note: non-generic lambda
8306 // auto N = [](auto c) {
8307 // int x = sizeof(a);
8308 // x = sizeof(b); <-- specifically this line
8309 // x = sizeof(c);
8310 // };
8311 // };
8312 // };
8313 // }
8314 // foo('a')
8315 if (CallOpWasAlreadyTransformed)
8316 getDerived().transformedLocalDecl(NewParamDeclArray[I],
8317 NewParamDeclArray[I]);
8318 // Add to Params array, so these parameters can be used to create
8319 // the newly transformed call operator.
8320 Params.push_back(NewParamDeclArray[I]);
8321 }
8322 }
8323
8324 if (!NewCallOpTSI)
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008325 return ExprError();
8326
Eli Friedmand564afb2012-09-19 01:18:11 +00008327 // Create the local class that will describe the lambda.
8328 CXXRecordDecl *Class
8329 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008330 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00008331 /*KnownDependent=*/false,
8332 E->getCaptureDefault());
8333
Eli Friedmand564afb2012-09-19 01:18:11 +00008334 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8335
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008336 // Build the call operator.
Faisal Vali2cba1332013-10-23 06:44:28 +00008337 CXXMethodDecl *NewCallOperator
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008338 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008339 NewCallOpTSI,
Douglas Gregoradb376e2012-02-14 22:28:59 +00008340 E->getCallOperator()->getLocEnd(),
Richard Smith505df232012-07-22 23:45:10 +00008341 Params);
Faisal Vali2cba1332013-10-23 06:44:28 +00008342 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00008343
Faisal Vali2cba1332013-10-23 06:44:28 +00008344 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
8345
8346 return getDerived().TransformLambdaScope(E, NewCallOperator);
Richard Smith2589b9802012-07-25 03:56:55 +00008347}
8348
8349template<typename Derived>
8350ExprResult
8351TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
8352 CXXMethodDecl *CallOperator) {
Richard Smithba71c082013-05-16 06:20:58 +00008353 bool Invalid = false;
8354
8355 // Transform any init-capture expressions before entering the scope of the
8356 // lambda.
Robert Wilhelmb869a8f2013-08-10 12:33:24 +00008357 SmallVector<ExprResult, 8> InitCaptureExprs;
Richard Smithba71c082013-05-16 06:20:58 +00008358 InitCaptureExprs.resize(E->explicit_capture_end() -
8359 E->explicit_capture_begin());
8360 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8361 CEnd = E->capture_end();
8362 C != CEnd; ++C) {
8363 if (!C->isInitCapture())
8364 continue;
8365 InitCaptureExprs[C - E->capture_begin()] =
Richard Smithbb13c9a2013-09-28 04:02:39 +00008366 getDerived().TransformInitializer(
8367 C->getCapturedVar()->getInit(),
8368 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smithba71c082013-05-16 06:20:58 +00008369 }
8370
Douglas Gregorb4328232012-02-14 00:00:48 +00008371 // Introduce the context of the call operator.
8372 Sema::ContextRAII SavedContext(getSema(), CallOperator);
8373
Faisal Vali2b391ab2013-09-26 19:54:12 +00008374 LambdaScopeInfo *const LSI = getSema().getCurLambda();
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008375 // Enter the scope of the lambda.
Faisal Vali2b391ab2013-09-26 19:54:12 +00008376 getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008377 E->getCaptureDefault(),
James Dennettddd36ff2013-08-09 23:08:25 +00008378 E->getCaptureDefaultLoc(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008379 E->hasExplicitParameters(),
8380 E->hasExplicitResultType(),
8381 E->isMutable());
Chad Rosier1dcde962012-08-08 18:46:20 +00008382
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008383 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008384 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00008385 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008386 CEnd = E->capture_end();
8387 C != CEnd; ++C) {
8388 // When we hit the first implicit capture, tell Sema that we've finished
8389 // the list of explicit captures.
8390 if (!FinishedExplicitCaptures && C->isImplicit()) {
8391 getSema().finishLambdaExplicitCaptures(LSI);
8392 FinishedExplicitCaptures = true;
8393 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008394
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008395 // Capturing 'this' is trivial.
8396 if (C->capturesThis()) {
8397 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8398 continue;
8399 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008400
Richard Smithba71c082013-05-16 06:20:58 +00008401 // Rebuild init-captures, including the implied field declaration.
8402 if (C->isInitCapture()) {
8403 ExprResult Init = InitCaptureExprs[C - E->capture_begin()];
8404 if (Init.isInvalid()) {
8405 Invalid = true;
8406 continue;
8407 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00008408 VarDecl *OldVD = C->getCapturedVar();
8409 VarDecl *NewVD = getSema().checkInitCapture(
8410 C->getLocation(), OldVD->getType()->isReferenceType(),
8411 OldVD->getIdentifier(), Init.take());
8412 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00008413 Invalid = true;
8414 else
Richard Smithbb13c9a2013-09-28 04:02:39 +00008415 getDerived().transformedLocalDecl(OldVD, NewVD);
8416 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00008417 continue;
8418 }
8419
8420 assert(C->capturesVariable() && "unexpected kind of lambda capture");
8421
Douglas Gregor3e308b12012-02-14 19:27:52 +00008422 // Determine the capture kind for Sema.
8423 Sema::TryCaptureKind Kind
8424 = C->isImplicit()? Sema::TryCapture_Implicit
8425 : C->getCaptureKind() == LCK_ByCopy
8426 ? Sema::TryCapture_ExplicitByVal
8427 : Sema::TryCapture_ExplicitByRef;
8428 SourceLocation EllipsisLoc;
8429 if (C->isPackExpansion()) {
8430 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8431 bool ShouldExpand = false;
8432 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008433 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00008434 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8435 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008436 Unexpanded,
8437 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00008438 NumExpansions)) {
8439 Invalid = true;
8440 continue;
8441 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008442
Douglas Gregor3e308b12012-02-14 19:27:52 +00008443 if (ShouldExpand) {
8444 // The transform has determined that we should perform an expansion;
8445 // transform and capture each of the arguments.
8446 // expansion of the pattern. Do so.
8447 VarDecl *Pack = C->getCapturedVar();
8448 for (unsigned I = 0; I != *NumExpansions; ++I) {
8449 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8450 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008451 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008452 Pack));
8453 if (!CapturedVar) {
8454 Invalid = true;
8455 continue;
8456 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008457
Douglas Gregor3e308b12012-02-14 19:27:52 +00008458 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00008459 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8460 }
Douglas Gregor3e308b12012-02-14 19:27:52 +00008461 continue;
8462 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008463
Douglas Gregor3e308b12012-02-14 19:27:52 +00008464 EllipsisLoc = C->getEllipsisLoc();
8465 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008466
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008467 // Transform the captured variable.
8468 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008469 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008470 C->getCapturedVar()));
8471 if (!CapturedVar) {
8472 Invalid = true;
8473 continue;
8474 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008475
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008476 // Capture the transformed variable.
Douglas Gregorfdf598e2012-02-18 09:37:24 +00008477 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008478 }
8479 if (!FinishedExplicitCaptures)
8480 getSema().finishLambdaExplicitCaptures(LSI);
8481
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008482
8483 // Enter a new evaluation context to insulate the lambda from any
8484 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00008485 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008486
8487 if (Invalid) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008488 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008489 /*IsInstantiation=*/true);
8490 return ExprError();
8491 }
8492
8493 // Instantiate the body of the lambda expression.
Douglas Gregorb4328232012-02-14 00:00:48 +00008494 StmtResult Body = getDerived().TransformStmt(E->getBody());
8495 if (Body.isInvalid()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008496 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregorb4328232012-02-14 00:00:48 +00008497 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00008498 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00008499 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00008500
Chad Rosier1dcde962012-08-08 18:46:20 +00008501 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorb61e8092012-04-04 17:40:10 +00008502 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregore31e6062012-02-07 10:09:13 +00008503}
8504
8505template<typename Derived>
8506ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008507TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008508 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00008509 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8510 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008511 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008512
Douglas Gregora16548e2009-08-11 05:31:07 +00008513 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008514 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00008515 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00008516 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008517 &ArgumentChanged))
8518 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008519
Douglas Gregora16548e2009-08-11 05:31:07 +00008520 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008521 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008522 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00008523 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00008524
Douglas Gregora16548e2009-08-11 05:31:07 +00008525 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00008526 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00008527 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008528 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008529 E->getRParenLoc());
8530}
Mike Stump11289f42009-09-09 15:08:12 +00008531
Douglas Gregora16548e2009-08-11 05:31:07 +00008532template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008533ExprResult
John McCall8cd78132009-11-19 22:55:06 +00008534TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008535 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008536 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00008537 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00008538 Expr *OldBase;
8539 QualType BaseType;
8540 QualType ObjectType;
8541 if (!E->isImplicitAccess()) {
8542 OldBase = E->getBase();
8543 Base = getDerived().TransformExpr(OldBase);
8544 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008545 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008546
John McCall2d74de92009-12-01 22:10:20 +00008547 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00008548 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00008549 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00008550 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008551 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008552 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00008553 ObjectTy,
8554 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00008555 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008556 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00008557
John McCallba7bf592010-08-24 05:47:05 +00008558 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00008559 BaseType = ((Expr*) Base.get())->getType();
8560 } else {
8561 OldBase = 0;
8562 BaseType = getDerived().TransformType(E->getBaseType());
8563 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8564 }
Mike Stump11289f42009-09-09 15:08:12 +00008565
Douglas Gregora5cb6da2009-10-20 05:58:46 +00008566 // Transform the first part of the nested-name-specifier that qualifies
8567 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00008568 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00008569 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00008570 E->getFirstQualifierFoundInScope(),
8571 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00008572
Douglas Gregore16af532011-02-28 18:50:33 +00008573 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008574 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00008575 QualifierLoc
8576 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8577 ObjectType,
8578 FirstQualifierInScope);
8579 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008580 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008581 }
Mike Stump11289f42009-09-09 15:08:12 +00008582
Abramo Bagnara7945c982012-01-27 09:46:47 +00008583 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8584
John McCall31f82722010-11-12 08:19:04 +00008585 // TODO: If this is a conversion-function-id, verify that the
8586 // destination type name (if present) resolves the same way after
8587 // instantiation as it did in the local scope.
8588
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008589 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00008590 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008591 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008592 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008593
John McCall2d74de92009-12-01 22:10:20 +00008594 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00008595 // This is a reference to a member without an explicitly-specified
8596 // template argument list. Optimize for this common case.
8597 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00008598 Base.get() == OldBase &&
8599 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00008600 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008601 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00008602 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00008603 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00008604
John McCallb268a282010-08-23 23:25:46 +00008605 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008606 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00008607 E->isArrow(),
8608 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00008609 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008610 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00008611 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008612 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00008613 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00008614 }
8615
John McCall6b51f282009-11-23 01:53:49 +00008616 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008617 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8618 E->getNumTemplateArgs(),
8619 TransArgs))
8620 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008621
John McCallb268a282010-08-23 23:25:46 +00008622 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008623 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00008624 E->isArrow(),
8625 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00008626 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008627 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00008628 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008629 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00008630 &TransArgs);
8631}
8632
8633template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008634ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008635TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00008636 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00008637 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00008638 QualType BaseType;
8639 if (!Old->isImplicitAccess()) {
8640 Base = getDerived().TransformExpr(Old->getBase());
8641 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008642 return ExprError();
Richard Smithcab9a7d2011-10-26 19:06:56 +00008643 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8644 Old->isArrow());
8645 if (Base.isInvalid())
8646 return ExprError();
8647 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +00008648 } else {
8649 BaseType = getDerived().TransformType(Old->getBaseType());
8650 }
John McCall10eae182009-11-30 22:42:35 +00008651
Douglas Gregor0da1d432011-02-28 20:01:57 +00008652 NestedNameSpecifierLoc QualifierLoc;
8653 if (Old->getQualifierLoc()) {
8654 QualifierLoc
8655 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8656 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008657 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00008658 }
8659
Abramo Bagnara7945c982012-01-27 09:46:47 +00008660 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8661
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008662 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00008663 Sema::LookupOrdinaryName);
8664
8665 // Transform all the decls.
8666 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8667 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008668 NamedDecl *InstD = static_cast<NamedDecl*>(
8669 getDerived().TransformDecl(Old->getMemberLoc(),
8670 *I));
John McCall84d87672009-12-10 09:41:52 +00008671 if (!InstD) {
8672 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8673 // This can happen because of dependent hiding.
8674 if (isa<UsingShadowDecl>(*I))
8675 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00008676 else {
8677 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008678 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00008679 }
John McCall84d87672009-12-10 09:41:52 +00008680 }
John McCall10eae182009-11-30 22:42:35 +00008681
8682 // Expand using declarations.
8683 if (isa<UsingDecl>(InstD)) {
8684 UsingDecl *UD = cast<UsingDecl>(InstD);
8685 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8686 E = UD->shadow_end(); I != E; ++I)
8687 R.addDecl(*I);
8688 continue;
8689 }
8690
8691 R.addDecl(InstD);
8692 }
8693
8694 R.resolveKind();
8695
Douglas Gregor9262f472010-04-27 18:19:34 +00008696 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00008697 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008698 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00008699 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00008700 Old->getMemberLoc(),
8701 Old->getNamingClass()));
8702 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00008703 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008704
Douglas Gregorda7be082010-04-27 16:10:10 +00008705 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00008706 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008707
John McCall10eae182009-11-30 22:42:35 +00008708 TemplateArgumentListInfo TransArgs;
8709 if (Old->hasExplicitTemplateArgs()) {
8710 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8711 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008712 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8713 Old->getNumTemplateArgs(),
8714 TransArgs))
8715 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00008716 }
John McCall38836f02010-01-15 08:34:02 +00008717
8718 // FIXME: to do this check properly, we will need to preserve the
8719 // first-qualifier-in-scope here, just in case we had a dependent
8720 // base (and therefore couldn't do the check) and a
8721 // nested-name-qualifier (and therefore could do the lookup).
8722 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00008723
John McCallb268a282010-08-23 23:25:46 +00008724 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008725 BaseType,
John McCall10eae182009-11-30 22:42:35 +00008726 Old->getOperatorLoc(),
8727 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00008728 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008729 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +00008730 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00008731 R,
8732 (Old->hasExplicitTemplateArgs()
8733 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00008734}
8735
8736template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008737ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008738TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00008739 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008740 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8741 if (SubExpr.isInvalid())
8742 return ExprError();
8743
8744 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00008745 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008746
8747 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8748}
8749
8750template<typename Derived>
8751ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008752TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00008753 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8754 if (Pattern.isInvalid())
8755 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008756
Douglas Gregor0f836ea2011-01-13 00:19:55 +00008757 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8758 return SemaRef.Owned(E);
8759
Douglas Gregorb8840002011-01-14 21:20:45 +00008760 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8761 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008762}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008763
8764template<typename Derived>
8765ExprResult
8766TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8767 // If E is not value-dependent, then nothing will change when we transform it.
8768 // Note: This is an instantiation-centric view.
8769 if (!E->isValueDependent())
8770 return SemaRef.Owned(E);
8771
8772 // Note: None of the implementations of TryExpandParameterPacks can ever
8773 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00008774 // so
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008775 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8776 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00008777 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008778 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00008779 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +00008780 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00008781 ShouldExpand, RetainExpansion,
8782 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008783 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008784
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008785 if (RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008786 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00008787
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008788 NamedDecl *Pack = E->getPack();
8789 if (!ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008790 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008791 Pack));
8792 if (!Pack)
8793 return ExprError();
8794 }
8795
Chad Rosier1dcde962012-08-08 18:46:20 +00008796
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008797 // We now know the length of the parameter pack, so build a new expression
8798 // that stores that length.
Chad Rosier1dcde962012-08-08 18:46:20 +00008799 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8800 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008801 NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008802}
8803
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008804template<typename Derived>
8805ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00008806TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8807 SubstNonTypeTemplateParmPackExpr *E) {
8808 // Default behavior is to do nothing with this transformation.
8809 return SemaRef.Owned(E);
8810}
8811
8812template<typename Derived>
8813ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00008814TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8815 SubstNonTypeTemplateParmExpr *E) {
8816 // Default behavior is to do nothing with this transformation.
8817 return SemaRef.Owned(E);
8818}
8819
8820template<typename Derived>
8821ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +00008822TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8823 // Default behavior is to do nothing with this transformation.
8824 return SemaRef.Owned(E);
8825}
8826
8827template<typename Derived>
8828ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00008829TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8830 MaterializeTemporaryExpr *E) {
8831 return getDerived().TransformExpr(E->GetTemporaryExpr());
8832}
Chad Rosier1dcde962012-08-08 18:46:20 +00008833
Douglas Gregorfe314812011-06-21 17:03:29 +00008834template<typename Derived>
8835ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +00008836TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
8837 CXXStdInitializerListExpr *E) {
8838 return getDerived().TransformExpr(E->getSubExpr());
8839}
8840
8841template<typename Derived>
8842ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008843TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00008844 return SemaRef.MaybeBindToTemporary(E);
8845}
8846
8847template<typename Derived>
8848ExprResult
8849TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rose8986c5992012-03-12 17:53:02 +00008850 return SemaRef.Owned(E);
Ted Kremeneke65b0862012-03-06 20:05:56 +00008851}
8852
8853template<typename Derived>
8854ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +00008855TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8856 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8857 if (SubExpr.isInvalid())
8858 return ExprError();
8859
8860 if (!getDerived().AlwaysRebuild() &&
8861 SubExpr.get() == E->getSubExpr())
8862 return SemaRef.Owned(E);
8863
8864 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +00008865}
8866
8867template<typename Derived>
8868ExprResult
8869TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8870 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008871 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00008872 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00008873 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00008874 /*IsCall=*/false, Elements, &ArgChanged))
8875 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008876
Ted Kremeneke65b0862012-03-06 20:05:56 +00008877 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8878 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00008879
Ted Kremeneke65b0862012-03-06 20:05:56 +00008880 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8881 Elements.data(),
8882 Elements.size());
8883}
8884
8885template<typename Derived>
8886ExprResult
8887TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +00008888 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00008889 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008890 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00008891 bool ArgChanged = false;
8892 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8893 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +00008894
Ted Kremeneke65b0862012-03-06 20:05:56 +00008895 if (OrigElement.isPackExpansion()) {
8896 // This key/value element is a pack expansion.
8897 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8898 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8899 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8900 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8901
8902 // Determine whether the set of unexpanded parameter packs can
8903 // and should be expanded.
8904 bool Expand = true;
8905 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008906 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8907 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +00008908 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8909 OrigElement.Value->getLocEnd());
8910 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8911 PatternRange,
8912 Unexpanded,
8913 Expand, RetainExpansion,
8914 NumExpansions))
8915 return ExprError();
8916
8917 if (!Expand) {
8918 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00008919 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +00008920 // expansion.
8921 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8922 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8923 if (Key.isInvalid())
8924 return ExprError();
8925
8926 if (Key.get() != OrigElement.Key)
8927 ArgChanged = true;
8928
8929 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8930 if (Value.isInvalid())
8931 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008932
Ted Kremeneke65b0862012-03-06 20:05:56 +00008933 if (Value.get() != OrigElement.Value)
8934 ArgChanged = true;
8935
Chad Rosier1dcde962012-08-08 18:46:20 +00008936 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00008937 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8938 };
8939 Elements.push_back(Expansion);
8940 continue;
8941 }
8942
8943 // Record right away that the argument was changed. This needs
8944 // to happen even if the array expands to nothing.
8945 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00008946
Ted Kremeneke65b0862012-03-06 20:05:56 +00008947 // The transform has determined that we should perform an elementwise
8948 // expansion of the pattern. Do so.
8949 for (unsigned I = 0; I != *NumExpansions; ++I) {
8950 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8951 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8952 if (Key.isInvalid())
8953 return ExprError();
8954
8955 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8956 if (Value.isInvalid())
8957 return ExprError();
8958
Chad Rosier1dcde962012-08-08 18:46:20 +00008959 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00008960 Key.get(), Value.get(), SourceLocation(), NumExpansions
8961 };
8962
8963 // If any unexpanded parameter packs remain, we still have a
8964 // pack expansion.
8965 if (Key.get()->containsUnexpandedParameterPack() ||
8966 Value.get()->containsUnexpandedParameterPack())
8967 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +00008968
Ted Kremeneke65b0862012-03-06 20:05:56 +00008969 Elements.push_back(Element);
8970 }
8971
8972 // We've finished with this pack expansion.
8973 continue;
8974 }
8975
8976 // Transform and check key.
8977 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8978 if (Key.isInvalid())
8979 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008980
Ted Kremeneke65b0862012-03-06 20:05:56 +00008981 if (Key.get() != OrigElement.Key)
8982 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00008983
Ted Kremeneke65b0862012-03-06 20:05:56 +00008984 // Transform and check value.
8985 ExprResult Value
8986 = getDerived().TransformExpr(OrigElement.Value);
8987 if (Value.isInvalid())
8988 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008989
Ted Kremeneke65b0862012-03-06 20:05:56 +00008990 if (Value.get() != OrigElement.Value)
8991 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00008992
8993 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +00008994 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +00008995 };
8996 Elements.push_back(Element);
8997 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008998
Ted Kremeneke65b0862012-03-06 20:05:56 +00008999 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9000 return SemaRef.MaybeBindToTemporary(E);
9001
9002 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
9003 Elements.data(),
9004 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +00009005}
9006
Mike Stump11289f42009-09-09 15:08:12 +00009007template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009008ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009009TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00009010 TypeSourceInfo *EncodedTypeInfo
9011 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
9012 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009013 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009014
Douglas Gregora16548e2009-08-11 05:31:07 +00009015 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00009016 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00009017 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009018
9019 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00009020 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009021 E->getRParenLoc());
9022}
Mike Stump11289f42009-09-09 15:08:12 +00009023
Douglas Gregora16548e2009-08-11 05:31:07 +00009024template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +00009025ExprResult TreeTransform<Derived>::
9026TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +00009027 // This is a kind of implicit conversion, and it needs to get dropped
9028 // and recomputed for the same general reasons that ImplicitCastExprs
9029 // do, as well a more specific one: this expression is only valid when
9030 // it appears *immediately* as an argument expression.
9031 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +00009032}
9033
9034template<typename Derived>
9035ExprResult TreeTransform<Derived>::
9036TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009037 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +00009038 = getDerived().TransformType(E->getTypeInfoAsWritten());
9039 if (!TSInfo)
9040 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009041
John McCall31168b02011-06-15 23:02:42 +00009042 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +00009043 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +00009044 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009045
John McCall31168b02011-06-15 23:02:42 +00009046 if (!getDerived().AlwaysRebuild() &&
9047 TSInfo == E->getTypeInfoAsWritten() &&
9048 Result.get() == E->getSubExpr())
9049 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009050
John McCall31168b02011-06-15 23:02:42 +00009051 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +00009052 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +00009053 Result.get());
9054}
9055
9056template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009057ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009058TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009059 // Transform arguments.
9060 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009061 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009062 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009063 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009064 &ArgChanged))
9065 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009066
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009067 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
9068 // Class message: transform the receiver type.
9069 TypeSourceInfo *ReceiverTypeInfo
9070 = getDerived().TransformType(E->getClassReceiverTypeInfo());
9071 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009072 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009073
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009074 // If nothing changed, just retain the existing message send.
9075 if (!getDerived().AlwaysRebuild() &&
9076 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009077 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009078
9079 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009080 SmallVector<SourceLocation, 16> SelLocs;
9081 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009082 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
9083 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009084 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009085 E->getMethodDecl(),
9086 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009087 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009088 E->getRightLoc());
9089 }
9090
9091 // Instance message: transform the receiver
9092 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
9093 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00009094 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009095 = getDerived().TransformExpr(E->getInstanceReceiver());
9096 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009097 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009098
9099 // If nothing changed, just retain the existing message send.
9100 if (!getDerived().AlwaysRebuild() &&
9101 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009102 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009103
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009104 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009105 SmallVector<SourceLocation, 16> SelLocs;
9106 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +00009107 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009108 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009109 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009110 E->getMethodDecl(),
9111 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009112 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009113 E->getRightLoc());
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>::TransformObjCSelectorExpr(ObjCSelectorExpr *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>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00009125 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009126}
9127
Mike Stump11289f42009-09-09 15:08:12 +00009128template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009129ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009130TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009131 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009132 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009133 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009134 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00009135
9136 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009137
Douglas Gregord51d90d2010-04-26 20:11:03 +00009138 // If nothing changed, just retain the existing expression.
9139 if (!getDerived().AlwaysRebuild() &&
9140 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00009141 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009142
John McCallb268a282010-08-23 23:25:46 +00009143 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009144 E->getLocation(),
9145 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00009146}
9147
Mike Stump11289f42009-09-09 15:08:12 +00009148template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009149ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009150TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00009151 // 'super' and types never change. Property never changes. Just
9152 // retain the existing expression.
9153 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00009154 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009155
Douglas Gregor9faee212010-04-26 20:47:02 +00009156 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009157 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00009158 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009159 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009160
Douglas Gregor9faee212010-04-26 20:47:02 +00009161 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009162
Douglas Gregor9faee212010-04-26 20:47:02 +00009163 // If nothing changed, just retain the existing expression.
9164 if (!getDerived().AlwaysRebuild() &&
9165 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00009166 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009167
John McCallb7bd14f2010-12-02 01:19:52 +00009168 if (E->isExplicitProperty())
9169 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9170 E->getExplicitProperty(),
9171 E->getLocation());
9172
9173 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +00009174 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +00009175 E->getImplicitPropertyGetter(),
9176 E->getImplicitPropertySetter(),
9177 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00009178}
9179
Mike Stump11289f42009-09-09 15:08:12 +00009180template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009181ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +00009182TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
9183 // Transform the base expression.
9184 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9185 if (Base.isInvalid())
9186 return ExprError();
9187
9188 // Transform the key expression.
9189 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
9190 if (Key.isInvalid())
9191 return ExprError();
9192
9193 // If nothing changed, just retain the existing expression.
9194 if (!getDerived().AlwaysRebuild() &&
9195 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
9196 return SemaRef.Owned(E);
9197
Chad Rosier1dcde962012-08-08 18:46:20 +00009198 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009199 Base.get(), Key.get(),
9200 E->getAtIndexMethodDecl(),
9201 E->setAtIndexMethodDecl());
9202}
9203
9204template<typename Derived>
9205ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009206TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009207 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009208 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009209 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009210 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009211
Douglas Gregord51d90d2010-04-26 20:11:03 +00009212 // If nothing changed, just retain the existing expression.
9213 if (!getDerived().AlwaysRebuild() &&
9214 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00009215 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009216
John McCallb268a282010-08-23 23:25:46 +00009217 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00009218 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009219 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00009220}
9221
Mike Stump11289f42009-09-09 15:08:12 +00009222template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009223ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009224TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009225 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009226 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +00009227 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009228 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00009229 SubExprs, &ArgumentChanged))
9230 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009231
Douglas Gregora16548e2009-08-11 05:31:07 +00009232 if (!getDerived().AlwaysRebuild() &&
9233 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00009234 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00009235
Douglas Gregora16548e2009-08-11 05:31:07 +00009236 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009237 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009238 E->getRParenLoc());
9239}
9240
Mike Stump11289f42009-09-09 15:08:12 +00009241template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009242ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +00009243TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
9244 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
9245 if (SrcExpr.isInvalid())
9246 return ExprError();
9247
9248 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9249 if (!Type)
9250 return ExprError();
9251
9252 if (!getDerived().AlwaysRebuild() &&
9253 Type == E->getTypeSourceInfo() &&
9254 SrcExpr.get() == E->getSrcExpr())
9255 return SemaRef.Owned(E);
9256
9257 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
9258 SrcExpr.get(), Type,
9259 E->getRParenLoc());
9260}
9261
9262template<typename Derived>
9263ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009264TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00009265 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +00009266
John McCall490112f2011-02-04 18:33:18 +00009267 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
9268 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
9269
9270 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +00009271 blockScope->TheDecl->setBlockMissingReturnType(
9272 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +00009273
Chris Lattner01cf8db2011-07-20 06:58:45 +00009274 SmallVector<ParmVarDecl*, 4> params;
9275 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +00009276
Fariborz Jahanian1babe772010-07-09 18:44:02 +00009277 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00009278 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
9279 oldBlock->param_begin(),
9280 oldBlock->param_size(),
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009281 0, paramTypes, &params)) {
9282 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009283 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009284 }
John McCall490112f2011-02-04 18:33:18 +00009285
Jordan Rosea0a86be2013-03-08 22:25:36 +00009286 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +00009287 QualType exprResultType =
9288 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregor476e3022011-01-19 21:32:01 +00009289
Jordan Rose5c382722013-03-08 21:51:21 +00009290 QualType functionType =
9291 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009292 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +00009293 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00009294
9295 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00009296 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +00009297 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +00009298
9299 if (!oldBlock->blockMissingReturnType()) {
9300 blockScope->HasImplicitReturnType = false;
9301 blockScope->ReturnType = exprResultType;
9302 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009303
John McCall3882ace2011-01-05 12:14:39 +00009304 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00009305 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009306 if (body.isInvalid()) {
9307 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall3882ace2011-01-05 12:14:39 +00009308 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009309 }
John McCall3882ace2011-01-05 12:14:39 +00009310
John McCall490112f2011-02-04 18:33:18 +00009311#ifndef NDEBUG
9312 // In builds with assertions, make sure that we captured everything we
9313 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009314 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
9315 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
9316 e = oldBlock->capture_end(); i != e; ++i) {
9317 VarDecl *oldCapture = i->getVariable();
John McCall490112f2011-02-04 18:33:18 +00009318
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009319 // Ignore parameter packs.
9320 if (isa<ParmVarDecl>(oldCapture) &&
9321 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9322 continue;
John McCall490112f2011-02-04 18:33:18 +00009323
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009324 VarDecl *newCapture =
9325 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9326 oldCapture));
9327 assert(blockScope->CaptureMap.count(newCapture));
9328 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009329 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +00009330 }
9331#endif
9332
9333 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
9334 /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00009335}
9336
Mike Stump11289f42009-09-09 15:08:12 +00009337template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009338ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +00009339TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +00009340 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +00009341}
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009342
9343template<typename Derived>
9344ExprResult
9345TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009346 QualType RetTy = getDerived().TransformType(E->getType());
9347 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009348 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009349 SubExprs.reserve(E->getNumSubExprs());
9350 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9351 SubExprs, &ArgumentChanged))
9352 return ExprError();
9353
9354 if (!getDerived().AlwaysRebuild() &&
9355 !ArgumentChanged)
9356 return SemaRef.Owned(E);
9357
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009358 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009359 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009360}
Chad Rosier1dcde962012-08-08 18:46:20 +00009361
Douglas Gregora16548e2009-08-11 05:31:07 +00009362//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00009363// Type reconstruction
9364//===----------------------------------------------------------------------===//
9365
Mike Stump11289f42009-09-09 15:08:12 +00009366template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009367QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9368 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009369 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009370 getDerived().getBaseEntity());
9371}
9372
Mike Stump11289f42009-09-09 15:08:12 +00009373template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009374QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9375 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009376 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009377 getDerived().getBaseEntity());
9378}
9379
Mike Stump11289f42009-09-09 15:08:12 +00009380template<typename Derived>
9381QualType
John McCall70dd5f62009-10-30 00:06:24 +00009382TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9383 bool WrittenAsLValue,
9384 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00009385 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00009386 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009387}
9388
9389template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009390QualType
John McCall70dd5f62009-10-30 00:06:24 +00009391TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9392 QualType ClassType,
9393 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00009394 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00009395 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009396}
9397
9398template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009399QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00009400TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9401 ArrayType::ArraySizeModifier SizeMod,
9402 const llvm::APInt *Size,
9403 Expr *SizeExpr,
9404 unsigned IndexTypeQuals,
9405 SourceRange BracketsRange) {
9406 if (SizeExpr || !Size)
9407 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9408 IndexTypeQuals, BracketsRange,
9409 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00009410
9411 QualType Types[] = {
9412 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9413 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9414 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00009415 };
Craig Toppere5ce8312013-07-15 03:38:40 +00009416 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009417 QualType SizeType;
9418 for (unsigned I = 0; I != NumTypes; ++I)
9419 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9420 SizeType = Types[I];
9421 break;
9422 }
Mike Stump11289f42009-09-09 15:08:12 +00009423
Eli Friedman9562f392012-01-25 23:20:27 +00009424 // Note that we can return a VariableArrayType here in the case where
9425 // the element type was a dependent VariableArrayType.
9426 IntegerLiteral *ArraySize
9427 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9428 /*FIXME*/BracketsRange.getBegin());
9429 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009430 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00009431 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009432}
Mike Stump11289f42009-09-09 15:08:12 +00009433
Douglas Gregord6ff3322009-08-04 16:50:30 +00009434template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009435QualType
9436TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009437 ArrayType::ArraySizeModifier SizeMod,
9438 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00009439 unsigned IndexTypeQuals,
9440 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009441 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00009442 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009443}
9444
9445template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009446QualType
Mike Stump11289f42009-09-09 15:08:12 +00009447TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009448 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00009449 unsigned IndexTypeQuals,
9450 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009451 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00009452 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009453}
Mike Stump11289f42009-09-09 15:08:12 +00009454
Douglas Gregord6ff3322009-08-04 16:50:30 +00009455template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009456QualType
9457TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009458 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009459 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009460 unsigned IndexTypeQuals,
9461 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009462 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00009463 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009464 IndexTypeQuals, BracketsRange);
9465}
9466
9467template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009468QualType
9469TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009470 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009471 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009472 unsigned IndexTypeQuals,
9473 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009474 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00009475 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009476 IndexTypeQuals, BracketsRange);
9477}
9478
9479template<typename Derived>
9480QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00009481 unsigned NumElements,
9482 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00009483 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00009484 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009485}
Mike Stump11289f42009-09-09 15:08:12 +00009486
Douglas Gregord6ff3322009-08-04 16:50:30 +00009487template<typename Derived>
9488QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9489 unsigned NumElements,
9490 SourceLocation AttributeLoc) {
9491 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9492 NumElements, true);
9493 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00009494 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9495 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00009496 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009497}
Mike Stump11289f42009-09-09 15:08:12 +00009498
Douglas Gregord6ff3322009-08-04 16:50:30 +00009499template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009500QualType
9501TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00009502 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009503 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00009504 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009505}
Mike Stump11289f42009-09-09 15:08:12 +00009506
Douglas Gregord6ff3322009-08-04 16:50:30 +00009507template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +00009508QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9509 QualType T,
9510 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009511 const FunctionProtoType::ExtProtoInfo &EPI) {
9512 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009513 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00009514 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +00009515 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009516}
Mike Stump11289f42009-09-09 15:08:12 +00009517
Douglas Gregord6ff3322009-08-04 16:50:30 +00009518template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00009519QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9520 return SemaRef.Context.getFunctionNoProtoType(T);
9521}
9522
9523template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00009524QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9525 assert(D && "no decl found");
9526 if (D->isInvalidDecl()) return QualType();
9527
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009528 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00009529 TypeDecl *Ty;
9530 if (isa<UsingDecl>(D)) {
9531 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +00009532 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +00009533 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9534
9535 // A valid resolved using typename decl points to exactly one type decl.
9536 assert(++Using->shadow_begin() == Using->shadow_end());
9537 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00009538
John McCallb96ec562009-12-04 22:46:56 +00009539 } else {
9540 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9541 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9542 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9543 }
9544
9545 return SemaRef.Context.getTypeDeclType(Ty);
9546}
9547
9548template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00009549QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9550 SourceLocation Loc) {
9551 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009552}
9553
9554template<typename Derived>
9555QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9556 return SemaRef.Context.getTypeOfType(Underlying);
9557}
9558
9559template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00009560QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9561 SourceLocation Loc) {
9562 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009563}
9564
9565template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00009566QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9567 UnaryTransformType::UTTKind UKind,
9568 SourceLocation Loc) {
9569 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9570}
9571
9572template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00009573QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00009574 TemplateName Template,
9575 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +00009576 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +00009577 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009578}
Mike Stump11289f42009-09-09 15:08:12 +00009579
Douglas Gregor1135c352009-08-06 05:28:30 +00009580template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +00009581QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9582 SourceLocation KWLoc) {
9583 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9584}
9585
9586template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009587TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009588TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00009589 bool TemplateKW,
9590 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +00009591 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00009592 Template);
9593}
9594
9595template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009596TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009597TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9598 const IdentifierInfo &Name,
9599 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00009600 QualType ObjectType,
9601 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +00009602 UnqualifiedId TemplateName;
9603 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +00009604 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +00009605 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +00009606 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009607 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +00009608 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00009609 /*EnteringContext=*/false,
9610 Template);
John McCall31f82722010-11-12 08:19:04 +00009611 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00009612}
Mike Stump11289f42009-09-09 15:08:12 +00009613
Douglas Gregora16548e2009-08-11 05:31:07 +00009614template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00009615TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009616TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00009617 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00009618 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00009619 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +00009620 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +00009621 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +00009622 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +00009623 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +00009624 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +00009625 Sema::TemplateTy Template;
9626 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009627 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +00009628 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00009629 /*EnteringContext=*/false,
9630 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +00009631 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +00009632}
Chad Rosier1dcde962012-08-08 18:46:20 +00009633
Douglas Gregor71395fa2009-11-04 00:56:37 +00009634template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009635ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009636TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9637 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00009638 Expr *OrigCallee,
9639 Expr *First,
9640 Expr *Second) {
9641 Expr *Callee = OrigCallee->IgnoreParenCasts();
9642 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00009643
Douglas Gregora16548e2009-08-11 05:31:07 +00009644 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00009645 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00009646 if (!First->getType()->isOverloadableType() &&
9647 !Second->getType()->isOverloadableType())
9648 return getSema().CreateBuiltinArraySubscriptExpr(First,
9649 Callee->getLocStart(),
9650 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00009651 } else if (Op == OO_Arrow) {
9652 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00009653 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9654 } else if (Second == 0 || isPostIncDec) {
9655 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009656 // The argument is not of overloadable type, so try to create a
9657 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00009658 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00009659 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00009660
John McCallb268a282010-08-23 23:25:46 +00009661 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00009662 }
9663 } else {
John McCallb268a282010-08-23 23:25:46 +00009664 if (!First->getType()->isOverloadableType() &&
9665 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009666 // Neither of the arguments is an overloadable type, so try to
9667 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00009668 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00009669 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00009670 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00009671 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009672 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009673
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009674 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00009675 }
9676 }
Mike Stump11289f42009-09-09 15:08:12 +00009677
9678 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00009679 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00009680 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00009681
John McCallb268a282010-08-23 23:25:46 +00009682 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00009683 assert(ULE->requiresADL());
9684
9685 // FIXME: Do we have to check
9686 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00009687 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00009688 } else {
Richard Smith58db83d2012-11-28 21:47:39 +00009689 // If we've resolved this to a particular non-member function, just call
9690 // that function. If we resolved it to a member function,
9691 // CreateOverloaded* will find that function for us.
9692 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9693 if (!isa<CXXMethodDecl>(ND))
9694 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +00009695 }
Mike Stump11289f42009-09-09 15:08:12 +00009696
Douglas Gregora16548e2009-08-11 05:31:07 +00009697 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00009698 Expr *Args[2] = { First, Second };
9699 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00009700
Douglas Gregora16548e2009-08-11 05:31:07 +00009701 // Create the overloaded operator invocation for unary operators.
9702 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00009703 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00009704 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00009705 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00009706 }
Mike Stump11289f42009-09-09 15:08:12 +00009707
Douglas Gregore9d62932011-07-15 16:25:15 +00009708 if (Op == OO_Subscript) {
9709 SourceLocation LBrace;
9710 SourceLocation RBrace;
9711
9712 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9713 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9714 LBrace = SourceLocation::getFromRawEncoding(
9715 NameLoc.CXXOperatorName.BeginOpNameLoc);
9716 RBrace = SourceLocation::getFromRawEncoding(
9717 NameLoc.CXXOperatorName.EndOpNameLoc);
9718 } else {
9719 LBrace = Callee->getLocStart();
9720 RBrace = OpLoc;
9721 }
9722
9723 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9724 First, Second);
9725 }
Sebastian Redladba46e2009-10-29 20:17:01 +00009726
Douglas Gregora16548e2009-08-11 05:31:07 +00009727 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00009728 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00009729 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00009730 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9731 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009732 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009733
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009734 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00009735}
Mike Stump11289f42009-09-09 15:08:12 +00009736
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009737template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00009738ExprResult
John McCallb268a282010-08-23 23:25:46 +00009739TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009740 SourceLocation OperatorLoc,
9741 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +00009742 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009743 TypeSourceInfo *ScopeType,
9744 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009745 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009746 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +00009747 QualType BaseType = Base->getType();
9748 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009749 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +00009750 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00009751 !BaseType->getAs<PointerType>()->getPointeeType()
9752 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009753 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00009754 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009755 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009756 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009757 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009758 /*FIXME?*/true);
9759 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009760
Douglas Gregor678f90d2010-02-25 01:56:36 +00009761 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009762 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9763 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9764 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9765 NameInfo.setNamedTypeInfo(DestroyedType);
9766
Richard Smith8e4a3862012-05-15 06:15:11 +00009767 // The scope type is now known to be a valid nested name specifier
9768 // component. Tack it on to the end of the nested name specifier.
9769 if (ScopeType)
9770 SS.Extend(SemaRef.Context, SourceLocation(),
9771 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009772
Abramo Bagnara7945c982012-01-27 09:46:47 +00009773 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +00009774 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009775 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009776 SS, TemplateKWLoc,
9777 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009778 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009779 /*TemplateArgs*/ 0);
9780}
9781
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00009782template<typename Derived>
9783StmtResult
9784TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +00009785 SourceLocation Loc = S->getLocStart();
9786 unsigned NumParams = S->getCapturedDecl()->getNumParams();
9787 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/0,
9788 S->getCapturedRegionKind(), NumParams);
9789 StmtResult Body = getDerived().TransformStmt(S->getCapturedStmt());
9790
9791 if (Body.isInvalid()) {
9792 getSema().ActOnCapturedRegionError();
9793 return StmtError();
9794 }
9795
9796 return getSema().ActOnCapturedRegionEnd(Body.take());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00009797}
9798
Douglas Gregord6ff3322009-08-04 16:50:30 +00009799} // end namespace clang
9800
9801#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H