blob: 7c343635a7f552551916b17abb0f804e472d5109 [file] [log] [blame]
Chris Lattner57ad3782011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregor577f75a2009-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 Lattner57ad3782011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-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 Lattner57ad3782011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Douglas Gregor577f75a2009-08-04 16:50:30 +000014#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_SEMA_TREETRANSFORM_H
16
Chandler Carruth55fc8732012-12-04 09:13:33 +000017#include "TypeLocBuilder.h"
Douglas Gregorc68afe22009-09-03 21:38:09 +000018#include "clang/AST/Decl.h"
John McCall7cd088e2010-08-24 07:21:54 +000019#include "clang/AST/DeclObjC.h"
Richard Smith3e4c6c42011-05-05 21:57:07 +000020#include "clang/AST/DeclTemplate.h"
Douglas Gregor657c1ac2009-08-06 22:17:10 +000021#include "clang/AST/Expr.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000022#include "clang/AST/ExprCXX.h"
23#include "clang/AST/ExprObjC.h"
Douglas Gregor43959a92009-08-20 07:17:43 +000024#include "clang/AST/Stmt.h"
25#include "clang/AST/StmtCXX.h"
26#include "clang/AST/StmtObjC.h"
Alexey Bataev4fa7eab2013-07-19 03:13:43 +000027#include "clang/AST/StmtOpenMP.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000028#include "clang/Lex/Preprocessor.h"
Chandler Carruth55fc8732012-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"
Faisal Vali618c2852013-10-03 06:29:33 +000036#include "clang/Sema/Template.h"
David Blaikiea71f9d02011-09-22 02:34:54 +000037#include "llvm/ADT/ArrayRef.h"
John McCalla2becad2009-10-21 00:40:46 +000038#include "llvm/Support/ErrorHandling.h"
Douglas Gregor577f75a2009-08-04 16:50:30 +000039#include <algorithm>
40
41namespace clang {
John McCall781472f2010-08-25 08:40:02 +000042using namespace sema;
Mike Stump1eb44332009-09-09 15:08:12 +000043
Douglas Gregor577f75a2009-08-04 16:50:30 +000044/// \brief A semantic tree transformation that allows one to transform one
45/// abstract syntax tree into another.
46///
Mike Stump1eb44332009-09-09 15:08:12 +000047/// A new tree transformation is defined by creating a new subclass \c X of
48/// \c TreeTransform<X> and then overriding certain operations to provide
49/// behavior specific to that transformation. For example, template
Douglas Gregor577f75a2009-08-04 16:50:30 +000050/// instantiation is implemented as a tree transformation where the
51/// transformation of TemplateTypeParmType nodes involves substituting the
52/// template arguments for their corresponding template parameters; a similar
53/// transformation is performed for non-type template parameters and
54/// template template parameters.
55///
56/// This tree-transformation template uses static polymorphism to allow
Mike Stump1eb44332009-09-09 15:08:12 +000057/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregor577f75a2009-08-04 16:50:30 +000058/// override any of the transformation or rebuild operators by providing an
59/// operation with the same signature as the default implementation. The
60/// overridding function should not be virtual.
61///
62/// Semantic tree transformations are split into two stages, either of which
63/// can be replaced by a subclass. The "transform" step transforms an AST node
64/// or the parts of an AST node using the various transformation functions,
65/// then passes the pieces on to the "rebuild" step, which constructs a new AST
66/// node of the appropriate kind from the pieces. The default transformation
67/// routines recursively transform the operands to composite AST nodes (e.g.,
68/// the pointee type of a PointerType node) and, if any of those operand nodes
69/// were changed by the transformation, invokes the rebuild operation to create
70/// a new AST node.
71///
Mike Stump1eb44332009-09-09 15:08:12 +000072/// Subclasses can customize the transformation at various levels. The
Douglas Gregor670444e2009-08-04 22:27:00 +000073/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregor9151c112011-03-02 18:50:38 +000074/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregor577f75a2009-08-04 16:50:30 +000075/// TransformTemplateName(), or TransformTemplateArgument() with entirely
76/// new implementations.
77///
78/// For more fine-grained transformations, subclasses can replace any of the
79/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregor43959a92009-08-20 07:17:43 +000080/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregor577f75a2009-08-04 16:50:30 +000081/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump1eb44332009-09-09 15:08:12 +000082/// to substitute template arguments for their corresponding template
Douglas Gregor577f75a2009-08-04 16:50:30 +000083/// parameters. Additionally, subclasses can override the \c RebuildXXX
84/// functions to control how AST nodes are rebuilt when their operands change.
85/// By default, \c TreeTransform will invoke semantic analysis to rebuild
86/// AST nodes. However, certain other tree transformations (e.g, cloning) may
87/// be able to use more efficient rebuild steps.
88///
89/// There are a handful of other functions that can be overridden, allowing one
Mike Stump1eb44332009-09-09 15:08:12 +000090/// to avoid traversing nodes that don't need any transformation
Douglas Gregor577f75a2009-08-04 16:50:30 +000091/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
92/// operands have not changed (\c AlwaysRebuild()), and customize the
93/// default locations and entity names used for type-checking
94/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregor577f75a2009-08-04 16:50:30 +000095template<typename Derived>
96class TreeTransform {
Douglas Gregord3731192011-01-10 07:32:04 +000097 /// \brief Private RAII object that helps us forget and then re-remember
98 /// the template argument corresponding to a partially-substituted parameter
99 /// pack.
100 class ForgetPartiallySubstitutedPackRAII {
101 Derived &Self;
102 TemplateArgument Old;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000103
Douglas Gregord3731192011-01-10 07:32:04 +0000104 public:
105 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
106 Old = Self.ForgetPartiallySubstitutedPack();
107 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000108
Douglas Gregord3731192011-01-10 07:32:04 +0000109 ~ForgetPartiallySubstitutedPackRAII() {
110 Self.RememberPartiallySubstitutedPack(Old);
111 }
112 };
Chad Rosier4a9d7952012-08-08 18:46:20 +0000113
Douglas Gregor577f75a2009-08-04 16:50:30 +0000114protected:
115 Sema &SemaRef;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000116
Douglas Gregordfca6f52012-02-13 22:00:16 +0000117 /// \brief The set of local declarations that have been transformed, for
118 /// cases where we are forced to build new declarations within the transformer
119 /// rather than in the subclass (e.g., lambda closure types).
120 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000121
Mike Stump1eb44332009-09-09 15:08:12 +0000122public:
Douglas Gregor577f75a2009-08-04 16:50:30 +0000123 /// \brief Initializes a new tree transformer.
Douglas Gregorb99268b2010-12-21 00:52:54 +0000124 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000125
Douglas Gregor577f75a2009-08-04 16:50:30 +0000126 /// \brief Retrieves a reference to the derived class.
127 Derived &getDerived() { return static_cast<Derived&>(*this); }
128
129 /// \brief Retrieves a reference to the derived class.
Mike Stump1eb44332009-09-09 15:08:12 +0000130 const Derived &getDerived() const {
131 return static_cast<const Derived&>(*this);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000132 }
133
John McCall60d7b3a2010-08-24 06:29:42 +0000134 static inline ExprResult Owned(Expr *E) { return E; }
135 static inline StmtResult Owned(Stmt *S) { return S; }
John McCall9ae2f072010-08-23 23:25:46 +0000136
Douglas Gregor577f75a2009-08-04 16:50:30 +0000137 /// \brief Retrieves a reference to the semantic analysis object used for
138 /// this tree transform.
139 Sema &getSema() const { return SemaRef; }
Mike Stump1eb44332009-09-09 15:08:12 +0000140
Douglas Gregor577f75a2009-08-04 16:50:30 +0000141 /// \brief Whether the transformation should always rebuild AST nodes, even
142 /// if none of the children have changed.
143 ///
144 /// Subclasses may override this function to specify when the transformation
145 /// should rebuild all AST nodes.
146 bool AlwaysRebuild() { return false; }
Mike Stump1eb44332009-09-09 15:08:12 +0000147
Douglas Gregor577f75a2009-08-04 16:50:30 +0000148 /// \brief Returns the location of the entity being transformed, if that
149 /// information was not available elsewhere in the AST.
150 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000151 /// By default, returns no source-location information. Subclasses can
Douglas Gregor577f75a2009-08-04 16:50:30 +0000152 /// provide an alternative implementation that provides better location
153 /// information.
154 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump1eb44332009-09-09 15:08:12 +0000155
Douglas Gregor577f75a2009-08-04 16:50:30 +0000156 /// \brief Returns the name of the entity being transformed, if that
157 /// information was not available elsewhere in the AST.
158 ///
159 /// By default, returns an empty name. Subclasses can provide an alternative
160 /// implementation with a more precise name.
161 DeclarationName getBaseEntity() { return DeclarationName(); }
162
Douglas Gregorb98b1992009-08-11 05:31:07 +0000163 /// \brief Sets the "base" location and entity when that
164 /// information is known based on another transformation.
165 ///
166 /// By default, the source location and entity are ignored. Subclasses can
167 /// override this function to provide a customized implementation.
168 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000169
Douglas Gregorb98b1992009-08-11 05:31:07 +0000170 /// \brief RAII object that temporarily sets the base location and entity
171 /// used for reporting diagnostics in types.
172 class TemporaryBase {
173 TreeTransform &Self;
174 SourceLocation OldLocation;
175 DeclarationName OldEntity;
Mike Stump1eb44332009-09-09 15:08:12 +0000176
Douglas Gregorb98b1992009-08-11 05:31:07 +0000177 public:
178 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump1eb44332009-09-09 15:08:12 +0000179 DeclarationName Entity) : Self(Self) {
Douglas Gregorb98b1992009-08-11 05:31:07 +0000180 OldLocation = Self.getDerived().getBaseLocation();
181 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000182
Douglas Gregorae201f72011-01-25 17:51:48 +0000183 if (Location.isValid())
184 Self.getDerived().setBase(Location, Entity);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000185 }
Mike Stump1eb44332009-09-09 15:08:12 +0000186
Douglas Gregorb98b1992009-08-11 05:31:07 +0000187 ~TemporaryBase() {
188 Self.getDerived().setBase(OldLocation, OldEntity);
189 }
190 };
Mike Stump1eb44332009-09-09 15:08:12 +0000191
192 /// \brief Determine whether the given type \p T has already been
Douglas Gregor577f75a2009-08-04 16:50:30 +0000193 /// transformed.
194 ///
195 /// Subclasses can provide an alternative implementation of this routine
Mike Stump1eb44332009-09-09 15:08:12 +0000196 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregor577f75a2009-08-04 16:50:30 +0000197 /// not change. For example, template instantiation need not traverse
198 /// non-dependent types.
199 bool AlreadyTransformed(QualType T) {
200 return T.isNull();
201 }
202
Douglas Gregor6eef5192009-12-14 19:27:10 +0000203 /// \brief Determine whether the given call argument should be dropped, e.g.,
204 /// because it is a default argument.
205 ///
206 /// Subclasses can provide an alternative implementation of this routine to
207 /// determine which kinds of call arguments get dropped. By default,
208 /// CXXDefaultArgument nodes are dropped (prior to transformation).
209 bool DropCallArgument(Expr *E) {
210 return E->isDefaultArgument();
211 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000212
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000213 /// \brief Determine whether we should expand a pack expansion with the
214 /// given set of parameter packs into separate arguments by repeatedly
215 /// transforming the pattern.
216 ///
Douglas Gregorb99268b2010-12-21 00:52:54 +0000217 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000218 /// Subclasses can override this routine to provide different behavior.
219 ///
220 /// \param EllipsisLoc The location of the ellipsis that identifies the
221 /// pack expansion.
222 ///
223 /// \param PatternRange The source range that covers the entire pattern of
224 /// the pack expansion.
225 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000226 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000227 /// pattern.
228 ///
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000229 /// \param ShouldExpand Will be set to \c true if the transformer should
230 /// expand the corresponding pack expansions into separate arguments. When
231 /// set, \c NumExpansions must also be set.
232 ///
Douglas Gregord3731192011-01-10 07:32:04 +0000233 /// \param RetainExpansion Whether the caller should add an unexpanded
234 /// pack expansion after all of the expanded arguments. This is used
235 /// when extending explicitly-specified template argument packs per
236 /// C++0x [temp.arg.explicit]p9.
237 ///
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000238 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregorcded4f62011-01-14 17:04:44 +0000239 /// the expanded form of the corresponding pack expansion. This is both an
240 /// input and an output parameter, which can be set by the caller if the
241 /// number of expansions is known a priori (e.g., due to a prior substitution)
242 /// and will be set by the callee when the number of expansions is known.
243 /// The callee must set this value when \c ShouldExpand is \c true; it may
244 /// set this value in other cases.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000245 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000246 /// \returns true if an error occurred (e.g., because the parameter packs
247 /// are to be instantiated with arguments of different lengths), false
248 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000249 /// must be set.
250 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
251 SourceRange PatternRange,
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +0000252 ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000253 bool &ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +0000254 bool &RetainExpansion,
David Blaikiedc84cd52013-02-20 22:23:23 +0000255 Optional<unsigned> &NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000256 ShouldExpand = false;
257 return false;
258 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000259
Douglas Gregord3731192011-01-10 07:32:04 +0000260 /// \brief "Forget" about the partially-substituted pack template argument,
261 /// when performing an instantiation that must preserve the parameter pack
262 /// use.
263 ///
264 /// This routine is meant to be overridden by the template instantiator.
265 TemplateArgument ForgetPartiallySubstitutedPack() {
266 return TemplateArgument();
267 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000268
Douglas Gregord3731192011-01-10 07:32:04 +0000269 /// \brief "Remember" the partially-substituted pack template argument
270 /// after performing an instantiation that must preserve the parameter pack
271 /// use.
272 ///
273 /// This routine is meant to be overridden by the template instantiator.
274 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000275
Douglas Gregor12c9c002011-01-07 16:43:16 +0000276 /// \brief Note to the derived class when a function parameter pack is
277 /// being expanded.
278 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000279
Douglas Gregor577f75a2009-08-04 16:50:30 +0000280 /// \brief Transforms the given type into another type.
281 ///
John McCalla2becad2009-10-21 00:40:46 +0000282 /// By default, this routine transforms a type by creating a
John McCalla93c9342009-12-07 02:54:59 +0000283 /// TypeSourceInfo for it and delegating to the appropriate
John McCalla2becad2009-10-21 00:40:46 +0000284 /// function. This is expensive, but we don't mind, because
285 /// this method is deprecated anyway; all users should be
John McCalla93c9342009-12-07 02:54:59 +0000286 /// switched to storing TypeSourceInfos.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000287 ///
288 /// \returns the transformed type.
John McCall43fed0d2010-11-12 08:19:04 +0000289 QualType TransformType(QualType T);
Mike Stump1eb44332009-09-09 15:08:12 +0000290
John McCalla2becad2009-10-21 00:40:46 +0000291 /// \brief Transforms the given type-with-location into a new
292 /// type-with-location.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000293 ///
John McCalla2becad2009-10-21 00:40:46 +0000294 /// By default, this routine transforms a type by delegating to the
295 /// appropriate TransformXXXType to build a new type. Subclasses
296 /// may override this function (to take over all type
297 /// transformations) or some set of the TransformXXXType functions
298 /// to alter the transformation.
John McCall43fed0d2010-11-12 08:19:04 +0000299 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCalla2becad2009-10-21 00:40:46 +0000300
301 /// \brief Transform the given type-with-location into a new
302 /// type, collecting location information in the given builder
303 /// as necessary.
304 ///
John McCall43fed0d2010-11-12 08:19:04 +0000305 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump1eb44332009-09-09 15:08:12 +0000306
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000307 /// \brief Transform the given statement.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000308 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000309 /// By default, this routine transforms a statement by delegating to the
Douglas Gregor43959a92009-08-20 07:17:43 +0000310 /// appropriate TransformXXXStmt function to transform a specific kind of
311 /// statement or the TransformExpr() function to transform an expression.
312 /// Subclasses may override this function to transform statements using some
313 /// other mechanism.
314 ///
315 /// \returns the transformed statement.
John McCall60d7b3a2010-08-24 06:29:42 +0000316 StmtResult TransformStmt(Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +0000317
Alexey Bataev4fa7eab2013-07-19 03:13:43 +0000318 /// \brief Transform the given statement.
319 ///
320 /// By default, this routine transforms a statement by delegating to the
321 /// appropriate TransformOMPXXXClause function to transform a specific kind
322 /// of clause. Subclasses may override this function to transform statements
323 /// using some other mechanism.
324 ///
325 /// \returns the transformed OpenMP clause.
326 OMPClause *TransformOMPClause(OMPClause *S);
327
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000328 /// \brief Transform the given expression.
329 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000330 /// By default, this routine transforms an expression by delegating to the
331 /// appropriate TransformXXXExpr function to build a new expression.
332 /// Subclasses may override this function to transform expressions using some
333 /// other mechanism.
334 ///
335 /// \returns the transformed expression.
John McCall60d7b3a2010-08-24 06:29:42 +0000336 ExprResult TransformExpr(Expr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000337
Richard Smithc83c2302012-12-19 01:39:02 +0000338 /// \brief Transform the given initializer.
339 ///
340 /// By default, this routine transforms an initializer by stripping off the
341 /// semantic nodes added by initialization, then passing the result to
342 /// TransformExpr or TransformExprs.
343 ///
344 /// \returns the transformed initializer.
345 ExprResult TransformInitializer(Expr *Init, bool CXXDirectInit);
346
Douglas Gregoraa165f82011-01-03 19:04:46 +0000347 /// \brief Transform the given list of expressions.
348 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000349 /// This routine transforms a list of expressions by invoking
350 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregoraa165f82011-01-03 19:04:46 +0000351 /// support for variadic templates by expanding any pack expansions (if the
352 /// derived class permits such expansion) along the way. When pack expansions
353 /// are present, the number of outputs may not equal the number of inputs.
354 ///
355 /// \param Inputs The set of expressions to be transformed.
356 ///
357 /// \param NumInputs The number of expressions in \c Inputs.
358 ///
359 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier4a9d7952012-08-08 18:46:20 +0000360 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregoraa165f82011-01-03 19:04:46 +0000361 /// be.
362 ///
363 /// \param Outputs The transformed input expressions will be added to this
364 /// vector.
365 ///
366 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
367 /// due to transformation.
368 ///
369 /// \returns true if an error occurred, false otherwise.
370 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +0000371 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +0000372 bool *ArgChanged = 0);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000373
Douglas Gregor577f75a2009-08-04 16:50:30 +0000374 /// \brief Transform the given declaration, which is referenced from a type
375 /// or expression.
376 ///
Douglas Gregordfca6f52012-02-13 22:00:16 +0000377 /// By default, acts as the identity function on declarations, unless the
378 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregordcee1a12009-08-06 05:28:30 +0000379 /// may override this function to provide alternate behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000380 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregordfca6f52012-02-13 22:00:16 +0000381 llvm::DenseMap<Decl *, Decl *>::iterator Known
382 = TransformedLocalDecls.find(D);
383 if (Known != TransformedLocalDecls.end())
384 return Known->second;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000385
386 return D;
Douglas Gregordfca6f52012-02-13 22:00:16 +0000387 }
Douglas Gregor43959a92009-08-20 07:17:43 +0000388
Chad Rosier4a9d7952012-08-08 18:46:20 +0000389 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregordfca6f52012-02-13 22:00:16 +0000390 /// place them on the new declaration.
391 ///
392 /// By default, this operation does nothing. Subclasses may override this
393 /// behavior to transform attributes.
394 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000395
Douglas Gregordfca6f52012-02-13 22:00:16 +0000396 /// \brief Note that a local declaration has been transformed by this
397 /// transformer.
398 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000399 /// Local declarations are typically transformed via a call to
Douglas Gregordfca6f52012-02-13 22:00:16 +0000400 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
401 /// the transformer itself has to transform the declarations. This routine
402 /// can be overridden by a subclass that keeps track of such mappings.
403 void transformedLocalDecl(Decl *Old, Decl *New) {
404 TransformedLocalDecls[Old] = New;
405 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000406
Douglas Gregor43959a92009-08-20 07:17:43 +0000407 /// \brief Transform the definition of the given declaration.
408 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000409 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregor43959a92009-08-20 07:17:43 +0000410 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000411 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
412 return getDerived().TransformDecl(Loc, D);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000413 }
Mike Stump1eb44332009-09-09 15:08:12 +0000414
Douglas Gregor6cd21982009-10-20 05:58:46 +0000415 /// \brief Transform the given declaration, which was the first part of a
416 /// nested-name-specifier in a member access expression.
417 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000418 /// This specific declaration transformation only applies to the first
Douglas Gregor6cd21982009-10-20 05:58:46 +0000419 /// identifier in a nested-name-specifier of a member access expression, e.g.,
420 /// the \c T in \c x->T::member
421 ///
422 /// By default, invokes TransformDecl() to transform the declaration.
423 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000424 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
425 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregor6cd21982009-10-20 05:58:46 +0000426 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000427
Douglas Gregorc22b5ff2011-02-25 02:25:35 +0000428 /// \brief Transform the given nested-name-specifier with source-location
429 /// information.
430 ///
431 /// By default, transforms all of the types and declarations within the
432 /// nested-name-specifier. Subclasses may override this function to provide
433 /// alternate behavior.
434 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
435 NestedNameSpecifierLoc NNS,
436 QualType ObjectType = QualType(),
437 NamedDecl *FirstQualifierInScope = 0);
438
Douglas Gregor81499bb2009-09-03 22:13:48 +0000439 /// \brief Transform the given declaration name.
440 ///
441 /// By default, transforms the types of conversion function, constructor,
442 /// and destructor names and then (if needed) rebuilds the declaration name.
443 /// Identifiers and selectors are returned unmodified. Sublcasses may
444 /// override this function to provide alternate behavior.
Abramo Bagnara25777432010-08-11 22:01:17 +0000445 DeclarationNameInfo
John McCall43fed0d2010-11-12 08:19:04 +0000446 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump1eb44332009-09-09 15:08:12 +0000447
Douglas Gregor577f75a2009-08-04 16:50:30 +0000448 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000449 ///
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000450 /// \param SS The nested-name-specifier that qualifies the template
451 /// name. This nested-name-specifier must already have been transformed.
452 ///
453 /// \param Name The template name to transform.
454 ///
455 /// \param NameLoc The source location of the template name.
456 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000457 /// \param ObjectType If we're translating a template name within a member
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000458 /// access expression, this is the type of the object whose member template
459 /// is being referenced.
460 ///
461 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
462 /// also refers to a name within the current (lexical) scope, this is the
463 /// declaration it refers to.
464 ///
465 /// By default, transforms the template name by transforming the declarations
466 /// and nested-name-specifiers that occur within the template name.
467 /// Subclasses may override this function to provide alternate behavior.
468 TemplateName TransformTemplateName(CXXScopeSpec &SS,
469 TemplateName Name,
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000470 SourceLocation NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000471 QualType ObjectType = QualType(),
472 NamedDecl *FirstQualifierInScope = 0);
473
Douglas Gregor577f75a2009-08-04 16:50:30 +0000474 /// \brief Transform the given template argument.
475 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000476 /// By default, this operation transforms the type, expression, or
477 /// declaration stored within the template argument and constructs a
Douglas Gregor670444e2009-08-04 22:27:00 +0000478 /// new template argument from the transformed result. Subclasses may
479 /// override this function to provide alternate behavior.
John McCall833ca992009-10-29 08:12:44 +0000480 ///
481 /// Returns true if there was an error.
482 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
483 TemplateArgumentLoc &Output);
484
Douglas Gregorfcc12532010-12-20 17:31:10 +0000485 /// \brief Transform the given set of template arguments.
486 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000487 /// By default, this operation transforms all of the template arguments
Douglas Gregorfcc12532010-12-20 17:31:10 +0000488 /// in the input set using \c TransformTemplateArgument(), and appends
489 /// the transformed arguments to the output list.
490 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000491 /// Note that this overload of \c TransformTemplateArguments() is merely
492 /// a convenience function. Subclasses that wish to override this behavior
493 /// should override the iterator-based member template version.
494 ///
Douglas Gregorfcc12532010-12-20 17:31:10 +0000495 /// \param Inputs The set of template arguments to be transformed.
496 ///
497 /// \param NumInputs The number of template arguments in \p Inputs.
498 ///
499 /// \param Outputs The set of transformed template arguments output by this
500 /// routine.
501 ///
502 /// Returns true if an error occurred.
503 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
504 unsigned NumInputs,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000505 TemplateArgumentListInfo &Outputs) {
506 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
507 }
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000508
509 /// \brief Transform the given set of template arguments.
510 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000511 /// By default, this operation transforms all of the template arguments
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000512 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier4a9d7952012-08-08 18:46:20 +0000513 /// the transformed arguments to the output list.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000514 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000515 /// \param First An iterator to the first template argument.
516 ///
517 /// \param Last An iterator one step past the last template argument.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000518 ///
519 /// \param Outputs The set of transformed template arguments output by this
520 /// routine.
521 ///
522 /// Returns true if an error occurred.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000523 template<typename InputIterator>
524 bool TransformTemplateArguments(InputIterator First,
525 InputIterator Last,
526 TemplateArgumentListInfo &Outputs);
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000527
John McCall833ca992009-10-29 08:12:44 +0000528 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
529 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
530 TemplateArgumentLoc &ArgLoc);
531
John McCalla93c9342009-12-07 02:54:59 +0000532 /// \brief Fakes up a TypeSourceInfo for a type.
533 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
534 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall833ca992009-10-29 08:12:44 +0000535 getDerived().getBaseLocation());
536 }
Mike Stump1eb44332009-09-09 15:08:12 +0000537
John McCalla2becad2009-10-21 00:40:46 +0000538#define ABSTRACT_TYPELOC(CLASS, PARENT)
539#define TYPELOC(CLASS, PARENT) \
John McCall43fed0d2010-11-12 08:19:04 +0000540 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCalla2becad2009-10-21 00:40:46 +0000541#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000542
Douglas Gregorcefc3af2012-04-16 07:05:22 +0000543 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
544 FunctionProtoTypeLoc TL,
545 CXXRecordDecl *ThisContext,
546 unsigned ThisTypeQuals);
547
John Wiegley28bbe4b2011-04-28 01:08:34 +0000548 StmtResult
549 TransformSEHHandler(Stmt *Handler);
550
Chad Rosier4a9d7952012-08-08 18:46:20 +0000551 QualType
John McCall43fed0d2010-11-12 08:19:04 +0000552 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
553 TemplateSpecializationTypeLoc TL,
554 TemplateName Template);
555
Chad Rosier4a9d7952012-08-08 18:46:20 +0000556 QualType
John McCall43fed0d2010-11-12 08:19:04 +0000557 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
558 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +0000559 TemplateName Template,
560 CXXScopeSpec &SS);
Douglas Gregora88f09f2011-02-28 17:23:35 +0000561
Chad Rosier4a9d7952012-08-08 18:46:20 +0000562 QualType
Douglas Gregora88f09f2011-02-28 17:23:35 +0000563 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000564 DependentTemplateSpecializationTypeLoc TL,
565 NestedNameSpecifierLoc QualifierLoc);
566
John McCall21ef0fa2010-03-11 09:03:00 +0000567 /// \brief Transforms the parameters of a function type into the
568 /// given vectors.
569 ///
570 /// The result vectors should be kept in sync; null entries in the
571 /// variables vector are acceptable.
572 ///
573 /// Return true on error.
Douglas Gregora009b592011-01-07 00:20:55 +0000574 bool TransformFunctionTypeParams(SourceLocation Loc,
575 ParmVarDecl **Params, unsigned NumParams,
576 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +0000577 SmallVectorImpl<QualType> &PTypes,
578 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall21ef0fa2010-03-11 09:03:00 +0000579
580 /// \brief Transforms a single function-type parameter. Return null
581 /// on error.
John McCallfb44de92011-05-01 22:35:37 +0000582 ///
583 /// \param indexAdjustment - A number to add to the parameter's
584 /// scope index; can be negative
Douglas Gregor6a24bfd2011-01-14 22:40:04 +0000585 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +0000586 int indexAdjustment,
David Blaikiedc84cd52013-02-20 22:23:23 +0000587 Optional<unsigned> NumExpansions,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +0000588 bool ExpectParameterPack);
John McCall21ef0fa2010-03-11 09:03:00 +0000589
John McCall43fed0d2010-11-12 08:19:04 +0000590 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall833ca992009-10-29 08:12:44 +0000591
John McCall60d7b3a2010-08-24 06:29:42 +0000592 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
593 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000594
Richard Smith612409e2012-07-25 03:56:55 +0000595 /// \brief Transform the captures and body of a lambda expression.
596 ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator);
597
Faisal Vali618c2852013-10-03 06:29:33 +0000598 TemplateParameterList *TransformTemplateParameterList(
599 TemplateParameterList *TPL) {
600 return TPL;
601 }
602
Richard Smithefeeccf2012-10-21 03:28:35 +0000603 ExprResult TransformAddressOfOperand(Expr *E);
604 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
605 bool IsAddressOfOperand);
606
Eli Friedman1ac6c932013-09-06 01:13:30 +0000607// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
608// amount of stack usage with clang.
Douglas Gregor43959a92009-08-20 07:17:43 +0000609#define STMT(Node, Parent) \
Eli Friedman1ac6c932013-09-06 01:13:30 +0000610 LLVM_ATTRIBUTE_NOINLINE \
John McCall60d7b3a2010-08-24 06:29:42 +0000611 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000612#define EXPR(Node, Parent) \
Eli Friedman1ac6c932013-09-06 01:13:30 +0000613 LLVM_ATTRIBUTE_NOINLINE \
John McCall60d7b3a2010-08-24 06:29:42 +0000614 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000615#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000616#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000617
Alexey Bataev4fa7eab2013-07-19 03:13:43 +0000618#define OPENMP_CLAUSE(Name, Class) \
Eli Friedman1ac6c932013-09-06 01:13:30 +0000619 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev4fa7eab2013-07-19 03:13:43 +0000620 OMPClause *Transform ## Class(Class *S);
621#include "clang/Basic/OpenMPKinds.def"
622
Douglas Gregor577f75a2009-08-04 16:50:30 +0000623 /// \brief Build a new pointer type given its pointee type.
624 ///
625 /// By default, performs semantic analysis when building the pointer type.
626 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000627 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000628
629 /// \brief Build a new block pointer type given its pointee type.
630 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000631 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000632 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000633 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000634
John McCall85737a72009-10-30 00:06:24 +0000635 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000636 ///
John McCall85737a72009-10-30 00:06:24 +0000637 /// By default, performs semantic analysis when building the
638 /// reference type. Subclasses may override this routine to provide
639 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000640 ///
John McCall85737a72009-10-30 00:06:24 +0000641 /// \param LValue whether the type was written with an lvalue sigil
642 /// or an rvalue sigil.
643 QualType RebuildReferenceType(QualType ReferentType,
644 bool LValue,
645 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000646
Douglas Gregor577f75a2009-08-04 16:50:30 +0000647 /// \brief Build a new member pointer type given the pointee type and the
648 /// class type it refers into.
649 ///
650 /// By default, performs semantic analysis when building the member pointer
651 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000652 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
653 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000654
Douglas Gregor577f75a2009-08-04 16:50:30 +0000655 /// \brief Build a new array type given the element type, size
656 /// modifier, size of the array (if known), size expression, and index type
657 /// qualifiers.
658 ///
659 /// By default, performs semantic analysis when building the array type.
660 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000661 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000662 QualType RebuildArrayType(QualType ElementType,
663 ArrayType::ArraySizeModifier SizeMod,
664 const llvm::APInt *Size,
665 Expr *SizeExpr,
666 unsigned IndexTypeQuals,
667 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000668
Douglas Gregor577f75a2009-08-04 16:50:30 +0000669 /// \brief Build a new constant array type given the element type, size
670 /// modifier, (known) size of the array, and index type qualifiers.
671 ///
672 /// By default, performs semantic analysis when building the array type.
673 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000674 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000675 ArrayType::ArraySizeModifier SizeMod,
676 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000677 unsigned IndexTypeQuals,
678 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000679
Douglas Gregor577f75a2009-08-04 16:50:30 +0000680 /// \brief Build a new incomplete array type given the element type, size
681 /// modifier, and index type qualifiers.
682 ///
683 /// By default, performs semantic analysis when building the array type.
684 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000685 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000686 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000687 unsigned IndexTypeQuals,
688 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000689
Mike Stump1eb44332009-09-09 15:08:12 +0000690 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000691 /// size modifier, size expression, and index type qualifiers.
692 ///
693 /// By default, performs semantic analysis when building the array type.
694 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000695 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000696 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000697 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000698 unsigned IndexTypeQuals,
699 SourceRange BracketsRange);
700
Mike Stump1eb44332009-09-09 15:08:12 +0000701 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000702 /// size modifier, size expression, and index type qualifiers.
703 ///
704 /// By default, performs semantic analysis when building the array type.
705 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000706 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000707 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000708 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000709 unsigned IndexTypeQuals,
710 SourceRange BracketsRange);
711
712 /// \brief Build a new vector type given the element type and
713 /// number of elements.
714 ///
715 /// By default, performs semantic analysis when building the vector type.
716 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000717 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000718 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000719
Douglas Gregor577f75a2009-08-04 16:50:30 +0000720 /// \brief Build a new extended vector type given the element type and
721 /// number of elements.
722 ///
723 /// By default, performs semantic analysis when building the vector type.
724 /// Subclasses may override this routine to provide different behavior.
725 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
726 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000727
728 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000729 /// given the element type and number of elements.
730 ///
731 /// By default, performs semantic analysis when building the vector type.
732 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000733 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000734 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000735 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000736
Douglas Gregor577f75a2009-08-04 16:50:30 +0000737 /// \brief Build a new function type.
738 ///
739 /// By default, performs semantic analysis when building the function type.
740 /// Subclasses may override this routine to provide different behavior.
741 QualType RebuildFunctionProtoType(QualType T,
Jordan Rosebea522f2013-03-08 21:51:21 +0000742 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +0000743 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump1eb44332009-09-09 15:08:12 +0000744
John McCalla2becad2009-10-21 00:40:46 +0000745 /// \brief Build a new unprototyped function type.
746 QualType RebuildFunctionNoProtoType(QualType ResultType);
747
John McCalled976492009-12-04 22:46:56 +0000748 /// \brief Rebuild an unresolved typename type, given the decl that
749 /// the UnresolvedUsingTypenameDecl was transformed to.
750 QualType RebuildUnresolvedUsingType(Decl *D);
751
Douglas Gregor577f75a2009-08-04 16:50:30 +0000752 /// \brief Build a new typedef type.
Richard Smith162e1c12011-04-15 14:24:37 +0000753 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregor577f75a2009-08-04 16:50:30 +0000754 return SemaRef.Context.getTypeDeclType(Typedef);
755 }
756
757 /// \brief Build a new class/struct/union type.
758 QualType RebuildRecordType(RecordDecl *Record) {
759 return SemaRef.Context.getTypeDeclType(Record);
760 }
761
762 /// \brief Build a new Enum type.
763 QualType RebuildEnumType(EnumDecl *Enum) {
764 return SemaRef.Context.getTypeDeclType(Enum);
765 }
John McCall7da24312009-09-05 00:15:47 +0000766
Mike Stump1eb44332009-09-09 15:08:12 +0000767 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000768 ///
769 /// By default, performs semantic analysis when building the typeof type.
770 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000771 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000772
Mike Stump1eb44332009-09-09 15:08:12 +0000773 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000774 ///
775 /// By default, builds a new TypeOfType with the given underlying type.
776 QualType RebuildTypeOfType(QualType Underlying);
777
Sean Huntca63c202011-05-24 22:41:36 +0000778 /// \brief Build a new unary transform type.
779 QualType RebuildUnaryTransformType(QualType BaseType,
780 UnaryTransformType::UTTKind UKind,
781 SourceLocation Loc);
782
Richard Smitha2c36462013-04-26 16:15:35 +0000783 /// \brief Build a new C++11 decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000784 ///
785 /// By default, performs semantic analysis when building the decltype type.
786 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000787 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000788
Richard Smitha2c36462013-04-26 16:15:35 +0000789 /// \brief Build a new C++11 auto type.
Richard Smith34b41d92011-02-20 03:19:35 +0000790 ///
791 /// By default, builds a new AutoType with the given deduced type.
Richard Smitha2c36462013-04-26 16:15:35 +0000792 QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) {
Richard Smithdc7a4f52013-04-30 13:56:41 +0000793 // Note, IsDependent is always false here: we implicitly convert an 'auto'
794 // which has been deduced to a dependent type into an undeduced 'auto', so
795 // that we'll retry deduction after the transformation.
Faisal Valifad9e132013-09-26 19:54:12 +0000796 return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto,
797 /*IsDependent*/ false);
Richard Smith34b41d92011-02-20 03:19:35 +0000798 }
799
Douglas Gregor577f75a2009-08-04 16:50:30 +0000800 /// \brief Build a new template specialization type.
801 ///
802 /// By default, performs semantic analysis when building the template
803 /// specialization type. Subclasses may override this routine to provide
804 /// different behavior.
805 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000806 SourceLocation TemplateLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000807 TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000808
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000809 /// \brief Build a new parenthesized type.
810 ///
811 /// By default, builds a new ParenType type from the inner type.
812 /// Subclasses may override this routine to provide different behavior.
813 QualType RebuildParenType(QualType InnerType) {
814 return SemaRef.Context.getParenType(InnerType);
815 }
816
Douglas Gregor577f75a2009-08-04 16:50:30 +0000817 /// \brief Build a new qualified name type.
818 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000819 /// By default, builds a new ElaboratedType type from the keyword,
820 /// the nested-name-specifier and the named type.
821 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000822 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
823 ElaboratedTypeKeyword Keyword,
Douglas Gregor9e876872011-03-01 18:12:44 +0000824 NestedNameSpecifierLoc QualifierLoc,
825 QualType Named) {
Chad Rosier4a9d7952012-08-08 18:46:20 +0000826 return SemaRef.Context.getElaboratedType(Keyword,
827 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor9e876872011-03-01 18:12:44 +0000828 Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000829 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000830
831 /// \brief Build a new typename type that refers to a template-id.
832 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000833 /// By default, builds a new DependentNameType type from the
834 /// nested-name-specifier and the given type. Subclasses may override
835 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000836 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000837 ElaboratedTypeKeyword Keyword,
838 NestedNameSpecifierLoc QualifierLoc,
839 const IdentifierInfo *Name,
840 SourceLocation NameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000841 TemplateArgumentListInfo &Args) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000842 // Rebuild the template name.
843 // TODO: avoid TemplateName abstraction
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000844 CXXScopeSpec SS;
845 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000846 TemplateName InstName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000847 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000848
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000849 if (InstName.isNull())
850 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000851
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000852 // If it's still dependent, make a dependent specialization.
853 if (InstName.getAsDependentTemplateName())
Chad Rosier4a9d7952012-08-08 18:46:20 +0000854 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
855 QualifierLoc.getNestedNameSpecifier(),
856 Name,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000857 Args);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000858
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000859 // Otherwise, make an elaborated type wrapping a non-dependent
860 // specialization.
861 QualType T =
862 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
863 if (T.isNull()) return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000864
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000865 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
866 return T;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000867
868 return SemaRef.Context.getElaboratedType(Keyword,
869 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000870 T);
871 }
872
Douglas Gregor577f75a2009-08-04 16:50:30 +0000873 /// \brief Build a new typename type that refers to an identifier.
874 ///
875 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000876 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000877 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000878 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000879 SourceLocation KeywordLoc,
Douglas Gregor2494dd02011-03-01 01:34:45 +0000880 NestedNameSpecifierLoc QualifierLoc,
881 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000882 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000883 CXXScopeSpec SS;
Douglas Gregor2494dd02011-03-01 01:34:45 +0000884 SS.Adopt(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000885
Douglas Gregor2494dd02011-03-01 01:34:45 +0000886 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000887 // If the name is still dependent, just build a new dependent name type.
888 if (!SemaRef.computeDeclContext(SS))
Chad Rosier4a9d7952012-08-08 18:46:20 +0000889 return SemaRef.Context.getDependentNameType(Keyword,
890 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000891 Id);
Douglas Gregor40336422010-03-31 22:19:08 +0000892 }
893
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000894 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor2494dd02011-03-01 01:34:45 +0000895 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregore29425b2011-02-28 22:42:13 +0000896 *Id, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000897
898 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
899
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000900 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000901 // into a non-dependent elaborated-type-specifier. Find the tag we're
902 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000903 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000904 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
905 if (!DC)
906 return QualType();
907
John McCall56138762010-05-27 06:40:31 +0000908 if (SemaRef.RequireCompleteDeclContext(SS, DC))
909 return QualType();
910
Douglas Gregor40336422010-03-31 22:19:08 +0000911 TagDecl *Tag = 0;
912 SemaRef.LookupQualifiedName(Result, DC);
913 switch (Result.getResultKind()) {
914 case LookupResult::NotFound:
915 case LookupResult::NotFoundInCurrentInstantiation:
916 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000917
Douglas Gregor40336422010-03-31 22:19:08 +0000918 case LookupResult::Found:
919 Tag = Result.getAsSingle<TagDecl>();
920 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000921
Douglas Gregor40336422010-03-31 22:19:08 +0000922 case LookupResult::FoundOverloaded:
923 case LookupResult::FoundUnresolvedValue:
924 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier4a9d7952012-08-08 18:46:20 +0000925
Douglas Gregor40336422010-03-31 22:19:08 +0000926 case LookupResult::Ambiguous:
927 // Let the LookupResult structure handle ambiguities.
928 return QualType();
929 }
930
931 if (!Tag) {
Nick Lewycky446e4022011-01-24 19:01:04 +0000932 // Check where the name exists but isn't a tag type and use that to emit
933 // better diagnostics.
934 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
935 SemaRef.LookupQualifiedName(Result, DC);
936 switch (Result.getResultKind()) {
937 case LookupResult::Found:
938 case LookupResult::FoundOverloaded:
939 case LookupResult::FoundUnresolvedValue: {
Richard Smith3e4c6c42011-05-05 21:57:07 +0000940 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky446e4022011-01-24 19:01:04 +0000941 unsigned Kind = 0;
942 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smith162e1c12011-04-15 14:24:37 +0000943 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
944 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky446e4022011-01-24 19:01:04 +0000945 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
946 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
947 break;
Richard Smith3e4c6c42011-05-05 21:57:07 +0000948 }
Nick Lewycky446e4022011-01-24 19:01:04 +0000949 default:
950 // FIXME: Would be nice to highlight just the source range.
951 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
952 << Kind << Id << DC;
953 break;
954 }
Douglas Gregor40336422010-03-31 22:19:08 +0000955 return QualType();
956 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000957
Richard Trieubbf34c02011-06-10 03:11:26 +0000958 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
959 IdLoc, *Id)) {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000960 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000961 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
962 return QualType();
963 }
964
965 // Build the elaborated-type-specifier type.
966 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000967 return SemaRef.Context.getElaboratedType(Keyword,
968 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000969 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000970 }
Mike Stump1eb44332009-09-09 15:08:12 +0000971
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000972 /// \brief Build a new pack expansion type.
973 ///
974 /// By default, builds a new PackExpansionType type from the given pattern.
975 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000976 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000977 SourceRange PatternRange,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000978 SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +0000979 Optional<unsigned> NumExpansions) {
Douglas Gregorcded4f62011-01-14 17:04:44 +0000980 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
981 NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000982 }
983
Eli Friedmanb001de72011-10-06 23:00:33 +0000984 /// \brief Build a new atomic type given its value type.
985 ///
986 /// By default, performs semantic analysis when building the atomic type.
987 /// Subclasses may override this routine to provide different behavior.
988 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
989
Douglas Gregord1067e52009-08-06 06:41:21 +0000990 /// \brief Build a new template name given a nested name specifier, a flag
991 /// indicating whether the "template" keyword was provided, and the template
992 /// that the template name refers to.
993 ///
994 /// By default, builds the new template name directly. Subclasses may override
995 /// this routine to provide different behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000996 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +0000997 bool TemplateKW,
998 TemplateDecl *Template);
999
Douglas Gregord1067e52009-08-06 06:41:21 +00001000 /// \brief Build a new template name given a nested name specifier and the
1001 /// name that is referred to as a template.
1002 ///
1003 /// By default, performs semantic analysis to determine whether the name can
1004 /// be resolved to a specific template, then builds the appropriate kind of
1005 /// template name. Subclasses may override this routine to provide different
1006 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00001007 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1008 const IdentifierInfo &Name,
1009 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00001010 QualType ObjectType,
1011 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +00001012
Douglas Gregorca1bdd72009-11-04 00:56:37 +00001013 /// \brief Build a new template name given a nested name specifier and the
1014 /// overloaded operator name that is referred to as a template.
1015 ///
1016 /// By default, performs semantic analysis to determine whether the name can
1017 /// be resolved to a specific template, then builds the appropriate kind of
1018 /// template name. Subclasses may override this routine to provide different
1019 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00001020 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00001021 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00001022 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00001023 QualType ObjectType);
Douglas Gregor1aee05d2011-01-15 06:45:20 +00001024
1025 /// \brief Build a new template name given a template template parameter pack
Chad Rosier4a9d7952012-08-08 18:46:20 +00001026 /// and the
Douglas Gregor1aee05d2011-01-15 06:45:20 +00001027 ///
1028 /// By default, performs semantic analysis to determine whether the name can
1029 /// be resolved to a specific template, then builds the appropriate kind of
1030 /// template name. Subclasses may override this routine to provide different
1031 /// behavior.
1032 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1033 const TemplateArgument &ArgPack) {
1034 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1035 }
1036
Douglas Gregor43959a92009-08-20 07:17:43 +00001037 /// \brief Build a new compound statement.
1038 ///
1039 /// By default, performs semantic analysis to build the new statement.
1040 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001041 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001042 MultiStmtArg Statements,
1043 SourceLocation RBraceLoc,
1044 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +00001045 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00001046 IsStmtExpr);
1047 }
1048
1049 /// \brief Build a new case statement.
1050 ///
1051 /// By default, performs semantic analysis to build the new statement.
1052 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001053 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001054 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001055 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001056 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001057 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001058 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001059 ColonLoc);
1060 }
Mike Stump1eb44332009-09-09 15:08:12 +00001061
Douglas Gregor43959a92009-08-20 07:17:43 +00001062 /// \brief Attach the body to a new case statement.
1063 ///
1064 /// By default, performs semantic analysis to build the new statement.
1065 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001066 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001067 getSema().ActOnCaseStmtBody(S, Body);
1068 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +00001069 }
Mike Stump1eb44332009-09-09 15:08:12 +00001070
Douglas Gregor43959a92009-08-20 07:17:43 +00001071 /// \brief Build a new default statement.
1072 ///
1073 /// By default, performs semantic analysis to build the new statement.
1074 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001075 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001076 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001077 Stmt *SubStmt) {
1078 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +00001079 /*CurScope=*/0);
1080 }
Mike Stump1eb44332009-09-09 15:08:12 +00001081
Douglas Gregor43959a92009-08-20 07:17:43 +00001082 /// \brief Build a new label statement.
1083 ///
1084 /// By default, performs semantic analysis to build the new statement.
1085 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001086 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1087 SourceLocation ColonLoc, Stmt *SubStmt) {
1088 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregor43959a92009-08-20 07:17:43 +00001089 }
Mike Stump1eb44332009-09-09 15:08:12 +00001090
Richard Smith534986f2012-04-14 00:33:13 +00001091 /// \brief Build a new label statement.
1092 ///
1093 /// By default, performs semantic analysis to build the new statement.
1094 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko49908902012-07-09 10:04:07 +00001095 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1096 ArrayRef<const Attr*> Attrs,
Richard Smith534986f2012-04-14 00:33:13 +00001097 Stmt *SubStmt) {
1098 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1099 }
1100
Douglas Gregor43959a92009-08-20 07:17:43 +00001101 /// \brief Build a new "if" statement.
1102 ///
1103 /// By default, performs semantic analysis to build the new statement.
1104 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001105 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001106 VarDecl *CondVar, Stmt *Then,
Chris Lattner57ad3782011-02-17 20:34:02 +00001107 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001108 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +00001109 }
Mike Stump1eb44332009-09-09 15:08:12 +00001110
Douglas Gregor43959a92009-08-20 07:17:43 +00001111 /// \brief Start building a new switch statement.
1112 ///
1113 /// By default, performs semantic analysis to build the new statement.
1114 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001115 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001116 Expr *Cond, VarDecl *CondVar) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001117 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001118 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001119 }
Mike Stump1eb44332009-09-09 15:08:12 +00001120
Douglas Gregor43959a92009-08-20 07:17:43 +00001121 /// \brief Attach the body to the switch statement.
1122 ///
1123 /// By default, performs semantic analysis to build the new statement.
1124 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001125 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001126 Stmt *Switch, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001127 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001128 }
1129
1130 /// \brief Build a new while statement.
1131 ///
1132 /// By default, performs semantic analysis to build the new statement.
1133 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001134 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1135 VarDecl *CondVar, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001136 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001137 }
Mike Stump1eb44332009-09-09 15:08:12 +00001138
Douglas Gregor43959a92009-08-20 07:17:43 +00001139 /// \brief Build a new do-while statement.
1140 ///
1141 /// By default, performs semantic analysis to build the new statement.
1142 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001143 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001144 SourceLocation WhileLoc, SourceLocation LParenLoc,
1145 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001146 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1147 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001148 }
1149
1150 /// \brief Build a new for statement.
1151 ///
1152 /// By default, performs semantic analysis to build the new statement.
1153 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001154 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001155 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001156 VarDecl *CondVar, Sema::FullExprArg Inc,
1157 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001158 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001159 CondVar, Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001160 }
Mike Stump1eb44332009-09-09 15:08:12 +00001161
Douglas Gregor43959a92009-08-20 07:17:43 +00001162 /// \brief Build a new goto statement.
1163 ///
1164 /// By default, performs semantic analysis to build the new statement.
1165 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001166 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1167 LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001168 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregor43959a92009-08-20 07:17:43 +00001169 }
1170
1171 /// \brief Build a new indirect goto statement.
1172 ///
1173 /// By default, performs semantic analysis to build the new statement.
1174 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001175 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001176 SourceLocation StarLoc,
1177 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001178 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001179 }
Mike Stump1eb44332009-09-09 15:08:12 +00001180
Douglas Gregor43959a92009-08-20 07:17:43 +00001181 /// \brief Build a new return statement.
1182 ///
1183 /// By default, performs semantic analysis to build the new statement.
1184 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001185 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001186 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001187 }
Mike Stump1eb44332009-09-09 15:08:12 +00001188
Douglas Gregor43959a92009-08-20 07:17:43 +00001189 /// \brief Build a new declaration statement.
1190 ///
1191 /// By default, performs semantic analysis to build the new statement.
1192 /// Subclasses may override this routine to provide different behavior.
Rafael Espindola4549d7f2013-07-09 12:05:01 +00001193 StmtResult RebuildDeclStmt(llvm::MutableArrayRef<Decl *> Decls,
1194 SourceLocation StartLoc, SourceLocation EndLoc) {
1195 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith406c38e2011-02-23 00:37:57 +00001196 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001197 }
Mike Stump1eb44332009-09-09 15:08:12 +00001198
Anders Carlsson703e3942010-01-24 05:50:09 +00001199 /// \brief Build a new inline asm statement.
1200 ///
1201 /// By default, performs semantic analysis to build the new statement.
1202 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001203 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1204 bool IsVolatile, unsigned NumOutputs,
1205 unsigned NumInputs, IdentifierInfo **Names,
1206 MultiExprArg Constraints, MultiExprArg Exprs,
1207 Expr *AsmString, MultiExprArg Clobbers,
1208 SourceLocation RParenLoc) {
1209 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1210 NumInputs, Names, Constraints, Exprs,
1211 AsmString, Clobbers, RParenLoc);
Anders Carlsson703e3942010-01-24 05:50:09 +00001212 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001213
Chad Rosier8cd64b42012-06-11 20:47:18 +00001214 /// \brief Build a new MS style inline asm statement.
1215 ///
1216 /// By default, performs semantic analysis to build the new statement.
1217 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001218 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallaeeacf72013-05-03 00:10:13 +00001219 ArrayRef<Token> AsmToks,
1220 StringRef AsmString,
1221 unsigned NumOutputs, unsigned NumInputs,
1222 ArrayRef<StringRef> Constraints,
1223 ArrayRef<StringRef> Clobbers,
1224 ArrayRef<Expr*> Exprs,
1225 SourceLocation EndLoc) {
1226 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1227 NumOutputs, NumInputs,
1228 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier8cd64b42012-06-11 20:47:18 +00001229 }
1230
James Dennett699c9042012-06-15 07:13:21 +00001231 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001232 ///
1233 /// By default, performs semantic analysis to build the new statement.
1234 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001235 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001236 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001237 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001238 Stmt *Finally) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001239 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001240 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001241 }
1242
Douglas Gregorbe270a02010-04-26 17:57:08 +00001243 /// \brief Rebuild an Objective-C exception declaration.
1244 ///
1245 /// By default, performs semantic analysis to build the new declaration.
1246 /// Subclasses may override this routine to provide different behavior.
1247 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1248 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001249 return getSema().BuildObjCExceptionDecl(TInfo, T,
1250 ExceptionDecl->getInnerLocStart(),
1251 ExceptionDecl->getLocation(),
1252 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001253 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001254
James Dennett699c9042012-06-15 07:13:21 +00001255 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorbe270a02010-04-26 17:57:08 +00001256 ///
1257 /// By default, performs semantic analysis to build the new statement.
1258 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001259 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001260 SourceLocation RParenLoc,
1261 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001262 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001263 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001264 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001265 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001266
James Dennett699c9042012-06-15 07:13:21 +00001267 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001268 ///
1269 /// By default, performs semantic analysis to build the new statement.
1270 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001271 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001272 Stmt *Body) {
1273 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001274 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001275
James Dennett699c9042012-06-15 07:13:21 +00001276 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001277 ///
1278 /// By default, performs semantic analysis to build the new statement.
1279 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001280 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001281 Expr *Operand) {
1282 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001283 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001284
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00001285 /// \brief Build a new OpenMP parallel directive.
1286 ///
1287 /// By default, performs semantic analysis to build the new statement.
1288 /// Subclasses may override this routine to provide different behavior.
1289 StmtResult RebuildOMPParallelDirective(ArrayRef<OMPClause *> Clauses,
1290 Stmt *AStmt,
1291 SourceLocation StartLoc,
1292 SourceLocation EndLoc) {
1293 return getSema().ActOnOpenMPParallelDirective(Clauses, AStmt,
1294 StartLoc, EndLoc);
1295 }
1296
1297 /// \brief Build a new OpenMP 'default' clause.
1298 ///
1299 /// By default, performs semantic analysis to build the new statement.
1300 /// Subclasses may override this routine to provide different behavior.
1301 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1302 SourceLocation KindKwLoc,
1303 SourceLocation StartLoc,
1304 SourceLocation LParenLoc,
1305 SourceLocation EndLoc) {
1306 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1307 StartLoc, LParenLoc, EndLoc);
1308 }
1309
1310 /// \brief Build a new OpenMP 'private' clause.
1311 ///
1312 /// By default, performs semantic analysis to build the new statement.
1313 /// Subclasses may override this routine to provide different behavior.
1314 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1315 SourceLocation StartLoc,
1316 SourceLocation LParenLoc,
1317 SourceLocation EndLoc) {
1318 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1319 EndLoc);
1320 }
1321
Alexey Bataevd195bc32013-10-01 05:32:34 +00001322 /// \brief Build a new OpenMP 'firstprivate' clause.
1323 ///
1324 /// By default, performs semantic analysis to build the new statement.
1325 /// Subclasses may override this routine to provide different behavior.
1326 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1327 SourceLocation StartLoc,
1328 SourceLocation LParenLoc,
1329 SourceLocation EndLoc) {
1330 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1331 EndLoc);
1332 }
1333
Alexey Bataev0c018352013-09-06 18:03:48 +00001334 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1335 SourceLocation StartLoc,
1336 SourceLocation LParenLoc,
1337 SourceLocation EndLoc) {
1338 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1339 EndLoc);
1340 }
1341
James Dennett699c9042012-06-15 07:13:21 +00001342 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCall07524032011-07-27 21:50:02 +00001343 ///
1344 /// By default, performs semantic analysis to build the new statement.
1345 /// Subclasses may override this routine to provide different behavior.
1346 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1347 Expr *object) {
1348 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1349 }
1350
James Dennett699c9042012-06-15 07:13:21 +00001351 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001352 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001353 /// By default, performs semantic analysis to build the new statement.
1354 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001355 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall07524032011-07-27 21:50:02 +00001356 Expr *Object, Stmt *Body) {
1357 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001358 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001359
James Dennett699c9042012-06-15 07:13:21 +00001360 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCallf85e1932011-06-15 23:02:42 +00001361 ///
1362 /// By default, performs semantic analysis to build the new statement.
1363 /// Subclasses may override this routine to provide different behavior.
1364 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1365 Stmt *Body) {
1366 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1367 }
John McCall990567c2011-07-27 01:07:15 +00001368
Douglas Gregorc3203e72010-04-22 23:10:45 +00001369 /// \brief Build a new Objective-C fast enumeration statement.
1370 ///
1371 /// By default, performs semantic analysis to build the new statement.
1372 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001373 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001374 Stmt *Element,
1375 Expr *Collection,
1376 SourceLocation RParenLoc,
1377 Stmt *Body) {
Sam Panzerbc20bbb2012-08-16 21:47:25 +00001378 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001379 Element,
John McCall9ae2f072010-08-23 23:25:46 +00001380 Collection,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001381 RParenLoc);
1382 if (ForEachStmt.isInvalid())
1383 return StmtError();
1384
1385 return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001386 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001387
Douglas Gregor43959a92009-08-20 07:17:43 +00001388 /// \brief Build a new C++ exception declaration.
1389 ///
1390 /// By default, performs semantic analysis to build the new decaration.
1391 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001392 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001393 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001394 SourceLocation StartLoc,
1395 SourceLocation IdLoc,
1396 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001397 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1398 StartLoc, IdLoc, Id);
1399 if (Var)
1400 getSema().CurContext->addDecl(Var);
1401 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001402 }
1403
1404 /// \brief Build a new C++ catch statement.
1405 ///
1406 /// By default, performs semantic analysis to build the new statement.
1407 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001408 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001409 VarDecl *ExceptionDecl,
1410 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001411 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1412 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001413 }
Mike Stump1eb44332009-09-09 15:08:12 +00001414
Douglas Gregor43959a92009-08-20 07:17:43 +00001415 /// \brief Build a new C++ try statement.
1416 ///
1417 /// By default, performs semantic analysis to build the new statement.
1418 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelm21adb0c2013-08-22 09:20:03 +00001419 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1420 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001421 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00001422 }
Mike Stump1eb44332009-09-09 15:08:12 +00001423
Richard Smithad762fc2011-04-14 22:09:26 +00001424 /// \brief Build a new C++0x range-based for statement.
1425 ///
1426 /// By default, performs semantic analysis to build the new statement.
1427 /// Subclasses may override this routine to provide different behavior.
1428 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1429 SourceLocation ColonLoc,
1430 Stmt *Range, Stmt *BeginEnd,
1431 Expr *Cond, Expr *Inc,
1432 Stmt *LoopVar,
1433 SourceLocation RParenLoc) {
Douglas Gregor6f96f4b2013-04-08 18:40:13 +00001434 // If we've just learned that the range is actually an Objective-C
1435 // collection, treat this as an Objective-C fast enumeration loop.
1436 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1437 if (RangeStmt->isSingleDecl()) {
1438 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39b60dc2013-05-02 18:35:56 +00001439 if (RangeVar->isInvalidDecl())
1440 return StmtError();
1441
Douglas Gregor6f96f4b2013-04-08 18:40:13 +00001442 Expr *RangeExpr = RangeVar->getInit();
1443 if (!RangeExpr->isTypeDependent() &&
1444 RangeExpr->getType()->isObjCObjectPointerType())
1445 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1446 RParenLoc);
1447 }
1448 }
1449 }
1450
Richard Smithad762fc2011-04-14 22:09:26 +00001451 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smith8b533d92012-09-20 21:52:32 +00001452 Cond, Inc, LoopVar, RParenLoc,
1453 Sema::BFRK_Rebuild);
Richard Smithad762fc2011-04-14 22:09:26 +00001454 }
Douglas Gregorba0513d2011-10-25 01:33:02 +00001455
1456 /// \brief Build a new C++0x range-based for statement.
1457 ///
1458 /// By default, performs semantic analysis to build the new statement.
1459 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001460 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregorba0513d2011-10-25 01:33:02 +00001461 bool IsIfExists,
1462 NestedNameSpecifierLoc QualifierLoc,
1463 DeclarationNameInfo NameInfo,
1464 Stmt *Nested) {
1465 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1466 QualifierLoc, NameInfo, Nested);
1467 }
1468
Richard Smithad762fc2011-04-14 22:09:26 +00001469 /// \brief Attach body to a C++0x range-based for statement.
1470 ///
1471 /// By default, performs semantic analysis to finish the new statement.
1472 /// Subclasses may override this routine to provide different behavior.
1473 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1474 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1475 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001476
John Wiegley28bbe4b2011-04-28 01:08:34 +00001477 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1478 SourceLocation TryLoc,
1479 Stmt *TryBlock,
1480 Stmt *Handler) {
1481 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1482 }
1483
1484 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1485 Expr *FilterExpr,
1486 Stmt *Block) {
1487 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1488 }
1489
1490 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1491 Stmt *Block) {
1492 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1493 }
1494
Douglas Gregorb98b1992009-08-11 05:31:07 +00001495 /// \brief Build a new expression that references a declaration.
1496 ///
1497 /// By default, performs semantic analysis to build the new expression.
1498 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001499 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001500 LookupResult &R,
1501 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001502 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1503 }
1504
1505
1506 /// \brief Build a new expression that references a declaration.
1507 ///
1508 /// By default, performs semantic analysis to build the new expression.
1509 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001510 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001511 ValueDecl *VD,
1512 const DeclarationNameInfo &NameInfo,
1513 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001514 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001515 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001516
1517 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001518
1519 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001520 }
Mike Stump1eb44332009-09-09 15:08:12 +00001521
Douglas Gregorb98b1992009-08-11 05:31:07 +00001522 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001523 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001524 /// By default, performs semantic analysis to build the new expression.
1525 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001526 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001527 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001528 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001529 }
1530
Douglas Gregora71d8192009-09-04 17:36:40 +00001531 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001532 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001533 /// By default, performs semantic analysis to build the new expression.
1534 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001535 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001536 SourceLocation OperatorLoc,
1537 bool isArrow,
1538 CXXScopeSpec &SS,
1539 TypeSourceInfo *ScopeType,
1540 SourceLocation CCLoc,
1541 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001542 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001543
Douglas Gregorb98b1992009-08-11 05:31:07 +00001544 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001545 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001546 /// By default, performs semantic analysis to build the new expression.
1547 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001548 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001549 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001550 Expr *SubExpr) {
1551 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001552 }
Mike Stump1eb44332009-09-09 15:08:12 +00001553
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001554 /// \brief Build a new builtin offsetof expression.
1555 ///
1556 /// By default, performs semantic analysis to build the new expression.
1557 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001558 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001559 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001560 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001561 unsigned NumComponents,
1562 SourceLocation RParenLoc) {
1563 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1564 NumComponents, RParenLoc);
1565 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001566
1567 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001568 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001569 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001570 /// By default, performs semantic analysis to build the new expression.
1571 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001572 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1573 SourceLocation OpLoc,
1574 UnaryExprOrTypeTrait ExprKind,
1575 SourceRange R) {
1576 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001577 }
1578
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001579 /// \brief Build a new sizeof, alignof or vec step expression with an
1580 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001581 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001582 /// By default, performs semantic analysis to build the new expression.
1583 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001584 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1585 UnaryExprOrTypeTrait ExprKind,
1586 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001587 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001588 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001589 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001590 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001591
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001592 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001593 }
Mike Stump1eb44332009-09-09 15:08:12 +00001594
Douglas Gregorb98b1992009-08-11 05:31:07 +00001595 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001596 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001597 /// By default, performs semantic analysis to build the new expression.
1598 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001599 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001600 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001601 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001602 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001603 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1604 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001605 RBracketLoc);
1606 }
1607
1608 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001609 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001610 /// By default, performs semantic analysis to build the new expression.
1611 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001612 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001613 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001614 SourceLocation RParenLoc,
1615 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001616 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001617 Args, RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001618 }
1619
1620 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001621 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001622 /// By default, performs semantic analysis to build the new expression.
1623 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001624 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001625 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001626 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001627 SourceLocation TemplateKWLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001628 const DeclarationNameInfo &MemberNameInfo,
1629 ValueDecl *Member,
1630 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001631 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001632 NamedDecl *FirstQualifierInScope) {
Richard Smith9138b4e2011-10-26 19:06:56 +00001633 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1634 isArrow);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001635 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001636 // We have a reference to an unnamed field. This is always the
1637 // base of an anonymous struct/union member access, i.e. the
1638 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001639 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001640 assert(Member->getType()->isRecordType() &&
1641 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001642
Richard Smith9138b4e2011-10-26 19:06:56 +00001643 BaseResult =
1644 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley429bb272011-04-08 18:41:53 +00001645 QualifierLoc.getNestedNameSpecifier(),
1646 FoundDecl, Member);
1647 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001648 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001649 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001650 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001651 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001652 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001653 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001654 cast<FieldDecl>(Member)->getType(),
1655 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001656 return getSema().Owned(ME);
1657 }
Mike Stump1eb44332009-09-09 15:08:12 +00001658
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001659 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001660 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001661
John Wiegley429bb272011-04-08 18:41:53 +00001662 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001663 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001664
John McCall6bb80172010-03-30 21:47:33 +00001665 // FIXME: this involves duplicating earlier analysis in a lot of
1666 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001667 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001668 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001669 R.resolveKind();
1670
John McCall9ae2f072010-08-23 23:25:46 +00001671 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001672 SS, TemplateKWLoc,
1673 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001674 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001675 }
Mike Stump1eb44332009-09-09 15:08:12 +00001676
Douglas Gregorb98b1992009-08-11 05:31:07 +00001677 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001678 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001679 /// By default, performs semantic analysis to build the new expression.
1680 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001681 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001682 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001683 Expr *LHS, Expr *RHS) {
1684 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001685 }
1686
1687 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001688 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001689 /// By default, performs semantic analysis to build the new expression.
1690 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001691 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001692 SourceLocation QuestionLoc,
1693 Expr *LHS,
1694 SourceLocation ColonLoc,
1695 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001696 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1697 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001698 }
1699
Douglas Gregorb98b1992009-08-11 05:31:07 +00001700 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001701 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001702 /// By default, performs semantic analysis to build the new expression.
1703 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001704 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001705 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001706 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001707 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001708 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001709 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001710 }
Mike Stump1eb44332009-09-09 15:08:12 +00001711
Douglas Gregorb98b1992009-08-11 05:31:07 +00001712 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001713 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001714 /// By default, performs semantic analysis to build the new expression.
1715 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001716 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001717 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001718 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001719 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001720 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001721 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001722 }
Mike Stump1eb44332009-09-09 15:08:12 +00001723
Douglas Gregorb98b1992009-08-11 05:31:07 +00001724 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001725 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001726 /// By default, performs semantic analysis to build the new expression.
1727 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001728 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001729 SourceLocation OpLoc,
1730 SourceLocation AccessorLoc,
1731 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001732
John McCall129e2df2009-11-30 22:42:35 +00001733 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001734 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001735 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001736 OpLoc, /*IsArrow*/ false,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001737 SS, SourceLocation(),
1738 /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001739 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001740 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001741 }
Mike Stump1eb44332009-09-09 15:08:12 +00001742
Douglas Gregorb98b1992009-08-11 05:31:07 +00001743 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001744 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001745 /// By default, performs semantic analysis to build the new expression.
1746 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001747 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001748 MultiExprArg Inits,
1749 SourceLocation RBraceLoc,
1750 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001751 ExprResult Result
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001752 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregore48319a2009-11-09 17:16:50 +00001753 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001754 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00001755
Douglas Gregore48319a2009-11-09 17:16:50 +00001756 // Patch in the result type we were given, which may have been computed
1757 // when the initial InitListExpr was built.
1758 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1759 ILE->setType(ResultTy);
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001760 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001761 }
Mike Stump1eb44332009-09-09 15:08:12 +00001762
Douglas Gregorb98b1992009-08-11 05:31:07 +00001763 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001764 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001765 /// By default, performs semantic analysis to build the new expression.
1766 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001767 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001768 MultiExprArg ArrayExprs,
1769 SourceLocation EqualOrColonLoc,
1770 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001771 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001772 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001773 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001774 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001775 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001776 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001777
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001778 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001779 }
Mike Stump1eb44332009-09-09 15:08:12 +00001780
Douglas Gregorb98b1992009-08-11 05:31:07 +00001781 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001782 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001783 /// By default, builds the implicit value initialization without performing
1784 /// any semantic analysis. Subclasses may override this routine to provide
1785 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001786 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001787 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1788 }
Mike Stump1eb44332009-09-09 15:08:12 +00001789
Douglas Gregorb98b1992009-08-11 05:31:07 +00001790 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001791 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001792 /// By default, performs semantic analysis to build the new expression.
1793 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001794 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001795 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001796 SourceLocation RParenLoc) {
1797 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001798 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001799 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001800 }
1801
1802 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001803 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001804 /// By default, performs semantic analysis to build the new expression.
1805 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001806 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +00001807 MultiExprArg SubExprs,
1808 SourceLocation RParenLoc) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001809 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001810 }
Mike Stump1eb44332009-09-09 15:08:12 +00001811
Douglas Gregorb98b1992009-08-11 05:31:07 +00001812 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001813 ///
1814 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001815 /// rather than attempting to map the label statement itself.
1816 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001817 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001818 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001819 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001820 }
Mike Stump1eb44332009-09-09 15:08:12 +00001821
Douglas Gregorb98b1992009-08-11 05:31:07 +00001822 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001823 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001824 /// By default, performs semantic analysis to build the new expression.
1825 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001826 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001827 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001828 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001829 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001830 }
Mike Stump1eb44332009-09-09 15:08:12 +00001831
Douglas Gregorb98b1992009-08-11 05:31:07 +00001832 /// \brief Build a new __builtin_choose_expr expression.
1833 ///
1834 /// By default, performs semantic analysis to build the new expression.
1835 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001836 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001837 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001838 SourceLocation RParenLoc) {
1839 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001840 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001841 RParenLoc);
1842 }
Mike Stump1eb44332009-09-09 15:08:12 +00001843
Peter Collingbournef111d932011-04-15 00:35:48 +00001844 /// \brief Build a new generic selection expression.
1845 ///
1846 /// By default, performs semantic analysis to build the new expression.
1847 /// Subclasses may override this routine to provide different behavior.
1848 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1849 SourceLocation DefaultLoc,
1850 SourceLocation RParenLoc,
1851 Expr *ControllingExpr,
Dmitri Gribenko80613222013-05-10 13:06:58 +00001852 ArrayRef<TypeSourceInfo *> Types,
1853 ArrayRef<Expr *> Exprs) {
Peter Collingbournef111d932011-04-15 00:35:48 +00001854 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko80613222013-05-10 13:06:58 +00001855 ControllingExpr, Types, Exprs);
Peter Collingbournef111d932011-04-15 00:35:48 +00001856 }
1857
Douglas Gregorb98b1992009-08-11 05:31:07 +00001858 /// \brief Build a new overloaded operator call expression.
1859 ///
1860 /// By default, performs semantic analysis to build the new expression.
1861 /// The semantic analysis provides the behavior of template instantiation,
1862 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001863 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001864 /// argument-dependent lookup, etc. Subclasses may override this routine to
1865 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001866 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001867 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001868 Expr *Callee,
1869 Expr *First,
1870 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001871
1872 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001873 /// reinterpret_cast.
1874 ///
1875 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001876 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001877 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001878 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001879 Stmt::StmtClass Class,
1880 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001881 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001882 SourceLocation RAngleLoc,
1883 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001884 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001885 SourceLocation RParenLoc) {
1886 switch (Class) {
1887 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001888 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001889 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001890 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001891
1892 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001893 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001894 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001895 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001896
Douglas Gregorb98b1992009-08-11 05:31:07 +00001897 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001898 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001899 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001900 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001901 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001902
Douglas Gregorb98b1992009-08-11 05:31:07 +00001903 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001904 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001905 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001906 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001907
Douglas Gregorb98b1992009-08-11 05:31:07 +00001908 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001909 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001910 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001911 }
Mike Stump1eb44332009-09-09 15:08:12 +00001912
Douglas Gregorb98b1992009-08-11 05:31:07 +00001913 /// \brief Build a new C++ static_cast expression.
1914 ///
1915 /// By default, performs semantic analysis to build the new expression.
1916 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001917 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001918 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001919 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001920 SourceLocation RAngleLoc,
1921 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001922 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001923 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001924 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001925 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001926 SourceRange(LAngleLoc, RAngleLoc),
1927 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001928 }
1929
1930 /// \brief Build a new C++ dynamic_cast expression.
1931 ///
1932 /// By default, performs semantic analysis to build the new expression.
1933 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001934 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001935 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001936 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001937 SourceLocation RAngleLoc,
1938 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001939 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001940 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001941 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001942 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001943 SourceRange(LAngleLoc, RAngleLoc),
1944 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001945 }
1946
1947 /// \brief Build a new C++ reinterpret_cast expression.
1948 ///
1949 /// By default, performs semantic analysis to build the new expression.
1950 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001951 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001952 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001953 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001954 SourceLocation RAngleLoc,
1955 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001956 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001957 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001958 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001959 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001960 SourceRange(LAngleLoc, RAngleLoc),
1961 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001962 }
1963
1964 /// \brief Build a new C++ const_cast expression.
1965 ///
1966 /// By default, performs semantic analysis to build the new expression.
1967 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001968 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001969 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001970 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001971 SourceLocation RAngleLoc,
1972 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001973 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001974 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001975 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001976 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001977 SourceRange(LAngleLoc, RAngleLoc),
1978 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001979 }
Mike Stump1eb44332009-09-09 15:08:12 +00001980
Douglas Gregorb98b1992009-08-11 05:31:07 +00001981 /// \brief Build a new C++ functional-style cast expression.
1982 ///
1983 /// By default, performs semantic analysis to build the new expression.
1984 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001985 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1986 SourceLocation LParenLoc,
1987 Expr *Sub,
1988 SourceLocation RParenLoc) {
1989 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001990 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001991 RParenLoc);
1992 }
Mike Stump1eb44332009-09-09 15:08:12 +00001993
Douglas Gregorb98b1992009-08-11 05:31:07 +00001994 /// \brief Build a new C++ typeid(type) expression.
1995 ///
1996 /// By default, performs semantic analysis to build the new expression.
1997 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001998 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001999 SourceLocation TypeidLoc,
2000 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002001 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002002 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00002003 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002004 }
Mike Stump1eb44332009-09-09 15:08:12 +00002005
Francois Pichet01b7c302010-09-08 12:20:18 +00002006
Douglas Gregorb98b1992009-08-11 05:31:07 +00002007 /// \brief Build a new C++ typeid(expr) expression.
2008 ///
2009 /// By default, performs semantic analysis to build the new expression.
2010 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002011 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00002012 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00002013 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002014 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002015 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00002016 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002017 }
2018
Francois Pichet01b7c302010-09-08 12:20:18 +00002019 /// \brief Build a new C++ __uuidof(type) expression.
2020 ///
2021 /// By default, performs semantic analysis to build the new expression.
2022 /// Subclasses may override this routine to provide different behavior.
2023 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2024 SourceLocation TypeidLoc,
2025 TypeSourceInfo *Operand,
2026 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002027 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet01b7c302010-09-08 12:20:18 +00002028 RParenLoc);
2029 }
2030
2031 /// \brief Build a new C++ __uuidof(expr) expression.
2032 ///
2033 /// By default, performs semantic analysis to build the new expression.
2034 /// Subclasses may override this routine to provide different behavior.
2035 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2036 SourceLocation TypeidLoc,
2037 Expr *Operand,
2038 SourceLocation RParenLoc) {
2039 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2040 RParenLoc);
2041 }
2042
Douglas Gregorb98b1992009-08-11 05:31:07 +00002043 /// \brief Build a new C++ "this" expression.
2044 ///
2045 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00002046 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00002047 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002048 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00002049 QualType ThisType,
2050 bool isImplicit) {
Eli Friedmanb69b42c2012-01-11 02:36:31 +00002051 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002052 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00002053 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
2054 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002055 }
2056
2057 /// \brief Build a new C++ throw expression.
2058 ///
2059 /// By default, performs semantic analysis to build the new expression.
2060 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00002061 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2062 bool IsThrownVariableInScope) {
2063 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002064 }
2065
2066 /// \brief Build a new C++ default-argument expression.
2067 ///
2068 /// By default, builds a new default-argument expression, which does not
2069 /// require any semantic analysis. Subclasses may override this routine to
2070 /// provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002071 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00002072 ParmVarDecl *Param) {
2073 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
2074 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002075 }
2076
Richard Smithc3bf52c2013-04-20 22:23:05 +00002077 /// \brief Build a new C++11 default-initialization expression.
2078 ///
2079 /// By default, builds a new default field initialization expression, which
2080 /// does not require any semantic analysis. Subclasses may override this
2081 /// routine to provide different behavior.
2082 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2083 FieldDecl *Field) {
2084 return getSema().Owned(CXXDefaultInitExpr::Create(getSema().Context, Loc,
2085 Field));
2086 }
2087
Douglas Gregorb98b1992009-08-11 05:31:07 +00002088 /// \brief Build a new C++ zero-initialization expression.
2089 ///
2090 /// By default, performs semantic analysis to build the new expression.
2091 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002092 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2093 SourceLocation LParenLoc,
2094 SourceLocation RParenLoc) {
2095 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002096 None, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002097 }
Mike Stump1eb44332009-09-09 15:08:12 +00002098
Douglas Gregorb98b1992009-08-11 05:31:07 +00002099 /// \brief Build a new C++ "new" expression.
2100 ///
2101 /// By default, performs semantic analysis to build the new expression.
2102 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002103 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002104 bool UseGlobal,
2105 SourceLocation PlacementLParen,
2106 MultiExprArg PlacementArgs,
2107 SourceLocation PlacementRParen,
2108 SourceRange TypeIdParens,
2109 QualType AllocatedType,
2110 TypeSourceInfo *AllocatedTypeInfo,
2111 Expr *ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002112 SourceRange DirectInitRange,
2113 Expr *Initializer) {
Mike Stump1eb44332009-09-09 15:08:12 +00002114 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002115 PlacementLParen,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002116 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002117 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00002118 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002119 AllocatedType,
2120 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00002121 ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002122 DirectInitRange,
2123 Initializer);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002124 }
Mike Stump1eb44332009-09-09 15:08:12 +00002125
Douglas Gregorb98b1992009-08-11 05:31:07 +00002126 /// \brief Build a new C++ "delete" expression.
2127 ///
2128 /// By default, performs semantic analysis to build the new expression.
2129 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002130 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002131 bool IsGlobalDelete,
2132 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002133 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002134 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002135 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002136 }
Mike Stump1eb44332009-09-09 15:08:12 +00002137
Douglas Gregorb98b1992009-08-11 05:31:07 +00002138 /// \brief Build a new unary type trait expression.
2139 ///
2140 /// By default, performs semantic analysis to build the new expression.
2141 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002142 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00002143 SourceLocation StartLoc,
2144 TypeSourceInfo *T,
2145 SourceLocation RParenLoc) {
2146 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002147 }
2148
Francois Pichet6ad6f282010-12-07 00:08:36 +00002149 /// \brief Build a new binary type trait expression.
2150 ///
2151 /// By default, performs semantic analysis to build the new expression.
2152 /// Subclasses may override this routine to provide different behavior.
2153 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
2154 SourceLocation StartLoc,
2155 TypeSourceInfo *LhsT,
2156 TypeSourceInfo *RhsT,
2157 SourceLocation RParenLoc) {
2158 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
2159 }
2160
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00002161 /// \brief Build a new type trait expression.
2162 ///
2163 /// By default, performs semantic analysis to build the new expression.
2164 /// Subclasses may override this routine to provide different behavior.
2165 ExprResult RebuildTypeTrait(TypeTrait Trait,
2166 SourceLocation StartLoc,
2167 ArrayRef<TypeSourceInfo *> Args,
2168 SourceLocation RParenLoc) {
2169 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2170 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002171
John Wiegley21ff2e52011-04-28 00:16:57 +00002172 /// \brief Build a new array type trait expression.
2173 ///
2174 /// By default, performs semantic analysis to build the new expression.
2175 /// Subclasses may override this routine to provide different behavior.
2176 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2177 SourceLocation StartLoc,
2178 TypeSourceInfo *TSInfo,
2179 Expr *DimExpr,
2180 SourceLocation RParenLoc) {
2181 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2182 }
2183
John Wiegley55262202011-04-25 06:54:41 +00002184 /// \brief Build a new expression trait expression.
2185 ///
2186 /// By default, performs semantic analysis to build the new expression.
2187 /// Subclasses may override this routine to provide different behavior.
2188 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2189 SourceLocation StartLoc,
2190 Expr *Queried,
2191 SourceLocation RParenLoc) {
2192 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2193 }
2194
Mike Stump1eb44332009-09-09 15:08:12 +00002195 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002196 /// expression.
2197 ///
2198 /// By default, performs semantic analysis to build the new expression.
2199 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002200 ExprResult RebuildDependentScopeDeclRefExpr(
2201 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002202 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002203 const DeclarationNameInfo &NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00002204 const TemplateArgumentListInfo *TemplateArgs,
2205 bool IsAddressOfOperand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002206 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002207 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002208
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002209 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002210 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002211 NameInfo, TemplateArgs);
John McCallf7a1a742009-11-24 19:00:30 +00002212
Richard Smithefeeccf2012-10-21 03:28:35 +00002213 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo,
2214 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002215 }
2216
2217 /// \brief Build a new template-id expression.
2218 ///
2219 /// By default, performs semantic analysis to build the new expression.
2220 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002221 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002222 SourceLocation TemplateKWLoc,
2223 LookupResult &R,
2224 bool RequiresADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002225 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002226 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2227 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002228 }
2229
2230 /// \brief Build a new object-construction expression.
2231 ///
2232 /// By default, performs semantic analysis to build the new expression.
2233 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002234 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002235 SourceLocation Loc,
2236 CXXConstructorDecl *Constructor,
2237 bool IsElidable,
2238 MultiExprArg Args,
2239 bool HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002240 bool ListInitialization,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002241 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002242 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002243 SourceRange ParenRange) {
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00002244 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002245 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002246 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002247 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002248
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002249 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002250 ConvertedArgs,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002251 HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002252 ListInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002253 RequiresZeroInit, ConstructKind,
2254 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002255 }
2256
2257 /// \brief Build a new object-construction expression.
2258 ///
2259 /// By default, performs semantic analysis to build the new expression.
2260 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002261 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2262 SourceLocation LParenLoc,
2263 MultiExprArg Args,
2264 SourceLocation RParenLoc) {
2265 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002266 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002267 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002268 RParenLoc);
2269 }
2270
2271 /// \brief Build a new object-construction expression.
2272 ///
2273 /// By default, performs semantic analysis to build the new expression.
2274 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002275 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2276 SourceLocation LParenLoc,
2277 MultiExprArg Args,
2278 SourceLocation RParenLoc) {
2279 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002280 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002281 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002282 RParenLoc);
2283 }
Mike Stump1eb44332009-09-09 15:08:12 +00002284
Douglas Gregorb98b1992009-08-11 05:31:07 +00002285 /// \brief Build a new member reference expression.
2286 ///
2287 /// By default, performs semantic analysis to build the new expression.
2288 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002289 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002290 QualType BaseType,
2291 bool IsArrow,
2292 SourceLocation OperatorLoc,
2293 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002294 SourceLocation TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00002295 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002296 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002297 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002298 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002299 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002300
John McCall9ae2f072010-08-23 23:25:46 +00002301 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002302 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002303 SS, TemplateKWLoc,
2304 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002305 MemberNameInfo,
2306 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002307 }
2308
John McCall129e2df2009-11-30 22:42:35 +00002309 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002310 ///
2311 /// By default, performs semantic analysis to build the new expression.
2312 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002313 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2314 SourceLocation OperatorLoc,
2315 bool IsArrow,
2316 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002317 SourceLocation TemplateKWLoc,
Richard Smith9138b4e2011-10-26 19:06:56 +00002318 NamedDecl *FirstQualifierInScope,
2319 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002320 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002321 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002322 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002323
John McCall9ae2f072010-08-23 23:25:46 +00002324 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002325 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002326 SS, TemplateKWLoc,
2327 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00002328 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002329 }
Mike Stump1eb44332009-09-09 15:08:12 +00002330
Sebastian Redl2e156222010-09-10 20:55:43 +00002331 /// \brief Build a new noexcept expression.
2332 ///
2333 /// By default, performs semantic analysis to build the new expression.
2334 /// Subclasses may override this routine to provide different behavior.
2335 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2336 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2337 }
2338
Douglas Gregoree8aff02011-01-04 17:33:58 +00002339 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002340 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2341 SourceLocation PackLoc,
Douglas Gregoree8aff02011-01-04 17:33:58 +00002342 SourceLocation RParenLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002343 Optional<unsigned> Length) {
Douglas Gregor089e8932011-10-10 18:59:29 +00002344 if (Length)
Chad Rosier4a9d7952012-08-08 18:46:20 +00002345 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2346 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002347 RParenLoc, *Length);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002348
2349 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2350 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002351 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002352 }
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002353
Patrick Beardeb382ec2012-04-19 00:25:12 +00002354 /// \brief Build a new Objective-C boxed expression.
2355 ///
2356 /// By default, performs semantic analysis to build the new expression.
2357 /// Subclasses may override this routine to provide different behavior.
2358 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2359 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2360 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002361
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002362 /// \brief Build a new Objective-C array literal.
2363 ///
2364 /// By default, performs semantic analysis to build the new expression.
2365 /// Subclasses may override this routine to provide different behavior.
2366 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2367 Expr **Elements, unsigned NumElements) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002368 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002369 MultiExprArg(Elements, NumElements));
2370 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002371
2372 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002373 Expr *Base, Expr *Key,
2374 ObjCMethodDecl *getterMethod,
2375 ObjCMethodDecl *setterMethod) {
2376 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2377 getterMethod, setterMethod);
2378 }
2379
2380 /// \brief Build a new Objective-C dictionary literal.
2381 ///
2382 /// By default, performs semantic analysis to build the new expression.
2383 /// Subclasses may override this routine to provide different behavior.
2384 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2385 ObjCDictionaryElement *Elements,
2386 unsigned NumElements) {
2387 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2388 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002389
James Dennett699c9042012-06-15 07:13:21 +00002390 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregorb98b1992009-08-11 05:31:07 +00002391 ///
2392 /// By default, performs semantic analysis to build the new expression.
2393 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002394 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002395 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002396 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002397 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002398 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002399 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002400
Douglas Gregor92e986e2010-04-22 16:44:27 +00002401 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002402 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002403 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002404 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002405 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002406 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002407 MultiExprArg Args,
2408 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002409 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2410 ReceiverTypeInfo->getType(),
2411 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002412 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002413 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002414 }
2415
2416 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002417 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002418 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002419 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002420 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002421 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002422 MultiExprArg Args,
2423 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002424 return SemaRef.BuildInstanceMessage(Receiver,
2425 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002426 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002427 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002428 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002429 }
2430
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002431 /// \brief Build a new Objective-C ivar reference expression.
2432 ///
2433 /// By default, performs semantic analysis to build the new expression.
2434 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002435 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002436 SourceLocation IvarLoc,
2437 bool IsArrow, bool IsFreeIvar) {
2438 // FIXME: We lose track of the IsFreeIvar bit.
2439 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002440 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002441 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2442 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002443 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002444 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002445 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002446 false);
John Wiegley429bb272011-04-08 18:41:53 +00002447 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002448 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002449
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002450 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002451 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002452
John Wiegley429bb272011-04-08 18:41:53 +00002453 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002454 /*FIXME:*/IvarLoc, IsArrow,
2455 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002456 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002457 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002458 /*TemplateArgs=*/0);
2459 }
Douglas Gregore3303542010-04-26 20:47:02 +00002460
2461 /// \brief Build a new Objective-C property reference expression.
2462 ///
2463 /// By default, performs semantic analysis to build the new expression.
2464 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002465 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002466 ObjCPropertyDecl *Property,
2467 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002468 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002469 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002470 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2471 Sema::LookupMemberName);
2472 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002473 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002474 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002475 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002476 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002477 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002478
Douglas Gregore3303542010-04-26 20:47:02 +00002479 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002480 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002481
John Wiegley429bb272011-04-08 18:41:53 +00002482 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002483 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002484 SS, SourceLocation(),
Douglas Gregore3303542010-04-26 20:47:02 +00002485 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002486 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002487 /*TemplateArgs=*/0);
2488 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002489
John McCall12f78a62010-12-02 01:19:52 +00002490 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002491 ///
2492 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002493 /// Subclasses may override this routine to provide different behavior.
2494 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2495 ObjCMethodDecl *Getter,
2496 ObjCMethodDecl *Setter,
2497 SourceLocation PropertyLoc) {
2498 // Since these expressions can only be value-dependent, we do not
2499 // need to perform semantic analysis again.
2500 return Owned(
2501 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2502 VK_LValue, OK_ObjCProperty,
2503 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002504 }
2505
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002506 /// \brief Build a new Objective-C "isa" expression.
2507 ///
2508 /// By default, performs semantic analysis to build the new expression.
2509 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002510 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002511 SourceLocation OpLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002512 bool IsArrow) {
2513 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002514 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002515 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2516 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002517 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002518 OpLoc,
John McCalld226f652010-08-21 09:40:31 +00002519 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002520 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002521 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002522
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002523 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002524 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002525
John Wiegley429bb272011-04-08 18:41:53 +00002526 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002527 OpLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002528 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002529 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002530 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002531 /*TemplateArgs=*/0);
2532 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002533
Douglas Gregorb98b1992009-08-11 05:31:07 +00002534 /// \brief Build a new shuffle vector expression.
2535 ///
2536 /// By default, performs semantic analysis to build the new expression.
2537 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002538 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002539 MultiExprArg SubExprs,
2540 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002541 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002542 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002543 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2544 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2545 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikie3bc93e32012-12-19 00:45:41 +00002546 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002547
Douglas Gregorb98b1992009-08-11 05:31:07 +00002548 // Build a reference to the __builtin_shufflevector builtin
David Blaikie3bc93e32012-12-19 00:45:41 +00002549 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002550 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2551 SemaRef.Context.BuiltinFnTy,
2552 VK_RValue, BuiltinLoc);
2553 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2554 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
2555 CK_BuiltinFnToFnPtr).take();
Mike Stump1eb44332009-09-09 15:08:12 +00002556
2557 // Build the CallExpr
John Wiegley429bb272011-04-08 18:41:53 +00002558 ExprResult TheCall = SemaRef.Owned(
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002559 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, SubExprs,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002560 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002561 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002562 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002563
Douglas Gregorb98b1992009-08-11 05:31:07 +00002564 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002565 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002566 }
John McCall43fed0d2010-11-12 08:19:04 +00002567
Hal Finkel414a1bd2013-09-18 03:29:45 +00002568 /// \brief Build a new convert vector expression.
2569 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2570 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2571 SourceLocation RParenLoc) {
2572 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2573 BuiltinLoc, RParenLoc);
2574 }
2575
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002576 /// \brief Build a new template argument pack expansion.
2577 ///
2578 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002579 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002580 /// different behavior.
2581 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002582 SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002583 Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002584 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002585 case TemplateArgument::Expression: {
2586 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002587 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2588 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002589 if (Result.isInvalid())
2590 return TemplateArgumentLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002591
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002592 return TemplateArgumentLoc(Result.get(), Result.get());
2593 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002594
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002595 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002596 return TemplateArgumentLoc(TemplateArgument(
2597 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002598 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002599 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002600 Pattern.getTemplateNameLoc(),
2601 EllipsisLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002602
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002603 case TemplateArgument::Null:
2604 case TemplateArgument::Integral:
2605 case TemplateArgument::Declaration:
2606 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002607 case TemplateArgument::TemplateExpansion:
Eli Friedmand7a6b162012-09-26 02:36:12 +00002608 case TemplateArgument::NullPtr:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002609 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002610
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002611 case TemplateArgument::Type:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002612 if (TypeSourceInfo *Expansion
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002613 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002614 EllipsisLoc,
2615 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002616 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2617 Expansion);
2618 break;
2619 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002620
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002621 return TemplateArgumentLoc();
2622 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002623
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002624 /// \brief Build a new expression pack expansion.
2625 ///
2626 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002627 /// for an expression. Subclasses may override this routine to provide
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002628 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002629 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002630 Optional<unsigned> NumExpansions) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002631 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002632 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002633
2634 /// \brief Build a new atomic operation expression.
2635 ///
2636 /// By default, performs semantic analysis to build the new expression.
2637 /// Subclasses may override this routine to provide different behavior.
2638 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2639 MultiExprArg SubExprs,
2640 QualType RetTy,
2641 AtomicExpr::AtomicOp Op,
2642 SourceLocation RParenLoc) {
2643 // Just create the expression; there is not any interesting semantic
2644 // analysis here because we can't actually build an AtomicExpr until
2645 // we are sure it is semantically sound.
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002646 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002647 RParenLoc);
2648 }
2649
John McCall43fed0d2010-11-12 08:19:04 +00002650private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002651 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2652 QualType ObjectType,
2653 NamedDecl *FirstQualifierInScope,
2654 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002655
2656 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2657 QualType ObjectType,
2658 NamedDecl *FirstQualifierInScope,
2659 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002660};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002661
Douglas Gregor43959a92009-08-20 07:17:43 +00002662template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002663StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002664 if (!S)
2665 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002666
Douglas Gregor43959a92009-08-20 07:17:43 +00002667 switch (S->getStmtClass()) {
2668 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002669
Douglas Gregor43959a92009-08-20 07:17:43 +00002670 // Transform individual statement nodes
2671#define STMT(Node, Parent) \
2672 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002673#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002674#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002675#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002676
Douglas Gregor43959a92009-08-20 07:17:43 +00002677 // Transform expressions by calling TransformExpr.
2678#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002679#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002680#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002681#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002682 {
John McCall60d7b3a2010-08-24 06:29:42 +00002683 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002684 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002685 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002686
Richard Smith41956372013-01-14 22:39:08 +00002687 return getSema().ActOnExprStmt(E);
Douglas Gregor43959a92009-08-20 07:17:43 +00002688 }
Mike Stump1eb44332009-09-09 15:08:12 +00002689 }
2690
John McCall3fa5cae2010-10-26 07:05:15 +00002691 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002692}
Mike Stump1eb44332009-09-09 15:08:12 +00002693
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00002694template<typename Derived>
2695OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2696 if (!S)
2697 return S;
2698
2699 switch (S->getClauseKind()) {
2700 default: break;
2701 // Transform individual clause nodes
2702#define OPENMP_CLAUSE(Name, Class) \
2703 case OMPC_ ## Name : \
2704 return getDerived().Transform ## Class(cast<Class>(S));
2705#include "clang/Basic/OpenMPKinds.def"
2706 }
2707
2708 return S;
2709}
2710
Mike Stump1eb44332009-09-09 15:08:12 +00002711
Douglas Gregor670444e2009-08-04 22:27:00 +00002712template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002713ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002714 if (!E)
2715 return SemaRef.Owned(E);
2716
2717 switch (E->getStmtClass()) {
2718 case Stmt::NoStmtClass: break;
2719#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002720#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002721#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002722 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002723#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002724 }
2725
John McCall3fa5cae2010-10-26 07:05:15 +00002726 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002727}
2728
2729template<typename Derived>
Richard Smithc83c2302012-12-19 01:39:02 +00002730ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2731 bool CXXDirectInit) {
2732 // Initializers are instantiated like expressions, except that various outer
2733 // layers are stripped.
2734 if (!Init)
2735 return SemaRef.Owned(Init);
2736
2737 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2738 Init = ExprTemp->getSubExpr();
2739
Richard Smith858c2c32013-05-30 22:40:16 +00002740 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2741 Init = MTE->GetTemporaryExpr();
2742
Richard Smithc83c2302012-12-19 01:39:02 +00002743 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2744 Init = Binder->getSubExpr();
2745
2746 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2747 Init = ICE->getSubExprAsWritten();
2748
Richard Smith7c3e6152013-06-12 22:31:48 +00002749 if (CXXStdInitializerListExpr *ILE =
2750 dyn_cast<CXXStdInitializerListExpr>(Init))
2751 return TransformInitializer(ILE->getSubExpr(), CXXDirectInit);
2752
Richard Smith5cf15892012-12-21 08:13:35 +00002753 // If this is not a direct-initializer, we only need to reconstruct
2754 // InitListExprs. Other forms of copy-initialization will be a no-op if
2755 // the initializer is already the right type.
2756 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2757 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2758 return getDerived().TransformExpr(Init);
2759
2760 // Revert value-initialization back to empty parens.
2761 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2762 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002763 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith5cf15892012-12-21 08:13:35 +00002764 Parens.getEnd());
2765 }
2766
2767 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2768 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002769 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith5cf15892012-12-21 08:13:35 +00002770 SourceLocation());
2771
2772 // Revert initialization by constructor back to a parenthesized or braced list
2773 // of expressions. Any other form of initializer can just be reused directly.
2774 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithc83c2302012-12-19 01:39:02 +00002775 return getDerived().TransformExpr(Init);
2776
2777 SmallVector<Expr*, 8> NewArgs;
2778 bool ArgChanged = false;
2779 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2780 /*IsCall*/true, NewArgs, &ArgChanged))
2781 return ExprError();
2782
2783 // If this was list initialization, revert to list form.
2784 if (Construct->isListInitialization())
2785 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2786 Construct->getLocEnd(),
2787 Construct->getType());
2788
Richard Smithc83c2302012-12-19 01:39:02 +00002789 // Build a ParenListExpr to represent anything else.
Enea Zaffanella1245a542013-09-07 05:49:53 +00002790 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smithc83c2302012-12-19 01:39:02 +00002791 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2792 Parens.getEnd());
2793}
2794
2795template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00002796bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2797 unsigned NumInputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002798 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002799 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002800 bool *ArgChanged) {
2801 for (unsigned I = 0; I != NumInputs; ++I) {
2802 // If requested, drop call arguments that need to be dropped.
2803 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2804 if (ArgChanged)
2805 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002806
Douglas Gregoraa165f82011-01-03 19:04:46 +00002807 break;
2808 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002809
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002810 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2811 Expr *Pattern = Expansion->getPattern();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002812
Chris Lattner686775d2011-07-20 06:58:45 +00002813 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002814 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2815 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002816
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002817 // Determine whether the set of unexpanded parameter packs can and should
2818 // be expanded.
2819 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002820 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00002821 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2822 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002823 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2824 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002825 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002826 Expand, RetainExpansion,
2827 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002828 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002829
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002830 if (!Expand) {
2831 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00002832 // transformation on the pack expansion, producing another pack
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002833 // expansion.
2834 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2835 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2836 if (OutPattern.isInvalid())
2837 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002838
2839 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002840 Expansion->getEllipsisLoc(),
2841 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002842 if (Out.isInvalid())
2843 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002844
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002845 if (ArgChanged)
2846 *ArgChanged = true;
2847 Outputs.push_back(Out.get());
2848 continue;
2849 }
John McCallc8fc90a2011-07-06 07:30:07 +00002850
2851 // Record right away that the argument was changed. This needs
2852 // to happen even if the array expands to nothing.
2853 if (ArgChanged) *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002854
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002855 // The transform has determined that we should perform an elementwise
2856 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002857 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002858 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2859 ExprResult Out = getDerived().TransformExpr(Pattern);
2860 if (Out.isInvalid())
2861 return true;
2862
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002863 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002864 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2865 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002866 if (Out.isInvalid())
2867 return true;
2868 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002869
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002870 Outputs.push_back(Out.get());
2871 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002872
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002873 continue;
2874 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002875
Richard Smithc83c2302012-12-19 01:39:02 +00002876 ExprResult Result =
2877 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
2878 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregoraa165f82011-01-03 19:04:46 +00002879 if (Result.isInvalid())
2880 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002881
Douglas Gregoraa165f82011-01-03 19:04:46 +00002882 if (Result.get() != Inputs[I] && ArgChanged)
2883 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002884
2885 Outputs.push_back(Result.get());
Douglas Gregoraa165f82011-01-03 19:04:46 +00002886 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002887
Douglas Gregoraa165f82011-01-03 19:04:46 +00002888 return false;
2889}
2890
2891template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002892NestedNameSpecifierLoc
2893TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2894 NestedNameSpecifierLoc NNS,
2895 QualType ObjectType,
2896 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002897 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002898 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002899 Qualifier = Qualifier.getPrefix())
2900 Qualifiers.push_back(Qualifier);
2901
2902 CXXScopeSpec SS;
2903 while (!Qualifiers.empty()) {
2904 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2905 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002906
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002907 switch (QNNS->getKind()) {
2908 case NestedNameSpecifier::Identifier:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002909 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002910 *QNNS->getAsIdentifier(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002911 Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002912 Q.getLocalEndLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002913 ObjectType, false, SS,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002914 FirstQualifierInScope, false))
2915 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002916
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002917 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002918
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002919 case NestedNameSpecifier::Namespace: {
2920 NamespaceDecl *NS
2921 = cast_or_null<NamespaceDecl>(
2922 getDerived().TransformDecl(
2923 Q.getLocalBeginLoc(),
2924 QNNS->getAsNamespace()));
2925 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2926 break;
2927 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002928
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002929 case NestedNameSpecifier::NamespaceAlias: {
2930 NamespaceAliasDecl *Alias
2931 = cast_or_null<NamespaceAliasDecl>(
2932 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2933 QNNS->getAsNamespaceAlias()));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002934 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002935 Q.getLocalEndLoc());
2936 break;
2937 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002938
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002939 case NestedNameSpecifier::Global:
2940 // There is no meaningful transformation that one could perform on the
2941 // global scope.
2942 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2943 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002944
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002945 case NestedNameSpecifier::TypeSpecWithTemplate:
2946 case NestedNameSpecifier::TypeSpec: {
2947 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2948 FirstQualifierInScope, SS);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002949
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002950 if (!TL)
2951 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002952
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002953 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith80ad52f2013-01-02 11:42:31 +00002954 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002955 TL.getType()->isEnumeralType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002956 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002957 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002958 if (TL.getType()->isEnumeralType())
2959 SemaRef.Diag(TL.getBeginLoc(),
2960 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002961 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2962 Q.getLocalEndLoc());
2963 break;
2964 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002965 // If the nested-name-specifier is an invalid type def, don't emit an
2966 // error because a previous error should have already been emitted.
David Blaikie39e6ab42013-02-18 22:06:02 +00002967 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
2968 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002969 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieu00c93a12011-05-07 01:36:37 +00002970 << TL.getType() << SS.getRange();
2971 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002972 return NestedNameSpecifierLoc();
2973 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002974 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002975
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002976 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002977 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002978 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002979 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002980
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002981 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002982 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002983 !getDerived().AlwaysRebuild())
2984 return NNS;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002985
2986 // If we can re-use the source-location data from the original
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002987 // nested-name-specifier, do so.
2988 if (SS.location_size() == NNS.getDataLength() &&
2989 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2990 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2991
2992 // Allocate new nested-name-specifier location information.
2993 return SS.getWithLocInContext(SemaRef.Context);
2994}
2995
2996template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002997DeclarationNameInfo
2998TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002999::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00003000 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00003001 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00003002 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00003003
3004 switch (Name.getNameKind()) {
3005 case DeclarationName::Identifier:
3006 case DeclarationName::ObjCZeroArgSelector:
3007 case DeclarationName::ObjCOneArgSelector:
3008 case DeclarationName::ObjCMultiArgSelector:
3009 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00003010 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00003011 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00003012 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00003013
Douglas Gregor81499bb2009-09-03 22:13:48 +00003014 case DeclarationName::CXXConstructorName:
3015 case DeclarationName::CXXDestructorName:
3016 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00003017 TypeSourceInfo *NewTInfo;
3018 CanQualType NewCanTy;
3019 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00003020 NewTInfo = getDerived().TransformType(OldTInfo);
3021 if (!NewTInfo)
3022 return DeclarationNameInfo();
3023 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00003024 }
3025 else {
3026 NewTInfo = 0;
3027 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00003028 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00003029 if (NewT.isNull())
3030 return DeclarationNameInfo();
3031 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3032 }
Mike Stump1eb44332009-09-09 15:08:12 +00003033
Abramo Bagnara25777432010-08-11 22:01:17 +00003034 DeclarationName NewName
3035 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3036 NewCanTy);
3037 DeclarationNameInfo NewNameInfo(NameInfo);
3038 NewNameInfo.setName(NewName);
3039 NewNameInfo.setNamedTypeInfo(NewTInfo);
3040 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00003041 }
Mike Stump1eb44332009-09-09 15:08:12 +00003042 }
3043
David Blaikieb219cfc2011-09-23 05:06:16 +00003044 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00003045}
3046
3047template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003048TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003049TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3050 TemplateName Name,
3051 SourceLocation NameLoc,
3052 QualType ObjectType,
3053 NamedDecl *FirstQualifierInScope) {
3054 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3055 TemplateDecl *Template = QTN->getTemplateDecl();
3056 assert(Template && "qualified template name must refer to a template");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003057
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003058 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00003059 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003060 Template));
3061 if (!TransTemplate)
3062 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003063
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003064 if (!getDerived().AlwaysRebuild() &&
3065 SS.getScopeRep() == QTN->getQualifier() &&
3066 TransTemplate == Template)
3067 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003068
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003069 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3070 TransTemplate);
3071 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003072
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003073 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3074 if (SS.getScopeRep()) {
3075 // These apply to the scope specifier, not the template.
3076 ObjectType = QualType();
3077 FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003078 }
3079
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003080 if (!getDerived().AlwaysRebuild() &&
3081 SS.getScopeRep() == DTN->getQualifier() &&
3082 ObjectType.isNull())
3083 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003084
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003085 if (DTN->isIdentifier()) {
3086 return getDerived().RebuildTemplateName(SS,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003087 *DTN->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003088 NameLoc,
3089 ObjectType,
3090 FirstQualifierInScope);
3091 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003092
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003093 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3094 ObjectType);
3095 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003096
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003097 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3098 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00003099 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003100 Template));
3101 if (!TransTemplate)
3102 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003103
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003104 if (!getDerived().AlwaysRebuild() &&
3105 TransTemplate == Template)
3106 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003107
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003108 return TemplateName(TransTemplate);
3109 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003110
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003111 if (SubstTemplateTemplateParmPackStorage *SubstPack
3112 = Name.getAsSubstTemplateTemplateParmPack()) {
3113 TemplateTemplateParmDecl *TransParam
3114 = cast_or_null<TemplateTemplateParmDecl>(
3115 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3116 if (!TransParam)
3117 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003118
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003119 if (!getDerived().AlwaysRebuild() &&
3120 TransParam == SubstPack->getParameterPack())
3121 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003122
3123 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003124 SubstPack->getArgumentPack());
3125 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003126
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003127 // These should be getting filtered out before they reach the AST.
3128 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003129}
3130
3131template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00003132void TreeTransform<Derived>::InventTemplateArgumentLoc(
3133 const TemplateArgument &Arg,
3134 TemplateArgumentLoc &Output) {
3135 SourceLocation Loc = getDerived().getBaseLocation();
3136 switch (Arg.getKind()) {
3137 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003138 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00003139 break;
3140
3141 case TemplateArgument::Type:
3142 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00003143 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier4a9d7952012-08-08 18:46:20 +00003144
John McCall833ca992009-10-29 08:12:44 +00003145 break;
3146
Douglas Gregor788cd062009-11-11 01:00:40 +00003147 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003148 case TemplateArgument::TemplateExpansion: {
3149 NestedNameSpecifierLocBuilder Builder;
3150 TemplateName Template = Arg.getAsTemplate();
3151 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3152 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3153 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3154 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003155
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003156 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier4a9d7952012-08-08 18:46:20 +00003157 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003158 Builder.getWithLocInContext(SemaRef.Context),
3159 Loc);
3160 else
Chad Rosier4a9d7952012-08-08 18:46:20 +00003161 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003162 Builder.getWithLocInContext(SemaRef.Context),
3163 Loc, Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003164
Douglas Gregor788cd062009-11-11 01:00:40 +00003165 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003166 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003167
John McCall833ca992009-10-29 08:12:44 +00003168 case TemplateArgument::Expression:
3169 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3170 break;
3171
3172 case TemplateArgument::Declaration:
3173 case TemplateArgument::Integral:
3174 case TemplateArgument::Pack:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003175 case TemplateArgument::NullPtr:
John McCall828bff22009-10-29 18:45:58 +00003176 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00003177 break;
3178 }
3179}
3180
3181template<typename Derived>
3182bool TreeTransform<Derived>::TransformTemplateArgument(
3183 const TemplateArgumentLoc &Input,
3184 TemplateArgumentLoc &Output) {
3185 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00003186 switch (Arg.getKind()) {
3187 case TemplateArgument::Null:
3188 case TemplateArgument::Integral:
Eli Friedman511e3ae2012-09-25 01:02:42 +00003189 case TemplateArgument::Pack:
3190 case TemplateArgument::Declaration:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003191 case TemplateArgument::NullPtr:
3192 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump1eb44332009-09-09 15:08:12 +00003193
Douglas Gregor670444e2009-08-04 22:27:00 +00003194 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00003195 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00003196 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00003197 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00003198
3199 DI = getDerived().TransformType(DI);
3200 if (!DI) return true;
3201
3202 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3203 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003204 }
Mike Stump1eb44332009-09-09 15:08:12 +00003205
Douglas Gregor788cd062009-11-11 01:00:40 +00003206 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003207 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3208 if (QualifierLoc) {
3209 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3210 if (!QualifierLoc)
3211 return true;
3212 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003213
Douglas Gregor1d752d72011-03-02 18:46:51 +00003214 CXXScopeSpec SS;
3215 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00003216 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00003217 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3218 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00003219 if (Template.isNull())
3220 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003221
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003222 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00003223 Input.getTemplateNameLoc());
3224 return false;
3225 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003226
3227 case TemplateArgument::TemplateExpansion:
3228 llvm_unreachable("Caller should expand pack expansions");
3229
Douglas Gregor670444e2009-08-04 22:27:00 +00003230 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00003231 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00003232 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003233 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003234
John McCall833ca992009-10-29 08:12:44 +00003235 Expr *InputExpr = Input.getSourceExpression();
3236 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3237
Chris Lattner223de242011-04-25 20:37:58 +00003238 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003239 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00003240 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00003241 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00003242 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003243 }
Douglas Gregor670444e2009-08-04 22:27:00 +00003244 }
Mike Stump1eb44332009-09-09 15:08:12 +00003245
Douglas Gregor670444e2009-08-04 22:27:00 +00003246 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003247 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003248}
3249
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003250/// \brief Iterator adaptor that invents template argument location information
3251/// for each of the template arguments in its underlying iterator.
3252template<typename Derived, typename InputIterator>
3253class TemplateArgumentLocInventIterator {
3254 TreeTransform<Derived> &Self;
3255 InputIterator Iter;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003256
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003257public:
3258 typedef TemplateArgumentLoc value_type;
3259 typedef TemplateArgumentLoc reference;
3260 typedef typename std::iterator_traits<InputIterator>::difference_type
3261 difference_type;
3262 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003263
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003264 class pointer {
3265 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003266
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003267 public:
3268 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003269
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003270 const TemplateArgumentLoc *operator->() const { return &Arg; }
3271 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00003272
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003273 TemplateArgumentLocInventIterator() { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003274
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003275 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3276 InputIterator Iter)
3277 : Self(Self), Iter(Iter) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003278
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003279 TemplateArgumentLocInventIterator &operator++() {
3280 ++Iter;
3281 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003282 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003283
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003284 TemplateArgumentLocInventIterator operator++(int) {
3285 TemplateArgumentLocInventIterator Old(*this);
3286 ++(*this);
3287 return Old;
3288 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003289
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003290 reference operator*() const {
3291 TemplateArgumentLoc Result;
3292 Self.InventTemplateArgumentLoc(*Iter, Result);
3293 return Result;
3294 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003295
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003296 pointer operator->() const { return pointer(**this); }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003297
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003298 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3299 const TemplateArgumentLocInventIterator &Y) {
3300 return X.Iter == Y.Iter;
3301 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003302
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003303 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3304 const TemplateArgumentLocInventIterator &Y) {
3305 return X.Iter != Y.Iter;
3306 }
3307};
Chad Rosier4a9d7952012-08-08 18:46:20 +00003308
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003309template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003310template<typename InputIterator>
3311bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3312 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003313 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003314 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003315 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003316 TemplateArgumentLoc In = *First;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003317
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003318 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3319 // Unpack argument packs, which we translate them into separate
3320 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003321 // FIXME: We could do much better if we could guarantee that the
3322 // TemplateArgumentLocInfo for the pack expansion would be usable for
3323 // all of the template arguments in the argument pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003324 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003325 TemplateArgument::pack_iterator>
3326 PackLocIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003327 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003328 In.getArgument().pack_begin()),
3329 PackLocIterator(*this,
3330 In.getArgument().pack_end()),
3331 Outputs))
3332 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003333
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003334 continue;
3335 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003336
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003337 if (In.getArgument().isPackExpansion()) {
3338 // We have a pack expansion, for which we will be substituting into
3339 // the pattern.
3340 SourceLocation Ellipsis;
David Blaikiedc84cd52013-02-20 22:23:23 +00003341 Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003342 TemplateArgumentLoc Pattern
Eli Friedman850cf512013-06-20 04:11:21 +00003343 = getSema().getTemplateArgumentPackExpansionPattern(
3344 In, Ellipsis, OrigNumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003345
Chris Lattner686775d2011-07-20 06:58:45 +00003346 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003347 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3348 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003349
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003350 // Determine whether the set of unexpanded parameter packs can and should
3351 // be expanded.
3352 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003353 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00003354 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003355 if (getDerived().TryExpandParameterPacks(Ellipsis,
3356 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003357 Unexpanded,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003358 Expand,
Douglas Gregord3731192011-01-10 07:32:04 +00003359 RetainExpansion,
3360 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003361 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003362
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003363 if (!Expand) {
3364 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00003365 // transformation on the pack expansion, producing another pack
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003366 // expansion.
3367 TemplateArgumentLoc OutPattern;
3368 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3369 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3370 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003371
Douglas Gregorcded4f62011-01-14 17:04:44 +00003372 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3373 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003374 if (Out.getArgument().isNull())
3375 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003376
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003377 Outputs.addArgument(Out);
3378 continue;
3379 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003380
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003381 // The transform has determined that we should perform an elementwise
3382 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003383 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003384 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3385
3386 if (getDerived().TransformTemplateArgument(Pattern, Out))
3387 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003388
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003389 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003390 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3391 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003392 if (Out.getArgument().isNull())
3393 return true;
3394 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003395
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003396 Outputs.addArgument(Out);
3397 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003398
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003399 // If we're supposed to retain a pack expansion, do so by temporarily
3400 // forgetting the partially-substituted parameter pack.
3401 if (RetainExpansion) {
3402 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003403
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003404 if (getDerived().TransformTemplateArgument(Pattern, Out))
3405 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003406
Douglas Gregorcded4f62011-01-14 17:04:44 +00003407 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3408 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003409 if (Out.getArgument().isNull())
3410 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003411
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003412 Outputs.addArgument(Out);
3413 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003414
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003415 continue;
3416 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003417
3418 // The simple case:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003419 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003420 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003421
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003422 Outputs.addArgument(Out);
3423 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003424
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003425 return false;
3426
3427}
3428
Douglas Gregor577f75a2009-08-04 16:50:30 +00003429//===----------------------------------------------------------------------===//
3430// Type transformation
3431//===----------------------------------------------------------------------===//
3432
3433template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003434QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003435 if (getDerived().AlreadyTransformed(T))
3436 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003437
John McCalla2becad2009-10-21 00:40:46 +00003438 // Temporary workaround. All of these transformations should
3439 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003440 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3441 getDerived().getBaseLocation());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003442
John McCall43fed0d2010-11-12 08:19:04 +00003443 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003444
John McCalla2becad2009-10-21 00:40:46 +00003445 if (!NewDI)
3446 return QualType();
3447
3448 return NewDI->getType();
3449}
3450
3451template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003452TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003453 // Refine the base location to the type's location.
3454 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3455 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003456 if (getDerived().AlreadyTransformed(DI->getType()))
3457 return DI;
3458
3459 TypeLocBuilder TLB;
3460
3461 TypeLoc TL = DI->getTypeLoc();
3462 TLB.reserve(TL.getFullDataSize());
3463
John McCall43fed0d2010-11-12 08:19:04 +00003464 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003465 if (Result.isNull())
3466 return 0;
3467
John McCalla93c9342009-12-07 02:54:59 +00003468 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003469}
3470
3471template<typename Derived>
3472QualType
John McCall43fed0d2010-11-12 08:19:04 +00003473TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003474 switch (T.getTypeLocClass()) {
3475#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie39e6ab42013-02-18 22:06:02 +00003476#define TYPELOC(CLASS, PARENT) \
3477 case TypeLoc::CLASS: \
3478 return getDerived().Transform##CLASS##Type(TLB, \
3479 T.castAs<CLASS##TypeLoc>());
John McCalla2becad2009-10-21 00:40:46 +00003480#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003481 }
Mike Stump1eb44332009-09-09 15:08:12 +00003482
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003483 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003484}
3485
3486/// FIXME: By default, this routine adds type qualifiers only to types
3487/// that can have qualifiers, and silently suppresses those qualifiers
3488/// that are not permitted (e.g., qualifiers on reference or function
3489/// types). This is the right thing for template instantiation, but
3490/// probably not for other clients.
3491template<typename Derived>
3492QualType
3493TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003494 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003495 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003496
John McCall43fed0d2010-11-12 08:19:04 +00003497 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003498 if (Result.isNull())
3499 return QualType();
3500
3501 // Silently suppress qualifiers if the result type can't be qualified.
3502 // FIXME: this is the right thing for template instantiation, but
3503 // probably not for other clients.
3504 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003505 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003506
John McCallf85e1932011-06-15 23:02:42 +00003507 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003508 // resulting type.
3509 if (Quals.hasObjCLifetime()) {
3510 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3511 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003512 else if (Result.getObjCLifetime()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003513 // Objective-C ARC:
Douglas Gregore559ca12011-06-17 22:11:49 +00003514 // A lifetime qualifier applied to a substituted template parameter
3515 // overrides the lifetime qualifier from the template argument.
Douglas Gregor92d13872013-01-17 23:59:28 +00003516 const AutoType *AutoTy;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003517 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore559ca12011-06-17 22:11:49 +00003518 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3519 QualType Replacement = SubstTypeParam->getReplacementType();
3520 Qualifiers Qs = Replacement.getQualifiers();
3521 Qs.removeObjCLifetime();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003522 Replacement
Douglas Gregore559ca12011-06-17 22:11:49 +00003523 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3524 Qs);
3525 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier4a9d7952012-08-08 18:46:20 +00003526 SubstTypeParam->getReplacedParameter(),
Douglas Gregore559ca12011-06-17 22:11:49 +00003527 Replacement);
3528 TLB.TypeWasModifiedSafely(Result);
Douglas Gregor92d13872013-01-17 23:59:28 +00003529 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3530 // 'auto' types behave the same way as template parameters.
3531 QualType Deduced = AutoTy->getDeducedType();
3532 Qualifiers Qs = Deduced.getQualifiers();
3533 Qs.removeObjCLifetime();
3534 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3535 Qs);
Faisal Valifad9e132013-09-26 19:54:12 +00003536 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3537 AutoTy->isDependentType());
Douglas Gregor92d13872013-01-17 23:59:28 +00003538 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore559ca12011-06-17 22:11:49 +00003539 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003540 // Otherwise, complain about the addition of a qualifier to an
3541 // already-qualified type.
Eli Friedman44ee0a72013-06-07 20:31:48 +00003542 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003543 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003544 << Result << R;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003545
Douglas Gregore559ca12011-06-17 22:11:49 +00003546 Quals.removeObjCLifetime();
3547 }
3548 }
3549 }
John McCall28654742010-06-05 06:41:15 +00003550 if (!Quals.empty()) {
3551 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smith9807a2e2013-03-27 23:36:39 +00003552 // BuildQualifiedType might not add qualifiers if they are invalid.
3553 if (Result.hasLocalQualifiers())
3554 TLB.push<QualifiedTypeLoc>(Result);
John McCall28654742010-06-05 06:41:15 +00003555 // No location information to preserve.
3556 }
John McCalla2becad2009-10-21 00:40:46 +00003557
3558 return Result;
3559}
3560
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003561template<typename Derived>
3562TypeLoc
3563TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3564 QualType ObjectType,
3565 NamedDecl *UnqualLookup,
3566 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003567 QualType T = TL.getType();
3568 if (getDerived().AlreadyTransformed(T))
3569 return TL;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003570
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003571 TypeLocBuilder TLB;
3572 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003573
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003574 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003575 TemplateSpecializationTypeLoc SpecTL =
3576 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003577
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003578 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003579 getDerived().TransformTemplateName(SS,
3580 SpecTL.getTypePtr()->getTemplateName(),
3581 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003582 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003583 if (Template.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003584 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003585
3586 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003587 Template);
3588 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003589 DependentTemplateSpecializationTypeLoc SpecTL =
3590 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003591
Douglas Gregora88f09f2011-02-28 17:23:35 +00003592 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003593 = getDerived().RebuildTemplateName(SS,
3594 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003595 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003596 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003597 if (Template.isNull())
3598 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003599
3600 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003601 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003602 Template,
3603 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003604 } else {
3605 // Nothing special needs to be done for these.
3606 Result = getDerived().TransformType(TLB, TL);
3607 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003608
3609 if (Result.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003610 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003611
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003612 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3613}
3614
Douglas Gregorb71d8212011-03-02 18:32:08 +00003615template<typename Derived>
3616TypeSourceInfo *
3617TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3618 QualType ObjectType,
3619 NamedDecl *UnqualLookup,
3620 CXXScopeSpec &SS) {
3621 // FIXME: Painfully copy-paste from the above!
Chad Rosier4a9d7952012-08-08 18:46:20 +00003622
Douglas Gregorb71d8212011-03-02 18:32:08 +00003623 QualType T = TSInfo->getType();
3624 if (getDerived().AlreadyTransformed(T))
3625 return TSInfo;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003626
Douglas Gregorb71d8212011-03-02 18:32:08 +00003627 TypeLocBuilder TLB;
3628 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003629
Douglas Gregorb71d8212011-03-02 18:32:08 +00003630 TypeLoc TL = TSInfo->getTypeLoc();
3631 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003632 TemplateSpecializationTypeLoc SpecTL =
3633 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003634
Douglas Gregorb71d8212011-03-02 18:32:08 +00003635 TemplateName Template
3636 = getDerived().TransformTemplateName(SS,
3637 SpecTL.getTypePtr()->getTemplateName(),
3638 SpecTL.getTemplateNameLoc(),
3639 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003640 if (Template.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003641 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003642
3643 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003644 Template);
3645 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003646 DependentTemplateSpecializationTypeLoc SpecTL =
3647 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003648
Douglas Gregorb71d8212011-03-02 18:32:08 +00003649 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003650 = getDerived().RebuildTemplateName(SS,
3651 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003652 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003653 ObjectType, UnqualLookup);
3654 if (Template.isNull())
3655 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003656
3657 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003658 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003659 Template,
3660 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003661 } else {
3662 // Nothing special needs to be done for these.
3663 Result = getDerived().TransformType(TLB, TL);
3664 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003665
3666 if (Result.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003667 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003668
Douglas Gregorb71d8212011-03-02 18:32:08 +00003669 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3670}
3671
John McCalla2becad2009-10-21 00:40:46 +00003672template <class TyLoc> static inline
3673QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3674 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3675 NewT.setNameLoc(T.getNameLoc());
3676 return T.getType();
3677}
3678
John McCalla2becad2009-10-21 00:40:46 +00003679template<typename Derived>
3680QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003681 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003682 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3683 NewT.setBuiltinLoc(T.getBuiltinLoc());
3684 if (T.needsExtraLocalData())
3685 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3686 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003687}
Mike Stump1eb44332009-09-09 15:08:12 +00003688
Douglas Gregor577f75a2009-08-04 16:50:30 +00003689template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003690QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003691 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003692 // FIXME: recurse?
3693 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003694}
Mike Stump1eb44332009-09-09 15:08:12 +00003695
Douglas Gregor577f75a2009-08-04 16:50:30 +00003696template<typename Derived>
Reid Kleckner12df2462013-06-24 17:51:48 +00003697QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3698 DecayedTypeLoc TL) {
3699 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3700 if (OriginalType.isNull())
3701 return QualType();
3702
3703 QualType Result = TL.getType();
3704 if (getDerived().AlwaysRebuild() ||
3705 OriginalType != TL.getOriginalLoc().getType())
3706 Result = SemaRef.Context.getDecayedType(OriginalType);
3707 TLB.push<DecayedTypeLoc>(Result);
3708 // Nothing to set for DecayedTypeLoc.
3709 return Result;
3710}
3711
3712template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003713QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003714 PointerTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003715 QualType PointeeType
3716 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003717 if (PointeeType.isNull())
3718 return QualType();
3719
3720 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003721 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003722 // A dependent pointer type 'T *' has is being transformed such
3723 // that an Objective-C class type is being replaced for 'T'. The
3724 // resulting pointer type is an ObjCObjectPointerType, not a
3725 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003726 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003727
John McCallc12c5bb2010-05-15 11:32:37 +00003728 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3729 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003730 return Result;
3731 }
John McCall43fed0d2010-11-12 08:19:04 +00003732
Douglas Gregor92e986e2010-04-22 16:44:27 +00003733 if (getDerived().AlwaysRebuild() ||
3734 PointeeType != TL.getPointeeLoc().getType()) {
3735 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3736 if (Result.isNull())
3737 return QualType();
3738 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003739
John McCallf85e1932011-06-15 23:02:42 +00003740 // Objective-C ARC can add lifetime qualifiers to the type that we're
3741 // pointing to.
3742 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003743
Douglas Gregor92e986e2010-04-22 16:44:27 +00003744 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3745 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003746 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003747}
Mike Stump1eb44332009-09-09 15:08:12 +00003748
3749template<typename Derived>
3750QualType
John McCalla2becad2009-10-21 00:40:46 +00003751TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003752 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003753 QualType PointeeType
Chad Rosier4a9d7952012-08-08 18:46:20 +00003754 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3755 if (PointeeType.isNull())
3756 return QualType();
3757
3758 QualType Result = TL.getType();
3759 if (getDerived().AlwaysRebuild() ||
3760 PointeeType != TL.getPointeeLoc().getType()) {
3761 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003762 TL.getSigilLoc());
3763 if (Result.isNull())
3764 return QualType();
3765 }
3766
Douglas Gregor39968ad2010-04-22 16:50:51 +00003767 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003768 NewT.setSigilLoc(TL.getSigilLoc());
3769 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003770}
3771
John McCall85737a72009-10-30 00:06:24 +00003772/// Transforms a reference type. Note that somewhat paradoxically we
3773/// don't care whether the type itself is an l-value type or an r-value
3774/// type; we only care if the type was *written* as an l-value type
3775/// or an r-value type.
3776template<typename Derived>
3777QualType
3778TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003779 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003780 const ReferenceType *T = TL.getTypePtr();
3781
3782 // Note that this works with the pointee-as-written.
3783 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3784 if (PointeeType.isNull())
3785 return QualType();
3786
3787 QualType Result = TL.getType();
3788 if (getDerived().AlwaysRebuild() ||
3789 PointeeType != T->getPointeeTypeAsWritten()) {
3790 Result = getDerived().RebuildReferenceType(PointeeType,
3791 T->isSpelledAsLValue(),
3792 TL.getSigilLoc());
3793 if (Result.isNull())
3794 return QualType();
3795 }
3796
John McCallf85e1932011-06-15 23:02:42 +00003797 // Objective-C ARC can add lifetime qualifiers to the type that we're
3798 // referring to.
3799 TLB.TypeWasModifiedSafely(
3800 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3801
John McCall85737a72009-10-30 00:06:24 +00003802 // r-value references can be rebuilt as l-value references.
3803 ReferenceTypeLoc NewTL;
3804 if (isa<LValueReferenceType>(Result))
3805 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3806 else
3807 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3808 NewTL.setSigilLoc(TL.getSigilLoc());
3809
3810 return Result;
3811}
3812
Mike Stump1eb44332009-09-09 15:08:12 +00003813template<typename Derived>
3814QualType
John McCalla2becad2009-10-21 00:40:46 +00003815TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003816 LValueReferenceTypeLoc TL) {
3817 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003818}
3819
Mike Stump1eb44332009-09-09 15:08:12 +00003820template<typename Derived>
3821QualType
John McCalla2becad2009-10-21 00:40:46 +00003822TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003823 RValueReferenceTypeLoc TL) {
3824 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003825}
Mike Stump1eb44332009-09-09 15:08:12 +00003826
Douglas Gregor577f75a2009-08-04 16:50:30 +00003827template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003828QualType
John McCalla2becad2009-10-21 00:40:46 +00003829TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003830 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003831 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003832 if (PointeeType.isNull())
3833 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003834
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003835 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3836 TypeSourceInfo* NewClsTInfo = 0;
3837 if (OldClsTInfo) {
3838 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3839 if (!NewClsTInfo)
3840 return QualType();
3841 }
3842
3843 const MemberPointerType *T = TL.getTypePtr();
3844 QualType OldClsType = QualType(T->getClass(), 0);
3845 QualType NewClsType;
3846 if (NewClsTInfo)
3847 NewClsType = NewClsTInfo->getType();
3848 else {
3849 NewClsType = getDerived().TransformType(OldClsType);
3850 if (NewClsType.isNull())
3851 return QualType();
3852 }
Mike Stump1eb44332009-09-09 15:08:12 +00003853
John McCalla2becad2009-10-21 00:40:46 +00003854 QualType Result = TL.getType();
3855 if (getDerived().AlwaysRebuild() ||
3856 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003857 NewClsType != OldClsType) {
3858 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003859 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003860 if (Result.isNull())
3861 return QualType();
3862 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003863
John McCalla2becad2009-10-21 00:40:46 +00003864 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3865 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003866 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003867
3868 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003869}
3870
Mike Stump1eb44332009-09-09 15:08:12 +00003871template<typename Derived>
3872QualType
John McCalla2becad2009-10-21 00:40:46 +00003873TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003874 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003875 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003876 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003877 if (ElementType.isNull())
3878 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003879
John McCalla2becad2009-10-21 00:40:46 +00003880 QualType Result = TL.getType();
3881 if (getDerived().AlwaysRebuild() ||
3882 ElementType != T->getElementType()) {
3883 Result = getDerived().RebuildConstantArrayType(ElementType,
3884 T->getSizeModifier(),
3885 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003886 T->getIndexTypeCVRQualifiers(),
3887 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003888 if (Result.isNull())
3889 return QualType();
3890 }
Eli Friedman457a3772012-01-25 22:19:07 +00003891
3892 // We might have either a ConstantArrayType or a VariableArrayType now:
3893 // a ConstantArrayType is allowed to have an element type which is a
3894 // VariableArrayType if the type is dependent. Fortunately, all array
3895 // types have the same location layout.
3896 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003897 NewTL.setLBracketLoc(TL.getLBracketLoc());
3898 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003899
John McCalla2becad2009-10-21 00:40:46 +00003900 Expr *Size = TL.getSizeExpr();
3901 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003902 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3903 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003904 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003905 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003906 }
3907 NewTL.setSizeExpr(Size);
3908
3909 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003910}
Mike Stump1eb44332009-09-09 15:08:12 +00003911
Douglas Gregor577f75a2009-08-04 16:50:30 +00003912template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003913QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003914 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003915 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003916 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003917 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003918 if (ElementType.isNull())
3919 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003920
John McCalla2becad2009-10-21 00:40:46 +00003921 QualType Result = TL.getType();
3922 if (getDerived().AlwaysRebuild() ||
3923 ElementType != T->getElementType()) {
3924 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003925 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003926 T->getIndexTypeCVRQualifiers(),
3927 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003928 if (Result.isNull())
3929 return QualType();
3930 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003931
John McCalla2becad2009-10-21 00:40:46 +00003932 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3933 NewTL.setLBracketLoc(TL.getLBracketLoc());
3934 NewTL.setRBracketLoc(TL.getRBracketLoc());
3935 NewTL.setSizeExpr(0);
3936
3937 return Result;
3938}
3939
3940template<typename Derived>
3941QualType
3942TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003943 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003944 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003945 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3946 if (ElementType.isNull())
3947 return QualType();
3948
John McCall60d7b3a2010-08-24 06:29:42 +00003949 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003950 = getDerived().TransformExpr(T->getSizeExpr());
3951 if (SizeResult.isInvalid())
3952 return QualType();
3953
John McCall9ae2f072010-08-23 23:25:46 +00003954 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003955
3956 QualType Result = TL.getType();
3957 if (getDerived().AlwaysRebuild() ||
3958 ElementType != T->getElementType() ||
3959 Size != T->getSizeExpr()) {
3960 Result = getDerived().RebuildVariableArrayType(ElementType,
3961 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003962 Size,
John McCalla2becad2009-10-21 00:40:46 +00003963 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003964 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003965 if (Result.isNull())
3966 return QualType();
3967 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003968
John McCalla2becad2009-10-21 00:40:46 +00003969 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3970 NewTL.setLBracketLoc(TL.getLBracketLoc());
3971 NewTL.setRBracketLoc(TL.getRBracketLoc());
3972 NewTL.setSizeExpr(Size);
3973
3974 return Result;
3975}
3976
3977template<typename Derived>
3978QualType
3979TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003980 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003981 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003982 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3983 if (ElementType.isNull())
3984 return QualType();
3985
Richard Smithf6702a32011-12-20 02:08:33 +00003986 // Array bounds are constant expressions.
3987 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3988 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003989
John McCall3b657512011-01-19 10:06:00 +00003990 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3991 Expr *origSize = TL.getSizeExpr();
3992 if (!origSize) origSize = T->getSizeExpr();
3993
3994 ExprResult sizeResult
3995 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003996 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003997 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003998 return QualType();
3999
John McCall3b657512011-01-19 10:06:00 +00004000 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00004001
4002 QualType Result = TL.getType();
4003 if (getDerived().AlwaysRebuild() ||
4004 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00004005 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00004006 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4007 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00004008 size,
John McCalla2becad2009-10-21 00:40:46 +00004009 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00004010 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00004011 if (Result.isNull())
4012 return QualType();
4013 }
John McCalla2becad2009-10-21 00:40:46 +00004014
4015 // We might have any sort of array type now, but fortunately they
4016 // all have the same location layout.
4017 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4018 NewTL.setLBracketLoc(TL.getLBracketLoc());
4019 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00004020 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00004021
4022 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004023}
Mike Stump1eb44332009-09-09 15:08:12 +00004024
4025template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00004026QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00004027 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004028 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004029 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004030
4031 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00004032 QualType ElementType = getDerived().TransformType(T->getElementType());
4033 if (ElementType.isNull())
4034 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004035
Richard Smithf6702a32011-12-20 02:08:33 +00004036 // Vector sizes are constant expressions.
4037 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4038 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00004039
John McCall60d7b3a2010-08-24 06:29:42 +00004040 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00004041 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004042 if (Size.isInvalid())
4043 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004044
John McCalla2becad2009-10-21 00:40:46 +00004045 QualType Result = TL.getType();
4046 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00004047 ElementType != T->getElementType() ||
4048 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00004049 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00004050 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00004051 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00004052 if (Result.isNull())
4053 return QualType();
4054 }
John McCalla2becad2009-10-21 00:40:46 +00004055
4056 // Result might be dependent or not.
4057 if (isa<DependentSizedExtVectorType>(Result)) {
4058 DependentSizedExtVectorTypeLoc NewTL
4059 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4060 NewTL.setNameLoc(TL.getNameLoc());
4061 } else {
4062 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4063 NewTL.setNameLoc(TL.getNameLoc());
4064 }
4065
4066 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004067}
Mike Stump1eb44332009-09-09 15:08:12 +00004068
4069template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004070QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004071 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004072 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004073 QualType ElementType = getDerived().TransformType(T->getElementType());
4074 if (ElementType.isNull())
4075 return QualType();
4076
John McCalla2becad2009-10-21 00:40:46 +00004077 QualType Result = TL.getType();
4078 if (getDerived().AlwaysRebuild() ||
4079 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00004080 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00004081 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00004082 if (Result.isNull())
4083 return QualType();
4084 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004085
John McCalla2becad2009-10-21 00:40:46 +00004086 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4087 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00004088
John McCalla2becad2009-10-21 00:40:46 +00004089 return Result;
4090}
4091
4092template<typename Derived>
4093QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004094 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004095 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004096 QualType ElementType = getDerived().TransformType(T->getElementType());
4097 if (ElementType.isNull())
4098 return QualType();
4099
4100 QualType Result = TL.getType();
4101 if (getDerived().AlwaysRebuild() ||
4102 ElementType != T->getElementType()) {
4103 Result = getDerived().RebuildExtVectorType(ElementType,
4104 T->getNumElements(),
4105 /*FIXME*/ SourceLocation());
4106 if (Result.isNull())
4107 return QualType();
4108 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004109
John McCalla2becad2009-10-21 00:40:46 +00004110 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4111 NewTL.setNameLoc(TL.getNameLoc());
4112
4113 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004114}
Mike Stump1eb44332009-09-09 15:08:12 +00004115
David Blaikiedc84cd52013-02-20 22:23:23 +00004116template <typename Derived>
4117ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4118 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4119 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00004120 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004121 TypeSourceInfo *NewDI = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004122
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004123 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004124 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004125 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004126 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00004127 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004128
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004129 TypeLocBuilder TLB;
4130 TypeLoc NewTL = OldDI->getTypeLoc();
4131 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004132
4133 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004134 OldExpansionTL.getPatternLoc());
4135 if (Result.isNull())
4136 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004137
4138 Result = RebuildPackExpansionType(Result,
4139 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004140 OldExpansionTL.getEllipsisLoc(),
4141 NumExpansions);
4142 if (Result.isNull())
4143 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004144
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004145 PackExpansionTypeLoc NewExpansionTL
4146 = TLB.push<PackExpansionTypeLoc>(Result);
4147 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4148 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4149 } else
4150 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00004151 if (!NewDI)
4152 return 0;
4153
John McCallfb44de92011-05-01 22:35:37 +00004154 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00004155 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00004156
4157 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4158 OldParm->getDeclContext(),
4159 OldParm->getInnerLocStart(),
4160 OldParm->getLocation(),
4161 OldParm->getIdentifier(),
4162 NewDI->getType(),
4163 NewDI,
4164 OldParm->getStorageClass(),
John McCallfb44de92011-05-01 22:35:37 +00004165 /* DefArg */ NULL);
4166 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4167 OldParm->getFunctionScopeIndex() + indexAdjustment);
4168 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00004169}
4170
4171template<typename Derived>
4172bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00004173 TransformFunctionTypeParams(SourceLocation Loc,
4174 ParmVarDecl **Params, unsigned NumParams,
4175 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00004176 SmallVectorImpl<QualType> &OutParamTypes,
4177 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00004178 int indexAdjustment = 0;
4179
Douglas Gregora009b592011-01-07 00:20:55 +00004180 for (unsigned i = 0; i != NumParams; ++i) {
4181 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00004182 assert(OldParm->getFunctionScopeIndex() == i);
4183
David Blaikiedc84cd52013-02-20 22:23:23 +00004184 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004185 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004186 if (OldParm->isParameterPack()) {
4187 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00004188 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00004189
Douglas Gregor603cfb42011-01-05 23:12:31 +00004190 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004191 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00004192 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004193 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4194 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004195 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4196
Douglas Gregor603cfb42011-01-05 23:12:31 +00004197 // Determine whether we should expand the parameter packs.
4198 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004199 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004200 Optional<unsigned> OrigNumExpansions =
4201 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004202 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004203 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4204 Pattern.getSourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004205 Unexpanded,
4206 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004207 RetainExpansion,
4208 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004209 return true;
4210 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004211
Douglas Gregor603cfb42011-01-05 23:12:31 +00004212 if (ShouldExpand) {
4213 // Expand the function parameter pack into multiple, separate
4214 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00004215 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00004216 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004217 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004218 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004219 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004220 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004221 OrigNumExpansions,
4222 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004223 if (!NewParm)
4224 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004225
Douglas Gregora009b592011-01-07 00:20:55 +00004226 OutParamTypes.push_back(NewParm->getType());
4227 if (PVars)
4228 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004229 }
Douglas Gregord3731192011-01-10 07:32:04 +00004230
4231 // If we're supposed to retain a pack expansion, do so by temporarily
4232 // forgetting the partially-substituted parameter pack.
4233 if (RetainExpansion) {
4234 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004235 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004236 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004237 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004238 OrigNumExpansions,
4239 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00004240 if (!NewParm)
4241 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004242
Douglas Gregord3731192011-01-10 07:32:04 +00004243 OutParamTypes.push_back(NewParm->getType());
4244 if (PVars)
4245 PVars->push_back(NewParm);
4246 }
4247
John McCallfb44de92011-05-01 22:35:37 +00004248 // The next parameter should have the same adjustment as the
4249 // last thing we pushed, but we post-incremented indexAdjustment
4250 // on every push. Also, if we push nothing, the adjustment should
4251 // go down by one.
4252 indexAdjustment--;
4253
Douglas Gregor603cfb42011-01-05 23:12:31 +00004254 // We're done with the pack expansion.
4255 continue;
4256 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004257
4258 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004259 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004260 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4261 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004262 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004263 NumExpansions,
4264 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004265 } else {
David Blaikiedc84cd52013-02-20 22:23:23 +00004266 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie66874fb2013-02-21 01:47:18 +00004267 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004268 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004269
John McCall21ef0fa2010-03-11 09:03:00 +00004270 if (!NewParm)
4271 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004272
Douglas Gregora009b592011-01-07 00:20:55 +00004273 OutParamTypes.push_back(NewParm->getType());
4274 if (PVars)
4275 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004276 continue;
4277 }
John McCall21ef0fa2010-03-11 09:03:00 +00004278
4279 // Deal with the possibility that we don't have a parameter
4280 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004281 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004282 bool IsPackExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004283 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004284 QualType NewType;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004285 if (const PackExpansionType *Expansion
Douglas Gregor603cfb42011-01-05 23:12:31 +00004286 = dyn_cast<PackExpansionType>(OldType)) {
4287 // We have a function parameter pack that may need to be expanded.
4288 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004289 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004290 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004291
Douglas Gregor603cfb42011-01-05 23:12:31 +00004292 // Determine whether we should expand the parameter packs.
4293 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004294 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004295 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004296 Unexpanded,
4297 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004298 RetainExpansion,
4299 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004300 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004301 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004302
Douglas Gregor603cfb42011-01-05 23:12:31 +00004303 if (ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004304 // Expand the function parameter pack into multiple, separate
Douglas Gregor603cfb42011-01-05 23:12:31 +00004305 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004306 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004307 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4308 QualType NewType = getDerived().TransformType(Pattern);
4309 if (NewType.isNull())
4310 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004311
Douglas Gregora009b592011-01-07 00:20:55 +00004312 OutParamTypes.push_back(NewType);
4313 if (PVars)
4314 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004315 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004316
Douglas Gregor603cfb42011-01-05 23:12:31 +00004317 // We're done with the pack expansion.
4318 continue;
4319 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004320
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004321 // If we're supposed to retain a pack expansion, do so by temporarily
4322 // forgetting the partially-substituted parameter pack.
4323 if (RetainExpansion) {
4324 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4325 QualType NewType = getDerived().TransformType(Pattern);
4326 if (NewType.isNull())
4327 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004328
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004329 OutParamTypes.push_back(NewType);
4330 if (PVars)
4331 PVars->push_back(0);
4332 }
Douglas Gregord3731192011-01-10 07:32:04 +00004333
Chad Rosier4a9d7952012-08-08 18:46:20 +00004334 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004335 // expansion.
4336 OldType = Expansion->getPattern();
4337 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004338 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4339 NewType = getDerived().TransformType(OldType);
4340 } else {
4341 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004342 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004343
Douglas Gregor603cfb42011-01-05 23:12:31 +00004344 if (NewType.isNull())
4345 return true;
4346
4347 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004348 NewType = getSema().Context.getPackExpansionType(NewType,
4349 NumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004350
Douglas Gregora009b592011-01-07 00:20:55 +00004351 OutParamTypes.push_back(NewType);
4352 if (PVars)
4353 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004354 }
4355
John McCallfb44de92011-05-01 22:35:37 +00004356#ifndef NDEBUG
4357 if (PVars) {
4358 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4359 if (ParmVarDecl *parm = (*PVars)[i])
4360 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004361 }
John McCallfb44de92011-05-01 22:35:37 +00004362#endif
4363
4364 return false;
4365}
John McCall21ef0fa2010-03-11 09:03:00 +00004366
4367template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004368QualType
John McCalla2becad2009-10-21 00:40:46 +00004369TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004370 FunctionProtoTypeLoc TL) {
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004371 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4372}
4373
4374template<typename Derived>
4375QualType
4376TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4377 FunctionProtoTypeLoc TL,
4378 CXXRecordDecl *ThisContext,
4379 unsigned ThisTypeQuals) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004380 // Transform the parameters and return type.
4381 //
Richard Smithe6975e92012-04-17 00:58:00 +00004382 // We are required to instantiate the params and return type in source order.
Douglas Gregordab60ad2010-10-01 18:44:50 +00004383 // When the function has a trailing return type, we instantiate the
4384 // parameters before the return type, since the return type can then refer
4385 // to the parameters themselves (via decltype, sizeof, etc.).
4386 //
Chris Lattner686775d2011-07-20 06:58:45 +00004387 SmallVector<QualType, 4> ParamTypes;
4388 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004389 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004390
Douglas Gregordab60ad2010-10-01 18:44:50 +00004391 QualType ResultType;
4392
Richard Smith9fbf3272012-08-14 22:51:13 +00004393 if (T->hasTrailingReturn()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004394 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004395 TL.getParmArray(),
4396 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004397 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004398 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004399 return QualType();
4400
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004401 {
4402 // C++11 [expr.prim.general]p3:
Chad Rosier4a9d7952012-08-08 18:46:20 +00004403 // If a declaration declares a member function or member function
4404 // template of a class X, the expression this is a prvalue of type
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004405 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier4a9d7952012-08-08 18:46:20 +00004406 // and the end of the function-definition, member-declarator, or
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004407 // declarator.
4408 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004409
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004410 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4411 if (ResultType.isNull())
4412 return QualType();
4413 }
Douglas Gregordab60ad2010-10-01 18:44:50 +00004414 }
4415 else {
4416 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4417 if (ResultType.isNull())
4418 return QualType();
4419
Chad Rosier4a9d7952012-08-08 18:46:20 +00004420 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004421 TL.getParmArray(),
4422 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004423 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004424 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004425 return QualType();
4426 }
4427
Richard Smithe6975e92012-04-17 00:58:00 +00004428 // FIXME: Need to transform the exception-specification too.
4429
John McCalla2becad2009-10-21 00:40:46 +00004430 QualType Result = TL.getType();
4431 if (getDerived().AlwaysRebuild() ||
4432 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004433 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004434 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
Jordan Rosebea522f2013-03-08 21:51:21 +00004435 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00004436 T->getExtProtoInfo());
John McCalla2becad2009-10-21 00:40:46 +00004437 if (Result.isNull())
4438 return QualType();
4439 }
Mike Stump1eb44332009-09-09 15:08:12 +00004440
John McCalla2becad2009-10-21 00:40:46 +00004441 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004442 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004443 NewTL.setLParenLoc(TL.getLParenLoc());
4444 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004445 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004446 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4447 NewTL.setArg(i, ParamDecls[i]);
4448
4449 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004450}
Mike Stump1eb44332009-09-09 15:08:12 +00004451
Douglas Gregor577f75a2009-08-04 16:50:30 +00004452template<typename Derived>
4453QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004454 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004455 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004456 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004457 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4458 if (ResultType.isNull())
4459 return QualType();
4460
4461 QualType Result = TL.getType();
4462 if (getDerived().AlwaysRebuild() ||
4463 ResultType != T->getResultType())
4464 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4465
4466 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004467 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004468 NewTL.setLParenLoc(TL.getLParenLoc());
4469 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004470 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004471
4472 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004473}
Mike Stump1eb44332009-09-09 15:08:12 +00004474
John McCalled976492009-12-04 22:46:56 +00004475template<typename Derived> QualType
4476TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004477 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004478 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004479 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004480 if (!D)
4481 return QualType();
4482
4483 QualType Result = TL.getType();
4484 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4485 Result = getDerived().RebuildUnresolvedUsingType(D);
4486 if (Result.isNull())
4487 return QualType();
4488 }
4489
4490 // We might get an arbitrary type spec type back. We should at
4491 // least always get a type spec type, though.
4492 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4493 NewTL.setNameLoc(TL.getNameLoc());
4494
4495 return Result;
4496}
4497
Douglas Gregor577f75a2009-08-04 16:50:30 +00004498template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004499QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004500 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004501 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004502 TypedefNameDecl *Typedef
4503 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4504 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004505 if (!Typedef)
4506 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004507
John McCalla2becad2009-10-21 00:40:46 +00004508 QualType Result = TL.getType();
4509 if (getDerived().AlwaysRebuild() ||
4510 Typedef != T->getDecl()) {
4511 Result = getDerived().RebuildTypedefType(Typedef);
4512 if (Result.isNull())
4513 return QualType();
4514 }
Mike Stump1eb44332009-09-09 15:08:12 +00004515
John McCalla2becad2009-10-21 00:40:46 +00004516 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4517 NewTL.setNameLoc(TL.getNameLoc());
4518
4519 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004520}
Mike Stump1eb44332009-09-09 15:08:12 +00004521
Douglas Gregor577f75a2009-08-04 16:50:30 +00004522template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004523QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004524 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004525 // typeof expressions are not potentially evaluated contexts
Eli Friedman80bfa3d2012-09-26 04:34:21 +00004526 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4527 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00004528
John McCall60d7b3a2010-08-24 06:29:42 +00004529 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004530 if (E.isInvalid())
4531 return QualType();
4532
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004533 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4534 if (E.isInvalid())
4535 return QualType();
4536
John McCalla2becad2009-10-21 00:40:46 +00004537 QualType Result = TL.getType();
4538 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004539 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004540 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004541 if (Result.isNull())
4542 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004543 }
John McCalla2becad2009-10-21 00:40:46 +00004544 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004545
John McCalla2becad2009-10-21 00:40:46 +00004546 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004547 NewTL.setTypeofLoc(TL.getTypeofLoc());
4548 NewTL.setLParenLoc(TL.getLParenLoc());
4549 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004550
4551 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004552}
Mike Stump1eb44332009-09-09 15:08:12 +00004553
4554template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004555QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004556 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004557 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4558 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4559 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004560 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004561
John McCalla2becad2009-10-21 00:40:46 +00004562 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004563 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4564 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004565 if (Result.isNull())
4566 return QualType();
4567 }
Mike Stump1eb44332009-09-09 15:08:12 +00004568
John McCalla2becad2009-10-21 00:40:46 +00004569 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004570 NewTL.setTypeofLoc(TL.getTypeofLoc());
4571 NewTL.setLParenLoc(TL.getLParenLoc());
4572 NewTL.setRParenLoc(TL.getRParenLoc());
4573 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004574
4575 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004576}
Mike Stump1eb44332009-09-09 15:08:12 +00004577
4578template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004579QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004580 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004581 const DecltypeType *T = TL.getTypePtr();
Faisal Vali618c2852013-10-03 06:29:33 +00004582 // Don't transform a decltype construct that has already been transformed
4583 // into a non-dependent type.
4584 // Allows the following to compile:
4585 // auto L = [](auto a) {
4586 // return [](auto b) ->decltype(a) {
4587 // return b;
4588 // };
4589 //};
4590 if (!T->isInstantiationDependentType()) {
4591 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(TL.getType());
4592 NewTL.setNameLoc(TL.getNameLoc());
4593 return NewTL.getType();
4594 }
John McCalla2becad2009-10-21 00:40:46 +00004595
Douglas Gregor670444e2009-08-04 22:27:00 +00004596 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004597 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4598 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004599
John McCall60d7b3a2010-08-24 06:29:42 +00004600 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004601 if (E.isInvalid())
4602 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004603
Richard Smith76f3f692012-02-22 02:04:18 +00004604 E = getSema().ActOnDecltypeExpression(E.take());
4605 if (E.isInvalid())
4606 return QualType();
4607
John McCalla2becad2009-10-21 00:40:46 +00004608 QualType Result = TL.getType();
4609 if (getDerived().AlwaysRebuild() ||
4610 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004611 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004612 if (Result.isNull())
4613 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004614 }
John McCalla2becad2009-10-21 00:40:46 +00004615 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004616
John McCalla2becad2009-10-21 00:40:46 +00004617 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4618 NewTL.setNameLoc(TL.getNameLoc());
4619
4620 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004621}
4622
4623template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004624QualType TreeTransform<Derived>::TransformUnaryTransformType(
4625 TypeLocBuilder &TLB,
4626 UnaryTransformTypeLoc TL) {
4627 QualType Result = TL.getType();
4628 if (Result->isDependentType()) {
4629 const UnaryTransformType *T = TL.getTypePtr();
4630 QualType NewBase =
4631 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4632 Result = getDerived().RebuildUnaryTransformType(NewBase,
4633 T->getUTTKind(),
4634 TL.getKWLoc());
4635 if (Result.isNull())
4636 return QualType();
4637 }
4638
4639 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4640 NewTL.setKWLoc(TL.getKWLoc());
4641 NewTL.setParensRange(TL.getParensRange());
4642 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4643 return Result;
4644}
4645
4646template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004647QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4648 AutoTypeLoc TL) {
4649 const AutoType *T = TL.getTypePtr();
4650 QualType OldDeduced = T->getDeducedType();
4651 QualType NewDeduced;
4652 if (!OldDeduced.isNull()) {
4653 NewDeduced = getDerived().TransformType(OldDeduced);
4654 if (NewDeduced.isNull())
4655 return QualType();
4656 }
4657
4658 QualType Result = TL.getType();
Richard Smithdc7a4f52013-04-30 13:56:41 +00004659 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4660 T->isDependentType()) {
Richard Smitha2c36462013-04-26 16:15:35 +00004661 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith34b41d92011-02-20 03:19:35 +00004662 if (Result.isNull())
4663 return QualType();
4664 }
4665
4666 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4667 NewTL.setNameLoc(TL.getNameLoc());
4668
4669 return Result;
4670}
4671
4672template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004673QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004674 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004675 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004676 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004677 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4678 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004679 if (!Record)
4680 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004681
John McCalla2becad2009-10-21 00:40:46 +00004682 QualType Result = TL.getType();
4683 if (getDerived().AlwaysRebuild() ||
4684 Record != T->getDecl()) {
4685 Result = getDerived().RebuildRecordType(Record);
4686 if (Result.isNull())
4687 return QualType();
4688 }
Mike Stump1eb44332009-09-09 15:08:12 +00004689
John McCalla2becad2009-10-21 00:40:46 +00004690 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4691 NewTL.setNameLoc(TL.getNameLoc());
4692
4693 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004694}
Mike Stump1eb44332009-09-09 15:08:12 +00004695
4696template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004697QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004698 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004699 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004700 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004701 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4702 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004703 if (!Enum)
4704 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004705
John McCalla2becad2009-10-21 00:40:46 +00004706 QualType Result = TL.getType();
4707 if (getDerived().AlwaysRebuild() ||
4708 Enum != T->getDecl()) {
4709 Result = getDerived().RebuildEnumType(Enum);
4710 if (Result.isNull())
4711 return QualType();
4712 }
Mike Stump1eb44332009-09-09 15:08:12 +00004713
John McCalla2becad2009-10-21 00:40:46 +00004714 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4715 NewTL.setNameLoc(TL.getNameLoc());
4716
4717 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004718}
John McCall7da24312009-09-05 00:15:47 +00004719
John McCall3cb0ebd2010-03-10 03:28:59 +00004720template<typename Derived>
4721QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4722 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004723 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004724 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4725 TL.getTypePtr()->getDecl());
4726 if (!D) return QualType();
4727
4728 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4729 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4730 return T;
4731}
4732
Douglas Gregor577f75a2009-08-04 16:50:30 +00004733template<typename Derived>
4734QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004735 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004736 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004737 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004738}
4739
Mike Stump1eb44332009-09-09 15:08:12 +00004740template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004741QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004742 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004743 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004744 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004745
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004746 // Substitute into the replacement type, which itself might involve something
4747 // that needs to be transformed. This only tends to occur with default
4748 // template arguments of template template parameters.
4749 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4750 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4751 if (Replacement.isNull())
4752 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004753
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004754 // Always canonicalize the replacement type.
4755 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4756 QualType Result
Chad Rosier4a9d7952012-08-08 18:46:20 +00004757 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004758 Replacement);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004759
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004760 // Propagate type-source information.
4761 SubstTemplateTypeParmTypeLoc NewTL
4762 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4763 NewTL.setNameLoc(TL.getNameLoc());
4764 return Result;
4765
John McCall49a832b2009-10-18 09:09:24 +00004766}
4767
4768template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004769QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4770 TypeLocBuilder &TLB,
4771 SubstTemplateTypeParmPackTypeLoc TL) {
4772 return TransformTypeSpecType(TLB, TL);
4773}
4774
4775template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004776QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004777 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004778 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004779 const TemplateSpecializationType *T = TL.getTypePtr();
4780
Douglas Gregor1d752d72011-03-02 18:46:51 +00004781 // The nested-name-specifier never matters in a TemplateSpecializationType,
4782 // because we can't have a dependent nested-name-specifier anyway.
4783 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004784 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004785 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4786 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004787 if (Template.isNull())
4788 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004789
John McCall43fed0d2010-11-12 08:19:04 +00004790 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4791}
4792
Eli Friedmanb001de72011-10-06 23:00:33 +00004793template<typename Derived>
4794QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4795 AtomicTypeLoc TL) {
4796 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4797 if (ValueType.isNull())
4798 return QualType();
4799
4800 QualType Result = TL.getType();
4801 if (getDerived().AlwaysRebuild() ||
4802 ValueType != TL.getValueLoc().getType()) {
4803 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4804 if (Result.isNull())
4805 return QualType();
4806 }
4807
4808 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4809 NewTL.setKWLoc(TL.getKWLoc());
4810 NewTL.setLParenLoc(TL.getLParenLoc());
4811 NewTL.setRParenLoc(TL.getRParenLoc());
4812
4813 return Result;
4814}
4815
Chad Rosier4a9d7952012-08-08 18:46:20 +00004816 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004817 /// container that provides a \c getArgLoc() member function.
4818 ///
4819 /// This iterator is intended to be used with the iterator form of
4820 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4821 template<typename ArgLocContainer>
4822 class TemplateArgumentLocContainerIterator {
4823 ArgLocContainer *Container;
4824 unsigned Index;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004825
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004826 public:
4827 typedef TemplateArgumentLoc value_type;
4828 typedef TemplateArgumentLoc reference;
4829 typedef int difference_type;
4830 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004831
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004832 class pointer {
4833 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004834
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004835 public:
4836 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004837
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004838 const TemplateArgumentLoc *operator->() const {
4839 return &Arg;
4840 }
4841 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004842
4843
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004844 TemplateArgumentLocContainerIterator() {}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004845
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004846 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4847 unsigned Index)
4848 : Container(&Container), Index(Index) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004849
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004850 TemplateArgumentLocContainerIterator &operator++() {
4851 ++Index;
4852 return *this;
4853 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004854
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004855 TemplateArgumentLocContainerIterator operator++(int) {
4856 TemplateArgumentLocContainerIterator Old(*this);
4857 ++(*this);
4858 return Old;
4859 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004860
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004861 TemplateArgumentLoc operator*() const {
4862 return Container->getArgLoc(Index);
4863 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004864
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004865 pointer operator->() const {
4866 return pointer(Container->getArgLoc(Index));
4867 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004868
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004869 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004870 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004871 return X.Container == Y.Container && X.Index == Y.Index;
4872 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004873
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004874 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004875 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004876 return !(X == Y);
4877 }
4878 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004879
4880
John McCall43fed0d2010-11-12 08:19:04 +00004881template <typename Derived>
4882QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4883 TypeLocBuilder &TLB,
4884 TemplateSpecializationTypeLoc TL,
4885 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004886 TemplateArgumentListInfo NewTemplateArgs;
4887 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4888 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004889 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4890 ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004891 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004892 ArgIterator(TL, TL.getNumArgs()),
4893 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004894 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004895
John McCall833ca992009-10-29 08:12:44 +00004896 // FIXME: maybe don't rebuild if all the template arguments are the same.
4897
4898 QualType Result =
4899 getDerived().RebuildTemplateSpecializationType(Template,
4900 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004901 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004902
4903 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004904 // Specializations of template template parameters are represented as
4905 // TemplateSpecializationTypes, and substitution of type alias templates
4906 // within a dependent context can transform them into
4907 // DependentTemplateSpecializationTypes.
4908 if (isa<DependentTemplateSpecializationType>(Result)) {
4909 DependentTemplateSpecializationTypeLoc NewTL
4910 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004911 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004912 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004913 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004914 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004915 NewTL.setLAngleLoc(TL.getLAngleLoc());
4916 NewTL.setRAngleLoc(TL.getRAngleLoc());
4917 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4918 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4919 return Result;
4920 }
4921
John McCall833ca992009-10-29 08:12:44 +00004922 TemplateSpecializationTypeLoc NewTL
4923 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004924 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004925 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4926 NewTL.setLAngleLoc(TL.getLAngleLoc());
4927 NewTL.setRAngleLoc(TL.getRAngleLoc());
4928 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4929 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004930 }
Mike Stump1eb44332009-09-09 15:08:12 +00004931
John McCall833ca992009-10-29 08:12:44 +00004932 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004933}
Mike Stump1eb44332009-09-09 15:08:12 +00004934
Douglas Gregora88f09f2011-02-28 17:23:35 +00004935template <typename Derived>
4936QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4937 TypeLocBuilder &TLB,
4938 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004939 TemplateName Template,
4940 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004941 TemplateArgumentListInfo NewTemplateArgs;
4942 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4943 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4944 typedef TemplateArgumentLocContainerIterator<
4945 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004946 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004947 ArgIterator(TL, TL.getNumArgs()),
4948 NewTemplateArgs))
4949 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004950
Douglas Gregora88f09f2011-02-28 17:23:35 +00004951 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier4a9d7952012-08-08 18:46:20 +00004952
Douglas Gregora88f09f2011-02-28 17:23:35 +00004953 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4954 QualType Result
4955 = getSema().Context.getDependentTemplateSpecializationType(
4956 TL.getTypePtr()->getKeyword(),
4957 DTN->getQualifier(),
4958 DTN->getIdentifier(),
4959 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004960
Douglas Gregora88f09f2011-02-28 17:23:35 +00004961 DependentTemplateSpecializationTypeLoc NewTL
4962 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004963 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004964 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004965 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004966 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004967 NewTL.setLAngleLoc(TL.getLAngleLoc());
4968 NewTL.setRAngleLoc(TL.getRAngleLoc());
4969 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4970 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4971 return Result;
4972 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004973
4974 QualType Result
Douglas Gregora88f09f2011-02-28 17:23:35 +00004975 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004976 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004977 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004978
Douglas Gregora88f09f2011-02-28 17:23:35 +00004979 if (!Result.isNull()) {
4980 /// FIXME: Wrap this in an elaborated-type-specifier?
4981 TemplateSpecializationTypeLoc NewTL
4982 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004983 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004984 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004985 NewTL.setLAngleLoc(TL.getLAngleLoc());
4986 NewTL.setRAngleLoc(TL.getRAngleLoc());
4987 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4988 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4989 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004990
Douglas Gregora88f09f2011-02-28 17:23:35 +00004991 return Result;
4992}
4993
Mike Stump1eb44332009-09-09 15:08:12 +00004994template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004995QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004996TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004997 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004998 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004999
Douglas Gregor9e876872011-03-01 18:12:44 +00005000 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00005001 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00005002 if (TL.getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005003 QualifierLoc
Douglas Gregor9e876872011-03-01 18:12:44 +00005004 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5005 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00005006 return QualType();
5007 }
Mike Stump1eb44332009-09-09 15:08:12 +00005008
John McCall43fed0d2010-11-12 08:19:04 +00005009 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5010 if (NamedT.isNull())
5011 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00005012
Richard Smith3e4c6c42011-05-05 21:57:07 +00005013 // C++0x [dcl.type.elab]p2:
5014 // If the identifier resolves to a typedef-name or the simple-template-id
5015 // resolves to an alias template specialization, the
5016 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00005017 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5018 if (const TemplateSpecializationType *TST =
5019 NamedT->getAs<TemplateSpecializationType>()) {
5020 TemplateName Template = TST->getTemplateName();
5021 if (TypeAliasTemplateDecl *TAT =
5022 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
5023 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5024 diag::err_tag_reference_non_tag) << 4;
5025 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5026 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00005027 }
5028 }
5029
John McCalla2becad2009-10-21 00:40:46 +00005030 QualType Result = TL.getType();
5031 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00005032 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005033 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00005034 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00005035 T->getKeyword(),
Douglas Gregor9e876872011-03-01 18:12:44 +00005036 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00005037 if (Result.isNull())
5038 return QualType();
5039 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00005040
Abramo Bagnara465d41b2010-05-11 21:36:43 +00005041 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005042 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00005043 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00005044 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00005045}
Mike Stump1eb44332009-09-09 15:08:12 +00005046
5047template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00005048QualType TreeTransform<Derived>::TransformAttributedType(
5049 TypeLocBuilder &TLB,
5050 AttributedTypeLoc TL) {
5051 const AttributedType *oldType = TL.getTypePtr();
5052 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5053 if (modifiedType.isNull())
5054 return QualType();
5055
5056 QualType result = TL.getType();
5057
5058 // FIXME: dependent operand expressions?
5059 if (getDerived().AlwaysRebuild() ||
5060 modifiedType != oldType->getModifiedType()) {
5061 // TODO: this is really lame; we should really be rebuilding the
5062 // equivalent type from first principles.
5063 QualType equivalentType
5064 = getDerived().TransformType(oldType->getEquivalentType());
5065 if (equivalentType.isNull())
5066 return QualType();
5067 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5068 modifiedType,
5069 equivalentType);
5070 }
5071
5072 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5073 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5074 if (TL.hasAttrOperand())
5075 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5076 if (TL.hasAttrExprOperand())
5077 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5078 else if (TL.hasAttrEnumOperand())
5079 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5080
5081 return result;
5082}
5083
5084template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00005085QualType
5086TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5087 ParenTypeLoc TL) {
5088 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5089 if (Inner.isNull())
5090 return QualType();
5091
5092 QualType Result = TL.getType();
5093 if (getDerived().AlwaysRebuild() ||
5094 Inner != TL.getInnerLoc().getType()) {
5095 Result = getDerived().RebuildParenType(Inner);
5096 if (Result.isNull())
5097 return QualType();
5098 }
5099
5100 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5101 NewTL.setLParenLoc(TL.getLParenLoc());
5102 NewTL.setRParenLoc(TL.getRParenLoc());
5103 return Result;
5104}
5105
5106template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00005107QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005108 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00005109 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00005110
Douglas Gregor2494dd02011-03-01 01:34:45 +00005111 NestedNameSpecifierLoc QualifierLoc
5112 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5113 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00005114 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00005115
John McCall33500952010-06-11 00:33:02 +00005116 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00005117 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00005118 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00005119 QualifierLoc,
5120 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00005121 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00005122 if (Result.isNull())
5123 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005124
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005125 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5126 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00005127 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5128
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005129 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005130 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00005131 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00005132 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005133 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005134 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00005135 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005136 NewTL.setNameLoc(TL.getNameLoc());
5137 }
John McCalla2becad2009-10-21 00:40:46 +00005138 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00005139}
Mike Stump1eb44332009-09-09 15:08:12 +00005140
Douglas Gregor577f75a2009-08-04 16:50:30 +00005141template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00005142QualType TreeTransform<Derived>::
5143 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005144 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005145 NestedNameSpecifierLoc QualifierLoc;
5146 if (TL.getQualifierLoc()) {
5147 QualifierLoc
5148 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5149 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00005150 return QualType();
5151 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005152
John McCall43fed0d2010-11-12 08:19:04 +00005153 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005154 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00005155}
5156
5157template<typename Derived>
5158QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005159TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5160 DependentTemplateSpecializationTypeLoc TL,
5161 NestedNameSpecifierLoc QualifierLoc) {
5162 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005163
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005164 TemplateArgumentListInfo NewTemplateArgs;
5165 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5166 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005167
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005168 typedef TemplateArgumentLocContainerIterator<
5169 DependentTemplateSpecializationTypeLoc> ArgIterator;
5170 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5171 ArgIterator(TL, TL.getNumArgs()),
5172 NewTemplateArgs))
5173 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005174
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005175 QualType Result
5176 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5177 QualifierLoc,
5178 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005179 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005180 NewTemplateArgs);
5181 if (Result.isNull())
5182 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005183
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005184 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5185 QualType NamedT = ElabT->getNamedType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005186
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005187 // Copy information relevant to the template specialization.
5188 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005189 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005190 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005191 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005192 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5193 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005194 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005195 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005196
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005197 // Copy information relevant to the elaborated type.
5198 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005199 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005200 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005201 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5202 DependentTemplateSpecializationTypeLoc SpecTL
5203 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005204 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005205 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005206 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005207 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005208 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5209 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005210 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005211 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005212 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005213 TemplateSpecializationTypeLoc SpecTL
5214 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005215 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005216 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005217 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5218 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005219 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005220 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005221 }
5222 return Result;
5223}
5224
5225template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00005226QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5227 PackExpansionTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005228 QualType Pattern
5229 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005230 if (Pattern.isNull())
5231 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005232
5233 QualType Result = TL.getType();
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005234 if (getDerived().AlwaysRebuild() ||
5235 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005236 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005237 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00005238 TL.getEllipsisLoc(),
5239 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005240 if (Result.isNull())
5241 return QualType();
5242 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005243
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005244 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5245 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5246 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00005247}
5248
5249template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005250QualType
5251TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005252 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005253 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005254 TLB.pushFullCopy(TL);
5255 return TL.getType();
5256}
5257
5258template<typename Derived>
5259QualType
5260TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005261 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005262 // ObjCObjectType is never dependent.
5263 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005264 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005265}
Mike Stump1eb44332009-09-09 15:08:12 +00005266
5267template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005268QualType
5269TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005270 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005271 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005272 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005273 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005274}
5275
Douglas Gregor577f75a2009-08-04 16:50:30 +00005276//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005277// Statement transformation
5278//===----------------------------------------------------------------------===//
5279template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005280StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005281TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005282 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005283}
5284
5285template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005286StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005287TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5288 return getDerived().TransformCompoundStmt(S, false);
5289}
5290
5291template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005292StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005293TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005294 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005295 Sema::CompoundScopeRAII CompoundScope(getSema());
5296
John McCall7114cba2010-08-27 19:56:05 +00005297 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005298 bool SubStmtChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005299 SmallVector<Stmt*, 8> Statements;
Douglas Gregor43959a92009-08-20 07:17:43 +00005300 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5301 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005302 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005303 if (Result.isInvalid()) {
5304 // Immediately fail if this was a DeclStmt, since it's very
5305 // likely that this will cause problems for future statements.
5306 if (isa<DeclStmt>(*B))
5307 return StmtError();
5308
5309 // Otherwise, just keep processing substatements and fail later.
5310 SubStmtInvalid = true;
5311 continue;
5312 }
Mike Stump1eb44332009-09-09 15:08:12 +00005313
Douglas Gregor43959a92009-08-20 07:17:43 +00005314 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5315 Statements.push_back(Result.takeAs<Stmt>());
5316 }
Mike Stump1eb44332009-09-09 15:08:12 +00005317
John McCall7114cba2010-08-27 19:56:05 +00005318 if (SubStmtInvalid)
5319 return StmtError();
5320
Douglas Gregor43959a92009-08-20 07:17:43 +00005321 if (!getDerived().AlwaysRebuild() &&
5322 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005323 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005324
5325 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005326 Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00005327 S->getRBracLoc(),
5328 IsStmtExpr);
5329}
Mike Stump1eb44332009-09-09 15:08:12 +00005330
Douglas Gregor43959a92009-08-20 07:17:43 +00005331template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005332StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005333TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005334 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005335 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005336 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5337 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005338
Eli Friedman264c1f82009-11-19 03:14:00 +00005339 // Transform the left-hand case value.
5340 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005341 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005342 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005343 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005344
Eli Friedman264c1f82009-11-19 03:14:00 +00005345 // Transform the right-hand case value (for the GNU case-range extension).
5346 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005347 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005348 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005349 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005350 }
Mike Stump1eb44332009-09-09 15:08:12 +00005351
Douglas Gregor43959a92009-08-20 07:17:43 +00005352 // Build the case statement.
5353 // Case statements are always rebuilt so that they will attached to their
5354 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005355 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005356 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005357 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005358 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005359 S->getColonLoc());
5360 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005361 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005362
Douglas Gregor43959a92009-08-20 07:17:43 +00005363 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005364 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005365 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005366 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005367
Douglas Gregor43959a92009-08-20 07:17:43 +00005368 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005369 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005370}
5371
5372template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005373StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005374TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005375 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005376 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005377 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005378 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005379
Douglas Gregor43959a92009-08-20 07:17:43 +00005380 // Default statements are always rebuilt
5381 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005382 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005383}
Mike Stump1eb44332009-09-09 15:08:12 +00005384
Douglas Gregor43959a92009-08-20 07:17:43 +00005385template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005386StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005387TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005388 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005389 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005390 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005391
Chris Lattner57ad3782011-02-17 20:34:02 +00005392 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5393 S->getDecl());
5394 if (!LD)
5395 return StmtError();
Richard Smith534986f2012-04-14 00:33:13 +00005396
5397
Douglas Gregor43959a92009-08-20 07:17:43 +00005398 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005399 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005400 cast<LabelDecl>(LD), SourceLocation(),
5401 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005402}
Mike Stump1eb44332009-09-09 15:08:12 +00005403
Douglas Gregor43959a92009-08-20 07:17:43 +00005404template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005405StmtResult
Richard Smith534986f2012-04-14 00:33:13 +00005406TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5407 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5408 if (SubStmt.isInvalid())
5409 return StmtError();
5410
5411 // TODO: transform attributes
5412 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5413 return S;
5414
5415 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5416 S->getAttrs(),
5417 SubStmt.get());
5418}
5419
5420template<typename Derived>
5421StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005422TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005423 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005424 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005425 VarDecl *ConditionVar = 0;
5426 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005427 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005428 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005429 getDerived().TransformDefinition(
5430 S->getConditionVariable()->getLocation(),
5431 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005432 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005433 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005434 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005435 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005436
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005437 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005438 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005439
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005440 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005441 if (S->getCond()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005442 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005443 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005444 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005445 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005446
John McCall9ae2f072010-08-23 23:25:46 +00005447 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005448 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005449 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005450
John McCall9ae2f072010-08-23 23:25:46 +00005451 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5452 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005453 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005454
Douglas Gregor43959a92009-08-20 07:17:43 +00005455 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005456 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005457 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005458 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005459
Douglas Gregor43959a92009-08-20 07:17:43 +00005460 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005461 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005462 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005463 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005464
Douglas Gregor43959a92009-08-20 07:17:43 +00005465 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005466 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005467 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005468 Then.get() == S->getThen() &&
5469 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005470 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005471
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005472 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005473 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005474 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005475}
5476
5477template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005478StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005479TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005480 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005481 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005482 VarDecl *ConditionVar = 0;
5483 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005484 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005485 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005486 getDerived().TransformDefinition(
5487 S->getConditionVariable()->getLocation(),
5488 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005489 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005490 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005491 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005492 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005493
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005494 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005495 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005496 }
Mike Stump1eb44332009-09-09 15:08:12 +00005497
Douglas Gregor43959a92009-08-20 07:17:43 +00005498 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005499 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005500 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005501 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005502 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005503 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005504
Douglas Gregor43959a92009-08-20 07:17:43 +00005505 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005506 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005507 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005508 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005509
Douglas Gregor43959a92009-08-20 07:17:43 +00005510 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005511 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5512 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005513}
Mike Stump1eb44332009-09-09 15:08:12 +00005514
Douglas Gregor43959a92009-08-20 07:17:43 +00005515template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005516StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005517TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005518 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005519 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005520 VarDecl *ConditionVar = 0;
5521 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005522 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005523 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005524 getDerived().TransformDefinition(
5525 S->getConditionVariable()->getLocation(),
5526 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005527 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005528 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005529 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005530 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005531
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005532 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005533 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005534
5535 if (S->getCond()) {
5536 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005537 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005538 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005539 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005540 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005541 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005542 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005543 }
Mike Stump1eb44332009-09-09 15:08:12 +00005544
John McCall9ae2f072010-08-23 23:25:46 +00005545 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5546 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005547 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005548
Douglas Gregor43959a92009-08-20 07:17:43 +00005549 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005550 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005551 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005552 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005553
Douglas Gregor43959a92009-08-20 07:17:43 +00005554 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005555 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005556 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005557 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005558 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005559
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005560 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005561 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005562}
Mike Stump1eb44332009-09-09 15:08:12 +00005563
Douglas Gregor43959a92009-08-20 07:17:43 +00005564template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005565StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005566TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005567 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005568 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005569 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005570 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005571
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005572 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005573 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005574 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005575 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005576
Douglas Gregor43959a92009-08-20 07:17:43 +00005577 if (!getDerived().AlwaysRebuild() &&
5578 Cond.get() == S->getCond() &&
5579 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005580 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005581
John McCall9ae2f072010-08-23 23:25:46 +00005582 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5583 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005584 S->getRParenLoc());
5585}
Mike Stump1eb44332009-09-09 15:08:12 +00005586
Douglas Gregor43959a92009-08-20 07:17:43 +00005587template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005588StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005589TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005590 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005591 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005592 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005593 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005594
Douglas Gregor43959a92009-08-20 07:17:43 +00005595 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005596 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005597 VarDecl *ConditionVar = 0;
5598 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005599 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005600 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005601 getDerived().TransformDefinition(
5602 S->getConditionVariable()->getLocation(),
5603 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005604 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005605 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005606 } else {
5607 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005608
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005609 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005610 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005611
5612 if (S->getCond()) {
5613 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005614 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005615 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005616 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005617 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005618
John McCall9ae2f072010-08-23 23:25:46 +00005619 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005620 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005621 }
Mike Stump1eb44332009-09-09 15:08:12 +00005622
Chad Rosier4a9d7952012-08-08 18:46:20 +00005623 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCall9ae2f072010-08-23 23:25:46 +00005624 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005625 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005626
Douglas Gregor43959a92009-08-20 07:17:43 +00005627 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005628 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005629 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005630 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005631
Richard Smith41956372013-01-14 22:39:08 +00005632 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCall9ae2f072010-08-23 23:25:46 +00005633 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005634 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005635
Douglas Gregor43959a92009-08-20 07:17:43 +00005636 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005637 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005638 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005639 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005640
Douglas Gregor43959a92009-08-20 07:17:43 +00005641 if (!getDerived().AlwaysRebuild() &&
5642 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005643 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005644 Inc.get() == S->getInc() &&
5645 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005646 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005647
Douglas Gregor43959a92009-08-20 07:17:43 +00005648 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005649 Init.get(), FullCond, ConditionVar,
5650 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005651}
5652
5653template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005654StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005655TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005656 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5657 S->getLabel());
5658 if (!LD)
5659 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005660
Douglas Gregor43959a92009-08-20 07:17:43 +00005661 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005662 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005663 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005664}
5665
5666template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005667StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005668TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005669 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005670 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005671 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005672 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005673
Douglas Gregor43959a92009-08-20 07:17:43 +00005674 if (!getDerived().AlwaysRebuild() &&
5675 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005676 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005677
5678 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005679 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005680}
5681
5682template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005683StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005684TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005685 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005686}
Mike Stump1eb44332009-09-09 15:08:12 +00005687
Douglas Gregor43959a92009-08-20 07:17:43 +00005688template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005689StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005690TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005691 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005692}
Mike Stump1eb44332009-09-09 15:08:12 +00005693
Douglas Gregor43959a92009-08-20 07:17:43 +00005694template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005695StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005696TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005697 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005698 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005699 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005700
Mike Stump1eb44332009-09-09 15:08:12 +00005701 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005702 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005703 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005704}
Mike Stump1eb44332009-09-09 15:08:12 +00005705
Douglas Gregor43959a92009-08-20 07:17:43 +00005706template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005707StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005708TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005709 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005710 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005711 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5712 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005713 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5714 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005715 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005716 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005717
Douglas Gregor43959a92009-08-20 07:17:43 +00005718 if (Transformed != *D)
5719 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005720
Douglas Gregor43959a92009-08-20 07:17:43 +00005721 Decls.push_back(Transformed);
5722 }
Mike Stump1eb44332009-09-09 15:08:12 +00005723
Douglas Gregor43959a92009-08-20 07:17:43 +00005724 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005725 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005726
Rafael Espindola4549d7f2013-07-09 12:05:01 +00005727 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005728}
Mike Stump1eb44332009-09-09 15:08:12 +00005729
Douglas Gregor43959a92009-08-20 07:17:43 +00005730template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005731StmtResult
Chad Rosierdf5faf52012-08-25 00:11:56 +00005732TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005733
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005734 SmallVector<Expr*, 8> Constraints;
5735 SmallVector<Expr*, 8> Exprs;
Chris Lattner686775d2011-07-20 06:58:45 +00005736 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005737
John McCall60d7b3a2010-08-24 06:29:42 +00005738 ExprResult AsmString;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005739 SmallVector<Expr*, 8> Clobbers;
Anders Carlsson703e3942010-01-24 05:50:09 +00005740
5741 bool ExprsChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005742
Anders Carlsson703e3942010-01-24 05:50:09 +00005743 // Go through the outputs.
5744 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005745 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005746
Anders Carlsson703e3942010-01-24 05:50:09 +00005747 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005748 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005749
Anders Carlsson703e3942010-01-24 05:50:09 +00005750 // Transform the output expr.
5751 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005752 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005753 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005754 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005755
Anders Carlsson703e3942010-01-24 05:50:09 +00005756 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005757
John McCall9ae2f072010-08-23 23:25:46 +00005758 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005759 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005760
Anders Carlsson703e3942010-01-24 05:50:09 +00005761 // Go through the inputs.
5762 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005763 Names.push_back(S->getInputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005764
Anders Carlsson703e3942010-01-24 05:50:09 +00005765 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005766 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005767
Anders Carlsson703e3942010-01-24 05:50:09 +00005768 // Transform the input expr.
5769 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005770 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005771 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005772 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005773
Anders Carlsson703e3942010-01-24 05:50:09 +00005774 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005775
John McCall9ae2f072010-08-23 23:25:46 +00005776 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005777 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005778
Anders Carlsson703e3942010-01-24 05:50:09 +00005779 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005780 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005781
5782 // Go through the clobbers.
5783 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosier5c7f5942012-08-27 23:28:41 +00005784 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005785
5786 // No need to transform the asm string literal.
5787 AsmString = SemaRef.Owned(S->getAsmString());
Chad Rosierdf5faf52012-08-25 00:11:56 +00005788 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5789 S->isVolatile(), S->getNumOutputs(),
5790 S->getNumInputs(), Names.data(),
5791 Constraints, Exprs, AsmString.get(),
5792 Clobbers, S->getRParenLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005793}
5794
Chad Rosier8cd64b42012-06-11 20:47:18 +00005795template<typename Derived>
5796StmtResult
5797TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier79efe242012-08-07 00:29:06 +00005798 ArrayRef<Token> AsmToks =
5799 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier62f22b82012-08-08 19:48:07 +00005800
John McCallaeeacf72013-05-03 00:10:13 +00005801 bool HadError = false, HadChange = false;
5802
5803 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5804 SmallVector<Expr*, 8> TransformedExprs;
5805 TransformedExprs.reserve(SrcExprs.size());
5806 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5807 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5808 if (!Result.isUsable()) {
5809 HadError = true;
5810 } else {
5811 HadChange |= (Result.get() != SrcExprs[i]);
5812 TransformedExprs.push_back(Result.take());
5813 }
5814 }
5815
5816 if (HadError) return StmtError();
5817 if (!HadChange && !getDerived().AlwaysRebuild())
5818 return Owned(S);
5819
Chad Rosier7bd092b2012-08-15 16:53:30 +00005820 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallaeeacf72013-05-03 00:10:13 +00005821 AsmToks, S->getAsmString(),
5822 S->getNumOutputs(), S->getNumInputs(),
5823 S->getAllConstraints(), S->getClobbers(),
5824 TransformedExprs, S->getEndLoc());
Chad Rosier8cd64b42012-06-11 20:47:18 +00005825}
Douglas Gregor43959a92009-08-20 07:17:43 +00005826
5827template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005828StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005829TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005830 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005831 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005832 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005833 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005834
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005835 // Transform the @catch statements (if present).
5836 bool AnyCatchChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005837 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005838 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005839 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005840 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005841 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005842 if (Catch.get() != S->getCatchStmt(I))
5843 AnyCatchChanged = true;
5844 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005845 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005846
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005847 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005848 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005849 if (S->getFinallyStmt()) {
5850 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5851 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005852 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005853 }
5854
5855 // If nothing changed, just retain this statement.
5856 if (!getDerived().AlwaysRebuild() &&
5857 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005858 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005859 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005860 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005861
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005862 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005863 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005864 CatchStmts, Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005865}
Mike Stump1eb44332009-09-09 15:08:12 +00005866
Douglas Gregor43959a92009-08-20 07:17:43 +00005867template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005868StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005869TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005870 // Transform the @catch parameter, if there is one.
5871 VarDecl *Var = 0;
5872 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5873 TypeSourceInfo *TSInfo = 0;
5874 if (FromVar->getTypeSourceInfo()) {
5875 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5876 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005877 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005878 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005879
Douglas Gregorbe270a02010-04-26 17:57:08 +00005880 QualType T;
5881 if (TSInfo)
5882 T = TSInfo->getType();
5883 else {
5884 T = getDerived().TransformType(FromVar->getType());
5885 if (T.isNull())
Chad Rosier4a9d7952012-08-08 18:46:20 +00005886 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005887 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005888
Douglas Gregorbe270a02010-04-26 17:57:08 +00005889 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5890 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005891 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005892 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005893
John McCall60d7b3a2010-08-24 06:29:42 +00005894 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005895 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005896 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005897
5898 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005899 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005900 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005901}
Mike Stump1eb44332009-09-09 15:08:12 +00005902
Douglas Gregor43959a92009-08-20 07:17:43 +00005903template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005904StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005905TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005906 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005907 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005908 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005909 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005910
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005911 // If nothing changed, just retain this statement.
5912 if (!getDerived().AlwaysRebuild() &&
5913 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005914 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005915
5916 // Build a new statement.
5917 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005918 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005919}
Mike Stump1eb44332009-09-09 15:08:12 +00005920
Douglas Gregor43959a92009-08-20 07:17:43 +00005921template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005922StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005923TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005924 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005925 if (S->getThrowExpr()) {
5926 Operand = getDerived().TransformExpr(S->getThrowExpr());
5927 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005928 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005929 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005930
Douglas Gregord1377b22010-04-22 21:44:01 +00005931 if (!getDerived().AlwaysRebuild() &&
5932 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005933 return getSema().Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005934
John McCall9ae2f072010-08-23 23:25:46 +00005935 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005936}
Mike Stump1eb44332009-09-09 15:08:12 +00005937
Douglas Gregor43959a92009-08-20 07:17:43 +00005938template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005939StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005940TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005941 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005942 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005943 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005944 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005945 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005946 Object =
5947 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5948 Object.get());
5949 if (Object.isInvalid())
5950 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005951
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005952 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005953 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005954 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005955 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005956
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005957 // If nothing change, just retain the current statement.
5958 if (!getDerived().AlwaysRebuild() &&
5959 Object.get() == S->getSynchExpr() &&
5960 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005961 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005962
5963 // Build a new statement.
5964 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005965 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005966}
5967
5968template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005969StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005970TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5971 ObjCAutoreleasePoolStmt *S) {
5972 // Transform the body.
5973 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5974 if (Body.isInvalid())
5975 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005976
John McCallf85e1932011-06-15 23:02:42 +00005977 // If nothing changed, just retain this statement.
5978 if (!getDerived().AlwaysRebuild() &&
5979 Body.get() == S->getSubStmt())
5980 return SemaRef.Owned(S);
5981
5982 // Build a new statement.
5983 return getDerived().RebuildObjCAutoreleasePoolStmt(
5984 S->getAtLoc(), Body.get());
5985}
5986
5987template<typename Derived>
5988StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005989TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005990 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005991 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005992 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005993 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005994 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005995
Douglas Gregorc3203e72010-04-22 23:10:45 +00005996 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005997 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005998 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005999 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006000
Douglas Gregorc3203e72010-04-22 23:10:45 +00006001 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00006002 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00006003 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006004 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006005
Douglas Gregorc3203e72010-04-22 23:10:45 +00006006 // If nothing changed, just retain this statement.
6007 if (!getDerived().AlwaysRebuild() &&
6008 Element.get() == S->getElement() &&
6009 Collection.get() == S->getCollection() &&
6010 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00006011 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006012
Douglas Gregorc3203e72010-04-22 23:10:45 +00006013 // Build a new statement.
6014 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006015 Element.get(),
6016 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00006017 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006018 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00006019}
6020
6021
6022template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006023StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00006024TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
6025 // Transform the exception declaration, if any.
6026 VarDecl *Var = 0;
6027 if (S->getExceptionDecl()) {
6028 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00006029 TypeSourceInfo *T = getDerived().TransformType(
6030 ExceptionDecl->getTypeSourceInfo());
6031 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006032 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00006033
Douglas Gregor83cb9422010-09-09 17:09:21 +00006034 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00006035 ExceptionDecl->getInnerLocStart(),
6036 ExceptionDecl->getLocation(),
6037 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00006038 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00006039 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00006040 }
Mike Stump1eb44332009-09-09 15:08:12 +00006041
Douglas Gregor43959a92009-08-20 07:17:43 +00006042 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00006043 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00006044 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006045 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00006046
Douglas Gregor43959a92009-08-20 07:17:43 +00006047 if (!getDerived().AlwaysRebuild() &&
6048 !Var &&
6049 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00006050 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00006051
6052 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
6053 Var,
John McCall9ae2f072010-08-23 23:25:46 +00006054 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00006055}
Mike Stump1eb44332009-09-09 15:08:12 +00006056
Douglas Gregor43959a92009-08-20 07:17:43 +00006057template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006058StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00006059TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
6060 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006061 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00006062 = getDerived().TransformCompoundStmt(S->getTryBlock());
6063 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006064 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00006065
Douglas Gregor43959a92009-08-20 07:17:43 +00006066 // Transform the handlers.
6067 bool HandlerChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006068 SmallVector<Stmt*, 8> Handlers;
Douglas Gregor43959a92009-08-20 07:17:43 +00006069 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00006070 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00006071 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
6072 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006073 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00006074
Douglas Gregor43959a92009-08-20 07:17:43 +00006075 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
6076 Handlers.push_back(Handler.takeAs<Stmt>());
6077 }
Mike Stump1eb44332009-09-09 15:08:12 +00006078
Douglas Gregor43959a92009-08-20 07:17:43 +00006079 if (!getDerived().AlwaysRebuild() &&
6080 TryBlock.get() == S->getTryBlock() &&
6081 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006082 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00006083
John McCall9ae2f072010-08-23 23:25:46 +00006084 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006085 Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00006086}
Mike Stump1eb44332009-09-09 15:08:12 +00006087
Richard Smithad762fc2011-04-14 22:09:26 +00006088template<typename Derived>
6089StmtResult
6090TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6091 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6092 if (Range.isInvalid())
6093 return StmtError();
6094
6095 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6096 if (BeginEnd.isInvalid())
6097 return StmtError();
6098
6099 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6100 if (Cond.isInvalid())
6101 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00006102 if (Cond.get())
6103 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
6104 if (Cond.isInvalid())
6105 return StmtError();
6106 if (Cond.get())
6107 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00006108
6109 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6110 if (Inc.isInvalid())
6111 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00006112 if (Inc.get())
6113 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00006114
6115 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6116 if (LoopVar.isInvalid())
6117 return StmtError();
6118
6119 StmtResult NewStmt = S;
6120 if (getDerived().AlwaysRebuild() ||
6121 Range.get() != S->getRangeStmt() ||
6122 BeginEnd.get() != S->getBeginEndStmt() ||
6123 Cond.get() != S->getCond() ||
6124 Inc.get() != S->getInc() ||
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006125 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smithad762fc2011-04-14 22:09:26 +00006126 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6127 S->getColonLoc(), Range.get(),
6128 BeginEnd.get(), Cond.get(),
6129 Inc.get(), LoopVar.get(),
6130 S->getRParenLoc());
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006131 if (NewStmt.isInvalid())
6132 return StmtError();
6133 }
Richard Smithad762fc2011-04-14 22:09:26 +00006134
6135 StmtResult Body = getDerived().TransformStmt(S->getBody());
6136 if (Body.isInvalid())
6137 return StmtError();
6138
6139 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6140 // it now so we have a new statement to attach the body to.
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006141 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smithad762fc2011-04-14 22:09:26 +00006142 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6143 S->getColonLoc(), Range.get(),
6144 BeginEnd.get(), Cond.get(),
6145 Inc.get(), LoopVar.get(),
6146 S->getRParenLoc());
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006147 if (NewStmt.isInvalid())
6148 return StmtError();
6149 }
Richard Smithad762fc2011-04-14 22:09:26 +00006150
6151 if (NewStmt.get() == S)
6152 return SemaRef.Owned(S);
6153
6154 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6155}
6156
John Wiegley28bbe4b2011-04-28 01:08:34 +00006157template<typename Derived>
6158StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00006159TreeTransform<Derived>::TransformMSDependentExistsStmt(
6160 MSDependentExistsStmt *S) {
6161 // Transform the nested-name-specifier, if any.
6162 NestedNameSpecifierLoc QualifierLoc;
6163 if (S->getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006164 QualifierLoc
Douglas Gregorba0513d2011-10-25 01:33:02 +00006165 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6166 if (!QualifierLoc)
6167 return StmtError();
6168 }
6169
6170 // Transform the declaration name.
6171 DeclarationNameInfo NameInfo = S->getNameInfo();
6172 if (NameInfo.getName()) {
6173 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6174 if (!NameInfo.getName())
6175 return StmtError();
6176 }
6177
6178 // Check whether anything changed.
6179 if (!getDerived().AlwaysRebuild() &&
6180 QualifierLoc == S->getQualifierLoc() &&
6181 NameInfo.getName() == S->getNameInfo().getName())
6182 return S;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006183
Douglas Gregorba0513d2011-10-25 01:33:02 +00006184 // Determine whether this name exists, if we can.
6185 CXXScopeSpec SS;
6186 SS.Adopt(QualifierLoc);
6187 bool Dependent = false;
6188 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
6189 case Sema::IER_Exists:
6190 if (S->isIfExists())
6191 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006192
Douglas Gregorba0513d2011-10-25 01:33:02 +00006193 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6194
6195 case Sema::IER_DoesNotExist:
6196 if (S->isIfNotExists())
6197 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006198
Douglas Gregorba0513d2011-10-25 01:33:02 +00006199 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006200
Douglas Gregorba0513d2011-10-25 01:33:02 +00006201 case Sema::IER_Dependent:
6202 Dependent = true;
6203 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006204
Douglas Gregor65019ac2011-10-25 03:44:56 +00006205 case Sema::IER_Error:
6206 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00006207 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006208
Douglas Gregorba0513d2011-10-25 01:33:02 +00006209 // We need to continue with the instantiation, so do so now.
6210 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6211 if (SubStmt.isInvalid())
6212 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006213
Douglas Gregorba0513d2011-10-25 01:33:02 +00006214 // If we have resolved the name, just transform to the substatement.
6215 if (!Dependent)
6216 return SubStmt;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006217
Douglas Gregorba0513d2011-10-25 01:33:02 +00006218 // The name is still dependent, so build a dependent expression again.
6219 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6220 S->isIfExists(),
6221 QualifierLoc,
6222 NameInfo,
6223 SubStmt.get());
6224}
6225
6226template<typename Derived>
John McCall76da55d2013-04-16 07:28:30 +00006227ExprResult
6228TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6229 NestedNameSpecifierLoc QualifierLoc;
6230 if (E->getQualifierLoc()) {
6231 QualifierLoc
6232 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6233 if (!QualifierLoc)
6234 return ExprError();
6235 }
6236
6237 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6238 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6239 if (!PD)
6240 return ExprError();
6241
6242 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6243 if (Base.isInvalid())
6244 return ExprError();
6245
6246 return new (SemaRef.getASTContext())
6247 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6248 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6249 QualifierLoc, E->getMemberLoc());
6250}
6251
6252template<typename Derived>
Douglas Gregorba0513d2011-10-25 01:33:02 +00006253StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00006254TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
6255 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
6256 if(TryBlock.isInvalid()) return StmtError();
6257
6258 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
6259 if(!getDerived().AlwaysRebuild() &&
6260 TryBlock.get() == S->getTryBlock() &&
6261 Handler.get() == S->getHandler())
6262 return SemaRef.Owned(S);
6263
6264 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
6265 S->getTryLoc(),
6266 TryBlock.take(),
6267 Handler.take());
6268}
6269
6270template<typename Derived>
6271StmtResult
6272TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
6273 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6274 if(Block.isInvalid()) return StmtError();
6275
6276 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
6277 Block.take());
6278}
6279
6280template<typename Derived>
6281StmtResult
6282TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
6283 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
6284 if(FilterExpr.isInvalid()) return StmtError();
6285
6286 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6287 if(Block.isInvalid()) return StmtError();
6288
6289 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
6290 FilterExpr.take(),
6291 Block.take());
6292}
6293
6294template<typename Derived>
6295StmtResult
6296TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6297 if(isa<SEHFinallyStmt>(Handler))
6298 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6299 else
6300 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6301}
6302
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006303template<typename Derived>
6304StmtResult
6305TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
Alexey Bataev0c018352013-09-06 18:03:48 +00006306 DeclarationNameInfo DirName;
6307 getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, 0);
6308
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006309 // Transform the clauses
Alexey Bataev0c018352013-09-06 18:03:48 +00006310 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006311 ArrayRef<OMPClause *> Clauses = D->clauses();
6312 TClauses.reserve(Clauses.size());
6313 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6314 I != E; ++I) {
6315 if (*I) {
6316 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataev0c018352013-09-06 18:03:48 +00006317 if (!Clause) {
6318 getSema().EndOpenMPDSABlock(0);
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006319 return StmtError();
Alexey Bataev0c018352013-09-06 18:03:48 +00006320 }
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006321 TClauses.push_back(Clause);
6322 }
6323 else {
6324 TClauses.push_back(0);
6325 }
6326 }
Alexey Bataev0c018352013-09-06 18:03:48 +00006327 if (!D->getAssociatedStmt()) {
6328 getSema().EndOpenMPDSABlock(0);
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006329 return StmtError();
Alexey Bataev0c018352013-09-06 18:03:48 +00006330 }
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006331 StmtResult AssociatedStmt =
6332 getDerived().TransformStmt(D->getAssociatedStmt());
Alexey Bataev0c018352013-09-06 18:03:48 +00006333 if (AssociatedStmt.isInvalid()) {
6334 getSema().EndOpenMPDSABlock(0);
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006335 return StmtError();
Alexey Bataev0c018352013-09-06 18:03:48 +00006336 }
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006337
Alexey Bataev0c018352013-09-06 18:03:48 +00006338 StmtResult Res = getDerived().RebuildOMPParallelDirective(TClauses,
6339 AssociatedStmt.take(),
6340 D->getLocStart(),
6341 D->getLocEnd());
6342 getSema().EndOpenMPDSABlock(Res.get());
6343 return Res;
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006344}
6345
6346template<typename Derived>
6347OMPClause *
6348TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
6349 return getDerived().RebuildOMPDefaultClause(C->getDefaultKind(),
6350 C->getDefaultKindKwLoc(),
6351 C->getLocStart(),
6352 C->getLParenLoc(),
6353 C->getLocEnd());
6354}
6355
6356template<typename Derived>
6357OMPClause *
6358TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev0c018352013-09-06 18:03:48 +00006359 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006360 Vars.reserve(C->varlist_size());
Alexey Bataev543c4ae2013-09-24 03:17:45 +00006361 for (OMPPrivateClause::varlist_iterator I = C->varlist_begin(),
6362 E = C->varlist_end();
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006363 I != E; ++I) {
6364 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6365 if (EVar.isInvalid())
6366 return 0;
6367 Vars.push_back(EVar.take());
6368 }
6369 return getDerived().RebuildOMPPrivateClause(Vars,
6370 C->getLocStart(),
6371 C->getLParenLoc(),
6372 C->getLocEnd());
6373}
6374
Alexey Bataev0c018352013-09-06 18:03:48 +00006375template<typename Derived>
6376OMPClause *
Alexey Bataevd195bc32013-10-01 05:32:34 +00006377TreeTransform<Derived>::TransformOMPFirstprivateClause(
6378 OMPFirstprivateClause *C) {
6379 llvm::SmallVector<Expr *, 16> Vars;
6380 Vars.reserve(C->varlist_size());
6381 for (OMPFirstprivateClause::varlist_iterator I = C->varlist_begin(),
6382 E = C->varlist_end();
6383 I != E; ++I) {
6384 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6385 if (EVar.isInvalid())
6386 return 0;
6387 Vars.push_back(EVar.take());
6388 }
6389 return getDerived().RebuildOMPFirstprivateClause(Vars,
6390 C->getLocStart(),
6391 C->getLParenLoc(),
6392 C->getLocEnd());
6393}
6394
6395template<typename Derived>
6396OMPClause *
Alexey Bataev0c018352013-09-06 18:03:48 +00006397TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
6398 llvm::SmallVector<Expr *, 16> Vars;
6399 Vars.reserve(C->varlist_size());
Alexey Bataev543c4ae2013-09-24 03:17:45 +00006400 for (OMPSharedClause::varlist_iterator I = C->varlist_begin(),
6401 E = C->varlist_end();
Alexey Bataev0c018352013-09-06 18:03:48 +00006402 I != E; ++I) {
6403 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6404 if (EVar.isInvalid())
6405 return 0;
6406 Vars.push_back(EVar.take());
6407 }
6408 return getDerived().RebuildOMPSharedClause(Vars,
6409 C->getLocStart(),
6410 C->getLParenLoc(),
6411 C->getLocEnd());
6412}
6413
Douglas Gregor43959a92009-08-20 07:17:43 +00006414//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00006415// Expression transformation
6416//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006417template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006418ExprResult
John McCall454feb92009-12-08 09:21:05 +00006419TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006420 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006421}
Mike Stump1eb44332009-09-09 15:08:12 +00006422
6423template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006424ExprResult
John McCall454feb92009-12-08 09:21:05 +00006425TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006426 NestedNameSpecifierLoc QualifierLoc;
6427 if (E->getQualifierLoc()) {
6428 QualifierLoc
6429 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6430 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006431 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006432 }
John McCalldbd872f2009-12-08 09:08:17 +00006433
6434 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006435 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6436 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006437 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006438 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006439
John McCallec8045d2010-08-17 21:27:17 +00006440 DeclarationNameInfo NameInfo = E->getNameInfo();
6441 if (NameInfo.getName()) {
6442 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6443 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006444 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006445 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006446
6447 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006448 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006449 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006450 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006451 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006452
6453 // Mark it referenced in the new context regardless.
6454 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006455 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006456
John McCall3fa5cae2010-10-26 07:05:15 +00006457 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006458 }
John McCalldbd872f2009-12-08 09:08:17 +00006459
6460 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006461 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006462 TemplateArgs = &TransArgs;
6463 TransArgs.setLAngleLoc(E->getLAngleLoc());
6464 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006465 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6466 E->getNumTemplateArgs(),
6467 TransArgs))
6468 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006469 }
6470
Chad Rosier4a9d7952012-08-08 18:46:20 +00006471 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregor40d96a62011-02-28 21:54:11 +00006472 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006473}
Mike Stump1eb44332009-09-09 15:08:12 +00006474
Douglas Gregorb98b1992009-08-11 05:31:07 +00006475template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006476ExprResult
John McCall454feb92009-12-08 09:21:05 +00006477TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006478 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006479}
Mike Stump1eb44332009-09-09 15:08:12 +00006480
Douglas Gregorb98b1992009-08-11 05:31:07 +00006481template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006482ExprResult
John McCall454feb92009-12-08 09:21:05 +00006483TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006484 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006485}
Mike Stump1eb44332009-09-09 15:08:12 +00006486
Douglas Gregorb98b1992009-08-11 05:31:07 +00006487template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006488ExprResult
John McCall454feb92009-12-08 09:21:05 +00006489TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006490 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006491}
Mike Stump1eb44332009-09-09 15:08:12 +00006492
Douglas Gregorb98b1992009-08-11 05:31:07 +00006493template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006494ExprResult
John McCall454feb92009-12-08 09:21:05 +00006495TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006496 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006497}
Mike Stump1eb44332009-09-09 15:08:12 +00006498
Douglas Gregorb98b1992009-08-11 05:31:07 +00006499template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006500ExprResult
John McCall454feb92009-12-08 09:21:05 +00006501TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006502 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006503}
6504
6505template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006506ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006507TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis391ca9f2013-04-09 01:17:02 +00006508 if (FunctionDecl *FD = E->getDirectCallee())
6509 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smith9fcce652012-03-07 08:35:16 +00006510 return SemaRef.MaybeBindToTemporary(E);
6511}
6512
6513template<typename Derived>
6514ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006515TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6516 ExprResult ControllingExpr =
6517 getDerived().TransformExpr(E->getControllingExpr());
6518 if (ControllingExpr.isInvalid())
6519 return ExprError();
6520
Chris Lattner686775d2011-07-20 06:58:45 +00006521 SmallVector<Expr *, 4> AssocExprs;
6522 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006523 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6524 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6525 if (TS) {
6526 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6527 if (!AssocType)
6528 return ExprError();
6529 AssocTypes.push_back(AssocType);
6530 } else {
6531 AssocTypes.push_back(0);
6532 }
6533
6534 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6535 if (AssocExpr.isInvalid())
6536 return ExprError();
6537 AssocExprs.push_back(AssocExpr.release());
6538 }
6539
6540 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6541 E->getDefaultLoc(),
6542 E->getRParenLoc(),
6543 ControllingExpr.release(),
Dmitri Gribenko80613222013-05-10 13:06:58 +00006544 AssocTypes,
6545 AssocExprs);
Peter Collingbournef111d932011-04-15 00:35:48 +00006546}
6547
6548template<typename Derived>
6549ExprResult
John McCall454feb92009-12-08 09:21:05 +00006550TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006551 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006552 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006553 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006554
Douglas Gregorb98b1992009-08-11 05:31:07 +00006555 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006556 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006557
John McCall9ae2f072010-08-23 23:25:46 +00006558 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006559 E->getRParen());
6560}
6561
Richard Smithefeeccf2012-10-21 03:28:35 +00006562/// \brief The operand of a unary address-of operator has special rules: it's
6563/// allowed to refer to a non-static member of a class even if there's no 'this'
6564/// object available.
6565template<typename Derived>
6566ExprResult
6567TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6568 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6569 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6570 else
6571 return getDerived().TransformExpr(E);
6572}
6573
Mike Stump1eb44332009-09-09 15:08:12 +00006574template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006575ExprResult
John McCall454feb92009-12-08 09:21:05 +00006576TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smith82b00012013-05-21 23:29:46 +00006577 ExprResult SubExpr;
6578 if (E->getOpcode() == UO_AddrOf)
6579 SubExpr = TransformAddressOfOperand(E->getSubExpr());
6580 else
6581 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006582 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006583 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006584
Douglas Gregorb98b1992009-08-11 05:31:07 +00006585 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006586 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006587
Douglas Gregorb98b1992009-08-11 05:31:07 +00006588 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6589 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006590 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006591}
Mike Stump1eb44332009-09-09 15:08:12 +00006592
Douglas Gregorb98b1992009-08-11 05:31:07 +00006593template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006594ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006595TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6596 // Transform the type.
6597 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6598 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006599 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006600
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006601 // Transform all of the components into components similar to what the
6602 // parser uses.
Chad Rosier4a9d7952012-08-08 18:46:20 +00006603 // FIXME: It would be slightly more efficient in the non-dependent case to
6604 // just map FieldDecls, rather than requiring the rebuilder to look for
6605 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006606 // template code that we don't care.
6607 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006608 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006609 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006610 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006611 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6612 const Node &ON = E->getComponent(I);
6613 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006614 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006615 Comp.LocStart = ON.getSourceRange().getBegin();
6616 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006617 switch (ON.getKind()) {
6618 case Node::Array: {
6619 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006620 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006621 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006622 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006623
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006624 ExprChanged = ExprChanged || Index.get() != FromIndex;
6625 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006626 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006627 break;
6628 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006629
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006630 case Node::Field:
6631 case Node::Identifier:
6632 Comp.isBrackets = false;
6633 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006634 if (!Comp.U.IdentInfo)
6635 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006636
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006637 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006638
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006639 case Node::Base:
6640 // Will be recomputed during the rebuild.
6641 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006642 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006643
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006644 Components.push_back(Comp);
6645 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006646
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006647 // If nothing changed, retain the existing expression.
6648 if (!getDerived().AlwaysRebuild() &&
6649 Type == E->getTypeSourceInfo() &&
6650 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006651 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006652
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006653 // Build a new offsetof expression.
6654 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6655 Components.data(), Components.size(),
6656 E->getRParenLoc());
6657}
6658
6659template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006660ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006661TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6662 assert(getDerived().AlreadyTransformed(E->getType()) &&
6663 "opaque value expression requires transformation");
6664 return SemaRef.Owned(E);
6665}
6666
6667template<typename Derived>
6668ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006669TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006670 // Rebuild the syntactic form. The original syntactic form has
6671 // opaque-value expressions in it, so strip those away and rebuild
6672 // the result. This is a really awful way of doing this, but the
6673 // better solution (rebuilding the semantic expressions and
6674 // rebinding OVEs as necessary) doesn't work; we'd need
6675 // TreeTransform to not strip away implicit conversions.
6676 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6677 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006678 if (result.isInvalid()) return ExprError();
6679
6680 // If that gives us a pseudo-object result back, the pseudo-object
6681 // expression must have been an lvalue-to-rvalue conversion which we
6682 // should reapply.
6683 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6684 result = SemaRef.checkPseudoObjectRValue(result.take());
6685
6686 return result;
6687}
6688
6689template<typename Derived>
6690ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006691TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6692 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006693 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006694 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006695
John McCalla93c9342009-12-07 02:54:59 +00006696 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006697 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006698 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006699
John McCall5ab75172009-11-04 07:28:41 +00006700 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006701 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006702
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006703 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6704 E->getKind(),
6705 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006706 }
Mike Stump1eb44332009-09-09 15:08:12 +00006707
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006708 // C++0x [expr.sizeof]p1:
6709 // The operand is either an expression, which is an unevaluated operand
6710 // [...]
Eli Friedman80bfa3d2012-09-26 04:34:21 +00006711 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6712 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00006713
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006714 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6715 if (SubExpr.isInvalid())
6716 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006717
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006718 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6719 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006720
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006721 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6722 E->getOperatorLoc(),
6723 E->getKind(),
6724 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006725}
Mike Stump1eb44332009-09-09 15:08:12 +00006726
Douglas Gregorb98b1992009-08-11 05:31:07 +00006727template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006728ExprResult
John McCall454feb92009-12-08 09:21:05 +00006729TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006730 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006731 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006732 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006733
John McCall60d7b3a2010-08-24 06:29:42 +00006734 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006735 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006736 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006737
6738
Douglas Gregorb98b1992009-08-11 05:31:07 +00006739 if (!getDerived().AlwaysRebuild() &&
6740 LHS.get() == E->getLHS() &&
6741 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006742 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006743
John McCall9ae2f072010-08-23 23:25:46 +00006744 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006745 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006746 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006747 E->getRBracketLoc());
6748}
Mike Stump1eb44332009-09-09 15:08:12 +00006749
6750template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006751ExprResult
John McCall454feb92009-12-08 09:21:05 +00006752TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006753 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006754 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006755 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006756 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006757
6758 // Transform arguments.
6759 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006760 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006761 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006762 &ArgChanged))
6763 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006764
Douglas Gregorb98b1992009-08-11 05:31:07 +00006765 if (!getDerived().AlwaysRebuild() &&
6766 Callee.get() == E->getCallee() &&
6767 !ArgChanged)
Dmitri Gribenko1ad23d62012-09-10 21:20:09 +00006768 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006769
Douglas Gregorb98b1992009-08-11 05:31:07 +00006770 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006771 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006772 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006773 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006774 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006775 E->getRParenLoc());
6776}
Mike Stump1eb44332009-09-09 15:08:12 +00006777
6778template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006779ExprResult
John McCall454feb92009-12-08 09:21:05 +00006780TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006781 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006782 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006783 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006784
Douglas Gregor40d96a62011-02-28 21:54:11 +00006785 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006786 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006787 QualifierLoc
6788 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006789
Douglas Gregor40d96a62011-02-28 21:54:11 +00006790 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006791 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006792 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006793 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006794
Eli Friedmanf595cc42009-12-04 06:40:45 +00006795 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006796 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6797 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006798 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006799 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006800
John McCall6bb80172010-03-30 21:47:33 +00006801 NamedDecl *FoundDecl = E->getFoundDecl();
6802 if (FoundDecl == E->getMemberDecl()) {
6803 FoundDecl = Member;
6804 } else {
6805 FoundDecl = cast_or_null<NamedDecl>(
6806 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6807 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006808 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006809 }
6810
Douglas Gregorb98b1992009-08-11 05:31:07 +00006811 if (!getDerived().AlwaysRebuild() &&
6812 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006813 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006814 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006815 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006816 !E->hasExplicitTemplateArgs()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006817
Anders Carlsson1f240322009-12-22 05:24:09 +00006818 // Mark it referenced in the new context regardless.
6819 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006820 SemaRef.MarkMemberReferenced(E);
6821
John McCall3fa5cae2010-10-26 07:05:15 +00006822 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006823 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006824
John McCalld5532b62009-11-23 01:53:49 +00006825 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006826 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006827 TransArgs.setLAngleLoc(E->getLAngleLoc());
6828 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006829 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6830 E->getNumTemplateArgs(),
6831 TransArgs))
6832 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006833 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006834
Douglas Gregorb98b1992009-08-11 05:31:07 +00006835 // FIXME: Bogus source location for the operator
6836 SourceLocation FakeOperatorLoc
6837 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6838
John McCallc2233c52010-01-15 08:34:02 +00006839 // FIXME: to do this check properly, we will need to preserve the
6840 // first-qualifier-in-scope here, just in case we had a dependent
6841 // base (and therefore couldn't do the check) and a
6842 // nested-name-qualifier (and therefore could do the lookup).
6843 NamedDecl *FirstQualifierInScope = 0;
6844
John McCall9ae2f072010-08-23 23:25:46 +00006845 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006846 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006847 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006848 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006849 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006850 Member,
John McCall6bb80172010-03-30 21:47:33 +00006851 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006852 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006853 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006854 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006855}
Mike Stump1eb44332009-09-09 15:08:12 +00006856
Douglas Gregorb98b1992009-08-11 05:31:07 +00006857template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006858ExprResult
John McCall454feb92009-12-08 09:21:05 +00006859TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006860 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006861 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006862 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006863
John McCall60d7b3a2010-08-24 06:29:42 +00006864 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006865 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006866 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006867
Douglas Gregorb98b1992009-08-11 05:31:07 +00006868 if (!getDerived().AlwaysRebuild() &&
6869 LHS.get() == E->getLHS() &&
6870 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006871 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006872
Lang Hamesbe9af122012-10-02 04:45:10 +00006873 Sema::FPContractStateRAII FPContractState(getSema());
6874 getSema().FPFeatures.fp_contract = E->isFPContractable();
6875
Douglas Gregorb98b1992009-08-11 05:31:07 +00006876 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006877 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006878}
6879
Mike Stump1eb44332009-09-09 15:08:12 +00006880template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006881ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006882TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006883 CompoundAssignOperator *E) {
6884 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006885}
Mike Stump1eb44332009-09-09 15:08:12 +00006886
Douglas Gregorb98b1992009-08-11 05:31:07 +00006887template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006888ExprResult TreeTransform<Derived>::
6889TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6890 // Just rebuild the common and RHS expressions and see whether we
6891 // get any changes.
6892
6893 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6894 if (commonExpr.isInvalid())
6895 return ExprError();
6896
6897 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6898 if (rhs.isInvalid())
6899 return ExprError();
6900
6901 if (!getDerived().AlwaysRebuild() &&
6902 commonExpr.get() == e->getCommon() &&
6903 rhs.get() == e->getFalseExpr())
6904 return SemaRef.Owned(e);
6905
6906 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6907 e->getQuestionLoc(),
6908 0,
6909 e->getColonLoc(),
6910 rhs.get());
6911}
6912
6913template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006914ExprResult
John McCall454feb92009-12-08 09:21:05 +00006915TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006916 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006917 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006918 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006919
John McCall60d7b3a2010-08-24 06:29:42 +00006920 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006921 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006922 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006923
John McCall60d7b3a2010-08-24 06:29:42 +00006924 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006925 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006926 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006927
Douglas Gregorb98b1992009-08-11 05:31:07 +00006928 if (!getDerived().AlwaysRebuild() &&
6929 Cond.get() == E->getCond() &&
6930 LHS.get() == E->getLHS() &&
6931 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006932 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006933
John McCall9ae2f072010-08-23 23:25:46 +00006934 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006935 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006936 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006937 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006938 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006939}
Mike Stump1eb44332009-09-09 15:08:12 +00006940
6941template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006942ExprResult
John McCall454feb92009-12-08 09:21:05 +00006943TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006944 // Implicit casts are eliminated during transformation, since they
6945 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006946 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006947}
Mike Stump1eb44332009-09-09 15:08:12 +00006948
Douglas Gregorb98b1992009-08-11 05:31:07 +00006949template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006950ExprResult
John McCall454feb92009-12-08 09:21:05 +00006951TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006952 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6953 if (!Type)
6954 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006955
John McCall60d7b3a2010-08-24 06:29:42 +00006956 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006957 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006958 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006959 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006960
Douglas Gregorb98b1992009-08-11 05:31:07 +00006961 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006962 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006963 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006964 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006965
John McCall9d125032010-01-15 18:39:57 +00006966 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006967 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006968 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006969 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006970}
Mike Stump1eb44332009-09-09 15:08:12 +00006971
Douglas Gregorb98b1992009-08-11 05:31:07 +00006972template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006973ExprResult
John McCall454feb92009-12-08 09:21:05 +00006974TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006975 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6976 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6977 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006978 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006979
John McCall60d7b3a2010-08-24 06:29:42 +00006980 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006981 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006982 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006983
Douglas Gregorb98b1992009-08-11 05:31:07 +00006984 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006985 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006986 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006987 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006988
John McCall1d7d8d62010-01-19 22:33:45 +00006989 // Note: the expression type doesn't necessarily match the
6990 // type-as-written, but that's okay, because it should always be
6991 // derivable from the initializer.
6992
John McCall42f56b52010-01-18 19:35:47 +00006993 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006994 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006995 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006996}
Mike Stump1eb44332009-09-09 15:08:12 +00006997
Douglas Gregorb98b1992009-08-11 05:31:07 +00006998template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006999ExprResult
John McCall454feb92009-12-08 09:21:05 +00007000TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007001 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007002 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007003 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007004
Douglas Gregorb98b1992009-08-11 05:31:07 +00007005 if (!getDerived().AlwaysRebuild() &&
7006 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00007007 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007008
Douglas Gregorb98b1992009-08-11 05:31:07 +00007009 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00007010 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00007011 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00007012 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007013 E->getAccessorLoc(),
7014 E->getAccessor());
7015}
Mike Stump1eb44332009-09-09 15:08:12 +00007016
Douglas Gregorb98b1992009-08-11 05:31:07 +00007017template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007018ExprResult
John McCall454feb92009-12-08 09:21:05 +00007019TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007020 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00007021
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007022 SmallVector<Expr*, 4> Inits;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007023 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007024 Inits, &InitChanged))
7025 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007026
Douglas Gregorb98b1992009-08-11 05:31:07 +00007027 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007028 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007029
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007030 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00007031 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007032}
Mike Stump1eb44332009-09-09 15:08:12 +00007033
Douglas Gregorb98b1992009-08-11 05:31:07 +00007034template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007035ExprResult
John McCall454feb92009-12-08 09:21:05 +00007036TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007037 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00007038
Douglas Gregor43959a92009-08-20 07:17:43 +00007039 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00007040 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007041 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007042 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007043
Douglas Gregor43959a92009-08-20 07:17:43 +00007044 // transform the designators.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007045 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregorb98b1992009-08-11 05:31:07 +00007046 bool ExprChanged = false;
7047 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
7048 DEnd = E->designators_end();
7049 D != DEnd; ++D) {
7050 if (D->isFieldDesignator()) {
7051 Desig.AddDesignator(Designator::getField(D->getFieldName(),
7052 D->getDotLoc(),
7053 D->getFieldLoc()));
7054 continue;
7055 }
Mike Stump1eb44332009-09-09 15:08:12 +00007056
Douglas Gregorb98b1992009-08-11 05:31:07 +00007057 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00007058 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007059 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007060 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007061
7062 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007063 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00007064
Douglas Gregorb98b1992009-08-11 05:31:07 +00007065 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
7066 ArrayExprs.push_back(Index.release());
7067 continue;
7068 }
Mike Stump1eb44332009-09-09 15:08:12 +00007069
Douglas Gregorb98b1992009-08-11 05:31:07 +00007070 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00007071 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00007072 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7073 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007074 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007075
John McCall60d7b3a2010-08-24 06:29:42 +00007076 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007077 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007078 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007079
7080 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007081 End.get(),
7082 D->getLBracketLoc(),
7083 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00007084
Douglas Gregorb98b1992009-08-11 05:31:07 +00007085 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7086 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00007087
Douglas Gregorb98b1992009-08-11 05:31:07 +00007088 ArrayExprs.push_back(Start.release());
7089 ArrayExprs.push_back(End.release());
7090 }
Mike Stump1eb44332009-09-09 15:08:12 +00007091
Douglas Gregorb98b1992009-08-11 05:31:07 +00007092 if (!getDerived().AlwaysRebuild() &&
7093 Init.get() == E->getInit() &&
7094 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007095 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007096
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007097 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007098 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007099 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007100}
Mike Stump1eb44332009-09-09 15:08:12 +00007101
Douglas Gregorb98b1992009-08-11 05:31:07 +00007102template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007103ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007104TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00007105 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00007106 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007107
Douglas Gregor5557b252009-10-28 00:29:27 +00007108 // FIXME: Will we ever have proper type location here? Will we actually
7109 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00007110 QualType T = getDerived().TransformType(E->getType());
7111 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007112 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007113
Douglas Gregorb98b1992009-08-11 05:31:07 +00007114 if (!getDerived().AlwaysRebuild() &&
7115 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00007116 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007117
Douglas Gregorb98b1992009-08-11 05:31:07 +00007118 return getDerived().RebuildImplicitValueInitExpr(T);
7119}
Mike Stump1eb44332009-09-09 15:08:12 +00007120
Douglas Gregorb98b1992009-08-11 05:31:07 +00007121template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007122ExprResult
John McCall454feb92009-12-08 09:21:05 +00007123TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00007124 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7125 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007126 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007127
John McCall60d7b3a2010-08-24 06:29:42 +00007128 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007129 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007130 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007131
Douglas Gregorb98b1992009-08-11 05:31:07 +00007132 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00007133 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007134 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007135 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007136
John McCall9ae2f072010-08-23 23:25:46 +00007137 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00007138 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007139}
7140
7141template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007142ExprResult
John McCall454feb92009-12-08 09:21:05 +00007143TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007144 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007145 SmallVector<Expr*, 4> Inits;
Douglas Gregoraa165f82011-01-03 19:04:46 +00007146 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7147 &ArgumentChanged))
7148 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007149
Douglas Gregorb98b1992009-08-11 05:31:07 +00007150 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007151 Inits,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007152 E->getRParenLoc());
7153}
Mike Stump1eb44332009-09-09 15:08:12 +00007154
Douglas Gregorb98b1992009-08-11 05:31:07 +00007155/// \brief Transform an address-of-label expression.
7156///
7157/// By default, the transformation of an address-of-label expression always
7158/// rebuilds the expression, so that the label identifier can be resolved to
7159/// the corresponding label statement by semantic analysis.
7160template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007161ExprResult
John McCall454feb92009-12-08 09:21:05 +00007162TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00007163 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7164 E->getLabel());
7165 if (!LD)
7166 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007167
Douglas Gregorb98b1992009-08-11 05:31:07 +00007168 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00007169 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007170}
Mike Stump1eb44332009-09-09 15:08:12 +00007171
7172template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00007173ExprResult
John McCall454feb92009-12-08 09:21:05 +00007174TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00007175 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00007176 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00007177 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00007178 if (SubStmt.isInvalid()) {
7179 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00007180 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00007181 }
Mike Stump1eb44332009-09-09 15:08:12 +00007182
Douglas Gregorb98b1992009-08-11 05:31:07 +00007183 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00007184 SubStmt.get() == E->getSubStmt()) {
7185 // Calling this an 'error' is unintuitive, but it does the right thing.
7186 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00007187 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00007188 }
Mike Stump1eb44332009-09-09 15:08:12 +00007189
7190 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007191 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007192 E->getRParenLoc());
7193}
Mike Stump1eb44332009-09-09 15:08:12 +00007194
Douglas Gregorb98b1992009-08-11 05:31:07 +00007195template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007196ExprResult
John McCall454feb92009-12-08 09:21:05 +00007197TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007198 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007199 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007200 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007201
John McCall60d7b3a2010-08-24 06:29:42 +00007202 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007203 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007204 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007205
John McCall60d7b3a2010-08-24 06:29:42 +00007206 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007207 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007208 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007209
Douglas Gregorb98b1992009-08-11 05:31:07 +00007210 if (!getDerived().AlwaysRebuild() &&
7211 Cond.get() == E->getCond() &&
7212 LHS.get() == E->getLHS() &&
7213 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00007214 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007215
Douglas Gregorb98b1992009-08-11 05:31:07 +00007216 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007217 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007218 E->getRParenLoc());
7219}
Mike Stump1eb44332009-09-09 15:08:12 +00007220
Douglas Gregorb98b1992009-08-11 05:31:07 +00007221template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007222ExprResult
John McCall454feb92009-12-08 09:21:05 +00007223TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007224 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007225}
7226
7227template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007228ExprResult
John McCall454feb92009-12-08 09:21:05 +00007229TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00007230 switch (E->getOperator()) {
7231 case OO_New:
7232 case OO_Delete:
7233 case OO_Array_New:
7234 case OO_Array_Delete:
7235 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier4a9d7952012-08-08 18:46:20 +00007236
Douglas Gregor668d6d92009-12-13 20:44:55 +00007237 case OO_Call: {
7238 // This is a call to an object's operator().
7239 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7240
7241 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00007242 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00007243 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007244 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00007245
7246 // FIXME: Poor location information
7247 SourceLocation FakeLParenLoc
7248 = SemaRef.PP.getLocForEndOfToken(
7249 static_cast<Expr *>(Object.get())->getLocEnd());
7250
7251 // Transform the call arguments.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007252 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007253 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007254 Args))
7255 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00007256
John McCall9ae2f072010-08-23 23:25:46 +00007257 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007258 Args,
Douglas Gregor668d6d92009-12-13 20:44:55 +00007259 E->getLocEnd());
7260 }
7261
7262#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7263 case OO_##Name:
7264#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7265#include "clang/Basic/OperatorKinds.def"
7266 case OO_Subscript:
7267 // Handled below.
7268 break;
7269
7270 case OO_Conditional:
7271 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00007272
7273 case OO_None:
7274 case NUM_OVERLOADED_OPERATORS:
7275 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00007276 }
7277
John McCall60d7b3a2010-08-24 06:29:42 +00007278 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007279 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007280 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007281
Richard Smithefeeccf2012-10-21 03:28:35 +00007282 ExprResult First;
7283 if (E->getOperator() == OO_Amp)
7284 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7285 else
7286 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007287 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007288 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007289
John McCall60d7b3a2010-08-24 06:29:42 +00007290 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00007291 if (E->getNumArgs() == 2) {
7292 Second = getDerived().TransformExpr(E->getArg(1));
7293 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007294 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007295 }
Mike Stump1eb44332009-09-09 15:08:12 +00007296
Douglas Gregorb98b1992009-08-11 05:31:07 +00007297 if (!getDerived().AlwaysRebuild() &&
7298 Callee.get() == E->getCallee() &&
7299 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00007300 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00007301 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007302
Lang Hamesbe9af122012-10-02 04:45:10 +00007303 Sema::FPContractStateRAII FPContractState(getSema());
7304 getSema().FPFeatures.fp_contract = E->isFPContractable();
7305
Douglas Gregorb98b1992009-08-11 05:31:07 +00007306 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7307 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007308 Callee.get(),
7309 First.get(),
7310 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007311}
Mike Stump1eb44332009-09-09 15:08:12 +00007312
Douglas Gregorb98b1992009-08-11 05:31:07 +00007313template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007314ExprResult
John McCall454feb92009-12-08 09:21:05 +00007315TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7316 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007317}
Mike Stump1eb44332009-09-09 15:08:12 +00007318
Douglas Gregorb98b1992009-08-11 05:31:07 +00007319template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007320ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00007321TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7322 // Transform the callee.
7323 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7324 if (Callee.isInvalid())
7325 return ExprError();
7326
7327 // Transform exec config.
7328 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7329 if (EC.isInvalid())
7330 return ExprError();
7331
7332 // Transform arguments.
7333 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007334 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007335 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007336 &ArgChanged))
7337 return ExprError();
7338
7339 if (!getDerived().AlwaysRebuild() &&
7340 Callee.get() == E->getCallee() &&
7341 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00007342 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00007343
7344 // FIXME: Wrong source location information for the '('.
7345 SourceLocation FakeLParenLoc
7346 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7347 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007348 Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007349 E->getRParenLoc(), EC.get());
7350}
7351
7352template<typename Derived>
7353ExprResult
John McCall454feb92009-12-08 09:21:05 +00007354TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007355 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7356 if (!Type)
7357 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007358
John McCall60d7b3a2010-08-24 06:29:42 +00007359 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007360 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007361 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007362 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007363
Douglas Gregorb98b1992009-08-11 05:31:07 +00007364 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007365 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007366 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007367 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007368 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00007369 E->getStmtClass(),
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007370 E->getAngleBrackets().getBegin(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007371 Type,
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007372 E->getAngleBrackets().getEnd(),
7373 // FIXME. this should be '(' location
7374 E->getAngleBrackets().getEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00007375 SubExpr.get(),
Abramo Bagnara6cf7d7d2012-10-15 21:08:58 +00007376 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007377}
Mike Stump1eb44332009-09-09 15:08:12 +00007378
Douglas Gregorb98b1992009-08-11 05:31:07 +00007379template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007380ExprResult
John McCall454feb92009-12-08 09:21:05 +00007381TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7382 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007383}
Mike Stump1eb44332009-09-09 15:08:12 +00007384
7385template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007386ExprResult
John McCall454feb92009-12-08 09:21:05 +00007387TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7388 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007389}
7390
Douglas Gregorb98b1992009-08-11 05:31:07 +00007391template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007392ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007393TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007394 CXXReinterpretCastExpr *E) {
7395 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007396}
Mike Stump1eb44332009-09-09 15:08:12 +00007397
Douglas Gregorb98b1992009-08-11 05:31:07 +00007398template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007399ExprResult
John McCall454feb92009-12-08 09:21:05 +00007400TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7401 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007402}
Mike Stump1eb44332009-09-09 15:08:12 +00007403
Douglas Gregorb98b1992009-08-11 05:31:07 +00007404template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007405ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007406TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007407 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007408 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7409 if (!Type)
7410 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007411
John McCall60d7b3a2010-08-24 06:29:42 +00007412 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007413 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007414 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007415 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007416
Douglas Gregorb98b1992009-08-11 05:31:07 +00007417 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007418 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007419 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007420 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007421
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007422 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedmancdd4b782013-08-15 22:02:56 +00007423 E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007424 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007425 E->getRParenLoc());
7426}
Mike Stump1eb44332009-09-09 15:08:12 +00007427
Douglas Gregorb98b1992009-08-11 05:31:07 +00007428template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007429ExprResult
John McCall454feb92009-12-08 09:21:05 +00007430TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007431 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007432 TypeSourceInfo *TInfo
7433 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7434 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007435 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007436
Douglas Gregorb98b1992009-08-11 05:31:07 +00007437 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007438 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007439 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007440
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007441 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7442 E->getLocStart(),
7443 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007444 E->getLocEnd());
7445 }
Mike Stump1eb44332009-09-09 15:08:12 +00007446
Eli Friedmanef331b72012-01-20 01:26:23 +00007447 // We don't know whether the subexpression is potentially evaluated until
7448 // after we perform semantic analysis. We speculatively assume it is
7449 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007450 // potentially evaluated.
Eli Friedman80bfa3d2012-09-26 04:34:21 +00007451 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7452 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00007453
John McCall60d7b3a2010-08-24 06:29:42 +00007454 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007455 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007456 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007457
Douglas Gregorb98b1992009-08-11 05:31:07 +00007458 if (!getDerived().AlwaysRebuild() &&
7459 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007460 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007461
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007462 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7463 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007464 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007465 E->getLocEnd());
7466}
7467
7468template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007469ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007470TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7471 if (E->isTypeOperand()) {
7472 TypeSourceInfo *TInfo
7473 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7474 if (!TInfo)
7475 return ExprError();
7476
7477 if (!getDerived().AlwaysRebuild() &&
7478 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007479 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007480
Douglas Gregor3c52a212011-03-06 17:40:41 +00007481 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007482 E->getLocStart(),
7483 TInfo,
7484 E->getLocEnd());
7485 }
7486
Francois Pichet01b7c302010-09-08 12:20:18 +00007487 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7488
7489 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7490 if (SubExpr.isInvalid())
7491 return ExprError();
7492
7493 if (!getDerived().AlwaysRebuild() &&
7494 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007495 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007496
7497 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7498 E->getLocStart(),
7499 SubExpr.get(),
7500 E->getLocEnd());
7501}
7502
7503template<typename Derived>
7504ExprResult
John McCall454feb92009-12-08 09:21:05 +00007505TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007506 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007507}
Mike Stump1eb44332009-09-09 15:08:12 +00007508
Douglas Gregorb98b1992009-08-11 05:31:07 +00007509template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007510ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007511TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007512 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007513 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007514}
Mike Stump1eb44332009-09-09 15:08:12 +00007515
Douglas Gregorb98b1992009-08-11 05:31:07 +00007516template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007517ExprResult
John McCall454feb92009-12-08 09:21:05 +00007518TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithcafeb942013-06-07 02:33:37 +00007519 QualType T = getSema().getCurrentThisType();
Mike Stump1eb44332009-09-09 15:08:12 +00007520
Douglas Gregorec79d872012-02-24 17:41:38 +00007521 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7522 // Make sure that we capture 'this'.
7523 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007524 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007525 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007526
Douglas Gregor828a1972010-01-07 23:12:05 +00007527 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007528}
Mike Stump1eb44332009-09-09 15:08:12 +00007529
Douglas Gregorb98b1992009-08-11 05:31:07 +00007530template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007531ExprResult
John McCall454feb92009-12-08 09:21:05 +00007532TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007533 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007534 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007535 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007536
Douglas Gregorb98b1992009-08-11 05:31:07 +00007537 if (!getDerived().AlwaysRebuild() &&
7538 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007539 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007540
Douglas Gregorbca01b42011-07-06 22:04:06 +00007541 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7542 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007543}
Mike Stump1eb44332009-09-09 15:08:12 +00007544
Douglas Gregorb98b1992009-08-11 05:31:07 +00007545template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007546ExprResult
John McCall454feb92009-12-08 09:21:05 +00007547TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007548 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007549 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7550 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007551 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007552 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007553
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007554 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007555 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007556 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007557
Douglas Gregor036aed12009-12-23 23:03:06 +00007558 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007559}
Mike Stump1eb44332009-09-09 15:08:12 +00007560
Douglas Gregorb98b1992009-08-11 05:31:07 +00007561template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007562ExprResult
Richard Smithc3bf52c2013-04-20 22:23:05 +00007563TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
7564 FieldDecl *Field
7565 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
7566 E->getField()));
7567 if (!Field)
7568 return ExprError();
7569
7570 if (!getDerived().AlwaysRebuild() && Field == E->getField())
7571 return SemaRef.Owned(E);
7572
7573 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
7574}
7575
7576template<typename Derived>
7577ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007578TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7579 CXXScalarValueInitExpr *E) {
7580 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7581 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007582 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007583
Douglas Gregorb98b1992009-08-11 05:31:07 +00007584 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007585 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007586 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007587
Chad Rosier4a9d7952012-08-08 18:46:20 +00007588 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregorab6677e2010-09-08 00:15:04 +00007589 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007590 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007591}
Mike Stump1eb44332009-09-09 15:08:12 +00007592
Douglas Gregorb98b1992009-08-11 05:31:07 +00007593template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007594ExprResult
John McCall454feb92009-12-08 09:21:05 +00007595TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007596 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007597 TypeSourceInfo *AllocTypeInfo
7598 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7599 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007600 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007601
Douglas Gregorb98b1992009-08-11 05:31:07 +00007602 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007603 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007604 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007605 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007606
Douglas Gregorb98b1992009-08-11 05:31:07 +00007607 // Transform the placement arguments (if any).
7608 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007609 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007610 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregoraa165f82011-01-03 19:04:46 +00007611 E->getNumPlacementArgs(), true,
7612 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007613 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007614
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007615 // Transform the initializer (if any).
7616 Expr *OldInit = E->getInitializer();
7617 ExprResult NewInit;
7618 if (OldInit)
7619 NewInit = getDerived().TransformExpr(OldInit);
7620 if (NewInit.isInvalid())
7621 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007622
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007623 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007624 FunctionDecl *OperatorNew = 0;
7625 if (E->getOperatorNew()) {
7626 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007627 getDerived().TransformDecl(E->getLocStart(),
7628 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007629 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007630 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007631 }
7632
7633 FunctionDecl *OperatorDelete = 0;
7634 if (E->getOperatorDelete()) {
7635 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007636 getDerived().TransformDecl(E->getLocStart(),
7637 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007638 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007639 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007640 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007641
Douglas Gregorb98b1992009-08-11 05:31:07 +00007642 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007643 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007644 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007645 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007646 OperatorNew == E->getOperatorNew() &&
7647 OperatorDelete == E->getOperatorDelete() &&
7648 !ArgumentChanged) {
7649 // Mark any declarations we need as referenced.
7650 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007651 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007652 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007653 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007654 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007655
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007656 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007657 QualType ElementType
7658 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7659 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7660 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7661 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007662 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007663 }
7664 }
7665 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007666
John McCall3fa5cae2010-10-26 07:05:15 +00007667 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007668 }
Mike Stump1eb44332009-09-09 15:08:12 +00007669
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007670 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007671 if (!ArraySize.get()) {
7672 // If no array size was specified, but the new expression was
7673 // instantiated with an array type (e.g., "new T" where T is
7674 // instantiated with "int[4]"), extract the outer bound from the
7675 // array type as our array size. We do this with constant and
7676 // dependently-sized array types.
7677 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7678 if (!ArrayT) {
7679 // Do nothing
7680 } else if (const ConstantArrayType *ConsArrayT
7681 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007682 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007683 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier4a9d7952012-08-08 18:46:20 +00007684 ConsArrayT->getSize(),
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007685 SemaRef.Context.getSizeType(),
7686 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007687 AllocType = ConsArrayT->getElementType();
7688 } else if (const DependentSizedArrayType *DepArrayT
7689 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7690 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007691 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007692 AllocType = DepArrayT->getElementType();
7693 }
7694 }
7695 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007696
Douglas Gregorb98b1992009-08-11 05:31:07 +00007697 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7698 E->isGlobalNew(),
7699 /*FIXME:*/E->getLocStart(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007700 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007701 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007702 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007703 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007704 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007705 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007706 E->getDirectInitRange(),
7707 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007708}
Mike Stump1eb44332009-09-09 15:08:12 +00007709
Douglas Gregorb98b1992009-08-11 05:31:07 +00007710template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007711ExprResult
John McCall454feb92009-12-08 09:21:05 +00007712TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007713 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007714 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007715 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007716
Douglas Gregor1af74512010-02-26 00:38:10 +00007717 // Transform the delete operator, if known.
7718 FunctionDecl *OperatorDelete = 0;
7719 if (E->getOperatorDelete()) {
7720 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007721 getDerived().TransformDecl(E->getLocStart(),
7722 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007723 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007724 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007725 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007726
Douglas Gregorb98b1992009-08-11 05:31:07 +00007727 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007728 Operand.get() == E->getArgument() &&
7729 OperatorDelete == E->getOperatorDelete()) {
7730 // Mark any declarations we need as referenced.
7731 // FIXME: instantiation-specific.
7732 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007733 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007734
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007735 if (!E->getArgument()->isTypeDependent()) {
7736 QualType Destroyed = SemaRef.Context.getBaseElementType(
7737 E->getDestroyedType());
7738 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7739 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007740 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedman5f2987c2012-02-02 03:46:19 +00007741 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007742 }
7743 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007744
John McCall3fa5cae2010-10-26 07:05:15 +00007745 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007746 }
Mike Stump1eb44332009-09-09 15:08:12 +00007747
Douglas Gregorb98b1992009-08-11 05:31:07 +00007748 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7749 E->isGlobalDelete(),
7750 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007751 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007752}
Mike Stump1eb44332009-09-09 15:08:12 +00007753
Douglas Gregorb98b1992009-08-11 05:31:07 +00007754template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007755ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007756TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007757 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007758 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007759 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007760 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007761
John McCallb3d87482010-08-24 05:47:05 +00007762 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007763 bool MayBePseudoDestructor = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007764 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007765 E->getOperatorLoc(),
7766 E->isArrow()? tok::arrow : tok::period,
7767 ObjectTypePtr,
7768 MayBePseudoDestructor);
7769 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007770 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007771
John McCallb3d87482010-08-24 05:47:05 +00007772 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007773 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7774 if (QualifierLoc) {
7775 QualifierLoc
7776 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7777 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007778 return ExprError();
7779 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007780 CXXScopeSpec SS;
7781 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007782
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007783 PseudoDestructorTypeStorage Destroyed;
7784 if (E->getDestroyedTypeInfo()) {
7785 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007786 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007787 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007788 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007789 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007790 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007791 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007792 // We aren't likely to be able to resolve the identifier down to a type
7793 // now anyway, so just retain the identifier.
7794 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7795 E->getDestroyedTypeLoc());
7796 } else {
7797 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007798 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007799 *E->getDestroyedTypeIdentifier(),
7800 E->getDestroyedTypeLoc(),
7801 /*Scope=*/0,
7802 SS, ObjectTypePtr,
7803 false);
7804 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007805 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007806
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007807 Destroyed
7808 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7809 E->getDestroyedTypeLoc());
7810 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007811
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007812 TypeSourceInfo *ScopeTypeInfo = 0;
7813 if (E->getScopeTypeInfo()) {
Douglas Gregor303b96f2013-03-08 21:25:01 +00007814 CXXScopeSpec EmptySS;
7815 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
7816 E->getScopeTypeInfo(), ObjectType, 0, EmptySS);
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007817 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007818 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007819 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007820
John McCall9ae2f072010-08-23 23:25:46 +00007821 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007822 E->getOperatorLoc(),
7823 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007824 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007825 ScopeTypeInfo,
7826 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007827 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007828 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007829}
Mike Stump1eb44332009-09-09 15:08:12 +00007830
Douglas Gregora71d8192009-09-04 17:36:40 +00007831template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007832ExprResult
John McCallba135432009-11-21 08:51:07 +00007833TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007834 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007835 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7836 Sema::LookupOrdinaryName);
7837
7838 // Transform all the decls.
7839 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7840 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007841 NamedDecl *InstD = static_cast<NamedDecl*>(
7842 getDerived().TransformDecl(Old->getNameLoc(),
7843 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007844 if (!InstD) {
7845 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7846 // This can happen because of dependent hiding.
7847 if (isa<UsingShadowDecl>(*I))
7848 continue;
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007849 else {
7850 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00007851 return ExprError();
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007852 }
John McCall9f54ad42009-12-10 09:41:52 +00007853 }
John McCallf7a1a742009-11-24 19:00:30 +00007854
7855 // Expand using declarations.
7856 if (isa<UsingDecl>(InstD)) {
7857 UsingDecl *UD = cast<UsingDecl>(InstD);
7858 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7859 E = UD->shadow_end(); I != E; ++I)
7860 R.addDecl(*I);
7861 continue;
7862 }
7863
7864 R.addDecl(InstD);
7865 }
7866
7867 // Resolve a kind, but don't do any further analysis. If it's
7868 // ambiguous, the callee needs to deal with it.
7869 R.resolveKind();
7870
7871 // Rebuild the nested-name qualifier, if present.
7872 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007873 if (Old->getQualifierLoc()) {
7874 NestedNameSpecifierLoc QualifierLoc
7875 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7876 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007877 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007878
Douglas Gregor4c9be892011-02-28 20:01:57 +00007879 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007880 }
7881
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007882 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007883 CXXRecordDecl *NamingClass
7884 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7885 Old->getNameLoc(),
7886 Old->getNamingClass()));
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007887 if (!NamingClass) {
7888 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00007889 return ExprError();
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007890 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007891
Douglas Gregor66c45152010-04-27 16:10:10 +00007892 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007893 }
7894
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007895 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7896
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007897 // If we have neither explicit template arguments, nor the template keyword,
7898 // it's a normal declaration name.
7899 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007900 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7901
7902 // If we have template arguments, rebuild them, then rebuild the
7903 // templateid expression.
7904 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola02e221b2012-08-28 04:13:54 +00007905 if (Old->hasExplicitTemplateArgs() &&
7906 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregorfcc12532010-12-20 17:31:10 +00007907 Old->getNumTemplateArgs(),
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007908 TransArgs)) {
7909 R.clear();
Douglas Gregorfcc12532010-12-20 17:31:10 +00007910 return ExprError();
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007911 }
John McCallf7a1a742009-11-24 19:00:30 +00007912
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007913 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007914 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007915}
Mike Stump1eb44332009-09-09 15:08:12 +00007916
Douglas Gregorb98b1992009-08-11 05:31:07 +00007917template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007918ExprResult
John McCall454feb92009-12-08 09:21:05 +00007919TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007920 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7921 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007922 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007923
Douglas Gregorb98b1992009-08-11 05:31:07 +00007924 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007925 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007926 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007927
Mike Stump1eb44332009-09-09 15:08:12 +00007928 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007929 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007930 T,
7931 E->getLocEnd());
7932}
Mike Stump1eb44332009-09-09 15:08:12 +00007933
Douglas Gregorb98b1992009-08-11 05:31:07 +00007934template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007935ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007936TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7937 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7938 if (!LhsT)
7939 return ExprError();
7940
7941 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7942 if (!RhsT)
7943 return ExprError();
7944
7945 if (!getDerived().AlwaysRebuild() &&
7946 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7947 return SemaRef.Owned(E);
7948
7949 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7950 E->getLocStart(),
7951 LhsT, RhsT,
7952 E->getLocEnd());
7953}
7954
7955template<typename Derived>
7956ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007957TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7958 bool ArgChanged = false;
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00007959 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007960 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7961 TypeSourceInfo *From = E->getArg(I);
7962 TypeLoc FromTL = From->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00007963 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007964 TypeLocBuilder TLB;
7965 TLB.reserve(FromTL.getFullDataSize());
7966 QualType To = getDerived().TransformType(TLB, FromTL);
7967 if (To.isNull())
7968 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007969
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007970 if (To == From->getType())
7971 Args.push_back(From);
7972 else {
7973 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7974 ArgChanged = true;
7975 }
7976 continue;
7977 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007978
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007979 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007980
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007981 // We have a pack expansion. Instantiate it.
David Blaikie39e6ab42013-02-18 22:06:02 +00007982 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007983 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7984 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7985 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007986
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007987 // Determine whether the set of unexpanded parameter packs can and should
7988 // be expanded.
7989 bool Expand = true;
7990 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00007991 Optional<unsigned> OrigNumExpansions =
7992 ExpansionTL.getTypePtr()->getNumExpansions();
7993 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007994 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7995 PatternTL.getSourceRange(),
7996 Unexpanded,
7997 Expand, RetainExpansion,
7998 NumExpansions))
7999 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008000
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008001 if (!Expand) {
8002 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00008003 // transformation on the pack expansion, producing another pack
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008004 // expansion.
8005 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008006
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008007 TypeLocBuilder TLB;
8008 TLB.reserve(From->getTypeLoc().getFullDataSize());
8009
8010 QualType To = getDerived().TransformType(TLB, PatternTL);
8011 if (To.isNull())
8012 return ExprError();
8013
Chad Rosier4a9d7952012-08-08 18:46:20 +00008014 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008015 PatternTL.getSourceRange(),
8016 ExpansionTL.getEllipsisLoc(),
8017 NumExpansions);
8018 if (To.isNull())
8019 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008020
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008021 PackExpansionTypeLoc ToExpansionTL
8022 = TLB.push<PackExpansionTypeLoc>(To);
8023 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8024 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8025 continue;
8026 }
8027
8028 // Expand the pack expansion by substituting for each argument in the
8029 // pack(s).
8030 for (unsigned I = 0; I != *NumExpansions; ++I) {
8031 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
8032 TypeLocBuilder TLB;
8033 TLB.reserve(PatternTL.getFullDataSize());
8034 QualType To = getDerived().TransformType(TLB, PatternTL);
8035 if (To.isNull())
8036 return ExprError();
8037
Eli Friedman20cfeca2013-07-19 21:49:32 +00008038 if (To->containsUnexpandedParameterPack()) {
8039 To = getDerived().RebuildPackExpansionType(To,
8040 PatternTL.getSourceRange(),
8041 ExpansionTL.getEllipsisLoc(),
8042 NumExpansions);
8043 if (To.isNull())
8044 return ExprError();
8045
8046 PackExpansionTypeLoc ToExpansionTL
8047 = TLB.push<PackExpansionTypeLoc>(To);
8048 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8049 }
8050
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008051 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8052 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008053
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008054 if (!RetainExpansion)
8055 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008056
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008057 // If we're supposed to retain a pack expansion, do so by temporarily
8058 // forgetting the partially-substituted parameter pack.
8059 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
8060
8061 TypeLocBuilder TLB;
8062 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008063
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008064 QualType To = getDerived().TransformType(TLB, PatternTL);
8065 if (To.isNull())
8066 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008067
8068 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008069 PatternTL.getSourceRange(),
8070 ExpansionTL.getEllipsisLoc(),
8071 NumExpansions);
8072 if (To.isNull())
8073 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008074
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008075 PackExpansionTypeLoc ToExpansionTL
8076 = TLB.push<PackExpansionTypeLoc>(To);
8077 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8078 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8079 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008080
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008081 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8082 return SemaRef.Owned(E);
8083
8084 return getDerived().RebuildTypeTrait(E->getTrait(),
8085 E->getLocStart(),
8086 Args,
8087 E->getLocEnd());
8088}
8089
8090template<typename Derived>
8091ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00008092TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8093 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
8094 if (!T)
8095 return ExprError();
8096
8097 if (!getDerived().AlwaysRebuild() &&
8098 T == E->getQueriedTypeSourceInfo())
8099 return SemaRef.Owned(E);
8100
8101 ExprResult SubExpr;
8102 {
8103 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8104 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8105 if (SubExpr.isInvalid())
8106 return ExprError();
8107
8108 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
8109 return SemaRef.Owned(E);
8110 }
8111
8112 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8113 E->getLocStart(),
8114 T,
8115 SubExpr.get(),
8116 E->getLocEnd());
8117}
8118
8119template<typename Derived>
8120ExprResult
John Wiegley55262202011-04-25 06:54:41 +00008121TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8122 ExprResult SubExpr;
8123 {
8124 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8125 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8126 if (SubExpr.isInvalid())
8127 return ExprError();
8128
8129 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
8130 return SemaRef.Owned(E);
8131 }
8132
8133 return getDerived().RebuildExpressionTrait(
8134 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8135}
8136
8137template<typename Derived>
8138ExprResult
John McCall865d4472009-11-19 22:55:06 +00008139TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008140 DependentScopeDeclRefExpr *E) {
Richard Smithefeeccf2012-10-21 03:28:35 +00008141 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
8142}
8143
8144template<typename Derived>
8145ExprResult
8146TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8147 DependentScopeDeclRefExpr *E,
8148 bool IsAddressOfOperand) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008149 NestedNameSpecifierLoc QualifierLoc
8150 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8151 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008152 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008153 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00008154
John McCall43fed0d2010-11-12 08:19:04 +00008155 // TODO: If this is a conversion-function-id, verify that the
8156 // destination type name (if present) resolves the same way after
8157 // instantiation as it did in the local scope.
8158
Abramo Bagnara25777432010-08-11 22:01:17 +00008159 DeclarationNameInfo NameInfo
8160 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8161 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008162 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008163
John McCallf7a1a742009-11-24 19:00:30 +00008164 if (!E->hasExplicitTemplateArgs()) {
8165 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008166 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008167 // Note: it is sufficient to compare the Name component of NameInfo:
8168 // if name has not changed, DNLoc has not changed either.
8169 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00008170 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008171
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008172 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008173 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00008174 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00008175 /*TemplateArgs*/ 0,
8176 IsAddressOfOperand);
Douglas Gregorf17bb742009-10-22 17:20:55 +00008177 }
John McCalld5532b62009-11-23 01:53:49 +00008178
8179 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008180 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8181 E->getNumTemplateArgs(),
8182 TransArgs))
8183 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00008184
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008185 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008186 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00008187 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00008188 &TransArgs,
8189 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008190}
8191
8192template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008193ExprResult
John McCall454feb92009-12-08 09:21:05 +00008194TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithc83c2302012-12-19 01:39:02 +00008195 // CXXConstructExprs other than for list-initialization and
8196 // CXXTemporaryObjectExpr are always implicit, so when we have
8197 // a 1-argument construction we just transform that argument.
Richard Smith73ed67c2012-11-26 08:32:48 +00008198 if ((E->getNumArgs() == 1 ||
8199 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithc83c2302012-12-19 01:39:02 +00008200 (!getDerived().DropCallArgument(E->getArg(0))) &&
8201 !E->isListInitialization())
Douglas Gregor321725d2010-02-03 03:01:57 +00008202 return getDerived().TransformExpr(E->getArg(0));
8203
Douglas Gregorb98b1992009-08-11 05:31:07 +00008204 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8205
8206 QualType T = getDerived().TransformType(E->getType());
8207 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00008208 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00008209
8210 CXXConstructorDecl *Constructor
8211 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008212 getDerived().TransformDecl(E->getLocStart(),
8213 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008214 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00008215 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008216
Douglas Gregorb98b1992009-08-11 05:31:07 +00008217 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008218 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008219 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008220 &ArgumentChanged))
8221 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008222
Douglas Gregorb98b1992009-08-11 05:31:07 +00008223 if (!getDerived().AlwaysRebuild() &&
8224 T == E->getType() &&
8225 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00008226 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00008227 // Mark the constructor as referenced.
8228 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00008229 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00008230 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00008231 }
Mike Stump1eb44332009-09-09 15:08:12 +00008232
Douglas Gregor4411d2e2009-12-14 16:27:04 +00008233 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8234 Constructor, E->isElidable(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008235 Args,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00008236 E->hadMultipleCandidates(),
Richard Smithc83c2302012-12-19 01:39:02 +00008237 E->isListInitialization(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00008238 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00008239 E->getConstructionKind(),
Enea Zaffanella1245a542013-09-07 05:49:53 +00008240 E->getParenOrBraceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008241}
Mike Stump1eb44332009-09-09 15:08:12 +00008242
Douglas Gregorb98b1992009-08-11 05:31:07 +00008243/// \brief Transform a C++ temporary-binding expression.
8244///
Douglas Gregor51326552009-12-24 18:51:59 +00008245/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8246/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00008247template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008248ExprResult
John McCall454feb92009-12-08 09:21:05 +00008249TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00008250 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008251}
Mike Stump1eb44332009-09-09 15:08:12 +00008252
John McCall4765fa02010-12-06 08:20:24 +00008253/// \brief Transform a C++ expression that contains cleanups that should
8254/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00008255///
John McCall4765fa02010-12-06 08:20:24 +00008256/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00008257/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00008258template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008259ExprResult
John McCall4765fa02010-12-06 08:20:24 +00008260TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00008261 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008262}
Mike Stump1eb44332009-09-09 15:08:12 +00008263
Douglas Gregorb98b1992009-08-11 05:31:07 +00008264template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008265ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008266TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00008267 CXXTemporaryObjectExpr *E) {
8268 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8269 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008270 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008271
Douglas Gregorb98b1992009-08-11 05:31:07 +00008272 CXXConstructorDecl *Constructor
8273 = cast_or_null<CXXConstructorDecl>(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008274 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008275 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008276 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00008277 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008278
Douglas Gregorb98b1992009-08-11 05:31:07 +00008279 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008280 SmallVector<Expr*, 8> Args;
Douglas Gregorb98b1992009-08-11 05:31:07 +00008281 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008282 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008283 &ArgumentChanged))
8284 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008285
Douglas Gregorb98b1992009-08-11 05:31:07 +00008286 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008287 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008288 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00008289 !ArgumentChanged) {
8290 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00008291 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00008292 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00008293 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008294
Richard Smithc83c2302012-12-19 01:39:02 +00008295 // FIXME: Pass in E->isListInitialization().
Douglas Gregorab6677e2010-09-08 00:15:04 +00008296 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8297 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008298 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008299 E->getLocEnd());
8300}
Mike Stump1eb44332009-09-09 15:08:12 +00008301
Douglas Gregorb98b1992009-08-11 05:31:07 +00008302template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008303ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00008304TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Faisal Valifad9e132013-09-26 19:54:12 +00008305
Faisal Vali618c2852013-10-03 06:29:33 +00008306 getSema().PushLambdaScope();
8307 LambdaScopeInfo *LSI = getSema().getCurLambda();
8308 TemplateParameterList *const OrigTPL = E->getTemplateParameterList();
8309 TemplateParameterList *NewTPL = 0;
8310 // Transform the template parameters, and add them to the
8311 // current instantiation scope.
8312 if (OrigTPL) {
8313 NewTPL = getDerived().TransformTemplateParameterList(OrigTPL);
Faisal Valifad9e132013-09-26 19:54:12 +00008314 }
Faisal Vali618c2852013-10-03 06:29:33 +00008315 LSI->GLTemplateParameterList = NewTPL;
8316 // Transform the type of the lambda parameters and start the definition of
8317 // the lambda itself.
8318 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
8319 TypeSourceInfo *NewCallOpTSI = TransformType(OldCallOpTSI);
8320 if (!NewCallOpTSI)
Douglas Gregordfca6f52012-02-13 22:00:16 +00008321 return ExprError();
8322
Eli Friedman8da8a662012-09-19 01:18:11 +00008323 // Create the local class that will describe the lambda.
8324 CXXRecordDecl *Class
8325 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali618c2852013-10-03 06:29:33 +00008326 NewCallOpTSI,
Eli Friedman8da8a662012-09-19 01:18:11 +00008327 /*KnownDependent=*/false);
8328 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8329
Douglas Gregorc6889e72012-02-14 22:28:59 +00008330 // Transform lambda parameters.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008331 SmallVector<QualType, 4> ParamTypes;
8332 SmallVector<ParmVarDecl *, 4> Params;
Douglas Gregorc6889e72012-02-14 22:28:59 +00008333 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
8334 E->getCallOperator()->param_begin(),
8335 E->getCallOperator()->param_size(),
8336 0, ParamTypes, &Params))
Richard Smith612409e2012-07-25 03:56:55 +00008337 return ExprError();
Faisal Vali618c2852013-10-03 06:29:33 +00008338
Douglas Gregordfca6f52012-02-13 22:00:16 +00008339 // Build the call operator.
Faisal Vali618c2852013-10-03 06:29:33 +00008340 CXXMethodDecl *NewCallOperator
Douglas Gregordfca6f52012-02-13 22:00:16 +00008341 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Faisal Vali618c2852013-10-03 06:29:33 +00008342 NewCallOpTSI,
Douglas Gregorc6889e72012-02-14 22:28:59 +00008343 E->getCallOperator()->getLocEnd(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00008344 Params);
Faisal Vali618c2852013-10-03 06:29:33 +00008345 LSI->CallOperator = NewCallOperator;
8346 // Fix the Decl Contexts of the parameters within the call op function
8347 // prototype.
8348 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
8349
8350 TypeLoc NewCallOpTL = NewCallOpTSI->getTypeLoc();
8351 FunctionProtoTypeLoc NewFPTL = NewCallOpTL.castAs<FunctionProtoTypeLoc>();
8352 ParmVarDecl **NewParamDeclArray = NewFPTL.getParmArray();
8353 const unsigned NewNumArgs = NewFPTL.getNumArgs();
8354 for (unsigned I = 0; I < NewNumArgs; ++I) {
8355 NewParamDeclArray[I]->setOwningFunction(NewCallOperator);
8356 }
8357 // If this is a non-generic lambda, the parameters do not get added to the
8358 // current instantiation scope, so add them. This feels kludgey.
8359 // Anyway, it allows the following to compile when the enclosing template
8360 // is specialized and the entire lambda expression has to be
8361 // transformed. Without this FindInstantiatedDecl causes an assertion.
8362 // template<class T> void foo(T t) {
8363 // auto L = [](auto a) {
8364 // auto M = [](char b) { <-- note: non-generic lambda
8365 // auto N = [](auto c) {
8366 // int x = sizeof(a);
8367 // x = sizeof(b); <-- specifically this line
8368 // x = sizeof(c);
8369 // };
8370 // };
8371 // };
8372 // }
8373 // foo('a');
8374 //
8375 if (!E->isGenericLambda()) {
8376 for (unsigned I = 0; I < NewNumArgs; ++I)
8377 SemaRef.CurrentInstantiationScope->InstantiatedLocal(
8378 NewParamDeclArray[I], NewParamDeclArray[I]);
8379 }
8380 return getDerived().TransformLambdaScope(E, NewCallOperator);
Richard Smith612409e2012-07-25 03:56:55 +00008381}
8382
8383template<typename Derived>
8384ExprResult
8385TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
8386 CXXMethodDecl *CallOperator) {
Richard Smith0d8e9642013-05-16 06:20:58 +00008387 bool Invalid = false;
8388
8389 // Transform any init-capture expressions before entering the scope of the
8390 // lambda.
Robert Wilhelme7205c02013-08-10 12:33:24 +00008391 SmallVector<ExprResult, 8> InitCaptureExprs;
Richard Smith0d8e9642013-05-16 06:20:58 +00008392 InitCaptureExprs.resize(E->explicit_capture_end() -
8393 E->explicit_capture_begin());
8394 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8395 CEnd = E->capture_end();
8396 C != CEnd; ++C) {
8397 if (!C->isInitCapture())
8398 continue;
8399 InitCaptureExprs[C - E->capture_begin()] =
Richard Smith04fa7a32013-09-28 04:02:39 +00008400 getDerived().TransformInitializer(
8401 C->getCapturedVar()->getInit(),
8402 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith0d8e9642013-05-16 06:20:58 +00008403 }
8404
Douglas Gregord5387e82012-02-14 00:00:48 +00008405 // Introduce the context of the call operator.
8406 Sema::ContextRAII SavedContext(getSema(), CallOperator);
8407
Faisal Valifad9e132013-09-26 19:54:12 +00008408 LambdaScopeInfo *const LSI = getSema().getCurLambda();
Douglas Gregordfca6f52012-02-13 22:00:16 +00008409 // Enter the scope of the lambda.
Faisal Valifad9e132013-09-26 19:54:12 +00008410 getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008411 E->getCaptureDefault(),
James Dennettf68af642013-08-09 23:08:25 +00008412 E->getCaptureDefaultLoc(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008413 E->hasExplicitParameters(),
8414 E->hasExplicitResultType(),
8415 E->isMutable());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008416
Douglas Gregordfca6f52012-02-13 22:00:16 +00008417 // Transform captures.
Douglas Gregordfca6f52012-02-13 22:00:16 +00008418 bool FinishedExplicitCaptures = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008419 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008420 CEnd = E->capture_end();
8421 C != CEnd; ++C) {
8422 // When we hit the first implicit capture, tell Sema that we've finished
8423 // the list of explicit captures.
8424 if (!FinishedExplicitCaptures && C->isImplicit()) {
8425 getSema().finishLambdaExplicitCaptures(LSI);
8426 FinishedExplicitCaptures = true;
8427 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008428
Douglas Gregordfca6f52012-02-13 22:00:16 +00008429 // Capturing 'this' is trivial.
8430 if (C->capturesThis()) {
8431 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8432 continue;
8433 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008434
Richard Smith0d8e9642013-05-16 06:20:58 +00008435 // Rebuild init-captures, including the implied field declaration.
8436 if (C->isInitCapture()) {
8437 ExprResult Init = InitCaptureExprs[C - E->capture_begin()];
8438 if (Init.isInvalid()) {
8439 Invalid = true;
8440 continue;
8441 }
Richard Smith04fa7a32013-09-28 04:02:39 +00008442 VarDecl *OldVD = C->getCapturedVar();
8443 VarDecl *NewVD = getSema().checkInitCapture(
8444 C->getLocation(), OldVD->getType()->isReferenceType(),
8445 OldVD->getIdentifier(), Init.take());
8446 if (!NewVD)
Richard Smith0d8e9642013-05-16 06:20:58 +00008447 Invalid = true;
8448 else
Richard Smith04fa7a32013-09-28 04:02:39 +00008449 getDerived().transformedLocalDecl(OldVD, NewVD);
8450 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smith0d8e9642013-05-16 06:20:58 +00008451 continue;
8452 }
8453
8454 assert(C->capturesVariable() && "unexpected kind of lambda capture");
8455
Douglas Gregora7365242012-02-14 19:27:52 +00008456 // Determine the capture kind for Sema.
8457 Sema::TryCaptureKind Kind
8458 = C->isImplicit()? Sema::TryCapture_Implicit
8459 : C->getCaptureKind() == LCK_ByCopy
8460 ? Sema::TryCapture_ExplicitByVal
8461 : Sema::TryCapture_ExplicitByRef;
8462 SourceLocation EllipsisLoc;
8463 if (C->isPackExpansion()) {
8464 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8465 bool ShouldExpand = false;
8466 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008467 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008468 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8469 C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008470 Unexpanded,
8471 ShouldExpand, RetainExpansion,
Richard Smith0d8e9642013-05-16 06:20:58 +00008472 NumExpansions)) {
8473 Invalid = true;
8474 continue;
8475 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008476
Douglas Gregora7365242012-02-14 19:27:52 +00008477 if (ShouldExpand) {
8478 // The transform has determined that we should perform an expansion;
8479 // transform and capture each of the arguments.
8480 // expansion of the pattern. Do so.
8481 VarDecl *Pack = C->getCapturedVar();
8482 for (unsigned I = 0; I != *NumExpansions; ++I) {
8483 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8484 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008485 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008486 Pack));
8487 if (!CapturedVar) {
8488 Invalid = true;
8489 continue;
8490 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008491
Douglas Gregora7365242012-02-14 19:27:52 +00008492 // Capture the transformed variable.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008493 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8494 }
Douglas Gregora7365242012-02-14 19:27:52 +00008495 continue;
8496 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008497
Douglas Gregora7365242012-02-14 19:27:52 +00008498 EllipsisLoc = C->getEllipsisLoc();
8499 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008500
Douglas Gregordfca6f52012-02-13 22:00:16 +00008501 // Transform the captured variable.
8502 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008503 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008504 C->getCapturedVar()));
8505 if (!CapturedVar) {
8506 Invalid = true;
8507 continue;
8508 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008509
Douglas Gregordfca6f52012-02-13 22:00:16 +00008510 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00008511 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008512 }
8513 if (!FinishedExplicitCaptures)
8514 getSema().finishLambdaExplicitCaptures(LSI);
8515
Douglas Gregordfca6f52012-02-13 22:00:16 +00008516
8517 // Enter a new evaluation context to insulate the lambda from any
8518 // cleanups from the enclosing full-expression.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008519 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008520
8521 if (Invalid) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008522 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregordfca6f52012-02-13 22:00:16 +00008523 /*IsInstantiation=*/true);
8524 return ExprError();
8525 }
8526
8527 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00008528 StmtResult Body = getDerived().TransformStmt(E->getBody());
8529 if (Body.isInvalid()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008530 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregord5387e82012-02-14 00:00:48 +00008531 /*IsInstantiation=*/true);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008532 return ExprError();
Douglas Gregord5387e82012-02-14 00:00:48 +00008533 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00008534
Chad Rosier4a9d7952012-08-08 18:46:20 +00008535 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00008536 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00008537}
8538
8539template<typename Derived>
8540ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008541TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00008542 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00008543 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8544 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008545 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008546
Douglas Gregorb98b1992009-08-11 05:31:07 +00008547 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008548 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008549 Args.reserve(E->arg_size());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008550 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008551 &ArgumentChanged))
8552 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008553
Douglas Gregorb98b1992009-08-11 05:31:07 +00008554 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008555 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008556 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008557 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008558
Douglas Gregorb98b1992009-08-11 05:31:07 +00008559 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00008560 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008561 E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008562 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008563 E->getRParenLoc());
8564}
Mike Stump1eb44332009-09-09 15:08:12 +00008565
Douglas Gregorb98b1992009-08-11 05:31:07 +00008566template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008567ExprResult
John McCall865d4472009-11-19 22:55:06 +00008568TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008569 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008570 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008571 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008572 Expr *OldBase;
8573 QualType BaseType;
8574 QualType ObjectType;
8575 if (!E->isImplicitAccess()) {
8576 OldBase = E->getBase();
8577 Base = getDerived().TransformExpr(OldBase);
8578 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008579 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008580
John McCallaa81e162009-12-01 22:10:20 +00008581 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008582 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008583 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008584 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008585 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008586 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008587 ObjectTy,
8588 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008589 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008590 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008591
John McCallb3d87482010-08-24 05:47:05 +00008592 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008593 BaseType = ((Expr*) Base.get())->getType();
8594 } else {
8595 OldBase = 0;
8596 BaseType = getDerived().TransformType(E->getBaseType());
8597 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8598 }
Mike Stump1eb44332009-09-09 15:08:12 +00008599
Douglas Gregor6cd21982009-10-20 05:58:46 +00008600 // Transform the first part of the nested-name-specifier that qualifies
8601 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008602 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008603 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008604 E->getFirstQualifierFoundInScope(),
8605 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008606
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008607 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008608 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008609 QualifierLoc
8610 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8611 ObjectType,
8612 FirstQualifierInScope);
8613 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008614 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008615 }
Mike Stump1eb44332009-09-09 15:08:12 +00008616
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008617 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8618
John McCall43fed0d2010-11-12 08:19:04 +00008619 // TODO: If this is a conversion-function-id, verify that the
8620 // destination type name (if present) resolves the same way after
8621 // instantiation as it did in the local scope.
8622
Abramo Bagnara25777432010-08-11 22:01:17 +00008623 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008624 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008625 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008626 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008627
John McCallaa81e162009-12-01 22:10:20 +00008628 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008629 // This is a reference to a member without an explicitly-specified
8630 // template argument list. Optimize for this common case.
8631 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008632 Base.get() == OldBase &&
8633 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008634 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008635 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008636 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008637 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008638
John McCall9ae2f072010-08-23 23:25:46 +00008639 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008640 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008641 E->isArrow(),
8642 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008643 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008644 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008645 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008646 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008647 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008648 }
8649
John McCalld5532b62009-11-23 01:53:49 +00008650 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008651 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8652 E->getNumTemplateArgs(),
8653 TransArgs))
8654 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008655
John McCall9ae2f072010-08-23 23:25:46 +00008656 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008657 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008658 E->isArrow(),
8659 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008660 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008661 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008662 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008663 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008664 &TransArgs);
8665}
8666
8667template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008668ExprResult
John McCall454feb92009-12-08 09:21:05 +00008669TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008670 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008671 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008672 QualType BaseType;
8673 if (!Old->isImplicitAccess()) {
8674 Base = getDerived().TransformExpr(Old->getBase());
8675 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008676 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008677 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8678 Old->isArrow());
8679 if (Base.isInvalid())
8680 return ExprError();
8681 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008682 } else {
8683 BaseType = getDerived().TransformType(Old->getBaseType());
8684 }
John McCall129e2df2009-11-30 22:42:35 +00008685
Douglas Gregor4c9be892011-02-28 20:01:57 +00008686 NestedNameSpecifierLoc QualifierLoc;
8687 if (Old->getQualifierLoc()) {
8688 QualifierLoc
8689 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8690 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008691 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008692 }
8693
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008694 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8695
Abramo Bagnara25777432010-08-11 22:01:17 +00008696 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008697 Sema::LookupOrdinaryName);
8698
8699 // Transform all the decls.
8700 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8701 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008702 NamedDecl *InstD = static_cast<NamedDecl*>(
8703 getDerived().TransformDecl(Old->getMemberLoc(),
8704 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008705 if (!InstD) {
8706 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8707 // This can happen because of dependent hiding.
8708 if (isa<UsingShadowDecl>(*I))
8709 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008710 else {
8711 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008712 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008713 }
John McCall9f54ad42009-12-10 09:41:52 +00008714 }
John McCall129e2df2009-11-30 22:42:35 +00008715
8716 // Expand using declarations.
8717 if (isa<UsingDecl>(InstD)) {
8718 UsingDecl *UD = cast<UsingDecl>(InstD);
8719 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8720 E = UD->shadow_end(); I != E; ++I)
8721 R.addDecl(*I);
8722 continue;
8723 }
8724
8725 R.addDecl(InstD);
8726 }
8727
8728 R.resolveKind();
8729
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008730 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008731 if (Old->getNamingClass()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008732 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008733 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008734 Old->getMemberLoc(),
8735 Old->getNamingClass()));
8736 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008737 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008738
Douglas Gregor66c45152010-04-27 16:10:10 +00008739 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008740 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008741
John McCall129e2df2009-11-30 22:42:35 +00008742 TemplateArgumentListInfo TransArgs;
8743 if (Old->hasExplicitTemplateArgs()) {
8744 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8745 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008746 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8747 Old->getNumTemplateArgs(),
8748 TransArgs))
8749 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008750 }
John McCallc2233c52010-01-15 08:34:02 +00008751
8752 // FIXME: to do this check properly, we will need to preserve the
8753 // first-qualifier-in-scope here, just in case we had a dependent
8754 // base (and therefore couldn't do the check) and a
8755 // nested-name-qualifier (and therefore could do the lookup).
8756 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008757
John McCall9ae2f072010-08-23 23:25:46 +00008758 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008759 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008760 Old->getOperatorLoc(),
8761 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008762 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008763 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008764 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008765 R,
8766 (Old->hasExplicitTemplateArgs()
8767 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008768}
8769
8770template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008771ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008772TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008773 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008774 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8775 if (SubExpr.isInvalid())
8776 return ExprError();
8777
8778 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008779 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008780
8781 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8782}
8783
8784template<typename Derived>
8785ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008786TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008787 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8788 if (Pattern.isInvalid())
8789 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008790
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008791 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8792 return SemaRef.Owned(E);
8793
Douglas Gregor67fd1252011-01-14 21:20:45 +00008794 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8795 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008796}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008797
8798template<typename Derived>
8799ExprResult
8800TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8801 // If E is not value-dependent, then nothing will change when we transform it.
8802 // Note: This is an instantiation-centric view.
8803 if (!E->isValueDependent())
8804 return SemaRef.Owned(E);
8805
8806 // Note: None of the implementations of TryExpandParameterPacks can ever
8807 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier4a9d7952012-08-08 18:46:20 +00008808 // so
Douglas Gregoree8aff02011-01-04 17:33:58 +00008809 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8810 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008811 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008812 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008813 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008814 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008815 ShouldExpand, RetainExpansion,
8816 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008817 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008818
Douglas Gregor089e8932011-10-10 18:59:29 +00008819 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008820 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008821
Douglas Gregor089e8932011-10-10 18:59:29 +00008822 NamedDecl *Pack = E->getPack();
8823 if (!ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008824 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008825 Pack));
8826 if (!Pack)
8827 return ExprError();
8828 }
8829
Chad Rosier4a9d7952012-08-08 18:46:20 +00008830
Douglas Gregoree8aff02011-01-04 17:33:58 +00008831 // We now know the length of the parameter pack, so build a new expression
8832 // that stores that length.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008833 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8834 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008835 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008836}
8837
Douglas Gregorbe230c32011-01-03 17:17:50 +00008838template<typename Derived>
8839ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008840TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8841 SubstNonTypeTemplateParmPackExpr *E) {
8842 // Default behavior is to do nothing with this transformation.
8843 return SemaRef.Owned(E);
8844}
8845
8846template<typename Derived>
8847ExprResult
John McCall91a57552011-07-15 05:09:51 +00008848TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8849 SubstNonTypeTemplateParmExpr *E) {
8850 // Default behavior is to do nothing with this transformation.
8851 return SemaRef.Owned(E);
8852}
8853
8854template<typename Derived>
8855ExprResult
Richard Smith9a4db032012-09-12 00:56:43 +00008856TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8857 // Default behavior is to do nothing with this transformation.
8858 return SemaRef.Owned(E);
8859}
8860
8861template<typename Derived>
8862ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008863TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8864 MaterializeTemporaryExpr *E) {
8865 return getDerived().TransformExpr(E->GetTemporaryExpr());
8866}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008867
Douglas Gregor03e80032011-06-21 17:03:29 +00008868template<typename Derived>
8869ExprResult
Richard Smith7c3e6152013-06-12 22:31:48 +00008870TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
8871 CXXStdInitializerListExpr *E) {
8872 return getDerived().TransformExpr(E->getSubExpr());
8873}
8874
8875template<typename Derived>
8876ExprResult
John McCall454feb92009-12-08 09:21:05 +00008877TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008878 return SemaRef.MaybeBindToTemporary(E);
8879}
8880
8881template<typename Derived>
8882ExprResult
8883TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008884 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008885}
8886
8887template<typename Derived>
8888ExprResult
Patrick Beardeb382ec2012-04-19 00:25:12 +00008889TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8890 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8891 if (SubExpr.isInvalid())
8892 return ExprError();
8893
8894 if (!getDerived().AlwaysRebuild() &&
8895 SubExpr.get() == E->getSubExpr())
8896 return SemaRef.Owned(E);
8897
8898 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008899}
8900
8901template<typename Derived>
8902ExprResult
8903TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8904 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008905 SmallVector<Expr *, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008906 bool ArgChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008907 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008908 /*IsCall=*/false, Elements, &ArgChanged))
8909 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008910
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008911 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8912 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008913
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008914 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8915 Elements.data(),
8916 Elements.size());
8917}
8918
8919template<typename Derived>
8920ExprResult
8921TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008922 ObjCDictionaryLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008923 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008924 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008925 bool ArgChanged = false;
8926 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8927 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008928
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008929 if (OrigElement.isPackExpansion()) {
8930 // This key/value element is a pack expansion.
8931 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8932 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8933 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8934 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8935
8936 // Determine whether the set of unexpanded parameter packs can
8937 // and should be expanded.
8938 bool Expand = true;
8939 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008940 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8941 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008942 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8943 OrigElement.Value->getLocEnd());
8944 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8945 PatternRange,
8946 Unexpanded,
8947 Expand, RetainExpansion,
8948 NumExpansions))
8949 return ExprError();
8950
8951 if (!Expand) {
8952 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00008953 // transformation on the pack expansion, producing another pack
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008954 // expansion.
8955 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8956 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8957 if (Key.isInvalid())
8958 return ExprError();
8959
8960 if (Key.get() != OrigElement.Key)
8961 ArgChanged = true;
8962
8963 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8964 if (Value.isInvalid())
8965 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008966
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008967 if (Value.get() != OrigElement.Value)
8968 ArgChanged = true;
8969
Chad Rosier4a9d7952012-08-08 18:46:20 +00008970 ObjCDictionaryElement Expansion = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008971 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8972 };
8973 Elements.push_back(Expansion);
8974 continue;
8975 }
8976
8977 // Record right away that the argument was changed. This needs
8978 // to happen even if the array expands to nothing.
8979 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008980
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008981 // The transform has determined that we should perform an elementwise
8982 // expansion of the pattern. Do so.
8983 for (unsigned I = 0; I != *NumExpansions; ++I) {
8984 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8985 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8986 if (Key.isInvalid())
8987 return ExprError();
8988
8989 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8990 if (Value.isInvalid())
8991 return ExprError();
8992
Chad Rosier4a9d7952012-08-08 18:46:20 +00008993 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008994 Key.get(), Value.get(), SourceLocation(), NumExpansions
8995 };
8996
8997 // If any unexpanded parameter packs remain, we still have a
8998 // pack expansion.
8999 if (Key.get()->containsUnexpandedParameterPack() ||
9000 Value.get()->containsUnexpandedParameterPack())
9001 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier4a9d7952012-08-08 18:46:20 +00009002
Ted Kremenekebcb57a2012-03-06 20:05:56 +00009003 Elements.push_back(Element);
9004 }
9005
9006 // We've finished with this pack expansion.
9007 continue;
9008 }
9009
9010 // Transform and check key.
9011 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9012 if (Key.isInvalid())
9013 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009014
Ted Kremenekebcb57a2012-03-06 20:05:56 +00009015 if (Key.get() != OrigElement.Key)
9016 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00009017
Ted Kremenekebcb57a2012-03-06 20:05:56 +00009018 // Transform and check value.
9019 ExprResult Value
9020 = getDerived().TransformExpr(OrigElement.Value);
9021 if (Value.isInvalid())
9022 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009023
Ted Kremenekebcb57a2012-03-06 20:05:56 +00009024 if (Value.get() != OrigElement.Value)
9025 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00009026
9027 ObjCDictionaryElement Element = {
David Blaikie66874fb2013-02-21 01:47:18 +00009028 Key.get(), Value.get(), SourceLocation(), None
Ted Kremenekebcb57a2012-03-06 20:05:56 +00009029 };
9030 Elements.push_back(Element);
9031 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00009032
Ted Kremenekebcb57a2012-03-06 20:05:56 +00009033 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9034 return SemaRef.MaybeBindToTemporary(E);
9035
9036 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
9037 Elements.data(),
9038 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009039}
9040
Mike Stump1eb44332009-09-09 15:08:12 +00009041template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009042ExprResult
John McCall454feb92009-12-08 09:21:05 +00009043TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00009044 TypeSourceInfo *EncodedTypeInfo
9045 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
9046 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00009047 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009048
Douglas Gregorb98b1992009-08-11 05:31:07 +00009049 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00009050 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00009051 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009052
9053 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00009054 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00009055 E->getRParenLoc());
9056}
Mike Stump1eb44332009-09-09 15:08:12 +00009057
Douglas Gregorb98b1992009-08-11 05:31:07 +00009058template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00009059ExprResult TreeTransform<Derived>::
9060TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCall93b64572013-04-11 02:14:26 +00009061 // This is a kind of implicit conversion, and it needs to get dropped
9062 // and recomputed for the same general reasons that ImplicitCastExprs
9063 // do, as well a more specific one: this expression is only valid when
9064 // it appears *immediately* as an argument expression.
9065 return getDerived().TransformExpr(E->getSubExpr());
John McCallf85e1932011-06-15 23:02:42 +00009066}
9067
9068template<typename Derived>
9069ExprResult TreeTransform<Derived>::
9070TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00009071 TypeSourceInfo *TSInfo
John McCallf85e1932011-06-15 23:02:42 +00009072 = getDerived().TransformType(E->getTypeInfoAsWritten());
9073 if (!TSInfo)
9074 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009075
John McCallf85e1932011-06-15 23:02:42 +00009076 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009077 if (Result.isInvalid())
John McCallf85e1932011-06-15 23:02:42 +00009078 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009079
John McCallf85e1932011-06-15 23:02:42 +00009080 if (!getDerived().AlwaysRebuild() &&
9081 TSInfo == E->getTypeInfoAsWritten() &&
9082 Result.get() == E->getSubExpr())
9083 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009084
John McCallf85e1932011-06-15 23:02:42 +00009085 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00009086 E->getBridgeKeywordLoc(), TSInfo,
John McCallf85e1932011-06-15 23:02:42 +00009087 Result.get());
9088}
9089
9090template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009091ExprResult
John McCall454feb92009-12-08 09:21:05 +00009092TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00009093 // Transform arguments.
9094 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00009095 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00009096 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009097 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00009098 &ArgChanged))
9099 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009100
Douglas Gregor92e986e2010-04-22 16:44:27 +00009101 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
9102 // Class message: transform the receiver type.
9103 TypeSourceInfo *ReceiverTypeInfo
9104 = getDerived().TransformType(E->getClassReceiverTypeInfo());
9105 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00009106 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009107
Douglas Gregor92e986e2010-04-22 16:44:27 +00009108 // If nothing changed, just retain the existing message send.
9109 if (!getDerived().AlwaysRebuild() &&
9110 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00009111 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00009112
9113 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00009114 SmallVector<SourceLocation, 16> SelLocs;
9115 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00009116 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
9117 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00009118 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00009119 E->getMethodDecl(),
9120 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009121 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00009122 E->getRightLoc());
9123 }
9124
9125 // Instance message: transform the receiver
9126 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
9127 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00009128 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00009129 = getDerived().TransformExpr(E->getInstanceReceiver());
9130 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009131 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00009132
9133 // If nothing changed, just retain the existing message send.
9134 if (!getDerived().AlwaysRebuild() &&
9135 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00009136 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009137
Douglas Gregor92e986e2010-04-22 16:44:27 +00009138 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00009139 SmallVector<SourceLocation, 16> SelLocs;
9140 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00009141 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00009142 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00009143 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00009144 E->getMethodDecl(),
9145 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009146 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00009147 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009148}
9149
Mike Stump1eb44332009-09-09 15:08:12 +00009150template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009151ExprResult
John McCall454feb92009-12-08 09:21:05 +00009152TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00009153 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009154}
9155
Mike Stump1eb44332009-09-09 15:08:12 +00009156template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009157ExprResult
John McCall454feb92009-12-08 09:21:05 +00009158TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00009159 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009160}
9161
Mike Stump1eb44332009-09-09 15:08:12 +00009162template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009163ExprResult
John McCall454feb92009-12-08 09:21:05 +00009164TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009165 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00009166 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009167 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009168 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009169
9170 // We don't need to transform the ivar; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00009171
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009172 // If nothing changed, just retain the existing expression.
9173 if (!getDerived().AlwaysRebuild() &&
9174 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00009175 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009176
John McCall9ae2f072010-08-23 23:25:46 +00009177 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009178 E->getLocation(),
9179 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009180}
9181
Mike Stump1eb44332009-09-09 15:08:12 +00009182template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009183ExprResult
John McCall454feb92009-12-08 09:21:05 +00009184TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00009185 // 'super' and types never change. Property never changes. Just
9186 // retain the existing expression.
9187 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00009188 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009189
Douglas Gregore3303542010-04-26 20:47:02 +00009190 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00009191 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00009192 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009193 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009194
Douglas Gregore3303542010-04-26 20:47:02 +00009195 // We don't need to transform the property; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00009196
Douglas Gregore3303542010-04-26 20:47:02 +00009197 // If nothing changed, just retain the existing expression.
9198 if (!getDerived().AlwaysRebuild() &&
9199 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00009200 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009201
John McCall12f78a62010-12-02 01:19:52 +00009202 if (E->isExplicitProperty())
9203 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9204 E->getExplicitProperty(),
9205 E->getLocation());
9206
9207 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00009208 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00009209 E->getImplicitPropertyGetter(),
9210 E->getImplicitPropertySetter(),
9211 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009212}
9213
Mike Stump1eb44332009-09-09 15:08:12 +00009214template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009215ExprResult
Ted Kremenekebcb57a2012-03-06 20:05:56 +00009216TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
9217 // Transform the base expression.
9218 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9219 if (Base.isInvalid())
9220 return ExprError();
9221
9222 // Transform the key expression.
9223 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
9224 if (Key.isInvalid())
9225 return ExprError();
9226
9227 // If nothing changed, just retain the existing expression.
9228 if (!getDerived().AlwaysRebuild() &&
9229 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
9230 return SemaRef.Owned(E);
9231
Chad Rosier4a9d7952012-08-08 18:46:20 +00009232 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00009233 Base.get(), Key.get(),
9234 E->getAtIndexMethodDecl(),
9235 E->setAtIndexMethodDecl());
9236}
9237
9238template<typename Derived>
9239ExprResult
John McCall454feb92009-12-08 09:21:05 +00009240TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009241 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00009242 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009243 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009244 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009245
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009246 // If nothing changed, just retain the existing expression.
9247 if (!getDerived().AlwaysRebuild() &&
9248 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00009249 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009250
John McCall9ae2f072010-08-23 23:25:46 +00009251 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00009252 E->getOpLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009253 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009254}
9255
Mike Stump1eb44332009-09-09 15:08:12 +00009256template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009257ExprResult
John McCall454feb92009-12-08 09:21:05 +00009258TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009259 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00009260 SmallVector<Expr*, 8> SubExprs;
Douglas Gregoraa165f82011-01-03 19:04:46 +00009261 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009262 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00009263 SubExprs, &ArgumentChanged))
9264 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009265
Douglas Gregorb98b1992009-08-11 05:31:07 +00009266 if (!getDerived().AlwaysRebuild() &&
9267 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00009268 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00009269
Douglas Gregorb98b1992009-08-11 05:31:07 +00009270 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009271 SubExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00009272 E->getRParenLoc());
9273}
9274
Mike Stump1eb44332009-09-09 15:08:12 +00009275template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009276ExprResult
Hal Finkel414a1bd2013-09-18 03:29:45 +00009277TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
9278 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
9279 if (SrcExpr.isInvalid())
9280 return ExprError();
9281
9282 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9283 if (!Type)
9284 return ExprError();
9285
9286 if (!getDerived().AlwaysRebuild() &&
9287 Type == E->getTypeSourceInfo() &&
9288 SrcExpr.get() == E->getSrcExpr())
9289 return SemaRef.Owned(E);
9290
9291 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
9292 SrcExpr.get(), Type,
9293 E->getRParenLoc());
9294}
9295
9296template<typename Derived>
9297ExprResult
John McCall454feb92009-12-08 09:21:05 +00009298TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00009299 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009300
John McCallc6ac9c32011-02-04 18:33:18 +00009301 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
9302 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
9303
9304 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00009305 blockScope->TheDecl->setBlockMissingReturnType(
9306 oldBlock->blockMissingReturnType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009307
Chris Lattner686775d2011-07-20 06:58:45 +00009308 SmallVector<ParmVarDecl*, 4> params;
9309 SmallVector<QualType, 4> paramTypes;
Chad Rosier4a9d7952012-08-08 18:46:20 +00009310
Fariborz Jahaniana729da22010-07-09 18:44:02 +00009311 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00009312 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
9313 oldBlock->param_begin(),
9314 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009315 0, paramTypes, &params)) {
9316 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00009317 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009318 }
John McCallc6ac9c32011-02-04 18:33:18 +00009319
Jordan Rose09189892013-03-08 22:25:36 +00009320 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00009321 QualType exprResultType =
9322 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00009323
Jordan Rosebea522f2013-03-08 21:51:21 +00009324 QualType functionType =
9325 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rose09189892013-03-08 22:25:36 +00009326 exprFunctionType->getExtProtoInfo());
John McCallc6ac9c32011-02-04 18:33:18 +00009327 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00009328
9329 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00009330 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00009331 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00009332
9333 if (!oldBlock->blockMissingReturnType()) {
9334 blockScope->HasImplicitReturnType = false;
9335 blockScope->ReturnType = exprResultType;
9336 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00009337
John McCall711c52b2011-01-05 12:14:39 +00009338 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00009339 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009340 if (body.isInvalid()) {
9341 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00009342 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009343 }
John McCall711c52b2011-01-05 12:14:39 +00009344
John McCallc6ac9c32011-02-04 18:33:18 +00009345#ifndef NDEBUG
9346 // In builds with assertions, make sure that we captured everything we
9347 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00009348 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
9349 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
9350 e = oldBlock->capture_end(); i != e; ++i) {
9351 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00009352
Douglas Gregorfc921372011-05-20 15:32:55 +00009353 // Ignore parameter packs.
9354 if (isa<ParmVarDecl>(oldCapture) &&
9355 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9356 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00009357
Douglas Gregorfc921372011-05-20 15:32:55 +00009358 VarDecl *newCapture =
9359 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9360 oldCapture));
9361 assert(blockScope->CaptureMap.count(newCapture));
9362 }
Douglas Gregorec79d872012-02-24 17:41:38 +00009363 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00009364 }
9365#endif
9366
9367 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
9368 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009369}
9370
Mike Stump1eb44332009-09-09 15:08:12 +00009371template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009372ExprResult
Tanya Lattner61eee0c2011-06-04 00:47:47 +00009373TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00009374 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00009375}
Eli Friedman276b0612011-10-11 02:20:01 +00009376
9377template<typename Derived>
9378ExprResult
9379TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009380 QualType RetTy = getDerived().TransformType(E->getType());
9381 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00009382 SmallVector<Expr*, 8> SubExprs;
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009383 SubExprs.reserve(E->getNumSubExprs());
9384 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9385 SubExprs, &ArgumentChanged))
9386 return ExprError();
9387
9388 if (!getDerived().AlwaysRebuild() &&
9389 !ArgumentChanged)
9390 return SemaRef.Owned(E);
9391
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009392 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009393 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00009394}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009395
Douglas Gregorb98b1992009-08-11 05:31:07 +00009396//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00009397// Type reconstruction
9398//===----------------------------------------------------------------------===//
9399
Mike Stump1eb44332009-09-09 15:08:12 +00009400template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00009401QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9402 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00009403 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009404 getDerived().getBaseEntity());
9405}
9406
Mike Stump1eb44332009-09-09 15:08:12 +00009407template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00009408QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9409 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00009410 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009411 getDerived().getBaseEntity());
9412}
9413
Mike Stump1eb44332009-09-09 15:08:12 +00009414template<typename Derived>
9415QualType
John McCall85737a72009-10-30 00:06:24 +00009416TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9417 bool WrittenAsLValue,
9418 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00009419 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00009420 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009421}
9422
9423template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009424QualType
John McCall85737a72009-10-30 00:06:24 +00009425TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9426 QualType ClassType,
9427 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00009428 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00009429 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009430}
9431
9432template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009433QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00009434TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9435 ArrayType::ArraySizeModifier SizeMod,
9436 const llvm::APInt *Size,
9437 Expr *SizeExpr,
9438 unsigned IndexTypeQuals,
9439 SourceRange BracketsRange) {
9440 if (SizeExpr || !Size)
9441 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9442 IndexTypeQuals, BracketsRange,
9443 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00009444
9445 QualType Types[] = {
9446 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9447 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9448 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00009449 };
Craig Topperb9602322013-07-15 03:38:40 +00009450 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009451 QualType SizeType;
9452 for (unsigned I = 0; I != NumTypes; ++I)
9453 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9454 SizeType = Types[I];
9455 break;
9456 }
Mike Stump1eb44332009-09-09 15:08:12 +00009457
Eli Friedman01f276d2012-01-25 23:20:27 +00009458 // Note that we can return a VariableArrayType here in the case where
9459 // the element type was a dependent VariableArrayType.
9460 IntegerLiteral *ArraySize
9461 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9462 /*FIXME*/BracketsRange.getBegin());
9463 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009464 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00009465 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009466}
Mike Stump1eb44332009-09-09 15:08:12 +00009467
Douglas Gregor577f75a2009-08-04 16:50:30 +00009468template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009469QualType
9470TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009471 ArrayType::ArraySizeModifier SizeMod,
9472 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00009473 unsigned IndexTypeQuals,
9474 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009475 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00009476 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009477}
9478
9479template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009480QualType
Mike Stump1eb44332009-09-09 15:08:12 +00009481TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009482 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00009483 unsigned IndexTypeQuals,
9484 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009485 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00009486 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009487}
Mike Stump1eb44332009-09-09 15:08:12 +00009488
Douglas Gregor577f75a2009-08-04 16:50:30 +00009489template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009490QualType
9491TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009492 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009493 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009494 unsigned IndexTypeQuals,
9495 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009496 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009497 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009498 IndexTypeQuals, BracketsRange);
9499}
9500
9501template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009502QualType
9503TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009504 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009505 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009506 unsigned IndexTypeQuals,
9507 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009508 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009509 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009510 IndexTypeQuals, BracketsRange);
9511}
9512
9513template<typename Derived>
9514QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00009515 unsigned NumElements,
9516 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00009517 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00009518 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009519}
Mike Stump1eb44332009-09-09 15:08:12 +00009520
Douglas Gregor577f75a2009-08-04 16:50:30 +00009521template<typename Derived>
9522QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9523 unsigned NumElements,
9524 SourceLocation AttributeLoc) {
9525 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9526 NumElements, true);
9527 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00009528 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9529 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00009530 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009531}
Mike Stump1eb44332009-09-09 15:08:12 +00009532
Douglas Gregor577f75a2009-08-04 16:50:30 +00009533template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009534QualType
9535TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00009536 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009537 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00009538 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009539}
Mike Stump1eb44332009-09-09 15:08:12 +00009540
Douglas Gregor577f75a2009-08-04 16:50:30 +00009541template<typename Derived>
Jordan Rosebea522f2013-03-08 21:51:21 +00009542QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9543 QualType T,
9544 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00009545 const FunctionProtoType::ExtProtoInfo &EPI) {
9546 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009547 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00009548 getDerived().getBaseEntity(),
Jordan Rose09189892013-03-08 22:25:36 +00009549 EPI);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009550}
Mike Stump1eb44332009-09-09 15:08:12 +00009551
Douglas Gregor577f75a2009-08-04 16:50:30 +00009552template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00009553QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9554 return SemaRef.Context.getFunctionNoProtoType(T);
9555}
9556
9557template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00009558QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9559 assert(D && "no decl found");
9560 if (D->isInvalidDecl()) return QualType();
9561
Douglas Gregor92e986e2010-04-22 16:44:27 +00009562 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00009563 TypeDecl *Ty;
9564 if (isa<UsingDecl>(D)) {
9565 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanella8d030c72013-07-22 10:54:09 +00009566 assert(Using->hasTypename() &&
John McCalled976492009-12-04 22:46:56 +00009567 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9568
9569 // A valid resolved using typename decl points to exactly one type decl.
9570 assert(++Using->shadow_begin() == Using->shadow_end());
9571 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009572
John McCalled976492009-12-04 22:46:56 +00009573 } else {
9574 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9575 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9576 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9577 }
9578
9579 return SemaRef.Context.getTypeDeclType(Ty);
9580}
9581
9582template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009583QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9584 SourceLocation Loc) {
9585 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009586}
9587
9588template<typename Derived>
9589QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9590 return SemaRef.Context.getTypeOfType(Underlying);
9591}
9592
9593template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009594QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9595 SourceLocation Loc) {
9596 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009597}
9598
9599template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009600QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9601 UnaryTransformType::UTTKind UKind,
9602 SourceLocation Loc) {
9603 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9604}
9605
9606template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009607QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009608 TemplateName Template,
9609 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009610 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009611 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009612}
Mike Stump1eb44332009-09-09 15:08:12 +00009613
Douglas Gregordcee1a12009-08-06 05:28:30 +00009614template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009615QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9616 SourceLocation KWLoc) {
9617 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9618}
9619
9620template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009621TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009622TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009623 bool TemplateKW,
9624 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009625 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009626 Template);
9627}
9628
9629template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009630TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009631TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9632 const IdentifierInfo &Name,
9633 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009634 QualType ObjectType,
9635 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009636 UnqualifiedId TemplateName;
9637 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009638 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009639 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009640 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009641 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009642 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009643 /*EnteringContext=*/false,
9644 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009645 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009646}
Mike Stump1eb44332009-09-09 15:08:12 +00009647
Douglas Gregorb98b1992009-08-11 05:31:07 +00009648template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009649TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009650TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009651 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009652 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009653 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009654 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009655 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009656 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009657 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009658 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009659 Sema::TemplateTy Template;
9660 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009661 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009662 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009663 /*EnteringContext=*/false,
9664 Template);
Serge Pavlov18062392013-08-27 13:15:56 +00009665 return Template.get();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009666}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009667
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009668template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009669ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009670TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9671 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009672 Expr *OrigCallee,
9673 Expr *First,
9674 Expr *Second) {
9675 Expr *Callee = OrigCallee->IgnoreParenCasts();
9676 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009677
Douglas Gregorb98b1992009-08-11 05:31:07 +00009678 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009679 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009680 if (!First->getType()->isOverloadableType() &&
9681 !Second->getType()->isOverloadableType())
9682 return getSema().CreateBuiltinArraySubscriptExpr(First,
9683 Callee->getLocStart(),
9684 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009685 } else if (Op == OO_Arrow) {
9686 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009687 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9688 } else if (Second == 0 || isPostIncDec) {
9689 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009690 // The argument is not of overloadable type, so try to create a
9691 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009692 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009693 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009694
John McCall9ae2f072010-08-23 23:25:46 +00009695 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009696 }
9697 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009698 if (!First->getType()->isOverloadableType() &&
9699 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009700 // Neither of the arguments is an overloadable type, so try to
9701 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009702 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009703 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009704 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009705 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009706 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009707
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009708 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009709 }
9710 }
Mike Stump1eb44332009-09-09 15:08:12 +00009711
9712 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009713 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009714 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009715
John McCall9ae2f072010-08-23 23:25:46 +00009716 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009717 assert(ULE->requiresADL());
9718
9719 // FIXME: Do we have to check
9720 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009721 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009722 } else {
Richard Smithf6411662012-11-28 21:47:39 +00009723 // If we've resolved this to a particular non-member function, just call
9724 // that function. If we resolved it to a member function,
9725 // CreateOverloaded* will find that function for us.
9726 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9727 if (!isa<CXXMethodDecl>(ND))
9728 Functions.addDecl(ND);
John McCallba135432009-11-21 08:51:07 +00009729 }
Mike Stump1eb44332009-09-09 15:08:12 +00009730
Douglas Gregorb98b1992009-08-11 05:31:07 +00009731 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009732 Expr *Args[2] = { First, Second };
9733 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009734
Douglas Gregorb98b1992009-08-11 05:31:07 +00009735 // Create the overloaded operator invocation for unary operators.
9736 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009737 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009738 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009739 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009740 }
Mike Stump1eb44332009-09-09 15:08:12 +00009741
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009742 if (Op == OO_Subscript) {
9743 SourceLocation LBrace;
9744 SourceLocation RBrace;
9745
9746 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9747 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9748 LBrace = SourceLocation::getFromRawEncoding(
9749 NameLoc.CXXOperatorName.BeginOpNameLoc);
9750 RBrace = SourceLocation::getFromRawEncoding(
9751 NameLoc.CXXOperatorName.EndOpNameLoc);
9752 } else {
9753 LBrace = Callee->getLocStart();
9754 RBrace = OpLoc;
9755 }
9756
9757 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9758 First, Second);
9759 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009760
Douglas Gregorb98b1992009-08-11 05:31:07 +00009761 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009762 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009763 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009764 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9765 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009766 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009767
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009768 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009769}
Mike Stump1eb44332009-09-09 15:08:12 +00009770
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009771template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00009772ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009773TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009774 SourceLocation OperatorLoc,
9775 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009776 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009777 TypeSourceInfo *ScopeType,
9778 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009779 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009780 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009781 QualType BaseType = Base->getType();
9782 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009783 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00009784 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009785 !BaseType->getAs<PointerType>()->getPointeeType()
9786 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009787 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009788 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009789 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009790 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009791 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009792 /*FIXME?*/true);
9793 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009794
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009795 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009796 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9797 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9798 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9799 NameInfo.setNamedTypeInfo(DestroyedType);
9800
Richard Smith6314db92012-05-15 06:15:11 +00009801 // The scope type is now known to be a valid nested name specifier
9802 // component. Tack it on to the end of the nested name specifier.
9803 if (ScopeType)
9804 SS.Extend(SemaRef.Context, SourceLocation(),
9805 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnara25777432010-08-11 22:01:17 +00009806
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009807 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009808 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009809 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009810 SS, TemplateKWLoc,
9811 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009812 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009813 /*TemplateArgs*/ 0);
9814}
9815
Tareq A. Siraj051303c2013-04-16 18:53:08 +00009816template<typename Derived>
9817StmtResult
9818TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan9fd6b8f2013-05-04 03:59:06 +00009819 SourceLocation Loc = S->getLocStart();
9820 unsigned NumParams = S->getCapturedDecl()->getNumParams();
9821 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/0,
9822 S->getCapturedRegionKind(), NumParams);
9823 StmtResult Body = getDerived().TransformStmt(S->getCapturedStmt());
9824
9825 if (Body.isInvalid()) {
9826 getSema().ActOnCapturedRegionError();
9827 return StmtError();
9828 }
9829
9830 return getSema().ActOnCapturedRegionEnd(Body.take());
Tareq A. Siraj051303c2013-04-16 18:53:08 +00009831}
9832
Douglas Gregor577f75a2009-08-04 16:50:30 +00009833} // end namespace clang
9834
9835#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H