blob: 7195871d94f04ff97f355e18d4e2fe49769ac49b [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:
Nick Lewycky0c438082011-01-24 19:01:04 +0000955 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +0000956 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +0000957 break;
958 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000959 return QualType();
960 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000961
Richard Trieucaa33d32011-06-10 03:11:26 +0000962 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
963 IdLoc, *Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +0000964 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000965 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
966 return QualType();
967 }
968
969 // Build the elaborated-type-specifier type.
970 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +0000971 return SemaRef.Context.getElaboratedType(Keyword,
972 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000973 T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000974 }
Mike Stump11289f42009-09-09 15:08:12 +0000975
Douglas Gregor822d0302011-01-12 17:07:58 +0000976 /// \brief Build a new pack expansion type.
977 ///
978 /// By default, builds a new PackExpansionType type from the given pattern.
979 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000980 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +0000981 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000982 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +0000983 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000984 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
985 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +0000986 }
987
Eli Friedman0dfb8892011-10-06 23:00:33 +0000988 /// \brief Build a new atomic type given its value type.
989 ///
990 /// By default, performs semantic analysis when building the atomic type.
991 /// Subclasses may override this routine to provide different behavior.
992 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
993
Douglas Gregor71dc5092009-08-06 06:41:21 +0000994 /// \brief Build a new template name given a nested name specifier, a flag
995 /// indicating whether the "template" keyword was provided, and the template
996 /// that the template name refers to.
997 ///
998 /// By default, builds the new template name directly. Subclasses may override
999 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001000 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001001 bool TemplateKW,
1002 TemplateDecl *Template);
1003
Douglas Gregor71dc5092009-08-06 06:41:21 +00001004 /// \brief Build a new template name given a nested name specifier and the
1005 /// name that is referred to as a template.
1006 ///
1007 /// By default, performs semantic analysis to determine whether the name can
1008 /// be resolved to a specific template, then builds the appropriate kind of
1009 /// template name. Subclasses may override this routine to provide different
1010 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001011 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1012 const IdentifierInfo &Name,
1013 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00001014 QualType ObjectType,
1015 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001016
Douglas Gregor71395fa2009-11-04 00:56:37 +00001017 /// \brief Build a new template name given a nested name specifier and the
1018 /// overloaded operator name that is referred to as a template.
1019 ///
1020 /// By default, performs semantic analysis to determine whether the name can
1021 /// be resolved to a specific template, then builds the appropriate kind of
1022 /// template name. Subclasses may override this routine to provide different
1023 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001024 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001025 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00001026 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001027 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +00001028
1029 /// \brief Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001030 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001031 ///
1032 /// By default, performs semantic analysis to determine whether the name can
1033 /// be resolved to a specific template, then builds the appropriate kind of
1034 /// template name. Subclasses may override this routine to provide different
1035 /// behavior.
1036 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1037 const TemplateArgument &ArgPack) {
1038 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1039 }
1040
Douglas Gregorebe10102009-08-20 07:17:43 +00001041 /// \brief Build a new compound statement.
1042 ///
1043 /// By default, performs semantic analysis to build the new statement.
1044 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001045 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001046 MultiStmtArg Statements,
1047 SourceLocation RBraceLoc,
1048 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001049 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001050 IsStmtExpr);
1051 }
1052
1053 /// \brief Build a new case statement.
1054 ///
1055 /// By default, performs semantic analysis to build the new statement.
1056 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001057 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001058 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001059 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001060 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001061 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001062 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001063 ColonLoc);
1064 }
Mike Stump11289f42009-09-09 15:08:12 +00001065
Douglas Gregorebe10102009-08-20 07:17:43 +00001066 /// \brief Attach the body to a new case statement.
1067 ///
1068 /// By default, performs semantic analysis to build the new statement.
1069 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001070 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001071 getSema().ActOnCaseStmtBody(S, Body);
1072 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001073 }
Mike Stump11289f42009-09-09 15:08:12 +00001074
Douglas Gregorebe10102009-08-20 07:17:43 +00001075 /// \brief Build a new default statement.
1076 ///
1077 /// By default, performs semantic analysis to build the new statement.
1078 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001079 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001080 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001081 Stmt *SubStmt) {
1082 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +00001083 /*CurScope=*/0);
1084 }
Mike Stump11289f42009-09-09 15:08:12 +00001085
Douglas Gregorebe10102009-08-20 07:17:43 +00001086 /// \brief Build a new label statement.
1087 ///
1088 /// By default, performs semantic analysis to build the new statement.
1089 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001090 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1091 SourceLocation ColonLoc, Stmt *SubStmt) {
1092 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001093 }
Mike Stump11289f42009-09-09 15:08:12 +00001094
Richard Smithc202b282012-04-14 00:33:13 +00001095 /// \brief Build a new label statement.
1096 ///
1097 /// By default, performs semantic analysis to build the new statement.
1098 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001099 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1100 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001101 Stmt *SubStmt) {
1102 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1103 }
1104
Douglas Gregorebe10102009-08-20 07:17:43 +00001105 /// \brief Build a new "if" statement.
1106 ///
1107 /// By default, performs semantic analysis to build the new statement.
1108 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001109 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier1dcde962012-08-08 18:46:20 +00001110 VarDecl *CondVar, Stmt *Then,
Chris Lattnercab02a62011-02-17 20:34:02 +00001111 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001112 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001113 }
Mike Stump11289f42009-09-09 15:08:12 +00001114
Douglas Gregorebe10102009-08-20 07:17:43 +00001115 /// \brief Start building a new switch statement.
1116 ///
1117 /// By default, performs semantic analysis to build the new statement.
1118 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001119 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001120 Expr *Cond, VarDecl *CondVar) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001121 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001122 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001123 }
Mike Stump11289f42009-09-09 15:08:12 +00001124
Douglas Gregorebe10102009-08-20 07:17:43 +00001125 /// \brief Attach the body to the switch statement.
1126 ///
1127 /// By default, performs semantic analysis to build the new statement.
1128 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001129 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001130 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001131 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001132 }
1133
1134 /// \brief Build a new while statement.
1135 ///
1136 /// By default, performs semantic analysis to build the new statement.
1137 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001138 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1139 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001140 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001141 }
Mike Stump11289f42009-09-09 15:08:12 +00001142
Douglas Gregorebe10102009-08-20 07:17:43 +00001143 /// \brief Build a new do-while statement.
1144 ///
1145 /// By default, performs semantic analysis to build the new statement.
1146 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001147 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001148 SourceLocation WhileLoc, SourceLocation LParenLoc,
1149 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001150 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1151 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001152 }
1153
1154 /// \brief Build a new for statement.
1155 ///
1156 /// By default, performs semantic analysis to build the new statement.
1157 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001158 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier1dcde962012-08-08 18:46:20 +00001159 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001160 VarDecl *CondVar, Sema::FullExprArg Inc,
1161 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001162 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001163 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001164 }
Mike Stump11289f42009-09-09 15:08:12 +00001165
Douglas Gregorebe10102009-08-20 07:17:43 +00001166 /// \brief Build a new goto statement.
1167 ///
1168 /// By default, performs semantic analysis to build the new statement.
1169 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001170 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1171 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001172 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001173 }
1174
1175 /// \brief Build a new indirect goto statement.
1176 ///
1177 /// By default, performs semantic analysis to build the new statement.
1178 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001179 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001180 SourceLocation StarLoc,
1181 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001182 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001183 }
Mike Stump11289f42009-09-09 15:08:12 +00001184
Douglas Gregorebe10102009-08-20 07:17:43 +00001185 /// \brief Build a new return statement.
1186 ///
1187 /// By default, performs semantic analysis to build the new statement.
1188 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001189 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCallb268a282010-08-23 23:25:46 +00001190 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001191 }
Mike Stump11289f42009-09-09 15:08:12 +00001192
Douglas Gregorebe10102009-08-20 07:17:43 +00001193 /// \brief Build a new declaration statement.
1194 ///
1195 /// By default, performs semantic analysis to build the new statement.
1196 /// Subclasses may override this routine to provide different behavior.
Rafael Espindolaab417692013-07-09 12:05:01 +00001197 StmtResult RebuildDeclStmt(llvm::MutableArrayRef<Decl *> Decls,
1198 SourceLocation StartLoc, SourceLocation EndLoc) {
1199 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001200 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001201 }
Mike Stump11289f42009-09-09 15:08:12 +00001202
Anders Carlssonaaeef072010-01-24 05:50:09 +00001203 /// \brief Build a new inline asm statement.
1204 ///
1205 /// By default, performs semantic analysis to build the new statement.
1206 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001207 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1208 bool IsVolatile, unsigned NumOutputs,
1209 unsigned NumInputs, IdentifierInfo **Names,
1210 MultiExprArg Constraints, MultiExprArg Exprs,
1211 Expr *AsmString, MultiExprArg Clobbers,
1212 SourceLocation RParenLoc) {
1213 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1214 NumInputs, Names, Constraints, Exprs,
1215 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001216 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001217
Chad Rosier32503022012-06-11 20:47:18 +00001218 /// \brief Build a new MS style inline asm statement.
1219 ///
1220 /// By default, performs semantic analysis to build the new statement.
1221 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001222 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001223 ArrayRef<Token> AsmToks,
1224 StringRef AsmString,
1225 unsigned NumOutputs, unsigned NumInputs,
1226 ArrayRef<StringRef> Constraints,
1227 ArrayRef<StringRef> Clobbers,
1228 ArrayRef<Expr*> Exprs,
1229 SourceLocation EndLoc) {
1230 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1231 NumOutputs, NumInputs,
1232 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001233 }
1234
James Dennett2a4d13c2012-06-15 07:13:21 +00001235 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001236 ///
1237 /// By default, performs semantic analysis to build the new statement.
1238 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001239 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001240 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001241 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001242 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001243 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001244 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001245 }
1246
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001247 /// \brief Rebuild an Objective-C exception declaration.
1248 ///
1249 /// By default, performs semantic analysis to build the new declaration.
1250 /// Subclasses may override this routine to provide different behavior.
1251 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1252 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001253 return getSema().BuildObjCExceptionDecl(TInfo, T,
1254 ExceptionDecl->getInnerLocStart(),
1255 ExceptionDecl->getLocation(),
1256 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001257 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001258
James Dennett2a4d13c2012-06-15 07:13:21 +00001259 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001260 ///
1261 /// By default, performs semantic analysis to build the new statement.
1262 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001263 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001264 SourceLocation RParenLoc,
1265 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001266 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001267 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001268 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001269 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001270
James Dennett2a4d13c2012-06-15 07:13:21 +00001271 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001272 ///
1273 /// By default, performs semantic analysis to build the new statement.
1274 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001275 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001276 Stmt *Body) {
1277 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001278 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001279
James Dennett2a4d13c2012-06-15 07:13:21 +00001280 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001281 ///
1282 /// By default, performs semantic analysis to build the new statement.
1283 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001284 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001285 Expr *Operand) {
1286 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001287 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001288
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001289 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001290 ///
1291 /// By default, performs semantic analysis to build the new statement.
1292 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001293 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
1294 ArrayRef<OMPClause *> Clauses,
1295 Stmt *AStmt,
1296 SourceLocation StartLoc,
1297 SourceLocation EndLoc) {
1298 return getSema().ActOnOpenMPExecutableDirective(Kind, Clauses, AStmt,
1299 StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001300 }
1301
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001302 /// \brief Build a new OpenMP 'if' clause.
1303 ///
1304 /// By default, performs semantic analysis to build the new statement.
1305 /// Subclasses may override this routine to provide different behavior.
1306 OMPClause *RebuildOMPIfClause(Expr *Condition,
1307 SourceLocation StartLoc,
1308 SourceLocation LParenLoc,
1309 SourceLocation EndLoc) {
1310 return getSema().ActOnOpenMPIfClause(Condition, StartLoc,
1311 LParenLoc, EndLoc);
1312 }
1313
Alexey Bataev568a8332014-03-06 06:15:19 +00001314 /// \brief Build a new OpenMP 'num_threads' clause.
1315 ///
1316 /// By default, performs semantic analysis to build the new statement.
1317 /// Subclasses may override this routine to provide different behavior.
1318 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1319 SourceLocation StartLoc,
1320 SourceLocation LParenLoc,
1321 SourceLocation EndLoc) {
1322 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1323 LParenLoc, EndLoc);
1324 }
1325
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001326 /// \brief Build a new OpenMP 'default' clause.
1327 ///
1328 /// By default, performs semantic analysis to build the new statement.
1329 /// Subclasses may override this routine to provide different behavior.
1330 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1331 SourceLocation KindKwLoc,
1332 SourceLocation StartLoc,
1333 SourceLocation LParenLoc,
1334 SourceLocation EndLoc) {
1335 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1336 StartLoc, LParenLoc, EndLoc);
1337 }
1338
1339 /// \brief Build a new OpenMP 'private' clause.
1340 ///
1341 /// By default, performs semantic analysis to build the new statement.
1342 /// Subclasses may override this routine to provide different behavior.
1343 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1344 SourceLocation StartLoc,
1345 SourceLocation LParenLoc,
1346 SourceLocation EndLoc) {
1347 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1348 EndLoc);
1349 }
1350
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001351 /// \brief Build a new OpenMP 'firstprivate' clause.
1352 ///
1353 /// By default, performs semantic analysis to build the new statement.
1354 /// Subclasses may override this routine to provide different behavior.
1355 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1356 SourceLocation StartLoc,
1357 SourceLocation LParenLoc,
1358 SourceLocation EndLoc) {
1359 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1360 EndLoc);
1361 }
1362
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001363 /// \brief Build a new OpenMP 'shared' clause.
1364 ///
1365 /// By default, performs semantic analysis to build the new statement.
1366 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001367 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1368 SourceLocation StartLoc,
1369 SourceLocation LParenLoc,
1370 SourceLocation EndLoc) {
1371 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1372 EndLoc);
1373 }
1374
James Dennett2a4d13c2012-06-15 07:13:21 +00001375 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001376 ///
1377 /// By default, performs semantic analysis to build the new statement.
1378 /// Subclasses may override this routine to provide different behavior.
1379 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1380 Expr *object) {
1381 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1382 }
1383
James Dennett2a4d13c2012-06-15 07:13:21 +00001384 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001385 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001386 /// By default, performs semantic analysis to build the new statement.
1387 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001388 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001389 Expr *Object, Stmt *Body) {
1390 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001391 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001392
James Dennett2a4d13c2012-06-15 07:13:21 +00001393 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001394 ///
1395 /// By default, performs semantic analysis to build the new statement.
1396 /// Subclasses may override this routine to provide different behavior.
1397 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1398 Stmt *Body) {
1399 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1400 }
John McCall53848232011-07-27 01:07:15 +00001401
Douglas Gregorf68a5082010-04-22 23:10:45 +00001402 /// \brief Build a new Objective-C fast enumeration statement.
1403 ///
1404 /// By default, performs semantic analysis to build the new statement.
1405 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001406 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001407 Stmt *Element,
1408 Expr *Collection,
1409 SourceLocation RParenLoc,
1410 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001411 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001412 Element,
John McCallb268a282010-08-23 23:25:46 +00001413 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001414 RParenLoc);
1415 if (ForEachStmt.isInvalid())
1416 return StmtError();
1417
1418 return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001419 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001420
Douglas Gregorebe10102009-08-20 07:17:43 +00001421 /// \brief Build a new C++ exception declaration.
1422 ///
1423 /// By default, performs semantic analysis to build the new decaration.
1424 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001425 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001426 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001427 SourceLocation StartLoc,
1428 SourceLocation IdLoc,
1429 IdentifierInfo *Id) {
Douglas Gregor40965fa2011-04-14 22:32:28 +00001430 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1431 StartLoc, IdLoc, Id);
1432 if (Var)
1433 getSema().CurContext->addDecl(Var);
1434 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001435 }
1436
1437 /// \brief Build a new C++ catch statement.
1438 ///
1439 /// By default, performs semantic analysis to build the new statement.
1440 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001441 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001442 VarDecl *ExceptionDecl,
1443 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001444 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1445 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001446 }
Mike Stump11289f42009-09-09 15:08:12 +00001447
Douglas Gregorebe10102009-08-20 07:17:43 +00001448 /// \brief Build a new C++ try statement.
1449 ///
1450 /// By default, performs semantic analysis to build the new statement.
1451 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001452 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1453 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001454 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001455 }
Mike Stump11289f42009-09-09 15:08:12 +00001456
Richard Smith02e85f32011-04-14 22:09:26 +00001457 /// \brief Build a new C++0x range-based for statement.
1458 ///
1459 /// By default, performs semantic analysis to build the new statement.
1460 /// Subclasses may override this routine to provide different behavior.
1461 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1462 SourceLocation ColonLoc,
1463 Stmt *Range, Stmt *BeginEnd,
1464 Expr *Cond, Expr *Inc,
1465 Stmt *LoopVar,
1466 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001467 // If we've just learned that the range is actually an Objective-C
1468 // collection, treat this as an Objective-C fast enumeration loop.
1469 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1470 if (RangeStmt->isSingleDecl()) {
1471 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001472 if (RangeVar->isInvalidDecl())
1473 return StmtError();
1474
Douglas Gregorf7106af2013-04-08 18:40:13 +00001475 Expr *RangeExpr = RangeVar->getInit();
1476 if (!RangeExpr->isTypeDependent() &&
1477 RangeExpr->getType()->isObjCObjectPointerType())
1478 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1479 RParenLoc);
1480 }
1481 }
1482 }
1483
Richard Smith02e85f32011-04-14 22:09:26 +00001484 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001485 Cond, Inc, LoopVar, RParenLoc,
1486 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001487 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001488
1489 /// \brief Build a new C++0x range-based for statement.
1490 ///
1491 /// By default, performs semantic analysis to build the new statement.
1492 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001493 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001494 bool IsIfExists,
1495 NestedNameSpecifierLoc QualifierLoc,
1496 DeclarationNameInfo NameInfo,
1497 Stmt *Nested) {
1498 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1499 QualifierLoc, NameInfo, Nested);
1500 }
1501
Richard Smith02e85f32011-04-14 22:09:26 +00001502 /// \brief Attach body to a C++0x range-based for statement.
1503 ///
1504 /// By default, performs semantic analysis to finish the new statement.
1505 /// Subclasses may override this routine to provide different behavior.
1506 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1507 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1508 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001509
David Majnemerfad8f482013-10-15 09:33:02 +00001510 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
1511 Stmt *TryBlock, Stmt *Handler) {
1512 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001513 }
1514
David Majnemerfad8f482013-10-15 09:33:02 +00001515 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001516 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001517 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001518 }
1519
David Majnemerfad8f482013-10-15 09:33:02 +00001520 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
1521 return getSema().ActOnSEHFinallyBlock(Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001522 }
1523
Douglas Gregora16548e2009-08-11 05:31:07 +00001524 /// \brief Build a new expression that references a declaration.
1525 ///
1526 /// By default, performs semantic analysis to build the new expression.
1527 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001528 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001529 LookupResult &R,
1530 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001531 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1532 }
1533
1534
1535 /// \brief Build a new expression that references a declaration.
1536 ///
1537 /// By default, performs semantic analysis to build the new expression.
1538 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001539 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001540 ValueDecl *VD,
1541 const DeclarationNameInfo &NameInfo,
1542 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001543 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001544 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001545
1546 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001547
1548 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001549 }
Mike Stump11289f42009-09-09 15:08:12 +00001550
Douglas Gregora16548e2009-08-11 05:31:07 +00001551 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001552 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001553 /// By default, performs semantic analysis to build the new expression.
1554 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001555 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001556 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001557 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001558 }
1559
Douglas Gregorad8a3362009-09-04 17:36:40 +00001560 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001561 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001562 /// By default, performs semantic analysis to build the new expression.
1563 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001564 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001565 SourceLocation OperatorLoc,
1566 bool isArrow,
1567 CXXScopeSpec &SS,
1568 TypeSourceInfo *ScopeType,
1569 SourceLocation CCLoc,
1570 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001571 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001572
Douglas Gregora16548e2009-08-11 05:31:07 +00001573 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001574 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001575 /// By default, performs semantic analysis to build the new expression.
1576 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001577 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001578 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001579 Expr *SubExpr) {
1580 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001581 }
Mike Stump11289f42009-09-09 15:08:12 +00001582
Douglas Gregor882211c2010-04-28 22:16:22 +00001583 /// \brief Build a new builtin offsetof expression.
1584 ///
1585 /// By default, performs semantic analysis to build the new expression.
1586 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001587 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001588 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001589 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001590 unsigned NumComponents,
1591 SourceLocation RParenLoc) {
1592 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1593 NumComponents, RParenLoc);
1594 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001595
1596 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001597 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001598 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001599 /// By default, performs semantic analysis to build the new expression.
1600 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001601 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1602 SourceLocation OpLoc,
1603 UnaryExprOrTypeTrait ExprKind,
1604 SourceRange R) {
1605 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001606 }
1607
Peter Collingbournee190dee2011-03-11 19:24:49 +00001608 /// \brief Build a new sizeof, alignof or vec step expression with an
1609 /// expression argument.
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.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001613 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1614 UnaryExprOrTypeTrait ExprKind,
1615 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001616 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001617 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001618 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001619 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001620
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001621 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001622 }
Mike Stump11289f42009-09-09 15:08:12 +00001623
Douglas Gregora16548e2009-08-11 05:31:07 +00001624 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001625 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001626 /// By default, performs semantic analysis to build the new expression.
1627 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001628 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001629 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001630 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001631 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001632 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1633 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001634 RBracketLoc);
1635 }
1636
1637 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001638 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001639 /// By default, performs semantic analysis to build the new expression.
1640 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001641 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001642 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001643 SourceLocation RParenLoc,
1644 Expr *ExecConfig = 0) {
John McCallb268a282010-08-23 23:25:46 +00001645 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001646 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001647 }
1648
1649 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001650 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001651 /// By default, performs semantic analysis to build the new expression.
1652 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001653 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001654 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001655 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001656 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001657 const DeclarationNameInfo &MemberNameInfo,
1658 ValueDecl *Member,
1659 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001660 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001661 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00001662 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1663 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00001664 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001665 // We have a reference to an unnamed field. This is always the
1666 // base of an anonymous struct/union member access, i.e. the
1667 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001668 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001669 assert(Member->getType()->isRecordType() &&
1670 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001671
Richard Smithcab9a7d2011-10-26 19:06:56 +00001672 BaseResult =
1673 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley01296292011-04-08 18:41:53 +00001674 QualifierLoc.getNestedNameSpecifier(),
1675 FoundDecl, Member);
1676 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001677 return ExprError();
John Wiegley01296292011-04-08 18:41:53 +00001678 Base = BaseResult.take();
John McCall7decc9e2010-11-18 06:31:45 +00001679 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001680 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001681 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001682 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001683 cast<FieldDecl>(Member)->getType(),
1684 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001685 return getSema().Owned(ME);
1686 }
Mike Stump11289f42009-09-09 15:08:12 +00001687
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001688 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001689 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001690
John Wiegley01296292011-04-08 18:41:53 +00001691 Base = BaseResult.take();
John McCallb268a282010-08-23 23:25:46 +00001692 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001693
John McCall16df1e52010-03-30 21:47:33 +00001694 // FIXME: this involves duplicating earlier analysis in a lot of
1695 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001696 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001697 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001698 R.resolveKind();
1699
John McCallb268a282010-08-23 23:25:46 +00001700 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001701 SS, TemplateKWLoc,
1702 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001703 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001704 }
Mike Stump11289f42009-09-09 15:08:12 +00001705
Douglas Gregora16548e2009-08-11 05:31:07 +00001706 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001707 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001708 /// By default, performs semantic analysis to build the new expression.
1709 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001710 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001711 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001712 Expr *LHS, Expr *RHS) {
1713 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001714 }
1715
1716 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001717 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001718 /// By default, performs semantic analysis to build the new expression.
1719 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001720 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001721 SourceLocation QuestionLoc,
1722 Expr *LHS,
1723 SourceLocation ColonLoc,
1724 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001725 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1726 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001727 }
1728
Douglas Gregora16548e2009-08-11 05:31:07 +00001729 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001730 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001731 /// By default, performs semantic analysis to build the new expression.
1732 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001733 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001734 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001735 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001736 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001737 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001738 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001739 }
Mike Stump11289f42009-09-09 15:08:12 +00001740
Douglas Gregora16548e2009-08-11 05:31:07 +00001741 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001742 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001743 /// By default, performs semantic analysis to build the new expression.
1744 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001745 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001746 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001747 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001748 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001749 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001750 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001751 }
Mike Stump11289f42009-09-09 15:08:12 +00001752
Douglas Gregora16548e2009-08-11 05:31:07 +00001753 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001754 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001755 /// By default, performs semantic analysis to build the new expression.
1756 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001757 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001758 SourceLocation OpLoc,
1759 SourceLocation AccessorLoc,
1760 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001761
John McCall10eae182009-11-30 22:42:35 +00001762 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001763 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001764 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001765 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001766 SS, SourceLocation(),
1767 /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001768 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001769 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001770 }
Mike Stump11289f42009-09-09 15:08:12 +00001771
Douglas Gregora16548e2009-08-11 05:31:07 +00001772 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001773 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001774 /// By default, performs semantic analysis to build the new expression.
1775 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001776 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00001777 MultiExprArg Inits,
1778 SourceLocation RBraceLoc,
1779 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001780 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001781 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00001782 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001783 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00001784
Douglas Gregord3d93062009-11-09 17:16:50 +00001785 // Patch in the result type we were given, which may have been computed
1786 // when the initial InitListExpr was built.
1787 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1788 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001789 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001790 }
Mike Stump11289f42009-09-09 15:08:12 +00001791
Douglas Gregora16548e2009-08-11 05:31:07 +00001792 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001793 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001794 /// By default, performs semantic analysis to build the new expression.
1795 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001796 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001797 MultiExprArg ArrayExprs,
1798 SourceLocation EqualOrColonLoc,
1799 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001800 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001801 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001802 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001803 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001804 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001805 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001806
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001807 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001808 }
Mike Stump11289f42009-09-09 15:08:12 +00001809
Douglas Gregora16548e2009-08-11 05:31:07 +00001810 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001811 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001812 /// By default, builds the implicit value initialization without performing
1813 /// any semantic analysis. Subclasses may override this routine to provide
1814 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001815 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001816 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1817 }
Mike Stump11289f42009-09-09 15:08:12 +00001818
Douglas Gregora16548e2009-08-11 05:31:07 +00001819 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001820 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001821 /// By default, performs semantic analysis to build the new expression.
1822 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001823 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001824 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001825 SourceLocation RParenLoc) {
1826 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001827 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001828 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001829 }
1830
1831 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001832 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001833 /// By default, performs semantic analysis to build the new expression.
1834 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001835 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00001836 MultiExprArg SubExprs,
1837 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001838 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001839 }
Mike Stump11289f42009-09-09 15:08:12 +00001840
Douglas Gregora16548e2009-08-11 05:31:07 +00001841 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001842 ///
1843 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001844 /// rather than attempting to map the label statement itself.
1845 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001846 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001847 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001848 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001849 }
Mike Stump11289f42009-09-09 15:08:12 +00001850
Douglas Gregora16548e2009-08-11 05:31:07 +00001851 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001852 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001853 /// By default, performs semantic analysis to build the new expression.
1854 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001855 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001856 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001857 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001858 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001859 }
Mike Stump11289f42009-09-09 15:08:12 +00001860
Douglas Gregora16548e2009-08-11 05:31:07 +00001861 /// \brief Build a new __builtin_choose_expr expression.
1862 ///
1863 /// By default, performs semantic analysis to build the new expression.
1864 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001865 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001866 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001867 SourceLocation RParenLoc) {
1868 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001869 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001870 RParenLoc);
1871 }
Mike Stump11289f42009-09-09 15:08:12 +00001872
Peter Collingbourne91147592011-04-15 00:35:48 +00001873 /// \brief Build a new generic selection expression.
1874 ///
1875 /// By default, performs semantic analysis to build the new expression.
1876 /// Subclasses may override this routine to provide different behavior.
1877 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1878 SourceLocation DefaultLoc,
1879 SourceLocation RParenLoc,
1880 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00001881 ArrayRef<TypeSourceInfo *> Types,
1882 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00001883 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00001884 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00001885 }
1886
Douglas Gregora16548e2009-08-11 05:31:07 +00001887 /// \brief Build a new overloaded operator call expression.
1888 ///
1889 /// By default, performs semantic analysis to build the new expression.
1890 /// The semantic analysis provides the behavior of template instantiation,
1891 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001892 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001893 /// argument-dependent lookup, etc. Subclasses may override this routine to
1894 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001895 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001896 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001897 Expr *Callee,
1898 Expr *First,
1899 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001900
1901 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001902 /// reinterpret_cast.
1903 ///
1904 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001905 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001906 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001907 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001908 Stmt::StmtClass Class,
1909 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001910 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001911 SourceLocation RAngleLoc,
1912 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001913 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001914 SourceLocation RParenLoc) {
1915 switch (Class) {
1916 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001917 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001918 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001919 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001920
1921 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001922 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001923 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001924 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001925
Douglas Gregora16548e2009-08-11 05:31:07 +00001926 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001927 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001928 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001929 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001930 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001931
Douglas Gregora16548e2009-08-11 05:31:07 +00001932 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001933 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001934 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001935 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001936
Douglas Gregora16548e2009-08-11 05:31:07 +00001937 default:
David Blaikie83d382b2011-09-23 05:06:16 +00001938 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00001939 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001940 }
Mike Stump11289f42009-09-09 15:08:12 +00001941
Douglas Gregora16548e2009-08-11 05:31:07 +00001942 /// \brief Build a new C++ static_cast expression.
1943 ///
1944 /// By default, performs semantic analysis to build the new expression.
1945 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001946 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001947 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001948 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001949 SourceLocation RAngleLoc,
1950 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001951 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001952 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001953 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001954 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001955 SourceRange(LAngleLoc, RAngleLoc),
1956 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001957 }
1958
1959 /// \brief Build a new C++ dynamic_cast expression.
1960 ///
1961 /// By default, performs semantic analysis to build the new expression.
1962 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001963 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001964 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001965 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001966 SourceLocation RAngleLoc,
1967 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001968 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001969 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001970 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001971 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001972 SourceRange(LAngleLoc, RAngleLoc),
1973 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001974 }
1975
1976 /// \brief Build a new C++ reinterpret_cast expression.
1977 ///
1978 /// By default, performs semantic analysis to build the new expression.
1979 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001980 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001981 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001982 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001983 SourceLocation RAngleLoc,
1984 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001985 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001986 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001987 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001988 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001989 SourceRange(LAngleLoc, RAngleLoc),
1990 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001991 }
1992
1993 /// \brief Build a new C++ const_cast expression.
1994 ///
1995 /// By default, performs semantic analysis to build the new expression.
1996 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001997 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001998 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001999 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002000 SourceLocation RAngleLoc,
2001 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002002 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002003 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002004 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002005 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002006 SourceRange(LAngleLoc, RAngleLoc),
2007 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002008 }
Mike Stump11289f42009-09-09 15:08:12 +00002009
Douglas Gregora16548e2009-08-11 05:31:07 +00002010 /// \brief Build a new C++ functional-style cast expression.
2011 ///
2012 /// By default, performs semantic analysis to build the new expression.
2013 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002014 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2015 SourceLocation LParenLoc,
2016 Expr *Sub,
2017 SourceLocation RParenLoc) {
2018 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002019 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002020 RParenLoc);
2021 }
Mike Stump11289f42009-09-09 15:08:12 +00002022
Douglas Gregora16548e2009-08-11 05:31:07 +00002023 /// \brief Build a new C++ typeid(type) expression.
2024 ///
2025 /// By default, performs semantic analysis to build the new expression.
2026 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002027 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002028 SourceLocation TypeidLoc,
2029 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002030 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002031 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002032 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002033 }
Mike Stump11289f42009-09-09 15:08:12 +00002034
Francois Pichet9f4f2072010-09-08 12:20:18 +00002035
Douglas Gregora16548e2009-08-11 05:31:07 +00002036 /// \brief Build a new C++ typeid(expr) expression.
2037 ///
2038 /// By default, performs semantic analysis to build the new expression.
2039 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002040 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002041 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002042 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002043 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002044 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002045 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002046 }
2047
Francois Pichet9f4f2072010-09-08 12:20:18 +00002048 /// \brief Build a new C++ __uuidof(type) expression.
2049 ///
2050 /// By default, performs semantic analysis to build the new expression.
2051 /// Subclasses may override this routine to provide different behavior.
2052 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2053 SourceLocation TypeidLoc,
2054 TypeSourceInfo *Operand,
2055 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002056 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002057 RParenLoc);
2058 }
2059
2060 /// \brief Build a new C++ __uuidof(expr) expression.
2061 ///
2062 /// By default, performs semantic analysis to build the new expression.
2063 /// Subclasses may override this routine to provide different behavior.
2064 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2065 SourceLocation TypeidLoc,
2066 Expr *Operand,
2067 SourceLocation RParenLoc) {
2068 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2069 RParenLoc);
2070 }
2071
Douglas Gregora16548e2009-08-11 05:31:07 +00002072 /// \brief Build a new C++ "this" expression.
2073 ///
2074 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002075 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002076 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002077 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002078 QualType ThisType,
2079 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002080 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002081 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00002082 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
2083 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00002084 }
2085
2086 /// \brief Build a new C++ throw expression.
2087 ///
2088 /// By default, performs semantic analysis to build the new expression.
2089 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002090 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2091 bool IsThrownVariableInScope) {
2092 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002093 }
2094
2095 /// \brief Build a new C++ default-argument expression.
2096 ///
2097 /// By default, builds a new default-argument expression, which does not
2098 /// require any semantic analysis. Subclasses may override this routine to
2099 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002100 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002101 ParmVarDecl *Param) {
2102 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
2103 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00002104 }
2105
Richard Smith852c9db2013-04-20 22:23:05 +00002106 /// \brief Build a new C++11 default-initialization expression.
2107 ///
2108 /// By default, builds a new default field initialization expression, which
2109 /// does not require any semantic analysis. Subclasses may override this
2110 /// routine to provide different behavior.
2111 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2112 FieldDecl *Field) {
2113 return getSema().Owned(CXXDefaultInitExpr::Create(getSema().Context, Loc,
2114 Field));
2115 }
2116
Douglas Gregora16548e2009-08-11 05:31:07 +00002117 /// \brief Build a new C++ zero-initialization expression.
2118 ///
2119 /// By default, performs semantic analysis to build the new expression.
2120 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002121 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2122 SourceLocation LParenLoc,
2123 SourceLocation RParenLoc) {
2124 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002125 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002126 }
Mike Stump11289f42009-09-09 15:08:12 +00002127
Douglas Gregora16548e2009-08-11 05:31:07 +00002128 /// \brief Build a new C++ "new" expression.
2129 ///
2130 /// By default, performs semantic analysis to build the new expression.
2131 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002132 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002133 bool UseGlobal,
2134 SourceLocation PlacementLParen,
2135 MultiExprArg PlacementArgs,
2136 SourceLocation PlacementRParen,
2137 SourceRange TypeIdParens,
2138 QualType AllocatedType,
2139 TypeSourceInfo *AllocatedTypeInfo,
2140 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002141 SourceRange DirectInitRange,
2142 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002143 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002144 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002145 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002146 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002147 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002148 AllocatedType,
2149 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002150 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002151 DirectInitRange,
2152 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002153 }
Mike Stump11289f42009-09-09 15:08:12 +00002154
Douglas Gregora16548e2009-08-11 05:31:07 +00002155 /// \brief Build a new C++ "delete" expression.
2156 ///
2157 /// By default, performs semantic analysis to build the new expression.
2158 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002159 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002160 bool IsGlobalDelete,
2161 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002162 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002163 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002164 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002165 }
Mike Stump11289f42009-09-09 15:08:12 +00002166
Douglas Gregor29c42f22012-02-24 07:38:34 +00002167 /// \brief Build a new type trait expression.
2168 ///
2169 /// By default, performs semantic analysis to build the new expression.
2170 /// Subclasses may override this routine to provide different behavior.
2171 ExprResult RebuildTypeTrait(TypeTrait Trait,
2172 SourceLocation StartLoc,
2173 ArrayRef<TypeSourceInfo *> Args,
2174 SourceLocation RParenLoc) {
2175 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2176 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002177
John Wiegley6242b6a2011-04-28 00:16:57 +00002178 /// \brief Build a new array type trait expression.
2179 ///
2180 /// By default, performs semantic analysis to build the new expression.
2181 /// Subclasses may override this routine to provide different behavior.
2182 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2183 SourceLocation StartLoc,
2184 TypeSourceInfo *TSInfo,
2185 Expr *DimExpr,
2186 SourceLocation RParenLoc) {
2187 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2188 }
2189
John Wiegleyf9f65842011-04-25 06:54:41 +00002190 /// \brief Build a new expression trait expression.
2191 ///
2192 /// By default, performs semantic analysis to build the new expression.
2193 /// Subclasses may override this routine to provide different behavior.
2194 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2195 SourceLocation StartLoc,
2196 Expr *Queried,
2197 SourceLocation RParenLoc) {
2198 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2199 }
2200
Mike Stump11289f42009-09-09 15:08:12 +00002201 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002202 /// expression.
2203 ///
2204 /// By default, performs semantic analysis to build the new expression.
2205 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002206 ExprResult RebuildDependentScopeDeclRefExpr(
2207 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002208 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002209 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002210 const TemplateArgumentListInfo *TemplateArgs,
2211 bool IsAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002212 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002213 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002214
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002215 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnara7945c982012-01-27 09:46:47 +00002216 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002217 NameInfo, TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002218
Richard Smithdb2630f2012-10-21 03:28:35 +00002219 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo,
2220 IsAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002221 }
2222
2223 /// \brief Build a new template-id expression.
2224 ///
2225 /// By default, performs semantic analysis to build the new expression.
2226 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002227 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002228 SourceLocation TemplateKWLoc,
2229 LookupResult &R,
2230 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002231 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002232 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2233 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002234 }
2235
2236 /// \brief Build a new object-construction expression.
2237 ///
2238 /// By default, performs semantic analysis to build the new expression.
2239 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002240 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002241 SourceLocation Loc,
2242 CXXConstructorDecl *Constructor,
2243 bool IsElidable,
2244 MultiExprArg Args,
2245 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002246 bool ListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002247 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002248 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002249 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002250 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002251 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002252 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002253 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002254
Douglas Gregordb121ba2009-12-14 16:27:04 +00002255 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002256 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002257 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002258 ListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002259 RequiresZeroInit, ConstructKind,
2260 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002261 }
2262
2263 /// \brief Build a new object-construction expression.
2264 ///
2265 /// By default, performs semantic analysis to build the new expression.
2266 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002267 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2268 SourceLocation LParenLoc,
2269 MultiExprArg Args,
2270 SourceLocation RParenLoc) {
2271 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002272 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002273 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002274 RParenLoc);
2275 }
2276
2277 /// \brief Build a new object-construction expression.
2278 ///
2279 /// By default, performs semantic analysis to build the new expression.
2280 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002281 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2282 SourceLocation LParenLoc,
2283 MultiExprArg Args,
2284 SourceLocation RParenLoc) {
2285 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002286 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002287 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002288 RParenLoc);
2289 }
Mike Stump11289f42009-09-09 15:08:12 +00002290
Douglas Gregora16548e2009-08-11 05:31:07 +00002291 /// \brief Build a new member reference expression.
2292 ///
2293 /// By default, performs semantic analysis to build the new expression.
2294 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002295 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002296 QualType BaseType,
2297 bool IsArrow,
2298 SourceLocation OperatorLoc,
2299 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002300 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002301 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002302 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002303 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002304 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002305 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002306
John McCallb268a282010-08-23 23:25:46 +00002307 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002308 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002309 SS, TemplateKWLoc,
2310 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002311 MemberNameInfo,
2312 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002313 }
2314
John McCall10eae182009-11-30 22:42:35 +00002315 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002316 ///
2317 /// By default, performs semantic analysis to build the new expression.
2318 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002319 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2320 SourceLocation OperatorLoc,
2321 bool IsArrow,
2322 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002323 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002324 NamedDecl *FirstQualifierInScope,
2325 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002326 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002327 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002328 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002329
John McCallb268a282010-08-23 23:25:46 +00002330 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002331 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002332 SS, TemplateKWLoc,
2333 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00002334 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002335 }
Mike Stump11289f42009-09-09 15:08:12 +00002336
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002337 /// \brief Build a new noexcept expression.
2338 ///
2339 /// By default, performs semantic analysis to build the new expression.
2340 /// Subclasses may override this routine to provide different behavior.
2341 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2342 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2343 }
2344
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002345 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00002346 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2347 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002348 SourceLocation RParenLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002349 Optional<unsigned> Length) {
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002350 if (Length)
Chad Rosier1dcde962012-08-08 18:46:20 +00002351 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2352 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002353 RParenLoc, *Length);
Chad Rosier1dcde962012-08-08 18:46:20 +00002354
2355 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2356 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002357 RParenLoc);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002358 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002359
Patrick Beard0caa3942012-04-19 00:25:12 +00002360 /// \brief Build a new Objective-C boxed expression.
2361 ///
2362 /// By default, performs semantic analysis to build the new expression.
2363 /// Subclasses may override this routine to provide different behavior.
2364 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2365 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2366 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002367
Ted Kremeneke65b0862012-03-06 20:05:56 +00002368 /// \brief Build a new Objective-C array literal.
2369 ///
2370 /// By default, performs semantic analysis to build the new expression.
2371 /// Subclasses may override this routine to provide different behavior.
2372 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2373 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002374 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002375 MultiExprArg(Elements, NumElements));
2376 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002377
2378 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002379 Expr *Base, Expr *Key,
2380 ObjCMethodDecl *getterMethod,
2381 ObjCMethodDecl *setterMethod) {
2382 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2383 getterMethod, setterMethod);
2384 }
2385
2386 /// \brief Build a new Objective-C dictionary literal.
2387 ///
2388 /// By default, performs semantic analysis to build the new expression.
2389 /// Subclasses may override this routine to provide different behavior.
2390 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2391 ObjCDictionaryElement *Elements,
2392 unsigned NumElements) {
2393 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2394 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002395
James Dennett2a4d13c2012-06-15 07:13:21 +00002396 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002397 ///
2398 /// By default, performs semantic analysis to build the new expression.
2399 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002400 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002401 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002402 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00002403 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002404 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002405 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002406
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002407 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002408 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
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) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002415 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2416 ReceiverTypeInfo->getType(),
2417 /*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
2422 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002423 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002424 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002425 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002426 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002427 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002428 MultiExprArg Args,
2429 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002430 return SemaRef.BuildInstanceMessage(Receiver,
2431 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002432 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002433 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002434 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002435 }
2436
Douglas Gregord51d90d2010-04-26 20:11:03 +00002437 /// \brief Build a new Objective-C ivar reference expression.
2438 ///
2439 /// By default, performs semantic analysis to build the new expression.
2440 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002441 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002442 SourceLocation IvarLoc,
2443 bool IsArrow, bool IsFreeIvar) {
2444 // FIXME: We lose track of the IsFreeIvar bit.
2445 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002446 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002447 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2448 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002449 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002450 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00002451 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00002452 false);
John Wiegley01296292011-04-08 18:41:53 +00002453 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002454 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002455
Douglas Gregord51d90d2010-04-26 20:11:03 +00002456 if (Result.get())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002457 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002458
John Wiegley01296292011-04-08 18:41:53 +00002459 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002460 /*FIXME:*/IvarLoc, IsArrow,
2461 SS, SourceLocation(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00002462 /*FirstQualifierInScope=*/0,
Chad Rosier1dcde962012-08-08 18:46:20 +00002463 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002464 /*TemplateArgs=*/0);
2465 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002466
2467 /// \brief Build a new Objective-C property reference expression.
2468 ///
2469 /// By default, performs semantic analysis to build the new expression.
2470 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002471 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002472 ObjCPropertyDecl *Property,
2473 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002474 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002475 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregor9faee212010-04-26 20:47:02 +00002476 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2477 Sema::LookupMemberName);
2478 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002479 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002480 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002481 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002482 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002483 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002484
Douglas Gregor9faee212010-04-26 20:47:02 +00002485 if (Result.get())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002486 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002487
John Wiegley01296292011-04-08 18:41:53 +00002488 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Chad Rosier1dcde962012-08-08 18:46:20 +00002489 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002490 SS, SourceLocation(),
Douglas Gregor9faee212010-04-26 20:47:02 +00002491 /*FirstQualifierInScope=*/0,
Chad Rosier1dcde962012-08-08 18:46:20 +00002492 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002493 /*TemplateArgs=*/0);
2494 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002495
John McCallb7bd14f2010-12-02 01:19:52 +00002496 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002497 ///
2498 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002499 /// Subclasses may override this routine to provide different behavior.
2500 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2501 ObjCMethodDecl *Getter,
2502 ObjCMethodDecl *Setter,
2503 SourceLocation PropertyLoc) {
2504 // Since these expressions can only be value-dependent, we do not
2505 // need to perform semantic analysis again.
2506 return Owned(
2507 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2508 VK_LValue, OK_ObjCProperty,
2509 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002510 }
2511
Douglas Gregord51d90d2010-04-26 20:11:03 +00002512 /// \brief Build a new Objective-C "isa" expression.
2513 ///
2514 /// By default, performs semantic analysis to build the new expression.
2515 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002516 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002517 SourceLocation OpLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002518 bool IsArrow) {
2519 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002520 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002521 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2522 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002523 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002524 OpLoc,
John McCall48871652010-08-21 09:40:31 +00002525 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002526 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002527 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002528
Douglas Gregord51d90d2010-04-26 20:11:03 +00002529 if (Result.get())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002530 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002531
John Wiegley01296292011-04-08 18:41:53 +00002532 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002533 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002534 SS, SourceLocation(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00002535 /*FirstQualifierInScope=*/0,
Chad Rosier1dcde962012-08-08 18:46:20 +00002536 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002537 /*TemplateArgs=*/0);
2538 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002539
Douglas Gregora16548e2009-08-11 05:31:07 +00002540 /// \brief Build a new shuffle vector expression.
2541 ///
2542 /// By default, performs semantic analysis to build the new expression.
2543 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002544 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002545 MultiExprArg SubExprs,
2546 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002547 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002548 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002549 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2550 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2551 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002552 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002553
Douglas Gregora16548e2009-08-11 05:31:07 +00002554 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002555 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002556 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2557 SemaRef.Context.BuiltinFnTy,
2558 VK_RValue, BuiltinLoc);
2559 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2560 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
2561 CK_BuiltinFnToFnPtr).take();
Mike Stump11289f42009-09-09 15:08:12 +00002562
2563 // Build the CallExpr
Alp Toker314cc812014-01-25 16:55:45 +00002564 ExprResult TheCall = SemaRef.Owned(new (SemaRef.Context) CallExpr(
2565 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
2566 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002567
Douglas Gregora16548e2009-08-11 05:31:07 +00002568 // Type-check the __builtin_shufflevector expression.
John Wiegley01296292011-04-08 18:41:53 +00002569 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002570 }
John McCall31f82722010-11-12 08:19:04 +00002571
Hal Finkelc4d7c822013-09-18 03:29:45 +00002572 /// \brief Build a new convert vector expression.
2573 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2574 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2575 SourceLocation RParenLoc) {
2576 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2577 BuiltinLoc, RParenLoc);
2578 }
2579
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002580 /// \brief Build a new template argument pack expansion.
2581 ///
2582 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002583 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002584 /// different behavior.
2585 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002586 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002587 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002588 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002589 case TemplateArgument::Expression: {
2590 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002591 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2592 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002593 if (Result.isInvalid())
2594 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002595
Douglas Gregor98318c22011-01-03 21:37:45 +00002596 return TemplateArgumentLoc(Result.get(), Result.get());
2597 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002598
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002599 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002600 return TemplateArgumentLoc(TemplateArgument(
2601 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002602 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002603 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002604 Pattern.getTemplateNameLoc(),
2605 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002606
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002607 case TemplateArgument::Null:
2608 case TemplateArgument::Integral:
2609 case TemplateArgument::Declaration:
2610 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002611 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002612 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002613 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002614
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002615 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002616 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002617 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002618 EllipsisLoc,
2619 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002620 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2621 Expansion);
2622 break;
2623 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002624
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002625 return TemplateArgumentLoc();
2626 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002627
Douglas Gregor968f23a2011-01-03 19:31:53 +00002628 /// \brief Build a new expression pack expansion.
2629 ///
2630 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002631 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002632 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002633 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002634 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002635 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002636 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002637
2638 /// \brief Build a new atomic operation expression.
2639 ///
2640 /// By default, performs semantic analysis to build the new expression.
2641 /// Subclasses may override this routine to provide different behavior.
2642 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2643 MultiExprArg SubExprs,
2644 QualType RetTy,
2645 AtomicExpr::AtomicOp Op,
2646 SourceLocation RParenLoc) {
2647 // Just create the expression; there is not any interesting semantic
2648 // analysis here because we can't actually build an AtomicExpr until
2649 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00002650 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002651 RParenLoc);
2652 }
2653
John McCall31f82722010-11-12 08:19:04 +00002654private:
Douglas Gregor14454802011-02-25 02:25:35 +00002655 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2656 QualType ObjectType,
2657 NamedDecl *FirstQualifierInScope,
2658 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002659
2660 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2661 QualType ObjectType,
2662 NamedDecl *FirstQualifierInScope,
2663 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00002664
2665 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
2666 NamedDecl *FirstQualifierInScope,
2667 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002668};
Douglas Gregora16548e2009-08-11 05:31:07 +00002669
Douglas Gregorebe10102009-08-20 07:17:43 +00002670template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002671StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002672 if (!S)
2673 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002674
Douglas Gregorebe10102009-08-20 07:17:43 +00002675 switch (S->getStmtClass()) {
2676 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002677
Douglas Gregorebe10102009-08-20 07:17:43 +00002678 // Transform individual statement nodes
2679#define STMT(Node, Parent) \
2680 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002681#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002682#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002683#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002684
Douglas Gregorebe10102009-08-20 07:17:43 +00002685 // Transform expressions by calling TransformExpr.
2686#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002687#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002688#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002689#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002690 {
John McCalldadc5752010-08-24 06:29:42 +00002691 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002692 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002693 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002694
Richard Smith945f8d32013-01-14 22:39:08 +00002695 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00002696 }
Mike Stump11289f42009-09-09 15:08:12 +00002697 }
2698
John McCallc3007a22010-10-26 07:05:15 +00002699 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002700}
Mike Stump11289f42009-09-09 15:08:12 +00002701
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002702template<typename Derived>
2703OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2704 if (!S)
2705 return S;
2706
2707 switch (S->getClauseKind()) {
2708 default: break;
2709 // Transform individual clause nodes
2710#define OPENMP_CLAUSE(Name, Class) \
2711 case OMPC_ ## Name : \
2712 return getDerived().Transform ## Class(cast<Class>(S));
2713#include "clang/Basic/OpenMPKinds.def"
2714 }
2715
2716 return S;
2717}
2718
Mike Stump11289f42009-09-09 15:08:12 +00002719
Douglas Gregore922c772009-08-04 22:27:00 +00002720template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002721ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002722 if (!E)
2723 return SemaRef.Owned(E);
2724
2725 switch (E->getStmtClass()) {
2726 case Stmt::NoStmtClass: break;
2727#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002728#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002729#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002730 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002731#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002732 }
2733
John McCallc3007a22010-10-26 07:05:15 +00002734 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002735}
2736
2737template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00002738ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2739 bool CXXDirectInit) {
2740 // Initializers are instantiated like expressions, except that various outer
2741 // layers are stripped.
2742 if (!Init)
2743 return SemaRef.Owned(Init);
2744
2745 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2746 Init = ExprTemp->getSubExpr();
2747
Richard Smithe6ca4752013-05-30 22:40:16 +00002748 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2749 Init = MTE->GetTemporaryExpr();
2750
Richard Smithd59b8322012-12-19 01:39:02 +00002751 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2752 Init = Binder->getSubExpr();
2753
2754 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2755 Init = ICE->getSubExprAsWritten();
2756
Richard Smithcc1b96d2013-06-12 22:31:48 +00002757 if (CXXStdInitializerListExpr *ILE =
2758 dyn_cast<CXXStdInitializerListExpr>(Init))
2759 return TransformInitializer(ILE->getSubExpr(), CXXDirectInit);
2760
Richard Smith38a549b2012-12-21 08:13:35 +00002761 // If this is not a direct-initializer, we only need to reconstruct
2762 // InitListExprs. Other forms of copy-initialization will be a no-op if
2763 // the initializer is already the right type.
2764 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2765 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2766 return getDerived().TransformExpr(Init);
2767
2768 // Revert value-initialization back to empty parens.
2769 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2770 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002771 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002772 Parens.getEnd());
2773 }
2774
2775 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2776 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002777 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002778 SourceLocation());
2779
2780 // Revert initialization by constructor back to a parenthesized or braced list
2781 // of expressions. Any other form of initializer can just be reused directly.
2782 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00002783 return getDerived().TransformExpr(Init);
2784
2785 SmallVector<Expr*, 8> NewArgs;
2786 bool ArgChanged = false;
2787 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2788 /*IsCall*/true, NewArgs, &ArgChanged))
2789 return ExprError();
2790
2791 // If this was list initialization, revert to list form.
2792 if (Construct->isListInitialization())
2793 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2794 Construct->getLocEnd(),
2795 Construct->getType());
2796
Richard Smithd59b8322012-12-19 01:39:02 +00002797 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00002798 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smithd59b8322012-12-19 01:39:02 +00002799 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2800 Parens.getEnd());
2801}
2802
2803template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00002804bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2805 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002806 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00002807 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002808 bool *ArgChanged) {
2809 for (unsigned I = 0; I != NumInputs; ++I) {
2810 // If requested, drop call arguments that need to be dropped.
2811 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2812 if (ArgChanged)
2813 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002814
Douglas Gregora3efea12011-01-03 19:04:46 +00002815 break;
2816 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002817
Douglas Gregor968f23a2011-01-03 19:31:53 +00002818 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2819 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00002820
Chris Lattner01cf8db2011-07-20 06:58:45 +00002821 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002822 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2823 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00002824
Douglas Gregor968f23a2011-01-03 19:31:53 +00002825 // Determine whether the set of unexpanded parameter packs can and should
2826 // be expanded.
2827 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002828 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00002829 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2830 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002831 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2832 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00002833 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002834 Expand, RetainExpansion,
2835 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002836 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002837
Douglas Gregor968f23a2011-01-03 19:31:53 +00002838 if (!Expand) {
2839 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00002840 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00002841 // expansion.
2842 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2843 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2844 if (OutPattern.isInvalid())
2845 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002846
2847 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002848 Expansion->getEllipsisLoc(),
2849 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002850 if (Out.isInvalid())
2851 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002852
Douglas Gregor968f23a2011-01-03 19:31:53 +00002853 if (ArgChanged)
2854 *ArgChanged = true;
2855 Outputs.push_back(Out.get());
2856 continue;
2857 }
John McCall542e7c62011-07-06 07:30:07 +00002858
2859 // Record right away that the argument was changed. This needs
2860 // to happen even if the array expands to nothing.
2861 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002862
Douglas Gregor968f23a2011-01-03 19:31:53 +00002863 // The transform has determined that we should perform an elementwise
2864 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002865 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002866 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2867 ExprResult Out = getDerived().TransformExpr(Pattern);
2868 if (Out.isInvalid())
2869 return true;
2870
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002871 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002872 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2873 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002874 if (Out.isInvalid())
2875 return true;
2876 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002877
Douglas Gregor968f23a2011-01-03 19:31:53 +00002878 Outputs.push_back(Out.get());
2879 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002880
Douglas Gregor968f23a2011-01-03 19:31:53 +00002881 continue;
2882 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002883
Richard Smithd59b8322012-12-19 01:39:02 +00002884 ExprResult Result =
2885 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
2886 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00002887 if (Result.isInvalid())
2888 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002889
Douglas Gregora3efea12011-01-03 19:04:46 +00002890 if (Result.get() != Inputs[I] && ArgChanged)
2891 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002892
2893 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00002894 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002895
Douglas Gregora3efea12011-01-03 19:04:46 +00002896 return false;
2897}
2898
2899template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00002900NestedNameSpecifierLoc
2901TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2902 NestedNameSpecifierLoc NNS,
2903 QualType ObjectType,
2904 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00002905 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00002906 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00002907 Qualifier = Qualifier.getPrefix())
2908 Qualifiers.push_back(Qualifier);
2909
2910 CXXScopeSpec SS;
2911 while (!Qualifiers.empty()) {
2912 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2913 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00002914
Douglas Gregor14454802011-02-25 02:25:35 +00002915 switch (QNNS->getKind()) {
2916 case NestedNameSpecifier::Identifier:
Chad Rosier1dcde962012-08-08 18:46:20 +00002917 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregor14454802011-02-25 02:25:35 +00002918 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00002919 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00002920 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00002921 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00002922 FirstQualifierInScope, false))
2923 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002924
Douglas Gregor14454802011-02-25 02:25:35 +00002925 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00002926
Douglas Gregor14454802011-02-25 02:25:35 +00002927 case NestedNameSpecifier::Namespace: {
2928 NamespaceDecl *NS
2929 = cast_or_null<NamespaceDecl>(
2930 getDerived().TransformDecl(
2931 Q.getLocalBeginLoc(),
2932 QNNS->getAsNamespace()));
2933 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2934 break;
2935 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002936
Douglas Gregor14454802011-02-25 02:25:35 +00002937 case NestedNameSpecifier::NamespaceAlias: {
2938 NamespaceAliasDecl *Alias
2939 = cast_or_null<NamespaceAliasDecl>(
2940 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2941 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00002942 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00002943 Q.getLocalEndLoc());
2944 break;
2945 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002946
Douglas Gregor14454802011-02-25 02:25:35 +00002947 case NestedNameSpecifier::Global:
2948 // There is no meaningful transformation that one could perform on the
2949 // global scope.
2950 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2951 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00002952
Douglas Gregor14454802011-02-25 02:25:35 +00002953 case NestedNameSpecifier::TypeSpecWithTemplate:
2954 case NestedNameSpecifier::TypeSpec: {
2955 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2956 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00002957
Douglas Gregor14454802011-02-25 02:25:35 +00002958 if (!TL)
2959 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002960
Douglas Gregor14454802011-02-25 02:25:35 +00002961 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00002962 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00002963 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002964 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00002965 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00002966 if (TL.getType()->isEnumeralType())
2967 SemaRef.Diag(TL.getBeginLoc(),
2968 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00002969 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2970 Q.getLocalEndLoc());
2971 break;
2972 }
Richard Trieude756fb2011-05-07 01:36:37 +00002973 // If the nested-name-specifier is an invalid type def, don't emit an
2974 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00002975 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
2976 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002977 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00002978 << TL.getType() << SS.getRange();
2979 }
Douglas Gregor14454802011-02-25 02:25:35 +00002980 return NestedNameSpecifierLoc();
2981 }
Douglas Gregore16af532011-02-28 18:50:33 +00002982 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002983
Douglas Gregore16af532011-02-28 18:50:33 +00002984 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregor14454802011-02-25 02:25:35 +00002985 FirstQualifierInScope = 0;
Douglas Gregore16af532011-02-28 18:50:33 +00002986 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00002987 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002988
Douglas Gregor14454802011-02-25 02:25:35 +00002989 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00002990 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00002991 !getDerived().AlwaysRebuild())
2992 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00002993
2994 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00002995 // nested-name-specifier, do so.
2996 if (SS.location_size() == NNS.getDataLength() &&
2997 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2998 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2999
3000 // Allocate new nested-name-specifier location information.
3001 return SS.getWithLocInContext(SemaRef.Context);
3002}
3003
3004template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003005DeclarationNameInfo
3006TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003007::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003008 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003009 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003010 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003011
3012 switch (Name.getNameKind()) {
3013 case DeclarationName::Identifier:
3014 case DeclarationName::ObjCZeroArgSelector:
3015 case DeclarationName::ObjCOneArgSelector:
3016 case DeclarationName::ObjCMultiArgSelector:
3017 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003018 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003019 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003020 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003021
Douglas Gregorf816bd72009-09-03 22:13:48 +00003022 case DeclarationName::CXXConstructorName:
3023 case DeclarationName::CXXDestructorName:
3024 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003025 TypeSourceInfo *NewTInfo;
3026 CanQualType NewCanTy;
3027 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003028 NewTInfo = getDerived().TransformType(OldTInfo);
3029 if (!NewTInfo)
3030 return DeclarationNameInfo();
3031 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003032 }
3033 else {
3034 NewTInfo = 0;
3035 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003036 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003037 if (NewT.isNull())
3038 return DeclarationNameInfo();
3039 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3040 }
Mike Stump11289f42009-09-09 15:08:12 +00003041
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003042 DeclarationName NewName
3043 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3044 NewCanTy);
3045 DeclarationNameInfo NewNameInfo(NameInfo);
3046 NewNameInfo.setName(NewName);
3047 NewNameInfo.setNamedTypeInfo(NewTInfo);
3048 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003049 }
Mike Stump11289f42009-09-09 15:08:12 +00003050 }
3051
David Blaikie83d382b2011-09-23 05:06:16 +00003052 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003053}
3054
3055template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003056TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003057TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3058 TemplateName Name,
3059 SourceLocation NameLoc,
3060 QualType ObjectType,
3061 NamedDecl *FirstQualifierInScope) {
3062 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3063 TemplateDecl *Template = QTN->getTemplateDecl();
3064 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003065
Douglas Gregor9db53502011-03-02 18:07:45 +00003066 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003067 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003068 Template));
3069 if (!TransTemplate)
3070 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003071
Douglas Gregor9db53502011-03-02 18:07:45 +00003072 if (!getDerived().AlwaysRebuild() &&
3073 SS.getScopeRep() == QTN->getQualifier() &&
3074 TransTemplate == Template)
3075 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003076
Douglas Gregor9db53502011-03-02 18:07:45 +00003077 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3078 TransTemplate);
3079 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003080
Douglas Gregor9db53502011-03-02 18:07:45 +00003081 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3082 if (SS.getScopeRep()) {
3083 // These apply to the scope specifier, not the template.
3084 ObjectType = QualType();
3085 FirstQualifierInScope = 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00003086 }
3087
Douglas Gregor9db53502011-03-02 18:07:45 +00003088 if (!getDerived().AlwaysRebuild() &&
3089 SS.getScopeRep() == DTN->getQualifier() &&
3090 ObjectType.isNull())
3091 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003092
Douglas Gregor9db53502011-03-02 18:07:45 +00003093 if (DTN->isIdentifier()) {
3094 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003095 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003096 NameLoc,
3097 ObjectType,
3098 FirstQualifierInScope);
3099 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003100
Douglas Gregor9db53502011-03-02 18:07:45 +00003101 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3102 ObjectType);
3103 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003104
Douglas Gregor9db53502011-03-02 18:07:45 +00003105 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3106 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003107 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003108 Template));
3109 if (!TransTemplate)
3110 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003111
Douglas Gregor9db53502011-03-02 18:07:45 +00003112 if (!getDerived().AlwaysRebuild() &&
3113 TransTemplate == Template)
3114 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003115
Douglas Gregor9db53502011-03-02 18:07:45 +00003116 return TemplateName(TransTemplate);
3117 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003118
Douglas Gregor9db53502011-03-02 18:07:45 +00003119 if (SubstTemplateTemplateParmPackStorage *SubstPack
3120 = Name.getAsSubstTemplateTemplateParmPack()) {
3121 TemplateTemplateParmDecl *TransParam
3122 = cast_or_null<TemplateTemplateParmDecl>(
3123 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3124 if (!TransParam)
3125 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003126
Douglas Gregor9db53502011-03-02 18:07:45 +00003127 if (!getDerived().AlwaysRebuild() &&
3128 TransParam == SubstPack->getParameterPack())
3129 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003130
3131 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003132 SubstPack->getArgumentPack());
3133 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003134
Douglas Gregor9db53502011-03-02 18:07:45 +00003135 // These should be getting filtered out before they reach the AST.
3136 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003137}
3138
3139template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003140void TreeTransform<Derived>::InventTemplateArgumentLoc(
3141 const TemplateArgument &Arg,
3142 TemplateArgumentLoc &Output) {
3143 SourceLocation Loc = getDerived().getBaseLocation();
3144 switch (Arg.getKind()) {
3145 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003146 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003147 break;
3148
3149 case TemplateArgument::Type:
3150 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003151 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003152
John McCall0ad16662009-10-29 08:12:44 +00003153 break;
3154
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003155 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003156 case TemplateArgument::TemplateExpansion: {
3157 NestedNameSpecifierLocBuilder Builder;
3158 TemplateName Template = Arg.getAsTemplate();
3159 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3160 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3161 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3162 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003163
Douglas Gregor9d802122011-03-02 17:09:35 +00003164 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003165 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003166 Builder.getWithLocInContext(SemaRef.Context),
3167 Loc);
3168 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003169 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003170 Builder.getWithLocInContext(SemaRef.Context),
3171 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003172
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003173 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003174 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003175
John McCall0ad16662009-10-29 08:12:44 +00003176 case TemplateArgument::Expression:
3177 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3178 break;
3179
3180 case TemplateArgument::Declaration:
3181 case TemplateArgument::Integral:
3182 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003183 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003184 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003185 break;
3186 }
3187}
3188
3189template<typename Derived>
3190bool TreeTransform<Derived>::TransformTemplateArgument(
3191 const TemplateArgumentLoc &Input,
3192 TemplateArgumentLoc &Output) {
3193 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003194 switch (Arg.getKind()) {
3195 case TemplateArgument::Null:
3196 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003197 case TemplateArgument::Pack:
3198 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003199 case TemplateArgument::NullPtr:
3200 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003201
Douglas Gregore922c772009-08-04 22:27:00 +00003202 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003203 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00003204 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00003205 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003206
3207 DI = getDerived().TransformType(DI);
3208 if (!DI) return true;
3209
3210 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3211 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003212 }
Mike Stump11289f42009-09-09 15:08:12 +00003213
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003214 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003215 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3216 if (QualifierLoc) {
3217 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3218 if (!QualifierLoc)
3219 return true;
3220 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003221
Douglas Gregordf846d12011-03-02 18:46:51 +00003222 CXXScopeSpec SS;
3223 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003224 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003225 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3226 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003227 if (Template.isNull())
3228 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003229
Douglas Gregor9d802122011-03-02 17:09:35 +00003230 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003231 Input.getTemplateNameLoc());
3232 return false;
3233 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003234
3235 case TemplateArgument::TemplateExpansion:
3236 llvm_unreachable("Caller should expand pack expansions");
3237
Douglas Gregore922c772009-08-04 22:27:00 +00003238 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003239 // Template argument expressions are constant expressions.
Mike Stump11289f42009-09-09 15:08:12 +00003240 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smith764d2fe2011-12-20 02:08:33 +00003241 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003242
John McCall0ad16662009-10-29 08:12:44 +00003243 Expr *InputExpr = Input.getSourceExpression();
3244 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3245
Chris Lattnercdb591a2011-04-25 20:37:58 +00003246 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003247 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003248 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00003249 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00003250 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003251 }
Douglas Gregore922c772009-08-04 22:27:00 +00003252 }
Mike Stump11289f42009-09-09 15:08:12 +00003253
Douglas Gregore922c772009-08-04 22:27:00 +00003254 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003255 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003256}
3257
Douglas Gregorfe921a72010-12-20 23:36:19 +00003258/// \brief Iterator adaptor that invents template argument location information
3259/// for each of the template arguments in its underlying iterator.
3260template<typename Derived, typename InputIterator>
3261class TemplateArgumentLocInventIterator {
3262 TreeTransform<Derived> &Self;
3263 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003264
Douglas Gregorfe921a72010-12-20 23:36:19 +00003265public:
3266 typedef TemplateArgumentLoc value_type;
3267 typedef TemplateArgumentLoc reference;
3268 typedef typename std::iterator_traits<InputIterator>::difference_type
3269 difference_type;
3270 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003271
Douglas Gregorfe921a72010-12-20 23:36:19 +00003272 class pointer {
3273 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003274
Douglas Gregorfe921a72010-12-20 23:36:19 +00003275 public:
3276 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003277
Douglas Gregorfe921a72010-12-20 23:36:19 +00003278 const TemplateArgumentLoc *operator->() const { return &Arg; }
3279 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003280
Douglas Gregorfe921a72010-12-20 23:36:19 +00003281 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003282
Douglas Gregorfe921a72010-12-20 23:36:19 +00003283 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3284 InputIterator Iter)
3285 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003286
Douglas Gregorfe921a72010-12-20 23:36:19 +00003287 TemplateArgumentLocInventIterator &operator++() {
3288 ++Iter;
3289 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003290 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003291
Douglas Gregorfe921a72010-12-20 23:36:19 +00003292 TemplateArgumentLocInventIterator operator++(int) {
3293 TemplateArgumentLocInventIterator Old(*this);
3294 ++(*this);
3295 return Old;
3296 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003297
Douglas Gregorfe921a72010-12-20 23:36:19 +00003298 reference operator*() const {
3299 TemplateArgumentLoc Result;
3300 Self.InventTemplateArgumentLoc(*Iter, Result);
3301 return Result;
3302 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003303
Douglas Gregorfe921a72010-12-20 23:36:19 +00003304 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003305
Douglas Gregorfe921a72010-12-20 23:36:19 +00003306 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3307 const TemplateArgumentLocInventIterator &Y) {
3308 return X.Iter == Y.Iter;
3309 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003310
Douglas Gregorfe921a72010-12-20 23:36:19 +00003311 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3312 const TemplateArgumentLocInventIterator &Y) {
3313 return X.Iter != Y.Iter;
3314 }
3315};
Chad Rosier1dcde962012-08-08 18:46:20 +00003316
Douglas Gregor42cafa82010-12-20 17:42:22 +00003317template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003318template<typename InputIterator>
3319bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3320 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00003321 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003322 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003323 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003324 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003325
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003326 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3327 // Unpack argument packs, which we translate them into separate
3328 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003329 // FIXME: We could do much better if we could guarantee that the
3330 // TemplateArgumentLocInfo for the pack expansion would be usable for
3331 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003332 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003333 TemplateArgument::pack_iterator>
3334 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003335 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003336 In.getArgument().pack_begin()),
3337 PackLocIterator(*this,
3338 In.getArgument().pack_end()),
3339 Outputs))
3340 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003341
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003342 continue;
3343 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003344
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003345 if (In.getArgument().isPackExpansion()) {
3346 // We have a pack expansion, for which we will be substituting into
3347 // the pattern.
3348 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003349 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003350 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003351 = getSema().getTemplateArgumentPackExpansionPattern(
3352 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003353
Chris Lattner01cf8db2011-07-20 06:58:45 +00003354 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003355 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3356 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003357
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003358 // Determine whether the set of unexpanded parameter packs can and should
3359 // be expanded.
3360 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003361 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003362 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003363 if (getDerived().TryExpandParameterPacks(Ellipsis,
3364 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003365 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003366 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003367 RetainExpansion,
3368 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003369 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003370
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003371 if (!Expand) {
3372 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003373 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003374 // expansion.
3375 TemplateArgumentLoc OutPattern;
3376 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3377 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3378 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003379
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003380 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3381 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003382 if (Out.getArgument().isNull())
3383 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003384
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003385 Outputs.addArgument(Out);
3386 continue;
3387 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003388
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003389 // The transform has determined that we should perform an elementwise
3390 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003391 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003392 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3393
3394 if (getDerived().TransformTemplateArgument(Pattern, Out))
3395 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003396
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003397 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003398 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3399 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003400 if (Out.getArgument().isNull())
3401 return true;
3402 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003403
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003404 Outputs.addArgument(Out);
3405 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003406
Douglas Gregor48d24112011-01-10 20:53:55 +00003407 // If we're supposed to retain a pack expansion, do so by temporarily
3408 // forgetting the partially-substituted parameter pack.
3409 if (RetainExpansion) {
3410 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003411
Douglas Gregor48d24112011-01-10 20:53:55 +00003412 if (getDerived().TransformTemplateArgument(Pattern, Out))
3413 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003414
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003415 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3416 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003417 if (Out.getArgument().isNull())
3418 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003419
Douglas Gregor48d24112011-01-10 20:53:55 +00003420 Outputs.addArgument(Out);
3421 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003422
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003423 continue;
3424 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003425
3426 // The simple case:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003427 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003428 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003429
Douglas Gregor42cafa82010-12-20 17:42:22 +00003430 Outputs.addArgument(Out);
3431 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003432
Douglas Gregor42cafa82010-12-20 17:42:22 +00003433 return false;
3434
3435}
3436
Douglas Gregord6ff3322009-08-04 16:50:30 +00003437//===----------------------------------------------------------------------===//
3438// Type transformation
3439//===----------------------------------------------------------------------===//
3440
3441template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003442QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003443 if (getDerived().AlreadyTransformed(T))
3444 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003445
John McCall550e0c22009-10-21 00:40:46 +00003446 // Temporary workaround. All of these transformations should
3447 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003448 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3449 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003450
John McCall31f82722010-11-12 08:19:04 +00003451 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003452
John McCall550e0c22009-10-21 00:40:46 +00003453 if (!NewDI)
3454 return QualType();
3455
3456 return NewDI->getType();
3457}
3458
3459template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003460TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003461 // Refine the base location to the type's location.
3462 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3463 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003464 if (getDerived().AlreadyTransformed(DI->getType()))
3465 return DI;
3466
3467 TypeLocBuilder TLB;
3468
3469 TypeLoc TL = DI->getTypeLoc();
3470 TLB.reserve(TL.getFullDataSize());
3471
John McCall31f82722010-11-12 08:19:04 +00003472 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003473 if (Result.isNull())
3474 return 0;
3475
John McCallbcd03502009-12-07 02:54:59 +00003476 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003477}
3478
3479template<typename Derived>
3480QualType
John McCall31f82722010-11-12 08:19:04 +00003481TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003482 switch (T.getTypeLocClass()) {
3483#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003484#define TYPELOC(CLASS, PARENT) \
3485 case TypeLoc::CLASS: \
3486 return getDerived().Transform##CLASS##Type(TLB, \
3487 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003488#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003489 }
Mike Stump11289f42009-09-09 15:08:12 +00003490
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003491 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003492}
3493
3494/// FIXME: By default, this routine adds type qualifiers only to types
3495/// that can have qualifiers, and silently suppresses those qualifiers
3496/// that are not permitted (e.g., qualifiers on reference or function
3497/// types). This is the right thing for template instantiation, but
3498/// probably not for other clients.
3499template<typename Derived>
3500QualType
3501TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003502 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003503 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003504
John McCall31f82722010-11-12 08:19:04 +00003505 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003506 if (Result.isNull())
3507 return QualType();
3508
3509 // Silently suppress qualifiers if the result type can't be qualified.
3510 // FIXME: this is the right thing for template instantiation, but
3511 // probably not for other clients.
3512 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003513 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003514
John McCall31168b02011-06-15 23:02:42 +00003515 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003516 // resulting type.
3517 if (Quals.hasObjCLifetime()) {
3518 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3519 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003520 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003521 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003522 // A lifetime qualifier applied to a substituted template parameter
3523 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003524 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003525 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003526 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3527 QualType Replacement = SubstTypeParam->getReplacementType();
3528 Qualifiers Qs = Replacement.getQualifiers();
3529 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003530 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003531 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3532 Qs);
3533 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003534 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003535 Replacement);
3536 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003537 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3538 // 'auto' types behave the same way as template parameters.
3539 QualType Deduced = AutoTy->getDeducedType();
3540 Qualifiers Qs = Deduced.getQualifiers();
3541 Qs.removeObjCLifetime();
3542 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3543 Qs);
Faisal Vali2b391ab2013-09-26 19:54:12 +00003544 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3545 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003546 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003547 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003548 // Otherwise, complain about the addition of a qualifier to an
3549 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003550 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003551 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003552 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003553
Douglas Gregore46db902011-06-17 22:11:49 +00003554 Quals.removeObjCLifetime();
3555 }
3556 }
3557 }
John McCallcb0f89a2010-06-05 06:41:15 +00003558 if (!Quals.empty()) {
3559 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003560 // BuildQualifiedType might not add qualifiers if they are invalid.
3561 if (Result.hasLocalQualifiers())
3562 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003563 // No location information to preserve.
3564 }
John McCall550e0c22009-10-21 00:40:46 +00003565
3566 return Result;
3567}
3568
Douglas Gregor14454802011-02-25 02:25:35 +00003569template<typename Derived>
3570TypeLoc
3571TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3572 QualType ObjectType,
3573 NamedDecl *UnqualLookup,
3574 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003575 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00003576 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00003577
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003578 TypeSourceInfo *TSI =
3579 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3580 if (TSI)
3581 return TSI->getTypeLoc();
3582 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00003583}
3584
Douglas Gregor579c15f2011-03-02 18:32:08 +00003585template<typename Derived>
3586TypeSourceInfo *
3587TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3588 QualType ObjectType,
3589 NamedDecl *UnqualLookup,
3590 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003591 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00003592 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00003593
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003594 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
3595 UnqualLookup, SS);
3596}
3597
3598template <typename Derived>
3599TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
3600 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
3601 CXXScopeSpec &SS) {
3602 QualType T = TL.getType();
3603 assert(!getDerived().AlreadyTransformed(T));
3604
Douglas Gregor579c15f2011-03-02 18:32:08 +00003605 TypeLocBuilder TLB;
3606 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00003607
Douglas Gregor579c15f2011-03-02 18:32:08 +00003608 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003609 TemplateSpecializationTypeLoc SpecTL =
3610 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003611
Douglas Gregor579c15f2011-03-02 18:32:08 +00003612 TemplateName Template
3613 = getDerived().TransformTemplateName(SS,
3614 SpecTL.getTypePtr()->getTemplateName(),
3615 SpecTL.getTemplateNameLoc(),
3616 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00003617 if (Template.isNull())
Douglas Gregor579c15f2011-03-02 18:32:08 +00003618 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00003619
3620 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003621 Template);
3622 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003623 DependentTemplateSpecializationTypeLoc SpecTL =
3624 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003625
Douglas Gregor579c15f2011-03-02 18:32:08 +00003626 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00003627 = getDerived().RebuildTemplateName(SS,
3628 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00003629 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00003630 ObjectType, UnqualLookup);
3631 if (Template.isNull())
3632 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00003633
3634 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003635 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003636 Template,
3637 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003638 } else {
3639 // Nothing special needs to be done for these.
3640 Result = getDerived().TransformType(TLB, TL);
3641 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003642
3643 if (Result.isNull())
Douglas Gregor579c15f2011-03-02 18:32:08 +00003644 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00003645
Douglas Gregor579c15f2011-03-02 18:32:08 +00003646 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3647}
3648
John McCall550e0c22009-10-21 00:40:46 +00003649template <class TyLoc> static inline
3650QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3651 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3652 NewT.setNameLoc(T.getNameLoc());
3653 return T.getType();
3654}
3655
John McCall550e0c22009-10-21 00:40:46 +00003656template<typename Derived>
3657QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003658 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003659 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3660 NewT.setBuiltinLoc(T.getBuiltinLoc());
3661 if (T.needsExtraLocalData())
3662 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3663 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003664}
Mike Stump11289f42009-09-09 15:08:12 +00003665
Douglas Gregord6ff3322009-08-04 16:50:30 +00003666template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003667QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003668 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003669 // FIXME: recurse?
3670 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003671}
Mike Stump11289f42009-09-09 15:08:12 +00003672
Reid Kleckner0503a872013-12-05 01:23:43 +00003673template <typename Derived>
3674QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
3675 AdjustedTypeLoc TL) {
3676 // Adjustments applied during transformation are handled elsewhere.
3677 return getDerived().TransformType(TLB, TL.getOriginalLoc());
3678}
3679
Douglas Gregord6ff3322009-08-04 16:50:30 +00003680template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00003681QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3682 DecayedTypeLoc TL) {
3683 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3684 if (OriginalType.isNull())
3685 return QualType();
3686
3687 QualType Result = TL.getType();
3688 if (getDerived().AlwaysRebuild() ||
3689 OriginalType != TL.getOriginalLoc().getType())
3690 Result = SemaRef.Context.getDecayedType(OriginalType);
3691 TLB.push<DecayedTypeLoc>(Result);
3692 // Nothing to set for DecayedTypeLoc.
3693 return Result;
3694}
3695
3696template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003697QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003698 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003699 QualType PointeeType
3700 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003701 if (PointeeType.isNull())
3702 return QualType();
3703
3704 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003705 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003706 // A dependent pointer type 'T *' has is being transformed such
3707 // that an Objective-C class type is being replaced for 'T'. The
3708 // resulting pointer type is an ObjCObjectPointerType, not a
3709 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003710 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00003711
John McCall8b07ec22010-05-15 11:32:37 +00003712 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3713 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003714 return Result;
3715 }
John McCall31f82722010-11-12 08:19:04 +00003716
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003717 if (getDerived().AlwaysRebuild() ||
3718 PointeeType != TL.getPointeeLoc().getType()) {
3719 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3720 if (Result.isNull())
3721 return QualType();
3722 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003723
John McCall31168b02011-06-15 23:02:42 +00003724 // Objective-C ARC can add lifetime qualifiers to the type that we're
3725 // pointing to.
3726 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00003727
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003728 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3729 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00003730 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003731}
Mike Stump11289f42009-09-09 15:08:12 +00003732
3733template<typename Derived>
3734QualType
John McCall550e0c22009-10-21 00:40:46 +00003735TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003736 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003737 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00003738 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3739 if (PointeeType.isNull())
3740 return QualType();
3741
3742 QualType Result = TL.getType();
3743 if (getDerived().AlwaysRebuild() ||
3744 PointeeType != TL.getPointeeLoc().getType()) {
3745 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003746 TL.getSigilLoc());
3747 if (Result.isNull())
3748 return QualType();
3749 }
3750
Douglas Gregor049211a2010-04-22 16:50:51 +00003751 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003752 NewT.setSigilLoc(TL.getSigilLoc());
3753 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003754}
3755
John McCall70dd5f62009-10-30 00:06:24 +00003756/// Transforms a reference type. Note that somewhat paradoxically we
3757/// don't care whether the type itself is an l-value type or an r-value
3758/// type; we only care if the type was *written* as an l-value type
3759/// or an r-value type.
3760template<typename Derived>
3761QualType
3762TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003763 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003764 const ReferenceType *T = TL.getTypePtr();
3765
3766 // Note that this works with the pointee-as-written.
3767 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3768 if (PointeeType.isNull())
3769 return QualType();
3770
3771 QualType Result = TL.getType();
3772 if (getDerived().AlwaysRebuild() ||
3773 PointeeType != T->getPointeeTypeAsWritten()) {
3774 Result = getDerived().RebuildReferenceType(PointeeType,
3775 T->isSpelledAsLValue(),
3776 TL.getSigilLoc());
3777 if (Result.isNull())
3778 return QualType();
3779 }
3780
John McCall31168b02011-06-15 23:02:42 +00003781 // Objective-C ARC can add lifetime qualifiers to the type that we're
3782 // referring to.
3783 TLB.TypeWasModifiedSafely(
3784 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3785
John McCall70dd5f62009-10-30 00:06:24 +00003786 // r-value references can be rebuilt as l-value references.
3787 ReferenceTypeLoc NewTL;
3788 if (isa<LValueReferenceType>(Result))
3789 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3790 else
3791 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3792 NewTL.setSigilLoc(TL.getSigilLoc());
3793
3794 return Result;
3795}
3796
Mike Stump11289f42009-09-09 15:08:12 +00003797template<typename Derived>
3798QualType
John McCall550e0c22009-10-21 00:40:46 +00003799TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003800 LValueReferenceTypeLoc TL) {
3801 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003802}
3803
Mike Stump11289f42009-09-09 15:08:12 +00003804template<typename Derived>
3805QualType
John McCall550e0c22009-10-21 00:40:46 +00003806TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003807 RValueReferenceTypeLoc TL) {
3808 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003809}
Mike Stump11289f42009-09-09 15:08:12 +00003810
Douglas Gregord6ff3322009-08-04 16:50:30 +00003811template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003812QualType
John McCall550e0c22009-10-21 00:40:46 +00003813TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003814 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003815 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003816 if (PointeeType.isNull())
3817 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003818
Abramo Bagnara509357842011-03-05 14:42:21 +00003819 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3820 TypeSourceInfo* NewClsTInfo = 0;
3821 if (OldClsTInfo) {
3822 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3823 if (!NewClsTInfo)
3824 return QualType();
3825 }
3826
3827 const MemberPointerType *T = TL.getTypePtr();
3828 QualType OldClsType = QualType(T->getClass(), 0);
3829 QualType NewClsType;
3830 if (NewClsTInfo)
3831 NewClsType = NewClsTInfo->getType();
3832 else {
3833 NewClsType = getDerived().TransformType(OldClsType);
3834 if (NewClsType.isNull())
3835 return QualType();
3836 }
Mike Stump11289f42009-09-09 15:08:12 +00003837
John McCall550e0c22009-10-21 00:40:46 +00003838 QualType Result = TL.getType();
3839 if (getDerived().AlwaysRebuild() ||
3840 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00003841 NewClsType != OldClsType) {
3842 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00003843 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003844 if (Result.isNull())
3845 return QualType();
3846 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003847
Reid Kleckner0503a872013-12-05 01:23:43 +00003848 // If we had to adjust the pointee type when building a member pointer, make
3849 // sure to push TypeLoc info for it.
3850 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
3851 if (MPT && PointeeType != MPT->getPointeeType()) {
3852 assert(isa<AdjustedType>(MPT->getPointeeType()));
3853 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
3854 }
3855
John McCall550e0c22009-10-21 00:40:46 +00003856 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3857 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00003858 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00003859
3860 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003861}
3862
Mike Stump11289f42009-09-09 15:08:12 +00003863template<typename Derived>
3864QualType
John McCall550e0c22009-10-21 00:40:46 +00003865TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003866 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003867 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003868 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003869 if (ElementType.isNull())
3870 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003871
John McCall550e0c22009-10-21 00:40:46 +00003872 QualType Result = TL.getType();
3873 if (getDerived().AlwaysRebuild() ||
3874 ElementType != T->getElementType()) {
3875 Result = getDerived().RebuildConstantArrayType(ElementType,
3876 T->getSizeModifier(),
3877 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003878 T->getIndexTypeCVRQualifiers(),
3879 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003880 if (Result.isNull())
3881 return QualType();
3882 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00003883
3884 // We might have either a ConstantArrayType or a VariableArrayType now:
3885 // a ConstantArrayType is allowed to have an element type which is a
3886 // VariableArrayType if the type is dependent. Fortunately, all array
3887 // types have the same location layout.
3888 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00003889 NewTL.setLBracketLoc(TL.getLBracketLoc());
3890 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003891
John McCall550e0c22009-10-21 00:40:46 +00003892 Expr *Size = TL.getSizeExpr();
3893 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003894 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3895 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00003896 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanc6237c62012-02-29 03:16:56 +00003897 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCall550e0c22009-10-21 00:40:46 +00003898 }
3899 NewTL.setSizeExpr(Size);
3900
3901 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003902}
Mike Stump11289f42009-09-09 15:08:12 +00003903
Douglas Gregord6ff3322009-08-04 16:50:30 +00003904template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003905QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003906 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003907 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003908 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003909 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003910 if (ElementType.isNull())
3911 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003912
John McCall550e0c22009-10-21 00:40:46 +00003913 QualType Result = TL.getType();
3914 if (getDerived().AlwaysRebuild() ||
3915 ElementType != T->getElementType()) {
3916 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003917 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003918 T->getIndexTypeCVRQualifiers(),
3919 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003920 if (Result.isNull())
3921 return QualType();
3922 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003923
John McCall550e0c22009-10-21 00:40:46 +00003924 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3925 NewTL.setLBracketLoc(TL.getLBracketLoc());
3926 NewTL.setRBracketLoc(TL.getRBracketLoc());
3927 NewTL.setSizeExpr(0);
3928
3929 return Result;
3930}
3931
3932template<typename Derived>
3933QualType
3934TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003935 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003936 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003937 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3938 if (ElementType.isNull())
3939 return QualType();
3940
John McCalldadc5752010-08-24 06:29:42 +00003941 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003942 = getDerived().TransformExpr(T->getSizeExpr());
3943 if (SizeResult.isInvalid())
3944 return QualType();
3945
John McCallb268a282010-08-23 23:25:46 +00003946 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003947
3948 QualType Result = TL.getType();
3949 if (getDerived().AlwaysRebuild() ||
3950 ElementType != T->getElementType() ||
3951 Size != T->getSizeExpr()) {
3952 Result = getDerived().RebuildVariableArrayType(ElementType,
3953 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003954 Size,
John McCall550e0c22009-10-21 00:40:46 +00003955 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003956 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003957 if (Result.isNull())
3958 return QualType();
3959 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003960
Serge Pavlov774c6d02014-02-06 03:49:11 +00003961 // We might have constant size array now, but fortunately it has the same
3962 // location layout.
3963 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00003964 NewTL.setLBracketLoc(TL.getLBracketLoc());
3965 NewTL.setRBracketLoc(TL.getRBracketLoc());
3966 NewTL.setSizeExpr(Size);
3967
3968 return Result;
3969}
3970
3971template<typename Derived>
3972QualType
3973TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003974 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003975 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003976 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3977 if (ElementType.isNull())
3978 return QualType();
3979
Richard Smith764d2fe2011-12-20 02:08:33 +00003980 // Array bounds are constant expressions.
3981 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3982 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00003983
John McCall33ddac02011-01-19 10:06:00 +00003984 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3985 Expr *origSize = TL.getSizeExpr();
3986 if (!origSize) origSize = T->getSizeExpr();
3987
3988 ExprResult sizeResult
3989 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003990 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00003991 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00003992 return QualType();
3993
John McCall33ddac02011-01-19 10:06:00 +00003994 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00003995
3996 QualType Result = TL.getType();
3997 if (getDerived().AlwaysRebuild() ||
3998 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00003999 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004000 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4001 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004002 size,
John McCall550e0c22009-10-21 00:40:46 +00004003 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004004 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004005 if (Result.isNull())
4006 return QualType();
4007 }
John McCall550e0c22009-10-21 00:40:46 +00004008
4009 // We might have any sort of array type now, but fortunately they
4010 // all have the same location layout.
4011 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4012 NewTL.setLBracketLoc(TL.getLBracketLoc());
4013 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004014 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004015
4016 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004017}
Mike Stump11289f42009-09-09 15:08:12 +00004018
4019template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004020QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004021 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004022 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004023 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004024
4025 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004026 QualType ElementType = getDerived().TransformType(T->getElementType());
4027 if (ElementType.isNull())
4028 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004029
Richard Smith764d2fe2011-12-20 02:08:33 +00004030 // Vector sizes are constant expressions.
4031 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4032 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004033
John McCalldadc5752010-08-24 06:29:42 +00004034 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004035 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004036 if (Size.isInvalid())
4037 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004038
John McCall550e0c22009-10-21 00:40:46 +00004039 QualType Result = TL.getType();
4040 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004041 ElementType != T->getElementType() ||
4042 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004043 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00004044 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004045 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004046 if (Result.isNull())
4047 return QualType();
4048 }
John McCall550e0c22009-10-21 00:40:46 +00004049
4050 // Result might be dependent or not.
4051 if (isa<DependentSizedExtVectorType>(Result)) {
4052 DependentSizedExtVectorTypeLoc NewTL
4053 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4054 NewTL.setNameLoc(TL.getNameLoc());
4055 } else {
4056 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4057 NewTL.setNameLoc(TL.getNameLoc());
4058 }
4059
4060 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004061}
Mike Stump11289f42009-09-09 15:08:12 +00004062
4063template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004064QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004065 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004066 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004067 QualType ElementType = getDerived().TransformType(T->getElementType());
4068 if (ElementType.isNull())
4069 return QualType();
4070
John McCall550e0c22009-10-21 00:40:46 +00004071 QualType Result = TL.getType();
4072 if (getDerived().AlwaysRebuild() ||
4073 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004074 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004075 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004076 if (Result.isNull())
4077 return QualType();
4078 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004079
John McCall550e0c22009-10-21 00:40:46 +00004080 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4081 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004082
John McCall550e0c22009-10-21 00:40:46 +00004083 return Result;
4084}
4085
4086template<typename Derived>
4087QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004088 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004089 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004090 QualType ElementType = getDerived().TransformType(T->getElementType());
4091 if (ElementType.isNull())
4092 return QualType();
4093
4094 QualType Result = TL.getType();
4095 if (getDerived().AlwaysRebuild() ||
4096 ElementType != T->getElementType()) {
4097 Result = getDerived().RebuildExtVectorType(ElementType,
4098 T->getNumElements(),
4099 /*FIXME*/ SourceLocation());
4100 if (Result.isNull())
4101 return QualType();
4102 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004103
John McCall550e0c22009-10-21 00:40:46 +00004104 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4105 NewTL.setNameLoc(TL.getNameLoc());
4106
4107 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004108}
Mike Stump11289f42009-09-09 15:08:12 +00004109
David Blaikie05785d12013-02-20 22:23:23 +00004110template <typename Derived>
4111ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4112 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4113 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004114 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor715e4612011-01-14 22:40:04 +00004115 TypeSourceInfo *NewDI = 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00004116
Douglas Gregor715e4612011-01-14 22:40:04 +00004117 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004118 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004119 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004120 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004121 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004122
Douglas Gregor715e4612011-01-14 22:40:04 +00004123 TypeLocBuilder TLB;
4124 TypeLoc NewTL = OldDI->getTypeLoc();
4125 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004126
4127 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004128 OldExpansionTL.getPatternLoc());
4129 if (Result.isNull())
4130 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00004131
4132 Result = RebuildPackExpansionType(Result,
4133 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004134 OldExpansionTL.getEllipsisLoc(),
4135 NumExpansions);
4136 if (Result.isNull())
4137 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00004138
Douglas Gregor715e4612011-01-14 22:40:04 +00004139 PackExpansionTypeLoc NewExpansionTL
4140 = TLB.push<PackExpansionTypeLoc>(Result);
4141 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4142 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4143 } else
4144 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004145 if (!NewDI)
4146 return 0;
4147
John McCall8fb0d9d2011-05-01 22:35:37 +00004148 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004149 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004150
4151 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4152 OldParm->getDeclContext(),
4153 OldParm->getInnerLocStart(),
4154 OldParm->getLocation(),
4155 OldParm->getIdentifier(),
4156 NewDI->getType(),
4157 NewDI,
4158 OldParm->getStorageClass(),
John McCall8fb0d9d2011-05-01 22:35:37 +00004159 /* DefArg */ NULL);
4160 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4161 OldParm->getFunctionScopeIndex() + indexAdjustment);
4162 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004163}
4164
4165template<typename Derived>
4166bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004167 TransformFunctionTypeParams(SourceLocation Loc,
4168 ParmVarDecl **Params, unsigned NumParams,
4169 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004170 SmallVectorImpl<QualType> &OutParamTypes,
4171 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004172 int indexAdjustment = 0;
4173
Douglas Gregordd472162011-01-07 00:20:55 +00004174 for (unsigned i = 0; i != NumParams; ++i) {
4175 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004176 assert(OldParm->getFunctionScopeIndex() == i);
4177
David Blaikie05785d12013-02-20 22:23:23 +00004178 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004179 ParmVarDecl *NewParm = 0;
Douglas Gregor5499af42011-01-05 23:12:31 +00004180 if (OldParm->isParameterPack()) {
4181 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004182 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004183
Douglas Gregor5499af42011-01-05 23:12:31 +00004184 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004185 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004186 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004187 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4188 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004189 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4190
Douglas Gregor5499af42011-01-05 23:12:31 +00004191 // Determine whether we should expand the parameter packs.
4192 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004193 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004194 Optional<unsigned> OrigNumExpansions =
4195 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004196 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004197 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4198 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004199 Unexpanded,
4200 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004201 RetainExpansion,
4202 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004203 return true;
4204 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004205
Douglas Gregor5499af42011-01-05 23:12:31 +00004206 if (ShouldExpand) {
4207 // Expand the function parameter pack into multiple, separate
4208 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004209 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004210 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004211 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004212 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004213 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004214 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004215 OrigNumExpansions,
4216 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004217 if (!NewParm)
4218 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004219
Douglas Gregordd472162011-01-07 00:20:55 +00004220 OutParamTypes.push_back(NewParm->getType());
4221 if (PVars)
4222 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004223 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004224
4225 // If we're supposed to retain a pack expansion, do so by temporarily
4226 // forgetting the partially-substituted parameter pack.
4227 if (RetainExpansion) {
4228 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004229 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004230 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004231 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004232 OrigNumExpansions,
4233 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004234 if (!NewParm)
4235 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004236
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004237 OutParamTypes.push_back(NewParm->getType());
4238 if (PVars)
4239 PVars->push_back(NewParm);
4240 }
4241
John McCall8fb0d9d2011-05-01 22:35:37 +00004242 // The next parameter should have the same adjustment as the
4243 // last thing we pushed, but we post-incremented indexAdjustment
4244 // on every push. Also, if we push nothing, the adjustment should
4245 // go down by one.
4246 indexAdjustment--;
4247
Douglas Gregor5499af42011-01-05 23:12:31 +00004248 // We're done with the pack expansion.
4249 continue;
4250 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004251
4252 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004253 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004254 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4255 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004256 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004257 NumExpansions,
4258 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004259 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004260 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004261 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004262 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004263
John McCall58f10c32010-03-11 09:03:00 +00004264 if (!NewParm)
4265 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004266
Douglas Gregordd472162011-01-07 00:20:55 +00004267 OutParamTypes.push_back(NewParm->getType());
4268 if (PVars)
4269 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004270 continue;
4271 }
John McCall58f10c32010-03-11 09:03:00 +00004272
4273 // Deal with the possibility that we don't have a parameter
4274 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004275 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004276 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004277 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004278 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004279 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004280 = dyn_cast<PackExpansionType>(OldType)) {
4281 // We have a function parameter pack that may need to be expanded.
4282 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004283 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004284 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004285
Douglas Gregor5499af42011-01-05 23:12:31 +00004286 // Determine whether we should expand the parameter packs.
4287 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004288 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004289 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004290 Unexpanded,
4291 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004292 RetainExpansion,
4293 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004294 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004295 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004296
Douglas Gregor5499af42011-01-05 23:12:31 +00004297 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004298 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004299 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004300 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004301 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4302 QualType NewType = getDerived().TransformType(Pattern);
4303 if (NewType.isNull())
4304 return true;
John McCall58f10c32010-03-11 09:03:00 +00004305
Douglas Gregordd472162011-01-07 00:20:55 +00004306 OutParamTypes.push_back(NewType);
4307 if (PVars)
4308 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00004309 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004310
Douglas Gregor5499af42011-01-05 23:12:31 +00004311 // We're done with the pack expansion.
4312 continue;
4313 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004314
Douglas Gregor48d24112011-01-10 20:53:55 +00004315 // If we're supposed to retain a pack expansion, do so by temporarily
4316 // forgetting the partially-substituted parameter pack.
4317 if (RetainExpansion) {
4318 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4319 QualType NewType = getDerived().TransformType(Pattern);
4320 if (NewType.isNull())
4321 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004322
Douglas Gregor48d24112011-01-10 20:53:55 +00004323 OutParamTypes.push_back(NewType);
4324 if (PVars)
4325 PVars->push_back(0);
4326 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004327
Chad Rosier1dcde962012-08-08 18:46:20 +00004328 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004329 // expansion.
4330 OldType = Expansion->getPattern();
4331 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004332 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4333 NewType = getDerived().TransformType(OldType);
4334 } else {
4335 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004336 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004337
Douglas Gregor5499af42011-01-05 23:12:31 +00004338 if (NewType.isNull())
4339 return true;
4340
4341 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004342 NewType = getSema().Context.getPackExpansionType(NewType,
4343 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004344
Douglas Gregordd472162011-01-07 00:20:55 +00004345 OutParamTypes.push_back(NewType);
4346 if (PVars)
4347 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00004348 }
4349
John McCall8fb0d9d2011-05-01 22:35:37 +00004350#ifndef NDEBUG
4351 if (PVars) {
4352 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4353 if (ParmVarDecl *parm = (*PVars)[i])
4354 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004355 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004356#endif
4357
4358 return false;
4359}
John McCall58f10c32010-03-11 09:03:00 +00004360
4361template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004362QualType
John McCall550e0c22009-10-21 00:40:46 +00004363TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004364 FunctionProtoTypeLoc TL) {
Douglas Gregor3024f072012-04-16 07:05:22 +00004365 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4366}
4367
4368template<typename Derived>
4369QualType
4370TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4371 FunctionProtoTypeLoc TL,
4372 CXXRecordDecl *ThisContext,
4373 unsigned ThisTypeQuals) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004374 // Transform the parameters and return type.
4375 //
Richard Smithf623c962012-04-17 00:58:00 +00004376 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004377 // When the function has a trailing return type, we instantiate the
4378 // parameters before the return type, since the return type can then refer
4379 // to the parameters themselves (via decltype, sizeof, etc.).
4380 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004381 SmallVector<QualType, 4> ParamTypes;
4382 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004383 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004384
Douglas Gregor7fb25412010-10-01 18:44:50 +00004385 QualType ResultType;
4386
Richard Smith1226c602012-08-14 22:51:13 +00004387 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004388 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004389 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004390 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004391 return QualType();
4392
Douglas Gregor3024f072012-04-16 07:05:22 +00004393 {
4394 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004395 // If a declaration declares a member function or member function
4396 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004397 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004398 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004399 // declarator.
4400 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004401
Alp Toker42a16a62014-01-25 23:51:36 +00004402 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004403 if (ResultType.isNull())
4404 return QualType();
4405 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004406 }
4407 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004408 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004409 if (ResultType.isNull())
4410 return QualType();
4411
Alp Toker9cacbab2014-01-20 20:26:09 +00004412 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004413 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004414 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004415 return QualType();
4416 }
4417
Richard Smithf623c962012-04-17 00:58:00 +00004418 // FIXME: Need to transform the exception-specification too.
4419
John McCall550e0c22009-10-21 00:40:46 +00004420 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004421 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Alp Toker9cacbab2014-01-20 20:26:09 +00004422 T->getNumParams() != ParamTypes.size() ||
4423 !std::equal(T->param_type_begin(), T->param_type_end(),
4424 ParamTypes.begin())) {
Jordan Rose5c382722013-03-08 21:51:21 +00004425 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00004426 T->getExtProtoInfo());
John McCall550e0c22009-10-21 00:40:46 +00004427 if (Result.isNull())
4428 return QualType();
4429 }
Mike Stump11289f42009-09-09 15:08:12 +00004430
John McCall550e0c22009-10-21 00:40:46 +00004431 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004432 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004433 NewTL.setLParenLoc(TL.getLParenLoc());
4434 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004435 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004436 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4437 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004438
4439 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004440}
Mike Stump11289f42009-09-09 15:08:12 +00004441
Douglas Gregord6ff3322009-08-04 16:50:30 +00004442template<typename Derived>
4443QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004444 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004445 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004446 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00004447 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00004448 if (ResultType.isNull())
4449 return QualType();
4450
4451 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004452 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00004453 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4454
4455 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004456 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004457 NewTL.setLParenLoc(TL.getLParenLoc());
4458 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004459 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004460
4461 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004462}
Mike Stump11289f42009-09-09 15:08:12 +00004463
John McCallb96ec562009-12-04 22:46:56 +00004464template<typename Derived> QualType
4465TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004466 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004467 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004468 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004469 if (!D)
4470 return QualType();
4471
4472 QualType Result = TL.getType();
4473 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4474 Result = getDerived().RebuildUnresolvedUsingType(D);
4475 if (Result.isNull())
4476 return QualType();
4477 }
4478
4479 // We might get an arbitrary type spec type back. We should at
4480 // least always get a type spec type, though.
4481 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4482 NewTL.setNameLoc(TL.getNameLoc());
4483
4484 return Result;
4485}
4486
Douglas Gregord6ff3322009-08-04 16:50:30 +00004487template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004488QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004489 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004490 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004491 TypedefNameDecl *Typedef
4492 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4493 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004494 if (!Typedef)
4495 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004496
John McCall550e0c22009-10-21 00:40:46 +00004497 QualType Result = TL.getType();
4498 if (getDerived().AlwaysRebuild() ||
4499 Typedef != T->getDecl()) {
4500 Result = getDerived().RebuildTypedefType(Typedef);
4501 if (Result.isNull())
4502 return QualType();
4503 }
Mike Stump11289f42009-09-09 15:08:12 +00004504
John McCall550e0c22009-10-21 00:40:46 +00004505 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4506 NewTL.setNameLoc(TL.getNameLoc());
4507
4508 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004509}
Mike Stump11289f42009-09-09 15:08:12 +00004510
Douglas Gregord6ff3322009-08-04 16:50:30 +00004511template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004512QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004513 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004514 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00004515 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4516 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00004517
John McCalldadc5752010-08-24 06:29:42 +00004518 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004519 if (E.isInvalid())
4520 return QualType();
4521
Eli Friedmane4f22df2012-02-29 04:03:55 +00004522 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4523 if (E.isInvalid())
4524 return QualType();
4525
John McCall550e0c22009-10-21 00:40:46 +00004526 QualType Result = TL.getType();
4527 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004528 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004529 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004530 if (Result.isNull())
4531 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004532 }
John McCall550e0c22009-10-21 00:40:46 +00004533 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004534
John McCall550e0c22009-10-21 00:40:46 +00004535 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004536 NewTL.setTypeofLoc(TL.getTypeofLoc());
4537 NewTL.setLParenLoc(TL.getLParenLoc());
4538 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004539
4540 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004541}
Mike Stump11289f42009-09-09 15:08:12 +00004542
4543template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004544QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004545 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004546 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4547 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4548 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004549 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004550
John McCall550e0c22009-10-21 00:40:46 +00004551 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004552 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4553 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004554 if (Result.isNull())
4555 return QualType();
4556 }
Mike Stump11289f42009-09-09 15:08:12 +00004557
John McCall550e0c22009-10-21 00:40:46 +00004558 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004559 NewTL.setTypeofLoc(TL.getTypeofLoc());
4560 NewTL.setLParenLoc(TL.getLParenLoc());
4561 NewTL.setRParenLoc(TL.getRParenLoc());
4562 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004563
4564 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004565}
Mike Stump11289f42009-09-09 15:08:12 +00004566
4567template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004568QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004569 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004570 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004571
Douglas Gregore922c772009-08-04 22:27:00 +00004572 // decltype expressions are not potentially evaluated contexts
Richard Smithfd555f62012-02-22 02:04:18 +00004573 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4574 /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00004575
John McCalldadc5752010-08-24 06:29:42 +00004576 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004577 if (E.isInvalid())
4578 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004579
Richard Smithfd555f62012-02-22 02:04:18 +00004580 E = getSema().ActOnDecltypeExpression(E.take());
4581 if (E.isInvalid())
4582 return QualType();
4583
John McCall550e0c22009-10-21 00:40:46 +00004584 QualType Result = TL.getType();
4585 if (getDerived().AlwaysRebuild() ||
4586 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004587 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004588 if (Result.isNull())
4589 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004590 }
John McCall550e0c22009-10-21 00:40:46 +00004591 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004592
John McCall550e0c22009-10-21 00:40:46 +00004593 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4594 NewTL.setNameLoc(TL.getNameLoc());
4595
4596 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004597}
4598
4599template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004600QualType TreeTransform<Derived>::TransformUnaryTransformType(
4601 TypeLocBuilder &TLB,
4602 UnaryTransformTypeLoc TL) {
4603 QualType Result = TL.getType();
4604 if (Result->isDependentType()) {
4605 const UnaryTransformType *T = TL.getTypePtr();
4606 QualType NewBase =
4607 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4608 Result = getDerived().RebuildUnaryTransformType(NewBase,
4609 T->getUTTKind(),
4610 TL.getKWLoc());
4611 if (Result.isNull())
4612 return QualType();
4613 }
4614
4615 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4616 NewTL.setKWLoc(TL.getKWLoc());
4617 NewTL.setParensRange(TL.getParensRange());
4618 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4619 return Result;
4620}
4621
4622template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004623QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4624 AutoTypeLoc TL) {
4625 const AutoType *T = TL.getTypePtr();
4626 QualType OldDeduced = T->getDeducedType();
4627 QualType NewDeduced;
4628 if (!OldDeduced.isNull()) {
4629 NewDeduced = getDerived().TransformType(OldDeduced);
4630 if (NewDeduced.isNull())
4631 return QualType();
4632 }
4633
4634 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00004635 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4636 T->isDependentType()) {
Richard Smith74aeef52013-04-26 16:15:35 +00004637 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith30482bc2011-02-20 03:19:35 +00004638 if (Result.isNull())
4639 return QualType();
4640 }
4641
4642 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4643 NewTL.setNameLoc(TL.getNameLoc());
4644
4645 return Result;
4646}
4647
4648template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004649QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004650 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004651 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004652 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004653 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4654 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004655 if (!Record)
4656 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004657
John McCall550e0c22009-10-21 00:40:46 +00004658 QualType Result = TL.getType();
4659 if (getDerived().AlwaysRebuild() ||
4660 Record != T->getDecl()) {
4661 Result = getDerived().RebuildRecordType(Record);
4662 if (Result.isNull())
4663 return QualType();
4664 }
Mike Stump11289f42009-09-09 15:08:12 +00004665
John McCall550e0c22009-10-21 00:40:46 +00004666 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4667 NewTL.setNameLoc(TL.getNameLoc());
4668
4669 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004670}
Mike Stump11289f42009-09-09 15:08:12 +00004671
4672template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004673QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004674 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004675 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004676 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004677 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4678 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004679 if (!Enum)
4680 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004681
John McCall550e0c22009-10-21 00:40:46 +00004682 QualType Result = TL.getType();
4683 if (getDerived().AlwaysRebuild() ||
4684 Enum != T->getDecl()) {
4685 Result = getDerived().RebuildEnumType(Enum);
4686 if (Result.isNull())
4687 return QualType();
4688 }
Mike Stump11289f42009-09-09 15:08:12 +00004689
John McCall550e0c22009-10-21 00:40:46 +00004690 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4691 NewTL.setNameLoc(TL.getNameLoc());
4692
4693 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004694}
John McCallfcc33b02009-09-05 00:15:47 +00004695
John McCalle78aac42010-03-10 03:28:59 +00004696template<typename Derived>
4697QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4698 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004699 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004700 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4701 TL.getTypePtr()->getDecl());
4702 if (!D) return QualType();
4703
4704 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4705 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4706 return T;
4707}
4708
Douglas Gregord6ff3322009-08-04 16:50:30 +00004709template<typename Derived>
4710QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004711 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004712 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004713 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004714}
4715
Mike Stump11289f42009-09-09 15:08:12 +00004716template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004717QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004718 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004719 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004720 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00004721
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004722 // Substitute into the replacement type, which itself might involve something
4723 // that needs to be transformed. This only tends to occur with default
4724 // template arguments of template template parameters.
4725 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4726 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4727 if (Replacement.isNull())
4728 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00004729
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004730 // Always canonicalize the replacement type.
4731 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4732 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00004733 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004734 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00004735
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004736 // Propagate type-source information.
4737 SubstTemplateTypeParmTypeLoc NewTL
4738 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4739 NewTL.setNameLoc(TL.getNameLoc());
4740 return Result;
4741
John McCallcebee162009-10-18 09:09:24 +00004742}
4743
4744template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004745QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4746 TypeLocBuilder &TLB,
4747 SubstTemplateTypeParmPackTypeLoc TL) {
4748 return TransformTypeSpecType(TLB, TL);
4749}
4750
4751template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004752QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004753 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004754 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004755 const TemplateSpecializationType *T = TL.getTypePtr();
4756
Douglas Gregordf846d12011-03-02 18:46:51 +00004757 // The nested-name-specifier never matters in a TemplateSpecializationType,
4758 // because we can't have a dependent nested-name-specifier anyway.
4759 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004760 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004761 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4762 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004763 if (Template.isNull())
4764 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004765
John McCall31f82722010-11-12 08:19:04 +00004766 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4767}
4768
Eli Friedman0dfb8892011-10-06 23:00:33 +00004769template<typename Derived>
4770QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4771 AtomicTypeLoc TL) {
4772 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4773 if (ValueType.isNull())
4774 return QualType();
4775
4776 QualType Result = TL.getType();
4777 if (getDerived().AlwaysRebuild() ||
4778 ValueType != TL.getValueLoc().getType()) {
4779 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4780 if (Result.isNull())
4781 return QualType();
4782 }
4783
4784 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4785 NewTL.setKWLoc(TL.getKWLoc());
4786 NewTL.setLParenLoc(TL.getLParenLoc());
4787 NewTL.setRParenLoc(TL.getRParenLoc());
4788
4789 return Result;
4790}
4791
Chad Rosier1dcde962012-08-08 18:46:20 +00004792 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00004793 /// container that provides a \c getArgLoc() member function.
4794 ///
4795 /// This iterator is intended to be used with the iterator form of
4796 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4797 template<typename ArgLocContainer>
4798 class TemplateArgumentLocContainerIterator {
4799 ArgLocContainer *Container;
4800 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00004801
Douglas Gregorfe921a72010-12-20 23:36:19 +00004802 public:
4803 typedef TemplateArgumentLoc value_type;
4804 typedef TemplateArgumentLoc reference;
4805 typedef int difference_type;
4806 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00004807
Douglas Gregorfe921a72010-12-20 23:36:19 +00004808 class pointer {
4809 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00004810
Douglas Gregorfe921a72010-12-20 23:36:19 +00004811 public:
4812 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004813
Douglas Gregorfe921a72010-12-20 23:36:19 +00004814 const TemplateArgumentLoc *operator->() const {
4815 return &Arg;
4816 }
4817 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004818
4819
Douglas Gregorfe921a72010-12-20 23:36:19 +00004820 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00004821
Douglas Gregorfe921a72010-12-20 23:36:19 +00004822 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4823 unsigned Index)
4824 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004825
Douglas Gregorfe921a72010-12-20 23:36:19 +00004826 TemplateArgumentLocContainerIterator &operator++() {
4827 ++Index;
4828 return *this;
4829 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004830
Douglas Gregorfe921a72010-12-20 23:36:19 +00004831 TemplateArgumentLocContainerIterator operator++(int) {
4832 TemplateArgumentLocContainerIterator Old(*this);
4833 ++(*this);
4834 return Old;
4835 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004836
Douglas Gregorfe921a72010-12-20 23:36:19 +00004837 TemplateArgumentLoc operator*() const {
4838 return Container->getArgLoc(Index);
4839 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004840
Douglas Gregorfe921a72010-12-20 23:36:19 +00004841 pointer operator->() const {
4842 return pointer(Container->getArgLoc(Index));
4843 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004844
Douglas Gregorfe921a72010-12-20 23:36:19 +00004845 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004846 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004847 return X.Container == Y.Container && X.Index == Y.Index;
4848 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004849
Douglas Gregorfe921a72010-12-20 23:36:19 +00004850 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004851 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004852 return !(X == Y);
4853 }
4854 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004855
4856
John McCall31f82722010-11-12 08:19:04 +00004857template <typename Derived>
4858QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4859 TypeLocBuilder &TLB,
4860 TemplateSpecializationTypeLoc TL,
4861 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004862 TemplateArgumentListInfo NewTemplateArgs;
4863 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4864 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004865 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4866 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004867 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00004868 ArgIterator(TL, TL.getNumArgs()),
4869 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004870 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004871
John McCall0ad16662009-10-29 08:12:44 +00004872 // FIXME: maybe don't rebuild if all the template arguments are the same.
4873
4874 QualType Result =
4875 getDerived().RebuildTemplateSpecializationType(Template,
4876 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004877 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004878
4879 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00004880 // Specializations of template template parameters are represented as
4881 // TemplateSpecializationTypes, and substitution of type alias templates
4882 // within a dependent context can transform them into
4883 // DependentTemplateSpecializationTypes.
4884 if (isa<DependentTemplateSpecializationType>(Result)) {
4885 DependentTemplateSpecializationTypeLoc NewTL
4886 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004887 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00004888 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00004889 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004890 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00004891 NewTL.setLAngleLoc(TL.getLAngleLoc());
4892 NewTL.setRAngleLoc(TL.getRAngleLoc());
4893 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4894 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4895 return Result;
4896 }
4897
John McCall0ad16662009-10-29 08:12:44 +00004898 TemplateSpecializationTypeLoc NewTL
4899 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004900 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00004901 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4902 NewTL.setLAngleLoc(TL.getLAngleLoc());
4903 NewTL.setRAngleLoc(TL.getRAngleLoc());
4904 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4905 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004906 }
Mike Stump11289f42009-09-09 15:08:12 +00004907
John McCall0ad16662009-10-29 08:12:44 +00004908 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004909}
Mike Stump11289f42009-09-09 15:08:12 +00004910
Douglas Gregor5a064722011-02-28 17:23:35 +00004911template <typename Derived>
4912QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4913 TypeLocBuilder &TLB,
4914 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004915 TemplateName Template,
4916 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00004917 TemplateArgumentListInfo NewTemplateArgs;
4918 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4919 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4920 typedef TemplateArgumentLocContainerIterator<
4921 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004922 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00004923 ArgIterator(TL, TL.getNumArgs()),
4924 NewTemplateArgs))
4925 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00004926
Douglas Gregor5a064722011-02-28 17:23:35 +00004927 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00004928
Douglas Gregor5a064722011-02-28 17:23:35 +00004929 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4930 QualType Result
4931 = getSema().Context.getDependentTemplateSpecializationType(
4932 TL.getTypePtr()->getKeyword(),
4933 DTN->getQualifier(),
4934 DTN->getIdentifier(),
4935 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00004936
Douglas Gregor5a064722011-02-28 17:23:35 +00004937 DependentTemplateSpecializationTypeLoc NewTL
4938 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004939 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004940 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00004941 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004942 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00004943 NewTL.setLAngleLoc(TL.getLAngleLoc());
4944 NewTL.setRAngleLoc(TL.getRAngleLoc());
4945 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4946 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4947 return Result;
4948 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004949
4950 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00004951 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004952 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00004953 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00004954
Douglas Gregor5a064722011-02-28 17:23:35 +00004955 if (!Result.isNull()) {
4956 /// FIXME: Wrap this in an elaborated-type-specifier?
4957 TemplateSpecializationTypeLoc NewTL
4958 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00004959 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004960 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00004961 NewTL.setLAngleLoc(TL.getLAngleLoc());
4962 NewTL.setRAngleLoc(TL.getRAngleLoc());
4963 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4964 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4965 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004966
Douglas Gregor5a064722011-02-28 17:23:35 +00004967 return Result;
4968}
4969
Mike Stump11289f42009-09-09 15:08:12 +00004970template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004971QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00004972TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004973 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004974 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00004975
Douglas Gregor844cb502011-03-01 18:12:44 +00004976 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00004977 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00004978 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004979 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00004980 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4981 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00004982 return QualType();
4983 }
Mike Stump11289f42009-09-09 15:08:12 +00004984
John McCall31f82722010-11-12 08:19:04 +00004985 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4986 if (NamedT.isNull())
4987 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00004988
Richard Smith3f1b5d02011-05-05 21:57:07 +00004989 // C++0x [dcl.type.elab]p2:
4990 // If the identifier resolves to a typedef-name or the simple-template-id
4991 // resolves to an alias template specialization, the
4992 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00004993 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4994 if (const TemplateSpecializationType *TST =
4995 NamedT->getAs<TemplateSpecializationType>()) {
4996 TemplateName Template = TST->getTemplateName();
4997 if (TypeAliasTemplateDecl *TAT =
4998 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4999 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5000 diag::err_tag_reference_non_tag) << 4;
5001 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5002 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005003 }
5004 }
5005
John McCall550e0c22009-10-21 00:40:46 +00005006 QualType Result = TL.getType();
5007 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005008 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005009 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005010 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005011 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005012 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005013 if (Result.isNull())
5014 return QualType();
5015 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005016
Abramo Bagnara6150c882010-05-11 21:36:43 +00005017 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005018 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005019 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005020 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005021}
Mike Stump11289f42009-09-09 15:08:12 +00005022
5023template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005024QualType TreeTransform<Derived>::TransformAttributedType(
5025 TypeLocBuilder &TLB,
5026 AttributedTypeLoc TL) {
5027 const AttributedType *oldType = TL.getTypePtr();
5028 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5029 if (modifiedType.isNull())
5030 return QualType();
5031
5032 QualType result = TL.getType();
5033
5034 // FIXME: dependent operand expressions?
5035 if (getDerived().AlwaysRebuild() ||
5036 modifiedType != oldType->getModifiedType()) {
5037 // TODO: this is really lame; we should really be rebuilding the
5038 // equivalent type from first principles.
5039 QualType equivalentType
5040 = getDerived().TransformType(oldType->getEquivalentType());
5041 if (equivalentType.isNull())
5042 return QualType();
5043 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5044 modifiedType,
5045 equivalentType);
5046 }
5047
5048 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5049 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5050 if (TL.hasAttrOperand())
5051 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5052 if (TL.hasAttrExprOperand())
5053 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5054 else if (TL.hasAttrEnumOperand())
5055 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5056
5057 return result;
5058}
5059
5060template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005061QualType
5062TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5063 ParenTypeLoc TL) {
5064 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5065 if (Inner.isNull())
5066 return QualType();
5067
5068 QualType Result = TL.getType();
5069 if (getDerived().AlwaysRebuild() ||
5070 Inner != TL.getInnerLoc().getType()) {
5071 Result = getDerived().RebuildParenType(Inner);
5072 if (Result.isNull())
5073 return QualType();
5074 }
5075
5076 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5077 NewTL.setLParenLoc(TL.getLParenLoc());
5078 NewTL.setRParenLoc(TL.getRParenLoc());
5079 return Result;
5080}
5081
5082template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005083QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005084 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005085 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005086
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005087 NestedNameSpecifierLoc QualifierLoc
5088 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5089 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005090 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005091
John McCallc392f372010-06-11 00:33:02 +00005092 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005093 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005094 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005095 QualifierLoc,
5096 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005097 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005098 if (Result.isNull())
5099 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005100
Abramo Bagnarad7548482010-05-19 21:37:53 +00005101 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5102 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005103 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5104
Abramo Bagnarad7548482010-05-19 21:37:53 +00005105 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005106 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005107 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005108 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005109 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005110 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005111 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005112 NewTL.setNameLoc(TL.getNameLoc());
5113 }
John McCall550e0c22009-10-21 00:40:46 +00005114 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005115}
Mike Stump11289f42009-09-09 15:08:12 +00005116
Douglas Gregord6ff3322009-08-04 16:50:30 +00005117template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005118QualType TreeTransform<Derived>::
5119 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005120 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005121 NestedNameSpecifierLoc QualifierLoc;
5122 if (TL.getQualifierLoc()) {
5123 QualifierLoc
5124 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5125 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005126 return QualType();
5127 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005128
John McCall31f82722010-11-12 08:19:04 +00005129 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005130 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005131}
5132
5133template<typename Derived>
5134QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005135TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5136 DependentTemplateSpecializationTypeLoc TL,
5137 NestedNameSpecifierLoc QualifierLoc) {
5138 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005139
Douglas Gregora7a795b2011-03-01 20:11:18 +00005140 TemplateArgumentListInfo NewTemplateArgs;
5141 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5142 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005143
Douglas Gregora7a795b2011-03-01 20:11:18 +00005144 typedef TemplateArgumentLocContainerIterator<
5145 DependentTemplateSpecializationTypeLoc> ArgIterator;
5146 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5147 ArgIterator(TL, TL.getNumArgs()),
5148 NewTemplateArgs))
5149 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005150
Douglas Gregora7a795b2011-03-01 20:11:18 +00005151 QualType Result
5152 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5153 QualifierLoc,
5154 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005155 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005156 NewTemplateArgs);
5157 if (Result.isNull())
5158 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005159
Douglas Gregora7a795b2011-03-01 20:11:18 +00005160 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5161 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005162
Douglas Gregora7a795b2011-03-01 20:11:18 +00005163 // Copy information relevant to the template specialization.
5164 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005165 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005166 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005167 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005168 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5169 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005170 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005171 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005172
Douglas Gregora7a795b2011-03-01 20:11:18 +00005173 // Copy information relevant to the elaborated type.
5174 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005175 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005176 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005177 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5178 DependentTemplateSpecializationTypeLoc SpecTL
5179 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005180 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005181 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005182 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005183 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005184 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5185 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005186 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005187 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005188 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005189 TemplateSpecializationTypeLoc SpecTL
5190 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005191 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005192 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005193 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5194 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005195 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005196 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005197 }
5198 return Result;
5199}
5200
5201template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005202QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5203 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005204 QualType Pattern
5205 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005206 if (Pattern.isNull())
5207 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005208
5209 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005210 if (getDerived().AlwaysRebuild() ||
5211 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005212 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005213 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005214 TL.getEllipsisLoc(),
5215 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005216 if (Result.isNull())
5217 return QualType();
5218 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005219
Douglas Gregor822d0302011-01-12 17:07:58 +00005220 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5221 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5222 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005223}
5224
5225template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005226QualType
5227TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005228 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005229 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005230 TLB.pushFullCopy(TL);
5231 return TL.getType();
5232}
5233
5234template<typename Derived>
5235QualType
5236TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005237 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00005238 // ObjCObjectType is never dependent.
5239 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005240 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005241}
Mike Stump11289f42009-09-09 15:08:12 +00005242
5243template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005244QualType
5245TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005246 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005247 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005248 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005249 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005250}
5251
Douglas Gregord6ff3322009-08-04 16:50:30 +00005252//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005253// Statement transformation
5254//===----------------------------------------------------------------------===//
5255template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005256StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005257TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005258 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005259}
5260
5261template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005262StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005263TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5264 return getDerived().TransformCompoundStmt(S, false);
5265}
5266
5267template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005268StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005269TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005270 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005271 Sema::CompoundScopeRAII CompoundScope(getSema());
5272
John McCall1ababa62010-08-27 19:56:05 +00005273 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005274 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005275 SmallVector<Stmt*, 8> Statements;
Douglas Gregorebe10102009-08-20 07:17:43 +00005276 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5277 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00005278 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00005279 if (Result.isInvalid()) {
5280 // Immediately fail if this was a DeclStmt, since it's very
5281 // likely that this will cause problems for future statements.
5282 if (isa<DeclStmt>(*B))
5283 return StmtError();
5284
5285 // Otherwise, just keep processing substatements and fail later.
5286 SubStmtInvalid = true;
5287 continue;
5288 }
Mike Stump11289f42009-09-09 15:08:12 +00005289
Douglas Gregorebe10102009-08-20 07:17:43 +00005290 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5291 Statements.push_back(Result.takeAs<Stmt>());
5292 }
Mike Stump11289f42009-09-09 15:08:12 +00005293
John McCall1ababa62010-08-27 19:56:05 +00005294 if (SubStmtInvalid)
5295 return StmtError();
5296
Douglas Gregorebe10102009-08-20 07:17:43 +00005297 if (!getDerived().AlwaysRebuild() &&
5298 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00005299 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005300
5301 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005302 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005303 S->getRBracLoc(),
5304 IsStmtExpr);
5305}
Mike Stump11289f42009-09-09 15:08:12 +00005306
Douglas Gregorebe10102009-08-20 07:17:43 +00005307template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005308StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005309TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005310 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005311 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005312 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5313 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005314
Eli Friedman06577382009-11-19 03:14:00 +00005315 // Transform the left-hand case value.
5316 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005317 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005318 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005319 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005320
Eli Friedman06577382009-11-19 03:14:00 +00005321 // Transform the right-hand case value (for the GNU case-range extension).
5322 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005323 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005324 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005325 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005326 }
Mike Stump11289f42009-09-09 15:08:12 +00005327
Douglas Gregorebe10102009-08-20 07:17:43 +00005328 // Build the case statement.
5329 // Case statements are always rebuilt so that they will attached to their
5330 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005331 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005332 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005333 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005334 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005335 S->getColonLoc());
5336 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005337 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005338
Douglas Gregorebe10102009-08-20 07:17:43 +00005339 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005340 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005341 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005342 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005343
Douglas Gregorebe10102009-08-20 07:17:43 +00005344 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005345 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005346}
5347
5348template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005349StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005350TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005351 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005352 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005353 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005354 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005355
Douglas Gregorebe10102009-08-20 07:17:43 +00005356 // Default statements are always rebuilt
5357 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005358 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005359}
Mike Stump11289f42009-09-09 15:08:12 +00005360
Douglas Gregorebe10102009-08-20 07:17:43 +00005361template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005362StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005363TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005364 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005365 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005366 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005367
Chris Lattnercab02a62011-02-17 20:34:02 +00005368 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5369 S->getDecl());
5370 if (!LD)
5371 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00005372
5373
Douglas Gregorebe10102009-08-20 07:17:43 +00005374 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005375 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005376 cast<LabelDecl>(LD), SourceLocation(),
5377 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005378}
Mike Stump11289f42009-09-09 15:08:12 +00005379
Douglas Gregorebe10102009-08-20 07:17:43 +00005380template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005381StmtResult
Richard Smithc202b282012-04-14 00:33:13 +00005382TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5383 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5384 if (SubStmt.isInvalid())
5385 return StmtError();
5386
5387 // TODO: transform attributes
5388 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5389 return S;
5390
5391 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5392 S->getAttrs(),
5393 SubStmt.get());
5394}
5395
5396template<typename Derived>
5397StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005398TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005399 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005400 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00005401 VarDecl *ConditionVar = 0;
5402 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005403 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00005404 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005405 getDerived().TransformDefinition(
5406 S->getConditionVariable()->getLocation(),
5407 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00005408 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005409 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005410 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00005411 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005412
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005413 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005414 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005415
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005416 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005417 if (S->getCond()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005418 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005419 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005420 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005421 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005422
John McCallb268a282010-08-23 23:25:46 +00005423 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005424 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005425 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005426
John McCallb268a282010-08-23 23:25:46 +00005427 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5428 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005429 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005430
Douglas Gregorebe10102009-08-20 07:17:43 +00005431 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005432 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005433 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005434 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005435
Douglas Gregorebe10102009-08-20 07:17:43 +00005436 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005437 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005438 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005439 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005440
Douglas Gregorebe10102009-08-20 07:17:43 +00005441 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005442 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005443 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005444 Then.get() == S->getThen() &&
5445 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00005446 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005447
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005448 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005449 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00005450 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005451}
5452
5453template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005454StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005455TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005456 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005457 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00005458 VarDecl *ConditionVar = 0;
5459 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005460 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005461 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005462 getDerived().TransformDefinition(
5463 S->getConditionVariable()->getLocation(),
5464 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005465 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005466 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005467 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005468 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005469
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005470 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005471 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005472 }
Mike Stump11289f42009-09-09 15:08:12 +00005473
Douglas Gregorebe10102009-08-20 07:17:43 +00005474 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005475 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005476 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005477 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005478 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005479 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005480
Douglas Gregorebe10102009-08-20 07:17:43 +00005481 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005482 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005483 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005484 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005485
Douglas Gregorebe10102009-08-20 07:17:43 +00005486 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005487 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5488 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005489}
Mike Stump11289f42009-09-09 15:08:12 +00005490
Douglas Gregorebe10102009-08-20 07:17:43 +00005491template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005492StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005493TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005494 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005495 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00005496 VarDecl *ConditionVar = 0;
5497 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005498 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005499 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005500 getDerived().TransformDefinition(
5501 S->getConditionVariable()->getLocation(),
5502 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005503 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005504 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005505 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005506 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005507
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005508 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005509 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005510
5511 if (S->getCond()) {
5512 // Convert the condition to a boolean value.
Chad Rosier1dcde962012-08-08 18:46:20 +00005513 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005514 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005515 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005516 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005517 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005518 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005519 }
Mike Stump11289f42009-09-09 15:08:12 +00005520
John McCallb268a282010-08-23 23:25:46 +00005521 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5522 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005523 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005524
Douglas Gregorebe10102009-08-20 07:17:43 +00005525 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005526 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005527 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005528 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005529
Douglas Gregorebe10102009-08-20 07:17:43 +00005530 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005531 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005532 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005533 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005534 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005535
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005536 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005537 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005538}
Mike Stump11289f42009-09-09 15:08:12 +00005539
Douglas Gregorebe10102009-08-20 07:17:43 +00005540template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005541StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005542TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005543 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005544 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005545 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005546 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005547
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005548 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005549 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005550 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005551 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005552
Douglas Gregorebe10102009-08-20 07:17:43 +00005553 if (!getDerived().AlwaysRebuild() &&
5554 Cond.get() == S->getCond() &&
5555 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005556 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005557
John McCallb268a282010-08-23 23:25:46 +00005558 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5559 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005560 S->getRParenLoc());
5561}
Mike Stump11289f42009-09-09 15:08:12 +00005562
Douglas Gregorebe10102009-08-20 07:17:43 +00005563template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005564StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005565TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005566 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005567 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005568 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005569 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005570
Douglas Gregorebe10102009-08-20 07:17:43 +00005571 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005572 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005573 VarDecl *ConditionVar = 0;
5574 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005575 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005576 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005577 getDerived().TransformDefinition(
5578 S->getConditionVariable()->getLocation(),
5579 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005580 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005581 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005582 } else {
5583 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005584
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005585 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005586 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005587
5588 if (S->getCond()) {
5589 // Convert the condition to a boolean value.
Chad Rosier1dcde962012-08-08 18:46:20 +00005590 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005591 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005592 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005593 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005594
John McCallb268a282010-08-23 23:25:46 +00005595 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005596 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005597 }
Mike Stump11289f42009-09-09 15:08:12 +00005598
Chad Rosier1dcde962012-08-08 18:46:20 +00005599 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCallb268a282010-08-23 23:25:46 +00005600 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005601 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005602
Douglas Gregorebe10102009-08-20 07:17:43 +00005603 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005604 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005605 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005606 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005607
Richard Smith945f8d32013-01-14 22:39:08 +00005608 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00005609 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005610 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005611
Douglas Gregorebe10102009-08-20 07:17:43 +00005612 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005613 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005614 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005615 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005616
Douglas Gregorebe10102009-08-20 07:17:43 +00005617 if (!getDerived().AlwaysRebuild() &&
5618 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005619 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005620 Inc.get() == S->getInc() &&
5621 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005622 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005623
Douglas Gregorebe10102009-08-20 07:17:43 +00005624 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005625 Init.get(), FullCond, ConditionVar,
5626 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005627}
5628
5629template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005630StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005631TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005632 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5633 S->getLabel());
5634 if (!LD)
5635 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005636
Douglas Gregorebe10102009-08-20 07:17:43 +00005637 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005638 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005639 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005640}
5641
5642template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005643StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005644TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005645 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005646 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005647 return StmtError();
Eli Friedman9ccdb1d2012-01-31 22:47:07 +00005648 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump11289f42009-09-09 15:08:12 +00005649
Douglas Gregorebe10102009-08-20 07:17:43 +00005650 if (!getDerived().AlwaysRebuild() &&
5651 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00005652 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005653
5654 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005655 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005656}
5657
5658template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005659StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005660TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005661 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005662}
Mike Stump11289f42009-09-09 15:08:12 +00005663
Douglas Gregorebe10102009-08-20 07:17:43 +00005664template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005665StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005666TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005667 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005668}
Mike Stump11289f42009-09-09 15:08:12 +00005669
Douglas Gregorebe10102009-08-20 07:17:43 +00005670template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005671StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005672TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005673 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005674 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005675 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005676
Mike Stump11289f42009-09-09 15:08:12 +00005677 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005678 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005679 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005680}
Mike Stump11289f42009-09-09 15:08:12 +00005681
Douglas Gregorebe10102009-08-20 07:17:43 +00005682template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005683StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005684TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005685 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005686 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005687 for (auto *D : S->decls()) {
5688 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005689 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005690 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005691
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005692 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00005693 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005694
Douglas Gregorebe10102009-08-20 07:17:43 +00005695 Decls.push_back(Transformed);
5696 }
Mike Stump11289f42009-09-09 15:08:12 +00005697
Douglas Gregorebe10102009-08-20 07:17:43 +00005698 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00005699 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005700
Rafael Espindolaab417692013-07-09 12:05:01 +00005701 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005702}
Mike Stump11289f42009-09-09 15:08:12 +00005703
Douglas Gregorebe10102009-08-20 07:17:43 +00005704template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005705StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00005706TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005707
Benjamin Kramerf0623432012-08-23 22:51:59 +00005708 SmallVector<Expr*, 8> Constraints;
5709 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005710 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005711
John McCalldadc5752010-08-24 06:29:42 +00005712 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005713 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005714
5715 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00005716
Anders Carlssonaaeef072010-01-24 05:50:09 +00005717 // Go through the outputs.
5718 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005719 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005720
Anders Carlssonaaeef072010-01-24 05:50:09 +00005721 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005722 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005723
Anders Carlssonaaeef072010-01-24 05:50:09 +00005724 // Transform the output expr.
5725 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005726 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005727 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005728 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005729
Anders Carlssonaaeef072010-01-24 05:50:09 +00005730 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005731
John McCallb268a282010-08-23 23:25:46 +00005732 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005733 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005734
Anders Carlssonaaeef072010-01-24 05:50:09 +00005735 // Go through the inputs.
5736 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005737 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005738
Anders Carlssonaaeef072010-01-24 05:50:09 +00005739 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005740 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005741
Anders Carlssonaaeef072010-01-24 05:50:09 +00005742 // Transform the input expr.
5743 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005744 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005745 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005746 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005747
Anders Carlssonaaeef072010-01-24 05:50:09 +00005748 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005749
John McCallb268a282010-08-23 23:25:46 +00005750 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005751 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005752
Anders Carlssonaaeef072010-01-24 05:50:09 +00005753 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00005754 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005755
5756 // Go through the clobbers.
5757 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00005758 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005759
5760 // No need to transform the asm string literal.
5761 AsmString = SemaRef.Owned(S->getAsmString());
Chad Rosierde70e0e2012-08-25 00:11:56 +00005762 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5763 S->isVolatile(), S->getNumOutputs(),
5764 S->getNumInputs(), Names.data(),
5765 Constraints, Exprs, AsmString.get(),
5766 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005767}
5768
Chad Rosier32503022012-06-11 20:47:18 +00005769template<typename Derived>
5770StmtResult
5771TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00005772 ArrayRef<Token> AsmToks =
5773 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00005774
John McCallf413f5e2013-05-03 00:10:13 +00005775 bool HadError = false, HadChange = false;
5776
5777 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5778 SmallVector<Expr*, 8> TransformedExprs;
5779 TransformedExprs.reserve(SrcExprs.size());
5780 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5781 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5782 if (!Result.isUsable()) {
5783 HadError = true;
5784 } else {
5785 HadChange |= (Result.get() != SrcExprs[i]);
5786 TransformedExprs.push_back(Result.take());
5787 }
5788 }
5789
5790 if (HadError) return StmtError();
5791 if (!HadChange && !getDerived().AlwaysRebuild())
5792 return Owned(S);
5793
Chad Rosierb6f46c12012-08-15 16:53:30 +00005794 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00005795 AsmToks, S->getAsmString(),
5796 S->getNumOutputs(), S->getNumInputs(),
5797 S->getAllConstraints(), S->getClobbers(),
5798 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00005799}
Douglas Gregorebe10102009-08-20 07:17:43 +00005800
5801template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005802StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005803TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005804 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005805 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005806 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005807 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005808
Douglas Gregor96c79492010-04-23 22:50:49 +00005809 // Transform the @catch statements (if present).
5810 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005811 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00005812 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005813 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005814 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005815 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005816 if (Catch.get() != S->getCatchStmt(I))
5817 AnyCatchChanged = true;
5818 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005819 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005820
Douglas Gregor306de2f2010-04-22 23:59:56 +00005821 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005822 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005823 if (S->getFinallyStmt()) {
5824 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5825 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005826 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005827 }
5828
5829 // If nothing changed, just retain this statement.
5830 if (!getDerived().AlwaysRebuild() &&
5831 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005832 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005833 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00005834 return SemaRef.Owned(S);
Chad Rosier1dcde962012-08-08 18:46:20 +00005835
Douglas Gregor306de2f2010-04-22 23:59:56 +00005836 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005837 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005838 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005839}
Mike Stump11289f42009-09-09 15:08:12 +00005840
Douglas Gregorebe10102009-08-20 07:17:43 +00005841template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005842StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005843TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005844 // Transform the @catch parameter, if there is one.
5845 VarDecl *Var = 0;
5846 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5847 TypeSourceInfo *TSInfo = 0;
5848 if (FromVar->getTypeSourceInfo()) {
5849 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5850 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005851 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005852 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005853
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005854 QualType T;
5855 if (TSInfo)
5856 T = TSInfo->getType();
5857 else {
5858 T = getDerived().TransformType(FromVar->getType());
5859 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00005860 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005861 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005862
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005863 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5864 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005865 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005866 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005867
John McCalldadc5752010-08-24 06:29:42 +00005868 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005869 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005870 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005871
5872 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005873 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005874 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005875}
Mike Stump11289f42009-09-09 15:08:12 +00005876
Douglas Gregorebe10102009-08-20 07:17:43 +00005877template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005878StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005879TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005880 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005881 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005882 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005883 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005884
Douglas Gregor306de2f2010-04-22 23:59:56 +00005885 // If nothing changed, just retain this statement.
5886 if (!getDerived().AlwaysRebuild() &&
5887 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00005888 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00005889
5890 // Build a new statement.
5891 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005892 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005893}
Mike Stump11289f42009-09-09 15:08:12 +00005894
Douglas Gregorebe10102009-08-20 07:17:43 +00005895template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005896StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005897TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005898 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005899 if (S->getThrowExpr()) {
5900 Operand = getDerived().TransformExpr(S->getThrowExpr());
5901 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005902 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005903 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005904
Douglas Gregor2900c162010-04-22 21:44:01 +00005905 if (!getDerived().AlwaysRebuild() &&
5906 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005907 return getSema().Owned(S);
Chad Rosier1dcde962012-08-08 18:46:20 +00005908
John McCallb268a282010-08-23 23:25:46 +00005909 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005910}
Mike Stump11289f42009-09-09 15:08:12 +00005911
Douglas Gregorebe10102009-08-20 07:17:43 +00005912template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005913StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005914TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005915 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005916 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005917 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005918 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005919 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00005920 Object =
5921 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5922 Object.get());
5923 if (Object.isInvalid())
5924 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005925
Douglas Gregor6148de72010-04-22 22:01:21 +00005926 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005927 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005928 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005929 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005930
Douglas Gregor6148de72010-04-22 22:01:21 +00005931 // If nothing change, just retain the current statement.
5932 if (!getDerived().AlwaysRebuild() &&
5933 Object.get() == S->getSynchExpr() &&
5934 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005935 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005936
5937 // Build a new statement.
5938 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005939 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005940}
5941
5942template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005943StmtResult
John McCall31168b02011-06-15 23:02:42 +00005944TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5945 ObjCAutoreleasePoolStmt *S) {
5946 // Transform the body.
5947 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5948 if (Body.isInvalid())
5949 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005950
John McCall31168b02011-06-15 23:02:42 +00005951 // If nothing changed, just retain this statement.
5952 if (!getDerived().AlwaysRebuild() &&
5953 Body.get() == S->getSubStmt())
5954 return SemaRef.Owned(S);
5955
5956 // Build a new statement.
5957 return getDerived().RebuildObjCAutoreleasePoolStmt(
5958 S->getAtLoc(), Body.get());
5959}
5960
5961template<typename Derived>
5962StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005963TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005964 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005965 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005966 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005967 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005968 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005969
Douglas Gregorf68a5082010-04-22 23:10:45 +00005970 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00005971 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005972 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005973 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005974
Douglas Gregorf68a5082010-04-22 23:10:45 +00005975 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005976 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005977 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005978 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005979
Douglas Gregorf68a5082010-04-22 23:10:45 +00005980 // If nothing changed, just retain this statement.
5981 if (!getDerived().AlwaysRebuild() &&
5982 Element.get() == S->getElement() &&
5983 Collection.get() == S->getCollection() &&
5984 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005985 return SemaRef.Owned(S);
Chad Rosier1dcde962012-08-08 18:46:20 +00005986
Douglas Gregorf68a5082010-04-22 23:10:45 +00005987 // Build a new statement.
5988 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00005989 Element.get(),
5990 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00005991 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005992 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005993}
5994
David Majnemer5f7efef2013-10-15 09:50:08 +00005995template <typename Derived>
5996StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005997 // Transform the exception declaration, if any.
5998 VarDecl *Var = 0;
David Majnemer5f7efef2013-10-15 09:50:08 +00005999 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6000 TypeSourceInfo *T =
6001 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006002 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006003 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006004
David Majnemer5f7efef2013-10-15 09:50:08 +00006005 Var = getDerived().RebuildExceptionDecl(
6006 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6007 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006008 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006009 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006010 }
Mike Stump11289f42009-09-09 15:08:12 +00006011
Douglas Gregorebe10102009-08-20 07:17:43 +00006012 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006013 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006014 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006015 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006016
David Majnemer5f7efef2013-10-15 09:50:08 +00006017 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006018 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00006019 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00006020
David Majnemer5f7efef2013-10-15 09:50:08 +00006021 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006022}
Mike Stump11289f42009-09-09 15:08:12 +00006023
David Majnemer5f7efef2013-10-15 09:50:08 +00006024template <typename Derived>
6025StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006026 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006027 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006028 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006029 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006030
Douglas Gregorebe10102009-08-20 07:17:43 +00006031 // Transform the handlers.
6032 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006033 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006034 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006035 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006036 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006037 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006038
Douglas Gregorebe10102009-08-20 07:17:43 +00006039 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
6040 Handlers.push_back(Handler.takeAs<Stmt>());
6041 }
Mike Stump11289f42009-09-09 15:08:12 +00006042
David Majnemer5f7efef2013-10-15 09:50:08 +00006043 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006044 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00006045 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00006046
John McCallb268a282010-08-23 23:25:46 +00006047 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006048 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006049}
Mike Stump11289f42009-09-09 15:08:12 +00006050
Richard Smith02e85f32011-04-14 22:09:26 +00006051template<typename Derived>
6052StmtResult
6053TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6054 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6055 if (Range.isInvalid())
6056 return StmtError();
6057
6058 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6059 if (BeginEnd.isInvalid())
6060 return StmtError();
6061
6062 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6063 if (Cond.isInvalid())
6064 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006065 if (Cond.get())
6066 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
6067 if (Cond.isInvalid())
6068 return StmtError();
6069 if (Cond.get())
6070 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smith02e85f32011-04-14 22:09:26 +00006071
6072 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6073 if (Inc.isInvalid())
6074 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006075 if (Inc.get())
6076 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smith02e85f32011-04-14 22:09:26 +00006077
6078 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6079 if (LoopVar.isInvalid())
6080 return StmtError();
6081
6082 StmtResult NewStmt = S;
6083 if (getDerived().AlwaysRebuild() ||
6084 Range.get() != S->getRangeStmt() ||
6085 BeginEnd.get() != S->getBeginEndStmt() ||
6086 Cond.get() != S->getCond() ||
6087 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006088 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006089 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6090 S->getColonLoc(), Range.get(),
6091 BeginEnd.get(), Cond.get(),
6092 Inc.get(), LoopVar.get(),
6093 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006094 if (NewStmt.isInvalid())
6095 return StmtError();
6096 }
Richard Smith02e85f32011-04-14 22:09:26 +00006097
6098 StmtResult Body = getDerived().TransformStmt(S->getBody());
6099 if (Body.isInvalid())
6100 return StmtError();
6101
6102 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6103 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006104 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006105 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6106 S->getColonLoc(), Range.get(),
6107 BeginEnd.get(), Cond.get(),
6108 Inc.get(), LoopVar.get(),
6109 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006110 if (NewStmt.isInvalid())
6111 return StmtError();
6112 }
Richard Smith02e85f32011-04-14 22:09:26 +00006113
6114 if (NewStmt.get() == S)
6115 return SemaRef.Owned(S);
6116
6117 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6118}
6119
John Wiegley1c0675e2011-04-28 01:08:34 +00006120template<typename Derived>
6121StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006122TreeTransform<Derived>::TransformMSDependentExistsStmt(
6123 MSDependentExistsStmt *S) {
6124 // Transform the nested-name-specifier, if any.
6125 NestedNameSpecifierLoc QualifierLoc;
6126 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006127 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006128 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6129 if (!QualifierLoc)
6130 return StmtError();
6131 }
6132
6133 // Transform the declaration name.
6134 DeclarationNameInfo NameInfo = S->getNameInfo();
6135 if (NameInfo.getName()) {
6136 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6137 if (!NameInfo.getName())
6138 return StmtError();
6139 }
6140
6141 // Check whether anything changed.
6142 if (!getDerived().AlwaysRebuild() &&
6143 QualifierLoc == S->getQualifierLoc() &&
6144 NameInfo.getName() == S->getNameInfo().getName())
6145 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006146
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006147 // Determine whether this name exists, if we can.
6148 CXXScopeSpec SS;
6149 SS.Adopt(QualifierLoc);
6150 bool Dependent = false;
6151 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
6152 case Sema::IER_Exists:
6153 if (S->isIfExists())
6154 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006155
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006156 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6157
6158 case Sema::IER_DoesNotExist:
6159 if (S->isIfNotExists())
6160 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006161
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006162 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006163
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006164 case Sema::IER_Dependent:
6165 Dependent = true;
6166 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006167
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006168 case Sema::IER_Error:
6169 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006170 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006171
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006172 // We need to continue with the instantiation, so do so now.
6173 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6174 if (SubStmt.isInvalid())
6175 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006176
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006177 // If we have resolved the name, just transform to the substatement.
6178 if (!Dependent)
6179 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006180
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006181 // The name is still dependent, so build a dependent expression again.
6182 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6183 S->isIfExists(),
6184 QualifierLoc,
6185 NameInfo,
6186 SubStmt.get());
6187}
6188
6189template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006190ExprResult
6191TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6192 NestedNameSpecifierLoc QualifierLoc;
6193 if (E->getQualifierLoc()) {
6194 QualifierLoc
6195 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6196 if (!QualifierLoc)
6197 return ExprError();
6198 }
6199
6200 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6201 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6202 if (!PD)
6203 return ExprError();
6204
6205 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6206 if (Base.isInvalid())
6207 return ExprError();
6208
6209 return new (SemaRef.getASTContext())
6210 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6211 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6212 QualifierLoc, E->getMemberLoc());
6213}
6214
David Majnemerfad8f482013-10-15 09:33:02 +00006215template <typename Derived>
6216StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006217 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006218 if (TryBlock.isInvalid())
6219 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006220
6221 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006222 if (Handler.isInvalid())
6223 return StmtError();
6224
David Majnemerfad8f482013-10-15 09:33:02 +00006225 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6226 Handler.get() == S->getHandler())
John Wiegley1c0675e2011-04-28 01:08:34 +00006227 return SemaRef.Owned(S);
6228
David Majnemerfad8f482013-10-15 09:33:02 +00006229 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
6230 TryBlock.take(), Handler.take());
John Wiegley1c0675e2011-04-28 01:08:34 +00006231}
6232
David Majnemerfad8f482013-10-15 09:33:02 +00006233template <typename Derived>
6234StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
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().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.take());
John Wiegley1c0675e2011-04-28 01:08:34 +00006240}
6241
David Majnemerfad8f482013-10-15 09:33:02 +00006242template <typename Derived>
6243StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00006244 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00006245 if (FilterExpr.isInvalid())
6246 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006247
David Majnemer7e755502013-10-15 09:30:14 +00006248 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006249 if (Block.isInvalid())
6250 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006251
David Majnemerfad8f482013-10-15 09:33:02 +00006252 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.take(),
John Wiegley1c0675e2011-04-28 01:08:34 +00006253 Block.take());
6254}
6255
David Majnemerfad8f482013-10-15 09:33:02 +00006256template <typename Derived>
6257StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6258 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00006259 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6260 else
6261 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6262}
6263
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006264template<typename Derived>
6265StmtResult
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006266TreeTransform<Derived>::TransformOMPExecutableDirective(
6267 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006268
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006269 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00006270 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006271 ArrayRef<OMPClause *> Clauses = D->clauses();
6272 TClauses.reserve(Clauses.size());
6273 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6274 I != E; ++I) {
6275 if (*I) {
6276 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataev758e55e2013-09-06 18:03:48 +00006277 if (!Clause) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006278 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006279 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006280 TClauses.push_back(Clause);
6281 }
6282 else {
6283 TClauses.push_back(0);
6284 }
6285 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00006286 if (!D->getAssociatedStmt()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006287 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006288 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006289 StmtResult AssociatedStmt =
6290 getDerived().TransformStmt(D->getAssociatedStmt());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006291 if (AssociatedStmt.isInvalid()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006292 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006293 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006294
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006295 return getDerived().RebuildOMPExecutableDirective(D->getDirectiveKind(),
6296 TClauses,
6297 AssociatedStmt.take(),
6298 D->getLocStart(),
6299 D->getLocEnd());
6300}
6301
6302template<typename Derived>
6303StmtResult
6304TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6305 DeclarationNameInfo DirName;
Alexey Bataev3d76e772014-03-07 04:01:56 +00006306 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, 0);
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006307 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6308 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6309 return Res;
6310}
6311
6312template<typename Derived>
6313StmtResult
6314TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
6315 DeclarationNameInfo DirName;
Alexey Bataev96d15102014-03-07 04:16:48 +00006316 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, 0);
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006317 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6318 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006319 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006320}
6321
6322template<typename Derived>
6323OMPClause *
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006324TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00006325 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6326 if (Cond.isInvalid())
6327 return 0;
6328 return getDerived().RebuildOMPIfClause(Cond.take(), C->getLocStart(),
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006329 C->getLParenLoc(), C->getLocEnd());
6330}
6331
6332template<typename Derived>
6333OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00006334TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
6335 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
6336 if (NumThreads.isInvalid())
6337 return 0;
6338 return getDerived().RebuildOMPNumThreadsClause(NumThreads.take(),
6339 C->getLocStart(),
6340 C->getLParenLoc(),
6341 C->getLocEnd());
6342}
6343
6344template<typename Derived>
6345OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006346TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
6347 return getDerived().RebuildOMPDefaultClause(C->getDefaultKind(),
6348 C->getDefaultKindKwLoc(),
6349 C->getLocStart(),
6350 C->getLParenLoc(),
6351 C->getLocEnd());
6352}
6353
6354template<typename Derived>
6355OMPClause *
6356TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006357 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006358 Vars.reserve(C->varlist_size());
Aaron Ballman2205d2a2014-03-14 15:55:35 +00006359 for (auto *I : C->varlists()) {
6360 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(I));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006361 if (EVar.isInvalid())
6362 return 0;
6363 Vars.push_back(EVar.take());
6364 }
6365 return getDerived().RebuildOMPPrivateClause(Vars,
6366 C->getLocStart(),
6367 C->getLParenLoc(),
6368 C->getLocEnd());
6369}
6370
Alexey Bataev758e55e2013-09-06 18:03:48 +00006371template<typename Derived>
6372OMPClause *
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006373TreeTransform<Derived>::TransformOMPFirstprivateClause(
6374 OMPFirstprivateClause *C) {
6375 llvm::SmallVector<Expr *, 16> Vars;
6376 Vars.reserve(C->varlist_size());
Aaron Ballman2205d2a2014-03-14 15:55:35 +00006377 for (auto *I : C->varlists()) {
6378 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(I));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006379 if (EVar.isInvalid())
6380 return 0;
6381 Vars.push_back(EVar.take());
6382 }
6383 return getDerived().RebuildOMPFirstprivateClause(Vars,
6384 C->getLocStart(),
6385 C->getLParenLoc(),
6386 C->getLocEnd());
6387}
6388
6389template<typename Derived>
6390OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00006391TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
6392 llvm::SmallVector<Expr *, 16> Vars;
6393 Vars.reserve(C->varlist_size());
Aaron Ballman2205d2a2014-03-14 15:55:35 +00006394 for (auto *I : C->varlists()) {
6395 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(I));
Alexey Bataev758e55e2013-09-06 18:03:48 +00006396 if (EVar.isInvalid())
6397 return 0;
6398 Vars.push_back(EVar.take());
6399 }
6400 return getDerived().RebuildOMPSharedClause(Vars,
6401 C->getLocStart(),
6402 C->getLParenLoc(),
6403 C->getLocEnd());
6404}
6405
Douglas Gregorebe10102009-08-20 07:17:43 +00006406//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00006407// Expression transformation
6408//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00006409template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006410ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006411TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006412 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006413}
Mike Stump11289f42009-09-09 15:08:12 +00006414
6415template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006416ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006417TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006418 NestedNameSpecifierLoc QualifierLoc;
6419 if (E->getQualifierLoc()) {
6420 QualifierLoc
6421 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6422 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006423 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006424 }
John McCallce546572009-12-08 09:08:17 +00006425
6426 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006427 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6428 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006429 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00006430 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006431
John McCall815039a2010-08-17 21:27:17 +00006432 DeclarationNameInfo NameInfo = E->getNameInfo();
6433 if (NameInfo.getName()) {
6434 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6435 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006436 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00006437 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006438
6439 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006440 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006441 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006442 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00006443 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006444
6445 // Mark it referenced in the new context regardless.
6446 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00006447 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00006448
John McCallc3007a22010-10-26 07:05:15 +00006449 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006450 }
John McCallce546572009-12-08 09:08:17 +00006451
6452 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00006453 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006454 TemplateArgs = &TransArgs;
6455 TransArgs.setLAngleLoc(E->getLAngleLoc());
6456 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006457 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6458 E->getNumTemplateArgs(),
6459 TransArgs))
6460 return ExprError();
John McCallce546572009-12-08 09:08:17 +00006461 }
6462
Chad Rosier1dcde962012-08-08 18:46:20 +00006463 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00006464 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006465}
Mike Stump11289f42009-09-09 15:08:12 +00006466
Douglas Gregora16548e2009-08-11 05:31:07 +00006467template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006468ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006469TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006470 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006471}
Mike Stump11289f42009-09-09 15:08:12 +00006472
Douglas Gregora16548e2009-08-11 05:31:07 +00006473template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006474ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006475TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006476 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006477}
Mike Stump11289f42009-09-09 15:08:12 +00006478
Douglas Gregora16548e2009-08-11 05:31:07 +00006479template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006480ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006481TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006482 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006483}
Mike Stump11289f42009-09-09 15:08:12 +00006484
Douglas Gregora16548e2009-08-11 05:31:07 +00006485template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006486ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006487TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006488 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006489}
Mike Stump11289f42009-09-09 15:08:12 +00006490
Douglas Gregora16548e2009-08-11 05:31:07 +00006491template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006492ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006493TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006494 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006495}
6496
6497template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006498ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00006499TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00006500 if (FunctionDecl *FD = E->getDirectCallee())
6501 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00006502 return SemaRef.MaybeBindToTemporary(E);
6503}
6504
6505template<typename Derived>
6506ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00006507TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6508 ExprResult ControllingExpr =
6509 getDerived().TransformExpr(E->getControllingExpr());
6510 if (ControllingExpr.isInvalid())
6511 return ExprError();
6512
Chris Lattner01cf8db2011-07-20 06:58:45 +00006513 SmallVector<Expr *, 4> AssocExprs;
6514 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00006515 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6516 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6517 if (TS) {
6518 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6519 if (!AssocType)
6520 return ExprError();
6521 AssocTypes.push_back(AssocType);
6522 } else {
6523 AssocTypes.push_back(0);
6524 }
6525
6526 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6527 if (AssocExpr.isInvalid())
6528 return ExprError();
6529 AssocExprs.push_back(AssocExpr.release());
6530 }
6531
6532 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6533 E->getDefaultLoc(),
6534 E->getRParenLoc(),
6535 ControllingExpr.release(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00006536 AssocTypes,
6537 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00006538}
6539
6540template<typename Derived>
6541ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006542TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006543 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006544 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006545 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006546
Douglas Gregora16548e2009-08-11 05:31:07 +00006547 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006548 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006549
John McCallb268a282010-08-23 23:25:46 +00006550 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006551 E->getRParen());
6552}
6553
Richard Smithdb2630f2012-10-21 03:28:35 +00006554/// \brief The operand of a unary address-of operator has special rules: it's
6555/// allowed to refer to a non-static member of a class even if there's no 'this'
6556/// object available.
6557template<typename Derived>
6558ExprResult
6559TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6560 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6561 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6562 else
6563 return getDerived().TransformExpr(E);
6564}
6565
Mike Stump11289f42009-09-09 15:08:12 +00006566template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006567ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006568TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00006569 ExprResult SubExpr;
6570 if (E->getOpcode() == UO_AddrOf)
6571 SubExpr = TransformAddressOfOperand(E->getSubExpr());
6572 else
6573 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006574 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006575 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006576
Douglas Gregora16548e2009-08-11 05:31:07 +00006577 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006578 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006579
Douglas Gregora16548e2009-08-11 05:31:07 +00006580 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6581 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006582 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006583}
Mike Stump11289f42009-09-09 15:08:12 +00006584
Douglas Gregora16548e2009-08-11 05:31:07 +00006585template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006586ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00006587TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6588 // Transform the type.
6589 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6590 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00006591 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006592
Douglas Gregor882211c2010-04-28 22:16:22 +00006593 // Transform all of the components into components similar to what the
6594 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00006595 // FIXME: It would be slightly more efficient in the non-dependent case to
6596 // just map FieldDecls, rather than requiring the rebuilder to look for
6597 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00006598 // template code that we don't care.
6599 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00006600 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00006601 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006602 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00006603 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6604 const Node &ON = E->getComponent(I);
6605 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00006606 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00006607 Comp.LocStart = ON.getSourceRange().getBegin();
6608 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00006609 switch (ON.getKind()) {
6610 case Node::Array: {
6611 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00006612 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00006613 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006614 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006615
Douglas Gregor882211c2010-04-28 22:16:22 +00006616 ExprChanged = ExprChanged || Index.get() != FromIndex;
6617 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00006618 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00006619 break;
6620 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006621
Douglas Gregor882211c2010-04-28 22:16:22 +00006622 case Node::Field:
6623 case Node::Identifier:
6624 Comp.isBrackets = false;
6625 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00006626 if (!Comp.U.IdentInfo)
6627 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00006628
Douglas Gregor882211c2010-04-28 22:16:22 +00006629 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006630
Douglas Gregord1702062010-04-29 00:18:15 +00006631 case Node::Base:
6632 // Will be recomputed during the rebuild.
6633 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00006634 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006635
Douglas Gregor882211c2010-04-28 22:16:22 +00006636 Components.push_back(Comp);
6637 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006638
Douglas Gregor882211c2010-04-28 22:16:22 +00006639 // If nothing changed, retain the existing expression.
6640 if (!getDerived().AlwaysRebuild() &&
6641 Type == E->getTypeSourceInfo() &&
6642 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00006643 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00006644
Douglas Gregor882211c2010-04-28 22:16:22 +00006645 // Build a new offsetof expression.
6646 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6647 Components.data(), Components.size(),
6648 E->getRParenLoc());
6649}
6650
6651template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006652ExprResult
John McCall8d69a212010-11-15 23:31:06 +00006653TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6654 assert(getDerived().AlreadyTransformed(E->getType()) &&
6655 "opaque value expression requires transformation");
6656 return SemaRef.Owned(E);
6657}
6658
6659template<typename Derived>
6660ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00006661TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00006662 // Rebuild the syntactic form. The original syntactic form has
6663 // opaque-value expressions in it, so strip those away and rebuild
6664 // the result. This is a really awful way of doing this, but the
6665 // better solution (rebuilding the semantic expressions and
6666 // rebinding OVEs as necessary) doesn't work; we'd need
6667 // TreeTransform to not strip away implicit conversions.
6668 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6669 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00006670 if (result.isInvalid()) return ExprError();
6671
6672 // If that gives us a pseudo-object result back, the pseudo-object
6673 // expression must have been an lvalue-to-rvalue conversion which we
6674 // should reapply.
6675 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6676 result = SemaRef.checkPseudoObjectRValue(result.take());
6677
6678 return result;
6679}
6680
6681template<typename Derived>
6682ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00006683TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6684 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006685 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00006686 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00006687
John McCallbcd03502009-12-07 02:54:59 +00006688 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00006689 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006690 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006691
John McCall4c98fd82009-11-04 07:28:41 +00006692 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00006693 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006694
Peter Collingbournee190dee2011-03-11 19:24:49 +00006695 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6696 E->getKind(),
6697 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006698 }
Mike Stump11289f42009-09-09 15:08:12 +00006699
Eli Friedmane4f22df2012-02-29 04:03:55 +00006700 // C++0x [expr.sizeof]p1:
6701 // The operand is either an expression, which is an unevaluated operand
6702 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00006703 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6704 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00006705
Eli Friedmane4f22df2012-02-29 04:03:55 +00006706 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6707 if (SubExpr.isInvalid())
6708 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006709
Eli Friedmane4f22df2012-02-29 04:03:55 +00006710 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6711 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006712
Peter Collingbournee190dee2011-03-11 19:24:49 +00006713 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6714 E->getOperatorLoc(),
6715 E->getKind(),
6716 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006717}
Mike Stump11289f42009-09-09 15:08:12 +00006718
Douglas Gregora16548e2009-08-11 05:31:07 +00006719template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006720ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006721TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006722 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006723 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006724 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006725
John McCalldadc5752010-08-24 06:29:42 +00006726 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006727 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006728 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006729
6730
Douglas Gregora16548e2009-08-11 05:31:07 +00006731 if (!getDerived().AlwaysRebuild() &&
6732 LHS.get() == E->getLHS() &&
6733 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006734 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006735
John McCallb268a282010-08-23 23:25:46 +00006736 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006737 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006738 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006739 E->getRBracketLoc());
6740}
Mike Stump11289f42009-09-09 15:08:12 +00006741
6742template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006743ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006744TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006745 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00006746 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006747 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006748 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006749
6750 // Transform arguments.
6751 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006752 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00006753 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00006754 &ArgChanged))
6755 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006756
Douglas Gregora16548e2009-08-11 05:31:07 +00006757 if (!getDerived().AlwaysRebuild() &&
6758 Callee.get() == E->getCallee() &&
6759 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00006760 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00006761
Douglas Gregora16548e2009-08-11 05:31:07 +00006762 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00006763 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006764 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00006765 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006766 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00006767 E->getRParenLoc());
6768}
Mike Stump11289f42009-09-09 15:08:12 +00006769
6770template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006771ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006772TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006773 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006774 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006775 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006776
Douglas Gregorea972d32011-02-28 21:54:11 +00006777 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006778 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006779 QualifierLoc
6780 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006781
Douglas Gregorea972d32011-02-28 21:54:11 +00006782 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006783 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006784 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00006785 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00006786
Eli Friedman2cfcef62009-12-04 06:40:45 +00006787 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006788 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6789 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006790 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00006791 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006792
John McCall16df1e52010-03-30 21:47:33 +00006793 NamedDecl *FoundDecl = E->getFoundDecl();
6794 if (FoundDecl == E->getMemberDecl()) {
6795 FoundDecl = Member;
6796 } else {
6797 FoundDecl = cast_or_null<NamedDecl>(
6798 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6799 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00006800 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00006801 }
6802
Douglas Gregora16548e2009-08-11 05:31:07 +00006803 if (!getDerived().AlwaysRebuild() &&
6804 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006805 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006806 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00006807 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00006808 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006809
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006810 // Mark it referenced in the new context regardless.
6811 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00006812 SemaRef.MarkMemberReferenced(E);
6813
John McCallc3007a22010-10-26 07:05:15 +00006814 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006815 }
Douglas Gregora16548e2009-08-11 05:31:07 +00006816
John McCall6b51f282009-11-23 01:53:49 +00006817 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00006818 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00006819 TransArgs.setLAngleLoc(E->getLAngleLoc());
6820 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006821 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6822 E->getNumTemplateArgs(),
6823 TransArgs))
6824 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006825 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006826
Douglas Gregora16548e2009-08-11 05:31:07 +00006827 // FIXME: Bogus source location for the operator
6828 SourceLocation FakeOperatorLoc
6829 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6830
John McCall38836f02010-01-15 08:34:02 +00006831 // FIXME: to do this check properly, we will need to preserve the
6832 // first-qualifier-in-scope here, just in case we had a dependent
6833 // base (and therefore couldn't do the check) and a
6834 // nested-name-qualifier (and therefore could do the lookup).
6835 NamedDecl *FirstQualifierInScope = 0;
6836
John McCallb268a282010-08-23 23:25:46 +00006837 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006838 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00006839 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00006840 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006841 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006842 Member,
John McCall16df1e52010-03-30 21:47:33 +00006843 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00006844 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00006845 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00006846 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00006847}
Mike Stump11289f42009-09-09 15:08:12 +00006848
Douglas Gregora16548e2009-08-11 05:31:07 +00006849template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006850ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006851TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006852 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006853 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006854 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006855
John McCalldadc5752010-08-24 06:29:42 +00006856 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006857 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006858 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006859
Douglas Gregora16548e2009-08-11 05:31:07 +00006860 if (!getDerived().AlwaysRebuild() &&
6861 LHS.get() == E->getLHS() &&
6862 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006863 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006864
Lang Hames5de91cc2012-10-02 04:45:10 +00006865 Sema::FPContractStateRAII FPContractState(getSema());
6866 getSema().FPFeatures.fp_contract = E->isFPContractable();
6867
Douglas Gregora16548e2009-08-11 05:31:07 +00006868 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006869 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006870}
6871
Mike Stump11289f42009-09-09 15:08:12 +00006872template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006873ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006874TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00006875 CompoundAssignOperator *E) {
6876 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006877}
Mike Stump11289f42009-09-09 15:08:12 +00006878
Douglas Gregora16548e2009-08-11 05:31:07 +00006879template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00006880ExprResult TreeTransform<Derived>::
6881TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6882 // Just rebuild the common and RHS expressions and see whether we
6883 // get any changes.
6884
6885 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6886 if (commonExpr.isInvalid())
6887 return ExprError();
6888
6889 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6890 if (rhs.isInvalid())
6891 return ExprError();
6892
6893 if (!getDerived().AlwaysRebuild() &&
6894 commonExpr.get() == e->getCommon() &&
6895 rhs.get() == e->getFalseExpr())
6896 return SemaRef.Owned(e);
6897
6898 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6899 e->getQuestionLoc(),
6900 0,
6901 e->getColonLoc(),
6902 rhs.get());
6903}
6904
6905template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006906ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006907TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006908 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006909 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006910 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006911
John McCalldadc5752010-08-24 06:29:42 +00006912 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006913 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006914 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006915
John McCalldadc5752010-08-24 06:29:42 +00006916 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006917 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006918 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006919
Douglas Gregora16548e2009-08-11 05:31:07 +00006920 if (!getDerived().AlwaysRebuild() &&
6921 Cond.get() == E->getCond() &&
6922 LHS.get() == E->getLHS() &&
6923 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006924 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006925
John McCallb268a282010-08-23 23:25:46 +00006926 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006927 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00006928 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006929 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006930 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006931}
Mike Stump11289f42009-09-09 15:08:12 +00006932
6933template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006934ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006935TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00006936 // Implicit casts are eliminated during transformation, since they
6937 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00006938 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006939}
Mike Stump11289f42009-09-09 15:08:12 +00006940
Douglas Gregora16548e2009-08-11 05:31:07 +00006941template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006942ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006943TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006944 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6945 if (!Type)
6946 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006947
John McCalldadc5752010-08-24 06:29:42 +00006948 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006949 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006950 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006951 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006952
Douglas Gregora16548e2009-08-11 05:31:07 +00006953 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006954 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006955 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006956 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006957
John McCall97513962010-01-15 18:39:57 +00006958 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006959 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006960 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006961 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006962}
Mike Stump11289f42009-09-09 15:08:12 +00006963
Douglas Gregora16548e2009-08-11 05:31:07 +00006964template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006965ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006966TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00006967 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6968 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6969 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006970 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006971
John McCalldadc5752010-08-24 06:29:42 +00006972 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00006973 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006974 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006975
Douglas Gregora16548e2009-08-11 05:31:07 +00006976 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00006977 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006978 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00006979 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006980
John McCall5d7aa7f2010-01-19 22:33:45 +00006981 // Note: the expression type doesn't necessarily match the
6982 // type-as-written, but that's okay, because it should always be
6983 // derivable from the initializer.
6984
John McCalle15bbff2010-01-18 19:35:47 +00006985 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00006986 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00006987 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006988}
Mike Stump11289f42009-09-09 15:08:12 +00006989
Douglas Gregora16548e2009-08-11 05:31:07 +00006990template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006991ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006992TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006993 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006994 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006995 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006996
Douglas Gregora16548e2009-08-11 05:31:07 +00006997 if (!getDerived().AlwaysRebuild() &&
6998 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006999 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007000
Douglas Gregora16548e2009-08-11 05:31:07 +00007001 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00007002 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00007003 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00007004 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007005 E->getAccessorLoc(),
7006 E->getAccessor());
7007}
Mike Stump11289f42009-09-09 15:08:12 +00007008
Douglas Gregora16548e2009-08-11 05:31:07 +00007009template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007010ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007011TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007012 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00007013
Benjamin Kramerf0623432012-08-23 22:51:59 +00007014 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00007015 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00007016 Inits, &InitChanged))
7017 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007018
Douglas Gregora16548e2009-08-11 05:31:07 +00007019 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00007020 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007021
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007022 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00007023 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007024}
Mike Stump11289f42009-09-09 15:08:12 +00007025
Douglas Gregora16548e2009-08-11 05:31:07 +00007026template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007027ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007028TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007029 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00007030
Douglas Gregorebe10102009-08-20 07:17:43 +00007031 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00007032 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007033 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007034 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007035
Douglas Gregorebe10102009-08-20 07:17:43 +00007036 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007037 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00007038 bool ExprChanged = false;
7039 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
7040 DEnd = E->designators_end();
7041 D != DEnd; ++D) {
7042 if (D->isFieldDesignator()) {
7043 Desig.AddDesignator(Designator::getField(D->getFieldName(),
7044 D->getDotLoc(),
7045 D->getFieldLoc()));
7046 continue;
7047 }
Mike Stump11289f42009-09-09 15:08:12 +00007048
Douglas Gregora16548e2009-08-11 05:31:07 +00007049 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00007050 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007051 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007052 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007053
7054 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007055 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007056
Douglas Gregora16548e2009-08-11 05:31:07 +00007057 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
7058 ArrayExprs.push_back(Index.release());
7059 continue;
7060 }
Mike Stump11289f42009-09-09 15:08:12 +00007061
Douglas Gregora16548e2009-08-11 05:31:07 +00007062 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00007063 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00007064 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7065 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007066 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007067
John McCalldadc5752010-08-24 06:29:42 +00007068 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007069 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007070 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007071
7072 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007073 End.get(),
7074 D->getLBracketLoc(),
7075 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007076
Douglas Gregora16548e2009-08-11 05:31:07 +00007077 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7078 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00007079
Douglas Gregora16548e2009-08-11 05:31:07 +00007080 ArrayExprs.push_back(Start.release());
7081 ArrayExprs.push_back(End.release());
7082 }
Mike Stump11289f42009-09-09 15:08:12 +00007083
Douglas Gregora16548e2009-08-11 05:31:07 +00007084 if (!getDerived().AlwaysRebuild() &&
7085 Init.get() == E->getInit() &&
7086 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00007087 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007088
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007089 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007090 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007091 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007092}
Mike Stump11289f42009-09-09 15:08:12 +00007093
Douglas Gregora16548e2009-08-11 05:31:07 +00007094template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007095ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007096TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007097 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00007098 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00007099
Douglas Gregor3da3c062009-10-28 00:29:27 +00007100 // FIXME: Will we ever have proper type location here? Will we actually
7101 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00007102 QualType T = getDerived().TransformType(E->getType());
7103 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007104 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007105
Douglas Gregora16548e2009-08-11 05:31:07 +00007106 if (!getDerived().AlwaysRebuild() &&
7107 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00007108 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007109
Douglas Gregora16548e2009-08-11 05:31:07 +00007110 return getDerived().RebuildImplicitValueInitExpr(T);
7111}
Mike Stump11289f42009-09-09 15:08:12 +00007112
Douglas Gregora16548e2009-08-11 05:31:07 +00007113template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007114ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007115TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00007116 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7117 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007118 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007119
John McCalldadc5752010-08-24 06:29:42 +00007120 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007121 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007122 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007123
Douglas Gregora16548e2009-08-11 05:31:07 +00007124 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00007125 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007126 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007127 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007128
John McCallb268a282010-08-23 23:25:46 +00007129 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00007130 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007131}
7132
7133template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007134ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007135TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007136 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007137 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00007138 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7139 &ArgumentChanged))
7140 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007141
Douglas Gregora16548e2009-08-11 05:31:07 +00007142 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007143 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00007144 E->getRParenLoc());
7145}
Mike Stump11289f42009-09-09 15:08:12 +00007146
Douglas Gregora16548e2009-08-11 05:31:07 +00007147/// \brief Transform an address-of-label expression.
7148///
7149/// By default, the transformation of an address-of-label expression always
7150/// rebuilds the expression, so that the label identifier can be resolved to
7151/// the corresponding label statement by semantic analysis.
7152template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007153ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007154TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00007155 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7156 E->getLabel());
7157 if (!LD)
7158 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007159
Douglas Gregora16548e2009-08-11 05:31:07 +00007160 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00007161 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00007162}
Mike Stump11289f42009-09-09 15:08:12 +00007163
7164template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00007165ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007166TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00007167 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00007168 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00007169 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00007170 if (SubStmt.isInvalid()) {
7171 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00007172 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00007173 }
Mike Stump11289f42009-09-09 15:08:12 +00007174
Douglas Gregora16548e2009-08-11 05:31:07 +00007175 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00007176 SubStmt.get() == E->getSubStmt()) {
7177 // Calling this an 'error' is unintuitive, but it does the right thing.
7178 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007179 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00007180 }
Mike Stump11289f42009-09-09 15:08:12 +00007181
7182 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007183 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007184 E->getRParenLoc());
7185}
Mike Stump11289f42009-09-09 15:08:12 +00007186
Douglas Gregora16548e2009-08-11 05:31:07 +00007187template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007188ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007189TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007190 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007191 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007192 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007193
John McCalldadc5752010-08-24 06:29:42 +00007194 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007195 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007196 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007197
John McCalldadc5752010-08-24 06:29:42 +00007198 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007199 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007200 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007201
Douglas Gregora16548e2009-08-11 05:31:07 +00007202 if (!getDerived().AlwaysRebuild() &&
7203 Cond.get() == E->getCond() &&
7204 LHS.get() == E->getLHS() &&
7205 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00007206 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007207
Douglas Gregora16548e2009-08-11 05:31:07 +00007208 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00007209 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007210 E->getRParenLoc());
7211}
Mike Stump11289f42009-09-09 15:08:12 +00007212
Douglas Gregora16548e2009-08-11 05:31:07 +00007213template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007214ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007215TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007216 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007217}
7218
7219template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007220ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007221TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007222 switch (E->getOperator()) {
7223 case OO_New:
7224 case OO_Delete:
7225 case OO_Array_New:
7226 case OO_Array_Delete:
7227 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00007228
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007229 case OO_Call: {
7230 // This is a call to an object's operator().
7231 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7232
7233 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00007234 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007235 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007236 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007237
7238 // FIXME: Poor location information
7239 SourceLocation FakeLParenLoc
7240 = SemaRef.PP.getLocForEndOfToken(
7241 static_cast<Expr *>(Object.get())->getLocEnd());
7242
7243 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007244 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007245 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00007246 Args))
7247 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007248
John McCallb268a282010-08-23 23:25:46 +00007249 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007250 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007251 E->getLocEnd());
7252 }
7253
7254#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7255 case OO_##Name:
7256#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7257#include "clang/Basic/OperatorKinds.def"
7258 case OO_Subscript:
7259 // Handled below.
7260 break;
7261
7262 case OO_Conditional:
7263 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007264
7265 case OO_None:
7266 case NUM_OVERLOADED_OPERATORS:
7267 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007268 }
7269
John McCalldadc5752010-08-24 06:29:42 +00007270 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007271 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007272 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007273
Richard Smithdb2630f2012-10-21 03:28:35 +00007274 ExprResult First;
7275 if (E->getOperator() == OO_Amp)
7276 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7277 else
7278 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007279 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007280 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007281
John McCalldadc5752010-08-24 06:29:42 +00007282 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00007283 if (E->getNumArgs() == 2) {
7284 Second = getDerived().TransformExpr(E->getArg(1));
7285 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007286 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007287 }
Mike Stump11289f42009-09-09 15:08:12 +00007288
Douglas Gregora16548e2009-08-11 05:31:07 +00007289 if (!getDerived().AlwaysRebuild() &&
7290 Callee.get() == E->getCallee() &&
7291 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00007292 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007293 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007294
Lang Hames5de91cc2012-10-02 04:45:10 +00007295 Sema::FPContractStateRAII FPContractState(getSema());
7296 getSema().FPFeatures.fp_contract = E->isFPContractable();
7297
Douglas Gregora16548e2009-08-11 05:31:07 +00007298 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7299 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00007300 Callee.get(),
7301 First.get(),
7302 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007303}
Mike Stump11289f42009-09-09 15:08:12 +00007304
Douglas Gregora16548e2009-08-11 05:31:07 +00007305template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007306ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007307TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7308 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007309}
Mike Stump11289f42009-09-09 15:08:12 +00007310
Douglas Gregora16548e2009-08-11 05:31:07 +00007311template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007312ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00007313TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7314 // Transform the callee.
7315 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7316 if (Callee.isInvalid())
7317 return ExprError();
7318
7319 // Transform exec config.
7320 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7321 if (EC.isInvalid())
7322 return ExprError();
7323
7324 // Transform arguments.
7325 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007326 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007327 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007328 &ArgChanged))
7329 return ExprError();
7330
7331 if (!getDerived().AlwaysRebuild() &&
7332 Callee.get() == E->getCallee() &&
7333 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007334 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00007335
7336 // FIXME: Wrong source location information for the '('.
7337 SourceLocation FakeLParenLoc
7338 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7339 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007340 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007341 E->getRParenLoc(), EC.get());
7342}
7343
7344template<typename Derived>
7345ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007346TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007347 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7348 if (!Type)
7349 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007350
John McCalldadc5752010-08-24 06:29:42 +00007351 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007352 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007353 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007354 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007355
Douglas Gregora16548e2009-08-11 05:31:07 +00007356 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007357 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007358 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007359 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007360 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00007361 E->getStmtClass(),
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007362 E->getAngleBrackets().getBegin(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007363 Type,
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007364 E->getAngleBrackets().getEnd(),
7365 // FIXME. this should be '(' location
7366 E->getAngleBrackets().getEnd(),
John McCallb268a282010-08-23 23:25:46 +00007367 SubExpr.get(),
Abramo Bagnara9fb43862012-10-15 21:08:58 +00007368 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007369}
Mike Stump11289f42009-09-09 15:08:12 +00007370
Douglas Gregora16548e2009-08-11 05:31:07 +00007371template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007372ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007373TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7374 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007375}
Mike Stump11289f42009-09-09 15:08:12 +00007376
7377template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007378ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007379TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7380 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00007381}
7382
Douglas Gregora16548e2009-08-11 05:31:07 +00007383template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007384ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007385TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007386 CXXReinterpretCastExpr *E) {
7387 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007388}
Mike Stump11289f42009-09-09 15:08:12 +00007389
Douglas Gregora16548e2009-08-11 05:31:07 +00007390template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007391ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007392TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7393 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007394}
Mike Stump11289f42009-09-09 15:08:12 +00007395
Douglas Gregora16548e2009-08-11 05:31:07 +00007396template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007397ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007398TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007399 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007400 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7401 if (!Type)
7402 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007403
John McCalldadc5752010-08-24 06:29:42 +00007404 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007405 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007406 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007407 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007408
Douglas Gregora16548e2009-08-11 05:31:07 +00007409 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007410 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007411 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007412 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007413
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007414 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00007415 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007416 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007417 E->getRParenLoc());
7418}
Mike Stump11289f42009-09-09 15:08:12 +00007419
Douglas Gregora16548e2009-08-11 05:31:07 +00007420template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007421ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007422TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007423 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00007424 TypeSourceInfo *TInfo
7425 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7426 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007427 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007428
Douglas Gregora16548e2009-08-11 05:31:07 +00007429 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00007430 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007431 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007432
Douglas Gregor9da64192010-04-26 22:37:10 +00007433 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7434 E->getLocStart(),
7435 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007436 E->getLocEnd());
7437 }
Mike Stump11289f42009-09-09 15:08:12 +00007438
Eli Friedman456f0182012-01-20 01:26:23 +00007439 // We don't know whether the subexpression is potentially evaluated until
7440 // after we perform semantic analysis. We speculatively assume it is
7441 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00007442 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00007443 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7444 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007445
John McCalldadc5752010-08-24 06:29:42 +00007446 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00007447 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007448 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007449
Douglas Gregora16548e2009-08-11 05:31:07 +00007450 if (!getDerived().AlwaysRebuild() &&
7451 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00007452 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007453
Douglas Gregor9da64192010-04-26 22:37:10 +00007454 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7455 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007456 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007457 E->getLocEnd());
7458}
7459
7460template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007461ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00007462TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7463 if (E->isTypeOperand()) {
7464 TypeSourceInfo *TInfo
7465 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7466 if (!TInfo)
7467 return ExprError();
7468
7469 if (!getDerived().AlwaysRebuild() &&
7470 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007471 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00007472
Douglas Gregor69735112011-03-06 17:40:41 +00007473 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00007474 E->getLocStart(),
7475 TInfo,
7476 E->getLocEnd());
7477 }
7478
Francois Pichet9f4f2072010-09-08 12:20:18 +00007479 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7480
7481 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7482 if (SubExpr.isInvalid())
7483 return ExprError();
7484
7485 if (!getDerived().AlwaysRebuild() &&
7486 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00007487 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00007488
7489 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7490 E->getLocStart(),
7491 SubExpr.get(),
7492 E->getLocEnd());
7493}
7494
7495template<typename Derived>
7496ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007497TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007498 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007499}
Mike Stump11289f42009-09-09 15:08:12 +00007500
Douglas Gregora16548e2009-08-11 05:31:07 +00007501template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007502ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007503TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007504 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007505 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007506}
Mike Stump11289f42009-09-09 15:08:12 +00007507
Douglas Gregora16548e2009-08-11 05:31:07 +00007508template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007509ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007510TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00007511 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00007512
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007513 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7514 // Make sure that we capture 'this'.
7515 getSema().CheckCXXThisCapture(E->getLocStart());
John McCallc3007a22010-10-26 07:05:15 +00007516 return SemaRef.Owned(E);
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007517 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007518
Douglas Gregorb15af892010-01-07 23:12:05 +00007519 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007520}
Mike Stump11289f42009-09-09 15:08:12 +00007521
Douglas Gregora16548e2009-08-11 05:31:07 +00007522template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007523ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007524TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007525 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007526 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007527 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007528
Douglas Gregora16548e2009-08-11 05:31:07 +00007529 if (!getDerived().AlwaysRebuild() &&
7530 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007531 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007532
Douglas Gregor53e191ed2011-07-06 22:04:06 +00007533 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7534 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00007535}
Mike Stump11289f42009-09-09 15:08:12 +00007536
Douglas Gregora16548e2009-08-11 05:31:07 +00007537template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007538ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007539TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00007540 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007541 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7542 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007543 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00007544 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007545
Chandler Carruth794da4c2010-02-08 06:42:49 +00007546 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007547 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00007548 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007549
Douglas Gregor033f6752009-12-23 23:03:06 +00007550 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00007551}
Mike Stump11289f42009-09-09 15:08:12 +00007552
Douglas Gregora16548e2009-08-11 05:31:07 +00007553template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007554ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00007555TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
7556 FieldDecl *Field
7557 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
7558 E->getField()));
7559 if (!Field)
7560 return ExprError();
7561
7562 if (!getDerived().AlwaysRebuild() && Field == E->getField())
7563 return SemaRef.Owned(E);
7564
7565 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
7566}
7567
7568template<typename Derived>
7569ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00007570TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7571 CXXScalarValueInitExpr *E) {
7572 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7573 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007574 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007575
Douglas Gregora16548e2009-08-11 05:31:07 +00007576 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007577 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007578 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007579
Chad Rosier1dcde962012-08-08 18:46:20 +00007580 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00007581 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00007582 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007583}
Mike Stump11289f42009-09-09 15:08:12 +00007584
Douglas Gregora16548e2009-08-11 05:31:07 +00007585template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007586ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007587TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007588 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00007589 TypeSourceInfo *AllocTypeInfo
7590 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7591 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007592 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007593
Douglas Gregora16548e2009-08-11 05:31:07 +00007594 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00007595 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00007596 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007597 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007598
Douglas Gregora16548e2009-08-11 05:31:07 +00007599 // Transform the placement arguments (if any).
7600 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007601 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00007602 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00007603 E->getNumPlacementArgs(), true,
7604 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00007605 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007606
Sebastian Redl6047f072012-02-16 12:22:20 +00007607 // Transform the initializer (if any).
7608 Expr *OldInit = E->getInitializer();
7609 ExprResult NewInit;
7610 if (OldInit)
7611 NewInit = getDerived().TransformExpr(OldInit);
7612 if (NewInit.isInvalid())
7613 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007614
Sebastian Redl6047f072012-02-16 12:22:20 +00007615 // Transform new operator and delete operator.
Douglas Gregord2d9da02010-02-26 00:38:10 +00007616 FunctionDecl *OperatorNew = 0;
7617 if (E->getOperatorNew()) {
7618 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007619 getDerived().TransformDecl(E->getLocStart(),
7620 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007621 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00007622 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007623 }
7624
7625 FunctionDecl *OperatorDelete = 0;
7626 if (E->getOperatorDelete()) {
7627 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007628 getDerived().TransformDecl(E->getLocStart(),
7629 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007630 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007631 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007632 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007633
Douglas Gregora16548e2009-08-11 05:31:07 +00007634 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00007635 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007636 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00007637 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007638 OperatorNew == E->getOperatorNew() &&
7639 OperatorDelete == E->getOperatorDelete() &&
7640 !ArgumentChanged) {
7641 // Mark any declarations we need as referenced.
7642 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00007643 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007644 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007645 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007646 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00007647
Sebastian Redl6047f072012-02-16 12:22:20 +00007648 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00007649 QualType ElementType
7650 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7651 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7652 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7653 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00007654 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00007655 }
7656 }
7657 }
Sebastian Redl6047f072012-02-16 12:22:20 +00007658
John McCallc3007a22010-10-26 07:05:15 +00007659 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007660 }
Mike Stump11289f42009-09-09 15:08:12 +00007661
Douglas Gregor0744ef62010-09-07 21:49:58 +00007662 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007663 if (!ArraySize.get()) {
7664 // If no array size was specified, but the new expression was
7665 // instantiated with an array type (e.g., "new T" where T is
7666 // instantiated with "int[4]"), extract the outer bound from the
7667 // array type as our array size. We do this with constant and
7668 // dependently-sized array types.
7669 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7670 if (!ArrayT) {
7671 // Do nothing
7672 } else if (const ConstantArrayType *ConsArrayT
7673 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007674 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007675 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier1dcde962012-08-08 18:46:20 +00007676 ConsArrayT->getSize(),
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007677 SemaRef.Context.getSizeType(),
7678 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007679 AllocType = ConsArrayT->getElementType();
7680 } else if (const DependentSizedArrayType *DepArrayT
7681 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7682 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00007683 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007684 AllocType = DepArrayT->getElementType();
7685 }
7686 }
7687 }
Sebastian Redl6047f072012-02-16 12:22:20 +00007688
Douglas Gregora16548e2009-08-11 05:31:07 +00007689 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7690 E->isGlobalNew(),
7691 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007692 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007693 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00007694 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007695 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00007696 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00007697 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00007698 E->getDirectInitRange(),
7699 NewInit.take());
Douglas Gregora16548e2009-08-11 05:31:07 +00007700}
Mike Stump11289f42009-09-09 15:08:12 +00007701
Douglas Gregora16548e2009-08-11 05:31:07 +00007702template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007703ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007704TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007705 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00007706 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007707 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007708
Douglas Gregord2d9da02010-02-26 00:38:10 +00007709 // Transform the delete operator, if known.
7710 FunctionDecl *OperatorDelete = 0;
7711 if (E->getOperatorDelete()) {
7712 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007713 getDerived().TransformDecl(E->getLocStart(),
7714 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007715 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007716 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007717 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007718
Douglas Gregora16548e2009-08-11 05:31:07 +00007719 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007720 Operand.get() == E->getArgument() &&
7721 OperatorDelete == E->getOperatorDelete()) {
7722 // Mark any declarations we need as referenced.
7723 // FIXME: instantiation-specific.
7724 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007725 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00007726
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00007727 if (!E->getArgument()->isTypeDependent()) {
7728 QualType Destroyed = SemaRef.Context.getBaseElementType(
7729 E->getDestroyedType());
7730 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7731 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00007732 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00007733 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00007734 }
7735 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007736
John McCallc3007a22010-10-26 07:05:15 +00007737 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007738 }
Mike Stump11289f42009-09-09 15:08:12 +00007739
Douglas Gregora16548e2009-08-11 05:31:07 +00007740 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7741 E->isGlobalDelete(),
7742 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00007743 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007744}
Mike Stump11289f42009-09-09 15:08:12 +00007745
Douglas Gregora16548e2009-08-11 05:31:07 +00007746template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007747ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00007748TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007749 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007750 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00007751 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007752 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007753
John McCallba7bf592010-08-24 05:47:05 +00007754 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00007755 bool MayBePseudoDestructor = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00007756 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007757 E->getOperatorLoc(),
7758 E->isArrow()? tok::arrow : tok::period,
7759 ObjectTypePtr,
7760 MayBePseudoDestructor);
7761 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007762 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007763
John McCallba7bf592010-08-24 05:47:05 +00007764 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00007765 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7766 if (QualifierLoc) {
7767 QualifierLoc
7768 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7769 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00007770 return ExprError();
7771 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00007772 CXXScopeSpec SS;
7773 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00007774
Douglas Gregor678f90d2010-02-25 01:56:36 +00007775 PseudoDestructorTypeStorage Destroyed;
7776 if (E->getDestroyedTypeInfo()) {
7777 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00007778 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00007779 ObjectType, 0, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00007780 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007781 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00007782 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00007783 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00007784 // We aren't likely to be able to resolve the identifier down to a type
7785 // now anyway, so just retain the identifier.
7786 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7787 E->getDestroyedTypeLoc());
7788 } else {
7789 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00007790 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007791 *E->getDestroyedTypeIdentifier(),
7792 E->getDestroyedTypeLoc(),
7793 /*Scope=*/0,
7794 SS, ObjectTypePtr,
7795 false);
7796 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007797 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007798
Douglas Gregor678f90d2010-02-25 01:56:36 +00007799 Destroyed
7800 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7801 E->getDestroyedTypeLoc());
7802 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007803
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007804 TypeSourceInfo *ScopeTypeInfo = 0;
7805 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00007806 CXXScopeSpec EmptySS;
7807 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
7808 E->getScopeTypeInfo(), ObjectType, 0, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007809 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007810 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00007811 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007812
John McCallb268a282010-08-23 23:25:46 +00007813 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00007814 E->getOperatorLoc(),
7815 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00007816 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007817 ScopeTypeInfo,
7818 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007819 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007820 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00007821}
Mike Stump11289f42009-09-09 15:08:12 +00007822
Douglas Gregorad8a3362009-09-04 17:36:40 +00007823template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007824ExprResult
John McCalld14a8642009-11-21 08:51:07 +00007825TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007826 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00007827 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7828 Sema::LookupOrdinaryName);
7829
7830 // Transform all the decls.
7831 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7832 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007833 NamedDecl *InstD = static_cast<NamedDecl*>(
7834 getDerived().TransformDecl(Old->getNameLoc(),
7835 *I));
John McCall84d87672009-12-10 09:41:52 +00007836 if (!InstD) {
7837 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7838 // This can happen because of dependent hiding.
7839 if (isa<UsingShadowDecl>(*I))
7840 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00007841 else {
7842 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007843 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00007844 }
John McCall84d87672009-12-10 09:41:52 +00007845 }
John McCalle66edc12009-11-24 19:00:30 +00007846
7847 // Expand using declarations.
7848 if (isa<UsingDecl>(InstD)) {
7849 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00007850 for (auto *I : UD->shadows())
7851 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00007852 continue;
7853 }
7854
7855 R.addDecl(InstD);
7856 }
7857
7858 // Resolve a kind, but don't do any further analysis. If it's
7859 // ambiguous, the callee needs to deal with it.
7860 R.resolveKind();
7861
7862 // Rebuild the nested-name qualifier, if present.
7863 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00007864 if (Old->getQualifierLoc()) {
7865 NestedNameSpecifierLoc QualifierLoc
7866 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7867 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007868 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007869
Douglas Gregor0da1d432011-02-28 20:01:57 +00007870 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00007871 }
7872
Douglas Gregor9262f472010-04-27 18:19:34 +00007873 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00007874 CXXRecordDecl *NamingClass
7875 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7876 Old->getNameLoc(),
7877 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00007878 if (!NamingClass) {
7879 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007880 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00007881 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007882
Douglas Gregorda7be082010-04-27 16:10:10 +00007883 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00007884 }
7885
Abramo Bagnara7945c982012-01-27 09:46:47 +00007886 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7887
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00007888 // If we have neither explicit template arguments, nor the template keyword,
7889 // it's a normal declaration name.
7890 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCalle66edc12009-11-24 19:00:30 +00007891 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7892
7893 // If we have template arguments, rebuild them, then rebuild the
7894 // templateid expression.
7895 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00007896 if (Old->hasExplicitTemplateArgs() &&
7897 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00007898 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00007899 TransArgs)) {
7900 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00007901 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00007902 }
John McCalle66edc12009-11-24 19:00:30 +00007903
Abramo Bagnara7945c982012-01-27 09:46:47 +00007904 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00007905 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007906}
Mike Stump11289f42009-09-09 15:08:12 +00007907
Douglas Gregora16548e2009-08-11 05:31:07 +00007908template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007909ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00007910TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7911 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00007912 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00007913 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7914 TypeSourceInfo *From = E->getArg(I);
7915 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00007916 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00007917 TypeLocBuilder TLB;
7918 TLB.reserve(FromTL.getFullDataSize());
7919 QualType To = getDerived().TransformType(TLB, FromTL);
7920 if (To.isNull())
7921 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007922
Douglas Gregor29c42f22012-02-24 07:38:34 +00007923 if (To == From->getType())
7924 Args.push_back(From);
7925 else {
7926 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7927 ArgChanged = true;
7928 }
7929 continue;
7930 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007931
Douglas Gregor29c42f22012-02-24 07:38:34 +00007932 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00007933
Douglas Gregor29c42f22012-02-24 07:38:34 +00007934 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00007935 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00007936 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7937 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7938 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00007939
Douglas Gregor29c42f22012-02-24 07:38:34 +00007940 // Determine whether the set of unexpanded parameter packs can and should
7941 // be expanded.
7942 bool Expand = true;
7943 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00007944 Optional<unsigned> OrigNumExpansions =
7945 ExpansionTL.getTypePtr()->getNumExpansions();
7946 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00007947 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7948 PatternTL.getSourceRange(),
7949 Unexpanded,
7950 Expand, RetainExpansion,
7951 NumExpansions))
7952 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007953
Douglas Gregor29c42f22012-02-24 07:38:34 +00007954 if (!Expand) {
7955 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00007956 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00007957 // expansion.
7958 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00007959
Douglas Gregor29c42f22012-02-24 07:38:34 +00007960 TypeLocBuilder TLB;
7961 TLB.reserve(From->getTypeLoc().getFullDataSize());
7962
7963 QualType To = getDerived().TransformType(TLB, PatternTL);
7964 if (To.isNull())
7965 return ExprError();
7966
Chad Rosier1dcde962012-08-08 18:46:20 +00007967 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00007968 PatternTL.getSourceRange(),
7969 ExpansionTL.getEllipsisLoc(),
7970 NumExpansions);
7971 if (To.isNull())
7972 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007973
Douglas Gregor29c42f22012-02-24 07:38:34 +00007974 PackExpansionTypeLoc ToExpansionTL
7975 = TLB.push<PackExpansionTypeLoc>(To);
7976 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7977 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7978 continue;
7979 }
7980
7981 // Expand the pack expansion by substituting for each argument in the
7982 // pack(s).
7983 for (unsigned I = 0; I != *NumExpansions; ++I) {
7984 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7985 TypeLocBuilder TLB;
7986 TLB.reserve(PatternTL.getFullDataSize());
7987 QualType To = getDerived().TransformType(TLB, PatternTL);
7988 if (To.isNull())
7989 return ExprError();
7990
Eli Friedman5e05c4a2013-07-19 21:49:32 +00007991 if (To->containsUnexpandedParameterPack()) {
7992 To = getDerived().RebuildPackExpansionType(To,
7993 PatternTL.getSourceRange(),
7994 ExpansionTL.getEllipsisLoc(),
7995 NumExpansions);
7996 if (To.isNull())
7997 return ExprError();
7998
7999 PackExpansionTypeLoc ToExpansionTL
8000 = TLB.push<PackExpansionTypeLoc>(To);
8001 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8002 }
8003
Douglas Gregor29c42f22012-02-24 07:38:34 +00008004 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8005 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008006
Douglas Gregor29c42f22012-02-24 07:38:34 +00008007 if (!RetainExpansion)
8008 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008009
Douglas Gregor29c42f22012-02-24 07:38:34 +00008010 // If we're supposed to retain a pack expansion, do so by temporarily
8011 // forgetting the partially-substituted parameter pack.
8012 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
8013
8014 TypeLocBuilder TLB;
8015 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00008016
Douglas Gregor29c42f22012-02-24 07:38:34 +00008017 QualType To = getDerived().TransformType(TLB, PatternTL);
8018 if (To.isNull())
8019 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008020
8021 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008022 PatternTL.getSourceRange(),
8023 ExpansionTL.getEllipsisLoc(),
8024 NumExpansions);
8025 if (To.isNull())
8026 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008027
Douglas Gregor29c42f22012-02-24 07:38:34 +00008028 PackExpansionTypeLoc ToExpansionTL
8029 = TLB.push<PackExpansionTypeLoc>(To);
8030 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8031 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8032 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008033
Douglas Gregor29c42f22012-02-24 07:38:34 +00008034 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8035 return SemaRef.Owned(E);
8036
8037 return getDerived().RebuildTypeTrait(E->getTrait(),
8038 E->getLocStart(),
8039 Args,
8040 E->getLocEnd());
8041}
8042
8043template<typename Derived>
8044ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00008045TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8046 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
8047 if (!T)
8048 return ExprError();
8049
8050 if (!getDerived().AlwaysRebuild() &&
8051 T == E->getQueriedTypeSourceInfo())
8052 return SemaRef.Owned(E);
8053
8054 ExprResult SubExpr;
8055 {
8056 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8057 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8058 if (SubExpr.isInvalid())
8059 return ExprError();
8060
8061 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
8062 return SemaRef.Owned(E);
8063 }
8064
8065 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8066 E->getLocStart(),
8067 T,
8068 SubExpr.get(),
8069 E->getLocEnd());
8070}
8071
8072template<typename Derived>
8073ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00008074TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8075 ExprResult SubExpr;
8076 {
8077 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8078 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8079 if (SubExpr.isInvalid())
8080 return ExprError();
8081
8082 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
8083 return SemaRef.Owned(E);
8084 }
8085
8086 return getDerived().RebuildExpressionTrait(
8087 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8088}
8089
8090template<typename Derived>
8091ExprResult
John McCall8cd78132009-11-19 22:55:06 +00008092TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008093 DependentScopeDeclRefExpr *E) {
Richard Smithdb2630f2012-10-21 03:28:35 +00008094 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
8095}
8096
8097template<typename Derived>
8098ExprResult
8099TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8100 DependentScopeDeclRefExpr *E,
8101 bool IsAddressOfOperand) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00008102 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008103 NestedNameSpecifierLoc QualifierLoc
8104 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8105 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008106 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00008107 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008108
John McCall31f82722010-11-12 08:19:04 +00008109 // TODO: If this is a conversion-function-id, verify that the
8110 // destination type name (if present) resolves the same way after
8111 // instantiation as it did in the local scope.
8112
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008113 DeclarationNameInfo NameInfo
8114 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8115 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008116 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008117
John McCalle66edc12009-11-24 19:00:30 +00008118 if (!E->hasExplicitTemplateArgs()) {
8119 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008120 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008121 // Note: it is sufficient to compare the Name component of NameInfo:
8122 // if name has not changed, DNLoc has not changed either.
8123 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00008124 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00008125
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008126 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008127 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008128 NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00008129 /*TemplateArgs*/ 0,
8130 IsAddressOfOperand);
Douglas Gregord019ff62009-10-22 17:20:55 +00008131 }
John McCall6b51f282009-11-23 01:53:49 +00008132
8133 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008134 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8135 E->getNumTemplateArgs(),
8136 TransArgs))
8137 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008138
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008139 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008140 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008141 NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00008142 &TransArgs,
8143 IsAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00008144}
8145
8146template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008147ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008148TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00008149 // CXXConstructExprs other than for list-initialization and
8150 // CXXTemporaryObjectExpr are always implicit, so when we have
8151 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00008152 if ((E->getNumArgs() == 1 ||
8153 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00008154 (!getDerived().DropCallArgument(E->getArg(0))) &&
8155 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00008156 return getDerived().TransformExpr(E->getArg(0));
8157
Douglas Gregora16548e2009-08-11 05:31:07 +00008158 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8159
8160 QualType T = getDerived().TransformType(E->getType());
8161 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008162 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008163
8164 CXXConstructorDecl *Constructor
8165 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008166 getDerived().TransformDecl(E->getLocStart(),
8167 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008168 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008169 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008170
Douglas Gregora16548e2009-08-11 05:31:07 +00008171 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008172 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008173 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008174 &ArgumentChanged))
8175 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008176
Douglas Gregora16548e2009-08-11 05:31:07 +00008177 if (!getDerived().AlwaysRebuild() &&
8178 T == E->getType() &&
8179 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00008180 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00008181 // Mark the constructor as referenced.
8182 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008183 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00008184 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00008185 }
Mike Stump11289f42009-09-09 15:08:12 +00008186
Douglas Gregordb121ba2009-12-14 16:27:04 +00008187 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8188 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008189 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00008190 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00008191 E->isListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00008192 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00008193 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00008194 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008195}
Mike Stump11289f42009-09-09 15:08:12 +00008196
Douglas Gregora16548e2009-08-11 05:31:07 +00008197/// \brief Transform a C++ temporary-binding expression.
8198///
Douglas Gregor363b1512009-12-24 18:51:59 +00008199/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8200/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008201template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008202ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008203TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008204 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008205}
Mike Stump11289f42009-09-09 15:08:12 +00008206
John McCall5d413782010-12-06 08:20:24 +00008207/// \brief Transform a C++ expression that contains cleanups that should
8208/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00008209///
John McCall5d413782010-12-06 08:20:24 +00008210/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00008211/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008212template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008213ExprResult
John McCall5d413782010-12-06 08:20:24 +00008214TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008215 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008216}
Mike Stump11289f42009-09-09 15:08:12 +00008217
Douglas Gregora16548e2009-08-11 05:31:07 +00008218template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008219ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008220TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00008221 CXXTemporaryObjectExpr *E) {
8222 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8223 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008224 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008225
Douglas Gregora16548e2009-08-11 05:31:07 +00008226 CXXConstructorDecl *Constructor
8227 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00008228 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008229 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008230 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008231 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008232
Douglas Gregora16548e2009-08-11 05:31:07 +00008233 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008234 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00008235 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00008236 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008237 &ArgumentChanged))
8238 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008239
Douglas Gregora16548e2009-08-11 05:31:07 +00008240 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008241 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008242 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008243 !ArgumentChanged) {
8244 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008245 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00008246 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008247 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008248
Richard Smithd59b8322012-12-19 01:39:02 +00008249 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00008250 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8251 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008252 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008253 E->getLocEnd());
8254}
Mike Stump11289f42009-09-09 15:08:12 +00008255
Douglas Gregora16548e2009-08-11 05:31:07 +00008256template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008257ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00008258TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008259
8260 // Transform any init-capture expressions before entering the scope of the
8261 // lambda body, because they are not semantically within that scope.
8262 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
8263 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
8264 E->explicit_capture_begin());
8265
8266 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8267 CEnd = E->capture_end();
8268 C != CEnd; ++C) {
8269 if (!C->isInitCapture())
8270 continue;
8271 EnterExpressionEvaluationContext EEEC(getSema(),
8272 Sema::PotentiallyEvaluated);
8273 ExprResult NewExprInitResult = getDerived().TransformInitializer(
8274 C->getCapturedVar()->getInit(),
8275 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
8276
8277 if (NewExprInitResult.isInvalid())
8278 return ExprError();
8279 Expr *NewExprInit = NewExprInitResult.get();
8280
8281 VarDecl *OldVD = C->getCapturedVar();
8282 QualType NewInitCaptureType =
8283 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
8284 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
8285 NewExprInit);
8286 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008287 InitCaptureExprsAndTypes[C - E->capture_begin()] =
8288 std::make_pair(NewExprInitResult, NewInitCaptureType);
8289
8290 }
8291
Faisal Vali524ca282013-11-12 01:40:44 +00008292 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
Faisal Vali2cba1332013-10-23 06:44:28 +00008293 // Transform the template parameters, and add them to the current
8294 // instantiation scope. The null case is handled correctly.
8295 LSI->GLTemplateParameterList = getDerived().TransformTemplateParameterList(
8296 E->getTemplateParameterList());
8297
8298 // Check to see if the TypeSourceInfo of the call operator needs to
8299 // be transformed, and if so do the transformation in the
8300 // CurrentInstantiationScope.
8301
8302 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
8303 FunctionProtoTypeLoc OldCallOpFPTL =
8304 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
8305 TypeSourceInfo *NewCallOpTSI = 0;
8306
8307 const bool CallOpWasAlreadyTransformed =
8308 getDerived().AlreadyTransformed(OldCallOpTSI->getType());
8309
8310 // Use the Old Call Operator's TypeSourceInfo if it is already transformed.
8311 if (CallOpWasAlreadyTransformed)
8312 NewCallOpTSI = OldCallOpTSI;
8313 else {
8314 // Transform the TypeSourceInfo of the Original Lambda's Call Operator.
8315 // The transformation MUST be done in the CurrentInstantiationScope since
8316 // it introduces a mapping of the original to the newly created
8317 // transformed parameters.
8318
8319 TypeLocBuilder NewCallOpTLBuilder;
8320 QualType NewCallOpType = TransformFunctionProtoType(NewCallOpTLBuilder,
8321 OldCallOpFPTL,
8322 0, 0);
8323 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
8324 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00008325 }
Faisal Vali2cba1332013-10-23 06:44:28 +00008326 // Extract the ParmVarDecls from the NewCallOpTSI and add them to
8327 // the vector below - this will be used to synthesize the
8328 // NewCallOperator. Additionally, add the parameters of the untransformed
8329 // lambda call operator to the CurrentInstantiationScope.
8330 SmallVector<ParmVarDecl *, 4> Params;
8331 {
8332 FunctionProtoTypeLoc NewCallOpFPTL =
8333 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>();
8334 ParmVarDecl **NewParamDeclArray = NewCallOpFPTL.getParmArray();
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00008335 const unsigned NewNumArgs = NewCallOpFPTL.getNumParams();
Faisal Vali2cba1332013-10-23 06:44:28 +00008336
8337 for (unsigned I = 0; I < NewNumArgs; ++I) {
8338 // If this call operator's type does not require transformation,
8339 // the parameters do not get added to the current instantiation scope,
8340 // - so ADD them! This allows the following to compile when the enclosing
8341 // template is specialized and the entire lambda expression has to be
8342 // transformed.
8343 // template<class T> void foo(T t) {
8344 // auto L = [](auto a) {
8345 // auto M = [](char b) { <-- note: non-generic lambda
8346 // auto N = [](auto c) {
8347 // int x = sizeof(a);
8348 // x = sizeof(b); <-- specifically this line
8349 // x = sizeof(c);
8350 // };
8351 // };
8352 // };
8353 // }
8354 // foo('a')
8355 if (CallOpWasAlreadyTransformed)
8356 getDerived().transformedLocalDecl(NewParamDeclArray[I],
8357 NewParamDeclArray[I]);
8358 // Add to Params array, so these parameters can be used to create
8359 // the newly transformed call operator.
8360 Params.push_back(NewParamDeclArray[I]);
8361 }
8362 }
8363
8364 if (!NewCallOpTSI)
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008365 return ExprError();
8366
Eli Friedmand564afb2012-09-19 01:18:11 +00008367 // Create the local class that will describe the lambda.
8368 CXXRecordDecl *Class
8369 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008370 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00008371 /*KnownDependent=*/false,
8372 E->getCaptureDefault());
8373
Eli Friedmand564afb2012-09-19 01:18:11 +00008374 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8375
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008376 // Build the call operator.
Faisal Vali2cba1332013-10-23 06:44:28 +00008377 CXXMethodDecl *NewCallOperator
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008378 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008379 NewCallOpTSI,
Douglas Gregoradb376e2012-02-14 22:28:59 +00008380 E->getCallOperator()->getLocEnd(),
Richard Smith505df232012-07-22 23:45:10 +00008381 Params);
Faisal Vali2cba1332013-10-23 06:44:28 +00008382 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00008383
Faisal Vali2cba1332013-10-23 06:44:28 +00008384 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
8385
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008386 return getDerived().TransformLambdaScope(E, NewCallOperator,
8387 InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +00008388}
8389
8390template<typename Derived>
8391ExprResult
8392TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008393 CXXMethodDecl *CallOperator,
8394 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes) {
Richard Smithba71c082013-05-16 06:20:58 +00008395 bool Invalid = false;
8396
Douglas Gregorb4328232012-02-14 00:00:48 +00008397 // Introduce the context of the call operator.
Richard Smith7ff2bcb2014-01-24 01:54:52 +00008398 Sema::ContextRAII SavedContext(getSema(), CallOperator,
8399 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00008400
Faisal Vali2b391ab2013-09-26 19:54:12 +00008401 LambdaScopeInfo *const LSI = getSema().getCurLambda();
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008402 // Enter the scope of the lambda.
Faisal Vali2b391ab2013-09-26 19:54:12 +00008403 getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008404 E->getCaptureDefault(),
James Dennettddd36ff2013-08-09 23:08:25 +00008405 E->getCaptureDefaultLoc(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008406 E->hasExplicitParameters(),
8407 E->hasExplicitResultType(),
8408 E->isMutable());
Chad Rosier1dcde962012-08-08 18:46:20 +00008409
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008410 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008411 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00008412 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008413 CEnd = E->capture_end();
8414 C != CEnd; ++C) {
8415 // When we hit the first implicit capture, tell Sema that we've finished
8416 // the list of explicit captures.
8417 if (!FinishedExplicitCaptures && C->isImplicit()) {
8418 getSema().finishLambdaExplicitCaptures(LSI);
8419 FinishedExplicitCaptures = true;
8420 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008421
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008422 // Capturing 'this' is trivial.
8423 if (C->capturesThis()) {
8424 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8425 continue;
8426 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008427
Richard Smithba71c082013-05-16 06:20:58 +00008428 // Rebuild init-captures, including the implied field declaration.
8429 if (C->isInitCapture()) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008430
8431 InitCaptureInfoTy InitExprTypePair =
8432 InitCaptureExprsAndTypes[C - E->capture_begin()];
8433 ExprResult Init = InitExprTypePair.first;
8434 QualType InitQualType = InitExprTypePair.second;
8435 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00008436 Invalid = true;
8437 continue;
8438 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00008439 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008440 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
8441 OldVD->getLocation(), InitExprTypePair.second,
8442 OldVD->getIdentifier(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00008443 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00008444 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008445 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00008446 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008447 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00008448 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00008449 continue;
8450 }
8451
8452 assert(C->capturesVariable() && "unexpected kind of lambda capture");
8453
Douglas Gregor3e308b12012-02-14 19:27:52 +00008454 // Determine the capture kind for Sema.
8455 Sema::TryCaptureKind Kind
8456 = C->isImplicit()? Sema::TryCapture_Implicit
8457 : C->getCaptureKind() == LCK_ByCopy
8458 ? Sema::TryCapture_ExplicitByVal
8459 : Sema::TryCapture_ExplicitByRef;
8460 SourceLocation EllipsisLoc;
8461 if (C->isPackExpansion()) {
8462 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8463 bool ShouldExpand = false;
8464 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008465 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00008466 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8467 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008468 Unexpanded,
8469 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00008470 NumExpansions)) {
8471 Invalid = true;
8472 continue;
8473 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008474
Douglas Gregor3e308b12012-02-14 19:27:52 +00008475 if (ShouldExpand) {
8476 // The transform has determined that we should perform an expansion;
8477 // transform and capture each of the arguments.
8478 // expansion of the pattern. Do so.
8479 VarDecl *Pack = C->getCapturedVar();
8480 for (unsigned I = 0; I != *NumExpansions; ++I) {
8481 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8482 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008483 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008484 Pack));
8485 if (!CapturedVar) {
8486 Invalid = true;
8487 continue;
8488 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008489
Douglas Gregor3e308b12012-02-14 19:27:52 +00008490 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00008491 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8492 }
Douglas Gregor3e308b12012-02-14 19:27:52 +00008493 continue;
8494 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008495
Douglas Gregor3e308b12012-02-14 19:27:52 +00008496 EllipsisLoc = C->getEllipsisLoc();
8497 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008498
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008499 // Transform the captured variable.
8500 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008501 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008502 C->getCapturedVar()));
8503 if (!CapturedVar) {
8504 Invalid = true;
8505 continue;
8506 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008507
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008508 // Capture the transformed variable.
Douglas Gregorfdf598e2012-02-18 09:37:24 +00008509 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008510 }
8511 if (!FinishedExplicitCaptures)
8512 getSema().finishLambdaExplicitCaptures(LSI);
8513
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008514
8515 // Enter a new evaluation context to insulate the lambda from any
8516 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00008517 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008518
8519 if (Invalid) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008520 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008521 /*IsInstantiation=*/true);
8522 return ExprError();
8523 }
8524
8525 // Instantiate the body of the lambda expression.
Douglas Gregorb4328232012-02-14 00:00:48 +00008526 StmtResult Body = getDerived().TransformStmt(E->getBody());
8527 if (Body.isInvalid()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008528 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregorb4328232012-02-14 00:00:48 +00008529 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00008530 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00008531 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00008532
Chad Rosier1dcde962012-08-08 18:46:20 +00008533 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorb61e8092012-04-04 17:40:10 +00008534 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregore31e6062012-02-07 10:09:13 +00008535}
8536
8537template<typename Derived>
8538ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008539TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008540 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00008541 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8542 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008543 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008544
Douglas Gregora16548e2009-08-11 05:31:07 +00008545 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008546 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00008547 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00008548 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008549 &ArgumentChanged))
8550 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008551
Douglas Gregora16548e2009-08-11 05:31:07 +00008552 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008553 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008554 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00008555 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00008556
Douglas Gregora16548e2009-08-11 05:31:07 +00008557 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00008558 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00008559 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008560 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008561 E->getRParenLoc());
8562}
Mike Stump11289f42009-09-09 15:08:12 +00008563
Douglas Gregora16548e2009-08-11 05:31:07 +00008564template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008565ExprResult
John McCall8cd78132009-11-19 22:55:06 +00008566TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008567 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008568 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00008569 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00008570 Expr *OldBase;
8571 QualType BaseType;
8572 QualType ObjectType;
8573 if (!E->isImplicitAccess()) {
8574 OldBase = E->getBase();
8575 Base = getDerived().TransformExpr(OldBase);
8576 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008577 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008578
John McCall2d74de92009-12-01 22:10:20 +00008579 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00008580 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00008581 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00008582 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008583 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008584 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00008585 ObjectTy,
8586 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00008587 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008588 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00008589
John McCallba7bf592010-08-24 05:47:05 +00008590 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00008591 BaseType = ((Expr*) Base.get())->getType();
8592 } else {
8593 OldBase = 0;
8594 BaseType = getDerived().TransformType(E->getBaseType());
8595 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8596 }
Mike Stump11289f42009-09-09 15:08:12 +00008597
Douglas Gregora5cb6da2009-10-20 05:58:46 +00008598 // Transform the first part of the nested-name-specifier that qualifies
8599 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00008600 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00008601 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00008602 E->getFirstQualifierFoundInScope(),
8603 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00008604
Douglas Gregore16af532011-02-28 18:50:33 +00008605 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008606 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00008607 QualifierLoc
8608 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8609 ObjectType,
8610 FirstQualifierInScope);
8611 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008612 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008613 }
Mike Stump11289f42009-09-09 15:08:12 +00008614
Abramo Bagnara7945c982012-01-27 09:46:47 +00008615 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8616
John McCall31f82722010-11-12 08:19:04 +00008617 // TODO: If this is a conversion-function-id, verify that the
8618 // destination type name (if present) resolves the same way after
8619 // instantiation as it did in the local scope.
8620
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008621 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00008622 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008623 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008624 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008625
John McCall2d74de92009-12-01 22:10:20 +00008626 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00008627 // This is a reference to a member without an explicitly-specified
8628 // template argument list. Optimize for this common case.
8629 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00008630 Base.get() == OldBase &&
8631 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00008632 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008633 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00008634 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00008635 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00008636
John McCallb268a282010-08-23 23:25:46 +00008637 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008638 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00008639 E->isArrow(),
8640 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00008641 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008642 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00008643 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008644 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00008645 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00008646 }
8647
John McCall6b51f282009-11-23 01:53:49 +00008648 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008649 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8650 E->getNumTemplateArgs(),
8651 TransArgs))
8652 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008653
John McCallb268a282010-08-23 23:25:46 +00008654 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008655 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00008656 E->isArrow(),
8657 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00008658 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008659 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00008660 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008661 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00008662 &TransArgs);
8663}
8664
8665template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008666ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008667TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00008668 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00008669 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00008670 QualType BaseType;
8671 if (!Old->isImplicitAccess()) {
8672 Base = getDerived().TransformExpr(Old->getBase());
8673 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008674 return ExprError();
Richard Smithcab9a7d2011-10-26 19:06:56 +00008675 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8676 Old->isArrow());
8677 if (Base.isInvalid())
8678 return ExprError();
8679 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +00008680 } else {
8681 BaseType = getDerived().TransformType(Old->getBaseType());
8682 }
John McCall10eae182009-11-30 22:42:35 +00008683
Douglas Gregor0da1d432011-02-28 20:01:57 +00008684 NestedNameSpecifierLoc QualifierLoc;
8685 if (Old->getQualifierLoc()) {
8686 QualifierLoc
8687 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8688 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008689 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00008690 }
8691
Abramo Bagnara7945c982012-01-27 09:46:47 +00008692 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8693
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008694 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00008695 Sema::LookupOrdinaryName);
8696
8697 // Transform all the decls.
8698 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8699 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008700 NamedDecl *InstD = static_cast<NamedDecl*>(
8701 getDerived().TransformDecl(Old->getMemberLoc(),
8702 *I));
John McCall84d87672009-12-10 09:41:52 +00008703 if (!InstD) {
8704 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8705 // This can happen because of dependent hiding.
8706 if (isa<UsingShadowDecl>(*I))
8707 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00008708 else {
8709 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008710 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00008711 }
John McCall84d87672009-12-10 09:41:52 +00008712 }
John McCall10eae182009-11-30 22:42:35 +00008713
8714 // Expand using declarations.
8715 if (isa<UsingDecl>(InstD)) {
8716 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00008717 for (auto *I : UD->shadows())
8718 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +00008719 continue;
8720 }
8721
8722 R.addDecl(InstD);
8723 }
8724
8725 R.resolveKind();
8726
Douglas Gregor9262f472010-04-27 18:19:34 +00008727 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00008728 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008729 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00008730 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00008731 Old->getMemberLoc(),
8732 Old->getNamingClass()));
8733 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00008734 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008735
Douglas Gregorda7be082010-04-27 16:10:10 +00008736 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00008737 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008738
John McCall10eae182009-11-30 22:42:35 +00008739 TemplateArgumentListInfo TransArgs;
8740 if (Old->hasExplicitTemplateArgs()) {
8741 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8742 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008743 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8744 Old->getNumTemplateArgs(),
8745 TransArgs))
8746 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00008747 }
John McCall38836f02010-01-15 08:34:02 +00008748
8749 // FIXME: to do this check properly, we will need to preserve the
8750 // first-qualifier-in-scope here, just in case we had a dependent
8751 // base (and therefore couldn't do the check) and a
8752 // nested-name-qualifier (and therefore could do the lookup).
8753 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00008754
John McCallb268a282010-08-23 23:25:46 +00008755 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008756 BaseType,
John McCall10eae182009-11-30 22:42:35 +00008757 Old->getOperatorLoc(),
8758 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00008759 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008760 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +00008761 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00008762 R,
8763 (Old->hasExplicitTemplateArgs()
8764 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00008765}
8766
8767template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008768ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008769TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00008770 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008771 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8772 if (SubExpr.isInvalid())
8773 return ExprError();
8774
8775 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00008776 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008777
8778 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8779}
8780
8781template<typename Derived>
8782ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008783TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00008784 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8785 if (Pattern.isInvalid())
8786 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008787
Douglas Gregor0f836ea2011-01-13 00:19:55 +00008788 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8789 return SemaRef.Owned(E);
8790
Douglas Gregorb8840002011-01-14 21:20:45 +00008791 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8792 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008793}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008794
8795template<typename Derived>
8796ExprResult
8797TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8798 // If E is not value-dependent, then nothing will change when we transform it.
8799 // Note: This is an instantiation-centric view.
8800 if (!E->isValueDependent())
8801 return SemaRef.Owned(E);
8802
8803 // Note: None of the implementations of TryExpandParameterPacks can ever
8804 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00008805 // so
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008806 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8807 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00008808 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008809 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00008810 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +00008811 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00008812 ShouldExpand, RetainExpansion,
8813 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008814 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008815
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008816 if (RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008817 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00008818
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008819 NamedDecl *Pack = E->getPack();
8820 if (!ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008821 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008822 Pack));
8823 if (!Pack)
8824 return ExprError();
8825 }
8826
Chad Rosier1dcde962012-08-08 18:46:20 +00008827
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008828 // We now know the length of the parameter pack, so build a new expression
8829 // that stores that length.
Chad Rosier1dcde962012-08-08 18:46:20 +00008830 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8831 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008832 NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008833}
8834
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008835template<typename Derived>
8836ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00008837TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8838 SubstNonTypeTemplateParmPackExpr *E) {
8839 // Default behavior is to do nothing with this transformation.
8840 return SemaRef.Owned(E);
8841}
8842
8843template<typename Derived>
8844ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00008845TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8846 SubstNonTypeTemplateParmExpr *E) {
8847 // Default behavior is to do nothing with this transformation.
8848 return SemaRef.Owned(E);
8849}
8850
8851template<typename Derived>
8852ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +00008853TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8854 // Default behavior is to do nothing with this transformation.
8855 return SemaRef.Owned(E);
8856}
8857
8858template<typename Derived>
8859ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00008860TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8861 MaterializeTemporaryExpr *E) {
8862 return getDerived().TransformExpr(E->GetTemporaryExpr());
8863}
Chad Rosier1dcde962012-08-08 18:46:20 +00008864
Douglas Gregorfe314812011-06-21 17:03:29 +00008865template<typename Derived>
8866ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +00008867TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
8868 CXXStdInitializerListExpr *E) {
8869 return getDerived().TransformExpr(E->getSubExpr());
8870}
8871
8872template<typename Derived>
8873ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008874TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00008875 return SemaRef.MaybeBindToTemporary(E);
8876}
8877
8878template<typename Derived>
8879ExprResult
8880TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rose8986c5992012-03-12 17:53:02 +00008881 return SemaRef.Owned(E);
Ted Kremeneke65b0862012-03-06 20:05:56 +00008882}
8883
8884template<typename Derived>
8885ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +00008886TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8887 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8888 if (SubExpr.isInvalid())
8889 return ExprError();
8890
8891 if (!getDerived().AlwaysRebuild() &&
8892 SubExpr.get() == E->getSubExpr())
8893 return SemaRef.Owned(E);
8894
8895 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +00008896}
8897
8898template<typename Derived>
8899ExprResult
8900TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8901 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008902 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00008903 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00008904 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00008905 /*IsCall=*/false, Elements, &ArgChanged))
8906 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008907
Ted Kremeneke65b0862012-03-06 20:05:56 +00008908 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8909 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00008910
Ted Kremeneke65b0862012-03-06 20:05:56 +00008911 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8912 Elements.data(),
8913 Elements.size());
8914}
8915
8916template<typename Derived>
8917ExprResult
8918TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +00008919 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00008920 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008921 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00008922 bool ArgChanged = false;
8923 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8924 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +00008925
Ted Kremeneke65b0862012-03-06 20:05:56 +00008926 if (OrigElement.isPackExpansion()) {
8927 // This key/value element is a pack expansion.
8928 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8929 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8930 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8931 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8932
8933 // Determine whether the set of unexpanded parameter packs can
8934 // and should be expanded.
8935 bool Expand = true;
8936 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008937 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8938 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +00008939 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8940 OrigElement.Value->getLocEnd());
8941 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8942 PatternRange,
8943 Unexpanded,
8944 Expand, RetainExpansion,
8945 NumExpansions))
8946 return ExprError();
8947
8948 if (!Expand) {
8949 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00008950 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +00008951 // expansion.
8952 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8953 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8954 if (Key.isInvalid())
8955 return ExprError();
8956
8957 if (Key.get() != OrigElement.Key)
8958 ArgChanged = true;
8959
8960 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8961 if (Value.isInvalid())
8962 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008963
Ted Kremeneke65b0862012-03-06 20:05:56 +00008964 if (Value.get() != OrigElement.Value)
8965 ArgChanged = true;
8966
Chad Rosier1dcde962012-08-08 18:46:20 +00008967 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00008968 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8969 };
8970 Elements.push_back(Expansion);
8971 continue;
8972 }
8973
8974 // Record right away that the argument was changed. This needs
8975 // to happen even if the array expands to nothing.
8976 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00008977
Ted Kremeneke65b0862012-03-06 20:05:56 +00008978 // The transform has determined that we should perform an elementwise
8979 // expansion of the pattern. Do so.
8980 for (unsigned I = 0; I != *NumExpansions; ++I) {
8981 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8982 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8983 if (Key.isInvalid())
8984 return ExprError();
8985
8986 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8987 if (Value.isInvalid())
8988 return ExprError();
8989
Chad Rosier1dcde962012-08-08 18:46:20 +00008990 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00008991 Key.get(), Value.get(), SourceLocation(), NumExpansions
8992 };
8993
8994 // If any unexpanded parameter packs remain, we still have a
8995 // pack expansion.
8996 if (Key.get()->containsUnexpandedParameterPack() ||
8997 Value.get()->containsUnexpandedParameterPack())
8998 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +00008999
Ted Kremeneke65b0862012-03-06 20:05:56 +00009000 Elements.push_back(Element);
9001 }
9002
9003 // We've finished with this pack expansion.
9004 continue;
9005 }
9006
9007 // Transform and check key.
9008 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9009 if (Key.isInvalid())
9010 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009011
Ted Kremeneke65b0862012-03-06 20:05:56 +00009012 if (Key.get() != OrigElement.Key)
9013 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009014
Ted Kremeneke65b0862012-03-06 20:05:56 +00009015 // Transform and check value.
9016 ExprResult Value
9017 = getDerived().TransformExpr(OrigElement.Value);
9018 if (Value.isInvalid())
9019 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009020
Ted Kremeneke65b0862012-03-06 20:05:56 +00009021 if (Value.get() != OrigElement.Value)
9022 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009023
9024 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +00009025 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +00009026 };
9027 Elements.push_back(Element);
9028 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009029
Ted Kremeneke65b0862012-03-06 20:05:56 +00009030 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9031 return SemaRef.MaybeBindToTemporary(E);
9032
9033 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
9034 Elements.data(),
9035 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +00009036}
9037
Mike Stump11289f42009-09-09 15:08:12 +00009038template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009039ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009040TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00009041 TypeSourceInfo *EncodedTypeInfo
9042 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
9043 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009044 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009045
Douglas Gregora16548e2009-08-11 05:31:07 +00009046 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00009047 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00009048 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009049
9050 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00009051 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009052 E->getRParenLoc());
9053}
Mike Stump11289f42009-09-09 15:08:12 +00009054
Douglas Gregora16548e2009-08-11 05:31:07 +00009055template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +00009056ExprResult TreeTransform<Derived>::
9057TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +00009058 // This is a kind of implicit conversion, and it needs to get dropped
9059 // and recomputed for the same general reasons that ImplicitCastExprs
9060 // do, as well a more specific one: this expression is only valid when
9061 // it appears *immediately* as an argument expression.
9062 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +00009063}
9064
9065template<typename Derived>
9066ExprResult TreeTransform<Derived>::
9067TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009068 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +00009069 = getDerived().TransformType(E->getTypeInfoAsWritten());
9070 if (!TSInfo)
9071 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009072
John McCall31168b02011-06-15 23:02:42 +00009073 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +00009074 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +00009075 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009076
John McCall31168b02011-06-15 23:02:42 +00009077 if (!getDerived().AlwaysRebuild() &&
9078 TSInfo == E->getTypeInfoAsWritten() &&
9079 Result.get() == E->getSubExpr())
9080 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009081
John McCall31168b02011-06-15 23:02:42 +00009082 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +00009083 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +00009084 Result.get());
9085}
9086
9087template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009088ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009089TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009090 // Transform arguments.
9091 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009092 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009093 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009094 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009095 &ArgChanged))
9096 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009097
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009098 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
9099 // Class message: transform the receiver type.
9100 TypeSourceInfo *ReceiverTypeInfo
9101 = getDerived().TransformType(E->getClassReceiverTypeInfo());
9102 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009103 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009104
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009105 // If nothing changed, just retain the existing message send.
9106 if (!getDerived().AlwaysRebuild() &&
9107 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009108 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009109
9110 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009111 SmallVector<SourceLocation, 16> SelLocs;
9112 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009113 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
9114 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009115 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009116 E->getMethodDecl(),
9117 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009118 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009119 E->getRightLoc());
9120 }
9121
9122 // Instance message: transform the receiver
9123 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
9124 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00009125 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009126 = getDerived().TransformExpr(E->getInstanceReceiver());
9127 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009128 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009129
9130 // If nothing changed, just retain the existing message send.
9131 if (!getDerived().AlwaysRebuild() &&
9132 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009133 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009134
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009135 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009136 SmallVector<SourceLocation, 16> SelLocs;
9137 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +00009138 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009139 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009140 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009141 E->getMethodDecl(),
9142 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009143 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009144 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009145}
9146
Mike Stump11289f42009-09-09 15:08:12 +00009147template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009148ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009149TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00009150 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009151}
9152
Mike Stump11289f42009-09-09 15:08:12 +00009153template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009154ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009155TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00009156 return SemaRef.Owned(E);
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>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009162 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009163 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009164 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009165 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00009166
9167 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009168
Douglas Gregord51d90d2010-04-26 20:11:03 +00009169 // If nothing changed, just retain the existing expression.
9170 if (!getDerived().AlwaysRebuild() &&
9171 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00009172 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009173
John McCallb268a282010-08-23 23:25:46 +00009174 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009175 E->getLocation(),
9176 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00009177}
9178
Mike Stump11289f42009-09-09 15:08:12 +00009179template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009180ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009181TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00009182 // 'super' and types never change. Property never changes. Just
9183 // retain the existing expression.
9184 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00009185 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009186
Douglas Gregor9faee212010-04-26 20:47:02 +00009187 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009188 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00009189 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009190 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009191
Douglas Gregor9faee212010-04-26 20:47:02 +00009192 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009193
Douglas Gregor9faee212010-04-26 20:47:02 +00009194 // If nothing changed, just retain the existing expression.
9195 if (!getDerived().AlwaysRebuild() &&
9196 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00009197 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009198
John McCallb7bd14f2010-12-02 01:19:52 +00009199 if (E->isExplicitProperty())
9200 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9201 E->getExplicitProperty(),
9202 E->getLocation());
9203
9204 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +00009205 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +00009206 E->getImplicitPropertyGetter(),
9207 E->getImplicitPropertySetter(),
9208 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00009209}
9210
Mike Stump11289f42009-09-09 15:08:12 +00009211template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009212ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +00009213TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
9214 // Transform the base expression.
9215 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9216 if (Base.isInvalid())
9217 return ExprError();
9218
9219 // Transform the key expression.
9220 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
9221 if (Key.isInvalid())
9222 return ExprError();
9223
9224 // If nothing changed, just retain the existing expression.
9225 if (!getDerived().AlwaysRebuild() &&
9226 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
9227 return SemaRef.Owned(E);
9228
Chad Rosier1dcde962012-08-08 18:46:20 +00009229 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009230 Base.get(), Key.get(),
9231 E->getAtIndexMethodDecl(),
9232 E->setAtIndexMethodDecl());
9233}
9234
9235template<typename Derived>
9236ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009237TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009238 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009239 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009240 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009241 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009242
Douglas Gregord51d90d2010-04-26 20:11:03 +00009243 // If nothing changed, just retain the existing expression.
9244 if (!getDerived().AlwaysRebuild() &&
9245 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00009246 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009247
John McCallb268a282010-08-23 23:25:46 +00009248 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00009249 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009250 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00009251}
9252
Mike Stump11289f42009-09-09 15:08:12 +00009253template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009254ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009255TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009256 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009257 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +00009258 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009259 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00009260 SubExprs, &ArgumentChanged))
9261 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009262
Douglas Gregora16548e2009-08-11 05:31:07 +00009263 if (!getDerived().AlwaysRebuild() &&
9264 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00009265 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00009266
Douglas Gregora16548e2009-08-11 05:31:07 +00009267 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009268 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009269 E->getRParenLoc());
9270}
9271
Mike Stump11289f42009-09-09 15:08:12 +00009272template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009273ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +00009274TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
9275 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
9276 if (SrcExpr.isInvalid())
9277 return ExprError();
9278
9279 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9280 if (!Type)
9281 return ExprError();
9282
9283 if (!getDerived().AlwaysRebuild() &&
9284 Type == E->getTypeSourceInfo() &&
9285 SrcExpr.get() == E->getSrcExpr())
9286 return SemaRef.Owned(E);
9287
9288 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
9289 SrcExpr.get(), Type,
9290 E->getRParenLoc());
9291}
9292
9293template<typename Derived>
9294ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009295TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00009296 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +00009297
John McCall490112f2011-02-04 18:33:18 +00009298 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
9299 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
9300
9301 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +00009302 blockScope->TheDecl->setBlockMissingReturnType(
9303 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +00009304
Chris Lattner01cf8db2011-07-20 06:58:45 +00009305 SmallVector<ParmVarDecl*, 4> params;
9306 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +00009307
Fariborz Jahanian1babe772010-07-09 18:44:02 +00009308 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00009309 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
9310 oldBlock->param_begin(),
9311 oldBlock->param_size(),
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009312 0, paramTypes, &params)) {
9313 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009314 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009315 }
John McCall490112f2011-02-04 18:33:18 +00009316
Jordan Rosea0a86be2013-03-08 22:25:36 +00009317 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +00009318 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +00009319 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +00009320
Jordan Rose5c382722013-03-08 21:51:21 +00009321 QualType functionType =
9322 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009323 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +00009324 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00009325
9326 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00009327 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +00009328 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +00009329
9330 if (!oldBlock->blockMissingReturnType()) {
9331 blockScope->HasImplicitReturnType = false;
9332 blockScope->ReturnType = exprResultType;
9333 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009334
John McCall3882ace2011-01-05 12:14:39 +00009335 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00009336 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009337 if (body.isInvalid()) {
9338 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall3882ace2011-01-05 12:14:39 +00009339 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009340 }
John McCall3882ace2011-01-05 12:14:39 +00009341
John McCall490112f2011-02-04 18:33:18 +00009342#ifndef NDEBUG
9343 // In builds with assertions, make sure that we captured everything we
9344 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009345 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
9346 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
9347 e = oldBlock->capture_end(); i != e; ++i) {
9348 VarDecl *oldCapture = i->getVariable();
John McCall490112f2011-02-04 18:33:18 +00009349
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009350 // Ignore parameter packs.
9351 if (isa<ParmVarDecl>(oldCapture) &&
9352 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9353 continue;
John McCall490112f2011-02-04 18:33:18 +00009354
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009355 VarDecl *newCapture =
9356 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9357 oldCapture));
9358 assert(blockScope->CaptureMap.count(newCapture));
9359 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009360 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +00009361 }
9362#endif
9363
9364 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
9365 /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00009366}
9367
Mike Stump11289f42009-09-09 15:08:12 +00009368template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009369ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +00009370TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +00009371 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +00009372}
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009373
9374template<typename Derived>
9375ExprResult
9376TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009377 QualType RetTy = getDerived().TransformType(E->getType());
9378 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009379 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009380 SubExprs.reserve(E->getNumSubExprs());
9381 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9382 SubExprs, &ArgumentChanged))
9383 return ExprError();
9384
9385 if (!getDerived().AlwaysRebuild() &&
9386 !ArgumentChanged)
9387 return SemaRef.Owned(E);
9388
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009389 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009390 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009391}
Chad Rosier1dcde962012-08-08 18:46:20 +00009392
Douglas Gregora16548e2009-08-11 05:31:07 +00009393//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00009394// Type reconstruction
9395//===----------------------------------------------------------------------===//
9396
Mike Stump11289f42009-09-09 15:08:12 +00009397template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009398QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9399 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009400 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009401 getDerived().getBaseEntity());
9402}
9403
Mike Stump11289f42009-09-09 15:08:12 +00009404template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009405QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9406 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009407 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009408 getDerived().getBaseEntity());
9409}
9410
Mike Stump11289f42009-09-09 15:08:12 +00009411template<typename Derived>
9412QualType
John McCall70dd5f62009-10-30 00:06:24 +00009413TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9414 bool WrittenAsLValue,
9415 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00009416 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00009417 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009418}
9419
9420template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009421QualType
John McCall70dd5f62009-10-30 00:06:24 +00009422TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9423 QualType ClassType,
9424 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +00009425 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
9426 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009427}
9428
9429template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009430QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00009431TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9432 ArrayType::ArraySizeModifier SizeMod,
9433 const llvm::APInt *Size,
9434 Expr *SizeExpr,
9435 unsigned IndexTypeQuals,
9436 SourceRange BracketsRange) {
9437 if (SizeExpr || !Size)
9438 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9439 IndexTypeQuals, BracketsRange,
9440 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00009441
9442 QualType Types[] = {
9443 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9444 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9445 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00009446 };
Craig Toppere5ce8312013-07-15 03:38:40 +00009447 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009448 QualType SizeType;
9449 for (unsigned I = 0; I != NumTypes; ++I)
9450 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9451 SizeType = Types[I];
9452 break;
9453 }
Mike Stump11289f42009-09-09 15:08:12 +00009454
Eli Friedman9562f392012-01-25 23:20:27 +00009455 // Note that we can return a VariableArrayType here in the case where
9456 // the element type was a dependent VariableArrayType.
9457 IntegerLiteral *ArraySize
9458 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9459 /*FIXME*/BracketsRange.getBegin());
9460 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009461 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00009462 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009463}
Mike Stump11289f42009-09-09 15:08:12 +00009464
Douglas Gregord6ff3322009-08-04 16:50:30 +00009465template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009466QualType
9467TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009468 ArrayType::ArraySizeModifier SizeMod,
9469 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00009470 unsigned IndexTypeQuals,
9471 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009472 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00009473 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009474}
9475
9476template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009477QualType
Mike Stump11289f42009-09-09 15:08:12 +00009478TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009479 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00009480 unsigned IndexTypeQuals,
9481 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009482 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00009483 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009484}
Mike Stump11289f42009-09-09 15:08:12 +00009485
Douglas Gregord6ff3322009-08-04 16:50:30 +00009486template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009487QualType
9488TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009489 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009490 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009491 unsigned IndexTypeQuals,
9492 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009493 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00009494 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009495 IndexTypeQuals, BracketsRange);
9496}
9497
9498template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009499QualType
9500TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009501 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009502 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009503 unsigned IndexTypeQuals,
9504 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009505 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00009506 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009507 IndexTypeQuals, BracketsRange);
9508}
9509
9510template<typename Derived>
9511QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00009512 unsigned NumElements,
9513 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00009514 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00009515 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
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>
9519QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9520 unsigned NumElements,
9521 SourceLocation AttributeLoc) {
9522 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9523 NumElements, true);
9524 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00009525 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9526 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00009527 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009528}
Mike Stump11289f42009-09-09 15:08:12 +00009529
Douglas Gregord6ff3322009-08-04 16:50:30 +00009530template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009531QualType
9532TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00009533 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009534 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00009535 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009536}
Mike Stump11289f42009-09-09 15:08:12 +00009537
Douglas Gregord6ff3322009-08-04 16:50:30 +00009538template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +00009539QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9540 QualType T,
9541 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009542 const FunctionProtoType::ExtProtoInfo &EPI) {
9543 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009544 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00009545 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +00009546 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009547}
Mike Stump11289f42009-09-09 15:08:12 +00009548
Douglas Gregord6ff3322009-08-04 16:50:30 +00009549template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00009550QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9551 return SemaRef.Context.getFunctionNoProtoType(T);
9552}
9553
9554template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00009555QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9556 assert(D && "no decl found");
9557 if (D->isInvalidDecl()) return QualType();
9558
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009559 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00009560 TypeDecl *Ty;
9561 if (isa<UsingDecl>(D)) {
9562 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +00009563 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +00009564 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9565
9566 // A valid resolved using typename decl points to exactly one type decl.
9567 assert(++Using->shadow_begin() == Using->shadow_end());
9568 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00009569
John McCallb96ec562009-12-04 22:46:56 +00009570 } else {
9571 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9572 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9573 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9574 }
9575
9576 return SemaRef.Context.getTypeDeclType(Ty);
9577}
9578
9579template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00009580QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9581 SourceLocation Loc) {
9582 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009583}
9584
9585template<typename Derived>
9586QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9587 return SemaRef.Context.getTypeOfType(Underlying);
9588}
9589
9590template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00009591QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9592 SourceLocation Loc) {
9593 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009594}
9595
9596template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00009597QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9598 UnaryTransformType::UTTKind UKind,
9599 SourceLocation Loc) {
9600 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9601}
9602
9603template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00009604QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00009605 TemplateName Template,
9606 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +00009607 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +00009608 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009609}
Mike Stump11289f42009-09-09 15:08:12 +00009610
Douglas Gregor1135c352009-08-06 05:28:30 +00009611template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +00009612QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9613 SourceLocation KWLoc) {
9614 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9615}
9616
9617template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009618TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009619TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00009620 bool TemplateKW,
9621 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +00009622 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00009623 Template);
9624}
9625
9626template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009627TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009628TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9629 const IdentifierInfo &Name,
9630 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00009631 QualType ObjectType,
9632 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +00009633 UnqualifiedId TemplateName;
9634 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +00009635 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +00009636 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +00009637 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009638 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +00009639 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00009640 /*EnteringContext=*/false,
9641 Template);
John McCall31f82722010-11-12 08:19:04 +00009642 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00009643}
Mike Stump11289f42009-09-09 15:08:12 +00009644
Douglas Gregora16548e2009-08-11 05:31:07 +00009645template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00009646TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009647TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00009648 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00009649 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00009650 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +00009651 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +00009652 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +00009653 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +00009654 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +00009655 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +00009656 Sema::TemplateTy Template;
9657 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009658 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +00009659 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00009660 /*EnteringContext=*/false,
9661 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +00009662 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +00009663}
Chad Rosier1dcde962012-08-08 18:46:20 +00009664
Douglas Gregor71395fa2009-11-04 00:56:37 +00009665template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009666ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009667TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9668 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00009669 Expr *OrigCallee,
9670 Expr *First,
9671 Expr *Second) {
9672 Expr *Callee = OrigCallee->IgnoreParenCasts();
9673 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00009674
Douglas Gregora16548e2009-08-11 05:31:07 +00009675 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00009676 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00009677 if (!First->getType()->isOverloadableType() &&
9678 !Second->getType()->isOverloadableType())
9679 return getSema().CreateBuiltinArraySubscriptExpr(First,
9680 Callee->getLocStart(),
9681 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00009682 } else if (Op == OO_Arrow) {
9683 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00009684 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9685 } else if (Second == 0 || isPostIncDec) {
9686 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009687 // The argument is not of overloadable type, so try to create a
9688 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00009689 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00009690 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00009691
John McCallb268a282010-08-23 23:25:46 +00009692 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00009693 }
9694 } else {
John McCallb268a282010-08-23 23:25:46 +00009695 if (!First->getType()->isOverloadableType() &&
9696 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009697 // Neither of the arguments is an overloadable type, so try to
9698 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00009699 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00009700 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00009701 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00009702 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009703 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009704
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009705 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00009706 }
9707 }
Mike Stump11289f42009-09-09 15:08:12 +00009708
9709 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00009710 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00009711 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00009712
John McCallb268a282010-08-23 23:25:46 +00009713 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00009714 assert(ULE->requiresADL());
9715
9716 // FIXME: Do we have to check
9717 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00009718 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00009719 } else {
Richard Smith58db83d2012-11-28 21:47:39 +00009720 // If we've resolved this to a particular non-member function, just call
9721 // that function. If we resolved it to a member function,
9722 // CreateOverloaded* will find that function for us.
9723 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9724 if (!isa<CXXMethodDecl>(ND))
9725 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +00009726 }
Mike Stump11289f42009-09-09 15:08:12 +00009727
Douglas Gregora16548e2009-08-11 05:31:07 +00009728 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00009729 Expr *Args[2] = { First, Second };
9730 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00009731
Douglas Gregora16548e2009-08-11 05:31:07 +00009732 // Create the overloaded operator invocation for unary operators.
9733 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00009734 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00009735 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00009736 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00009737 }
Mike Stump11289f42009-09-09 15:08:12 +00009738
Douglas Gregore9d62932011-07-15 16:25:15 +00009739 if (Op == OO_Subscript) {
9740 SourceLocation LBrace;
9741 SourceLocation RBrace;
9742
9743 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9744 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9745 LBrace = SourceLocation::getFromRawEncoding(
9746 NameLoc.CXXOperatorName.BeginOpNameLoc);
9747 RBrace = SourceLocation::getFromRawEncoding(
9748 NameLoc.CXXOperatorName.EndOpNameLoc);
9749 } else {
9750 LBrace = Callee->getLocStart();
9751 RBrace = OpLoc;
9752 }
9753
9754 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9755 First, Second);
9756 }
Sebastian Redladba46e2009-10-29 20:17:01 +00009757
Douglas Gregora16548e2009-08-11 05:31:07 +00009758 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00009759 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00009760 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00009761 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9762 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009763 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009764
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009765 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00009766}
Mike Stump11289f42009-09-09 15:08:12 +00009767
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009768template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00009769ExprResult
John McCallb268a282010-08-23 23:25:46 +00009770TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009771 SourceLocation OperatorLoc,
9772 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +00009773 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009774 TypeSourceInfo *ScopeType,
9775 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009776 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009777 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +00009778 QualType BaseType = Base->getType();
9779 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009780 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +00009781 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00009782 !BaseType->getAs<PointerType>()->getPointeeType()
9783 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009784 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00009785 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009786 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009787 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009788 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009789 /*FIXME?*/true);
9790 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009791
Douglas Gregor678f90d2010-02-25 01:56:36 +00009792 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009793 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9794 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9795 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9796 NameInfo.setNamedTypeInfo(DestroyedType);
9797
Richard Smith8e4a3862012-05-15 06:15:11 +00009798 // The scope type is now known to be a valid nested name specifier
9799 // component. Tack it on to the end of the nested name specifier.
9800 if (ScopeType)
9801 SS.Extend(SemaRef.Context, SourceLocation(),
9802 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009803
Abramo Bagnara7945c982012-01-27 09:46:47 +00009804 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +00009805 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009806 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009807 SS, TemplateKWLoc,
9808 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009809 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009810 /*TemplateArgs*/ 0);
9811}
9812
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00009813template<typename Derived>
9814StmtResult
9815TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +00009816 SourceLocation Loc = S->getLocStart();
9817 unsigned NumParams = S->getCapturedDecl()->getNumParams();
9818 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/0,
9819 S->getCapturedRegionKind(), NumParams);
9820 StmtResult Body = getDerived().TransformStmt(S->getCapturedStmt());
9821
9822 if (Body.isInvalid()) {
9823 getSema().ActOnCapturedRegionError();
9824 return StmtError();
9825 }
9826
9827 return getSema().ActOnCapturedRegionEnd(Body.take());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00009828}
9829
Douglas Gregord6ff3322009-08-04 16:50:30 +00009830} // end namespace clang
9831
9832#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H