blob: 5d2124f7ce6cd7c1961b75120cbd572b46118db9 [file] [log] [blame]
Chris Lattnercab02a62011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnercab02a62011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00008//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
Chris Lattnercab02a62011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Douglas Gregord6ff3322009-08-04 16:50:30 +000014#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_SEMA_TREETRANSFORM_H
16
Chandler Carruth3a022472012-12-04 09:13:33 +000017#include "TypeLocBuilder.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000018#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000019#include "clang/AST/DeclObjC.h"
Richard Smith3f1b5d02011-05-05 21:57:07 +000020#include "clang/AST/DeclTemplate.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000021#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000022#include "clang/AST/ExprCXX.h"
23#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000024#include "clang/AST/Stmt.h"
25#include "clang/AST/StmtCXX.h"
26#include "clang/AST/StmtObjC.h"
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000027#include "clang/AST/StmtOpenMP.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000028#include "clang/Lex/Preprocessor.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000029#include "clang/Sema/Designator.h"
30#include "clang/Sema/Lookup.h"
31#include "clang/Sema/Ownership.h"
32#include "clang/Sema/ParsedTemplate.h"
33#include "clang/Sema/ScopeInfo.h"
34#include "clang/Sema/SemaDiagnostic.h"
35#include "clang/Sema/SemaInternal.h"
David Blaikieb9c168a2011-09-22 02:34:54 +000036#include "llvm/ADT/ArrayRef.h"
John McCall550e0c22009-10-21 00:40:46 +000037#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000038#include <algorithm>
39
40namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000041using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000042
Douglas Gregord6ff3322009-08-04 16:50:30 +000043/// \brief A semantic tree transformation that allows one to transform one
44/// abstract syntax tree into another.
45///
Mike Stump11289f42009-09-09 15:08:12 +000046/// A new tree transformation is defined by creating a new subclass \c X of
47/// \c TreeTransform<X> and then overriding certain operations to provide
48/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000049/// instantiation is implemented as a tree transformation where the
50/// transformation of TemplateTypeParmType nodes involves substituting the
51/// template arguments for their corresponding template parameters; a similar
52/// transformation is performed for non-type template parameters and
53/// template template parameters.
54///
55/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000056/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000057/// override any of the transformation or rebuild operators by providing an
58/// operation with the same signature as the default implementation. The
59/// overridding function should not be virtual.
60///
61/// Semantic tree transformations are split into two stages, either of which
62/// can be replaced by a subclass. The "transform" step transforms an AST node
63/// or the parts of an AST node using the various transformation functions,
64/// then passes the pieces on to the "rebuild" step, which constructs a new AST
65/// node of the appropriate kind from the pieces. The default transformation
66/// routines recursively transform the operands to composite AST nodes (e.g.,
67/// the pointee type of a PointerType node) and, if any of those operand nodes
68/// were changed by the transformation, invokes the rebuild operation to create
69/// a new AST node.
70///
Mike Stump11289f42009-09-09 15:08:12 +000071/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000072/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregorfd35cde2011-03-02 18:50:38 +000073/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000074/// TransformTemplateName(), or TransformTemplateArgument() with entirely
75/// new implementations.
76///
77/// For more fine-grained transformations, subclasses can replace any of the
78/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000079/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000080/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000081/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000082/// parameters. Additionally, subclasses can override the \c RebuildXXX
83/// functions to control how AST nodes are rebuilt when their operands change.
84/// By default, \c TreeTransform will invoke semantic analysis to rebuild
85/// AST nodes. However, certain other tree transformations (e.g, cloning) may
86/// be able to use more efficient rebuild steps.
87///
88/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000089/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000090/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
91/// operands have not changed (\c AlwaysRebuild()), and customize the
92/// default locations and entity names used for type-checking
93/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000094template<typename Derived>
95class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000096 /// \brief Private RAII object that helps us forget and then re-remember
97 /// the template argument corresponding to a partially-substituted parameter
98 /// pack.
99 class ForgetPartiallySubstitutedPackRAII {
100 Derived &Self;
101 TemplateArgument Old;
Chad Rosier1dcde962012-08-08 18:46:20 +0000102
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000103 public:
104 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
105 Old = Self.ForgetPartiallySubstitutedPack();
106 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000107
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000108 ~ForgetPartiallySubstitutedPackRAII() {
109 Self.RememberPartiallySubstitutedPack(Old);
110 }
111 };
Chad Rosier1dcde962012-08-08 18:46:20 +0000112
Douglas Gregord6ff3322009-08-04 16:50:30 +0000113protected:
114 Sema &SemaRef;
Chad Rosier1dcde962012-08-08 18:46:20 +0000115
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000116 /// \brief The set of local declarations that have been transformed, for
117 /// cases where we are forced to build new declarations within the transformer
118 /// rather than in the subclass (e.g., lambda closure types).
119 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
Chad Rosier1dcde962012-08-08 18:46:20 +0000120
Mike Stump11289f42009-09-09 15:08:12 +0000121public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000122 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000123 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000124
Douglas Gregord6ff3322009-08-04 16:50:30 +0000125 /// \brief Retrieves a reference to the derived class.
126 Derived &getDerived() { return static_cast<Derived&>(*this); }
127
128 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000129 const Derived &getDerived() const {
130 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000131 }
132
John McCalldadc5752010-08-24 06:29:42 +0000133 static inline ExprResult Owned(Expr *E) { return E; }
134 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000135
Douglas Gregord6ff3322009-08-04 16:50:30 +0000136 /// \brief Retrieves a reference to the semantic analysis object used for
137 /// this tree transform.
138 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000139
Douglas Gregord6ff3322009-08-04 16:50:30 +0000140 /// \brief Whether the transformation should always rebuild AST nodes, even
141 /// if none of the children have changed.
142 ///
143 /// Subclasses may override this function to specify when the transformation
144 /// should rebuild all AST nodes.
Richard Smith2aa81a72013-11-07 20:07:17 +0000145 ///
146 /// We must always rebuild all AST nodes when performing variadic template
147 /// pack expansion, in order to avoid violating the AST invariant that each
148 /// statement node appears at most once in its containing declaration.
149 bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; }
Mike Stump11289f42009-09-09 15:08:12 +0000150
Douglas Gregord6ff3322009-08-04 16:50:30 +0000151 /// \brief Returns the location of the entity being transformed, if that
152 /// information was not available elsewhere in the AST.
153 ///
Mike Stump11289f42009-09-09 15:08:12 +0000154 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000155 /// provide an alternative implementation that provides better location
156 /// information.
157 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000158
Douglas Gregord6ff3322009-08-04 16:50:30 +0000159 /// \brief Returns the name of the entity being transformed, if that
160 /// information was not available elsewhere in the AST.
161 ///
162 /// By default, returns an empty name. Subclasses can provide an alternative
163 /// implementation with a more precise name.
164 DeclarationName getBaseEntity() { return DeclarationName(); }
165
Douglas Gregora16548e2009-08-11 05:31:07 +0000166 /// \brief Sets the "base" location and entity when that
167 /// information is known based on another transformation.
168 ///
169 /// By default, the source location and entity are ignored. Subclasses can
170 /// override this function to provide a customized implementation.
171 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000172
Douglas Gregora16548e2009-08-11 05:31:07 +0000173 /// \brief RAII object that temporarily sets the base location and entity
174 /// used for reporting diagnostics in types.
175 class TemporaryBase {
176 TreeTransform &Self;
177 SourceLocation OldLocation;
178 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000179
Douglas Gregora16548e2009-08-11 05:31:07 +0000180 public:
181 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000182 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000183 OldLocation = Self.getDerived().getBaseLocation();
184 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier1dcde962012-08-08 18:46:20 +0000185
Douglas Gregora518d5b2011-01-25 17:51:48 +0000186 if (Location.isValid())
187 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000188 }
Mike Stump11289f42009-09-09 15:08:12 +0000189
Douglas Gregora16548e2009-08-11 05:31:07 +0000190 ~TemporaryBase() {
191 Self.getDerived().setBase(OldLocation, OldEntity);
192 }
193 };
Mike Stump11289f42009-09-09 15:08:12 +0000194
195 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000196 /// transformed.
197 ///
198 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000199 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000200 /// not change. For example, template instantiation need not traverse
201 /// non-dependent types.
202 bool AlreadyTransformed(QualType T) {
203 return T.isNull();
204 }
205
Douglas Gregord196a582009-12-14 19:27:10 +0000206 /// \brief Determine whether the given call argument should be dropped, e.g.,
207 /// because it is a default argument.
208 ///
209 /// Subclasses can provide an alternative implementation of this routine to
210 /// determine which kinds of call arguments get dropped. By default,
211 /// CXXDefaultArgument nodes are dropped (prior to transformation).
212 bool DropCallArgument(Expr *E) {
213 return E->isDefaultArgument();
214 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000215
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000216 /// \brief Determine whether we should expand a pack expansion with the
217 /// given set of parameter packs into separate arguments by repeatedly
218 /// transforming the pattern.
219 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000220 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000221 /// Subclasses can override this routine to provide different behavior.
222 ///
223 /// \param EllipsisLoc The location of the ellipsis that identifies the
224 /// pack expansion.
225 ///
226 /// \param PatternRange The source range that covers the entire pattern of
227 /// the pack expansion.
228 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000229 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000230 /// pattern.
231 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000232 /// \param ShouldExpand Will be set to \c true if the transformer should
233 /// expand the corresponding pack expansions into separate arguments. When
234 /// set, \c NumExpansions must also be set.
235 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000236 /// \param RetainExpansion Whether the caller should add an unexpanded
237 /// pack expansion after all of the expanded arguments. This is used
238 /// when extending explicitly-specified template argument packs per
239 /// C++0x [temp.arg.explicit]p9.
240 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000241 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000242 /// the expanded form of the corresponding pack expansion. This is both an
243 /// input and an output parameter, which can be set by the caller if the
244 /// number of expansions is known a priori (e.g., due to a prior substitution)
245 /// and will be set by the callee when the number of expansions is known.
246 /// The callee must set this value when \c ShouldExpand is \c true; it may
247 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000248 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000249 /// \returns true if an error occurred (e.g., because the parameter packs
250 /// are to be instantiated with arguments of different lengths), false
251 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000252 /// must be set.
253 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
254 SourceRange PatternRange,
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000255 ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000256 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000257 bool &RetainExpansion,
David Blaikie05785d12013-02-20 22:23:23 +0000258 Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000259 ShouldExpand = false;
260 return false;
261 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000262
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000263 /// \brief "Forget" about the partially-substituted pack template argument,
264 /// when performing an instantiation that must preserve the parameter pack
265 /// use.
266 ///
267 /// This routine is meant to be overridden by the template instantiator.
268 TemplateArgument ForgetPartiallySubstitutedPack() {
269 return TemplateArgument();
270 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000271
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000272 /// \brief "Remember" the partially-substituted pack template argument
273 /// after performing an instantiation that must preserve the parameter pack
274 /// use.
275 ///
276 /// This routine is meant to be overridden by the template instantiator.
277 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000278
Douglas Gregorf3010112011-01-07 16:43:16 +0000279 /// \brief Note to the derived class when a function parameter pack is
280 /// being expanded.
281 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000282
Douglas Gregord6ff3322009-08-04 16:50:30 +0000283 /// \brief Transforms the given type into another type.
284 ///
John McCall550e0c22009-10-21 00:40:46 +0000285 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000286 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000287 /// function. This is expensive, but we don't mind, because
288 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000289 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000290 ///
291 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000292 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000293
John McCall550e0c22009-10-21 00:40:46 +0000294 /// \brief Transforms the given type-with-location into a new
295 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000296 ///
John McCall550e0c22009-10-21 00:40:46 +0000297 /// By default, this routine transforms a type by delegating to the
298 /// appropriate TransformXXXType to build a new type. Subclasses
299 /// may override this function (to take over all type
300 /// transformations) or some set of the TransformXXXType functions
301 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000302 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000303
304 /// \brief Transform the given type-with-location into a new
305 /// type, collecting location information in the given builder
306 /// as necessary.
307 ///
John McCall31f82722010-11-12 08:19:04 +0000308 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000309
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000310 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000311 ///
Mike Stump11289f42009-09-09 15:08:12 +0000312 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000313 /// appropriate TransformXXXStmt function to transform a specific kind of
314 /// statement or the TransformExpr() function to transform an expression.
315 /// Subclasses may override this function to transform statements using some
316 /// other mechanism.
317 ///
318 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000319 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000320
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000321 /// \brief Transform the given statement.
322 ///
323 /// By default, this routine transforms a statement by delegating to the
324 /// appropriate TransformOMPXXXClause function to transform a specific kind
325 /// of clause. Subclasses may override this function to transform statements
326 /// using some other mechanism.
327 ///
328 /// \returns the transformed OpenMP clause.
329 OMPClause *TransformOMPClause(OMPClause *S);
330
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000331 /// \brief Transform the given expression.
332 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000333 /// By default, this routine transforms an expression by delegating to the
334 /// appropriate TransformXXXExpr function to build a new expression.
335 /// Subclasses may override this function to transform expressions using some
336 /// other mechanism.
337 ///
338 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000339 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000340
Richard Smithd59b8322012-12-19 01:39:02 +0000341 /// \brief Transform the given initializer.
342 ///
343 /// By default, this routine transforms an initializer by stripping off the
344 /// semantic nodes added by initialization, then passing the result to
345 /// TransformExpr or TransformExprs.
346 ///
347 /// \returns the transformed initializer.
348 ExprResult TransformInitializer(Expr *Init, bool CXXDirectInit);
349
Douglas Gregora3efea12011-01-03 19:04:46 +0000350 /// \brief Transform the given list of expressions.
351 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000352 /// This routine transforms a list of expressions by invoking
353 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregora3efea12011-01-03 19:04:46 +0000354 /// support for variadic templates by expanding any pack expansions (if the
355 /// derived class permits such expansion) along the way. When pack expansions
356 /// are present, the number of outputs may not equal the number of inputs.
357 ///
358 /// \param Inputs The set of expressions to be transformed.
359 ///
360 /// \param NumInputs The number of expressions in \c Inputs.
361 ///
362 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier1dcde962012-08-08 18:46:20 +0000363 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregora3efea12011-01-03 19:04:46 +0000364 /// be.
365 ///
366 /// \param Outputs The transformed input expressions will be added to this
367 /// vector.
368 ///
369 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
370 /// due to transformation.
371 ///
372 /// \returns true if an error occurred, false otherwise.
373 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000374 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +0000375 bool *ArgChanged = 0);
Chad Rosier1dcde962012-08-08 18:46:20 +0000376
Douglas Gregord6ff3322009-08-04 16:50:30 +0000377 /// \brief Transform the given declaration, which is referenced from a type
378 /// or expression.
379 ///
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000380 /// By default, acts as the identity function on declarations, unless the
381 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregor1135c352009-08-06 05:28:30 +0000382 /// may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000383 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000384 llvm::DenseMap<Decl *, Decl *>::iterator Known
385 = TransformedLocalDecls.find(D);
386 if (Known != TransformedLocalDecls.end())
387 return Known->second;
Chad Rosier1dcde962012-08-08 18:46:20 +0000388
389 return D;
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000390 }
Douglas Gregorebe10102009-08-20 07:17:43 +0000391
Chad Rosier1dcde962012-08-08 18:46:20 +0000392 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000393 /// place them on the new declaration.
394 ///
395 /// By default, this operation does nothing. Subclasses may override this
396 /// behavior to transform attributes.
397 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000398
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000399 /// \brief Note that a local declaration has been transformed by this
400 /// transformer.
401 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000402 /// Local declarations are typically transformed via a call to
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000403 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
404 /// the transformer itself has to transform the declarations. This routine
405 /// can be overridden by a subclass that keeps track of such mappings.
406 void transformedLocalDecl(Decl *Old, Decl *New) {
407 TransformedLocalDecls[Old] = New;
408 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000409
Douglas Gregorebe10102009-08-20 07:17:43 +0000410 /// \brief Transform the definition of the given declaration.
411 ///
Mike Stump11289f42009-09-09 15:08:12 +0000412 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000413 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000414 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
415 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000416 }
Mike Stump11289f42009-09-09 15:08:12 +0000417
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000418 /// \brief Transform the given declaration, which was the first part of a
419 /// nested-name-specifier in a member access expression.
420 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000421 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000422 /// identifier in a nested-name-specifier of a member access expression, e.g.,
423 /// the \c T in \c x->T::member
424 ///
425 /// By default, invokes TransformDecl() to transform the declaration.
426 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000427 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
428 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000429 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000430
Douglas Gregor14454802011-02-25 02:25:35 +0000431 /// \brief Transform the given nested-name-specifier with source-location
432 /// information.
433 ///
434 /// By default, transforms all of the types and declarations within the
435 /// nested-name-specifier. Subclasses may override this function to provide
436 /// alternate behavior.
437 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
438 NestedNameSpecifierLoc NNS,
439 QualType ObjectType = QualType(),
440 NamedDecl *FirstQualifierInScope = 0);
441
Douglas Gregorf816bd72009-09-03 22:13:48 +0000442 /// \brief Transform the given declaration name.
443 ///
444 /// By default, transforms the types of conversion function, constructor,
445 /// and destructor names and then (if needed) rebuilds the declaration name.
446 /// Identifiers and selectors are returned unmodified. Sublcasses may
447 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000448 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000449 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000450
Douglas Gregord6ff3322009-08-04 16:50:30 +0000451 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000452 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000453 /// \param SS The nested-name-specifier that qualifies the template
454 /// name. This nested-name-specifier must already have been transformed.
455 ///
456 /// \param Name The template name to transform.
457 ///
458 /// \param NameLoc The source location of the template name.
459 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000460 /// \param ObjectType If we're translating a template name within a member
Douglas Gregor9db53502011-03-02 18:07:45 +0000461 /// access expression, this is the type of the object whose member template
462 /// is being referenced.
463 ///
464 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
465 /// also refers to a name within the current (lexical) scope, this is the
466 /// declaration it refers to.
467 ///
468 /// By default, transforms the template name by transforming the declarations
469 /// and nested-name-specifiers that occur within the template name.
470 /// Subclasses may override this function to provide alternate behavior.
471 TemplateName TransformTemplateName(CXXScopeSpec &SS,
472 TemplateName Name,
Abramo Bagnara7945c982012-01-27 09:46:47 +0000473 SourceLocation NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +0000474 QualType ObjectType = QualType(),
475 NamedDecl *FirstQualifierInScope = 0);
476
Douglas Gregord6ff3322009-08-04 16:50:30 +0000477 /// \brief Transform the given template argument.
478 ///
Mike Stump11289f42009-09-09 15:08:12 +0000479 /// By default, this operation transforms the type, expression, or
480 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000481 /// new template argument from the transformed result. Subclasses may
482 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000483 ///
484 /// Returns true if there was an error.
485 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
486 TemplateArgumentLoc &Output);
487
Douglas Gregor62e06f22010-12-20 17:31:10 +0000488 /// \brief Transform the given set of template arguments.
489 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000490 /// By default, this operation transforms all of the template arguments
Douglas Gregor62e06f22010-12-20 17:31:10 +0000491 /// in the input set using \c TransformTemplateArgument(), and appends
492 /// the transformed arguments to the output list.
493 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000494 /// Note that this overload of \c TransformTemplateArguments() is merely
495 /// a convenience function. Subclasses that wish to override this behavior
496 /// should override the iterator-based member template version.
497 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000498 /// \param Inputs The set of template arguments to be transformed.
499 ///
500 /// \param NumInputs The number of template arguments in \p Inputs.
501 ///
502 /// \param Outputs The set of transformed template arguments output by this
503 /// routine.
504 ///
505 /// Returns true if an error occurred.
506 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
507 unsigned NumInputs,
Douglas Gregorfe921a72010-12-20 23:36:19 +0000508 TemplateArgumentListInfo &Outputs) {
509 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
510 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000511
512 /// \brief Transform the given set of template arguments.
513 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000514 /// By default, this operation transforms all of the template arguments
Douglas Gregor42cafa82010-12-20 17:42:22 +0000515 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier1dcde962012-08-08 18:46:20 +0000516 /// the transformed arguments to the output list.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000517 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000518 /// \param First An iterator to the first template argument.
519 ///
520 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000521 ///
522 /// \param Outputs The set of transformed template arguments output by this
523 /// routine.
524 ///
525 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000526 template<typename InputIterator>
527 bool TransformTemplateArguments(InputIterator First,
528 InputIterator Last,
529 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000530
John McCall0ad16662009-10-29 08:12:44 +0000531 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
532 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
533 TemplateArgumentLoc &ArgLoc);
534
John McCallbcd03502009-12-07 02:54:59 +0000535 /// \brief Fakes up a TypeSourceInfo for a type.
536 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
537 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000538 getDerived().getBaseLocation());
539 }
Mike Stump11289f42009-09-09 15:08:12 +0000540
John McCall550e0c22009-10-21 00:40:46 +0000541#define ABSTRACT_TYPELOC(CLASS, PARENT)
542#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000543 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000544#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000545
Douglas Gregor3024f072012-04-16 07:05:22 +0000546 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
547 FunctionProtoTypeLoc TL,
548 CXXRecordDecl *ThisContext,
549 unsigned ThisTypeQuals);
550
David Majnemerfad8f482013-10-15 09:33:02 +0000551 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000552
Chad Rosier1dcde962012-08-08 18:46:20 +0000553 QualType
John McCall31f82722010-11-12 08:19:04 +0000554 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
555 TemplateSpecializationTypeLoc TL,
556 TemplateName Template);
557
Chad Rosier1dcde962012-08-08 18:46:20 +0000558 QualType
John McCall31f82722010-11-12 08:19:04 +0000559 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
560 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000561 TemplateName Template,
562 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000563
Chad Rosier1dcde962012-08-08 18:46:20 +0000564 QualType
Douglas Gregor5a064722011-02-28 17:23:35 +0000565 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000566 DependentTemplateSpecializationTypeLoc TL,
567 NestedNameSpecifierLoc QualifierLoc);
568
John McCall58f10c32010-03-11 09:03:00 +0000569 /// \brief Transforms the parameters of a function type into the
570 /// given vectors.
571 ///
572 /// The result vectors should be kept in sync; null entries in the
573 /// variables vector are acceptable.
574 ///
575 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000576 bool TransformFunctionTypeParams(SourceLocation Loc,
577 ParmVarDecl **Params, unsigned NumParams,
578 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000579 SmallVectorImpl<QualType> &PTypes,
580 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000581
582 /// \brief Transforms a single function-type parameter. Return null
583 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000584 ///
585 /// \param indexAdjustment - A number to add to the parameter's
586 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000587 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000588 int indexAdjustment,
David Blaikie05785d12013-02-20 22:23:23 +0000589 Optional<unsigned> NumExpansions,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +0000590 bool ExpectParameterPack);
John McCall58f10c32010-03-11 09:03:00 +0000591
John McCall31f82722010-11-12 08:19:04 +0000592 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000593
John McCalldadc5752010-08-24 06:29:42 +0000594 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
595 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +0000596
597 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Richard Smith2589b9802012-07-25 03:56:55 +0000598 /// \brief Transform the captures and body of a lambda expression.
Faisal Vali5fb7c3c2013-12-05 01:40:41 +0000599 ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator,
600 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +0000601
Faisal Vali2cba1332013-10-23 06:44:28 +0000602 TemplateParameterList *TransformTemplateParameterList(
603 TemplateParameterList *TPL) {
604 return TPL;
605 }
606
Richard Smithdb2630f2012-10-21 03:28:35 +0000607 ExprResult TransformAddressOfOperand(Expr *E);
608 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
609 bool IsAddressOfOperand);
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000610 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000611
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000612// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
613// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000614#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000615 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000616 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000617#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000618 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000619 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000620#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000621#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000622
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000623#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000624 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000625 OMPClause *Transform ## Class(Class *S);
626#include "clang/Basic/OpenMPKinds.def"
627
Douglas Gregord6ff3322009-08-04 16:50:30 +0000628 /// \brief Build a new pointer type given its pointee type.
629 ///
630 /// By default, performs semantic analysis when building the pointer type.
631 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000632 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000633
634 /// \brief Build a new block pointer type given its pointee type.
635 ///
Mike Stump11289f42009-09-09 15:08:12 +0000636 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000637 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000638 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000639
John McCall70dd5f62009-10-30 00:06:24 +0000640 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000641 ///
John McCall70dd5f62009-10-30 00:06:24 +0000642 /// By default, performs semantic analysis when building the
643 /// reference type. Subclasses may override this routine to provide
644 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000645 ///
John McCall70dd5f62009-10-30 00:06:24 +0000646 /// \param LValue whether the type was written with an lvalue sigil
647 /// or an rvalue sigil.
648 QualType RebuildReferenceType(QualType ReferentType,
649 bool LValue,
650 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000651
Douglas Gregord6ff3322009-08-04 16:50:30 +0000652 /// \brief Build a new member pointer type given the pointee type and the
653 /// class type it refers into.
654 ///
655 /// By default, performs semantic analysis when building the member pointer
656 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000657 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
658 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000659
Douglas Gregord6ff3322009-08-04 16:50:30 +0000660 /// \brief Build a new array type given the element type, size
661 /// modifier, size of the array (if known), size expression, and index type
662 /// qualifiers.
663 ///
664 /// By default, performs semantic analysis when building the array type.
665 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000666 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000667 QualType RebuildArrayType(QualType ElementType,
668 ArrayType::ArraySizeModifier SizeMod,
669 const llvm::APInt *Size,
670 Expr *SizeExpr,
671 unsigned IndexTypeQuals,
672 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000673
Douglas Gregord6ff3322009-08-04 16:50:30 +0000674 /// \brief Build a new constant array type given the element type, size
675 /// modifier, (known) size of the array, and index type qualifiers.
676 ///
677 /// By default, performs semantic analysis when building the array type.
678 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000679 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000680 ArrayType::ArraySizeModifier SizeMod,
681 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000682 unsigned IndexTypeQuals,
683 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000684
Douglas Gregord6ff3322009-08-04 16:50:30 +0000685 /// \brief Build a new incomplete array type given the element type, size
686 /// modifier, and index type qualifiers.
687 ///
688 /// By default, performs semantic analysis when building the array type.
689 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000690 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000691 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000692 unsigned IndexTypeQuals,
693 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000694
Mike Stump11289f42009-09-09 15:08:12 +0000695 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000696 /// size modifier, size expression, and index type qualifiers.
697 ///
698 /// By default, performs semantic analysis when building the array type.
699 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000700 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000701 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000702 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000703 unsigned IndexTypeQuals,
704 SourceRange BracketsRange);
705
Mike Stump11289f42009-09-09 15:08:12 +0000706 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000707 /// size modifier, size expression, and index type qualifiers.
708 ///
709 /// By default, performs semantic analysis when building the array type.
710 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000711 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000712 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000713 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000714 unsigned IndexTypeQuals,
715 SourceRange BracketsRange);
716
717 /// \brief Build a new vector type given the element type and
718 /// number of elements.
719 ///
720 /// By default, performs semantic analysis when building the vector type.
721 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000722 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000723 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000724
Douglas Gregord6ff3322009-08-04 16:50:30 +0000725 /// \brief Build a new extended vector type given the element type and
726 /// number of elements.
727 ///
728 /// By default, performs semantic analysis when building the vector type.
729 /// Subclasses may override this routine to provide different behavior.
730 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
731 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000732
733 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000734 /// given the element type and number of elements.
735 ///
736 /// By default, performs semantic analysis when building the vector type.
737 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000738 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000739 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000740 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000741
Douglas Gregord6ff3322009-08-04 16:50:30 +0000742 /// \brief Build a new function type.
743 ///
744 /// By default, performs semantic analysis when building the function type.
745 /// Subclasses may override this routine to provide different behavior.
746 QualType RebuildFunctionProtoType(QualType T,
Jordan Rose5c382722013-03-08 21:51:21 +0000747 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000748 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000749
John McCall550e0c22009-10-21 00:40:46 +0000750 /// \brief Build a new unprototyped function type.
751 QualType RebuildFunctionNoProtoType(QualType ResultType);
752
John McCallb96ec562009-12-04 22:46:56 +0000753 /// \brief Rebuild an unresolved typename type, given the decl that
754 /// the UnresolvedUsingTypenameDecl was transformed to.
755 QualType RebuildUnresolvedUsingType(Decl *D);
756
Douglas Gregord6ff3322009-08-04 16:50:30 +0000757 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000758 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000759 return SemaRef.Context.getTypeDeclType(Typedef);
760 }
761
762 /// \brief Build a new class/struct/union type.
763 QualType RebuildRecordType(RecordDecl *Record) {
764 return SemaRef.Context.getTypeDeclType(Record);
765 }
766
767 /// \brief Build a new Enum type.
768 QualType RebuildEnumType(EnumDecl *Enum) {
769 return SemaRef.Context.getTypeDeclType(Enum);
770 }
John McCallfcc33b02009-09-05 00:15:47 +0000771
Mike Stump11289f42009-09-09 15:08:12 +0000772 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000773 ///
774 /// By default, performs semantic analysis when building the typeof type.
775 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000776 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000777
Mike Stump11289f42009-09-09 15:08:12 +0000778 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000779 ///
780 /// By default, builds a new TypeOfType with the given underlying type.
781 QualType RebuildTypeOfType(QualType Underlying);
782
Alexis Hunte852b102011-05-24 22:41:36 +0000783 /// \brief Build a new unary transform type.
784 QualType RebuildUnaryTransformType(QualType BaseType,
785 UnaryTransformType::UTTKind UKind,
786 SourceLocation Loc);
787
Richard Smith74aeef52013-04-26 16:15:35 +0000788 /// \brief Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000789 ///
790 /// By default, performs semantic analysis when building the decltype type.
791 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000792 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000793
Richard Smith74aeef52013-04-26 16:15:35 +0000794 /// \brief Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000795 ///
796 /// By default, builds a new AutoType with the given deduced type.
Richard Smith74aeef52013-04-26 16:15:35 +0000797 QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) {
Richard Smith27d807c2013-04-30 13:56:41 +0000798 // Note, IsDependent is always false here: we implicitly convert an 'auto'
799 // which has been deduced to a dependent type into an undeduced 'auto', so
800 // that we'll retry deduction after the transformation.
Faisal Vali2b391ab2013-09-26 19:54:12 +0000801 return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto,
802 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000803 }
804
Douglas Gregord6ff3322009-08-04 16:50:30 +0000805 /// \brief Build a new template specialization type.
806 ///
807 /// By default, performs semantic analysis when building the template
808 /// specialization type. Subclasses may override this routine to provide
809 /// different behavior.
810 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000811 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000812 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000813
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000814 /// \brief Build a new parenthesized type.
815 ///
816 /// By default, builds a new ParenType type from the inner type.
817 /// Subclasses may override this routine to provide different behavior.
818 QualType RebuildParenType(QualType InnerType) {
819 return SemaRef.Context.getParenType(InnerType);
820 }
821
Douglas Gregord6ff3322009-08-04 16:50:30 +0000822 /// \brief Build a new qualified name type.
823 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000824 /// By default, builds a new ElaboratedType type from the keyword,
825 /// the nested-name-specifier and the named type.
826 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000827 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
828 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000829 NestedNameSpecifierLoc QualifierLoc,
830 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000831 return SemaRef.Context.getElaboratedType(Keyword,
832 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000833 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000834 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000835
836 /// \brief Build a new typename type that refers to a template-id.
837 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000838 /// By default, builds a new DependentNameType type from the
839 /// nested-name-specifier and the given type. Subclasses may override
840 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000841 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000842 ElaboratedTypeKeyword Keyword,
843 NestedNameSpecifierLoc QualifierLoc,
844 const IdentifierInfo *Name,
845 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000846 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000847 // Rebuild the template name.
848 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000849 CXXScopeSpec SS;
850 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +0000851 TemplateName InstName
Douglas Gregor9db53502011-03-02 18:07:45 +0000852 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Chad Rosier1dcde962012-08-08 18:46:20 +0000853
Douglas Gregora7a795b2011-03-01 20:11:18 +0000854 if (InstName.isNull())
855 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000856
Douglas Gregora7a795b2011-03-01 20:11:18 +0000857 // If it's still dependent, make a dependent specialization.
858 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000859 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
860 QualifierLoc.getNestedNameSpecifier(),
861 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000862 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000863
Douglas Gregora7a795b2011-03-01 20:11:18 +0000864 // Otherwise, make an elaborated type wrapping a non-dependent
865 // specialization.
866 QualType T =
867 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
868 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000869
Douglas Gregora7a795b2011-03-01 20:11:18 +0000870 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
871 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +0000872
873 return SemaRef.Context.getElaboratedType(Keyword,
874 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +0000875 T);
876 }
877
Douglas Gregord6ff3322009-08-04 16:50:30 +0000878 /// \brief Build a new typename type that refers to an identifier.
879 ///
880 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000881 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000882 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000883 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000884 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000885 NestedNameSpecifierLoc QualifierLoc,
886 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000887 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000888 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000889 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000890
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000891 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000892 // If the name is still dependent, just build a new dependent name type.
893 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +0000894 return SemaRef.Context.getDependentNameType(Keyword,
895 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000896 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000897 }
898
Abramo Bagnara6150c882010-05-11 21:36:43 +0000899 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000900 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000901 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000902
903 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
904
Abramo Bagnarad7548482010-05-19 21:37:53 +0000905 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000906 // into a non-dependent elaborated-type-specifier. Find the tag we're
907 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000908 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000909 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
910 if (!DC)
911 return QualType();
912
John McCallbf8c5192010-05-27 06:40:31 +0000913 if (SemaRef.RequireCompleteDeclContext(SS, DC))
914 return QualType();
915
Douglas Gregore677daf2010-03-31 22:19:08 +0000916 TagDecl *Tag = 0;
917 SemaRef.LookupQualifiedName(Result, DC);
918 switch (Result.getResultKind()) {
919 case LookupResult::NotFound:
920 case LookupResult::NotFoundInCurrentInstantiation:
921 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000922
Douglas Gregore677daf2010-03-31 22:19:08 +0000923 case LookupResult::Found:
924 Tag = Result.getAsSingle<TagDecl>();
925 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000926
Douglas Gregore677daf2010-03-31 22:19:08 +0000927 case LookupResult::FoundOverloaded:
928 case LookupResult::FoundUnresolvedValue:
929 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +0000930
Douglas Gregore677daf2010-03-31 22:19:08 +0000931 case LookupResult::Ambiguous:
932 // Let the LookupResult structure handle ambiguities.
933 return QualType();
934 }
935
936 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000937 // Check where the name exists but isn't a tag type and use that to emit
938 // better diagnostics.
939 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
940 SemaRef.LookupQualifiedName(Result, DC);
941 switch (Result.getResultKind()) {
942 case LookupResult::Found:
943 case LookupResult::FoundOverloaded:
944 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +0000945 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky0c438082011-01-24 19:01:04 +0000946 unsigned Kind = 0;
947 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smithdda56e42011-04-15 14:24:37 +0000948 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
949 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky0c438082011-01-24 19:01:04 +0000950 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
951 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
952 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +0000953 }
Nick Lewycky0c438082011-01-24 19:01:04 +0000954 default:
955 // FIXME: Would be nice to highlight just the source range.
956 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
957 << Kind << Id << DC;
958 break;
959 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000960 return QualType();
961 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000962
Richard Trieucaa33d32011-06-10 03:11:26 +0000963 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
964 IdLoc, *Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +0000965 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000966 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
967 return QualType();
968 }
969
970 // Build the elaborated-type-specifier type.
971 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +0000972 return SemaRef.Context.getElaboratedType(Keyword,
973 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000974 T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000975 }
Mike Stump11289f42009-09-09 15:08:12 +0000976
Douglas Gregor822d0302011-01-12 17:07:58 +0000977 /// \brief Build a new pack expansion type.
978 ///
979 /// By default, builds a new PackExpansionType type from the given pattern.
980 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000981 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +0000982 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000983 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +0000984 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000985 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
986 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +0000987 }
988
Eli Friedman0dfb8892011-10-06 23:00:33 +0000989 /// \brief Build a new atomic type given its value type.
990 ///
991 /// By default, performs semantic analysis when building the atomic type.
992 /// Subclasses may override this routine to provide different behavior.
993 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
994
Douglas Gregor71dc5092009-08-06 06:41:21 +0000995 /// \brief Build a new template name given a nested name specifier, a flag
996 /// indicating whether the "template" keyword was provided, and the template
997 /// that the template name refers to.
998 ///
999 /// By default, builds the new template name directly. Subclasses may override
1000 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001001 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001002 bool TemplateKW,
1003 TemplateDecl *Template);
1004
Douglas Gregor71dc5092009-08-06 06:41:21 +00001005 /// \brief Build a new template name given a nested name specifier and the
1006 /// name that is referred to as a template.
1007 ///
1008 /// By default, performs semantic analysis to determine whether the name can
1009 /// be resolved to a specific template, then builds the appropriate kind of
1010 /// template name. Subclasses may override this routine to provide different
1011 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001012 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1013 const IdentifierInfo &Name,
1014 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00001015 QualType ObjectType,
1016 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001017
Douglas Gregor71395fa2009-11-04 00:56:37 +00001018 /// \brief Build a new template name given a nested name specifier and the
1019 /// overloaded operator name that is referred to as a template.
1020 ///
1021 /// By default, performs semantic analysis to determine whether the name can
1022 /// be resolved to a specific template, then builds the appropriate kind of
1023 /// template name. Subclasses may override this routine to provide different
1024 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001025 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001026 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00001027 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001028 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +00001029
1030 /// \brief Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001031 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001032 ///
1033 /// By default, performs semantic analysis to determine whether the name can
1034 /// be resolved to a specific template, then builds the appropriate kind of
1035 /// template name. Subclasses may override this routine to provide different
1036 /// behavior.
1037 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1038 const TemplateArgument &ArgPack) {
1039 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1040 }
1041
Douglas Gregorebe10102009-08-20 07:17:43 +00001042 /// \brief Build a new compound statement.
1043 ///
1044 /// By default, performs semantic analysis to build the new statement.
1045 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001046 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001047 MultiStmtArg Statements,
1048 SourceLocation RBraceLoc,
1049 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001050 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001051 IsStmtExpr);
1052 }
1053
1054 /// \brief Build a new case statement.
1055 ///
1056 /// By default, performs semantic analysis to build the new statement.
1057 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001058 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001059 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001060 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001061 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001062 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001063 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001064 ColonLoc);
1065 }
Mike Stump11289f42009-09-09 15:08:12 +00001066
Douglas Gregorebe10102009-08-20 07:17:43 +00001067 /// \brief Attach the body to a new case statement.
1068 ///
1069 /// By default, performs semantic analysis to build the new statement.
1070 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001071 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001072 getSema().ActOnCaseStmtBody(S, Body);
1073 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001074 }
Mike Stump11289f42009-09-09 15:08:12 +00001075
Douglas Gregorebe10102009-08-20 07:17:43 +00001076 /// \brief Build a new default statement.
1077 ///
1078 /// By default, performs semantic analysis to build the new statement.
1079 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001080 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001081 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001082 Stmt *SubStmt) {
1083 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +00001084 /*CurScope=*/0);
1085 }
Mike Stump11289f42009-09-09 15:08:12 +00001086
Douglas Gregorebe10102009-08-20 07:17:43 +00001087 /// \brief Build a new label statement.
1088 ///
1089 /// By default, performs semantic analysis to build the new statement.
1090 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001091 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1092 SourceLocation ColonLoc, Stmt *SubStmt) {
1093 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001094 }
Mike Stump11289f42009-09-09 15:08:12 +00001095
Richard Smithc202b282012-04-14 00:33:13 +00001096 /// \brief Build a new label statement.
1097 ///
1098 /// By default, performs semantic analysis to build the new statement.
1099 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001100 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1101 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001102 Stmt *SubStmt) {
1103 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1104 }
1105
Douglas Gregorebe10102009-08-20 07:17:43 +00001106 /// \brief Build a new "if" statement.
1107 ///
1108 /// By default, performs semantic analysis to build the new statement.
1109 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001110 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier1dcde962012-08-08 18:46:20 +00001111 VarDecl *CondVar, Stmt *Then,
Chris Lattnercab02a62011-02-17 20:34:02 +00001112 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001113 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001114 }
Mike Stump11289f42009-09-09 15:08:12 +00001115
Douglas Gregorebe10102009-08-20 07:17:43 +00001116 /// \brief Start building a new switch statement.
1117 ///
1118 /// By default, performs semantic analysis to build the new statement.
1119 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001120 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001121 Expr *Cond, VarDecl *CondVar) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001122 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001123 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001124 }
Mike Stump11289f42009-09-09 15:08:12 +00001125
Douglas Gregorebe10102009-08-20 07:17:43 +00001126 /// \brief Attach the body to the switch statement.
1127 ///
1128 /// By default, performs semantic analysis to build the new statement.
1129 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001130 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001131 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001132 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001133 }
1134
1135 /// \brief Build a new while statement.
1136 ///
1137 /// By default, performs semantic analysis to build the new statement.
1138 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001139 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1140 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001141 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001142 }
Mike Stump11289f42009-09-09 15:08:12 +00001143
Douglas Gregorebe10102009-08-20 07:17:43 +00001144 /// \brief Build a new do-while statement.
1145 ///
1146 /// By default, performs semantic analysis to build the new statement.
1147 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001148 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001149 SourceLocation WhileLoc, SourceLocation LParenLoc,
1150 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001151 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1152 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001153 }
1154
1155 /// \brief Build a new for statement.
1156 ///
1157 /// By default, performs semantic analysis to build the new statement.
1158 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001159 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier1dcde962012-08-08 18:46:20 +00001160 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001161 VarDecl *CondVar, Sema::FullExprArg Inc,
1162 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001163 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001164 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001165 }
Mike Stump11289f42009-09-09 15:08:12 +00001166
Douglas Gregorebe10102009-08-20 07:17:43 +00001167 /// \brief Build a new goto statement.
1168 ///
1169 /// By default, performs semantic analysis to build the new statement.
1170 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001171 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1172 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001173 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001174 }
1175
1176 /// \brief Build a new indirect goto statement.
1177 ///
1178 /// By default, performs semantic analysis to build the new statement.
1179 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001180 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001181 SourceLocation StarLoc,
1182 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001183 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001184 }
Mike Stump11289f42009-09-09 15:08:12 +00001185
Douglas Gregorebe10102009-08-20 07:17:43 +00001186 /// \brief Build a new return statement.
1187 ///
1188 /// By default, performs semantic analysis to build the new statement.
1189 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001190 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCallb268a282010-08-23 23:25:46 +00001191 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001192 }
Mike Stump11289f42009-09-09 15:08:12 +00001193
Douglas Gregorebe10102009-08-20 07:17:43 +00001194 /// \brief Build a new declaration statement.
1195 ///
1196 /// By default, performs semantic analysis to build the new statement.
1197 /// Subclasses may override this routine to provide different behavior.
Rafael Espindolaab417692013-07-09 12:05:01 +00001198 StmtResult RebuildDeclStmt(llvm::MutableArrayRef<Decl *> Decls,
1199 SourceLocation StartLoc, SourceLocation EndLoc) {
1200 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001201 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001202 }
Mike Stump11289f42009-09-09 15:08:12 +00001203
Anders Carlssonaaeef072010-01-24 05:50:09 +00001204 /// \brief Build a new inline asm statement.
1205 ///
1206 /// By default, performs semantic analysis to build the new statement.
1207 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001208 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1209 bool IsVolatile, unsigned NumOutputs,
1210 unsigned NumInputs, IdentifierInfo **Names,
1211 MultiExprArg Constraints, MultiExprArg Exprs,
1212 Expr *AsmString, MultiExprArg Clobbers,
1213 SourceLocation RParenLoc) {
1214 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1215 NumInputs, Names, Constraints, Exprs,
1216 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001217 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001218
Chad Rosier32503022012-06-11 20:47:18 +00001219 /// \brief Build a new MS style inline asm statement.
1220 ///
1221 /// By default, performs semantic analysis to build the new statement.
1222 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001223 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001224 ArrayRef<Token> AsmToks,
1225 StringRef AsmString,
1226 unsigned NumOutputs, unsigned NumInputs,
1227 ArrayRef<StringRef> Constraints,
1228 ArrayRef<StringRef> Clobbers,
1229 ArrayRef<Expr*> Exprs,
1230 SourceLocation EndLoc) {
1231 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1232 NumOutputs, NumInputs,
1233 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001234 }
1235
James Dennett2a4d13c2012-06-15 07:13:21 +00001236 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001237 ///
1238 /// By default, performs semantic analysis to build the new statement.
1239 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001240 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001241 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001242 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001243 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001244 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001245 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001246 }
1247
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001248 /// \brief Rebuild an Objective-C exception declaration.
1249 ///
1250 /// By default, performs semantic analysis to build the new declaration.
1251 /// Subclasses may override this routine to provide different behavior.
1252 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1253 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001254 return getSema().BuildObjCExceptionDecl(TInfo, T,
1255 ExceptionDecl->getInnerLocStart(),
1256 ExceptionDecl->getLocation(),
1257 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001258 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001259
James Dennett2a4d13c2012-06-15 07:13:21 +00001260 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001261 ///
1262 /// By default, performs semantic analysis to build the new statement.
1263 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001264 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001265 SourceLocation RParenLoc,
1266 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001267 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001268 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001269 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001270 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001271
James Dennett2a4d13c2012-06-15 07:13:21 +00001272 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001273 ///
1274 /// By default, performs semantic analysis to build the new statement.
1275 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001276 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001277 Stmt *Body) {
1278 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001279 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001280
James Dennett2a4d13c2012-06-15 07:13:21 +00001281 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001282 ///
1283 /// By default, performs semantic analysis to build the new statement.
1284 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001285 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001286 Expr *Operand) {
1287 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001288 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001289
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001290 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001291 ///
1292 /// By default, performs semantic analysis to build the new statement.
1293 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001294 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
1295 ArrayRef<OMPClause *> Clauses,
1296 Stmt *AStmt,
1297 SourceLocation StartLoc,
1298 SourceLocation EndLoc) {
1299 return getSema().ActOnOpenMPExecutableDirective(Kind, Clauses, AStmt,
1300 StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001301 }
1302
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001303 /// \brief Build a new OpenMP 'if' clause.
1304 ///
1305 /// By default, performs semantic analysis to build the new statement.
1306 /// Subclasses may override this routine to provide different behavior.
1307 OMPClause *RebuildOMPIfClause(Expr *Condition,
1308 SourceLocation StartLoc,
1309 SourceLocation LParenLoc,
1310 SourceLocation EndLoc) {
1311 return getSema().ActOnOpenMPIfClause(Condition, StartLoc,
1312 LParenLoc, EndLoc);
1313 }
1314
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001315 /// \brief Build a new OpenMP 'default' clause.
1316 ///
1317 /// By default, performs semantic analysis to build the new statement.
1318 /// Subclasses may override this routine to provide different behavior.
1319 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1320 SourceLocation KindKwLoc,
1321 SourceLocation StartLoc,
1322 SourceLocation LParenLoc,
1323 SourceLocation EndLoc) {
1324 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1325 StartLoc, LParenLoc, EndLoc);
1326 }
1327
1328 /// \brief Build a new OpenMP 'private' clause.
1329 ///
1330 /// By default, performs semantic analysis to build the new statement.
1331 /// Subclasses may override this routine to provide different behavior.
1332 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1333 SourceLocation StartLoc,
1334 SourceLocation LParenLoc,
1335 SourceLocation EndLoc) {
1336 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1337 EndLoc);
1338 }
1339
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001340 /// \brief Build a new OpenMP 'firstprivate' clause.
1341 ///
1342 /// By default, performs semantic analysis to build the new statement.
1343 /// Subclasses may override this routine to provide different behavior.
1344 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1345 SourceLocation StartLoc,
1346 SourceLocation LParenLoc,
1347 SourceLocation EndLoc) {
1348 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1349 EndLoc);
1350 }
1351
Alexey Bataev758e55e2013-09-06 18:03:48 +00001352 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1353 SourceLocation StartLoc,
1354 SourceLocation LParenLoc,
1355 SourceLocation EndLoc) {
1356 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1357 EndLoc);
1358 }
1359
James Dennett2a4d13c2012-06-15 07:13:21 +00001360 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001361 ///
1362 /// By default, performs semantic analysis to build the new statement.
1363 /// Subclasses may override this routine to provide different behavior.
1364 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1365 Expr *object) {
1366 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1367 }
1368
James Dennett2a4d13c2012-06-15 07:13:21 +00001369 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001370 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001371 /// By default, performs semantic analysis to build the new statement.
1372 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001373 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001374 Expr *Object, Stmt *Body) {
1375 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001376 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001377
James Dennett2a4d13c2012-06-15 07:13:21 +00001378 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001379 ///
1380 /// By default, performs semantic analysis to build the new statement.
1381 /// Subclasses may override this routine to provide different behavior.
1382 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1383 Stmt *Body) {
1384 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1385 }
John McCall53848232011-07-27 01:07:15 +00001386
Douglas Gregorf68a5082010-04-22 23:10:45 +00001387 /// \brief Build a new Objective-C fast enumeration statement.
1388 ///
1389 /// By default, performs semantic analysis to build the new statement.
1390 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001391 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001392 Stmt *Element,
1393 Expr *Collection,
1394 SourceLocation RParenLoc,
1395 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001396 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001397 Element,
John McCallb268a282010-08-23 23:25:46 +00001398 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001399 RParenLoc);
1400 if (ForEachStmt.isInvalid())
1401 return StmtError();
1402
1403 return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001404 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001405
Douglas Gregorebe10102009-08-20 07:17:43 +00001406 /// \brief Build a new C++ exception declaration.
1407 ///
1408 /// By default, performs semantic analysis to build the new decaration.
1409 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001410 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001411 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001412 SourceLocation StartLoc,
1413 SourceLocation IdLoc,
1414 IdentifierInfo *Id) {
Douglas Gregor40965fa2011-04-14 22:32:28 +00001415 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1416 StartLoc, IdLoc, Id);
1417 if (Var)
1418 getSema().CurContext->addDecl(Var);
1419 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001420 }
1421
1422 /// \brief Build a new C++ catch statement.
1423 ///
1424 /// By default, performs semantic analysis to build the new statement.
1425 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001426 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001427 VarDecl *ExceptionDecl,
1428 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001429 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1430 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001431 }
Mike Stump11289f42009-09-09 15:08:12 +00001432
Douglas Gregorebe10102009-08-20 07:17:43 +00001433 /// \brief Build a new C++ try statement.
1434 ///
1435 /// By default, performs semantic analysis to build the new statement.
1436 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001437 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1438 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001439 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001440 }
Mike Stump11289f42009-09-09 15:08:12 +00001441
Richard Smith02e85f32011-04-14 22:09:26 +00001442 /// \brief Build a new C++0x range-based for statement.
1443 ///
1444 /// By default, performs semantic analysis to build the new statement.
1445 /// Subclasses may override this routine to provide different behavior.
1446 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1447 SourceLocation ColonLoc,
1448 Stmt *Range, Stmt *BeginEnd,
1449 Expr *Cond, Expr *Inc,
1450 Stmt *LoopVar,
1451 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001452 // If we've just learned that the range is actually an Objective-C
1453 // collection, treat this as an Objective-C fast enumeration loop.
1454 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1455 if (RangeStmt->isSingleDecl()) {
1456 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001457 if (RangeVar->isInvalidDecl())
1458 return StmtError();
1459
Douglas Gregorf7106af2013-04-08 18:40:13 +00001460 Expr *RangeExpr = RangeVar->getInit();
1461 if (!RangeExpr->isTypeDependent() &&
1462 RangeExpr->getType()->isObjCObjectPointerType())
1463 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1464 RParenLoc);
1465 }
1466 }
1467 }
1468
Richard Smith02e85f32011-04-14 22:09:26 +00001469 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001470 Cond, Inc, LoopVar, RParenLoc,
1471 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001472 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001473
1474 /// \brief Build a new C++0x range-based for statement.
1475 ///
1476 /// By default, performs semantic analysis to build the new statement.
1477 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001478 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001479 bool IsIfExists,
1480 NestedNameSpecifierLoc QualifierLoc,
1481 DeclarationNameInfo NameInfo,
1482 Stmt *Nested) {
1483 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1484 QualifierLoc, NameInfo, Nested);
1485 }
1486
Richard Smith02e85f32011-04-14 22:09:26 +00001487 /// \brief Attach body to a C++0x range-based for statement.
1488 ///
1489 /// By default, performs semantic analysis to finish the new statement.
1490 /// Subclasses may override this routine to provide different behavior.
1491 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1492 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1493 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001494
David Majnemerfad8f482013-10-15 09:33:02 +00001495 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
1496 Stmt *TryBlock, Stmt *Handler) {
1497 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001498 }
1499
David Majnemerfad8f482013-10-15 09:33:02 +00001500 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001501 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001502 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001503 }
1504
David Majnemerfad8f482013-10-15 09:33:02 +00001505 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
1506 return getSema().ActOnSEHFinallyBlock(Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001507 }
1508
Douglas Gregora16548e2009-08-11 05:31:07 +00001509 /// \brief Build a new expression that references a declaration.
1510 ///
1511 /// By default, performs semantic analysis to build the new expression.
1512 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001513 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001514 LookupResult &R,
1515 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001516 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1517 }
1518
1519
1520 /// \brief Build a new expression that references a declaration.
1521 ///
1522 /// By default, performs semantic analysis to build the new expression.
1523 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001524 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001525 ValueDecl *VD,
1526 const DeclarationNameInfo &NameInfo,
1527 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001528 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001529 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001530
1531 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001532
1533 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001534 }
Mike Stump11289f42009-09-09 15:08:12 +00001535
Douglas Gregora16548e2009-08-11 05:31:07 +00001536 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001537 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001538 /// By default, performs semantic analysis to build the new expression.
1539 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001540 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001541 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001542 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001543 }
1544
Douglas Gregorad8a3362009-09-04 17:36:40 +00001545 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001546 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001547 /// By default, performs semantic analysis to build the new expression.
1548 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001549 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001550 SourceLocation OperatorLoc,
1551 bool isArrow,
1552 CXXScopeSpec &SS,
1553 TypeSourceInfo *ScopeType,
1554 SourceLocation CCLoc,
1555 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001556 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001557
Douglas Gregora16548e2009-08-11 05:31:07 +00001558 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001559 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001560 /// By default, performs semantic analysis to build the new expression.
1561 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001562 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001563 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001564 Expr *SubExpr) {
1565 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001566 }
Mike Stump11289f42009-09-09 15:08:12 +00001567
Douglas Gregor882211c2010-04-28 22:16:22 +00001568 /// \brief Build a new builtin offsetof expression.
1569 ///
1570 /// By default, performs semantic analysis to build the new expression.
1571 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001572 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001573 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001574 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001575 unsigned NumComponents,
1576 SourceLocation RParenLoc) {
1577 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1578 NumComponents, RParenLoc);
1579 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001580
1581 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001582 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001583 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001584 /// By default, performs semantic analysis to build the new expression.
1585 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001586 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1587 SourceLocation OpLoc,
1588 UnaryExprOrTypeTrait ExprKind,
1589 SourceRange R) {
1590 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001591 }
1592
Peter Collingbournee190dee2011-03-11 19:24:49 +00001593 /// \brief Build a new sizeof, alignof or vec step expression with an
1594 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001595 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001596 /// By default, performs semantic analysis to build the new expression.
1597 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001598 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1599 UnaryExprOrTypeTrait ExprKind,
1600 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001601 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001602 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001603 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001604 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001605
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001606 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001607 }
Mike Stump11289f42009-09-09 15:08:12 +00001608
Douglas Gregora16548e2009-08-11 05:31:07 +00001609 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001610 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001611 /// By default, performs semantic analysis to build the new expression.
1612 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001613 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001614 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001615 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001616 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001617 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1618 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001619 RBracketLoc);
1620 }
1621
1622 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001623 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001624 /// By default, performs semantic analysis to build the new expression.
1625 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001626 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001627 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001628 SourceLocation RParenLoc,
1629 Expr *ExecConfig = 0) {
John McCallb268a282010-08-23 23:25:46 +00001630 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001631 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001632 }
1633
1634 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001635 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001636 /// By default, performs semantic analysis to build the new expression.
1637 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001638 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001639 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001640 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001641 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001642 const DeclarationNameInfo &MemberNameInfo,
1643 ValueDecl *Member,
1644 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001645 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001646 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00001647 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1648 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00001649 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001650 // We have a reference to an unnamed field. This is always the
1651 // base of an anonymous struct/union member access, i.e. the
1652 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001653 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001654 assert(Member->getType()->isRecordType() &&
1655 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001656
Richard Smithcab9a7d2011-10-26 19:06:56 +00001657 BaseResult =
1658 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley01296292011-04-08 18:41:53 +00001659 QualifierLoc.getNestedNameSpecifier(),
1660 FoundDecl, Member);
1661 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001662 return ExprError();
John Wiegley01296292011-04-08 18:41:53 +00001663 Base = BaseResult.take();
John McCall7decc9e2010-11-18 06:31:45 +00001664 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001665 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001666 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001667 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001668 cast<FieldDecl>(Member)->getType(),
1669 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001670 return getSema().Owned(ME);
1671 }
Mike Stump11289f42009-09-09 15:08:12 +00001672
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001673 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001674 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001675
John Wiegley01296292011-04-08 18:41:53 +00001676 Base = BaseResult.take();
John McCallb268a282010-08-23 23:25:46 +00001677 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001678
John McCall16df1e52010-03-30 21:47:33 +00001679 // FIXME: this involves duplicating earlier analysis in a lot of
1680 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001681 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001682 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001683 R.resolveKind();
1684
John McCallb268a282010-08-23 23:25:46 +00001685 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001686 SS, TemplateKWLoc,
1687 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001688 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001689 }
Mike Stump11289f42009-09-09 15:08:12 +00001690
Douglas Gregora16548e2009-08-11 05:31:07 +00001691 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001692 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001693 /// By default, performs semantic analysis to build the new expression.
1694 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001695 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001696 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001697 Expr *LHS, Expr *RHS) {
1698 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001699 }
1700
1701 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001702 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001703 /// By default, performs semantic analysis to build the new expression.
1704 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001705 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001706 SourceLocation QuestionLoc,
1707 Expr *LHS,
1708 SourceLocation ColonLoc,
1709 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001710 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1711 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001712 }
1713
Douglas Gregora16548e2009-08-11 05:31:07 +00001714 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001715 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001716 /// By default, performs semantic analysis to build the new expression.
1717 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001718 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001719 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001720 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001721 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001722 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001723 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001724 }
Mike Stump11289f42009-09-09 15:08:12 +00001725
Douglas Gregora16548e2009-08-11 05:31:07 +00001726 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001727 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001728 /// By default, performs semantic analysis to build the new expression.
1729 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001730 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001731 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001732 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001733 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001734 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001735 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001736 }
Mike Stump11289f42009-09-09 15:08:12 +00001737
Douglas Gregora16548e2009-08-11 05:31:07 +00001738 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001739 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001740 /// By default, performs semantic analysis to build the new expression.
1741 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001742 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001743 SourceLocation OpLoc,
1744 SourceLocation AccessorLoc,
1745 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001746
John McCall10eae182009-11-30 22:42:35 +00001747 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001748 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001749 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001750 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001751 SS, SourceLocation(),
1752 /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001753 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001754 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001755 }
Mike Stump11289f42009-09-09 15:08:12 +00001756
Douglas Gregora16548e2009-08-11 05:31:07 +00001757 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001758 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001759 /// By default, performs semantic analysis to build the new expression.
1760 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001761 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00001762 MultiExprArg Inits,
1763 SourceLocation RBraceLoc,
1764 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001765 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001766 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00001767 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001768 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00001769
Douglas Gregord3d93062009-11-09 17:16:50 +00001770 // Patch in the result type we were given, which may have been computed
1771 // when the initial InitListExpr was built.
1772 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1773 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001774 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001775 }
Mike Stump11289f42009-09-09 15:08:12 +00001776
Douglas Gregora16548e2009-08-11 05:31:07 +00001777 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001778 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001779 /// By default, performs semantic analysis to build the new expression.
1780 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001781 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001782 MultiExprArg ArrayExprs,
1783 SourceLocation EqualOrColonLoc,
1784 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001785 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001786 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001787 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001788 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001789 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001790 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001791
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001792 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001793 }
Mike Stump11289f42009-09-09 15:08:12 +00001794
Douglas Gregora16548e2009-08-11 05:31:07 +00001795 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001796 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001797 /// By default, builds the implicit value initialization without performing
1798 /// any semantic analysis. Subclasses may override this routine to provide
1799 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001800 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001801 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1802 }
Mike Stump11289f42009-09-09 15:08:12 +00001803
Douglas Gregora16548e2009-08-11 05:31:07 +00001804 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001805 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001806 /// By default, performs semantic analysis to build the new expression.
1807 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001808 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001809 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001810 SourceLocation RParenLoc) {
1811 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001812 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001813 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001814 }
1815
1816 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001817 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001818 /// By default, performs semantic analysis to build the new expression.
1819 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001820 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00001821 MultiExprArg SubExprs,
1822 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001823 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001824 }
Mike Stump11289f42009-09-09 15:08:12 +00001825
Douglas Gregora16548e2009-08-11 05:31:07 +00001826 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001827 ///
1828 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001829 /// rather than attempting to map the label statement itself.
1830 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001831 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001832 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001833 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001834 }
Mike Stump11289f42009-09-09 15:08:12 +00001835
Douglas Gregora16548e2009-08-11 05:31:07 +00001836 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001837 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001838 /// By default, performs semantic analysis to build the new expression.
1839 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001840 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001841 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001842 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001843 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001844 }
Mike Stump11289f42009-09-09 15:08:12 +00001845
Douglas Gregora16548e2009-08-11 05:31:07 +00001846 /// \brief Build a new __builtin_choose_expr expression.
1847 ///
1848 /// By default, performs semantic analysis to build the new expression.
1849 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001850 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001851 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001852 SourceLocation RParenLoc) {
1853 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001854 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001855 RParenLoc);
1856 }
Mike Stump11289f42009-09-09 15:08:12 +00001857
Peter Collingbourne91147592011-04-15 00:35:48 +00001858 /// \brief Build a new generic selection expression.
1859 ///
1860 /// By default, performs semantic analysis to build the new expression.
1861 /// Subclasses may override this routine to provide different behavior.
1862 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1863 SourceLocation DefaultLoc,
1864 SourceLocation RParenLoc,
1865 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00001866 ArrayRef<TypeSourceInfo *> Types,
1867 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00001868 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00001869 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00001870 }
1871
Douglas Gregora16548e2009-08-11 05:31:07 +00001872 /// \brief Build a new overloaded operator call expression.
1873 ///
1874 /// By default, performs semantic analysis to build the new expression.
1875 /// The semantic analysis provides the behavior of template instantiation,
1876 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001877 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001878 /// argument-dependent lookup, etc. Subclasses may override this routine to
1879 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001880 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001881 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001882 Expr *Callee,
1883 Expr *First,
1884 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001885
1886 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001887 /// reinterpret_cast.
1888 ///
1889 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001890 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001891 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001892 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001893 Stmt::StmtClass Class,
1894 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001895 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001896 SourceLocation RAngleLoc,
1897 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001898 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001899 SourceLocation RParenLoc) {
1900 switch (Class) {
1901 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001902 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001903 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001904 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001905
1906 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001907 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001908 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001909 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001910
Douglas Gregora16548e2009-08-11 05:31:07 +00001911 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001912 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001913 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001914 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001915 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001916
Douglas Gregora16548e2009-08-11 05:31:07 +00001917 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001918 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001919 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001920 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001921
Douglas Gregora16548e2009-08-11 05:31:07 +00001922 default:
David Blaikie83d382b2011-09-23 05:06:16 +00001923 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00001924 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001925 }
Mike Stump11289f42009-09-09 15:08:12 +00001926
Douglas Gregora16548e2009-08-11 05:31:07 +00001927 /// \brief Build a new C++ static_cast expression.
1928 ///
1929 /// By default, performs semantic analysis to build the new expression.
1930 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001931 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001932 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001933 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001934 SourceLocation RAngleLoc,
1935 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001936 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001937 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001938 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001939 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001940 SourceRange(LAngleLoc, RAngleLoc),
1941 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001942 }
1943
1944 /// \brief Build a new C++ dynamic_cast expression.
1945 ///
1946 /// By default, performs semantic analysis to build the new expression.
1947 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001948 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001949 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001950 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001951 SourceLocation RAngleLoc,
1952 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001953 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001954 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001955 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001956 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001957 SourceRange(LAngleLoc, RAngleLoc),
1958 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001959 }
1960
1961 /// \brief Build a new C++ reinterpret_cast expression.
1962 ///
1963 /// By default, performs semantic analysis to build the new expression.
1964 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001965 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001966 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001967 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001968 SourceLocation RAngleLoc,
1969 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001970 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001971 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001972 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001973 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001974 SourceRange(LAngleLoc, RAngleLoc),
1975 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001976 }
1977
1978 /// \brief Build a new C++ const_cast expression.
1979 ///
1980 /// By default, performs semantic analysis to build the new expression.
1981 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001982 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001983 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001984 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001985 SourceLocation RAngleLoc,
1986 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001987 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001988 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001989 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001990 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001991 SourceRange(LAngleLoc, RAngleLoc),
1992 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001993 }
Mike Stump11289f42009-09-09 15:08:12 +00001994
Douglas Gregora16548e2009-08-11 05:31:07 +00001995 /// \brief Build a new C++ functional-style cast expression.
1996 ///
1997 /// By default, performs semantic analysis to build the new expression.
1998 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001999 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2000 SourceLocation LParenLoc,
2001 Expr *Sub,
2002 SourceLocation RParenLoc) {
2003 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002004 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002005 RParenLoc);
2006 }
Mike Stump11289f42009-09-09 15:08:12 +00002007
Douglas Gregora16548e2009-08-11 05:31:07 +00002008 /// \brief Build a new C++ typeid(type) expression.
2009 ///
2010 /// By default, performs semantic analysis to build the new expression.
2011 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002012 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002013 SourceLocation TypeidLoc,
2014 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002015 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002016 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002017 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002018 }
Mike Stump11289f42009-09-09 15:08:12 +00002019
Francois Pichet9f4f2072010-09-08 12:20:18 +00002020
Douglas Gregora16548e2009-08-11 05:31:07 +00002021 /// \brief Build a new C++ typeid(expr) expression.
2022 ///
2023 /// By default, performs semantic analysis to build the new expression.
2024 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002025 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002026 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002027 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002028 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002029 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002030 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002031 }
2032
Francois Pichet9f4f2072010-09-08 12:20:18 +00002033 /// \brief Build a new C++ __uuidof(type) expression.
2034 ///
2035 /// By default, performs semantic analysis to build the new expression.
2036 /// Subclasses may override this routine to provide different behavior.
2037 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2038 SourceLocation TypeidLoc,
2039 TypeSourceInfo *Operand,
2040 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002041 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002042 RParenLoc);
2043 }
2044
2045 /// \brief Build a new C++ __uuidof(expr) expression.
2046 ///
2047 /// By default, performs semantic analysis to build the new expression.
2048 /// Subclasses may override this routine to provide different behavior.
2049 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2050 SourceLocation TypeidLoc,
2051 Expr *Operand,
2052 SourceLocation RParenLoc) {
2053 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2054 RParenLoc);
2055 }
2056
Douglas Gregora16548e2009-08-11 05:31:07 +00002057 /// \brief Build a new C++ "this" expression.
2058 ///
2059 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002060 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002061 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002062 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002063 QualType ThisType,
2064 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002065 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002066 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00002067 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
2068 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00002069 }
2070
2071 /// \brief Build a new C++ throw expression.
2072 ///
2073 /// By default, performs semantic analysis to build the new expression.
2074 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002075 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2076 bool IsThrownVariableInScope) {
2077 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002078 }
2079
2080 /// \brief Build a new C++ default-argument expression.
2081 ///
2082 /// By default, builds a new default-argument expression, which does not
2083 /// require any semantic analysis. Subclasses may override this routine to
2084 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002085 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002086 ParmVarDecl *Param) {
2087 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
2088 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00002089 }
2090
Richard Smith852c9db2013-04-20 22:23:05 +00002091 /// \brief Build a new C++11 default-initialization expression.
2092 ///
2093 /// By default, builds a new default field initialization expression, which
2094 /// does not require any semantic analysis. Subclasses may override this
2095 /// routine to provide different behavior.
2096 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2097 FieldDecl *Field) {
2098 return getSema().Owned(CXXDefaultInitExpr::Create(getSema().Context, Loc,
2099 Field));
2100 }
2101
Douglas Gregora16548e2009-08-11 05:31:07 +00002102 /// \brief Build a new C++ zero-initialization expression.
2103 ///
2104 /// By default, performs semantic analysis to build the new expression.
2105 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002106 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2107 SourceLocation LParenLoc,
2108 SourceLocation RParenLoc) {
2109 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002110 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002111 }
Mike Stump11289f42009-09-09 15:08:12 +00002112
Douglas Gregora16548e2009-08-11 05:31:07 +00002113 /// \brief Build a new C++ "new" expression.
2114 ///
2115 /// By default, performs semantic analysis to build the new expression.
2116 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002117 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002118 bool UseGlobal,
2119 SourceLocation PlacementLParen,
2120 MultiExprArg PlacementArgs,
2121 SourceLocation PlacementRParen,
2122 SourceRange TypeIdParens,
2123 QualType AllocatedType,
2124 TypeSourceInfo *AllocatedTypeInfo,
2125 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002126 SourceRange DirectInitRange,
2127 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002128 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002129 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002130 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002131 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002132 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002133 AllocatedType,
2134 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002135 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002136 DirectInitRange,
2137 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002138 }
Mike Stump11289f42009-09-09 15:08:12 +00002139
Douglas Gregora16548e2009-08-11 05:31:07 +00002140 /// \brief Build a new C++ "delete" expression.
2141 ///
2142 /// By default, performs semantic analysis to build the new expression.
2143 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002144 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002145 bool IsGlobalDelete,
2146 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002147 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002148 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002149 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002150 }
Mike Stump11289f42009-09-09 15:08:12 +00002151
Douglas Gregor29c42f22012-02-24 07:38:34 +00002152 /// \brief Build a new type trait expression.
2153 ///
2154 /// By default, performs semantic analysis to build the new expression.
2155 /// Subclasses may override this routine to provide different behavior.
2156 ExprResult RebuildTypeTrait(TypeTrait Trait,
2157 SourceLocation StartLoc,
2158 ArrayRef<TypeSourceInfo *> Args,
2159 SourceLocation RParenLoc) {
2160 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2161 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002162
John Wiegley6242b6a2011-04-28 00:16:57 +00002163 /// \brief Build a new array type trait expression.
2164 ///
2165 /// By default, performs semantic analysis to build the new expression.
2166 /// Subclasses may override this routine to provide different behavior.
2167 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2168 SourceLocation StartLoc,
2169 TypeSourceInfo *TSInfo,
2170 Expr *DimExpr,
2171 SourceLocation RParenLoc) {
2172 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2173 }
2174
John Wiegleyf9f65842011-04-25 06:54:41 +00002175 /// \brief Build a new expression trait expression.
2176 ///
2177 /// By default, performs semantic analysis to build the new expression.
2178 /// Subclasses may override this routine to provide different behavior.
2179 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2180 SourceLocation StartLoc,
2181 Expr *Queried,
2182 SourceLocation RParenLoc) {
2183 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2184 }
2185
Mike Stump11289f42009-09-09 15:08:12 +00002186 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002187 /// expression.
2188 ///
2189 /// By default, performs semantic analysis to build the new expression.
2190 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002191 ExprResult RebuildDependentScopeDeclRefExpr(
2192 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002193 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002194 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002195 const TemplateArgumentListInfo *TemplateArgs,
2196 bool IsAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002197 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002198 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002199
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002200 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnara7945c982012-01-27 09:46:47 +00002201 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002202 NameInfo, TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002203
Richard Smithdb2630f2012-10-21 03:28:35 +00002204 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo,
2205 IsAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002206 }
2207
2208 /// \brief Build a new template-id expression.
2209 ///
2210 /// By default, performs semantic analysis to build the new expression.
2211 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002212 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002213 SourceLocation TemplateKWLoc,
2214 LookupResult &R,
2215 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002216 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002217 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2218 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002219 }
2220
2221 /// \brief Build a new object-construction expression.
2222 ///
2223 /// By default, performs semantic analysis to build the new expression.
2224 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002225 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002226 SourceLocation Loc,
2227 CXXConstructorDecl *Constructor,
2228 bool IsElidable,
2229 MultiExprArg Args,
2230 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002231 bool ListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002232 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002233 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002234 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002235 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002236 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002237 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002238 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002239
Douglas Gregordb121ba2009-12-14 16:27:04 +00002240 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002241 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002242 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002243 ListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002244 RequiresZeroInit, ConstructKind,
2245 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002246 }
2247
2248 /// \brief Build a new object-construction expression.
2249 ///
2250 /// By default, performs semantic analysis to build the new expression.
2251 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002252 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2253 SourceLocation LParenLoc,
2254 MultiExprArg Args,
2255 SourceLocation RParenLoc) {
2256 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002257 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002258 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002259 RParenLoc);
2260 }
2261
2262 /// \brief Build a new object-construction expression.
2263 ///
2264 /// By default, performs semantic analysis to build the new expression.
2265 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002266 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2267 SourceLocation LParenLoc,
2268 MultiExprArg Args,
2269 SourceLocation RParenLoc) {
2270 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002271 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002272 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002273 RParenLoc);
2274 }
Mike Stump11289f42009-09-09 15:08:12 +00002275
Douglas Gregora16548e2009-08-11 05:31:07 +00002276 /// \brief Build a new member reference expression.
2277 ///
2278 /// By default, performs semantic analysis to build the new expression.
2279 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002280 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002281 QualType BaseType,
2282 bool IsArrow,
2283 SourceLocation OperatorLoc,
2284 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002285 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002286 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002287 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002288 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002289 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002290 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002291
John McCallb268a282010-08-23 23:25:46 +00002292 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002293 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002294 SS, TemplateKWLoc,
2295 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002296 MemberNameInfo,
2297 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002298 }
2299
John McCall10eae182009-11-30 22:42:35 +00002300 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002301 ///
2302 /// By default, performs semantic analysis to build the new expression.
2303 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002304 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2305 SourceLocation OperatorLoc,
2306 bool IsArrow,
2307 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002308 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002309 NamedDecl *FirstQualifierInScope,
2310 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002311 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002312 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002313 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002314
John McCallb268a282010-08-23 23:25:46 +00002315 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002316 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002317 SS, TemplateKWLoc,
2318 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00002319 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002320 }
Mike Stump11289f42009-09-09 15:08:12 +00002321
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002322 /// \brief Build a new noexcept expression.
2323 ///
2324 /// By default, performs semantic analysis to build the new expression.
2325 /// Subclasses may override this routine to provide different behavior.
2326 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2327 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2328 }
2329
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002330 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00002331 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2332 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002333 SourceLocation RParenLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002334 Optional<unsigned> Length) {
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002335 if (Length)
Chad Rosier1dcde962012-08-08 18:46:20 +00002336 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2337 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002338 RParenLoc, *Length);
Chad Rosier1dcde962012-08-08 18:46:20 +00002339
2340 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2341 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002342 RParenLoc);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002343 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002344
Patrick Beard0caa3942012-04-19 00:25:12 +00002345 /// \brief Build a new Objective-C boxed expression.
2346 ///
2347 /// By default, performs semantic analysis to build the new expression.
2348 /// Subclasses may override this routine to provide different behavior.
2349 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2350 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2351 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002352
Ted Kremeneke65b0862012-03-06 20:05:56 +00002353 /// \brief Build a new Objective-C array literal.
2354 ///
2355 /// By default, performs semantic analysis to build the new expression.
2356 /// Subclasses may override this routine to provide different behavior.
2357 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2358 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002359 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002360 MultiExprArg(Elements, NumElements));
2361 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002362
2363 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002364 Expr *Base, Expr *Key,
2365 ObjCMethodDecl *getterMethod,
2366 ObjCMethodDecl *setterMethod) {
2367 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2368 getterMethod, setterMethod);
2369 }
2370
2371 /// \brief Build a new Objective-C dictionary literal.
2372 ///
2373 /// By default, performs semantic analysis to build the new expression.
2374 /// Subclasses may override this routine to provide different behavior.
2375 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2376 ObjCDictionaryElement *Elements,
2377 unsigned NumElements) {
2378 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2379 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002380
James Dennett2a4d13c2012-06-15 07:13:21 +00002381 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002382 ///
2383 /// By default, performs semantic analysis to build the new expression.
2384 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002385 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002386 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002387 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00002388 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002389 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002390 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002391
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002392 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002393 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002394 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002395 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002396 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002397 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002398 MultiExprArg Args,
2399 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002400 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2401 ReceiverTypeInfo->getType(),
2402 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002403 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002404 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002405 }
2406
2407 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002408 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002409 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002410 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002411 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002412 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002413 MultiExprArg Args,
2414 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002415 return SemaRef.BuildInstanceMessage(Receiver,
2416 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002417 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002418 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002419 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002420 }
2421
Douglas Gregord51d90d2010-04-26 20:11:03 +00002422 /// \brief Build a new Objective-C ivar reference expression.
2423 ///
2424 /// By default, performs semantic analysis to build the new expression.
2425 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002426 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002427 SourceLocation IvarLoc,
2428 bool IsArrow, bool IsFreeIvar) {
2429 // FIXME: We lose track of the IsFreeIvar bit.
2430 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002431 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002432 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2433 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002434 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002435 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00002436 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00002437 false);
John Wiegley01296292011-04-08 18:41:53 +00002438 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002439 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002440
Douglas Gregord51d90d2010-04-26 20:11:03 +00002441 if (Result.get())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002442 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002443
John Wiegley01296292011-04-08 18:41:53 +00002444 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002445 /*FIXME:*/IvarLoc, IsArrow,
2446 SS, SourceLocation(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00002447 /*FirstQualifierInScope=*/0,
Chad Rosier1dcde962012-08-08 18:46:20 +00002448 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002449 /*TemplateArgs=*/0);
2450 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002451
2452 /// \brief Build a new Objective-C property reference expression.
2453 ///
2454 /// By default, performs semantic analysis to build the new expression.
2455 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002456 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002457 ObjCPropertyDecl *Property,
2458 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002459 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002460 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregor9faee212010-04-26 20:47:02 +00002461 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2462 Sema::LookupMemberName);
2463 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002464 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002465 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002466 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002467 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002468 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002469
Douglas Gregor9faee212010-04-26 20:47:02 +00002470 if (Result.get())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002471 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002472
John Wiegley01296292011-04-08 18:41:53 +00002473 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Chad Rosier1dcde962012-08-08 18:46:20 +00002474 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002475 SS, SourceLocation(),
Douglas Gregor9faee212010-04-26 20:47:02 +00002476 /*FirstQualifierInScope=*/0,
Chad Rosier1dcde962012-08-08 18:46:20 +00002477 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002478 /*TemplateArgs=*/0);
2479 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002480
John McCallb7bd14f2010-12-02 01:19:52 +00002481 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002482 ///
2483 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002484 /// Subclasses may override this routine to provide different behavior.
2485 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2486 ObjCMethodDecl *Getter,
2487 ObjCMethodDecl *Setter,
2488 SourceLocation PropertyLoc) {
2489 // Since these expressions can only be value-dependent, we do not
2490 // need to perform semantic analysis again.
2491 return Owned(
2492 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2493 VK_LValue, OK_ObjCProperty,
2494 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002495 }
2496
Douglas Gregord51d90d2010-04-26 20:11:03 +00002497 /// \brief Build a new Objective-C "isa" expression.
2498 ///
2499 /// By default, performs semantic analysis to build the new expression.
2500 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002501 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002502 SourceLocation OpLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002503 bool IsArrow) {
2504 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002505 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002506 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2507 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002508 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002509 OpLoc,
John McCall48871652010-08-21 09:40:31 +00002510 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002511 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002512 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002513
Douglas Gregord51d90d2010-04-26 20:11:03 +00002514 if (Result.get())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002515 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002516
John Wiegley01296292011-04-08 18:41:53 +00002517 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002518 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002519 SS, SourceLocation(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00002520 /*FirstQualifierInScope=*/0,
Chad Rosier1dcde962012-08-08 18:46:20 +00002521 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002522 /*TemplateArgs=*/0);
2523 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002524
Douglas Gregora16548e2009-08-11 05:31:07 +00002525 /// \brief Build a new shuffle vector expression.
2526 ///
2527 /// By default, performs semantic analysis to build the new expression.
2528 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002529 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002530 MultiExprArg SubExprs,
2531 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002532 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002533 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002534 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2535 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2536 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002537 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002538
Douglas Gregora16548e2009-08-11 05:31:07 +00002539 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002540 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002541 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2542 SemaRef.Context.BuiltinFnTy,
2543 VK_RValue, BuiltinLoc);
2544 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2545 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
2546 CK_BuiltinFnToFnPtr).take();
Mike Stump11289f42009-09-09 15:08:12 +00002547
2548 // Build the CallExpr
Alp Toker314cc812014-01-25 16:55:45 +00002549 ExprResult TheCall = SemaRef.Owned(new (SemaRef.Context) CallExpr(
2550 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
2551 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002552
Douglas Gregora16548e2009-08-11 05:31:07 +00002553 // Type-check the __builtin_shufflevector expression.
John Wiegley01296292011-04-08 18:41:53 +00002554 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002555 }
John McCall31f82722010-11-12 08:19:04 +00002556
Hal Finkelc4d7c822013-09-18 03:29:45 +00002557 /// \brief Build a new convert vector expression.
2558 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2559 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2560 SourceLocation RParenLoc) {
2561 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2562 BuiltinLoc, RParenLoc);
2563 }
2564
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002565 /// \brief Build a new template argument pack expansion.
2566 ///
2567 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002568 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002569 /// different behavior.
2570 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002571 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002572 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002573 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002574 case TemplateArgument::Expression: {
2575 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002576 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2577 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002578 if (Result.isInvalid())
2579 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002580
Douglas Gregor98318c22011-01-03 21:37:45 +00002581 return TemplateArgumentLoc(Result.get(), Result.get());
2582 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002583
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002584 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002585 return TemplateArgumentLoc(TemplateArgument(
2586 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002587 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002588 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002589 Pattern.getTemplateNameLoc(),
2590 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002591
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002592 case TemplateArgument::Null:
2593 case TemplateArgument::Integral:
2594 case TemplateArgument::Declaration:
2595 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002596 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002597 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002598 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002599
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002600 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002601 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002602 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002603 EllipsisLoc,
2604 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002605 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2606 Expansion);
2607 break;
2608 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002609
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002610 return TemplateArgumentLoc();
2611 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002612
Douglas Gregor968f23a2011-01-03 19:31:53 +00002613 /// \brief Build a new expression pack expansion.
2614 ///
2615 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002616 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002617 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002618 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002619 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002620 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002621 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002622
2623 /// \brief Build a new atomic operation expression.
2624 ///
2625 /// By default, performs semantic analysis to build the new expression.
2626 /// Subclasses may override this routine to provide different behavior.
2627 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2628 MultiExprArg SubExprs,
2629 QualType RetTy,
2630 AtomicExpr::AtomicOp Op,
2631 SourceLocation RParenLoc) {
2632 // Just create the expression; there is not any interesting semantic
2633 // analysis here because we can't actually build an AtomicExpr until
2634 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00002635 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002636 RParenLoc);
2637 }
2638
John McCall31f82722010-11-12 08:19:04 +00002639private:
Douglas Gregor14454802011-02-25 02:25:35 +00002640 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2641 QualType ObjectType,
2642 NamedDecl *FirstQualifierInScope,
2643 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002644
2645 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2646 QualType ObjectType,
2647 NamedDecl *FirstQualifierInScope,
2648 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00002649
2650 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
2651 NamedDecl *FirstQualifierInScope,
2652 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002653};
Douglas Gregora16548e2009-08-11 05:31:07 +00002654
Douglas Gregorebe10102009-08-20 07:17:43 +00002655template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002656StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002657 if (!S)
2658 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002659
Douglas Gregorebe10102009-08-20 07:17:43 +00002660 switch (S->getStmtClass()) {
2661 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002662
Douglas Gregorebe10102009-08-20 07:17:43 +00002663 // Transform individual statement nodes
2664#define STMT(Node, Parent) \
2665 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002666#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002667#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002668#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002669
Douglas Gregorebe10102009-08-20 07:17:43 +00002670 // Transform expressions by calling TransformExpr.
2671#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002672#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002673#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002674#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002675 {
John McCalldadc5752010-08-24 06:29:42 +00002676 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002677 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002678 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002679
Richard Smith945f8d32013-01-14 22:39:08 +00002680 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00002681 }
Mike Stump11289f42009-09-09 15:08:12 +00002682 }
2683
John McCallc3007a22010-10-26 07:05:15 +00002684 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002685}
Mike Stump11289f42009-09-09 15:08:12 +00002686
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002687template<typename Derived>
2688OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2689 if (!S)
2690 return S;
2691
2692 switch (S->getClauseKind()) {
2693 default: break;
2694 // Transform individual clause nodes
2695#define OPENMP_CLAUSE(Name, Class) \
2696 case OMPC_ ## Name : \
2697 return getDerived().Transform ## Class(cast<Class>(S));
2698#include "clang/Basic/OpenMPKinds.def"
2699 }
2700
2701 return S;
2702}
2703
Mike Stump11289f42009-09-09 15:08:12 +00002704
Douglas Gregore922c772009-08-04 22:27:00 +00002705template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002706ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002707 if (!E)
2708 return SemaRef.Owned(E);
2709
2710 switch (E->getStmtClass()) {
2711 case Stmt::NoStmtClass: break;
2712#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002713#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002714#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002715 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002716#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002717 }
2718
John McCallc3007a22010-10-26 07:05:15 +00002719 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002720}
2721
2722template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00002723ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2724 bool CXXDirectInit) {
2725 // Initializers are instantiated like expressions, except that various outer
2726 // layers are stripped.
2727 if (!Init)
2728 return SemaRef.Owned(Init);
2729
2730 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2731 Init = ExprTemp->getSubExpr();
2732
Richard Smithe6ca4752013-05-30 22:40:16 +00002733 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2734 Init = MTE->GetTemporaryExpr();
2735
Richard Smithd59b8322012-12-19 01:39:02 +00002736 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2737 Init = Binder->getSubExpr();
2738
2739 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2740 Init = ICE->getSubExprAsWritten();
2741
Richard Smithcc1b96d2013-06-12 22:31:48 +00002742 if (CXXStdInitializerListExpr *ILE =
2743 dyn_cast<CXXStdInitializerListExpr>(Init))
2744 return TransformInitializer(ILE->getSubExpr(), CXXDirectInit);
2745
Richard Smith38a549b2012-12-21 08:13:35 +00002746 // If this is not a direct-initializer, we only need to reconstruct
2747 // InitListExprs. Other forms of copy-initialization will be a no-op if
2748 // the initializer is already the right type.
2749 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2750 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2751 return getDerived().TransformExpr(Init);
2752
2753 // Revert value-initialization back to empty parens.
2754 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2755 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002756 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002757 Parens.getEnd());
2758 }
2759
2760 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2761 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002762 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002763 SourceLocation());
2764
2765 // Revert initialization by constructor back to a parenthesized or braced list
2766 // of expressions. Any other form of initializer can just be reused directly.
2767 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00002768 return getDerived().TransformExpr(Init);
2769
2770 SmallVector<Expr*, 8> NewArgs;
2771 bool ArgChanged = false;
2772 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2773 /*IsCall*/true, NewArgs, &ArgChanged))
2774 return ExprError();
2775
2776 // If this was list initialization, revert to list form.
2777 if (Construct->isListInitialization())
2778 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2779 Construct->getLocEnd(),
2780 Construct->getType());
2781
Richard Smithd59b8322012-12-19 01:39:02 +00002782 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00002783 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smithd59b8322012-12-19 01:39:02 +00002784 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2785 Parens.getEnd());
2786}
2787
2788template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00002789bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2790 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002791 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00002792 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002793 bool *ArgChanged) {
2794 for (unsigned I = 0; I != NumInputs; ++I) {
2795 // If requested, drop call arguments that need to be dropped.
2796 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2797 if (ArgChanged)
2798 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002799
Douglas Gregora3efea12011-01-03 19:04:46 +00002800 break;
2801 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002802
Douglas Gregor968f23a2011-01-03 19:31:53 +00002803 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2804 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00002805
Chris Lattner01cf8db2011-07-20 06:58:45 +00002806 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002807 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2808 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00002809
Douglas Gregor968f23a2011-01-03 19:31:53 +00002810 // Determine whether the set of unexpanded parameter packs can and should
2811 // be expanded.
2812 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002813 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00002814 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2815 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002816 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2817 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00002818 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002819 Expand, RetainExpansion,
2820 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002821 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002822
Douglas Gregor968f23a2011-01-03 19:31:53 +00002823 if (!Expand) {
2824 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00002825 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00002826 // expansion.
2827 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2828 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2829 if (OutPattern.isInvalid())
2830 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002831
2832 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002833 Expansion->getEllipsisLoc(),
2834 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002835 if (Out.isInvalid())
2836 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002837
Douglas Gregor968f23a2011-01-03 19:31:53 +00002838 if (ArgChanged)
2839 *ArgChanged = true;
2840 Outputs.push_back(Out.get());
2841 continue;
2842 }
John McCall542e7c62011-07-06 07:30:07 +00002843
2844 // Record right away that the argument was changed. This needs
2845 // to happen even if the array expands to nothing.
2846 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002847
Douglas Gregor968f23a2011-01-03 19:31:53 +00002848 // The transform has determined that we should perform an elementwise
2849 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002850 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002851 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2852 ExprResult Out = getDerived().TransformExpr(Pattern);
2853 if (Out.isInvalid())
2854 return true;
2855
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002856 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002857 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2858 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002859 if (Out.isInvalid())
2860 return true;
2861 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002862
Douglas Gregor968f23a2011-01-03 19:31:53 +00002863 Outputs.push_back(Out.get());
2864 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002865
Douglas Gregor968f23a2011-01-03 19:31:53 +00002866 continue;
2867 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002868
Richard Smithd59b8322012-12-19 01:39:02 +00002869 ExprResult Result =
2870 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
2871 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00002872 if (Result.isInvalid())
2873 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002874
Douglas Gregora3efea12011-01-03 19:04:46 +00002875 if (Result.get() != Inputs[I] && ArgChanged)
2876 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002877
2878 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00002879 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002880
Douglas Gregora3efea12011-01-03 19:04:46 +00002881 return false;
2882}
2883
2884template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00002885NestedNameSpecifierLoc
2886TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2887 NestedNameSpecifierLoc NNS,
2888 QualType ObjectType,
2889 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00002890 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00002891 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00002892 Qualifier = Qualifier.getPrefix())
2893 Qualifiers.push_back(Qualifier);
2894
2895 CXXScopeSpec SS;
2896 while (!Qualifiers.empty()) {
2897 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2898 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00002899
Douglas Gregor14454802011-02-25 02:25:35 +00002900 switch (QNNS->getKind()) {
2901 case NestedNameSpecifier::Identifier:
Chad Rosier1dcde962012-08-08 18:46:20 +00002902 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregor14454802011-02-25 02:25:35 +00002903 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00002904 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00002905 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00002906 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00002907 FirstQualifierInScope, false))
2908 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002909
Douglas Gregor14454802011-02-25 02:25:35 +00002910 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00002911
Douglas Gregor14454802011-02-25 02:25:35 +00002912 case NestedNameSpecifier::Namespace: {
2913 NamespaceDecl *NS
2914 = cast_or_null<NamespaceDecl>(
2915 getDerived().TransformDecl(
2916 Q.getLocalBeginLoc(),
2917 QNNS->getAsNamespace()));
2918 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2919 break;
2920 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002921
Douglas Gregor14454802011-02-25 02:25:35 +00002922 case NestedNameSpecifier::NamespaceAlias: {
2923 NamespaceAliasDecl *Alias
2924 = cast_or_null<NamespaceAliasDecl>(
2925 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2926 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00002927 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00002928 Q.getLocalEndLoc());
2929 break;
2930 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002931
Douglas Gregor14454802011-02-25 02:25:35 +00002932 case NestedNameSpecifier::Global:
2933 // There is no meaningful transformation that one could perform on the
2934 // global scope.
2935 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2936 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00002937
Douglas Gregor14454802011-02-25 02:25:35 +00002938 case NestedNameSpecifier::TypeSpecWithTemplate:
2939 case NestedNameSpecifier::TypeSpec: {
2940 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2941 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00002942
Douglas Gregor14454802011-02-25 02:25:35 +00002943 if (!TL)
2944 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002945
Douglas Gregor14454802011-02-25 02:25:35 +00002946 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00002947 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00002948 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002949 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00002950 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00002951 if (TL.getType()->isEnumeralType())
2952 SemaRef.Diag(TL.getBeginLoc(),
2953 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00002954 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2955 Q.getLocalEndLoc());
2956 break;
2957 }
Richard Trieude756fb2011-05-07 01:36:37 +00002958 // If the nested-name-specifier is an invalid type def, don't emit an
2959 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00002960 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
2961 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002962 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00002963 << TL.getType() << SS.getRange();
2964 }
Douglas Gregor14454802011-02-25 02:25:35 +00002965 return NestedNameSpecifierLoc();
2966 }
Douglas Gregore16af532011-02-28 18:50:33 +00002967 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002968
Douglas Gregore16af532011-02-28 18:50:33 +00002969 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregor14454802011-02-25 02:25:35 +00002970 FirstQualifierInScope = 0;
Douglas Gregore16af532011-02-28 18:50:33 +00002971 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00002972 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002973
Douglas Gregor14454802011-02-25 02:25:35 +00002974 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00002975 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00002976 !getDerived().AlwaysRebuild())
2977 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00002978
2979 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00002980 // nested-name-specifier, do so.
2981 if (SS.location_size() == NNS.getDataLength() &&
2982 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2983 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2984
2985 // Allocate new nested-name-specifier location information.
2986 return SS.getWithLocInContext(SemaRef.Context);
2987}
2988
2989template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002990DeclarationNameInfo
2991TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002992::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002993 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002994 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002995 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002996
2997 switch (Name.getNameKind()) {
2998 case DeclarationName::Identifier:
2999 case DeclarationName::ObjCZeroArgSelector:
3000 case DeclarationName::ObjCOneArgSelector:
3001 case DeclarationName::ObjCMultiArgSelector:
3002 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003003 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003004 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003005 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003006
Douglas Gregorf816bd72009-09-03 22:13:48 +00003007 case DeclarationName::CXXConstructorName:
3008 case DeclarationName::CXXDestructorName:
3009 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003010 TypeSourceInfo *NewTInfo;
3011 CanQualType NewCanTy;
3012 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003013 NewTInfo = getDerived().TransformType(OldTInfo);
3014 if (!NewTInfo)
3015 return DeclarationNameInfo();
3016 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003017 }
3018 else {
3019 NewTInfo = 0;
3020 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003021 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003022 if (NewT.isNull())
3023 return DeclarationNameInfo();
3024 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3025 }
Mike Stump11289f42009-09-09 15:08:12 +00003026
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003027 DeclarationName NewName
3028 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3029 NewCanTy);
3030 DeclarationNameInfo NewNameInfo(NameInfo);
3031 NewNameInfo.setName(NewName);
3032 NewNameInfo.setNamedTypeInfo(NewTInfo);
3033 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003034 }
Mike Stump11289f42009-09-09 15:08:12 +00003035 }
3036
David Blaikie83d382b2011-09-23 05:06:16 +00003037 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003038}
3039
3040template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003041TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003042TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3043 TemplateName Name,
3044 SourceLocation NameLoc,
3045 QualType ObjectType,
3046 NamedDecl *FirstQualifierInScope) {
3047 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3048 TemplateDecl *Template = QTN->getTemplateDecl();
3049 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003050
Douglas Gregor9db53502011-03-02 18:07:45 +00003051 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003052 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003053 Template));
3054 if (!TransTemplate)
3055 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003056
Douglas Gregor9db53502011-03-02 18:07:45 +00003057 if (!getDerived().AlwaysRebuild() &&
3058 SS.getScopeRep() == QTN->getQualifier() &&
3059 TransTemplate == Template)
3060 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003061
Douglas Gregor9db53502011-03-02 18:07:45 +00003062 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3063 TransTemplate);
3064 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003065
Douglas Gregor9db53502011-03-02 18:07:45 +00003066 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3067 if (SS.getScopeRep()) {
3068 // These apply to the scope specifier, not the template.
3069 ObjectType = QualType();
3070 FirstQualifierInScope = 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00003071 }
3072
Douglas Gregor9db53502011-03-02 18:07:45 +00003073 if (!getDerived().AlwaysRebuild() &&
3074 SS.getScopeRep() == DTN->getQualifier() &&
3075 ObjectType.isNull())
3076 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003077
Douglas Gregor9db53502011-03-02 18:07:45 +00003078 if (DTN->isIdentifier()) {
3079 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003080 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003081 NameLoc,
3082 ObjectType,
3083 FirstQualifierInScope);
3084 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003085
Douglas Gregor9db53502011-03-02 18:07:45 +00003086 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3087 ObjectType);
3088 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003089
Douglas Gregor9db53502011-03-02 18:07:45 +00003090 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3091 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003092 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003093 Template));
3094 if (!TransTemplate)
3095 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003096
Douglas Gregor9db53502011-03-02 18:07:45 +00003097 if (!getDerived().AlwaysRebuild() &&
3098 TransTemplate == Template)
3099 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003100
Douglas Gregor9db53502011-03-02 18:07:45 +00003101 return TemplateName(TransTemplate);
3102 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003103
Douglas Gregor9db53502011-03-02 18:07:45 +00003104 if (SubstTemplateTemplateParmPackStorage *SubstPack
3105 = Name.getAsSubstTemplateTemplateParmPack()) {
3106 TemplateTemplateParmDecl *TransParam
3107 = cast_or_null<TemplateTemplateParmDecl>(
3108 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3109 if (!TransParam)
3110 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003111
Douglas Gregor9db53502011-03-02 18:07:45 +00003112 if (!getDerived().AlwaysRebuild() &&
3113 TransParam == SubstPack->getParameterPack())
3114 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003115
3116 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003117 SubstPack->getArgumentPack());
3118 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003119
Douglas Gregor9db53502011-03-02 18:07:45 +00003120 // These should be getting filtered out before they reach the AST.
3121 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003122}
3123
3124template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003125void TreeTransform<Derived>::InventTemplateArgumentLoc(
3126 const TemplateArgument &Arg,
3127 TemplateArgumentLoc &Output) {
3128 SourceLocation Loc = getDerived().getBaseLocation();
3129 switch (Arg.getKind()) {
3130 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003131 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003132 break;
3133
3134 case TemplateArgument::Type:
3135 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003136 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003137
John McCall0ad16662009-10-29 08:12:44 +00003138 break;
3139
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003140 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003141 case TemplateArgument::TemplateExpansion: {
3142 NestedNameSpecifierLocBuilder Builder;
3143 TemplateName Template = Arg.getAsTemplate();
3144 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3145 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3146 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3147 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003148
Douglas Gregor9d802122011-03-02 17:09:35 +00003149 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003150 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003151 Builder.getWithLocInContext(SemaRef.Context),
3152 Loc);
3153 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003154 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003155 Builder.getWithLocInContext(SemaRef.Context),
3156 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003157
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003158 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003159 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003160
John McCall0ad16662009-10-29 08:12:44 +00003161 case TemplateArgument::Expression:
3162 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3163 break;
3164
3165 case TemplateArgument::Declaration:
3166 case TemplateArgument::Integral:
3167 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003168 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003169 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003170 break;
3171 }
3172}
3173
3174template<typename Derived>
3175bool TreeTransform<Derived>::TransformTemplateArgument(
3176 const TemplateArgumentLoc &Input,
3177 TemplateArgumentLoc &Output) {
3178 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003179 switch (Arg.getKind()) {
3180 case TemplateArgument::Null:
3181 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003182 case TemplateArgument::Pack:
3183 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003184 case TemplateArgument::NullPtr:
3185 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003186
Douglas Gregore922c772009-08-04 22:27:00 +00003187 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003188 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00003189 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00003190 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003191
3192 DI = getDerived().TransformType(DI);
3193 if (!DI) return true;
3194
3195 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3196 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003197 }
Mike Stump11289f42009-09-09 15:08:12 +00003198
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003199 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003200 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3201 if (QualifierLoc) {
3202 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3203 if (!QualifierLoc)
3204 return true;
3205 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003206
Douglas Gregordf846d12011-03-02 18:46:51 +00003207 CXXScopeSpec SS;
3208 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003209 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003210 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3211 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003212 if (Template.isNull())
3213 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003214
Douglas Gregor9d802122011-03-02 17:09:35 +00003215 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003216 Input.getTemplateNameLoc());
3217 return false;
3218 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003219
3220 case TemplateArgument::TemplateExpansion:
3221 llvm_unreachable("Caller should expand pack expansions");
3222
Douglas Gregore922c772009-08-04 22:27:00 +00003223 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003224 // Template argument expressions are constant expressions.
Mike Stump11289f42009-09-09 15:08:12 +00003225 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smith764d2fe2011-12-20 02:08:33 +00003226 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003227
John McCall0ad16662009-10-29 08:12:44 +00003228 Expr *InputExpr = Input.getSourceExpression();
3229 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3230
Chris Lattnercdb591a2011-04-25 20:37:58 +00003231 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003232 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003233 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00003234 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00003235 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003236 }
Douglas Gregore922c772009-08-04 22:27:00 +00003237 }
Mike Stump11289f42009-09-09 15:08:12 +00003238
Douglas Gregore922c772009-08-04 22:27:00 +00003239 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003240 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003241}
3242
Douglas Gregorfe921a72010-12-20 23:36:19 +00003243/// \brief Iterator adaptor that invents template argument location information
3244/// for each of the template arguments in its underlying iterator.
3245template<typename Derived, typename InputIterator>
3246class TemplateArgumentLocInventIterator {
3247 TreeTransform<Derived> &Self;
3248 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003249
Douglas Gregorfe921a72010-12-20 23:36:19 +00003250public:
3251 typedef TemplateArgumentLoc value_type;
3252 typedef TemplateArgumentLoc reference;
3253 typedef typename std::iterator_traits<InputIterator>::difference_type
3254 difference_type;
3255 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003256
Douglas Gregorfe921a72010-12-20 23:36:19 +00003257 class pointer {
3258 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003259
Douglas Gregorfe921a72010-12-20 23:36:19 +00003260 public:
3261 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003262
Douglas Gregorfe921a72010-12-20 23:36:19 +00003263 const TemplateArgumentLoc *operator->() const { return &Arg; }
3264 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003265
Douglas Gregorfe921a72010-12-20 23:36:19 +00003266 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003267
Douglas Gregorfe921a72010-12-20 23:36:19 +00003268 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3269 InputIterator Iter)
3270 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003271
Douglas Gregorfe921a72010-12-20 23:36:19 +00003272 TemplateArgumentLocInventIterator &operator++() {
3273 ++Iter;
3274 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003275 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003276
Douglas Gregorfe921a72010-12-20 23:36:19 +00003277 TemplateArgumentLocInventIterator operator++(int) {
3278 TemplateArgumentLocInventIterator Old(*this);
3279 ++(*this);
3280 return Old;
3281 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003282
Douglas Gregorfe921a72010-12-20 23:36:19 +00003283 reference operator*() const {
3284 TemplateArgumentLoc Result;
3285 Self.InventTemplateArgumentLoc(*Iter, Result);
3286 return Result;
3287 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003288
Douglas Gregorfe921a72010-12-20 23:36:19 +00003289 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003290
Douglas Gregorfe921a72010-12-20 23:36:19 +00003291 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3292 const TemplateArgumentLocInventIterator &Y) {
3293 return X.Iter == Y.Iter;
3294 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003295
Douglas Gregorfe921a72010-12-20 23:36:19 +00003296 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3297 const TemplateArgumentLocInventIterator &Y) {
3298 return X.Iter != Y.Iter;
3299 }
3300};
Chad Rosier1dcde962012-08-08 18:46:20 +00003301
Douglas Gregor42cafa82010-12-20 17:42:22 +00003302template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003303template<typename InputIterator>
3304bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3305 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00003306 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003307 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003308 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003309 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003310
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003311 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3312 // Unpack argument packs, which we translate them into separate
3313 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003314 // FIXME: We could do much better if we could guarantee that the
3315 // TemplateArgumentLocInfo for the pack expansion would be usable for
3316 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003317 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003318 TemplateArgument::pack_iterator>
3319 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003320 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003321 In.getArgument().pack_begin()),
3322 PackLocIterator(*this,
3323 In.getArgument().pack_end()),
3324 Outputs))
3325 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003326
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003327 continue;
3328 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003329
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003330 if (In.getArgument().isPackExpansion()) {
3331 // We have a pack expansion, for which we will be substituting into
3332 // the pattern.
3333 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003334 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003335 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003336 = getSema().getTemplateArgumentPackExpansionPattern(
3337 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003338
Chris Lattner01cf8db2011-07-20 06:58:45 +00003339 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003340 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3341 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003342
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003343 // Determine whether the set of unexpanded parameter packs can and should
3344 // be expanded.
3345 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003346 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003347 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003348 if (getDerived().TryExpandParameterPacks(Ellipsis,
3349 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003350 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003351 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003352 RetainExpansion,
3353 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003354 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003355
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003356 if (!Expand) {
3357 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003358 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003359 // expansion.
3360 TemplateArgumentLoc OutPattern;
3361 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3362 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3363 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003364
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003365 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3366 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003367 if (Out.getArgument().isNull())
3368 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003369
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003370 Outputs.addArgument(Out);
3371 continue;
3372 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003373
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003374 // The transform has determined that we should perform an elementwise
3375 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003376 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003377 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3378
3379 if (getDerived().TransformTemplateArgument(Pattern, Out))
3380 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003381
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003382 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003383 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3384 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003385 if (Out.getArgument().isNull())
3386 return true;
3387 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003388
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003389 Outputs.addArgument(Out);
3390 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003391
Douglas Gregor48d24112011-01-10 20:53:55 +00003392 // If we're supposed to retain a pack expansion, do so by temporarily
3393 // forgetting the partially-substituted parameter pack.
3394 if (RetainExpansion) {
3395 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003396
Douglas Gregor48d24112011-01-10 20:53:55 +00003397 if (getDerived().TransformTemplateArgument(Pattern, Out))
3398 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003399
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003400 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3401 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003402 if (Out.getArgument().isNull())
3403 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003404
Douglas Gregor48d24112011-01-10 20:53:55 +00003405 Outputs.addArgument(Out);
3406 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003407
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003408 continue;
3409 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003410
3411 // The simple case:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003412 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003413 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003414
Douglas Gregor42cafa82010-12-20 17:42:22 +00003415 Outputs.addArgument(Out);
3416 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003417
Douglas Gregor42cafa82010-12-20 17:42:22 +00003418 return false;
3419
3420}
3421
Douglas Gregord6ff3322009-08-04 16:50:30 +00003422//===----------------------------------------------------------------------===//
3423// Type transformation
3424//===----------------------------------------------------------------------===//
3425
3426template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003427QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003428 if (getDerived().AlreadyTransformed(T))
3429 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003430
John McCall550e0c22009-10-21 00:40:46 +00003431 // Temporary workaround. All of these transformations should
3432 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003433 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3434 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003435
John McCall31f82722010-11-12 08:19:04 +00003436 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003437
John McCall550e0c22009-10-21 00:40:46 +00003438 if (!NewDI)
3439 return QualType();
3440
3441 return NewDI->getType();
3442}
3443
3444template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003445TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003446 // Refine the base location to the type's location.
3447 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3448 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003449 if (getDerived().AlreadyTransformed(DI->getType()))
3450 return DI;
3451
3452 TypeLocBuilder TLB;
3453
3454 TypeLoc TL = DI->getTypeLoc();
3455 TLB.reserve(TL.getFullDataSize());
3456
John McCall31f82722010-11-12 08:19:04 +00003457 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003458 if (Result.isNull())
3459 return 0;
3460
John McCallbcd03502009-12-07 02:54:59 +00003461 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003462}
3463
3464template<typename Derived>
3465QualType
John McCall31f82722010-11-12 08:19:04 +00003466TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003467 switch (T.getTypeLocClass()) {
3468#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003469#define TYPELOC(CLASS, PARENT) \
3470 case TypeLoc::CLASS: \
3471 return getDerived().Transform##CLASS##Type(TLB, \
3472 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003473#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003474 }
Mike Stump11289f42009-09-09 15:08:12 +00003475
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003476 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003477}
3478
3479/// FIXME: By default, this routine adds type qualifiers only to types
3480/// that can have qualifiers, and silently suppresses those qualifiers
3481/// that are not permitted (e.g., qualifiers on reference or function
3482/// types). This is the right thing for template instantiation, but
3483/// probably not for other clients.
3484template<typename Derived>
3485QualType
3486TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003487 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003488 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003489
John McCall31f82722010-11-12 08:19:04 +00003490 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003491 if (Result.isNull())
3492 return QualType();
3493
3494 // Silently suppress qualifiers if the result type can't be qualified.
3495 // FIXME: this is the right thing for template instantiation, but
3496 // probably not for other clients.
3497 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003498 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003499
John McCall31168b02011-06-15 23:02:42 +00003500 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003501 // resulting type.
3502 if (Quals.hasObjCLifetime()) {
3503 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3504 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003505 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003506 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003507 // A lifetime qualifier applied to a substituted template parameter
3508 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003509 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003510 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003511 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3512 QualType Replacement = SubstTypeParam->getReplacementType();
3513 Qualifiers Qs = Replacement.getQualifiers();
3514 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003515 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003516 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3517 Qs);
3518 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003519 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003520 Replacement);
3521 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003522 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3523 // 'auto' types behave the same way as template parameters.
3524 QualType Deduced = AutoTy->getDeducedType();
3525 Qualifiers Qs = Deduced.getQualifiers();
3526 Qs.removeObjCLifetime();
3527 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3528 Qs);
Faisal Vali2b391ab2013-09-26 19:54:12 +00003529 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3530 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003531 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003532 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003533 // Otherwise, complain about the addition of a qualifier to an
3534 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003535 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003536 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003537 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003538
Douglas Gregore46db902011-06-17 22:11:49 +00003539 Quals.removeObjCLifetime();
3540 }
3541 }
3542 }
John McCallcb0f89a2010-06-05 06:41:15 +00003543 if (!Quals.empty()) {
3544 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003545 // BuildQualifiedType might not add qualifiers if they are invalid.
3546 if (Result.hasLocalQualifiers())
3547 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003548 // No location information to preserve.
3549 }
John McCall550e0c22009-10-21 00:40:46 +00003550
3551 return Result;
3552}
3553
Douglas Gregor14454802011-02-25 02:25:35 +00003554template<typename Derived>
3555TypeLoc
3556TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3557 QualType ObjectType,
3558 NamedDecl *UnqualLookup,
3559 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003560 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00003561 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00003562
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003563 TypeSourceInfo *TSI =
3564 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3565 if (TSI)
3566 return TSI->getTypeLoc();
3567 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00003568}
3569
Douglas Gregor579c15f2011-03-02 18:32:08 +00003570template<typename Derived>
3571TypeSourceInfo *
3572TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3573 QualType ObjectType,
3574 NamedDecl *UnqualLookup,
3575 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003576 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00003577 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00003578
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003579 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
3580 UnqualLookup, SS);
3581}
3582
3583template <typename Derived>
3584TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
3585 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
3586 CXXScopeSpec &SS) {
3587 QualType T = TL.getType();
3588 assert(!getDerived().AlreadyTransformed(T));
3589
Douglas Gregor579c15f2011-03-02 18:32:08 +00003590 TypeLocBuilder TLB;
3591 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00003592
Douglas Gregor579c15f2011-03-02 18:32:08 +00003593 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003594 TemplateSpecializationTypeLoc SpecTL =
3595 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003596
Douglas Gregor579c15f2011-03-02 18:32:08 +00003597 TemplateName Template
3598 = getDerived().TransformTemplateName(SS,
3599 SpecTL.getTypePtr()->getTemplateName(),
3600 SpecTL.getTemplateNameLoc(),
3601 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00003602 if (Template.isNull())
Douglas Gregor579c15f2011-03-02 18:32:08 +00003603 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00003604
3605 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003606 Template);
3607 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003608 DependentTemplateSpecializationTypeLoc SpecTL =
3609 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003610
Douglas Gregor579c15f2011-03-02 18:32:08 +00003611 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00003612 = getDerived().RebuildTemplateName(SS,
3613 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00003614 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00003615 ObjectType, UnqualLookup);
3616 if (Template.isNull())
3617 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00003618
3619 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003620 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003621 Template,
3622 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003623 } else {
3624 // Nothing special needs to be done for these.
3625 Result = getDerived().TransformType(TLB, TL);
3626 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003627
3628 if (Result.isNull())
Douglas Gregor579c15f2011-03-02 18:32:08 +00003629 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00003630
Douglas Gregor579c15f2011-03-02 18:32:08 +00003631 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3632}
3633
John McCall550e0c22009-10-21 00:40:46 +00003634template <class TyLoc> static inline
3635QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3636 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3637 NewT.setNameLoc(T.getNameLoc());
3638 return T.getType();
3639}
3640
John McCall550e0c22009-10-21 00:40:46 +00003641template<typename Derived>
3642QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003643 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003644 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3645 NewT.setBuiltinLoc(T.getBuiltinLoc());
3646 if (T.needsExtraLocalData())
3647 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3648 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003649}
Mike Stump11289f42009-09-09 15:08:12 +00003650
Douglas Gregord6ff3322009-08-04 16:50:30 +00003651template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003652QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003653 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003654 // FIXME: recurse?
3655 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003656}
Mike Stump11289f42009-09-09 15:08:12 +00003657
Reid Kleckner0503a872013-12-05 01:23:43 +00003658template <typename Derived>
3659QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
3660 AdjustedTypeLoc TL) {
3661 // Adjustments applied during transformation are handled elsewhere.
3662 return getDerived().TransformType(TLB, TL.getOriginalLoc());
3663}
3664
Douglas Gregord6ff3322009-08-04 16:50:30 +00003665template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00003666QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3667 DecayedTypeLoc TL) {
3668 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3669 if (OriginalType.isNull())
3670 return QualType();
3671
3672 QualType Result = TL.getType();
3673 if (getDerived().AlwaysRebuild() ||
3674 OriginalType != TL.getOriginalLoc().getType())
3675 Result = SemaRef.Context.getDecayedType(OriginalType);
3676 TLB.push<DecayedTypeLoc>(Result);
3677 // Nothing to set for DecayedTypeLoc.
3678 return Result;
3679}
3680
3681template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003682QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003683 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003684 QualType PointeeType
3685 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003686 if (PointeeType.isNull())
3687 return QualType();
3688
3689 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003690 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003691 // A dependent pointer type 'T *' has is being transformed such
3692 // that an Objective-C class type is being replaced for 'T'. The
3693 // resulting pointer type is an ObjCObjectPointerType, not a
3694 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003695 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00003696
John McCall8b07ec22010-05-15 11:32:37 +00003697 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3698 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003699 return Result;
3700 }
John McCall31f82722010-11-12 08:19:04 +00003701
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003702 if (getDerived().AlwaysRebuild() ||
3703 PointeeType != TL.getPointeeLoc().getType()) {
3704 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3705 if (Result.isNull())
3706 return QualType();
3707 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003708
John McCall31168b02011-06-15 23:02:42 +00003709 // Objective-C ARC can add lifetime qualifiers to the type that we're
3710 // pointing to.
3711 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00003712
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003713 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3714 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00003715 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003716}
Mike Stump11289f42009-09-09 15:08:12 +00003717
3718template<typename Derived>
3719QualType
John McCall550e0c22009-10-21 00:40:46 +00003720TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003721 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003722 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00003723 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3724 if (PointeeType.isNull())
3725 return QualType();
3726
3727 QualType Result = TL.getType();
3728 if (getDerived().AlwaysRebuild() ||
3729 PointeeType != TL.getPointeeLoc().getType()) {
3730 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003731 TL.getSigilLoc());
3732 if (Result.isNull())
3733 return QualType();
3734 }
3735
Douglas Gregor049211a2010-04-22 16:50:51 +00003736 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003737 NewT.setSigilLoc(TL.getSigilLoc());
3738 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003739}
3740
John McCall70dd5f62009-10-30 00:06:24 +00003741/// Transforms a reference type. Note that somewhat paradoxically we
3742/// don't care whether the type itself is an l-value type or an r-value
3743/// type; we only care if the type was *written* as an l-value type
3744/// or an r-value type.
3745template<typename Derived>
3746QualType
3747TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003748 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003749 const ReferenceType *T = TL.getTypePtr();
3750
3751 // Note that this works with the pointee-as-written.
3752 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3753 if (PointeeType.isNull())
3754 return QualType();
3755
3756 QualType Result = TL.getType();
3757 if (getDerived().AlwaysRebuild() ||
3758 PointeeType != T->getPointeeTypeAsWritten()) {
3759 Result = getDerived().RebuildReferenceType(PointeeType,
3760 T->isSpelledAsLValue(),
3761 TL.getSigilLoc());
3762 if (Result.isNull())
3763 return QualType();
3764 }
3765
John McCall31168b02011-06-15 23:02:42 +00003766 // Objective-C ARC can add lifetime qualifiers to the type that we're
3767 // referring to.
3768 TLB.TypeWasModifiedSafely(
3769 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3770
John McCall70dd5f62009-10-30 00:06:24 +00003771 // r-value references can be rebuilt as l-value references.
3772 ReferenceTypeLoc NewTL;
3773 if (isa<LValueReferenceType>(Result))
3774 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3775 else
3776 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3777 NewTL.setSigilLoc(TL.getSigilLoc());
3778
3779 return Result;
3780}
3781
Mike Stump11289f42009-09-09 15:08:12 +00003782template<typename Derived>
3783QualType
John McCall550e0c22009-10-21 00:40:46 +00003784TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003785 LValueReferenceTypeLoc TL) {
3786 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003787}
3788
Mike Stump11289f42009-09-09 15:08:12 +00003789template<typename Derived>
3790QualType
John McCall550e0c22009-10-21 00:40:46 +00003791TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003792 RValueReferenceTypeLoc TL) {
3793 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003794}
Mike Stump11289f42009-09-09 15:08:12 +00003795
Douglas Gregord6ff3322009-08-04 16:50:30 +00003796template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003797QualType
John McCall550e0c22009-10-21 00:40:46 +00003798TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003799 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003800 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003801 if (PointeeType.isNull())
3802 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003803
Abramo Bagnara509357842011-03-05 14:42:21 +00003804 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3805 TypeSourceInfo* NewClsTInfo = 0;
3806 if (OldClsTInfo) {
3807 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3808 if (!NewClsTInfo)
3809 return QualType();
3810 }
3811
3812 const MemberPointerType *T = TL.getTypePtr();
3813 QualType OldClsType = QualType(T->getClass(), 0);
3814 QualType NewClsType;
3815 if (NewClsTInfo)
3816 NewClsType = NewClsTInfo->getType();
3817 else {
3818 NewClsType = getDerived().TransformType(OldClsType);
3819 if (NewClsType.isNull())
3820 return QualType();
3821 }
Mike Stump11289f42009-09-09 15:08:12 +00003822
John McCall550e0c22009-10-21 00:40:46 +00003823 QualType Result = TL.getType();
3824 if (getDerived().AlwaysRebuild() ||
3825 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00003826 NewClsType != OldClsType) {
3827 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00003828 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003829 if (Result.isNull())
3830 return QualType();
3831 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003832
Reid Kleckner0503a872013-12-05 01:23:43 +00003833 // If we had to adjust the pointee type when building a member pointer, make
3834 // sure to push TypeLoc info for it.
3835 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
3836 if (MPT && PointeeType != MPT->getPointeeType()) {
3837 assert(isa<AdjustedType>(MPT->getPointeeType()));
3838 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
3839 }
3840
John McCall550e0c22009-10-21 00:40:46 +00003841 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3842 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00003843 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00003844
3845 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003846}
3847
Mike Stump11289f42009-09-09 15:08:12 +00003848template<typename Derived>
3849QualType
John McCall550e0c22009-10-21 00:40:46 +00003850TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003851 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003852 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003853 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003854 if (ElementType.isNull())
3855 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003856
John McCall550e0c22009-10-21 00:40:46 +00003857 QualType Result = TL.getType();
3858 if (getDerived().AlwaysRebuild() ||
3859 ElementType != T->getElementType()) {
3860 Result = getDerived().RebuildConstantArrayType(ElementType,
3861 T->getSizeModifier(),
3862 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003863 T->getIndexTypeCVRQualifiers(),
3864 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003865 if (Result.isNull())
3866 return QualType();
3867 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00003868
3869 // We might have either a ConstantArrayType or a VariableArrayType now:
3870 // a ConstantArrayType is allowed to have an element type which is a
3871 // VariableArrayType if the type is dependent. Fortunately, all array
3872 // types have the same location layout.
3873 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00003874 NewTL.setLBracketLoc(TL.getLBracketLoc());
3875 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003876
John McCall550e0c22009-10-21 00:40:46 +00003877 Expr *Size = TL.getSizeExpr();
3878 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003879 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3880 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00003881 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanc6237c62012-02-29 03:16:56 +00003882 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCall550e0c22009-10-21 00:40:46 +00003883 }
3884 NewTL.setSizeExpr(Size);
3885
3886 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003887}
Mike Stump11289f42009-09-09 15:08:12 +00003888
Douglas Gregord6ff3322009-08-04 16:50:30 +00003889template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003890QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003891 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003892 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003893 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003894 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003895 if (ElementType.isNull())
3896 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003897
John McCall550e0c22009-10-21 00:40:46 +00003898 QualType Result = TL.getType();
3899 if (getDerived().AlwaysRebuild() ||
3900 ElementType != T->getElementType()) {
3901 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003902 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003903 T->getIndexTypeCVRQualifiers(),
3904 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003905 if (Result.isNull())
3906 return QualType();
3907 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003908
John McCall550e0c22009-10-21 00:40:46 +00003909 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3910 NewTL.setLBracketLoc(TL.getLBracketLoc());
3911 NewTL.setRBracketLoc(TL.getRBracketLoc());
3912 NewTL.setSizeExpr(0);
3913
3914 return Result;
3915}
3916
3917template<typename Derived>
3918QualType
3919TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003920 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003921 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003922 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3923 if (ElementType.isNull())
3924 return QualType();
3925
John McCalldadc5752010-08-24 06:29:42 +00003926 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003927 = getDerived().TransformExpr(T->getSizeExpr());
3928 if (SizeResult.isInvalid())
3929 return QualType();
3930
John McCallb268a282010-08-23 23:25:46 +00003931 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003932
3933 QualType Result = TL.getType();
3934 if (getDerived().AlwaysRebuild() ||
3935 ElementType != T->getElementType() ||
3936 Size != T->getSizeExpr()) {
3937 Result = getDerived().RebuildVariableArrayType(ElementType,
3938 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003939 Size,
John McCall550e0c22009-10-21 00:40:46 +00003940 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003941 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003942 if (Result.isNull())
3943 return QualType();
3944 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003945
Serge Pavlov774c6d02014-02-06 03:49:11 +00003946 // We might have constant size array now, but fortunately it has the same
3947 // location layout.
3948 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00003949 NewTL.setLBracketLoc(TL.getLBracketLoc());
3950 NewTL.setRBracketLoc(TL.getRBracketLoc());
3951 NewTL.setSizeExpr(Size);
3952
3953 return Result;
3954}
3955
3956template<typename Derived>
3957QualType
3958TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003959 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003960 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003961 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3962 if (ElementType.isNull())
3963 return QualType();
3964
Richard Smith764d2fe2011-12-20 02:08:33 +00003965 // Array bounds are constant expressions.
3966 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3967 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00003968
John McCall33ddac02011-01-19 10:06:00 +00003969 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3970 Expr *origSize = TL.getSizeExpr();
3971 if (!origSize) origSize = T->getSizeExpr();
3972
3973 ExprResult sizeResult
3974 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003975 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00003976 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00003977 return QualType();
3978
John McCall33ddac02011-01-19 10:06:00 +00003979 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00003980
3981 QualType Result = TL.getType();
3982 if (getDerived().AlwaysRebuild() ||
3983 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00003984 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00003985 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3986 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00003987 size,
John McCall550e0c22009-10-21 00:40:46 +00003988 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003989 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003990 if (Result.isNull())
3991 return QualType();
3992 }
John McCall550e0c22009-10-21 00:40:46 +00003993
3994 // We might have any sort of array type now, but fortunately they
3995 // all have the same location layout.
3996 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3997 NewTL.setLBracketLoc(TL.getLBracketLoc());
3998 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00003999 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004000
4001 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004002}
Mike Stump11289f42009-09-09 15:08:12 +00004003
4004template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004005QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004006 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004007 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004008 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004009
4010 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004011 QualType ElementType = getDerived().TransformType(T->getElementType());
4012 if (ElementType.isNull())
4013 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004014
Richard Smith764d2fe2011-12-20 02:08:33 +00004015 // Vector sizes are constant expressions.
4016 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4017 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004018
John McCalldadc5752010-08-24 06:29:42 +00004019 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004020 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004021 if (Size.isInvalid())
4022 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004023
John McCall550e0c22009-10-21 00:40:46 +00004024 QualType Result = TL.getType();
4025 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004026 ElementType != T->getElementType() ||
4027 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004028 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00004029 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004030 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004031 if (Result.isNull())
4032 return QualType();
4033 }
John McCall550e0c22009-10-21 00:40:46 +00004034
4035 // Result might be dependent or not.
4036 if (isa<DependentSizedExtVectorType>(Result)) {
4037 DependentSizedExtVectorTypeLoc NewTL
4038 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4039 NewTL.setNameLoc(TL.getNameLoc());
4040 } else {
4041 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4042 NewTL.setNameLoc(TL.getNameLoc());
4043 }
4044
4045 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004046}
Mike Stump11289f42009-09-09 15:08:12 +00004047
4048template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004049QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004050 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004051 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004052 QualType ElementType = getDerived().TransformType(T->getElementType());
4053 if (ElementType.isNull())
4054 return QualType();
4055
John McCall550e0c22009-10-21 00:40:46 +00004056 QualType Result = TL.getType();
4057 if (getDerived().AlwaysRebuild() ||
4058 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004059 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004060 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004061 if (Result.isNull())
4062 return QualType();
4063 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004064
John McCall550e0c22009-10-21 00:40:46 +00004065 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4066 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004067
John McCall550e0c22009-10-21 00:40:46 +00004068 return Result;
4069}
4070
4071template<typename Derived>
4072QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004073 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004074 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004075 QualType ElementType = getDerived().TransformType(T->getElementType());
4076 if (ElementType.isNull())
4077 return QualType();
4078
4079 QualType Result = TL.getType();
4080 if (getDerived().AlwaysRebuild() ||
4081 ElementType != T->getElementType()) {
4082 Result = getDerived().RebuildExtVectorType(ElementType,
4083 T->getNumElements(),
4084 /*FIXME*/ SourceLocation());
4085 if (Result.isNull())
4086 return QualType();
4087 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004088
John McCall550e0c22009-10-21 00:40:46 +00004089 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4090 NewTL.setNameLoc(TL.getNameLoc());
4091
4092 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004093}
Mike Stump11289f42009-09-09 15:08:12 +00004094
David Blaikie05785d12013-02-20 22:23:23 +00004095template <typename Derived>
4096ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4097 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4098 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004099 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor715e4612011-01-14 22:40:04 +00004100 TypeSourceInfo *NewDI = 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00004101
Douglas Gregor715e4612011-01-14 22:40:04 +00004102 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004103 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004104 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004105 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004106 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004107
Douglas Gregor715e4612011-01-14 22:40:04 +00004108 TypeLocBuilder TLB;
4109 TypeLoc NewTL = OldDI->getTypeLoc();
4110 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004111
4112 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004113 OldExpansionTL.getPatternLoc());
4114 if (Result.isNull())
4115 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00004116
4117 Result = RebuildPackExpansionType(Result,
4118 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004119 OldExpansionTL.getEllipsisLoc(),
4120 NumExpansions);
4121 if (Result.isNull())
4122 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00004123
Douglas Gregor715e4612011-01-14 22:40:04 +00004124 PackExpansionTypeLoc NewExpansionTL
4125 = TLB.push<PackExpansionTypeLoc>(Result);
4126 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4127 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4128 } else
4129 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004130 if (!NewDI)
4131 return 0;
4132
John McCall8fb0d9d2011-05-01 22:35:37 +00004133 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004134 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004135
4136 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4137 OldParm->getDeclContext(),
4138 OldParm->getInnerLocStart(),
4139 OldParm->getLocation(),
4140 OldParm->getIdentifier(),
4141 NewDI->getType(),
4142 NewDI,
4143 OldParm->getStorageClass(),
John McCall8fb0d9d2011-05-01 22:35:37 +00004144 /* DefArg */ NULL);
4145 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4146 OldParm->getFunctionScopeIndex() + indexAdjustment);
4147 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004148}
4149
4150template<typename Derived>
4151bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004152 TransformFunctionTypeParams(SourceLocation Loc,
4153 ParmVarDecl **Params, unsigned NumParams,
4154 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004155 SmallVectorImpl<QualType> &OutParamTypes,
4156 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004157 int indexAdjustment = 0;
4158
Douglas Gregordd472162011-01-07 00:20:55 +00004159 for (unsigned i = 0; i != NumParams; ++i) {
4160 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004161 assert(OldParm->getFunctionScopeIndex() == i);
4162
David Blaikie05785d12013-02-20 22:23:23 +00004163 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004164 ParmVarDecl *NewParm = 0;
Douglas Gregor5499af42011-01-05 23:12:31 +00004165 if (OldParm->isParameterPack()) {
4166 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004167 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004168
Douglas Gregor5499af42011-01-05 23:12:31 +00004169 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004170 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004171 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004172 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4173 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004174 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4175
Douglas Gregor5499af42011-01-05 23:12:31 +00004176 // Determine whether we should expand the parameter packs.
4177 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004178 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004179 Optional<unsigned> OrigNumExpansions =
4180 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004181 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004182 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4183 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004184 Unexpanded,
4185 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004186 RetainExpansion,
4187 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004188 return true;
4189 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004190
Douglas Gregor5499af42011-01-05 23:12:31 +00004191 if (ShouldExpand) {
4192 // Expand the function parameter pack into multiple, separate
4193 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004194 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004195 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004196 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004197 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004198 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004199 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004200 OrigNumExpansions,
4201 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004202 if (!NewParm)
4203 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004204
Douglas Gregordd472162011-01-07 00:20:55 +00004205 OutParamTypes.push_back(NewParm->getType());
4206 if (PVars)
4207 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004208 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004209
4210 // If we're supposed to retain a pack expansion, do so by temporarily
4211 // forgetting the partially-substituted parameter pack.
4212 if (RetainExpansion) {
4213 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004214 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004215 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004216 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004217 OrigNumExpansions,
4218 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004219 if (!NewParm)
4220 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004221
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004222 OutParamTypes.push_back(NewParm->getType());
4223 if (PVars)
4224 PVars->push_back(NewParm);
4225 }
4226
John McCall8fb0d9d2011-05-01 22:35:37 +00004227 // The next parameter should have the same adjustment as the
4228 // last thing we pushed, but we post-incremented indexAdjustment
4229 // on every push. Also, if we push nothing, the adjustment should
4230 // go down by one.
4231 indexAdjustment--;
4232
Douglas Gregor5499af42011-01-05 23:12:31 +00004233 // We're done with the pack expansion.
4234 continue;
4235 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004236
4237 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004238 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004239 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4240 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004241 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004242 NumExpansions,
4243 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004244 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004245 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004246 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004247 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004248
John McCall58f10c32010-03-11 09:03:00 +00004249 if (!NewParm)
4250 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004251
Douglas Gregordd472162011-01-07 00:20:55 +00004252 OutParamTypes.push_back(NewParm->getType());
4253 if (PVars)
4254 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004255 continue;
4256 }
John McCall58f10c32010-03-11 09:03:00 +00004257
4258 // Deal with the possibility that we don't have a parameter
4259 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004260 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004261 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004262 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004263 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004264 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004265 = dyn_cast<PackExpansionType>(OldType)) {
4266 // We have a function parameter pack that may need to be expanded.
4267 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004268 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004269 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004270
Douglas Gregor5499af42011-01-05 23:12:31 +00004271 // Determine whether we should expand the parameter packs.
4272 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004273 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004274 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004275 Unexpanded,
4276 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004277 RetainExpansion,
4278 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004279 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004280 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004281
Douglas Gregor5499af42011-01-05 23:12:31 +00004282 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004283 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004284 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004285 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004286 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4287 QualType NewType = getDerived().TransformType(Pattern);
4288 if (NewType.isNull())
4289 return true;
John McCall58f10c32010-03-11 09:03:00 +00004290
Douglas Gregordd472162011-01-07 00:20:55 +00004291 OutParamTypes.push_back(NewType);
4292 if (PVars)
4293 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00004294 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004295
Douglas Gregor5499af42011-01-05 23:12:31 +00004296 // We're done with the pack expansion.
4297 continue;
4298 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004299
Douglas Gregor48d24112011-01-10 20:53:55 +00004300 // If we're supposed to retain a pack expansion, do so by temporarily
4301 // forgetting the partially-substituted parameter pack.
4302 if (RetainExpansion) {
4303 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4304 QualType NewType = getDerived().TransformType(Pattern);
4305 if (NewType.isNull())
4306 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004307
Douglas Gregor48d24112011-01-10 20:53:55 +00004308 OutParamTypes.push_back(NewType);
4309 if (PVars)
4310 PVars->push_back(0);
4311 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004312
Chad Rosier1dcde962012-08-08 18:46:20 +00004313 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004314 // expansion.
4315 OldType = Expansion->getPattern();
4316 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004317 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4318 NewType = getDerived().TransformType(OldType);
4319 } else {
4320 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004321 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004322
Douglas Gregor5499af42011-01-05 23:12:31 +00004323 if (NewType.isNull())
4324 return true;
4325
4326 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004327 NewType = getSema().Context.getPackExpansionType(NewType,
4328 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004329
Douglas Gregordd472162011-01-07 00:20:55 +00004330 OutParamTypes.push_back(NewType);
4331 if (PVars)
4332 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00004333 }
4334
John McCall8fb0d9d2011-05-01 22:35:37 +00004335#ifndef NDEBUG
4336 if (PVars) {
4337 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4338 if (ParmVarDecl *parm = (*PVars)[i])
4339 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004340 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004341#endif
4342
4343 return false;
4344}
John McCall58f10c32010-03-11 09:03:00 +00004345
4346template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004347QualType
John McCall550e0c22009-10-21 00:40:46 +00004348TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004349 FunctionProtoTypeLoc TL) {
Douglas Gregor3024f072012-04-16 07:05:22 +00004350 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4351}
4352
4353template<typename Derived>
4354QualType
4355TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4356 FunctionProtoTypeLoc TL,
4357 CXXRecordDecl *ThisContext,
4358 unsigned ThisTypeQuals) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004359 // Transform the parameters and return type.
4360 //
Richard Smithf623c962012-04-17 00:58:00 +00004361 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004362 // When the function has a trailing return type, we instantiate the
4363 // parameters before the return type, since the return type can then refer
4364 // to the parameters themselves (via decltype, sizeof, etc.).
4365 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004366 SmallVector<QualType, 4> ParamTypes;
4367 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004368 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004369
Douglas Gregor7fb25412010-10-01 18:44:50 +00004370 QualType ResultType;
4371
Richard Smith1226c602012-08-14 22:51:13 +00004372 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004373 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004374 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004375 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004376 return QualType();
4377
Douglas Gregor3024f072012-04-16 07:05:22 +00004378 {
4379 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004380 // If a declaration declares a member function or member function
4381 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004382 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004383 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004384 // declarator.
4385 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004386
Alp Toker42a16a62014-01-25 23:51:36 +00004387 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004388 if (ResultType.isNull())
4389 return QualType();
4390 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004391 }
4392 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004393 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004394 if (ResultType.isNull())
4395 return QualType();
4396
Alp Toker9cacbab2014-01-20 20:26:09 +00004397 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004398 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004399 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004400 return QualType();
4401 }
4402
Richard Smithf623c962012-04-17 00:58:00 +00004403 // FIXME: Need to transform the exception-specification too.
4404
John McCall550e0c22009-10-21 00:40:46 +00004405 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004406 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Alp Toker9cacbab2014-01-20 20:26:09 +00004407 T->getNumParams() != ParamTypes.size() ||
4408 !std::equal(T->param_type_begin(), T->param_type_end(),
4409 ParamTypes.begin())) {
Jordan Rose5c382722013-03-08 21:51:21 +00004410 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00004411 T->getExtProtoInfo());
John McCall550e0c22009-10-21 00:40:46 +00004412 if (Result.isNull())
4413 return QualType();
4414 }
Mike Stump11289f42009-09-09 15:08:12 +00004415
John McCall550e0c22009-10-21 00:40:46 +00004416 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004417 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004418 NewTL.setLParenLoc(TL.getLParenLoc());
4419 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004420 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004421 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4422 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004423
4424 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004425}
Mike Stump11289f42009-09-09 15:08:12 +00004426
Douglas Gregord6ff3322009-08-04 16:50:30 +00004427template<typename Derived>
4428QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004429 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004430 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004431 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00004432 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00004433 if (ResultType.isNull())
4434 return QualType();
4435
4436 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004437 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00004438 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4439
4440 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004441 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004442 NewTL.setLParenLoc(TL.getLParenLoc());
4443 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004444 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004445
4446 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004447}
Mike Stump11289f42009-09-09 15:08:12 +00004448
John McCallb96ec562009-12-04 22:46:56 +00004449template<typename Derived> QualType
4450TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004451 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004452 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004453 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004454 if (!D)
4455 return QualType();
4456
4457 QualType Result = TL.getType();
4458 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4459 Result = getDerived().RebuildUnresolvedUsingType(D);
4460 if (Result.isNull())
4461 return QualType();
4462 }
4463
4464 // We might get an arbitrary type spec type back. We should at
4465 // least always get a type spec type, though.
4466 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4467 NewTL.setNameLoc(TL.getNameLoc());
4468
4469 return Result;
4470}
4471
Douglas Gregord6ff3322009-08-04 16:50:30 +00004472template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004473QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004474 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004475 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004476 TypedefNameDecl *Typedef
4477 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4478 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004479 if (!Typedef)
4480 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004481
John McCall550e0c22009-10-21 00:40:46 +00004482 QualType Result = TL.getType();
4483 if (getDerived().AlwaysRebuild() ||
4484 Typedef != T->getDecl()) {
4485 Result = getDerived().RebuildTypedefType(Typedef);
4486 if (Result.isNull())
4487 return QualType();
4488 }
Mike Stump11289f42009-09-09 15:08:12 +00004489
John McCall550e0c22009-10-21 00:40:46 +00004490 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4491 NewTL.setNameLoc(TL.getNameLoc());
4492
4493 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004494}
Mike Stump11289f42009-09-09 15:08:12 +00004495
Douglas Gregord6ff3322009-08-04 16:50:30 +00004496template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004497QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004498 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004499 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00004500 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4501 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00004502
John McCalldadc5752010-08-24 06:29:42 +00004503 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004504 if (E.isInvalid())
4505 return QualType();
4506
Eli Friedmane4f22df2012-02-29 04:03:55 +00004507 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4508 if (E.isInvalid())
4509 return QualType();
4510
John McCall550e0c22009-10-21 00:40:46 +00004511 QualType Result = TL.getType();
4512 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004513 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004514 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004515 if (Result.isNull())
4516 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004517 }
John McCall550e0c22009-10-21 00:40:46 +00004518 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004519
John McCall550e0c22009-10-21 00:40:46 +00004520 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004521 NewTL.setTypeofLoc(TL.getTypeofLoc());
4522 NewTL.setLParenLoc(TL.getLParenLoc());
4523 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004524
4525 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004526}
Mike Stump11289f42009-09-09 15:08:12 +00004527
4528template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004529QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004530 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004531 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4532 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4533 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004534 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004535
John McCall550e0c22009-10-21 00:40:46 +00004536 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004537 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4538 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004539 if (Result.isNull())
4540 return QualType();
4541 }
Mike Stump11289f42009-09-09 15:08:12 +00004542
John McCall550e0c22009-10-21 00:40:46 +00004543 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004544 NewTL.setTypeofLoc(TL.getTypeofLoc());
4545 NewTL.setLParenLoc(TL.getLParenLoc());
4546 NewTL.setRParenLoc(TL.getRParenLoc());
4547 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004548
4549 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004550}
Mike Stump11289f42009-09-09 15:08:12 +00004551
4552template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004553QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004554 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004555 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004556
Douglas Gregore922c772009-08-04 22:27:00 +00004557 // decltype expressions are not potentially evaluated contexts
Richard Smithfd555f62012-02-22 02:04:18 +00004558 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4559 /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00004560
John McCalldadc5752010-08-24 06:29:42 +00004561 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004562 if (E.isInvalid())
4563 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004564
Richard Smithfd555f62012-02-22 02:04:18 +00004565 E = getSema().ActOnDecltypeExpression(E.take());
4566 if (E.isInvalid())
4567 return QualType();
4568
John McCall550e0c22009-10-21 00:40:46 +00004569 QualType Result = TL.getType();
4570 if (getDerived().AlwaysRebuild() ||
4571 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004572 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004573 if (Result.isNull())
4574 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004575 }
John McCall550e0c22009-10-21 00:40:46 +00004576 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004577
John McCall550e0c22009-10-21 00:40:46 +00004578 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4579 NewTL.setNameLoc(TL.getNameLoc());
4580
4581 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004582}
4583
4584template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004585QualType TreeTransform<Derived>::TransformUnaryTransformType(
4586 TypeLocBuilder &TLB,
4587 UnaryTransformTypeLoc TL) {
4588 QualType Result = TL.getType();
4589 if (Result->isDependentType()) {
4590 const UnaryTransformType *T = TL.getTypePtr();
4591 QualType NewBase =
4592 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4593 Result = getDerived().RebuildUnaryTransformType(NewBase,
4594 T->getUTTKind(),
4595 TL.getKWLoc());
4596 if (Result.isNull())
4597 return QualType();
4598 }
4599
4600 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4601 NewTL.setKWLoc(TL.getKWLoc());
4602 NewTL.setParensRange(TL.getParensRange());
4603 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4604 return Result;
4605}
4606
4607template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004608QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4609 AutoTypeLoc TL) {
4610 const AutoType *T = TL.getTypePtr();
4611 QualType OldDeduced = T->getDeducedType();
4612 QualType NewDeduced;
4613 if (!OldDeduced.isNull()) {
4614 NewDeduced = getDerived().TransformType(OldDeduced);
4615 if (NewDeduced.isNull())
4616 return QualType();
4617 }
4618
4619 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00004620 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4621 T->isDependentType()) {
Richard Smith74aeef52013-04-26 16:15:35 +00004622 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith30482bc2011-02-20 03:19:35 +00004623 if (Result.isNull())
4624 return QualType();
4625 }
4626
4627 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4628 NewTL.setNameLoc(TL.getNameLoc());
4629
4630 return Result;
4631}
4632
4633template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004634QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004635 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004636 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004637 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004638 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4639 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004640 if (!Record)
4641 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004642
John McCall550e0c22009-10-21 00:40:46 +00004643 QualType Result = TL.getType();
4644 if (getDerived().AlwaysRebuild() ||
4645 Record != T->getDecl()) {
4646 Result = getDerived().RebuildRecordType(Record);
4647 if (Result.isNull())
4648 return QualType();
4649 }
Mike Stump11289f42009-09-09 15:08:12 +00004650
John McCall550e0c22009-10-21 00:40:46 +00004651 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4652 NewTL.setNameLoc(TL.getNameLoc());
4653
4654 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004655}
Mike Stump11289f42009-09-09 15:08:12 +00004656
4657template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004658QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004659 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004660 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004661 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004662 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4663 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004664 if (!Enum)
4665 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004666
John McCall550e0c22009-10-21 00:40:46 +00004667 QualType Result = TL.getType();
4668 if (getDerived().AlwaysRebuild() ||
4669 Enum != T->getDecl()) {
4670 Result = getDerived().RebuildEnumType(Enum);
4671 if (Result.isNull())
4672 return QualType();
4673 }
Mike Stump11289f42009-09-09 15:08:12 +00004674
John McCall550e0c22009-10-21 00:40:46 +00004675 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4676 NewTL.setNameLoc(TL.getNameLoc());
4677
4678 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004679}
John McCallfcc33b02009-09-05 00:15:47 +00004680
John McCalle78aac42010-03-10 03:28:59 +00004681template<typename Derived>
4682QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4683 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004684 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004685 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4686 TL.getTypePtr()->getDecl());
4687 if (!D) return QualType();
4688
4689 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4690 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4691 return T;
4692}
4693
Douglas Gregord6ff3322009-08-04 16:50:30 +00004694template<typename Derived>
4695QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004696 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004697 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004698 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004699}
4700
Mike Stump11289f42009-09-09 15:08:12 +00004701template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004702QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004703 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004704 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004705 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00004706
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004707 // Substitute into the replacement type, which itself might involve something
4708 // that needs to be transformed. This only tends to occur with default
4709 // template arguments of template template parameters.
4710 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4711 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4712 if (Replacement.isNull())
4713 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00004714
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004715 // Always canonicalize the replacement type.
4716 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4717 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00004718 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004719 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00004720
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004721 // Propagate type-source information.
4722 SubstTemplateTypeParmTypeLoc NewTL
4723 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4724 NewTL.setNameLoc(TL.getNameLoc());
4725 return Result;
4726
John McCallcebee162009-10-18 09:09:24 +00004727}
4728
4729template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004730QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4731 TypeLocBuilder &TLB,
4732 SubstTemplateTypeParmPackTypeLoc TL) {
4733 return TransformTypeSpecType(TLB, TL);
4734}
4735
4736template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004737QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004738 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004739 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004740 const TemplateSpecializationType *T = TL.getTypePtr();
4741
Douglas Gregordf846d12011-03-02 18:46:51 +00004742 // The nested-name-specifier never matters in a TemplateSpecializationType,
4743 // because we can't have a dependent nested-name-specifier anyway.
4744 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004745 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004746 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4747 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004748 if (Template.isNull())
4749 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004750
John McCall31f82722010-11-12 08:19:04 +00004751 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4752}
4753
Eli Friedman0dfb8892011-10-06 23:00:33 +00004754template<typename Derived>
4755QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4756 AtomicTypeLoc TL) {
4757 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4758 if (ValueType.isNull())
4759 return QualType();
4760
4761 QualType Result = TL.getType();
4762 if (getDerived().AlwaysRebuild() ||
4763 ValueType != TL.getValueLoc().getType()) {
4764 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4765 if (Result.isNull())
4766 return QualType();
4767 }
4768
4769 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4770 NewTL.setKWLoc(TL.getKWLoc());
4771 NewTL.setLParenLoc(TL.getLParenLoc());
4772 NewTL.setRParenLoc(TL.getRParenLoc());
4773
4774 return Result;
4775}
4776
Chad Rosier1dcde962012-08-08 18:46:20 +00004777 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00004778 /// container that provides a \c getArgLoc() member function.
4779 ///
4780 /// This iterator is intended to be used with the iterator form of
4781 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4782 template<typename ArgLocContainer>
4783 class TemplateArgumentLocContainerIterator {
4784 ArgLocContainer *Container;
4785 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00004786
Douglas Gregorfe921a72010-12-20 23:36:19 +00004787 public:
4788 typedef TemplateArgumentLoc value_type;
4789 typedef TemplateArgumentLoc reference;
4790 typedef int difference_type;
4791 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00004792
Douglas Gregorfe921a72010-12-20 23:36:19 +00004793 class pointer {
4794 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00004795
Douglas Gregorfe921a72010-12-20 23:36:19 +00004796 public:
4797 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004798
Douglas Gregorfe921a72010-12-20 23:36:19 +00004799 const TemplateArgumentLoc *operator->() const {
4800 return &Arg;
4801 }
4802 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004803
4804
Douglas Gregorfe921a72010-12-20 23:36:19 +00004805 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00004806
Douglas Gregorfe921a72010-12-20 23:36:19 +00004807 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4808 unsigned Index)
4809 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004810
Douglas Gregorfe921a72010-12-20 23:36:19 +00004811 TemplateArgumentLocContainerIterator &operator++() {
4812 ++Index;
4813 return *this;
4814 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004815
Douglas Gregorfe921a72010-12-20 23:36:19 +00004816 TemplateArgumentLocContainerIterator operator++(int) {
4817 TemplateArgumentLocContainerIterator Old(*this);
4818 ++(*this);
4819 return Old;
4820 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004821
Douglas Gregorfe921a72010-12-20 23:36:19 +00004822 TemplateArgumentLoc operator*() const {
4823 return Container->getArgLoc(Index);
4824 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004825
Douglas Gregorfe921a72010-12-20 23:36:19 +00004826 pointer operator->() const {
4827 return pointer(Container->getArgLoc(Index));
4828 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004829
Douglas Gregorfe921a72010-12-20 23:36:19 +00004830 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004831 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004832 return X.Container == Y.Container && X.Index == Y.Index;
4833 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004834
Douglas Gregorfe921a72010-12-20 23:36:19 +00004835 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004836 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004837 return !(X == Y);
4838 }
4839 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004840
4841
John McCall31f82722010-11-12 08:19:04 +00004842template <typename Derived>
4843QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4844 TypeLocBuilder &TLB,
4845 TemplateSpecializationTypeLoc TL,
4846 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004847 TemplateArgumentListInfo NewTemplateArgs;
4848 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4849 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004850 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4851 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004852 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00004853 ArgIterator(TL, TL.getNumArgs()),
4854 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004855 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004856
John McCall0ad16662009-10-29 08:12:44 +00004857 // FIXME: maybe don't rebuild if all the template arguments are the same.
4858
4859 QualType Result =
4860 getDerived().RebuildTemplateSpecializationType(Template,
4861 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004862 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004863
4864 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00004865 // Specializations of template template parameters are represented as
4866 // TemplateSpecializationTypes, and substitution of type alias templates
4867 // within a dependent context can transform them into
4868 // DependentTemplateSpecializationTypes.
4869 if (isa<DependentTemplateSpecializationType>(Result)) {
4870 DependentTemplateSpecializationTypeLoc NewTL
4871 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004872 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00004873 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00004874 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004875 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00004876 NewTL.setLAngleLoc(TL.getLAngleLoc());
4877 NewTL.setRAngleLoc(TL.getRAngleLoc());
4878 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4879 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4880 return Result;
4881 }
4882
John McCall0ad16662009-10-29 08:12:44 +00004883 TemplateSpecializationTypeLoc NewTL
4884 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004885 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00004886 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4887 NewTL.setLAngleLoc(TL.getLAngleLoc());
4888 NewTL.setRAngleLoc(TL.getRAngleLoc());
4889 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4890 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004891 }
Mike Stump11289f42009-09-09 15:08:12 +00004892
John McCall0ad16662009-10-29 08:12:44 +00004893 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004894}
Mike Stump11289f42009-09-09 15:08:12 +00004895
Douglas Gregor5a064722011-02-28 17:23:35 +00004896template <typename Derived>
4897QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4898 TypeLocBuilder &TLB,
4899 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004900 TemplateName Template,
4901 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00004902 TemplateArgumentListInfo NewTemplateArgs;
4903 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4904 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4905 typedef TemplateArgumentLocContainerIterator<
4906 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004907 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00004908 ArgIterator(TL, TL.getNumArgs()),
4909 NewTemplateArgs))
4910 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00004911
Douglas Gregor5a064722011-02-28 17:23:35 +00004912 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00004913
Douglas Gregor5a064722011-02-28 17:23:35 +00004914 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4915 QualType Result
4916 = getSema().Context.getDependentTemplateSpecializationType(
4917 TL.getTypePtr()->getKeyword(),
4918 DTN->getQualifier(),
4919 DTN->getIdentifier(),
4920 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00004921
Douglas Gregor5a064722011-02-28 17:23:35 +00004922 DependentTemplateSpecializationTypeLoc NewTL
4923 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004924 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004925 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00004926 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004927 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00004928 NewTL.setLAngleLoc(TL.getLAngleLoc());
4929 NewTL.setRAngleLoc(TL.getRAngleLoc());
4930 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4931 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4932 return Result;
4933 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004934
4935 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00004936 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004937 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00004938 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00004939
Douglas Gregor5a064722011-02-28 17:23:35 +00004940 if (!Result.isNull()) {
4941 /// FIXME: Wrap this in an elaborated-type-specifier?
4942 TemplateSpecializationTypeLoc NewTL
4943 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00004944 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004945 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00004946 NewTL.setLAngleLoc(TL.getLAngleLoc());
4947 NewTL.setRAngleLoc(TL.getRAngleLoc());
4948 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4949 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4950 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004951
Douglas Gregor5a064722011-02-28 17:23:35 +00004952 return Result;
4953}
4954
Mike Stump11289f42009-09-09 15:08:12 +00004955template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004956QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00004957TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004958 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004959 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00004960
Douglas Gregor844cb502011-03-01 18:12:44 +00004961 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00004962 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00004963 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004964 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00004965 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4966 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00004967 return QualType();
4968 }
Mike Stump11289f42009-09-09 15:08:12 +00004969
John McCall31f82722010-11-12 08:19:04 +00004970 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4971 if (NamedT.isNull())
4972 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00004973
Richard Smith3f1b5d02011-05-05 21:57:07 +00004974 // C++0x [dcl.type.elab]p2:
4975 // If the identifier resolves to a typedef-name or the simple-template-id
4976 // resolves to an alias template specialization, the
4977 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00004978 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4979 if (const TemplateSpecializationType *TST =
4980 NamedT->getAs<TemplateSpecializationType>()) {
4981 TemplateName Template = TST->getTemplateName();
4982 if (TypeAliasTemplateDecl *TAT =
4983 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4984 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4985 diag::err_tag_reference_non_tag) << 4;
4986 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4987 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00004988 }
4989 }
4990
John McCall550e0c22009-10-21 00:40:46 +00004991 QualType Result = TL.getType();
4992 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00004993 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00004994 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00004995 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004996 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00004997 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00004998 if (Result.isNull())
4999 return QualType();
5000 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005001
Abramo Bagnara6150c882010-05-11 21:36:43 +00005002 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005003 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005004 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005005 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005006}
Mike Stump11289f42009-09-09 15:08:12 +00005007
5008template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005009QualType TreeTransform<Derived>::TransformAttributedType(
5010 TypeLocBuilder &TLB,
5011 AttributedTypeLoc TL) {
5012 const AttributedType *oldType = TL.getTypePtr();
5013 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5014 if (modifiedType.isNull())
5015 return QualType();
5016
5017 QualType result = TL.getType();
5018
5019 // FIXME: dependent operand expressions?
5020 if (getDerived().AlwaysRebuild() ||
5021 modifiedType != oldType->getModifiedType()) {
5022 // TODO: this is really lame; we should really be rebuilding the
5023 // equivalent type from first principles.
5024 QualType equivalentType
5025 = getDerived().TransformType(oldType->getEquivalentType());
5026 if (equivalentType.isNull())
5027 return QualType();
5028 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5029 modifiedType,
5030 equivalentType);
5031 }
5032
5033 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5034 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5035 if (TL.hasAttrOperand())
5036 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5037 if (TL.hasAttrExprOperand())
5038 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5039 else if (TL.hasAttrEnumOperand())
5040 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5041
5042 return result;
5043}
5044
5045template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005046QualType
5047TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5048 ParenTypeLoc TL) {
5049 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5050 if (Inner.isNull())
5051 return QualType();
5052
5053 QualType Result = TL.getType();
5054 if (getDerived().AlwaysRebuild() ||
5055 Inner != TL.getInnerLoc().getType()) {
5056 Result = getDerived().RebuildParenType(Inner);
5057 if (Result.isNull())
5058 return QualType();
5059 }
5060
5061 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5062 NewTL.setLParenLoc(TL.getLParenLoc());
5063 NewTL.setRParenLoc(TL.getRParenLoc());
5064 return Result;
5065}
5066
5067template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005068QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005069 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005070 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005071
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005072 NestedNameSpecifierLoc QualifierLoc
5073 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5074 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005075 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005076
John McCallc392f372010-06-11 00:33:02 +00005077 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005078 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005079 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005080 QualifierLoc,
5081 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005082 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005083 if (Result.isNull())
5084 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005085
Abramo Bagnarad7548482010-05-19 21:37:53 +00005086 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5087 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005088 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5089
Abramo Bagnarad7548482010-05-19 21:37:53 +00005090 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005091 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005092 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005093 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005094 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005095 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005096 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005097 NewTL.setNameLoc(TL.getNameLoc());
5098 }
John McCall550e0c22009-10-21 00:40:46 +00005099 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005100}
Mike Stump11289f42009-09-09 15:08:12 +00005101
Douglas Gregord6ff3322009-08-04 16:50:30 +00005102template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005103QualType TreeTransform<Derived>::
5104 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005105 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005106 NestedNameSpecifierLoc QualifierLoc;
5107 if (TL.getQualifierLoc()) {
5108 QualifierLoc
5109 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5110 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005111 return QualType();
5112 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005113
John McCall31f82722010-11-12 08:19:04 +00005114 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005115 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005116}
5117
5118template<typename Derived>
5119QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005120TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5121 DependentTemplateSpecializationTypeLoc TL,
5122 NestedNameSpecifierLoc QualifierLoc) {
5123 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005124
Douglas Gregora7a795b2011-03-01 20:11:18 +00005125 TemplateArgumentListInfo NewTemplateArgs;
5126 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5127 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005128
Douglas Gregora7a795b2011-03-01 20:11:18 +00005129 typedef TemplateArgumentLocContainerIterator<
5130 DependentTemplateSpecializationTypeLoc> ArgIterator;
5131 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5132 ArgIterator(TL, TL.getNumArgs()),
5133 NewTemplateArgs))
5134 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005135
Douglas Gregora7a795b2011-03-01 20:11:18 +00005136 QualType Result
5137 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5138 QualifierLoc,
5139 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005140 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005141 NewTemplateArgs);
5142 if (Result.isNull())
5143 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005144
Douglas Gregora7a795b2011-03-01 20:11:18 +00005145 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5146 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005147
Douglas Gregora7a795b2011-03-01 20:11:18 +00005148 // Copy information relevant to the template specialization.
5149 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005150 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005151 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005152 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005153 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5154 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005155 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005156 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005157
Douglas Gregora7a795b2011-03-01 20:11:18 +00005158 // Copy information relevant to the elaborated type.
5159 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005160 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005161 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005162 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5163 DependentTemplateSpecializationTypeLoc SpecTL
5164 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005165 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005166 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005167 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005168 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005169 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5170 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005171 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005172 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005173 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005174 TemplateSpecializationTypeLoc SpecTL
5175 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005176 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005177 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005178 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5179 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005180 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005181 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005182 }
5183 return Result;
5184}
5185
5186template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005187QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5188 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005189 QualType Pattern
5190 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005191 if (Pattern.isNull())
5192 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005193
5194 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005195 if (getDerived().AlwaysRebuild() ||
5196 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005197 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005198 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005199 TL.getEllipsisLoc(),
5200 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005201 if (Result.isNull())
5202 return QualType();
5203 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005204
Douglas Gregor822d0302011-01-12 17:07:58 +00005205 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5206 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5207 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005208}
5209
5210template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005211QualType
5212TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005213 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005214 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005215 TLB.pushFullCopy(TL);
5216 return TL.getType();
5217}
5218
5219template<typename Derived>
5220QualType
5221TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005222 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00005223 // ObjCObjectType is never dependent.
5224 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005225 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005226}
Mike Stump11289f42009-09-09 15:08:12 +00005227
5228template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005229QualType
5230TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005231 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005232 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005233 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005234 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005235}
5236
Douglas Gregord6ff3322009-08-04 16:50:30 +00005237//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005238// Statement transformation
5239//===----------------------------------------------------------------------===//
5240template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005241StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005242TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005243 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005244}
5245
5246template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005247StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005248TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5249 return getDerived().TransformCompoundStmt(S, false);
5250}
5251
5252template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005253StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005254TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005255 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005256 Sema::CompoundScopeRAII CompoundScope(getSema());
5257
John McCall1ababa62010-08-27 19:56:05 +00005258 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005259 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005260 SmallVector<Stmt*, 8> Statements;
Douglas Gregorebe10102009-08-20 07:17:43 +00005261 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5262 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00005263 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00005264 if (Result.isInvalid()) {
5265 // Immediately fail if this was a DeclStmt, since it's very
5266 // likely that this will cause problems for future statements.
5267 if (isa<DeclStmt>(*B))
5268 return StmtError();
5269
5270 // Otherwise, just keep processing substatements and fail later.
5271 SubStmtInvalid = true;
5272 continue;
5273 }
Mike Stump11289f42009-09-09 15:08:12 +00005274
Douglas Gregorebe10102009-08-20 07:17:43 +00005275 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5276 Statements.push_back(Result.takeAs<Stmt>());
5277 }
Mike Stump11289f42009-09-09 15:08:12 +00005278
John McCall1ababa62010-08-27 19:56:05 +00005279 if (SubStmtInvalid)
5280 return StmtError();
5281
Douglas Gregorebe10102009-08-20 07:17:43 +00005282 if (!getDerived().AlwaysRebuild() &&
5283 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00005284 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005285
5286 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005287 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005288 S->getRBracLoc(),
5289 IsStmtExpr);
5290}
Mike Stump11289f42009-09-09 15:08:12 +00005291
Douglas Gregorebe10102009-08-20 07:17:43 +00005292template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005293StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005294TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005295 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005296 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005297 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5298 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005299
Eli Friedman06577382009-11-19 03:14:00 +00005300 // Transform the left-hand case value.
5301 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005302 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005303 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005304 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005305
Eli Friedman06577382009-11-19 03:14:00 +00005306 // Transform the right-hand case value (for the GNU case-range extension).
5307 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005308 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005309 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005310 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005311 }
Mike Stump11289f42009-09-09 15:08:12 +00005312
Douglas Gregorebe10102009-08-20 07:17:43 +00005313 // Build the case statement.
5314 // Case statements are always rebuilt so that they will attached to their
5315 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005316 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005317 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005318 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005319 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005320 S->getColonLoc());
5321 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005322 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005323
Douglas Gregorebe10102009-08-20 07:17:43 +00005324 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005325 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005326 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005327 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005328
Douglas Gregorebe10102009-08-20 07:17:43 +00005329 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005330 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005331}
5332
5333template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005334StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005335TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005336 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005337 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005338 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005339 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005340
Douglas Gregorebe10102009-08-20 07:17:43 +00005341 // Default statements are always rebuilt
5342 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005343 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005344}
Mike Stump11289f42009-09-09 15:08:12 +00005345
Douglas Gregorebe10102009-08-20 07:17:43 +00005346template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005347StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005348TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005349 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005350 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005351 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005352
Chris Lattnercab02a62011-02-17 20:34:02 +00005353 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5354 S->getDecl());
5355 if (!LD)
5356 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00005357
5358
Douglas Gregorebe10102009-08-20 07:17:43 +00005359 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005360 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005361 cast<LabelDecl>(LD), SourceLocation(),
5362 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005363}
Mike Stump11289f42009-09-09 15:08:12 +00005364
Douglas Gregorebe10102009-08-20 07:17:43 +00005365template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005366StmtResult
Richard Smithc202b282012-04-14 00:33:13 +00005367TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5368 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5369 if (SubStmt.isInvalid())
5370 return StmtError();
5371
5372 // TODO: transform attributes
5373 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5374 return S;
5375
5376 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5377 S->getAttrs(),
5378 SubStmt.get());
5379}
5380
5381template<typename Derived>
5382StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005383TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005384 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005385 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00005386 VarDecl *ConditionVar = 0;
5387 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005388 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00005389 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005390 getDerived().TransformDefinition(
5391 S->getConditionVariable()->getLocation(),
5392 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00005393 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005394 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005395 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00005396 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005397
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005398 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005399 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005400
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005401 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005402 if (S->getCond()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005403 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005404 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005405 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005406 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005407
John McCallb268a282010-08-23 23:25:46 +00005408 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005409 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005410 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005411
John McCallb268a282010-08-23 23:25:46 +00005412 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5413 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005414 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005415
Douglas Gregorebe10102009-08-20 07:17:43 +00005416 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005417 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005418 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005419 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005420
Douglas Gregorebe10102009-08-20 07:17:43 +00005421 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005422 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005423 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005424 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005425
Douglas Gregorebe10102009-08-20 07:17:43 +00005426 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005427 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005428 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005429 Then.get() == S->getThen() &&
5430 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00005431 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005432
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005433 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005434 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00005435 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005436}
5437
5438template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005439StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005440TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005441 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005442 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00005443 VarDecl *ConditionVar = 0;
5444 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005445 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005446 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005447 getDerived().TransformDefinition(
5448 S->getConditionVariable()->getLocation(),
5449 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005450 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005451 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005452 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005453 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005454
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005455 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005456 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005457 }
Mike Stump11289f42009-09-09 15:08:12 +00005458
Douglas Gregorebe10102009-08-20 07:17:43 +00005459 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005460 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005461 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005462 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005463 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005464 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005465
Douglas Gregorebe10102009-08-20 07:17:43 +00005466 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005467 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005468 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005469 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005470
Douglas Gregorebe10102009-08-20 07:17:43 +00005471 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005472 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5473 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005474}
Mike Stump11289f42009-09-09 15:08:12 +00005475
Douglas Gregorebe10102009-08-20 07:17:43 +00005476template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005477StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005478TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005479 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005480 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00005481 VarDecl *ConditionVar = 0;
5482 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005483 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005484 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005485 getDerived().TransformDefinition(
5486 S->getConditionVariable()->getLocation(),
5487 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005488 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005489 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005490 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005491 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005492
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005493 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005494 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005495
5496 if (S->getCond()) {
5497 // Convert the condition to a boolean value.
Chad Rosier1dcde962012-08-08 18:46:20 +00005498 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005499 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005500 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005501 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005502 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005503 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005504 }
Mike Stump11289f42009-09-09 15:08:12 +00005505
John McCallb268a282010-08-23 23:25:46 +00005506 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5507 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005508 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005509
Douglas Gregorebe10102009-08-20 07:17:43 +00005510 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005511 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005512 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005513 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005514
Douglas Gregorebe10102009-08-20 07:17:43 +00005515 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005516 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005517 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005518 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005519 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005520
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005521 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005522 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005523}
Mike Stump11289f42009-09-09 15:08:12 +00005524
Douglas Gregorebe10102009-08-20 07:17:43 +00005525template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005526StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005527TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005528 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005529 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005530 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005531 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005532
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005533 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005534 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005535 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005536 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005537
Douglas Gregorebe10102009-08-20 07:17:43 +00005538 if (!getDerived().AlwaysRebuild() &&
5539 Cond.get() == S->getCond() &&
5540 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005541 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005542
John McCallb268a282010-08-23 23:25:46 +00005543 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5544 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005545 S->getRParenLoc());
5546}
Mike Stump11289f42009-09-09 15:08:12 +00005547
Douglas Gregorebe10102009-08-20 07:17:43 +00005548template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005549StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005550TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005551 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005552 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005553 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005554 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005555
Douglas Gregorebe10102009-08-20 07:17:43 +00005556 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005557 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005558 VarDecl *ConditionVar = 0;
5559 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005560 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005561 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005562 getDerived().TransformDefinition(
5563 S->getConditionVariable()->getLocation(),
5564 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005565 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005566 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005567 } else {
5568 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005569
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005570 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005571 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005572
5573 if (S->getCond()) {
5574 // Convert the condition to a boolean value.
Chad Rosier1dcde962012-08-08 18:46:20 +00005575 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005576 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005577 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005578 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005579
John McCallb268a282010-08-23 23:25:46 +00005580 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005581 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005582 }
Mike Stump11289f42009-09-09 15:08:12 +00005583
Chad Rosier1dcde962012-08-08 18:46:20 +00005584 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCallb268a282010-08-23 23:25:46 +00005585 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005586 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005587
Douglas Gregorebe10102009-08-20 07:17:43 +00005588 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005589 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005590 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005591 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005592
Richard Smith945f8d32013-01-14 22:39:08 +00005593 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00005594 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005595 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005596
Douglas Gregorebe10102009-08-20 07:17:43 +00005597 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005598 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005599 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005600 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005601
Douglas Gregorebe10102009-08-20 07:17:43 +00005602 if (!getDerived().AlwaysRebuild() &&
5603 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005604 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005605 Inc.get() == S->getInc() &&
5606 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005607 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005608
Douglas Gregorebe10102009-08-20 07:17:43 +00005609 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005610 Init.get(), FullCond, ConditionVar,
5611 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005612}
5613
5614template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005615StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005616TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005617 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5618 S->getLabel());
5619 if (!LD)
5620 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005621
Douglas Gregorebe10102009-08-20 07:17:43 +00005622 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005623 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005624 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005625}
5626
5627template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005628StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005629TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005630 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005631 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005632 return StmtError();
Eli Friedman9ccdb1d2012-01-31 22:47:07 +00005633 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump11289f42009-09-09 15:08:12 +00005634
Douglas Gregorebe10102009-08-20 07:17:43 +00005635 if (!getDerived().AlwaysRebuild() &&
5636 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00005637 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005638
5639 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005640 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005641}
5642
5643template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005644StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005645TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005646 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005647}
Mike Stump11289f42009-09-09 15:08:12 +00005648
Douglas Gregorebe10102009-08-20 07:17:43 +00005649template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005650StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005651TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005652 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005653}
Mike Stump11289f42009-09-09 15:08:12 +00005654
Douglas Gregorebe10102009-08-20 07:17:43 +00005655template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005656StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005657TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005658 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005659 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005660 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005661
Mike Stump11289f42009-09-09 15:08:12 +00005662 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005663 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005664 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005665}
Mike Stump11289f42009-09-09 15:08:12 +00005666
Douglas Gregorebe10102009-08-20 07:17:43 +00005667template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005668StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005669TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005670 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005671 SmallVector<Decl *, 4> Decls;
Douglas Gregorebe10102009-08-20 07:17:43 +00005672 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5673 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00005674 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5675 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005676 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005677 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005678
Douglas Gregorebe10102009-08-20 07:17:43 +00005679 if (Transformed != *D)
5680 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005681
Douglas Gregorebe10102009-08-20 07:17:43 +00005682 Decls.push_back(Transformed);
5683 }
Mike Stump11289f42009-09-09 15:08:12 +00005684
Douglas Gregorebe10102009-08-20 07:17:43 +00005685 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00005686 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005687
Rafael Espindolaab417692013-07-09 12:05:01 +00005688 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005689}
Mike Stump11289f42009-09-09 15:08:12 +00005690
Douglas Gregorebe10102009-08-20 07:17:43 +00005691template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005692StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00005693TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005694
Benjamin Kramerf0623432012-08-23 22:51:59 +00005695 SmallVector<Expr*, 8> Constraints;
5696 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005697 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005698
John McCalldadc5752010-08-24 06:29:42 +00005699 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005700 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005701
5702 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00005703
Anders Carlssonaaeef072010-01-24 05:50:09 +00005704 // Go through the outputs.
5705 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005706 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005707
Anders Carlssonaaeef072010-01-24 05:50:09 +00005708 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005709 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005710
Anders Carlssonaaeef072010-01-24 05:50:09 +00005711 // Transform the output expr.
5712 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005713 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005714 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005715 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005716
Anders Carlssonaaeef072010-01-24 05:50:09 +00005717 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005718
John McCallb268a282010-08-23 23:25:46 +00005719 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005720 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005721
Anders Carlssonaaeef072010-01-24 05:50:09 +00005722 // Go through the inputs.
5723 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005724 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005725
Anders Carlssonaaeef072010-01-24 05:50:09 +00005726 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005727 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005728
Anders Carlssonaaeef072010-01-24 05:50:09 +00005729 // Transform the input expr.
5730 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005731 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005732 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005733 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005734
Anders Carlssonaaeef072010-01-24 05:50:09 +00005735 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005736
John McCallb268a282010-08-23 23:25:46 +00005737 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005738 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005739
Anders Carlssonaaeef072010-01-24 05:50:09 +00005740 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00005741 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005742
5743 // Go through the clobbers.
5744 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00005745 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005746
5747 // No need to transform the asm string literal.
5748 AsmString = SemaRef.Owned(S->getAsmString());
Chad Rosierde70e0e2012-08-25 00:11:56 +00005749 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5750 S->isVolatile(), S->getNumOutputs(),
5751 S->getNumInputs(), Names.data(),
5752 Constraints, Exprs, AsmString.get(),
5753 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005754}
5755
Chad Rosier32503022012-06-11 20:47:18 +00005756template<typename Derived>
5757StmtResult
5758TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00005759 ArrayRef<Token> AsmToks =
5760 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00005761
John McCallf413f5e2013-05-03 00:10:13 +00005762 bool HadError = false, HadChange = false;
5763
5764 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5765 SmallVector<Expr*, 8> TransformedExprs;
5766 TransformedExprs.reserve(SrcExprs.size());
5767 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5768 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5769 if (!Result.isUsable()) {
5770 HadError = true;
5771 } else {
5772 HadChange |= (Result.get() != SrcExprs[i]);
5773 TransformedExprs.push_back(Result.take());
5774 }
5775 }
5776
5777 if (HadError) return StmtError();
5778 if (!HadChange && !getDerived().AlwaysRebuild())
5779 return Owned(S);
5780
Chad Rosierb6f46c12012-08-15 16:53:30 +00005781 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00005782 AsmToks, S->getAsmString(),
5783 S->getNumOutputs(), S->getNumInputs(),
5784 S->getAllConstraints(), S->getClobbers(),
5785 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00005786}
Douglas Gregorebe10102009-08-20 07:17:43 +00005787
5788template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005789StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005790TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005791 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005792 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005793 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005794 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005795
Douglas Gregor96c79492010-04-23 22:50:49 +00005796 // Transform the @catch statements (if present).
5797 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005798 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00005799 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005800 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005801 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005802 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005803 if (Catch.get() != S->getCatchStmt(I))
5804 AnyCatchChanged = true;
5805 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005806 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005807
Douglas Gregor306de2f2010-04-22 23:59:56 +00005808 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005809 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005810 if (S->getFinallyStmt()) {
5811 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5812 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005813 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005814 }
5815
5816 // If nothing changed, just retain this statement.
5817 if (!getDerived().AlwaysRebuild() &&
5818 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005819 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005820 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00005821 return SemaRef.Owned(S);
Chad Rosier1dcde962012-08-08 18:46:20 +00005822
Douglas Gregor306de2f2010-04-22 23:59:56 +00005823 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005824 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005825 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005826}
Mike Stump11289f42009-09-09 15:08:12 +00005827
Douglas Gregorebe10102009-08-20 07:17:43 +00005828template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005829StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005830TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005831 // Transform the @catch parameter, if there is one.
5832 VarDecl *Var = 0;
5833 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5834 TypeSourceInfo *TSInfo = 0;
5835 if (FromVar->getTypeSourceInfo()) {
5836 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5837 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005838 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005839 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005840
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005841 QualType T;
5842 if (TSInfo)
5843 T = TSInfo->getType();
5844 else {
5845 T = getDerived().TransformType(FromVar->getType());
5846 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00005847 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005848 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005849
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005850 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5851 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005852 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005853 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005854
John McCalldadc5752010-08-24 06:29:42 +00005855 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005856 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005857 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005858
5859 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005860 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005861 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005862}
Mike Stump11289f42009-09-09 15:08:12 +00005863
Douglas Gregorebe10102009-08-20 07:17:43 +00005864template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005865StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005866TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005867 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005868 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005869 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005870 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005871
Douglas Gregor306de2f2010-04-22 23:59:56 +00005872 // If nothing changed, just retain this statement.
5873 if (!getDerived().AlwaysRebuild() &&
5874 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00005875 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00005876
5877 // Build a new statement.
5878 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005879 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005880}
Mike Stump11289f42009-09-09 15:08:12 +00005881
Douglas Gregorebe10102009-08-20 07:17:43 +00005882template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005883StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005884TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005885 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005886 if (S->getThrowExpr()) {
5887 Operand = getDerived().TransformExpr(S->getThrowExpr());
5888 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005889 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005890 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005891
Douglas Gregor2900c162010-04-22 21:44:01 +00005892 if (!getDerived().AlwaysRebuild() &&
5893 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005894 return getSema().Owned(S);
Chad Rosier1dcde962012-08-08 18:46:20 +00005895
John McCallb268a282010-08-23 23:25:46 +00005896 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005897}
Mike Stump11289f42009-09-09 15:08:12 +00005898
Douglas Gregorebe10102009-08-20 07:17:43 +00005899template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005900StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005901TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005902 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005903 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005904 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005905 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005906 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00005907 Object =
5908 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5909 Object.get());
5910 if (Object.isInvalid())
5911 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005912
Douglas Gregor6148de72010-04-22 22:01:21 +00005913 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005914 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005915 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005916 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005917
Douglas Gregor6148de72010-04-22 22:01:21 +00005918 // If nothing change, just retain the current statement.
5919 if (!getDerived().AlwaysRebuild() &&
5920 Object.get() == S->getSynchExpr() &&
5921 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005922 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005923
5924 // Build a new statement.
5925 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005926 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005927}
5928
5929template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005930StmtResult
John McCall31168b02011-06-15 23:02:42 +00005931TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5932 ObjCAutoreleasePoolStmt *S) {
5933 // Transform the body.
5934 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5935 if (Body.isInvalid())
5936 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005937
John McCall31168b02011-06-15 23:02:42 +00005938 // If nothing changed, just retain this statement.
5939 if (!getDerived().AlwaysRebuild() &&
5940 Body.get() == S->getSubStmt())
5941 return SemaRef.Owned(S);
5942
5943 // Build a new statement.
5944 return getDerived().RebuildObjCAutoreleasePoolStmt(
5945 S->getAtLoc(), Body.get());
5946}
5947
5948template<typename Derived>
5949StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005950TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005951 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005952 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005953 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005954 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005955 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005956
Douglas Gregorf68a5082010-04-22 23:10:45 +00005957 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00005958 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005959 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005960 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005961
Douglas Gregorf68a5082010-04-22 23:10:45 +00005962 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005963 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005964 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005965 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005966
Douglas Gregorf68a5082010-04-22 23:10:45 +00005967 // If nothing changed, just retain this statement.
5968 if (!getDerived().AlwaysRebuild() &&
5969 Element.get() == S->getElement() &&
5970 Collection.get() == S->getCollection() &&
5971 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005972 return SemaRef.Owned(S);
Chad Rosier1dcde962012-08-08 18:46:20 +00005973
Douglas Gregorf68a5082010-04-22 23:10:45 +00005974 // Build a new statement.
5975 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00005976 Element.get(),
5977 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00005978 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005979 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005980}
5981
David Majnemer5f7efef2013-10-15 09:50:08 +00005982template <typename Derived>
5983StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005984 // Transform the exception declaration, if any.
5985 VarDecl *Var = 0;
David Majnemer5f7efef2013-10-15 09:50:08 +00005986 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
5987 TypeSourceInfo *T =
5988 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005989 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005990 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005991
David Majnemer5f7efef2013-10-15 09:50:08 +00005992 Var = getDerived().RebuildExceptionDecl(
5993 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
5994 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00005995 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00005996 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005997 }
Mike Stump11289f42009-09-09 15:08:12 +00005998
Douglas Gregorebe10102009-08-20 07:17:43 +00005999 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006000 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006001 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006002 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006003
David Majnemer5f7efef2013-10-15 09:50:08 +00006004 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006005 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00006006 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00006007
David Majnemer5f7efef2013-10-15 09:50:08 +00006008 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006009}
Mike Stump11289f42009-09-09 15:08:12 +00006010
David Majnemer5f7efef2013-10-15 09:50:08 +00006011template <typename Derived>
6012StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006013 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006014 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006015 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006016 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006017
Douglas Gregorebe10102009-08-20 07:17:43 +00006018 // Transform the handlers.
6019 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006020 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006021 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006022 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006023 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006024 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006025
Douglas Gregorebe10102009-08-20 07:17:43 +00006026 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
6027 Handlers.push_back(Handler.takeAs<Stmt>());
6028 }
Mike Stump11289f42009-09-09 15:08:12 +00006029
David Majnemer5f7efef2013-10-15 09:50:08 +00006030 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006031 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00006032 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00006033
John McCallb268a282010-08-23 23:25:46 +00006034 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006035 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006036}
Mike Stump11289f42009-09-09 15:08:12 +00006037
Richard Smith02e85f32011-04-14 22:09:26 +00006038template<typename Derived>
6039StmtResult
6040TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6041 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6042 if (Range.isInvalid())
6043 return StmtError();
6044
6045 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6046 if (BeginEnd.isInvalid())
6047 return StmtError();
6048
6049 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6050 if (Cond.isInvalid())
6051 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006052 if (Cond.get())
6053 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
6054 if (Cond.isInvalid())
6055 return StmtError();
6056 if (Cond.get())
6057 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smith02e85f32011-04-14 22:09:26 +00006058
6059 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6060 if (Inc.isInvalid())
6061 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006062 if (Inc.get())
6063 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smith02e85f32011-04-14 22:09:26 +00006064
6065 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6066 if (LoopVar.isInvalid())
6067 return StmtError();
6068
6069 StmtResult NewStmt = S;
6070 if (getDerived().AlwaysRebuild() ||
6071 Range.get() != S->getRangeStmt() ||
6072 BeginEnd.get() != S->getBeginEndStmt() ||
6073 Cond.get() != S->getCond() ||
6074 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006075 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006076 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6077 S->getColonLoc(), Range.get(),
6078 BeginEnd.get(), Cond.get(),
6079 Inc.get(), LoopVar.get(),
6080 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006081 if (NewStmt.isInvalid())
6082 return StmtError();
6083 }
Richard Smith02e85f32011-04-14 22:09:26 +00006084
6085 StmtResult Body = getDerived().TransformStmt(S->getBody());
6086 if (Body.isInvalid())
6087 return StmtError();
6088
6089 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6090 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006091 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006092 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6093 S->getColonLoc(), Range.get(),
6094 BeginEnd.get(), Cond.get(),
6095 Inc.get(), LoopVar.get(),
6096 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006097 if (NewStmt.isInvalid())
6098 return StmtError();
6099 }
Richard Smith02e85f32011-04-14 22:09:26 +00006100
6101 if (NewStmt.get() == S)
6102 return SemaRef.Owned(S);
6103
6104 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6105}
6106
John Wiegley1c0675e2011-04-28 01:08:34 +00006107template<typename Derived>
6108StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006109TreeTransform<Derived>::TransformMSDependentExistsStmt(
6110 MSDependentExistsStmt *S) {
6111 // Transform the nested-name-specifier, if any.
6112 NestedNameSpecifierLoc QualifierLoc;
6113 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006114 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006115 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6116 if (!QualifierLoc)
6117 return StmtError();
6118 }
6119
6120 // Transform the declaration name.
6121 DeclarationNameInfo NameInfo = S->getNameInfo();
6122 if (NameInfo.getName()) {
6123 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6124 if (!NameInfo.getName())
6125 return StmtError();
6126 }
6127
6128 // Check whether anything changed.
6129 if (!getDerived().AlwaysRebuild() &&
6130 QualifierLoc == S->getQualifierLoc() &&
6131 NameInfo.getName() == S->getNameInfo().getName())
6132 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006133
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006134 // Determine whether this name exists, if we can.
6135 CXXScopeSpec SS;
6136 SS.Adopt(QualifierLoc);
6137 bool Dependent = false;
6138 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
6139 case Sema::IER_Exists:
6140 if (S->isIfExists())
6141 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006142
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006143 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6144
6145 case Sema::IER_DoesNotExist:
6146 if (S->isIfNotExists())
6147 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006148
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006149 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006150
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006151 case Sema::IER_Dependent:
6152 Dependent = true;
6153 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006154
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006155 case Sema::IER_Error:
6156 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006157 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006158
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006159 // We need to continue with the instantiation, so do so now.
6160 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6161 if (SubStmt.isInvalid())
6162 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006163
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006164 // If we have resolved the name, just transform to the substatement.
6165 if (!Dependent)
6166 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006167
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006168 // The name is still dependent, so build a dependent expression again.
6169 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6170 S->isIfExists(),
6171 QualifierLoc,
6172 NameInfo,
6173 SubStmt.get());
6174}
6175
6176template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006177ExprResult
6178TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6179 NestedNameSpecifierLoc QualifierLoc;
6180 if (E->getQualifierLoc()) {
6181 QualifierLoc
6182 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6183 if (!QualifierLoc)
6184 return ExprError();
6185 }
6186
6187 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6188 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6189 if (!PD)
6190 return ExprError();
6191
6192 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6193 if (Base.isInvalid())
6194 return ExprError();
6195
6196 return new (SemaRef.getASTContext())
6197 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6198 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6199 QualifierLoc, E->getMemberLoc());
6200}
6201
David Majnemerfad8f482013-10-15 09:33:02 +00006202template <typename Derived>
6203StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006204 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006205 if (TryBlock.isInvalid())
6206 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006207
6208 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006209 if (Handler.isInvalid())
6210 return StmtError();
6211
David Majnemerfad8f482013-10-15 09:33:02 +00006212 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6213 Handler.get() == S->getHandler())
John Wiegley1c0675e2011-04-28 01:08:34 +00006214 return SemaRef.Owned(S);
6215
David Majnemerfad8f482013-10-15 09:33:02 +00006216 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
6217 TryBlock.take(), Handler.take());
John Wiegley1c0675e2011-04-28 01:08:34 +00006218}
6219
David Majnemerfad8f482013-10-15 09:33:02 +00006220template <typename Derived>
6221StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006222 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006223 if (Block.isInvalid())
6224 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006225
David Majnemerfad8f482013-10-15 09:33:02 +00006226 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.take());
John Wiegley1c0675e2011-04-28 01:08:34 +00006227}
6228
David Majnemerfad8f482013-10-15 09:33:02 +00006229template <typename Derived>
6230StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00006231 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00006232 if (FilterExpr.isInvalid())
6233 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006234
David Majnemer7e755502013-10-15 09:30:14 +00006235 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006236 if (Block.isInvalid())
6237 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006238
David Majnemerfad8f482013-10-15 09:33:02 +00006239 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.take(),
John Wiegley1c0675e2011-04-28 01:08:34 +00006240 Block.take());
6241}
6242
David Majnemerfad8f482013-10-15 09:33:02 +00006243template <typename Derived>
6244StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6245 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00006246 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6247 else
6248 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6249}
6250
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006251template<typename Derived>
6252StmtResult
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006253TreeTransform<Derived>::TransformOMPExecutableDirective(
6254 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006255
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006256 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00006257 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006258 ArrayRef<OMPClause *> Clauses = D->clauses();
6259 TClauses.reserve(Clauses.size());
6260 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6261 I != E; ++I) {
6262 if (*I) {
6263 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataev758e55e2013-09-06 18:03:48 +00006264 if (!Clause) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006265 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006266 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006267 TClauses.push_back(Clause);
6268 }
6269 else {
6270 TClauses.push_back(0);
6271 }
6272 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00006273 if (!D->getAssociatedStmt()) {
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()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006279 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006280 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006281
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006282 return getDerived().RebuildOMPExecutableDirective(D->getDirectiveKind(),
6283 TClauses,
6284 AssociatedStmt.take(),
6285 D->getLocStart(),
6286 D->getLocEnd());
6287}
6288
6289template<typename Derived>
6290StmtResult
6291TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6292 DeclarationNameInfo DirName;
6293 getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, 0);
6294 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6295 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6296 return Res;
6297}
6298
6299template<typename Derived>
6300StmtResult
6301TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
6302 DeclarationNameInfo DirName;
6303 getSema().StartOpenMPDSABlock(OMPD_simd, DirName, 0);
6304 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6305 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006306 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006307}
6308
6309template<typename Derived>
6310OMPClause *
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006311TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
6312 return getDerived().RebuildOMPIfClause(C->getCondition(), C->getLocStart(),
6313 C->getLParenLoc(), C->getLocEnd());
6314}
6315
6316template<typename Derived>
6317OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006318TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
6319 return getDerived().RebuildOMPDefaultClause(C->getDefaultKind(),
6320 C->getDefaultKindKwLoc(),
6321 C->getLocStart(),
6322 C->getLParenLoc(),
6323 C->getLocEnd());
6324}
6325
6326template<typename Derived>
6327OMPClause *
6328TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006329 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006330 Vars.reserve(C->varlist_size());
Alexey Bataev756c1962013-09-24 03:17:45 +00006331 for (OMPPrivateClause::varlist_iterator I = C->varlist_begin(),
6332 E = C->varlist_end();
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006333 I != E; ++I) {
6334 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6335 if (EVar.isInvalid())
6336 return 0;
6337 Vars.push_back(EVar.take());
6338 }
6339 return getDerived().RebuildOMPPrivateClause(Vars,
6340 C->getLocStart(),
6341 C->getLParenLoc(),
6342 C->getLocEnd());
6343}
6344
Alexey Bataev758e55e2013-09-06 18:03:48 +00006345template<typename Derived>
6346OMPClause *
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006347TreeTransform<Derived>::TransformOMPFirstprivateClause(
6348 OMPFirstprivateClause *C) {
6349 llvm::SmallVector<Expr *, 16> Vars;
6350 Vars.reserve(C->varlist_size());
6351 for (OMPFirstprivateClause::varlist_iterator I = C->varlist_begin(),
6352 E = C->varlist_end();
6353 I != E; ++I) {
6354 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6355 if (EVar.isInvalid())
6356 return 0;
6357 Vars.push_back(EVar.take());
6358 }
6359 return getDerived().RebuildOMPFirstprivateClause(Vars,
6360 C->getLocStart(),
6361 C->getLParenLoc(),
6362 C->getLocEnd());
6363}
6364
6365template<typename Derived>
6366OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00006367TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
6368 llvm::SmallVector<Expr *, 16> Vars;
6369 Vars.reserve(C->varlist_size());
Alexey Bataev756c1962013-09-24 03:17:45 +00006370 for (OMPSharedClause::varlist_iterator I = C->varlist_begin(),
6371 E = C->varlist_end();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006372 I != E; ++I) {
6373 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6374 if (EVar.isInvalid())
6375 return 0;
6376 Vars.push_back(EVar.take());
6377 }
6378 return getDerived().RebuildOMPSharedClause(Vars,
6379 C->getLocStart(),
6380 C->getLParenLoc(),
6381 C->getLocEnd());
6382}
6383
Douglas Gregorebe10102009-08-20 07:17:43 +00006384//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00006385// Expression transformation
6386//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00006387template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006388ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006389TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006390 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006391}
Mike Stump11289f42009-09-09 15:08:12 +00006392
6393template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006394ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006395TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006396 NestedNameSpecifierLoc QualifierLoc;
6397 if (E->getQualifierLoc()) {
6398 QualifierLoc
6399 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6400 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006401 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006402 }
John McCallce546572009-12-08 09:08:17 +00006403
6404 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006405 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6406 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006407 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00006408 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006409
John McCall815039a2010-08-17 21:27:17 +00006410 DeclarationNameInfo NameInfo = E->getNameInfo();
6411 if (NameInfo.getName()) {
6412 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6413 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006414 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00006415 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006416
6417 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006418 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006419 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006420 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00006421 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006422
6423 // Mark it referenced in the new context regardless.
6424 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00006425 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00006426
John McCallc3007a22010-10-26 07:05:15 +00006427 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006428 }
John McCallce546572009-12-08 09:08:17 +00006429
6430 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00006431 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006432 TemplateArgs = &TransArgs;
6433 TransArgs.setLAngleLoc(E->getLAngleLoc());
6434 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006435 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6436 E->getNumTemplateArgs(),
6437 TransArgs))
6438 return ExprError();
John McCallce546572009-12-08 09:08:17 +00006439 }
6440
Chad Rosier1dcde962012-08-08 18:46:20 +00006441 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00006442 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006443}
Mike Stump11289f42009-09-09 15:08:12 +00006444
Douglas Gregora16548e2009-08-11 05:31:07 +00006445template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006446ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006447TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006448 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006449}
Mike Stump11289f42009-09-09 15:08:12 +00006450
Douglas Gregora16548e2009-08-11 05:31:07 +00006451template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006452ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006453TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006454 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006455}
Mike Stump11289f42009-09-09 15:08:12 +00006456
Douglas Gregora16548e2009-08-11 05:31:07 +00006457template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006458ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006459TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006460 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006461}
Mike Stump11289f42009-09-09 15:08:12 +00006462
Douglas Gregora16548e2009-08-11 05:31:07 +00006463template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006464ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006465TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006466 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006467}
Mike Stump11289f42009-09-09 15:08:12 +00006468
Douglas Gregora16548e2009-08-11 05:31:07 +00006469template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006470ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006471TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006472 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006473}
6474
6475template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006476ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00006477TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00006478 if (FunctionDecl *FD = E->getDirectCallee())
6479 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00006480 return SemaRef.MaybeBindToTemporary(E);
6481}
6482
6483template<typename Derived>
6484ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00006485TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6486 ExprResult ControllingExpr =
6487 getDerived().TransformExpr(E->getControllingExpr());
6488 if (ControllingExpr.isInvalid())
6489 return ExprError();
6490
Chris Lattner01cf8db2011-07-20 06:58:45 +00006491 SmallVector<Expr *, 4> AssocExprs;
6492 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00006493 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6494 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6495 if (TS) {
6496 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6497 if (!AssocType)
6498 return ExprError();
6499 AssocTypes.push_back(AssocType);
6500 } else {
6501 AssocTypes.push_back(0);
6502 }
6503
6504 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6505 if (AssocExpr.isInvalid())
6506 return ExprError();
6507 AssocExprs.push_back(AssocExpr.release());
6508 }
6509
6510 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6511 E->getDefaultLoc(),
6512 E->getRParenLoc(),
6513 ControllingExpr.release(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00006514 AssocTypes,
6515 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00006516}
6517
6518template<typename Derived>
6519ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006520TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006521 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006522 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006523 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006524
Douglas Gregora16548e2009-08-11 05:31:07 +00006525 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006526 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006527
John McCallb268a282010-08-23 23:25:46 +00006528 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006529 E->getRParen());
6530}
6531
Richard Smithdb2630f2012-10-21 03:28:35 +00006532/// \brief The operand of a unary address-of operator has special rules: it's
6533/// allowed to refer to a non-static member of a class even if there's no 'this'
6534/// object available.
6535template<typename Derived>
6536ExprResult
6537TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6538 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6539 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6540 else
6541 return getDerived().TransformExpr(E);
6542}
6543
Mike Stump11289f42009-09-09 15:08:12 +00006544template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006545ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006546TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00006547 ExprResult SubExpr;
6548 if (E->getOpcode() == UO_AddrOf)
6549 SubExpr = TransformAddressOfOperand(E->getSubExpr());
6550 else
6551 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006552 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006553 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006554
Douglas Gregora16548e2009-08-11 05:31:07 +00006555 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006556 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006557
Douglas Gregora16548e2009-08-11 05:31:07 +00006558 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6559 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006560 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006561}
Mike Stump11289f42009-09-09 15:08:12 +00006562
Douglas Gregora16548e2009-08-11 05:31:07 +00006563template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006564ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00006565TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6566 // Transform the type.
6567 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6568 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00006569 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006570
Douglas Gregor882211c2010-04-28 22:16:22 +00006571 // Transform all of the components into components similar to what the
6572 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00006573 // FIXME: It would be slightly more efficient in the non-dependent case to
6574 // just map FieldDecls, rather than requiring the rebuilder to look for
6575 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00006576 // template code that we don't care.
6577 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00006578 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00006579 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006580 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00006581 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6582 const Node &ON = E->getComponent(I);
6583 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00006584 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00006585 Comp.LocStart = ON.getSourceRange().getBegin();
6586 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00006587 switch (ON.getKind()) {
6588 case Node::Array: {
6589 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00006590 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00006591 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006592 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006593
Douglas Gregor882211c2010-04-28 22:16:22 +00006594 ExprChanged = ExprChanged || Index.get() != FromIndex;
6595 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00006596 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00006597 break;
6598 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006599
Douglas Gregor882211c2010-04-28 22:16:22 +00006600 case Node::Field:
6601 case Node::Identifier:
6602 Comp.isBrackets = false;
6603 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00006604 if (!Comp.U.IdentInfo)
6605 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00006606
Douglas Gregor882211c2010-04-28 22:16:22 +00006607 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006608
Douglas Gregord1702062010-04-29 00:18:15 +00006609 case Node::Base:
6610 // Will be recomputed during the rebuild.
6611 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00006612 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006613
Douglas Gregor882211c2010-04-28 22:16:22 +00006614 Components.push_back(Comp);
6615 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006616
Douglas Gregor882211c2010-04-28 22:16:22 +00006617 // If nothing changed, retain the existing expression.
6618 if (!getDerived().AlwaysRebuild() &&
6619 Type == E->getTypeSourceInfo() &&
6620 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00006621 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00006622
Douglas Gregor882211c2010-04-28 22:16:22 +00006623 // Build a new offsetof expression.
6624 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6625 Components.data(), Components.size(),
6626 E->getRParenLoc());
6627}
6628
6629template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006630ExprResult
John McCall8d69a212010-11-15 23:31:06 +00006631TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6632 assert(getDerived().AlreadyTransformed(E->getType()) &&
6633 "opaque value expression requires transformation");
6634 return SemaRef.Owned(E);
6635}
6636
6637template<typename Derived>
6638ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00006639TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00006640 // Rebuild the syntactic form. The original syntactic form has
6641 // opaque-value expressions in it, so strip those away and rebuild
6642 // the result. This is a really awful way of doing this, but the
6643 // better solution (rebuilding the semantic expressions and
6644 // rebinding OVEs as necessary) doesn't work; we'd need
6645 // TreeTransform to not strip away implicit conversions.
6646 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6647 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00006648 if (result.isInvalid()) return ExprError();
6649
6650 // If that gives us a pseudo-object result back, the pseudo-object
6651 // expression must have been an lvalue-to-rvalue conversion which we
6652 // should reapply.
6653 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6654 result = SemaRef.checkPseudoObjectRValue(result.take());
6655
6656 return result;
6657}
6658
6659template<typename Derived>
6660ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00006661TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6662 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006663 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00006664 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00006665
John McCallbcd03502009-12-07 02:54:59 +00006666 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00006667 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006668 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006669
John McCall4c98fd82009-11-04 07:28:41 +00006670 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00006671 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006672
Peter Collingbournee190dee2011-03-11 19:24:49 +00006673 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6674 E->getKind(),
6675 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006676 }
Mike Stump11289f42009-09-09 15:08:12 +00006677
Eli Friedmane4f22df2012-02-29 04:03:55 +00006678 // C++0x [expr.sizeof]p1:
6679 // The operand is either an expression, which is an unevaluated operand
6680 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00006681 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6682 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00006683
Eli Friedmane4f22df2012-02-29 04:03:55 +00006684 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6685 if (SubExpr.isInvalid())
6686 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006687
Eli Friedmane4f22df2012-02-29 04:03:55 +00006688 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6689 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006690
Peter Collingbournee190dee2011-03-11 19:24:49 +00006691 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6692 E->getOperatorLoc(),
6693 E->getKind(),
6694 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006695}
Mike Stump11289f42009-09-09 15:08:12 +00006696
Douglas Gregora16548e2009-08-11 05:31:07 +00006697template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006698ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006699TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006700 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006701 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006702 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006703
John McCalldadc5752010-08-24 06:29:42 +00006704 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006705 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006706 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006707
6708
Douglas Gregora16548e2009-08-11 05:31:07 +00006709 if (!getDerived().AlwaysRebuild() &&
6710 LHS.get() == E->getLHS() &&
6711 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006712 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006713
John McCallb268a282010-08-23 23:25:46 +00006714 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006715 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006716 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006717 E->getRBracketLoc());
6718}
Mike Stump11289f42009-09-09 15:08:12 +00006719
6720template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006721ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006722TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006723 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00006724 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006725 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006726 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006727
6728 // Transform arguments.
6729 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006730 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00006731 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00006732 &ArgChanged))
6733 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006734
Douglas Gregora16548e2009-08-11 05:31:07 +00006735 if (!getDerived().AlwaysRebuild() &&
6736 Callee.get() == E->getCallee() &&
6737 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00006738 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00006739
Douglas Gregora16548e2009-08-11 05:31:07 +00006740 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00006741 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006742 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00006743 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006744 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00006745 E->getRParenLoc());
6746}
Mike Stump11289f42009-09-09 15:08:12 +00006747
6748template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006749ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006750TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006751 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006752 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006753 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006754
Douglas Gregorea972d32011-02-28 21:54:11 +00006755 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006756 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006757 QualifierLoc
6758 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006759
Douglas Gregorea972d32011-02-28 21:54:11 +00006760 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006761 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006762 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00006763 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00006764
Eli Friedman2cfcef62009-12-04 06:40:45 +00006765 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006766 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6767 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006768 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00006769 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006770
John McCall16df1e52010-03-30 21:47:33 +00006771 NamedDecl *FoundDecl = E->getFoundDecl();
6772 if (FoundDecl == E->getMemberDecl()) {
6773 FoundDecl = Member;
6774 } else {
6775 FoundDecl = cast_or_null<NamedDecl>(
6776 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6777 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00006778 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00006779 }
6780
Douglas Gregora16548e2009-08-11 05:31:07 +00006781 if (!getDerived().AlwaysRebuild() &&
6782 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006783 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006784 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00006785 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00006786 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006787
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006788 // Mark it referenced in the new context regardless.
6789 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00006790 SemaRef.MarkMemberReferenced(E);
6791
John McCallc3007a22010-10-26 07:05:15 +00006792 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006793 }
Douglas Gregora16548e2009-08-11 05:31:07 +00006794
John McCall6b51f282009-11-23 01:53:49 +00006795 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00006796 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00006797 TransArgs.setLAngleLoc(E->getLAngleLoc());
6798 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006799 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6800 E->getNumTemplateArgs(),
6801 TransArgs))
6802 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006803 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006804
Douglas Gregora16548e2009-08-11 05:31:07 +00006805 // FIXME: Bogus source location for the operator
6806 SourceLocation FakeOperatorLoc
6807 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6808
John McCall38836f02010-01-15 08:34:02 +00006809 // FIXME: to do this check properly, we will need to preserve the
6810 // first-qualifier-in-scope here, just in case we had a dependent
6811 // base (and therefore couldn't do the check) and a
6812 // nested-name-qualifier (and therefore could do the lookup).
6813 NamedDecl *FirstQualifierInScope = 0;
6814
John McCallb268a282010-08-23 23:25:46 +00006815 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006816 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00006817 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00006818 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006819 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006820 Member,
John McCall16df1e52010-03-30 21:47:33 +00006821 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00006822 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00006823 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00006824 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00006825}
Mike Stump11289f42009-09-09 15:08:12 +00006826
Douglas Gregora16548e2009-08-11 05:31:07 +00006827template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006828ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006829TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006830 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006831 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006832 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006833
John McCalldadc5752010-08-24 06:29:42 +00006834 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006835 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006836 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006837
Douglas Gregora16548e2009-08-11 05:31:07 +00006838 if (!getDerived().AlwaysRebuild() &&
6839 LHS.get() == E->getLHS() &&
6840 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006841 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006842
Lang Hames5de91cc2012-10-02 04:45:10 +00006843 Sema::FPContractStateRAII FPContractState(getSema());
6844 getSema().FPFeatures.fp_contract = E->isFPContractable();
6845
Douglas Gregora16548e2009-08-11 05:31:07 +00006846 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006847 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006848}
6849
Mike Stump11289f42009-09-09 15:08:12 +00006850template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006851ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006852TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00006853 CompoundAssignOperator *E) {
6854 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006855}
Mike Stump11289f42009-09-09 15:08:12 +00006856
Douglas Gregora16548e2009-08-11 05:31:07 +00006857template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00006858ExprResult TreeTransform<Derived>::
6859TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6860 // Just rebuild the common and RHS expressions and see whether we
6861 // get any changes.
6862
6863 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6864 if (commonExpr.isInvalid())
6865 return ExprError();
6866
6867 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6868 if (rhs.isInvalid())
6869 return ExprError();
6870
6871 if (!getDerived().AlwaysRebuild() &&
6872 commonExpr.get() == e->getCommon() &&
6873 rhs.get() == e->getFalseExpr())
6874 return SemaRef.Owned(e);
6875
6876 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6877 e->getQuestionLoc(),
6878 0,
6879 e->getColonLoc(),
6880 rhs.get());
6881}
6882
6883template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006884ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006885TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006886 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006887 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006888 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006889
John McCalldadc5752010-08-24 06:29:42 +00006890 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006891 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006892 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006893
John McCalldadc5752010-08-24 06:29:42 +00006894 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006895 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006896 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006897
Douglas Gregora16548e2009-08-11 05:31:07 +00006898 if (!getDerived().AlwaysRebuild() &&
6899 Cond.get() == E->getCond() &&
6900 LHS.get() == E->getLHS() &&
6901 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006902 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006903
John McCallb268a282010-08-23 23:25:46 +00006904 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006905 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00006906 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006907 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006908 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006909}
Mike Stump11289f42009-09-09 15:08:12 +00006910
6911template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006912ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006913TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00006914 // Implicit casts are eliminated during transformation, since they
6915 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00006916 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006917}
Mike Stump11289f42009-09-09 15:08:12 +00006918
Douglas Gregora16548e2009-08-11 05:31:07 +00006919template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006920ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006921TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006922 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6923 if (!Type)
6924 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006925
John McCalldadc5752010-08-24 06:29:42 +00006926 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006927 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006928 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006929 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006930
Douglas Gregora16548e2009-08-11 05:31:07 +00006931 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006932 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006933 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006934 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006935
John McCall97513962010-01-15 18:39:57 +00006936 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006937 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006938 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006939 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006940}
Mike Stump11289f42009-09-09 15:08:12 +00006941
Douglas Gregora16548e2009-08-11 05:31:07 +00006942template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006943ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006944TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00006945 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6946 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6947 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006948 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006949
John McCalldadc5752010-08-24 06:29:42 +00006950 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00006951 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006952 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006953
Douglas Gregora16548e2009-08-11 05:31:07 +00006954 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00006955 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006956 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00006957 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006958
John McCall5d7aa7f2010-01-19 22:33:45 +00006959 // Note: the expression type doesn't necessarily match the
6960 // type-as-written, but that's okay, because it should always be
6961 // derivable from the initializer.
6962
John McCalle15bbff2010-01-18 19:35:47 +00006963 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00006964 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00006965 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006966}
Mike Stump11289f42009-09-09 15:08:12 +00006967
Douglas Gregora16548e2009-08-11 05:31:07 +00006968template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006969ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006970TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006971 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006972 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006973 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006974
Douglas Gregora16548e2009-08-11 05:31:07 +00006975 if (!getDerived().AlwaysRebuild() &&
6976 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006977 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006978
Douglas Gregora16548e2009-08-11 05:31:07 +00006979 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00006980 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006981 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00006982 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006983 E->getAccessorLoc(),
6984 E->getAccessor());
6985}
Mike Stump11289f42009-09-09 15:08:12 +00006986
Douglas Gregora16548e2009-08-11 05:31:07 +00006987template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006988ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006989TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006990 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00006991
Benjamin Kramerf0623432012-08-23 22:51:59 +00006992 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00006993 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00006994 Inits, &InitChanged))
6995 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006996
Douglas Gregora16548e2009-08-11 05:31:07 +00006997 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00006998 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006999
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007000 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00007001 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007002}
Mike Stump11289f42009-09-09 15:08:12 +00007003
Douglas Gregora16548e2009-08-11 05:31:07 +00007004template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007005ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007006TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007007 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00007008
Douglas Gregorebe10102009-08-20 07:17:43 +00007009 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00007010 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007011 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007012 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007013
Douglas Gregorebe10102009-08-20 07:17:43 +00007014 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007015 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00007016 bool ExprChanged = false;
7017 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
7018 DEnd = E->designators_end();
7019 D != DEnd; ++D) {
7020 if (D->isFieldDesignator()) {
7021 Desig.AddDesignator(Designator::getField(D->getFieldName(),
7022 D->getDotLoc(),
7023 D->getFieldLoc()));
7024 continue;
7025 }
Mike Stump11289f42009-09-09 15:08:12 +00007026
Douglas Gregora16548e2009-08-11 05:31:07 +00007027 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00007028 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007029 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007030 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007031
7032 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007033 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007034
Douglas Gregora16548e2009-08-11 05:31:07 +00007035 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
7036 ArrayExprs.push_back(Index.release());
7037 continue;
7038 }
Mike Stump11289f42009-09-09 15:08:12 +00007039
Douglas Gregora16548e2009-08-11 05:31:07 +00007040 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00007041 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00007042 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7043 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007044 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007045
John McCalldadc5752010-08-24 06:29:42 +00007046 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007047 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007048 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007049
7050 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007051 End.get(),
7052 D->getLBracketLoc(),
7053 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007054
Douglas Gregora16548e2009-08-11 05:31:07 +00007055 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7056 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00007057
Douglas Gregora16548e2009-08-11 05:31:07 +00007058 ArrayExprs.push_back(Start.release());
7059 ArrayExprs.push_back(End.release());
7060 }
Mike Stump11289f42009-09-09 15:08:12 +00007061
Douglas Gregora16548e2009-08-11 05:31:07 +00007062 if (!getDerived().AlwaysRebuild() &&
7063 Init.get() == E->getInit() &&
7064 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00007065 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007066
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007067 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007068 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007069 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007070}
Mike Stump11289f42009-09-09 15:08:12 +00007071
Douglas Gregora16548e2009-08-11 05:31:07 +00007072template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007073ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007074TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007075 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00007076 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00007077
Douglas Gregor3da3c062009-10-28 00:29:27 +00007078 // FIXME: Will we ever have proper type location here? Will we actually
7079 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00007080 QualType T = getDerived().TransformType(E->getType());
7081 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007082 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007083
Douglas Gregora16548e2009-08-11 05:31:07 +00007084 if (!getDerived().AlwaysRebuild() &&
7085 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00007086 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007087
Douglas Gregora16548e2009-08-11 05:31:07 +00007088 return getDerived().RebuildImplicitValueInitExpr(T);
7089}
Mike Stump11289f42009-09-09 15:08:12 +00007090
Douglas Gregora16548e2009-08-11 05:31:07 +00007091template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007092ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007093TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00007094 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7095 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007096 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007097
John McCalldadc5752010-08-24 06:29:42 +00007098 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007099 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007100 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007101
Douglas Gregora16548e2009-08-11 05:31:07 +00007102 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00007103 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007104 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007105 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007106
John McCallb268a282010-08-23 23:25:46 +00007107 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00007108 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007109}
7110
7111template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007112ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007113TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007114 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007115 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00007116 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7117 &ArgumentChanged))
7118 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007119
Douglas Gregora16548e2009-08-11 05:31:07 +00007120 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007121 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00007122 E->getRParenLoc());
7123}
Mike Stump11289f42009-09-09 15:08:12 +00007124
Douglas Gregora16548e2009-08-11 05:31:07 +00007125/// \brief Transform an address-of-label expression.
7126///
7127/// By default, the transformation of an address-of-label expression always
7128/// rebuilds the expression, so that the label identifier can be resolved to
7129/// the corresponding label statement by semantic analysis.
7130template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007131ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007132TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00007133 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7134 E->getLabel());
7135 if (!LD)
7136 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007137
Douglas Gregora16548e2009-08-11 05:31:07 +00007138 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00007139 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00007140}
Mike Stump11289f42009-09-09 15:08:12 +00007141
7142template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00007143ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007144TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00007145 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00007146 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00007147 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00007148 if (SubStmt.isInvalid()) {
7149 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00007150 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00007151 }
Mike Stump11289f42009-09-09 15:08:12 +00007152
Douglas Gregora16548e2009-08-11 05:31:07 +00007153 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00007154 SubStmt.get() == E->getSubStmt()) {
7155 // Calling this an 'error' is unintuitive, but it does the right thing.
7156 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007157 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00007158 }
Mike Stump11289f42009-09-09 15:08:12 +00007159
7160 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007161 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007162 E->getRParenLoc());
7163}
Mike Stump11289f42009-09-09 15:08:12 +00007164
Douglas Gregora16548e2009-08-11 05:31:07 +00007165template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007166ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007167TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007168 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007169 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007170 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007171
John McCalldadc5752010-08-24 06:29:42 +00007172 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007173 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007174 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007175
John McCalldadc5752010-08-24 06:29:42 +00007176 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007177 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007178 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007179
Douglas Gregora16548e2009-08-11 05:31:07 +00007180 if (!getDerived().AlwaysRebuild() &&
7181 Cond.get() == E->getCond() &&
7182 LHS.get() == E->getLHS() &&
7183 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00007184 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007185
Douglas Gregora16548e2009-08-11 05:31:07 +00007186 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00007187 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007188 E->getRParenLoc());
7189}
Mike Stump11289f42009-09-09 15:08:12 +00007190
Douglas Gregora16548e2009-08-11 05:31:07 +00007191template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007192ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007193TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007194 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007195}
7196
7197template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007198ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007199TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007200 switch (E->getOperator()) {
7201 case OO_New:
7202 case OO_Delete:
7203 case OO_Array_New:
7204 case OO_Array_Delete:
7205 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00007206
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007207 case OO_Call: {
7208 // This is a call to an object's operator().
7209 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7210
7211 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00007212 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007213 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007214 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007215
7216 // FIXME: Poor location information
7217 SourceLocation FakeLParenLoc
7218 = SemaRef.PP.getLocForEndOfToken(
7219 static_cast<Expr *>(Object.get())->getLocEnd());
7220
7221 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007222 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007223 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00007224 Args))
7225 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007226
John McCallb268a282010-08-23 23:25:46 +00007227 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007228 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007229 E->getLocEnd());
7230 }
7231
7232#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7233 case OO_##Name:
7234#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7235#include "clang/Basic/OperatorKinds.def"
7236 case OO_Subscript:
7237 // Handled below.
7238 break;
7239
7240 case OO_Conditional:
7241 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007242
7243 case OO_None:
7244 case NUM_OVERLOADED_OPERATORS:
7245 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007246 }
7247
John McCalldadc5752010-08-24 06:29:42 +00007248 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007249 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007250 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007251
Richard Smithdb2630f2012-10-21 03:28:35 +00007252 ExprResult First;
7253 if (E->getOperator() == OO_Amp)
7254 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7255 else
7256 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007257 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007258 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007259
John McCalldadc5752010-08-24 06:29:42 +00007260 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00007261 if (E->getNumArgs() == 2) {
7262 Second = getDerived().TransformExpr(E->getArg(1));
7263 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007264 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007265 }
Mike Stump11289f42009-09-09 15:08:12 +00007266
Douglas Gregora16548e2009-08-11 05:31:07 +00007267 if (!getDerived().AlwaysRebuild() &&
7268 Callee.get() == E->getCallee() &&
7269 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00007270 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007271 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007272
Lang Hames5de91cc2012-10-02 04:45:10 +00007273 Sema::FPContractStateRAII FPContractState(getSema());
7274 getSema().FPFeatures.fp_contract = E->isFPContractable();
7275
Douglas Gregora16548e2009-08-11 05:31:07 +00007276 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7277 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00007278 Callee.get(),
7279 First.get(),
7280 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007281}
Mike Stump11289f42009-09-09 15:08:12 +00007282
Douglas Gregora16548e2009-08-11 05:31:07 +00007283template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007284ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007285TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7286 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007287}
Mike Stump11289f42009-09-09 15:08:12 +00007288
Douglas Gregora16548e2009-08-11 05:31:07 +00007289template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007290ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00007291TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7292 // Transform the callee.
7293 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7294 if (Callee.isInvalid())
7295 return ExprError();
7296
7297 // Transform exec config.
7298 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7299 if (EC.isInvalid())
7300 return ExprError();
7301
7302 // Transform arguments.
7303 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007304 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007305 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007306 &ArgChanged))
7307 return ExprError();
7308
7309 if (!getDerived().AlwaysRebuild() &&
7310 Callee.get() == E->getCallee() &&
7311 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007312 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00007313
7314 // FIXME: Wrong source location information for the '('.
7315 SourceLocation FakeLParenLoc
7316 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7317 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007318 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007319 E->getRParenLoc(), EC.get());
7320}
7321
7322template<typename Derived>
7323ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007324TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007325 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7326 if (!Type)
7327 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007328
John McCalldadc5752010-08-24 06:29:42 +00007329 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007330 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007331 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007332 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007333
Douglas Gregora16548e2009-08-11 05:31:07 +00007334 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007335 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007336 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007337 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007338 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00007339 E->getStmtClass(),
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007340 E->getAngleBrackets().getBegin(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007341 Type,
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007342 E->getAngleBrackets().getEnd(),
7343 // FIXME. this should be '(' location
7344 E->getAngleBrackets().getEnd(),
John McCallb268a282010-08-23 23:25:46 +00007345 SubExpr.get(),
Abramo Bagnara9fb43862012-10-15 21:08:58 +00007346 E->getRParenLoc());
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
John McCall47f29ea2009-12-08 09:21:05 +00007351TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7352 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007353}
Mike Stump11289f42009-09-09 15:08:12 +00007354
7355template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007356ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007357TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7358 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00007359}
7360
Douglas Gregora16548e2009-08-11 05:31:07 +00007361template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007362ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007363TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007364 CXXReinterpretCastExpr *E) {
7365 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007366}
Mike Stump11289f42009-09-09 15:08:12 +00007367
Douglas Gregora16548e2009-08-11 05:31:07 +00007368template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007369ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007370TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7371 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007372}
Mike Stump11289f42009-09-09 15:08:12 +00007373
Douglas Gregora16548e2009-08-11 05:31:07 +00007374template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007375ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007376TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007377 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007378 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7379 if (!Type)
7380 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007381
John McCalldadc5752010-08-24 06:29:42 +00007382 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007383 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007384 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007385 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007386
Douglas Gregora16548e2009-08-11 05:31:07 +00007387 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007388 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007389 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007390 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007391
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007392 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00007393 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007394 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007395 E->getRParenLoc());
7396}
Mike Stump11289f42009-09-09 15:08:12 +00007397
Douglas Gregora16548e2009-08-11 05:31:07 +00007398template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007399ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007400TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007401 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00007402 TypeSourceInfo *TInfo
7403 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7404 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007405 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007406
Douglas Gregora16548e2009-08-11 05:31:07 +00007407 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00007408 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007409 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007410
Douglas Gregor9da64192010-04-26 22:37:10 +00007411 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7412 E->getLocStart(),
7413 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007414 E->getLocEnd());
7415 }
Mike Stump11289f42009-09-09 15:08:12 +00007416
Eli Friedman456f0182012-01-20 01:26:23 +00007417 // We don't know whether the subexpression is potentially evaluated until
7418 // after we perform semantic analysis. We speculatively assume it is
7419 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00007420 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00007421 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7422 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007423
John McCalldadc5752010-08-24 06:29:42 +00007424 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00007425 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007426 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007427
Douglas Gregora16548e2009-08-11 05:31:07 +00007428 if (!getDerived().AlwaysRebuild() &&
7429 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00007430 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007431
Douglas Gregor9da64192010-04-26 22:37:10 +00007432 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7433 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007434 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007435 E->getLocEnd());
7436}
7437
7438template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007439ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00007440TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7441 if (E->isTypeOperand()) {
7442 TypeSourceInfo *TInfo
7443 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7444 if (!TInfo)
7445 return ExprError();
7446
7447 if (!getDerived().AlwaysRebuild() &&
7448 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007449 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00007450
Douglas Gregor69735112011-03-06 17:40:41 +00007451 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00007452 E->getLocStart(),
7453 TInfo,
7454 E->getLocEnd());
7455 }
7456
Francois Pichet9f4f2072010-09-08 12:20:18 +00007457 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7458
7459 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7460 if (SubExpr.isInvalid())
7461 return ExprError();
7462
7463 if (!getDerived().AlwaysRebuild() &&
7464 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00007465 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00007466
7467 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7468 E->getLocStart(),
7469 SubExpr.get(),
7470 E->getLocEnd());
7471}
7472
7473template<typename Derived>
7474ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007475TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007476 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007477}
Mike Stump11289f42009-09-09 15:08:12 +00007478
Douglas Gregora16548e2009-08-11 05:31:07 +00007479template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007480ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007481TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007482 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007483 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007484}
Mike Stump11289f42009-09-09 15:08:12 +00007485
Douglas Gregora16548e2009-08-11 05:31:07 +00007486template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007487ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007488TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00007489 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00007490
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007491 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7492 // Make sure that we capture 'this'.
7493 getSema().CheckCXXThisCapture(E->getLocStart());
John McCallc3007a22010-10-26 07:05:15 +00007494 return SemaRef.Owned(E);
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007495 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007496
Douglas Gregorb15af892010-01-07 23:12:05 +00007497 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007498}
Mike Stump11289f42009-09-09 15:08:12 +00007499
Douglas Gregora16548e2009-08-11 05:31:07 +00007500template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007501ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007502TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007503 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007504 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007505 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007506
Douglas Gregora16548e2009-08-11 05:31:07 +00007507 if (!getDerived().AlwaysRebuild() &&
7508 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007509 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007510
Douglas Gregor53e191ed2011-07-06 22:04:06 +00007511 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7512 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00007513}
Mike Stump11289f42009-09-09 15:08:12 +00007514
Douglas Gregora16548e2009-08-11 05:31:07 +00007515template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007516ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007517TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00007518 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007519 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7520 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007521 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00007522 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007523
Chandler Carruth794da4c2010-02-08 06:42:49 +00007524 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007525 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00007526 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007527
Douglas Gregor033f6752009-12-23 23:03:06 +00007528 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00007529}
Mike Stump11289f42009-09-09 15:08:12 +00007530
Douglas Gregora16548e2009-08-11 05:31:07 +00007531template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007532ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00007533TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
7534 FieldDecl *Field
7535 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
7536 E->getField()));
7537 if (!Field)
7538 return ExprError();
7539
7540 if (!getDerived().AlwaysRebuild() && Field == E->getField())
7541 return SemaRef.Owned(E);
7542
7543 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
7544}
7545
7546template<typename Derived>
7547ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00007548TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7549 CXXScalarValueInitExpr *E) {
7550 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7551 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007552 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007553
Douglas Gregora16548e2009-08-11 05:31:07 +00007554 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007555 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007556 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007557
Chad Rosier1dcde962012-08-08 18:46:20 +00007558 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00007559 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00007560 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007561}
Mike Stump11289f42009-09-09 15:08:12 +00007562
Douglas Gregora16548e2009-08-11 05:31:07 +00007563template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007564ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007565TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007566 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00007567 TypeSourceInfo *AllocTypeInfo
7568 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7569 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007570 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007571
Douglas Gregora16548e2009-08-11 05:31:07 +00007572 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00007573 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00007574 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007575 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007576
Douglas Gregora16548e2009-08-11 05:31:07 +00007577 // Transform the placement arguments (if any).
7578 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007579 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00007580 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00007581 E->getNumPlacementArgs(), true,
7582 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00007583 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007584
Sebastian Redl6047f072012-02-16 12:22:20 +00007585 // Transform the initializer (if any).
7586 Expr *OldInit = E->getInitializer();
7587 ExprResult NewInit;
7588 if (OldInit)
7589 NewInit = getDerived().TransformExpr(OldInit);
7590 if (NewInit.isInvalid())
7591 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007592
Sebastian Redl6047f072012-02-16 12:22:20 +00007593 // Transform new operator and delete operator.
Douglas Gregord2d9da02010-02-26 00:38:10 +00007594 FunctionDecl *OperatorNew = 0;
7595 if (E->getOperatorNew()) {
7596 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007597 getDerived().TransformDecl(E->getLocStart(),
7598 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007599 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00007600 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007601 }
7602
7603 FunctionDecl *OperatorDelete = 0;
7604 if (E->getOperatorDelete()) {
7605 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007606 getDerived().TransformDecl(E->getLocStart(),
7607 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007608 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007609 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007610 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007611
Douglas Gregora16548e2009-08-11 05:31:07 +00007612 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00007613 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007614 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00007615 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007616 OperatorNew == E->getOperatorNew() &&
7617 OperatorDelete == E->getOperatorDelete() &&
7618 !ArgumentChanged) {
7619 // Mark any declarations we need as referenced.
7620 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00007621 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007622 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007623 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007624 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00007625
Sebastian Redl6047f072012-02-16 12:22:20 +00007626 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00007627 QualType ElementType
7628 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7629 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7630 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7631 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00007632 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00007633 }
7634 }
7635 }
Sebastian Redl6047f072012-02-16 12:22:20 +00007636
John McCallc3007a22010-10-26 07:05:15 +00007637 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007638 }
Mike Stump11289f42009-09-09 15:08:12 +00007639
Douglas Gregor0744ef62010-09-07 21:49:58 +00007640 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007641 if (!ArraySize.get()) {
7642 // If no array size was specified, but the new expression was
7643 // instantiated with an array type (e.g., "new T" where T is
7644 // instantiated with "int[4]"), extract the outer bound from the
7645 // array type as our array size. We do this with constant and
7646 // dependently-sized array types.
7647 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7648 if (!ArrayT) {
7649 // Do nothing
7650 } else if (const ConstantArrayType *ConsArrayT
7651 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007652 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007653 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier1dcde962012-08-08 18:46:20 +00007654 ConsArrayT->getSize(),
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007655 SemaRef.Context.getSizeType(),
7656 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007657 AllocType = ConsArrayT->getElementType();
7658 } else if (const DependentSizedArrayType *DepArrayT
7659 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7660 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00007661 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007662 AllocType = DepArrayT->getElementType();
7663 }
7664 }
7665 }
Sebastian Redl6047f072012-02-16 12:22:20 +00007666
Douglas Gregora16548e2009-08-11 05:31:07 +00007667 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7668 E->isGlobalNew(),
7669 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007670 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007671 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00007672 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007673 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00007674 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00007675 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00007676 E->getDirectInitRange(),
7677 NewInit.take());
Douglas Gregora16548e2009-08-11 05:31:07 +00007678}
Mike Stump11289f42009-09-09 15:08:12 +00007679
Douglas Gregora16548e2009-08-11 05:31:07 +00007680template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007681ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007682TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007683 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00007684 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007685 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007686
Douglas Gregord2d9da02010-02-26 00:38:10 +00007687 // Transform the delete operator, if known.
7688 FunctionDecl *OperatorDelete = 0;
7689 if (E->getOperatorDelete()) {
7690 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007691 getDerived().TransformDecl(E->getLocStart(),
7692 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007693 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007694 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007695 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007696
Douglas Gregora16548e2009-08-11 05:31:07 +00007697 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007698 Operand.get() == E->getArgument() &&
7699 OperatorDelete == E->getOperatorDelete()) {
7700 // Mark any declarations we need as referenced.
7701 // FIXME: instantiation-specific.
7702 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007703 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00007704
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00007705 if (!E->getArgument()->isTypeDependent()) {
7706 QualType Destroyed = SemaRef.Context.getBaseElementType(
7707 E->getDestroyedType());
7708 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7709 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00007710 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00007711 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00007712 }
7713 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007714
John McCallc3007a22010-10-26 07:05:15 +00007715 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007716 }
Mike Stump11289f42009-09-09 15:08:12 +00007717
Douglas Gregora16548e2009-08-11 05:31:07 +00007718 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7719 E->isGlobalDelete(),
7720 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00007721 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007722}
Mike Stump11289f42009-09-09 15:08:12 +00007723
Douglas Gregora16548e2009-08-11 05:31:07 +00007724template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007725ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00007726TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007727 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007728 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00007729 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007730 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007731
John McCallba7bf592010-08-24 05:47:05 +00007732 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00007733 bool MayBePseudoDestructor = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00007734 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007735 E->getOperatorLoc(),
7736 E->isArrow()? tok::arrow : tok::period,
7737 ObjectTypePtr,
7738 MayBePseudoDestructor);
7739 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007740 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007741
John McCallba7bf592010-08-24 05:47:05 +00007742 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00007743 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7744 if (QualifierLoc) {
7745 QualifierLoc
7746 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7747 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00007748 return ExprError();
7749 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00007750 CXXScopeSpec SS;
7751 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00007752
Douglas Gregor678f90d2010-02-25 01:56:36 +00007753 PseudoDestructorTypeStorage Destroyed;
7754 if (E->getDestroyedTypeInfo()) {
7755 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00007756 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00007757 ObjectType, 0, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00007758 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007759 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00007760 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00007761 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00007762 // We aren't likely to be able to resolve the identifier down to a type
7763 // now anyway, so just retain the identifier.
7764 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7765 E->getDestroyedTypeLoc());
7766 } else {
7767 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00007768 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007769 *E->getDestroyedTypeIdentifier(),
7770 E->getDestroyedTypeLoc(),
7771 /*Scope=*/0,
7772 SS, ObjectTypePtr,
7773 false);
7774 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007775 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007776
Douglas Gregor678f90d2010-02-25 01:56:36 +00007777 Destroyed
7778 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7779 E->getDestroyedTypeLoc());
7780 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007781
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007782 TypeSourceInfo *ScopeTypeInfo = 0;
7783 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00007784 CXXScopeSpec EmptySS;
7785 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
7786 E->getScopeTypeInfo(), ObjectType, 0, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007787 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007788 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00007789 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007790
John McCallb268a282010-08-23 23:25:46 +00007791 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00007792 E->getOperatorLoc(),
7793 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00007794 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007795 ScopeTypeInfo,
7796 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007797 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007798 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00007799}
Mike Stump11289f42009-09-09 15:08:12 +00007800
Douglas Gregorad8a3362009-09-04 17:36:40 +00007801template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007802ExprResult
John McCalld14a8642009-11-21 08:51:07 +00007803TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007804 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00007805 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7806 Sema::LookupOrdinaryName);
7807
7808 // Transform all the decls.
7809 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7810 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007811 NamedDecl *InstD = static_cast<NamedDecl*>(
7812 getDerived().TransformDecl(Old->getNameLoc(),
7813 *I));
John McCall84d87672009-12-10 09:41:52 +00007814 if (!InstD) {
7815 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7816 // This can happen because of dependent hiding.
7817 if (isa<UsingShadowDecl>(*I))
7818 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00007819 else {
7820 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007821 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00007822 }
John McCall84d87672009-12-10 09:41:52 +00007823 }
John McCalle66edc12009-11-24 19:00:30 +00007824
7825 // Expand using declarations.
7826 if (isa<UsingDecl>(InstD)) {
7827 UsingDecl *UD = cast<UsingDecl>(InstD);
7828 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7829 E = UD->shadow_end(); I != E; ++I)
7830 R.addDecl(*I);
7831 continue;
7832 }
7833
7834 R.addDecl(InstD);
7835 }
7836
7837 // Resolve a kind, but don't do any further analysis. If it's
7838 // ambiguous, the callee needs to deal with it.
7839 R.resolveKind();
7840
7841 // Rebuild the nested-name qualifier, if present.
7842 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00007843 if (Old->getQualifierLoc()) {
7844 NestedNameSpecifierLoc QualifierLoc
7845 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7846 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007847 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007848
Douglas Gregor0da1d432011-02-28 20:01:57 +00007849 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00007850 }
7851
Douglas Gregor9262f472010-04-27 18:19:34 +00007852 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00007853 CXXRecordDecl *NamingClass
7854 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7855 Old->getNameLoc(),
7856 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00007857 if (!NamingClass) {
7858 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007859 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00007860 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007861
Douglas Gregorda7be082010-04-27 16:10:10 +00007862 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00007863 }
7864
Abramo Bagnara7945c982012-01-27 09:46:47 +00007865 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7866
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00007867 // If we have neither explicit template arguments, nor the template keyword,
7868 // it's a normal declaration name.
7869 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCalle66edc12009-11-24 19:00:30 +00007870 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7871
7872 // If we have template arguments, rebuild them, then rebuild the
7873 // templateid expression.
7874 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00007875 if (Old->hasExplicitTemplateArgs() &&
7876 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00007877 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00007878 TransArgs)) {
7879 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00007880 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00007881 }
John McCalle66edc12009-11-24 19:00:30 +00007882
Abramo Bagnara7945c982012-01-27 09:46:47 +00007883 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00007884 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007885}
Mike Stump11289f42009-09-09 15:08:12 +00007886
Douglas Gregora16548e2009-08-11 05:31:07 +00007887template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007888ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00007889TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7890 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00007891 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00007892 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7893 TypeSourceInfo *From = E->getArg(I);
7894 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00007895 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00007896 TypeLocBuilder TLB;
7897 TLB.reserve(FromTL.getFullDataSize());
7898 QualType To = getDerived().TransformType(TLB, FromTL);
7899 if (To.isNull())
7900 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007901
Douglas Gregor29c42f22012-02-24 07:38:34 +00007902 if (To == From->getType())
7903 Args.push_back(From);
7904 else {
7905 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7906 ArgChanged = true;
7907 }
7908 continue;
7909 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007910
Douglas Gregor29c42f22012-02-24 07:38:34 +00007911 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00007912
Douglas Gregor29c42f22012-02-24 07:38:34 +00007913 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00007914 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00007915 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7916 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7917 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00007918
Douglas Gregor29c42f22012-02-24 07:38:34 +00007919 // Determine whether the set of unexpanded parameter packs can and should
7920 // be expanded.
7921 bool Expand = true;
7922 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00007923 Optional<unsigned> OrigNumExpansions =
7924 ExpansionTL.getTypePtr()->getNumExpansions();
7925 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00007926 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7927 PatternTL.getSourceRange(),
7928 Unexpanded,
7929 Expand, RetainExpansion,
7930 NumExpansions))
7931 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007932
Douglas Gregor29c42f22012-02-24 07:38:34 +00007933 if (!Expand) {
7934 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00007935 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00007936 // expansion.
7937 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00007938
Douglas Gregor29c42f22012-02-24 07:38:34 +00007939 TypeLocBuilder TLB;
7940 TLB.reserve(From->getTypeLoc().getFullDataSize());
7941
7942 QualType To = getDerived().TransformType(TLB, PatternTL);
7943 if (To.isNull())
7944 return ExprError();
7945
Chad Rosier1dcde962012-08-08 18:46:20 +00007946 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00007947 PatternTL.getSourceRange(),
7948 ExpansionTL.getEllipsisLoc(),
7949 NumExpansions);
7950 if (To.isNull())
7951 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007952
Douglas Gregor29c42f22012-02-24 07:38:34 +00007953 PackExpansionTypeLoc ToExpansionTL
7954 = TLB.push<PackExpansionTypeLoc>(To);
7955 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7956 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7957 continue;
7958 }
7959
7960 // Expand the pack expansion by substituting for each argument in the
7961 // pack(s).
7962 for (unsigned I = 0; I != *NumExpansions; ++I) {
7963 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7964 TypeLocBuilder TLB;
7965 TLB.reserve(PatternTL.getFullDataSize());
7966 QualType To = getDerived().TransformType(TLB, PatternTL);
7967 if (To.isNull())
7968 return ExprError();
7969
Eli Friedman5e05c4a2013-07-19 21:49:32 +00007970 if (To->containsUnexpandedParameterPack()) {
7971 To = getDerived().RebuildPackExpansionType(To,
7972 PatternTL.getSourceRange(),
7973 ExpansionTL.getEllipsisLoc(),
7974 NumExpansions);
7975 if (To.isNull())
7976 return ExprError();
7977
7978 PackExpansionTypeLoc ToExpansionTL
7979 = TLB.push<PackExpansionTypeLoc>(To);
7980 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7981 }
7982
Douglas Gregor29c42f22012-02-24 07:38:34 +00007983 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7984 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007985
Douglas Gregor29c42f22012-02-24 07:38:34 +00007986 if (!RetainExpansion)
7987 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00007988
Douglas Gregor29c42f22012-02-24 07:38:34 +00007989 // If we're supposed to retain a pack expansion, do so by temporarily
7990 // forgetting the partially-substituted parameter pack.
7991 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7992
7993 TypeLocBuilder TLB;
7994 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00007995
Douglas Gregor29c42f22012-02-24 07:38:34 +00007996 QualType To = getDerived().TransformType(TLB, PatternTL);
7997 if (To.isNull())
7998 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007999
8000 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008001 PatternTL.getSourceRange(),
8002 ExpansionTL.getEllipsisLoc(),
8003 NumExpansions);
8004 if (To.isNull())
8005 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008006
Douglas Gregor29c42f22012-02-24 07:38:34 +00008007 PackExpansionTypeLoc ToExpansionTL
8008 = TLB.push<PackExpansionTypeLoc>(To);
8009 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8010 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8011 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008012
Douglas Gregor29c42f22012-02-24 07:38:34 +00008013 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8014 return SemaRef.Owned(E);
8015
8016 return getDerived().RebuildTypeTrait(E->getTrait(),
8017 E->getLocStart(),
8018 Args,
8019 E->getLocEnd());
8020}
8021
8022template<typename Derived>
8023ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00008024TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8025 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
8026 if (!T)
8027 return ExprError();
8028
8029 if (!getDerived().AlwaysRebuild() &&
8030 T == E->getQueriedTypeSourceInfo())
8031 return SemaRef.Owned(E);
8032
8033 ExprResult SubExpr;
8034 {
8035 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8036 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8037 if (SubExpr.isInvalid())
8038 return ExprError();
8039
8040 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
8041 return SemaRef.Owned(E);
8042 }
8043
8044 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8045 E->getLocStart(),
8046 T,
8047 SubExpr.get(),
8048 E->getLocEnd());
8049}
8050
8051template<typename Derived>
8052ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00008053TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8054 ExprResult SubExpr;
8055 {
8056 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8057 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8058 if (SubExpr.isInvalid())
8059 return ExprError();
8060
8061 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
8062 return SemaRef.Owned(E);
8063 }
8064
8065 return getDerived().RebuildExpressionTrait(
8066 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8067}
8068
8069template<typename Derived>
8070ExprResult
John McCall8cd78132009-11-19 22:55:06 +00008071TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008072 DependentScopeDeclRefExpr *E) {
Richard Smithdb2630f2012-10-21 03:28:35 +00008073 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
8074}
8075
8076template<typename Derived>
8077ExprResult
8078TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8079 DependentScopeDeclRefExpr *E,
8080 bool IsAddressOfOperand) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00008081 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008082 NestedNameSpecifierLoc QualifierLoc
8083 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8084 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008085 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00008086 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008087
John McCall31f82722010-11-12 08:19:04 +00008088 // TODO: If this is a conversion-function-id, verify that the
8089 // destination type name (if present) resolves the same way after
8090 // instantiation as it did in the local scope.
8091
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008092 DeclarationNameInfo NameInfo
8093 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8094 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008095 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008096
John McCalle66edc12009-11-24 19:00:30 +00008097 if (!E->hasExplicitTemplateArgs()) {
8098 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008099 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008100 // Note: it is sufficient to compare the Name component of NameInfo:
8101 // if name has not changed, DNLoc has not changed either.
8102 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00008103 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00008104
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008105 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008106 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008107 NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00008108 /*TemplateArgs*/ 0,
8109 IsAddressOfOperand);
Douglas Gregord019ff62009-10-22 17:20:55 +00008110 }
John McCall6b51f282009-11-23 01:53:49 +00008111
8112 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008113 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8114 E->getNumTemplateArgs(),
8115 TransArgs))
8116 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +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 &TransArgs,
8122 IsAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00008123}
8124
8125template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008126ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008127TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00008128 // CXXConstructExprs other than for list-initialization and
8129 // CXXTemporaryObjectExpr are always implicit, so when we have
8130 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00008131 if ((E->getNumArgs() == 1 ||
8132 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00008133 (!getDerived().DropCallArgument(E->getArg(0))) &&
8134 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00008135 return getDerived().TransformExpr(E->getArg(0));
8136
Douglas Gregora16548e2009-08-11 05:31:07 +00008137 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8138
8139 QualType T = getDerived().TransformType(E->getType());
8140 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008141 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008142
8143 CXXConstructorDecl *Constructor
8144 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008145 getDerived().TransformDecl(E->getLocStart(),
8146 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008147 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008148 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008149
Douglas Gregora16548e2009-08-11 05:31:07 +00008150 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008151 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008152 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008153 &ArgumentChanged))
8154 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008155
Douglas Gregora16548e2009-08-11 05:31:07 +00008156 if (!getDerived().AlwaysRebuild() &&
8157 T == E->getType() &&
8158 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00008159 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00008160 // Mark the constructor as referenced.
8161 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008162 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00008163 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00008164 }
Mike Stump11289f42009-09-09 15:08:12 +00008165
Douglas Gregordb121ba2009-12-14 16:27:04 +00008166 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8167 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008168 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00008169 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00008170 E->isListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00008171 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00008172 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00008173 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008174}
Mike Stump11289f42009-09-09 15:08:12 +00008175
Douglas Gregora16548e2009-08-11 05:31:07 +00008176/// \brief Transform a C++ temporary-binding expression.
8177///
Douglas Gregor363b1512009-12-24 18:51:59 +00008178/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8179/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008180template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008181ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008182TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008183 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008184}
Mike Stump11289f42009-09-09 15:08:12 +00008185
John McCall5d413782010-12-06 08:20:24 +00008186/// \brief Transform a C++ expression that contains cleanups that should
8187/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00008188///
John McCall5d413782010-12-06 08:20:24 +00008189/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00008190/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008191template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008192ExprResult
John McCall5d413782010-12-06 08:20:24 +00008193TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008194 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008195}
Mike Stump11289f42009-09-09 15:08:12 +00008196
Douglas Gregora16548e2009-08-11 05:31:07 +00008197template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008198ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008199TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00008200 CXXTemporaryObjectExpr *E) {
8201 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8202 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008203 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008204
Douglas Gregora16548e2009-08-11 05:31:07 +00008205 CXXConstructorDecl *Constructor
8206 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00008207 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008208 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008209 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008210 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008211
Douglas Gregora16548e2009-08-11 05:31:07 +00008212 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008213 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00008214 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00008215 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008216 &ArgumentChanged))
8217 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008218
Douglas Gregora16548e2009-08-11 05:31:07 +00008219 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008220 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008221 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008222 !ArgumentChanged) {
8223 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008224 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00008225 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008226 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008227
Richard Smithd59b8322012-12-19 01:39:02 +00008228 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00008229 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8230 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008231 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008232 E->getLocEnd());
8233}
Mike Stump11289f42009-09-09 15:08:12 +00008234
Douglas Gregora16548e2009-08-11 05:31:07 +00008235template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008236ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00008237TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008238
8239 // Transform any init-capture expressions before entering the scope of the
8240 // lambda body, because they are not semantically within that scope.
8241 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
8242 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
8243 E->explicit_capture_begin());
8244
8245 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8246 CEnd = E->capture_end();
8247 C != CEnd; ++C) {
8248 if (!C->isInitCapture())
8249 continue;
8250 EnterExpressionEvaluationContext EEEC(getSema(),
8251 Sema::PotentiallyEvaluated);
8252 ExprResult NewExprInitResult = getDerived().TransformInitializer(
8253 C->getCapturedVar()->getInit(),
8254 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
8255
8256 if (NewExprInitResult.isInvalid())
8257 return ExprError();
8258 Expr *NewExprInit = NewExprInitResult.get();
8259
8260 VarDecl *OldVD = C->getCapturedVar();
8261 QualType NewInitCaptureType =
8262 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
8263 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
8264 NewExprInit);
8265 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008266 InitCaptureExprsAndTypes[C - E->capture_begin()] =
8267 std::make_pair(NewExprInitResult, NewInitCaptureType);
8268
8269 }
8270
Faisal Vali524ca282013-11-12 01:40:44 +00008271 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
Faisal Vali2cba1332013-10-23 06:44:28 +00008272 // Transform the template parameters, and add them to the current
8273 // instantiation scope. The null case is handled correctly.
8274 LSI->GLTemplateParameterList = getDerived().TransformTemplateParameterList(
8275 E->getTemplateParameterList());
8276
8277 // Check to see if the TypeSourceInfo of the call operator needs to
8278 // be transformed, and if so do the transformation in the
8279 // CurrentInstantiationScope.
8280
8281 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
8282 FunctionProtoTypeLoc OldCallOpFPTL =
8283 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
8284 TypeSourceInfo *NewCallOpTSI = 0;
8285
8286 const bool CallOpWasAlreadyTransformed =
8287 getDerived().AlreadyTransformed(OldCallOpTSI->getType());
8288
8289 // Use the Old Call Operator's TypeSourceInfo if it is already transformed.
8290 if (CallOpWasAlreadyTransformed)
8291 NewCallOpTSI = OldCallOpTSI;
8292 else {
8293 // Transform the TypeSourceInfo of the Original Lambda's Call Operator.
8294 // The transformation MUST be done in the CurrentInstantiationScope since
8295 // it introduces a mapping of the original to the newly created
8296 // transformed parameters.
8297
8298 TypeLocBuilder NewCallOpTLBuilder;
8299 QualType NewCallOpType = TransformFunctionProtoType(NewCallOpTLBuilder,
8300 OldCallOpFPTL,
8301 0, 0);
8302 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
8303 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00008304 }
Faisal Vali2cba1332013-10-23 06:44:28 +00008305 // Extract the ParmVarDecls from the NewCallOpTSI and add them to
8306 // the vector below - this will be used to synthesize the
8307 // NewCallOperator. Additionally, add the parameters of the untransformed
8308 // lambda call operator to the CurrentInstantiationScope.
8309 SmallVector<ParmVarDecl *, 4> Params;
8310 {
8311 FunctionProtoTypeLoc NewCallOpFPTL =
8312 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>();
8313 ParmVarDecl **NewParamDeclArray = NewCallOpFPTL.getParmArray();
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00008314 const unsigned NewNumArgs = NewCallOpFPTL.getNumParams();
Faisal Vali2cba1332013-10-23 06:44:28 +00008315
8316 for (unsigned I = 0; I < NewNumArgs; ++I) {
8317 // If this call operator's type does not require transformation,
8318 // the parameters do not get added to the current instantiation scope,
8319 // - so ADD them! This allows the following to compile when the enclosing
8320 // template is specialized and the entire lambda expression has to be
8321 // transformed.
8322 // template<class T> void foo(T t) {
8323 // auto L = [](auto a) {
8324 // auto M = [](char b) { <-- note: non-generic lambda
8325 // auto N = [](auto c) {
8326 // int x = sizeof(a);
8327 // x = sizeof(b); <-- specifically this line
8328 // x = sizeof(c);
8329 // };
8330 // };
8331 // };
8332 // }
8333 // foo('a')
8334 if (CallOpWasAlreadyTransformed)
8335 getDerived().transformedLocalDecl(NewParamDeclArray[I],
8336 NewParamDeclArray[I]);
8337 // Add to Params array, so these parameters can be used to create
8338 // the newly transformed call operator.
8339 Params.push_back(NewParamDeclArray[I]);
8340 }
8341 }
8342
8343 if (!NewCallOpTSI)
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008344 return ExprError();
8345
Eli Friedmand564afb2012-09-19 01:18:11 +00008346 // Create the local class that will describe the lambda.
8347 CXXRecordDecl *Class
8348 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008349 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00008350 /*KnownDependent=*/false,
8351 E->getCaptureDefault());
8352
Eli Friedmand564afb2012-09-19 01:18:11 +00008353 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8354
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008355 // Build the call operator.
Faisal Vali2cba1332013-10-23 06:44:28 +00008356 CXXMethodDecl *NewCallOperator
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008357 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008358 NewCallOpTSI,
Douglas Gregoradb376e2012-02-14 22:28:59 +00008359 E->getCallOperator()->getLocEnd(),
Richard Smith505df232012-07-22 23:45:10 +00008360 Params);
Faisal Vali2cba1332013-10-23 06:44:28 +00008361 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00008362
Faisal Vali2cba1332013-10-23 06:44:28 +00008363 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
8364
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008365 return getDerived().TransformLambdaScope(E, NewCallOperator,
8366 InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +00008367}
8368
8369template<typename Derived>
8370ExprResult
8371TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008372 CXXMethodDecl *CallOperator,
8373 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes) {
Richard Smithba71c082013-05-16 06:20:58 +00008374 bool Invalid = false;
8375
Douglas Gregorb4328232012-02-14 00:00:48 +00008376 // Introduce the context of the call operator.
Richard Smith7ff2bcb2014-01-24 01:54:52 +00008377 Sema::ContextRAII SavedContext(getSema(), CallOperator,
8378 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00008379
Faisal Vali2b391ab2013-09-26 19:54:12 +00008380 LambdaScopeInfo *const LSI = getSema().getCurLambda();
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008381 // Enter the scope of the lambda.
Faisal Vali2b391ab2013-09-26 19:54:12 +00008382 getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008383 E->getCaptureDefault(),
James Dennettddd36ff2013-08-09 23:08:25 +00008384 E->getCaptureDefaultLoc(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008385 E->hasExplicitParameters(),
8386 E->hasExplicitResultType(),
8387 E->isMutable());
Chad Rosier1dcde962012-08-08 18:46:20 +00008388
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008389 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008390 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00008391 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008392 CEnd = E->capture_end();
8393 C != CEnd; ++C) {
8394 // When we hit the first implicit capture, tell Sema that we've finished
8395 // the list of explicit captures.
8396 if (!FinishedExplicitCaptures && C->isImplicit()) {
8397 getSema().finishLambdaExplicitCaptures(LSI);
8398 FinishedExplicitCaptures = true;
8399 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008400
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008401 // Capturing 'this' is trivial.
8402 if (C->capturesThis()) {
8403 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8404 continue;
8405 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008406
Richard Smithba71c082013-05-16 06:20:58 +00008407 // Rebuild init-captures, including the implied field declaration.
8408 if (C->isInitCapture()) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008409
8410 InitCaptureInfoTy InitExprTypePair =
8411 InitCaptureExprsAndTypes[C - E->capture_begin()];
8412 ExprResult Init = InitExprTypePair.first;
8413 QualType InitQualType = InitExprTypePair.second;
8414 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00008415 Invalid = true;
8416 continue;
8417 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00008418 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008419 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
8420 OldVD->getLocation(), InitExprTypePair.second,
8421 OldVD->getIdentifier(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00008422 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00008423 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008424 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00008425 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008426 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00008427 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00008428 continue;
8429 }
8430
8431 assert(C->capturesVariable() && "unexpected kind of lambda capture");
8432
Douglas Gregor3e308b12012-02-14 19:27:52 +00008433 // Determine the capture kind for Sema.
8434 Sema::TryCaptureKind Kind
8435 = C->isImplicit()? Sema::TryCapture_Implicit
8436 : C->getCaptureKind() == LCK_ByCopy
8437 ? Sema::TryCapture_ExplicitByVal
8438 : Sema::TryCapture_ExplicitByRef;
8439 SourceLocation EllipsisLoc;
8440 if (C->isPackExpansion()) {
8441 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8442 bool ShouldExpand = false;
8443 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008444 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00008445 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8446 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008447 Unexpanded,
8448 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00008449 NumExpansions)) {
8450 Invalid = true;
8451 continue;
8452 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008453
Douglas Gregor3e308b12012-02-14 19:27:52 +00008454 if (ShouldExpand) {
8455 // The transform has determined that we should perform an expansion;
8456 // transform and capture each of the arguments.
8457 // expansion of the pattern. Do so.
8458 VarDecl *Pack = C->getCapturedVar();
8459 for (unsigned I = 0; I != *NumExpansions; ++I) {
8460 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8461 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008462 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008463 Pack));
8464 if (!CapturedVar) {
8465 Invalid = true;
8466 continue;
8467 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008468
Douglas Gregor3e308b12012-02-14 19:27:52 +00008469 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00008470 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8471 }
Douglas Gregor3e308b12012-02-14 19:27:52 +00008472 continue;
8473 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008474
Douglas Gregor3e308b12012-02-14 19:27:52 +00008475 EllipsisLoc = C->getEllipsisLoc();
8476 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008477
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008478 // Transform the captured variable.
8479 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008480 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008481 C->getCapturedVar()));
8482 if (!CapturedVar) {
8483 Invalid = true;
8484 continue;
8485 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008486
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008487 // Capture the transformed variable.
Douglas Gregorfdf598e2012-02-18 09:37:24 +00008488 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008489 }
8490 if (!FinishedExplicitCaptures)
8491 getSema().finishLambdaExplicitCaptures(LSI);
8492
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008493
8494 // Enter a new evaluation context to insulate the lambda from any
8495 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00008496 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008497
8498 if (Invalid) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008499 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008500 /*IsInstantiation=*/true);
8501 return ExprError();
8502 }
8503
8504 // Instantiate the body of the lambda expression.
Douglas Gregorb4328232012-02-14 00:00:48 +00008505 StmtResult Body = getDerived().TransformStmt(E->getBody());
8506 if (Body.isInvalid()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008507 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregorb4328232012-02-14 00:00:48 +00008508 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00008509 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00008510 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00008511
Chad Rosier1dcde962012-08-08 18:46:20 +00008512 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorb61e8092012-04-04 17:40:10 +00008513 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregore31e6062012-02-07 10:09:13 +00008514}
8515
8516template<typename Derived>
8517ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008518TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008519 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00008520 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8521 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008522 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008523
Douglas Gregora16548e2009-08-11 05:31:07 +00008524 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008525 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00008526 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00008527 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008528 &ArgumentChanged))
8529 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008530
Douglas Gregora16548e2009-08-11 05:31:07 +00008531 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008532 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008533 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00008534 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00008535
Douglas Gregora16548e2009-08-11 05:31:07 +00008536 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00008537 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00008538 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008539 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008540 E->getRParenLoc());
8541}
Mike Stump11289f42009-09-09 15:08:12 +00008542
Douglas Gregora16548e2009-08-11 05:31:07 +00008543template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008544ExprResult
John McCall8cd78132009-11-19 22:55:06 +00008545TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008546 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008547 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00008548 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00008549 Expr *OldBase;
8550 QualType BaseType;
8551 QualType ObjectType;
8552 if (!E->isImplicitAccess()) {
8553 OldBase = E->getBase();
8554 Base = getDerived().TransformExpr(OldBase);
8555 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008556 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008557
John McCall2d74de92009-12-01 22:10:20 +00008558 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00008559 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00008560 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00008561 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008562 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008563 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00008564 ObjectTy,
8565 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00008566 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008567 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00008568
John McCallba7bf592010-08-24 05:47:05 +00008569 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00008570 BaseType = ((Expr*) Base.get())->getType();
8571 } else {
8572 OldBase = 0;
8573 BaseType = getDerived().TransformType(E->getBaseType());
8574 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8575 }
Mike Stump11289f42009-09-09 15:08:12 +00008576
Douglas Gregora5cb6da2009-10-20 05:58:46 +00008577 // Transform the first part of the nested-name-specifier that qualifies
8578 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00008579 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00008580 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00008581 E->getFirstQualifierFoundInScope(),
8582 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00008583
Douglas Gregore16af532011-02-28 18:50:33 +00008584 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008585 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00008586 QualifierLoc
8587 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8588 ObjectType,
8589 FirstQualifierInScope);
8590 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008591 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008592 }
Mike Stump11289f42009-09-09 15:08:12 +00008593
Abramo Bagnara7945c982012-01-27 09:46:47 +00008594 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8595
John McCall31f82722010-11-12 08:19:04 +00008596 // TODO: If this is a conversion-function-id, verify that the
8597 // destination type name (if present) resolves the same way after
8598 // instantiation as it did in the local scope.
8599
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008600 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00008601 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008602 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008603 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008604
John McCall2d74de92009-12-01 22:10:20 +00008605 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00008606 // This is a reference to a member without an explicitly-specified
8607 // template argument list. Optimize for this common case.
8608 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00008609 Base.get() == OldBase &&
8610 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00008611 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008612 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00008613 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00008614 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00008615
John McCallb268a282010-08-23 23:25:46 +00008616 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008617 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00008618 E->isArrow(),
8619 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00008620 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008621 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00008622 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008623 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00008624 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00008625 }
8626
John McCall6b51f282009-11-23 01:53:49 +00008627 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008628 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8629 E->getNumTemplateArgs(),
8630 TransArgs))
8631 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008632
John McCallb268a282010-08-23 23:25:46 +00008633 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008634 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00008635 E->isArrow(),
8636 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00008637 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008638 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00008639 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008640 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00008641 &TransArgs);
8642}
8643
8644template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008645ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008646TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00008647 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00008648 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00008649 QualType BaseType;
8650 if (!Old->isImplicitAccess()) {
8651 Base = getDerived().TransformExpr(Old->getBase());
8652 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008653 return ExprError();
Richard Smithcab9a7d2011-10-26 19:06:56 +00008654 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8655 Old->isArrow());
8656 if (Base.isInvalid())
8657 return ExprError();
8658 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +00008659 } else {
8660 BaseType = getDerived().TransformType(Old->getBaseType());
8661 }
John McCall10eae182009-11-30 22:42:35 +00008662
Douglas Gregor0da1d432011-02-28 20:01:57 +00008663 NestedNameSpecifierLoc QualifierLoc;
8664 if (Old->getQualifierLoc()) {
8665 QualifierLoc
8666 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8667 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008668 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00008669 }
8670
Abramo Bagnara7945c982012-01-27 09:46:47 +00008671 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8672
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008673 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00008674 Sema::LookupOrdinaryName);
8675
8676 // Transform all the decls.
8677 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8678 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008679 NamedDecl *InstD = static_cast<NamedDecl*>(
8680 getDerived().TransformDecl(Old->getMemberLoc(),
8681 *I));
John McCall84d87672009-12-10 09:41:52 +00008682 if (!InstD) {
8683 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8684 // This can happen because of dependent hiding.
8685 if (isa<UsingShadowDecl>(*I))
8686 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00008687 else {
8688 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008689 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00008690 }
John McCall84d87672009-12-10 09:41:52 +00008691 }
John McCall10eae182009-11-30 22:42:35 +00008692
8693 // Expand using declarations.
8694 if (isa<UsingDecl>(InstD)) {
8695 UsingDecl *UD = cast<UsingDecl>(InstD);
8696 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8697 E = UD->shadow_end(); I != E; ++I)
8698 R.addDecl(*I);
8699 continue;
8700 }
8701
8702 R.addDecl(InstD);
8703 }
8704
8705 R.resolveKind();
8706
Douglas Gregor9262f472010-04-27 18:19:34 +00008707 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00008708 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008709 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00008710 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00008711 Old->getMemberLoc(),
8712 Old->getNamingClass()));
8713 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00008714 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008715
Douglas Gregorda7be082010-04-27 16:10:10 +00008716 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00008717 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008718
John McCall10eae182009-11-30 22:42:35 +00008719 TemplateArgumentListInfo TransArgs;
8720 if (Old->hasExplicitTemplateArgs()) {
8721 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8722 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008723 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8724 Old->getNumTemplateArgs(),
8725 TransArgs))
8726 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00008727 }
John McCall38836f02010-01-15 08:34:02 +00008728
8729 // FIXME: to do this check properly, we will need to preserve the
8730 // first-qualifier-in-scope here, just in case we had a dependent
8731 // base (and therefore couldn't do the check) and a
8732 // nested-name-qualifier (and therefore could do the lookup).
8733 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00008734
John McCallb268a282010-08-23 23:25:46 +00008735 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008736 BaseType,
John McCall10eae182009-11-30 22:42:35 +00008737 Old->getOperatorLoc(),
8738 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00008739 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008740 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +00008741 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00008742 R,
8743 (Old->hasExplicitTemplateArgs()
8744 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00008745}
8746
8747template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008748ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008749TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00008750 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008751 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8752 if (SubExpr.isInvalid())
8753 return ExprError();
8754
8755 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00008756 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008757
8758 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8759}
8760
8761template<typename Derived>
8762ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008763TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00008764 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8765 if (Pattern.isInvalid())
8766 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008767
Douglas Gregor0f836ea2011-01-13 00:19:55 +00008768 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8769 return SemaRef.Owned(E);
8770
Douglas Gregorb8840002011-01-14 21:20:45 +00008771 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8772 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008773}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008774
8775template<typename Derived>
8776ExprResult
8777TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8778 // If E is not value-dependent, then nothing will change when we transform it.
8779 // Note: This is an instantiation-centric view.
8780 if (!E->isValueDependent())
8781 return SemaRef.Owned(E);
8782
8783 // Note: None of the implementations of TryExpandParameterPacks can ever
8784 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00008785 // so
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008786 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8787 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00008788 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008789 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00008790 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +00008791 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00008792 ShouldExpand, RetainExpansion,
8793 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008794 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008795
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008796 if (RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008797 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00008798
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008799 NamedDecl *Pack = E->getPack();
8800 if (!ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008801 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008802 Pack));
8803 if (!Pack)
8804 return ExprError();
8805 }
8806
Chad Rosier1dcde962012-08-08 18:46:20 +00008807
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008808 // We now know the length of the parameter pack, so build a new expression
8809 // that stores that length.
Chad Rosier1dcde962012-08-08 18:46:20 +00008810 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8811 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008812 NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008813}
8814
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008815template<typename Derived>
8816ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00008817TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8818 SubstNonTypeTemplateParmPackExpr *E) {
8819 // Default behavior is to do nothing with this transformation.
8820 return SemaRef.Owned(E);
8821}
8822
8823template<typename Derived>
8824ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00008825TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8826 SubstNonTypeTemplateParmExpr *E) {
8827 // Default behavior is to do nothing with this transformation.
8828 return SemaRef.Owned(E);
8829}
8830
8831template<typename Derived>
8832ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +00008833TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8834 // Default behavior is to do nothing with this transformation.
8835 return SemaRef.Owned(E);
8836}
8837
8838template<typename Derived>
8839ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00008840TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8841 MaterializeTemporaryExpr *E) {
8842 return getDerived().TransformExpr(E->GetTemporaryExpr());
8843}
Chad Rosier1dcde962012-08-08 18:46:20 +00008844
Douglas Gregorfe314812011-06-21 17:03:29 +00008845template<typename Derived>
8846ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +00008847TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
8848 CXXStdInitializerListExpr *E) {
8849 return getDerived().TransformExpr(E->getSubExpr());
8850}
8851
8852template<typename Derived>
8853ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008854TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00008855 return SemaRef.MaybeBindToTemporary(E);
8856}
8857
8858template<typename Derived>
8859ExprResult
8860TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rose8986c5992012-03-12 17:53:02 +00008861 return SemaRef.Owned(E);
Ted Kremeneke65b0862012-03-06 20:05:56 +00008862}
8863
8864template<typename Derived>
8865ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +00008866TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8867 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8868 if (SubExpr.isInvalid())
8869 return ExprError();
8870
8871 if (!getDerived().AlwaysRebuild() &&
8872 SubExpr.get() == E->getSubExpr())
8873 return SemaRef.Owned(E);
8874
8875 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +00008876}
8877
8878template<typename Derived>
8879ExprResult
8880TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8881 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008882 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00008883 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00008884 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00008885 /*IsCall=*/false, Elements, &ArgChanged))
8886 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008887
Ted Kremeneke65b0862012-03-06 20:05:56 +00008888 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8889 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00008890
Ted Kremeneke65b0862012-03-06 20:05:56 +00008891 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8892 Elements.data(),
8893 Elements.size());
8894}
8895
8896template<typename Derived>
8897ExprResult
8898TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +00008899 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00008900 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008901 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00008902 bool ArgChanged = false;
8903 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8904 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +00008905
Ted Kremeneke65b0862012-03-06 20:05:56 +00008906 if (OrigElement.isPackExpansion()) {
8907 // This key/value element is a pack expansion.
8908 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8909 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8910 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8911 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8912
8913 // Determine whether the set of unexpanded parameter packs can
8914 // and should be expanded.
8915 bool Expand = true;
8916 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008917 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8918 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +00008919 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8920 OrigElement.Value->getLocEnd());
8921 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8922 PatternRange,
8923 Unexpanded,
8924 Expand, RetainExpansion,
8925 NumExpansions))
8926 return ExprError();
8927
8928 if (!Expand) {
8929 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00008930 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +00008931 // expansion.
8932 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8933 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8934 if (Key.isInvalid())
8935 return ExprError();
8936
8937 if (Key.get() != OrigElement.Key)
8938 ArgChanged = true;
8939
8940 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8941 if (Value.isInvalid())
8942 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008943
Ted Kremeneke65b0862012-03-06 20:05:56 +00008944 if (Value.get() != OrigElement.Value)
8945 ArgChanged = true;
8946
Chad Rosier1dcde962012-08-08 18:46:20 +00008947 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00008948 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8949 };
8950 Elements.push_back(Expansion);
8951 continue;
8952 }
8953
8954 // Record right away that the argument was changed. This needs
8955 // to happen even if the array expands to nothing.
8956 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00008957
Ted Kremeneke65b0862012-03-06 20:05:56 +00008958 // The transform has determined that we should perform an elementwise
8959 // expansion of the pattern. Do so.
8960 for (unsigned I = 0; I != *NumExpansions; ++I) {
8961 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8962 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8963 if (Key.isInvalid())
8964 return ExprError();
8965
8966 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8967 if (Value.isInvalid())
8968 return ExprError();
8969
Chad Rosier1dcde962012-08-08 18:46:20 +00008970 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00008971 Key.get(), Value.get(), SourceLocation(), NumExpansions
8972 };
8973
8974 // If any unexpanded parameter packs remain, we still have a
8975 // pack expansion.
8976 if (Key.get()->containsUnexpandedParameterPack() ||
8977 Value.get()->containsUnexpandedParameterPack())
8978 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +00008979
Ted Kremeneke65b0862012-03-06 20:05:56 +00008980 Elements.push_back(Element);
8981 }
8982
8983 // We've finished with this pack expansion.
8984 continue;
8985 }
8986
8987 // Transform and check key.
8988 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8989 if (Key.isInvalid())
8990 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008991
Ted Kremeneke65b0862012-03-06 20:05:56 +00008992 if (Key.get() != OrigElement.Key)
8993 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00008994
Ted Kremeneke65b0862012-03-06 20:05:56 +00008995 // Transform and check value.
8996 ExprResult Value
8997 = getDerived().TransformExpr(OrigElement.Value);
8998 if (Value.isInvalid())
8999 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009000
Ted Kremeneke65b0862012-03-06 20:05:56 +00009001 if (Value.get() != OrigElement.Value)
9002 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009003
9004 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +00009005 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +00009006 };
9007 Elements.push_back(Element);
9008 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009009
Ted Kremeneke65b0862012-03-06 20:05:56 +00009010 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9011 return SemaRef.MaybeBindToTemporary(E);
9012
9013 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
9014 Elements.data(),
9015 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +00009016}
9017
Mike Stump11289f42009-09-09 15:08:12 +00009018template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009019ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009020TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00009021 TypeSourceInfo *EncodedTypeInfo
9022 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
9023 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009024 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009025
Douglas Gregora16548e2009-08-11 05:31:07 +00009026 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00009027 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00009028 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009029
9030 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00009031 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009032 E->getRParenLoc());
9033}
Mike Stump11289f42009-09-09 15:08:12 +00009034
Douglas Gregora16548e2009-08-11 05:31:07 +00009035template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +00009036ExprResult TreeTransform<Derived>::
9037TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +00009038 // This is a kind of implicit conversion, and it needs to get dropped
9039 // and recomputed for the same general reasons that ImplicitCastExprs
9040 // do, as well a more specific one: this expression is only valid when
9041 // it appears *immediately* as an argument expression.
9042 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +00009043}
9044
9045template<typename Derived>
9046ExprResult TreeTransform<Derived>::
9047TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009048 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +00009049 = getDerived().TransformType(E->getTypeInfoAsWritten());
9050 if (!TSInfo)
9051 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009052
John McCall31168b02011-06-15 23:02:42 +00009053 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +00009054 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +00009055 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009056
John McCall31168b02011-06-15 23:02:42 +00009057 if (!getDerived().AlwaysRebuild() &&
9058 TSInfo == E->getTypeInfoAsWritten() &&
9059 Result.get() == E->getSubExpr())
9060 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009061
John McCall31168b02011-06-15 23:02:42 +00009062 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +00009063 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +00009064 Result.get());
9065}
9066
9067template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009068ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009069TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009070 // Transform arguments.
9071 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009072 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009073 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009074 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009075 &ArgChanged))
9076 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009077
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009078 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
9079 // Class message: transform the receiver type.
9080 TypeSourceInfo *ReceiverTypeInfo
9081 = getDerived().TransformType(E->getClassReceiverTypeInfo());
9082 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009083 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009084
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009085 // If nothing changed, just retain the existing message send.
9086 if (!getDerived().AlwaysRebuild() &&
9087 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009088 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009089
9090 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009091 SmallVector<SourceLocation, 16> SelLocs;
9092 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009093 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
9094 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009095 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009096 E->getMethodDecl(),
9097 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009098 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009099 E->getRightLoc());
9100 }
9101
9102 // Instance message: transform the receiver
9103 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
9104 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00009105 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009106 = getDerived().TransformExpr(E->getInstanceReceiver());
9107 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009108 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009109
9110 // If nothing changed, just retain the existing message send.
9111 if (!getDerived().AlwaysRebuild() &&
9112 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009113 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009114
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009115 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009116 SmallVector<SourceLocation, 16> SelLocs;
9117 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +00009118 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009119 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009120 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009121 E->getMethodDecl(),
9122 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009123 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009124 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009125}
9126
Mike Stump11289f42009-09-09 15:08:12 +00009127template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009128ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009129TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00009130 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009131}
9132
Mike Stump11289f42009-09-09 15:08:12 +00009133template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009134ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009135TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00009136 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009137}
9138
Mike Stump11289f42009-09-09 15:08:12 +00009139template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009140ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009141TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009142 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009143 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009144 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009145 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00009146
9147 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009148
Douglas Gregord51d90d2010-04-26 20:11:03 +00009149 // If nothing changed, just retain the existing expression.
9150 if (!getDerived().AlwaysRebuild() &&
9151 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00009152 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009153
John McCallb268a282010-08-23 23:25:46 +00009154 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009155 E->getLocation(),
9156 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00009157}
9158
Mike Stump11289f42009-09-09 15:08:12 +00009159template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009160ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009161TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00009162 // 'super' and types never change. Property never changes. Just
9163 // retain the existing expression.
9164 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00009165 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009166
Douglas Gregor9faee212010-04-26 20:47:02 +00009167 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009168 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00009169 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009170 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009171
Douglas Gregor9faee212010-04-26 20:47:02 +00009172 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009173
Douglas Gregor9faee212010-04-26 20:47:02 +00009174 // If nothing changed, just retain the existing expression.
9175 if (!getDerived().AlwaysRebuild() &&
9176 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00009177 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009178
John McCallb7bd14f2010-12-02 01:19:52 +00009179 if (E->isExplicitProperty())
9180 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9181 E->getExplicitProperty(),
9182 E->getLocation());
9183
9184 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +00009185 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +00009186 E->getImplicitPropertyGetter(),
9187 E->getImplicitPropertySetter(),
9188 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00009189}
9190
Mike Stump11289f42009-09-09 15:08:12 +00009191template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009192ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +00009193TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
9194 // Transform the base expression.
9195 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9196 if (Base.isInvalid())
9197 return ExprError();
9198
9199 // Transform the key expression.
9200 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
9201 if (Key.isInvalid())
9202 return ExprError();
9203
9204 // If nothing changed, just retain the existing expression.
9205 if (!getDerived().AlwaysRebuild() &&
9206 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
9207 return SemaRef.Owned(E);
9208
Chad Rosier1dcde962012-08-08 18:46:20 +00009209 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009210 Base.get(), Key.get(),
9211 E->getAtIndexMethodDecl(),
9212 E->setAtIndexMethodDecl());
9213}
9214
9215template<typename Derived>
9216ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009217TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009218 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009219 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009220 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009221 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009222
Douglas Gregord51d90d2010-04-26 20:11:03 +00009223 // If nothing changed, just retain the existing expression.
9224 if (!getDerived().AlwaysRebuild() &&
9225 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00009226 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009227
John McCallb268a282010-08-23 23:25:46 +00009228 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00009229 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009230 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00009231}
9232
Mike Stump11289f42009-09-09 15:08:12 +00009233template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009234ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009235TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009236 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009237 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +00009238 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009239 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00009240 SubExprs, &ArgumentChanged))
9241 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009242
Douglas Gregora16548e2009-08-11 05:31:07 +00009243 if (!getDerived().AlwaysRebuild() &&
9244 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00009245 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00009246
Douglas Gregora16548e2009-08-11 05:31:07 +00009247 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009248 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009249 E->getRParenLoc());
9250}
9251
Mike Stump11289f42009-09-09 15:08:12 +00009252template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009253ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +00009254TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
9255 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
9256 if (SrcExpr.isInvalid())
9257 return ExprError();
9258
9259 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9260 if (!Type)
9261 return ExprError();
9262
9263 if (!getDerived().AlwaysRebuild() &&
9264 Type == E->getTypeSourceInfo() &&
9265 SrcExpr.get() == E->getSrcExpr())
9266 return SemaRef.Owned(E);
9267
9268 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
9269 SrcExpr.get(), Type,
9270 E->getRParenLoc());
9271}
9272
9273template<typename Derived>
9274ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009275TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00009276 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +00009277
John McCall490112f2011-02-04 18:33:18 +00009278 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
9279 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
9280
9281 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +00009282 blockScope->TheDecl->setBlockMissingReturnType(
9283 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +00009284
Chris Lattner01cf8db2011-07-20 06:58:45 +00009285 SmallVector<ParmVarDecl*, 4> params;
9286 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +00009287
Fariborz Jahanian1babe772010-07-09 18:44:02 +00009288 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00009289 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
9290 oldBlock->param_begin(),
9291 oldBlock->param_size(),
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009292 0, paramTypes, &params)) {
9293 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009294 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009295 }
John McCall490112f2011-02-04 18:33:18 +00009296
Jordan Rosea0a86be2013-03-08 22:25:36 +00009297 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +00009298 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +00009299 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +00009300
Jordan Rose5c382722013-03-08 21:51:21 +00009301 QualType functionType =
9302 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009303 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +00009304 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00009305
9306 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00009307 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +00009308 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +00009309
9310 if (!oldBlock->blockMissingReturnType()) {
9311 blockScope->HasImplicitReturnType = false;
9312 blockScope->ReturnType = exprResultType;
9313 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009314
John McCall3882ace2011-01-05 12:14:39 +00009315 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00009316 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009317 if (body.isInvalid()) {
9318 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall3882ace2011-01-05 12:14:39 +00009319 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009320 }
John McCall3882ace2011-01-05 12:14:39 +00009321
John McCall490112f2011-02-04 18:33:18 +00009322#ifndef NDEBUG
9323 // In builds with assertions, make sure that we captured everything we
9324 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009325 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
9326 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
9327 e = oldBlock->capture_end(); i != e; ++i) {
9328 VarDecl *oldCapture = i->getVariable();
John McCall490112f2011-02-04 18:33:18 +00009329
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009330 // Ignore parameter packs.
9331 if (isa<ParmVarDecl>(oldCapture) &&
9332 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9333 continue;
John McCall490112f2011-02-04 18:33:18 +00009334
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009335 VarDecl *newCapture =
9336 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9337 oldCapture));
9338 assert(blockScope->CaptureMap.count(newCapture));
9339 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009340 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +00009341 }
9342#endif
9343
9344 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
9345 /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00009346}
9347
Mike Stump11289f42009-09-09 15:08:12 +00009348template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009349ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +00009350TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +00009351 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +00009352}
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009353
9354template<typename Derived>
9355ExprResult
9356TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009357 QualType RetTy = getDerived().TransformType(E->getType());
9358 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009359 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009360 SubExprs.reserve(E->getNumSubExprs());
9361 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9362 SubExprs, &ArgumentChanged))
9363 return ExprError();
9364
9365 if (!getDerived().AlwaysRebuild() &&
9366 !ArgumentChanged)
9367 return SemaRef.Owned(E);
9368
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009369 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009370 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009371}
Chad Rosier1dcde962012-08-08 18:46:20 +00009372
Douglas Gregora16548e2009-08-11 05:31:07 +00009373//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00009374// Type reconstruction
9375//===----------------------------------------------------------------------===//
9376
Mike Stump11289f42009-09-09 15:08:12 +00009377template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009378QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9379 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009380 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009381 getDerived().getBaseEntity());
9382}
9383
Mike Stump11289f42009-09-09 15:08:12 +00009384template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009385QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9386 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009387 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009388 getDerived().getBaseEntity());
9389}
9390
Mike Stump11289f42009-09-09 15:08:12 +00009391template<typename Derived>
9392QualType
John McCall70dd5f62009-10-30 00:06:24 +00009393TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9394 bool WrittenAsLValue,
9395 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00009396 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00009397 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009398}
9399
9400template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009401QualType
John McCall70dd5f62009-10-30 00:06:24 +00009402TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9403 QualType ClassType,
9404 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +00009405 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
9406 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009407}
9408
9409template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009410QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00009411TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9412 ArrayType::ArraySizeModifier SizeMod,
9413 const llvm::APInt *Size,
9414 Expr *SizeExpr,
9415 unsigned IndexTypeQuals,
9416 SourceRange BracketsRange) {
9417 if (SizeExpr || !Size)
9418 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9419 IndexTypeQuals, BracketsRange,
9420 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00009421
9422 QualType Types[] = {
9423 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9424 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9425 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00009426 };
Craig Toppere5ce8312013-07-15 03:38:40 +00009427 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009428 QualType SizeType;
9429 for (unsigned I = 0; I != NumTypes; ++I)
9430 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9431 SizeType = Types[I];
9432 break;
9433 }
Mike Stump11289f42009-09-09 15:08:12 +00009434
Eli Friedman9562f392012-01-25 23:20:27 +00009435 // Note that we can return a VariableArrayType here in the case where
9436 // the element type was a dependent VariableArrayType.
9437 IntegerLiteral *ArraySize
9438 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9439 /*FIXME*/BracketsRange.getBegin());
9440 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009441 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00009442 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009443}
Mike Stump11289f42009-09-09 15:08:12 +00009444
Douglas Gregord6ff3322009-08-04 16:50:30 +00009445template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009446QualType
9447TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009448 ArrayType::ArraySizeModifier SizeMod,
9449 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00009450 unsigned IndexTypeQuals,
9451 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009452 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00009453 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009454}
9455
9456template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009457QualType
Mike Stump11289f42009-09-09 15:08:12 +00009458TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009459 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00009460 unsigned IndexTypeQuals,
9461 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009462 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00009463 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009464}
Mike Stump11289f42009-09-09 15:08:12 +00009465
Douglas Gregord6ff3322009-08-04 16:50:30 +00009466template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009467QualType
9468TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009469 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009470 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009471 unsigned IndexTypeQuals,
9472 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009473 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00009474 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009475 IndexTypeQuals, BracketsRange);
9476}
9477
9478template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009479QualType
9480TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009481 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009482 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009483 unsigned IndexTypeQuals,
9484 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009485 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00009486 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009487 IndexTypeQuals, BracketsRange);
9488}
9489
9490template<typename Derived>
9491QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00009492 unsigned NumElements,
9493 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00009494 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00009495 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009496}
Mike Stump11289f42009-09-09 15:08:12 +00009497
Douglas Gregord6ff3322009-08-04 16:50:30 +00009498template<typename Derived>
9499QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9500 unsigned NumElements,
9501 SourceLocation AttributeLoc) {
9502 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9503 NumElements, true);
9504 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00009505 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9506 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00009507 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009508}
Mike Stump11289f42009-09-09 15:08:12 +00009509
Douglas Gregord6ff3322009-08-04 16:50:30 +00009510template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009511QualType
9512TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00009513 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009514 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00009515 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
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>
Jordan Rose5c382722013-03-08 21:51:21 +00009519QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9520 QualType T,
9521 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009522 const FunctionProtoType::ExtProtoInfo &EPI) {
9523 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009524 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00009525 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +00009526 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009527}
Mike Stump11289f42009-09-09 15:08:12 +00009528
Douglas Gregord6ff3322009-08-04 16:50:30 +00009529template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00009530QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9531 return SemaRef.Context.getFunctionNoProtoType(T);
9532}
9533
9534template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00009535QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9536 assert(D && "no decl found");
9537 if (D->isInvalidDecl()) return QualType();
9538
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009539 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00009540 TypeDecl *Ty;
9541 if (isa<UsingDecl>(D)) {
9542 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +00009543 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +00009544 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9545
9546 // A valid resolved using typename decl points to exactly one type decl.
9547 assert(++Using->shadow_begin() == Using->shadow_end());
9548 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00009549
John McCallb96ec562009-12-04 22:46:56 +00009550 } else {
9551 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9552 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9553 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9554 }
9555
9556 return SemaRef.Context.getTypeDeclType(Ty);
9557}
9558
9559template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00009560QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9561 SourceLocation Loc) {
9562 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009563}
9564
9565template<typename Derived>
9566QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9567 return SemaRef.Context.getTypeOfType(Underlying);
9568}
9569
9570template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00009571QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9572 SourceLocation Loc) {
9573 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009574}
9575
9576template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00009577QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9578 UnaryTransformType::UTTKind UKind,
9579 SourceLocation Loc) {
9580 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9581}
9582
9583template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00009584QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00009585 TemplateName Template,
9586 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +00009587 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +00009588 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009589}
Mike Stump11289f42009-09-09 15:08:12 +00009590
Douglas Gregor1135c352009-08-06 05:28:30 +00009591template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +00009592QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9593 SourceLocation KWLoc) {
9594 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9595}
9596
9597template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009598TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009599TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00009600 bool TemplateKW,
9601 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +00009602 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00009603 Template);
9604}
9605
9606template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009607TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009608TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9609 const IdentifierInfo &Name,
9610 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00009611 QualType ObjectType,
9612 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +00009613 UnqualifiedId TemplateName;
9614 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +00009615 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +00009616 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +00009617 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009618 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +00009619 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00009620 /*EnteringContext=*/false,
9621 Template);
John McCall31f82722010-11-12 08:19:04 +00009622 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00009623}
Mike Stump11289f42009-09-09 15:08:12 +00009624
Douglas Gregora16548e2009-08-11 05:31:07 +00009625template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00009626TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009627TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00009628 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00009629 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00009630 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +00009631 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +00009632 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +00009633 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +00009634 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +00009635 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +00009636 Sema::TemplateTy Template;
9637 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009638 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +00009639 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00009640 /*EnteringContext=*/false,
9641 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +00009642 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +00009643}
Chad Rosier1dcde962012-08-08 18:46:20 +00009644
Douglas Gregor71395fa2009-11-04 00:56:37 +00009645template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009646ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009647TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9648 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00009649 Expr *OrigCallee,
9650 Expr *First,
9651 Expr *Second) {
9652 Expr *Callee = OrigCallee->IgnoreParenCasts();
9653 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00009654
Douglas Gregora16548e2009-08-11 05:31:07 +00009655 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00009656 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00009657 if (!First->getType()->isOverloadableType() &&
9658 !Second->getType()->isOverloadableType())
9659 return getSema().CreateBuiltinArraySubscriptExpr(First,
9660 Callee->getLocStart(),
9661 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00009662 } else if (Op == OO_Arrow) {
9663 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00009664 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9665 } else if (Second == 0 || isPostIncDec) {
9666 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009667 // The argument is not of overloadable type, so try to create a
9668 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00009669 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00009670 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00009671
John McCallb268a282010-08-23 23:25:46 +00009672 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00009673 }
9674 } else {
John McCallb268a282010-08-23 23:25:46 +00009675 if (!First->getType()->isOverloadableType() &&
9676 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009677 // Neither of the arguments is an overloadable type, so try to
9678 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00009679 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00009680 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00009681 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00009682 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009683 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009684
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009685 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00009686 }
9687 }
Mike Stump11289f42009-09-09 15:08:12 +00009688
9689 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00009690 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00009691 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00009692
John McCallb268a282010-08-23 23:25:46 +00009693 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00009694 assert(ULE->requiresADL());
9695
9696 // FIXME: Do we have to check
9697 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00009698 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00009699 } else {
Richard Smith58db83d2012-11-28 21:47:39 +00009700 // If we've resolved this to a particular non-member function, just call
9701 // that function. If we resolved it to a member function,
9702 // CreateOverloaded* will find that function for us.
9703 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9704 if (!isa<CXXMethodDecl>(ND))
9705 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +00009706 }
Mike Stump11289f42009-09-09 15:08:12 +00009707
Douglas Gregora16548e2009-08-11 05:31:07 +00009708 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00009709 Expr *Args[2] = { First, Second };
9710 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00009711
Douglas Gregora16548e2009-08-11 05:31:07 +00009712 // Create the overloaded operator invocation for unary operators.
9713 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00009714 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00009715 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00009716 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00009717 }
Mike Stump11289f42009-09-09 15:08:12 +00009718
Douglas Gregore9d62932011-07-15 16:25:15 +00009719 if (Op == OO_Subscript) {
9720 SourceLocation LBrace;
9721 SourceLocation RBrace;
9722
9723 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9724 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9725 LBrace = SourceLocation::getFromRawEncoding(
9726 NameLoc.CXXOperatorName.BeginOpNameLoc);
9727 RBrace = SourceLocation::getFromRawEncoding(
9728 NameLoc.CXXOperatorName.EndOpNameLoc);
9729 } else {
9730 LBrace = Callee->getLocStart();
9731 RBrace = OpLoc;
9732 }
9733
9734 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9735 First, Second);
9736 }
Sebastian Redladba46e2009-10-29 20:17:01 +00009737
Douglas Gregora16548e2009-08-11 05:31:07 +00009738 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00009739 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00009740 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00009741 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9742 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009743 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009744
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009745 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00009746}
Mike Stump11289f42009-09-09 15:08:12 +00009747
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009748template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00009749ExprResult
John McCallb268a282010-08-23 23:25:46 +00009750TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009751 SourceLocation OperatorLoc,
9752 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +00009753 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009754 TypeSourceInfo *ScopeType,
9755 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009756 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009757 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +00009758 QualType BaseType = Base->getType();
9759 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009760 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +00009761 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00009762 !BaseType->getAs<PointerType>()->getPointeeType()
9763 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009764 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00009765 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009766 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009767 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009768 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009769 /*FIXME?*/true);
9770 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009771
Douglas Gregor678f90d2010-02-25 01:56:36 +00009772 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009773 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9774 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9775 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9776 NameInfo.setNamedTypeInfo(DestroyedType);
9777
Richard Smith8e4a3862012-05-15 06:15:11 +00009778 // The scope type is now known to be a valid nested name specifier
9779 // component. Tack it on to the end of the nested name specifier.
9780 if (ScopeType)
9781 SS.Extend(SemaRef.Context, SourceLocation(),
9782 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009783
Abramo Bagnara7945c982012-01-27 09:46:47 +00009784 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +00009785 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009786 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009787 SS, TemplateKWLoc,
9788 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009789 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009790 /*TemplateArgs*/ 0);
9791}
9792
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00009793template<typename Derived>
9794StmtResult
9795TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +00009796 SourceLocation Loc = S->getLocStart();
9797 unsigned NumParams = S->getCapturedDecl()->getNumParams();
9798 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/0,
9799 S->getCapturedRegionKind(), NumParams);
9800 StmtResult Body = getDerived().TransformStmt(S->getCapturedStmt());
9801
9802 if (Body.isInvalid()) {
9803 getSema().ActOnCapturedRegionError();
9804 return StmtError();
9805 }
9806
9807 return getSema().ActOnCapturedRegionEnd(Body.take());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00009808}
9809
Douglas Gregord6ff3322009-08-04 16:50:30 +00009810} // end namespace clang
9811
9812#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H