blob: 2d22e4ca6473a808f444e64372d81dda4aa9a85c [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"
David Blaikiea71f9d02011-09-22 02:34:54 +000036#include "llvm/ADT/ArrayRef.h"
John McCalla2becad2009-10-21 00:40:46 +000037#include "llvm/Support/ErrorHandling.h"
Douglas Gregor577f75a2009-08-04 16:50:30 +000038#include <algorithm>
39
40namespace clang {
John McCall781472f2010-08-25 08:40:02 +000041using namespace sema;
Mike Stump1eb44332009-09-09 15:08:12 +000042
Douglas Gregor577f75a2009-08-04 16:50:30 +000043/// \brief A semantic tree transformation that allows one to transform one
44/// abstract syntax tree into another.
45///
Mike Stump1eb44332009-09-09 15:08:12 +000046/// A new tree transformation is defined by creating a new subclass \c X of
47/// \c TreeTransform<X> and then overriding certain operations to provide
48/// behavior specific to that transformation. For example, template
Douglas Gregor577f75a2009-08-04 16:50:30 +000049/// instantiation is implemented as a tree transformation where the
50/// transformation of TemplateTypeParmType nodes involves substituting the
51/// template arguments for their corresponding template parameters; a similar
52/// transformation is performed for non-type template parameters and
53/// template template parameters.
54///
55/// This tree-transformation template uses static polymorphism to allow
Mike Stump1eb44332009-09-09 15:08:12 +000056/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregor577f75a2009-08-04 16:50:30 +000057/// override any of the transformation or rebuild operators by providing an
58/// operation with the same signature as the default implementation. The
59/// overridding function should not be virtual.
60///
61/// Semantic tree transformations are split into two stages, either of which
62/// can be replaced by a subclass. The "transform" step transforms an AST node
63/// or the parts of an AST node using the various transformation functions,
64/// then passes the pieces on to the "rebuild" step, which constructs a new AST
65/// node of the appropriate kind from the pieces. The default transformation
66/// routines recursively transform the operands to composite AST nodes (e.g.,
67/// the pointee type of a PointerType node) and, if any of those operand nodes
68/// were changed by the transformation, invokes the rebuild operation to create
69/// a new AST node.
70///
Mike Stump1eb44332009-09-09 15:08:12 +000071/// Subclasses can customize the transformation at various levels. The
Douglas Gregor670444e2009-08-04 22:27:00 +000072/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregor9151c112011-03-02 18:50:38 +000073/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregor577f75a2009-08-04 16:50:30 +000074/// TransformTemplateName(), or TransformTemplateArgument() with entirely
75/// new implementations.
76///
77/// For more fine-grained transformations, subclasses can replace any of the
78/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregor43959a92009-08-20 07:17:43 +000079/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregor577f75a2009-08-04 16:50:30 +000080/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump1eb44332009-09-09 15:08:12 +000081/// to substitute template arguments for their corresponding template
Douglas Gregor577f75a2009-08-04 16:50:30 +000082/// parameters. Additionally, subclasses can override the \c RebuildXXX
83/// functions to control how AST nodes are rebuilt when their operands change.
84/// By default, \c TreeTransform will invoke semantic analysis to rebuild
85/// AST nodes. However, certain other tree transformations (e.g, cloning) may
86/// be able to use more efficient rebuild steps.
87///
88/// There are a handful of other functions that can be overridden, allowing one
Mike Stump1eb44332009-09-09 15:08:12 +000089/// to avoid traversing nodes that don't need any transformation
Douglas Gregor577f75a2009-08-04 16:50:30 +000090/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
91/// operands have not changed (\c AlwaysRebuild()), and customize the
92/// default locations and entity names used for type-checking
93/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregor577f75a2009-08-04 16:50:30 +000094template<typename Derived>
95class TreeTransform {
Douglas Gregord3731192011-01-10 07:32:04 +000096 /// \brief Private RAII object that helps us forget and then re-remember
97 /// the template argument corresponding to a partially-substituted parameter
98 /// pack.
99 class ForgetPartiallySubstitutedPackRAII {
100 Derived &Self;
101 TemplateArgument Old;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000102
Douglas Gregord3731192011-01-10 07:32:04 +0000103 public:
104 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
105 Old = Self.ForgetPartiallySubstitutedPack();
106 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000107
Douglas Gregord3731192011-01-10 07:32:04 +0000108 ~ForgetPartiallySubstitutedPackRAII() {
109 Self.RememberPartiallySubstitutedPack(Old);
110 }
111 };
Chad Rosier4a9d7952012-08-08 18:46:20 +0000112
Douglas Gregor577f75a2009-08-04 16:50:30 +0000113protected:
114 Sema &SemaRef;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000115
Douglas Gregordfca6f52012-02-13 22:00:16 +0000116 /// \brief The set of local declarations that have been transformed, for
117 /// cases where we are forced to build new declarations within the transformer
118 /// rather than in the subclass (e.g., lambda closure types).
119 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000120
Mike Stump1eb44332009-09-09 15:08:12 +0000121public:
Douglas Gregor577f75a2009-08-04 16:50:30 +0000122 /// \brief Initializes a new tree transformer.
Douglas Gregorb99268b2010-12-21 00:52:54 +0000123 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000124
Douglas Gregor577f75a2009-08-04 16:50:30 +0000125 /// \brief Retrieves a reference to the derived class.
126 Derived &getDerived() { return static_cast<Derived&>(*this); }
127
128 /// \brief Retrieves a reference to the derived class.
Mike Stump1eb44332009-09-09 15:08:12 +0000129 const Derived &getDerived() const {
130 return static_cast<const Derived&>(*this);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000131 }
132
John McCall60d7b3a2010-08-24 06:29:42 +0000133 static inline ExprResult Owned(Expr *E) { return E; }
134 static inline StmtResult Owned(Stmt *S) { return S; }
John McCall9ae2f072010-08-23 23:25:46 +0000135
Douglas Gregor577f75a2009-08-04 16:50:30 +0000136 /// \brief Retrieves a reference to the semantic analysis object used for
137 /// this tree transform.
138 Sema &getSema() const { return SemaRef; }
Mike Stump1eb44332009-09-09 15:08:12 +0000139
Douglas Gregor577f75a2009-08-04 16:50:30 +0000140 /// \brief Whether the transformation should always rebuild AST nodes, even
141 /// if none of the children have changed.
142 ///
143 /// Subclasses may override this function to specify when the transformation
144 /// should rebuild all AST nodes.
145 bool AlwaysRebuild() { return false; }
Mike Stump1eb44332009-09-09 15:08:12 +0000146
Douglas Gregor577f75a2009-08-04 16:50:30 +0000147 /// \brief Returns the location of the entity being transformed, if that
148 /// information was not available elsewhere in the AST.
149 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000150 /// By default, returns no source-location information. Subclasses can
Douglas Gregor577f75a2009-08-04 16:50:30 +0000151 /// provide an alternative implementation that provides better location
152 /// information.
153 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump1eb44332009-09-09 15:08:12 +0000154
Douglas Gregor577f75a2009-08-04 16:50:30 +0000155 /// \brief Returns the name of the entity being transformed, if that
156 /// information was not available elsewhere in the AST.
157 ///
158 /// By default, returns an empty name. Subclasses can provide an alternative
159 /// implementation with a more precise name.
160 DeclarationName getBaseEntity() { return DeclarationName(); }
161
Douglas Gregorb98b1992009-08-11 05:31:07 +0000162 /// \brief Sets the "base" location and entity when that
163 /// information is known based on another transformation.
164 ///
165 /// By default, the source location and entity are ignored. Subclasses can
166 /// override this function to provide a customized implementation.
167 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000168
Douglas Gregorb98b1992009-08-11 05:31:07 +0000169 /// \brief RAII object that temporarily sets the base location and entity
170 /// used for reporting diagnostics in types.
171 class TemporaryBase {
172 TreeTransform &Self;
173 SourceLocation OldLocation;
174 DeclarationName OldEntity;
Mike Stump1eb44332009-09-09 15:08:12 +0000175
Douglas Gregorb98b1992009-08-11 05:31:07 +0000176 public:
177 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump1eb44332009-09-09 15:08:12 +0000178 DeclarationName Entity) : Self(Self) {
Douglas Gregorb98b1992009-08-11 05:31:07 +0000179 OldLocation = Self.getDerived().getBaseLocation();
180 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000181
Douglas Gregorae201f72011-01-25 17:51:48 +0000182 if (Location.isValid())
183 Self.getDerived().setBase(Location, Entity);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000184 }
Mike Stump1eb44332009-09-09 15:08:12 +0000185
Douglas Gregorb98b1992009-08-11 05:31:07 +0000186 ~TemporaryBase() {
187 Self.getDerived().setBase(OldLocation, OldEntity);
188 }
189 };
Mike Stump1eb44332009-09-09 15:08:12 +0000190
191 /// \brief Determine whether the given type \p T has already been
Douglas Gregor577f75a2009-08-04 16:50:30 +0000192 /// transformed.
193 ///
194 /// Subclasses can provide an alternative implementation of this routine
Mike Stump1eb44332009-09-09 15:08:12 +0000195 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregor577f75a2009-08-04 16:50:30 +0000196 /// not change. For example, template instantiation need not traverse
197 /// non-dependent types.
198 bool AlreadyTransformed(QualType T) {
199 return T.isNull();
200 }
201
Douglas Gregor6eef5192009-12-14 19:27:10 +0000202 /// \brief Determine whether the given call argument should be dropped, e.g.,
203 /// because it is a default argument.
204 ///
205 /// Subclasses can provide an alternative implementation of this routine to
206 /// determine which kinds of call arguments get dropped. By default,
207 /// CXXDefaultArgument nodes are dropped (prior to transformation).
208 bool DropCallArgument(Expr *E) {
209 return E->isDefaultArgument();
210 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000211
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000212 /// \brief Determine whether we should expand a pack expansion with the
213 /// given set of parameter packs into separate arguments by repeatedly
214 /// transforming the pattern.
215 ///
Douglas Gregorb99268b2010-12-21 00:52:54 +0000216 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000217 /// Subclasses can override this routine to provide different behavior.
218 ///
219 /// \param EllipsisLoc The location of the ellipsis that identifies the
220 /// pack expansion.
221 ///
222 /// \param PatternRange The source range that covers the entire pattern of
223 /// the pack expansion.
224 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000225 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000226 /// pattern.
227 ///
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000228 /// \param ShouldExpand Will be set to \c true if the transformer should
229 /// expand the corresponding pack expansions into separate arguments. When
230 /// set, \c NumExpansions must also be set.
231 ///
Douglas Gregord3731192011-01-10 07:32:04 +0000232 /// \param RetainExpansion Whether the caller should add an unexpanded
233 /// pack expansion after all of the expanded arguments. This is used
234 /// when extending explicitly-specified template argument packs per
235 /// C++0x [temp.arg.explicit]p9.
236 ///
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000237 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregorcded4f62011-01-14 17:04:44 +0000238 /// the expanded form of the corresponding pack expansion. This is both an
239 /// input and an output parameter, which can be set by the caller if the
240 /// number of expansions is known a priori (e.g., due to a prior substitution)
241 /// and will be set by the callee when the number of expansions is known.
242 /// The callee must set this value when \c ShouldExpand is \c true; it may
243 /// set this value in other cases.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000244 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000245 /// \returns true if an error occurred (e.g., because the parameter packs
246 /// are to be instantiated with arguments of different lengths), false
247 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000248 /// must be set.
249 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
250 SourceRange PatternRange,
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +0000251 ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000252 bool &ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +0000253 bool &RetainExpansion,
David Blaikiedc84cd52013-02-20 22:23:23 +0000254 Optional<unsigned> &NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000255 ShouldExpand = false;
256 return false;
257 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000258
Douglas Gregord3731192011-01-10 07:32:04 +0000259 /// \brief "Forget" about the partially-substituted pack template argument,
260 /// when performing an instantiation that must preserve the parameter pack
261 /// use.
262 ///
263 /// This routine is meant to be overridden by the template instantiator.
264 TemplateArgument ForgetPartiallySubstitutedPack() {
265 return TemplateArgument();
266 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000267
Douglas Gregord3731192011-01-10 07:32:04 +0000268 /// \brief "Remember" the partially-substituted pack template argument
269 /// after performing an instantiation that must preserve the parameter pack
270 /// use.
271 ///
272 /// This routine is meant to be overridden by the template instantiator.
273 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000274
Douglas Gregor12c9c002011-01-07 16:43:16 +0000275 /// \brief Note to the derived class when a function parameter pack is
276 /// being expanded.
277 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000278
Douglas Gregor577f75a2009-08-04 16:50:30 +0000279 /// \brief Transforms the given type into another type.
280 ///
John McCalla2becad2009-10-21 00:40:46 +0000281 /// By default, this routine transforms a type by creating a
John McCalla93c9342009-12-07 02:54:59 +0000282 /// TypeSourceInfo for it and delegating to the appropriate
John McCalla2becad2009-10-21 00:40:46 +0000283 /// function. This is expensive, but we don't mind, because
284 /// this method is deprecated anyway; all users should be
John McCalla93c9342009-12-07 02:54:59 +0000285 /// switched to storing TypeSourceInfos.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000286 ///
287 /// \returns the transformed type.
John McCall43fed0d2010-11-12 08:19:04 +0000288 QualType TransformType(QualType T);
Mike Stump1eb44332009-09-09 15:08:12 +0000289
John McCalla2becad2009-10-21 00:40:46 +0000290 /// \brief Transforms the given type-with-location into a new
291 /// type-with-location.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000292 ///
John McCalla2becad2009-10-21 00:40:46 +0000293 /// By default, this routine transforms a type by delegating to the
294 /// appropriate TransformXXXType to build a new type. Subclasses
295 /// may override this function (to take over all type
296 /// transformations) or some set of the TransformXXXType functions
297 /// to alter the transformation.
John McCall43fed0d2010-11-12 08:19:04 +0000298 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCalla2becad2009-10-21 00:40:46 +0000299
300 /// \brief Transform the given type-with-location into a new
301 /// type, collecting location information in the given builder
302 /// as necessary.
303 ///
John McCall43fed0d2010-11-12 08:19:04 +0000304 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump1eb44332009-09-09 15:08:12 +0000305
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000306 /// \brief Transform the given statement.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000307 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000308 /// By default, this routine transforms a statement by delegating to the
Douglas Gregor43959a92009-08-20 07:17:43 +0000309 /// appropriate TransformXXXStmt function to transform a specific kind of
310 /// statement or the TransformExpr() function to transform an expression.
311 /// Subclasses may override this function to transform statements using some
312 /// other mechanism.
313 ///
314 /// \returns the transformed statement.
John McCall60d7b3a2010-08-24 06:29:42 +0000315 StmtResult TransformStmt(Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +0000316
Alexey Bataev4fa7eab2013-07-19 03:13:43 +0000317 /// \brief Transform the given statement.
318 ///
319 /// By default, this routine transforms a statement by delegating to the
320 /// appropriate TransformOMPXXXClause function to transform a specific kind
321 /// of clause. Subclasses may override this function to transform statements
322 /// using some other mechanism.
323 ///
324 /// \returns the transformed OpenMP clause.
325 OMPClause *TransformOMPClause(OMPClause *S);
326
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000327 /// \brief Transform the given expression.
328 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000329 /// By default, this routine transforms an expression by delegating to the
330 /// appropriate TransformXXXExpr function to build a new expression.
331 /// Subclasses may override this function to transform expressions using some
332 /// other mechanism.
333 ///
334 /// \returns the transformed expression.
John McCall60d7b3a2010-08-24 06:29:42 +0000335 ExprResult TransformExpr(Expr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000336
Richard Smithc83c2302012-12-19 01:39:02 +0000337 /// \brief Transform the given initializer.
338 ///
339 /// By default, this routine transforms an initializer by stripping off the
340 /// semantic nodes added by initialization, then passing the result to
341 /// TransformExpr or TransformExprs.
342 ///
343 /// \returns the transformed initializer.
344 ExprResult TransformInitializer(Expr *Init, bool CXXDirectInit);
345
Douglas Gregoraa165f82011-01-03 19:04:46 +0000346 /// \brief Transform the given list of expressions.
347 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000348 /// This routine transforms a list of expressions by invoking
349 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregoraa165f82011-01-03 19:04:46 +0000350 /// support for variadic templates by expanding any pack expansions (if the
351 /// derived class permits such expansion) along the way. When pack expansions
352 /// are present, the number of outputs may not equal the number of inputs.
353 ///
354 /// \param Inputs The set of expressions to be transformed.
355 ///
356 /// \param NumInputs The number of expressions in \c Inputs.
357 ///
358 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier4a9d7952012-08-08 18:46:20 +0000359 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregoraa165f82011-01-03 19:04:46 +0000360 /// be.
361 ///
362 /// \param Outputs The transformed input expressions will be added to this
363 /// vector.
364 ///
365 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
366 /// due to transformation.
367 ///
368 /// \returns true if an error occurred, false otherwise.
369 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +0000370 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +0000371 bool *ArgChanged = 0);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000372
Douglas Gregor577f75a2009-08-04 16:50:30 +0000373 /// \brief Transform the given declaration, which is referenced from a type
374 /// or expression.
375 ///
Douglas Gregordfca6f52012-02-13 22:00:16 +0000376 /// By default, acts as the identity function on declarations, unless the
377 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregordcee1a12009-08-06 05:28:30 +0000378 /// may override this function to provide alternate behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000379 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregordfca6f52012-02-13 22:00:16 +0000380 llvm::DenseMap<Decl *, Decl *>::iterator Known
381 = TransformedLocalDecls.find(D);
382 if (Known != TransformedLocalDecls.end())
383 return Known->second;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000384
385 return D;
Douglas Gregordfca6f52012-02-13 22:00:16 +0000386 }
Douglas Gregor43959a92009-08-20 07:17:43 +0000387
Chad Rosier4a9d7952012-08-08 18:46:20 +0000388 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregordfca6f52012-02-13 22:00:16 +0000389 /// place them on the new declaration.
390 ///
391 /// By default, this operation does nothing. Subclasses may override this
392 /// behavior to transform attributes.
393 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000394
Douglas Gregordfca6f52012-02-13 22:00:16 +0000395 /// \brief Note that a local declaration has been transformed by this
396 /// transformer.
397 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000398 /// Local declarations are typically transformed via a call to
Douglas Gregordfca6f52012-02-13 22:00:16 +0000399 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
400 /// the transformer itself has to transform the declarations. This routine
401 /// can be overridden by a subclass that keeps track of such mappings.
402 void transformedLocalDecl(Decl *Old, Decl *New) {
403 TransformedLocalDecls[Old] = New;
404 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000405
Douglas Gregor43959a92009-08-20 07:17:43 +0000406 /// \brief Transform the definition of the given declaration.
407 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000408 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregor43959a92009-08-20 07:17:43 +0000409 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000410 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
411 return getDerived().TransformDecl(Loc, D);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000412 }
Mike Stump1eb44332009-09-09 15:08:12 +0000413
Douglas Gregor6cd21982009-10-20 05:58:46 +0000414 /// \brief Transform the given declaration, which was the first part of a
415 /// nested-name-specifier in a member access expression.
416 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000417 /// This specific declaration transformation only applies to the first
Douglas Gregor6cd21982009-10-20 05:58:46 +0000418 /// identifier in a nested-name-specifier of a member access expression, e.g.,
419 /// the \c T in \c x->T::member
420 ///
421 /// By default, invokes TransformDecl() to transform the declaration.
422 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000423 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
424 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregor6cd21982009-10-20 05:58:46 +0000425 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000426
Douglas Gregorc22b5ff2011-02-25 02:25:35 +0000427 /// \brief Transform the given nested-name-specifier with source-location
428 /// information.
429 ///
430 /// By default, transforms all of the types and declarations within the
431 /// nested-name-specifier. Subclasses may override this function to provide
432 /// alternate behavior.
433 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
434 NestedNameSpecifierLoc NNS,
435 QualType ObjectType = QualType(),
436 NamedDecl *FirstQualifierInScope = 0);
437
Douglas Gregor81499bb2009-09-03 22:13:48 +0000438 /// \brief Transform the given declaration name.
439 ///
440 /// By default, transforms the types of conversion function, constructor,
441 /// and destructor names and then (if needed) rebuilds the declaration name.
442 /// Identifiers and selectors are returned unmodified. Sublcasses may
443 /// override this function to provide alternate behavior.
Abramo Bagnara25777432010-08-11 22:01:17 +0000444 DeclarationNameInfo
John McCall43fed0d2010-11-12 08:19:04 +0000445 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump1eb44332009-09-09 15:08:12 +0000446
Douglas Gregor577f75a2009-08-04 16:50:30 +0000447 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000448 ///
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000449 /// \param SS The nested-name-specifier that qualifies the template
450 /// name. This nested-name-specifier must already have been transformed.
451 ///
452 /// \param Name The template name to transform.
453 ///
454 /// \param NameLoc The source location of the template name.
455 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000456 /// \param ObjectType If we're translating a template name within a member
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000457 /// access expression, this is the type of the object whose member template
458 /// is being referenced.
459 ///
460 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
461 /// also refers to a name within the current (lexical) scope, this is the
462 /// declaration it refers to.
463 ///
464 /// By default, transforms the template name by transforming the declarations
465 /// and nested-name-specifiers that occur within the template name.
466 /// Subclasses may override this function to provide alternate behavior.
467 TemplateName TransformTemplateName(CXXScopeSpec &SS,
468 TemplateName Name,
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000469 SourceLocation NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000470 QualType ObjectType = QualType(),
471 NamedDecl *FirstQualifierInScope = 0);
472
Douglas Gregor577f75a2009-08-04 16:50:30 +0000473 /// \brief Transform the given template argument.
474 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000475 /// By default, this operation transforms the type, expression, or
476 /// declaration stored within the template argument and constructs a
Douglas Gregor670444e2009-08-04 22:27:00 +0000477 /// new template argument from the transformed result. Subclasses may
478 /// override this function to provide alternate behavior.
John McCall833ca992009-10-29 08:12:44 +0000479 ///
480 /// Returns true if there was an error.
481 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
482 TemplateArgumentLoc &Output);
483
Douglas Gregorfcc12532010-12-20 17:31:10 +0000484 /// \brief Transform the given set of template arguments.
485 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000486 /// By default, this operation transforms all of the template arguments
Douglas Gregorfcc12532010-12-20 17:31:10 +0000487 /// in the input set using \c TransformTemplateArgument(), and appends
488 /// the transformed arguments to the output list.
489 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000490 /// Note that this overload of \c TransformTemplateArguments() is merely
491 /// a convenience function. Subclasses that wish to override this behavior
492 /// should override the iterator-based member template version.
493 ///
Douglas Gregorfcc12532010-12-20 17:31:10 +0000494 /// \param Inputs The set of template arguments to be transformed.
495 ///
496 /// \param NumInputs The number of template arguments in \p Inputs.
497 ///
498 /// \param Outputs The set of transformed template arguments output by this
499 /// routine.
500 ///
501 /// Returns true if an error occurred.
502 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
503 unsigned NumInputs,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000504 TemplateArgumentListInfo &Outputs) {
505 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
506 }
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000507
508 /// \brief Transform the given set of template arguments.
509 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000510 /// By default, this operation transforms all of the template arguments
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000511 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier4a9d7952012-08-08 18:46:20 +0000512 /// the transformed arguments to the output list.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000513 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000514 /// \param First An iterator to the first template argument.
515 ///
516 /// \param Last An iterator one step past the last template argument.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000517 ///
518 /// \param Outputs The set of transformed template arguments output by this
519 /// routine.
520 ///
521 /// Returns true if an error occurred.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000522 template<typename InputIterator>
523 bool TransformTemplateArguments(InputIterator First,
524 InputIterator Last,
525 TemplateArgumentListInfo &Outputs);
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000526
John McCall833ca992009-10-29 08:12:44 +0000527 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
528 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
529 TemplateArgumentLoc &ArgLoc);
530
John McCalla93c9342009-12-07 02:54:59 +0000531 /// \brief Fakes up a TypeSourceInfo for a type.
532 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
533 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall833ca992009-10-29 08:12:44 +0000534 getDerived().getBaseLocation());
535 }
Mike Stump1eb44332009-09-09 15:08:12 +0000536
John McCalla2becad2009-10-21 00:40:46 +0000537#define ABSTRACT_TYPELOC(CLASS, PARENT)
538#define TYPELOC(CLASS, PARENT) \
John McCall43fed0d2010-11-12 08:19:04 +0000539 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCalla2becad2009-10-21 00:40:46 +0000540#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000541
Douglas Gregorcefc3af2012-04-16 07:05:22 +0000542 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
543 FunctionProtoTypeLoc TL,
544 CXXRecordDecl *ThisContext,
545 unsigned ThisTypeQuals);
546
David Majnemerfc210492013-10-15 09:33:02 +0000547 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley28bbe4b2011-04-28 01:08:34 +0000548
Chad Rosier4a9d7952012-08-08 18:46:20 +0000549 QualType
John McCall43fed0d2010-11-12 08:19:04 +0000550 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
551 TemplateSpecializationTypeLoc TL,
552 TemplateName Template);
553
Chad Rosier4a9d7952012-08-08 18:46:20 +0000554 QualType
John McCall43fed0d2010-11-12 08:19:04 +0000555 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
556 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +0000557 TemplateName Template,
558 CXXScopeSpec &SS);
Douglas Gregora88f09f2011-02-28 17:23:35 +0000559
Chad Rosier4a9d7952012-08-08 18:46:20 +0000560 QualType
Douglas Gregora88f09f2011-02-28 17:23:35 +0000561 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000562 DependentTemplateSpecializationTypeLoc TL,
563 NestedNameSpecifierLoc QualifierLoc);
564
John McCall21ef0fa2010-03-11 09:03:00 +0000565 /// \brief Transforms the parameters of a function type into the
566 /// given vectors.
567 ///
568 /// The result vectors should be kept in sync; null entries in the
569 /// variables vector are acceptable.
570 ///
571 /// Return true on error.
Douglas Gregora009b592011-01-07 00:20:55 +0000572 bool TransformFunctionTypeParams(SourceLocation Loc,
573 ParmVarDecl **Params, unsigned NumParams,
574 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +0000575 SmallVectorImpl<QualType> &PTypes,
576 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall21ef0fa2010-03-11 09:03:00 +0000577
578 /// \brief Transforms a single function-type parameter. Return null
579 /// on error.
John McCallfb44de92011-05-01 22:35:37 +0000580 ///
581 /// \param indexAdjustment - A number to add to the parameter's
582 /// scope index; can be negative
Douglas Gregor6a24bfd2011-01-14 22:40:04 +0000583 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +0000584 int indexAdjustment,
David Blaikiedc84cd52013-02-20 22:23:23 +0000585 Optional<unsigned> NumExpansions,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +0000586 bool ExpectParameterPack);
John McCall21ef0fa2010-03-11 09:03:00 +0000587
John McCall43fed0d2010-11-12 08:19:04 +0000588 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall833ca992009-10-29 08:12:44 +0000589
John McCall60d7b3a2010-08-24 06:29:42 +0000590 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
591 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000592
Richard Smith612409e2012-07-25 03:56:55 +0000593 /// \brief Transform the captures and body of a lambda expression.
594 ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator);
595
Faisal Valia3d311e2013-10-23 06:44:28 +0000596 TemplateParameterList *TransformTemplateParameterList(
597 TemplateParameterList *TPL) {
598 return TPL;
599 }
600
Richard Smithefeeccf2012-10-21 03:28:35 +0000601 ExprResult TransformAddressOfOperand(Expr *E);
602 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
603 bool IsAddressOfOperand);
604
Eli Friedman1ac6c932013-09-06 01:13:30 +0000605// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
606// amount of stack usage with clang.
Douglas Gregor43959a92009-08-20 07:17:43 +0000607#define STMT(Node, Parent) \
Eli Friedman1ac6c932013-09-06 01:13:30 +0000608 LLVM_ATTRIBUTE_NOINLINE \
John McCall60d7b3a2010-08-24 06:29:42 +0000609 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000610#define EXPR(Node, Parent) \
Eli Friedman1ac6c932013-09-06 01:13:30 +0000611 LLVM_ATTRIBUTE_NOINLINE \
John McCall60d7b3a2010-08-24 06:29:42 +0000612 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000613#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000614#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000615
Alexey Bataev4fa7eab2013-07-19 03:13:43 +0000616#define OPENMP_CLAUSE(Name, Class) \
Eli Friedman1ac6c932013-09-06 01:13:30 +0000617 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev4fa7eab2013-07-19 03:13:43 +0000618 OMPClause *Transform ## Class(Class *S);
619#include "clang/Basic/OpenMPKinds.def"
620
Douglas Gregor577f75a2009-08-04 16:50:30 +0000621 /// \brief Build a new pointer type given its pointee type.
622 ///
623 /// By default, performs semantic analysis when building the pointer type.
624 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000625 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000626
627 /// \brief Build a new block pointer type given its pointee type.
628 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000629 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000630 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000631 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000632
John McCall85737a72009-10-30 00:06:24 +0000633 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000634 ///
John McCall85737a72009-10-30 00:06:24 +0000635 /// By default, performs semantic analysis when building the
636 /// reference type. Subclasses may override this routine to provide
637 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000638 ///
John McCall85737a72009-10-30 00:06:24 +0000639 /// \param LValue whether the type was written with an lvalue sigil
640 /// or an rvalue sigil.
641 QualType RebuildReferenceType(QualType ReferentType,
642 bool LValue,
643 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000644
Douglas Gregor577f75a2009-08-04 16:50:30 +0000645 /// \brief Build a new member pointer type given the pointee type and the
646 /// class type it refers into.
647 ///
648 /// By default, performs semantic analysis when building the member pointer
649 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000650 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
651 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000652
Douglas Gregor577f75a2009-08-04 16:50:30 +0000653 /// \brief Build a new array type given the element type, size
654 /// modifier, size of the array (if known), size expression, and index type
655 /// qualifiers.
656 ///
657 /// By default, performs semantic analysis when building the array type.
658 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000659 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000660 QualType RebuildArrayType(QualType ElementType,
661 ArrayType::ArraySizeModifier SizeMod,
662 const llvm::APInt *Size,
663 Expr *SizeExpr,
664 unsigned IndexTypeQuals,
665 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000666
Douglas Gregor577f75a2009-08-04 16:50:30 +0000667 /// \brief Build a new constant array type given the element type, size
668 /// modifier, (known) size of the array, and index type qualifiers.
669 ///
670 /// By default, performs semantic analysis when building the array type.
671 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000672 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000673 ArrayType::ArraySizeModifier SizeMod,
674 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000675 unsigned IndexTypeQuals,
676 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000677
Douglas Gregor577f75a2009-08-04 16:50:30 +0000678 /// \brief Build a new incomplete array type given the element type, size
679 /// modifier, and index type qualifiers.
680 ///
681 /// By default, performs semantic analysis when building the array type.
682 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000683 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000684 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000685 unsigned IndexTypeQuals,
686 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000687
Mike Stump1eb44332009-09-09 15:08:12 +0000688 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000689 /// size modifier, size expression, and index type qualifiers.
690 ///
691 /// By default, performs semantic analysis when building the array type.
692 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000693 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000694 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000695 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000696 unsigned IndexTypeQuals,
697 SourceRange BracketsRange);
698
Mike Stump1eb44332009-09-09 15:08:12 +0000699 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000700 /// size modifier, size expression, and index type qualifiers.
701 ///
702 /// By default, performs semantic analysis when building the array type.
703 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000704 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000705 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000706 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000707 unsigned IndexTypeQuals,
708 SourceRange BracketsRange);
709
710 /// \brief Build a new vector type given the element type and
711 /// number of elements.
712 ///
713 /// By default, performs semantic analysis when building the vector type.
714 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000715 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000716 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000717
Douglas Gregor577f75a2009-08-04 16:50:30 +0000718 /// \brief Build a new extended vector type given the element type and
719 /// number of elements.
720 ///
721 /// By default, performs semantic analysis when building the vector type.
722 /// Subclasses may override this routine to provide different behavior.
723 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
724 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000725
726 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000727 /// given the element type and number of elements.
728 ///
729 /// By default, performs semantic analysis when building the vector type.
730 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000731 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000732 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000733 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000734
Douglas Gregor577f75a2009-08-04 16:50:30 +0000735 /// \brief Build a new function type.
736 ///
737 /// By default, performs semantic analysis when building the function type.
738 /// Subclasses may override this routine to provide different behavior.
739 QualType RebuildFunctionProtoType(QualType T,
Jordan Rosebea522f2013-03-08 21:51:21 +0000740 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +0000741 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump1eb44332009-09-09 15:08:12 +0000742
John McCalla2becad2009-10-21 00:40:46 +0000743 /// \brief Build a new unprototyped function type.
744 QualType RebuildFunctionNoProtoType(QualType ResultType);
745
John McCalled976492009-12-04 22:46:56 +0000746 /// \brief Rebuild an unresolved typename type, given the decl that
747 /// the UnresolvedUsingTypenameDecl was transformed to.
748 QualType RebuildUnresolvedUsingType(Decl *D);
749
Douglas Gregor577f75a2009-08-04 16:50:30 +0000750 /// \brief Build a new typedef type.
Richard Smith162e1c12011-04-15 14:24:37 +0000751 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregor577f75a2009-08-04 16:50:30 +0000752 return SemaRef.Context.getTypeDeclType(Typedef);
753 }
754
755 /// \brief Build a new class/struct/union type.
756 QualType RebuildRecordType(RecordDecl *Record) {
757 return SemaRef.Context.getTypeDeclType(Record);
758 }
759
760 /// \brief Build a new Enum type.
761 QualType RebuildEnumType(EnumDecl *Enum) {
762 return SemaRef.Context.getTypeDeclType(Enum);
763 }
John McCall7da24312009-09-05 00:15:47 +0000764
Mike Stump1eb44332009-09-09 15:08:12 +0000765 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000766 ///
767 /// By default, performs semantic analysis when building the typeof type.
768 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000769 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000770
Mike Stump1eb44332009-09-09 15:08:12 +0000771 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000772 ///
773 /// By default, builds a new TypeOfType with the given underlying type.
774 QualType RebuildTypeOfType(QualType Underlying);
775
Sean Huntca63c202011-05-24 22:41:36 +0000776 /// \brief Build a new unary transform type.
777 QualType RebuildUnaryTransformType(QualType BaseType,
778 UnaryTransformType::UTTKind UKind,
779 SourceLocation Loc);
780
Richard Smitha2c36462013-04-26 16:15:35 +0000781 /// \brief Build a new C++11 decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000782 ///
783 /// By default, performs semantic analysis when building the decltype type.
784 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000785 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000786
Richard Smitha2c36462013-04-26 16:15:35 +0000787 /// \brief Build a new C++11 auto type.
Richard Smith34b41d92011-02-20 03:19:35 +0000788 ///
789 /// By default, builds a new AutoType with the given deduced type.
Richard Smitha2c36462013-04-26 16:15:35 +0000790 QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) {
Richard Smithdc7a4f52013-04-30 13:56:41 +0000791 // Note, IsDependent is always false here: we implicitly convert an 'auto'
792 // which has been deduced to a dependent type into an undeduced 'auto', so
793 // that we'll retry deduction after the transformation.
Faisal Valifad9e132013-09-26 19:54:12 +0000794 return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto,
795 /*IsDependent*/ false);
Richard Smith34b41d92011-02-20 03:19:35 +0000796 }
797
Douglas Gregor577f75a2009-08-04 16:50:30 +0000798 /// \brief Build a new template specialization type.
799 ///
800 /// By default, performs semantic analysis when building the template
801 /// specialization type. Subclasses may override this routine to provide
802 /// different behavior.
803 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000804 SourceLocation TemplateLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000805 TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000806
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000807 /// \brief Build a new parenthesized type.
808 ///
809 /// By default, builds a new ParenType type from the inner type.
810 /// Subclasses may override this routine to provide different behavior.
811 QualType RebuildParenType(QualType InnerType) {
812 return SemaRef.Context.getParenType(InnerType);
813 }
814
Douglas Gregor577f75a2009-08-04 16:50:30 +0000815 /// \brief Build a new qualified name type.
816 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000817 /// By default, builds a new ElaboratedType type from the keyword,
818 /// the nested-name-specifier and the named type.
819 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000820 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
821 ElaboratedTypeKeyword Keyword,
Douglas Gregor9e876872011-03-01 18:12:44 +0000822 NestedNameSpecifierLoc QualifierLoc,
823 QualType Named) {
Chad Rosier4a9d7952012-08-08 18:46:20 +0000824 return SemaRef.Context.getElaboratedType(Keyword,
825 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor9e876872011-03-01 18:12:44 +0000826 Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000827 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000828
829 /// \brief Build a new typename type that refers to a template-id.
830 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000831 /// By default, builds a new DependentNameType type from the
832 /// nested-name-specifier and the given type. Subclasses may override
833 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000834 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000835 ElaboratedTypeKeyword Keyword,
836 NestedNameSpecifierLoc QualifierLoc,
837 const IdentifierInfo *Name,
838 SourceLocation NameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000839 TemplateArgumentListInfo &Args) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000840 // Rebuild the template name.
841 // TODO: avoid TemplateName abstraction
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000842 CXXScopeSpec SS;
843 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000844 TemplateName InstName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000845 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000846
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000847 if (InstName.isNull())
848 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000849
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000850 // If it's still dependent, make a dependent specialization.
851 if (InstName.getAsDependentTemplateName())
Chad Rosier4a9d7952012-08-08 18:46:20 +0000852 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
853 QualifierLoc.getNestedNameSpecifier(),
854 Name,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000855 Args);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000856
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000857 // Otherwise, make an elaborated type wrapping a non-dependent
858 // specialization.
859 QualType T =
860 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
861 if (T.isNull()) return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000862
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000863 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
864 return T;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000865
866 return SemaRef.Context.getElaboratedType(Keyword,
867 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000868 T);
869 }
870
Douglas Gregor577f75a2009-08-04 16:50:30 +0000871 /// \brief Build a new typename type that refers to an identifier.
872 ///
873 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000874 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000875 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000876 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000877 SourceLocation KeywordLoc,
Douglas Gregor2494dd02011-03-01 01:34:45 +0000878 NestedNameSpecifierLoc QualifierLoc,
879 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000880 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000881 CXXScopeSpec SS;
Douglas Gregor2494dd02011-03-01 01:34:45 +0000882 SS.Adopt(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000883
Douglas Gregor2494dd02011-03-01 01:34:45 +0000884 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000885 // If the name is still dependent, just build a new dependent name type.
886 if (!SemaRef.computeDeclContext(SS))
Chad Rosier4a9d7952012-08-08 18:46:20 +0000887 return SemaRef.Context.getDependentNameType(Keyword,
888 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000889 Id);
Douglas Gregor40336422010-03-31 22:19:08 +0000890 }
891
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000892 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor2494dd02011-03-01 01:34:45 +0000893 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregore29425b2011-02-28 22:42:13 +0000894 *Id, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000895
896 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
897
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000898 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000899 // into a non-dependent elaborated-type-specifier. Find the tag we're
900 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000901 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000902 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
903 if (!DC)
904 return QualType();
905
John McCall56138762010-05-27 06:40:31 +0000906 if (SemaRef.RequireCompleteDeclContext(SS, DC))
907 return QualType();
908
Douglas Gregor40336422010-03-31 22:19:08 +0000909 TagDecl *Tag = 0;
910 SemaRef.LookupQualifiedName(Result, DC);
911 switch (Result.getResultKind()) {
912 case LookupResult::NotFound:
913 case LookupResult::NotFoundInCurrentInstantiation:
914 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000915
Douglas Gregor40336422010-03-31 22:19:08 +0000916 case LookupResult::Found:
917 Tag = Result.getAsSingle<TagDecl>();
918 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000919
Douglas Gregor40336422010-03-31 22:19:08 +0000920 case LookupResult::FoundOverloaded:
921 case LookupResult::FoundUnresolvedValue:
922 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier4a9d7952012-08-08 18:46:20 +0000923
Douglas Gregor40336422010-03-31 22:19:08 +0000924 case LookupResult::Ambiguous:
925 // Let the LookupResult structure handle ambiguities.
926 return QualType();
927 }
928
929 if (!Tag) {
Nick Lewycky446e4022011-01-24 19:01:04 +0000930 // Check where the name exists but isn't a tag type and use that to emit
931 // better diagnostics.
932 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
933 SemaRef.LookupQualifiedName(Result, DC);
934 switch (Result.getResultKind()) {
935 case LookupResult::Found:
936 case LookupResult::FoundOverloaded:
937 case LookupResult::FoundUnresolvedValue: {
Richard Smith3e4c6c42011-05-05 21:57:07 +0000938 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky446e4022011-01-24 19:01:04 +0000939 unsigned Kind = 0;
940 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smith162e1c12011-04-15 14:24:37 +0000941 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
942 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky446e4022011-01-24 19:01:04 +0000943 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
944 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
945 break;
Richard Smith3e4c6c42011-05-05 21:57:07 +0000946 }
Nick Lewycky446e4022011-01-24 19:01:04 +0000947 default:
948 // FIXME: Would be nice to highlight just the source range.
949 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
950 << Kind << Id << DC;
951 break;
952 }
Douglas Gregor40336422010-03-31 22:19:08 +0000953 return QualType();
954 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000955
Richard Trieubbf34c02011-06-10 03:11:26 +0000956 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
957 IdLoc, *Id)) {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000958 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000959 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
960 return QualType();
961 }
962
963 // Build the elaborated-type-specifier type.
964 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000965 return SemaRef.Context.getElaboratedType(Keyword,
966 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000967 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000968 }
Mike Stump1eb44332009-09-09 15:08:12 +0000969
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000970 /// \brief Build a new pack expansion type.
971 ///
972 /// By default, builds a new PackExpansionType type from the given pattern.
973 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000974 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000975 SourceRange PatternRange,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000976 SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +0000977 Optional<unsigned> NumExpansions) {
Douglas Gregorcded4f62011-01-14 17:04:44 +0000978 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
979 NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000980 }
981
Eli Friedmanb001de72011-10-06 23:00:33 +0000982 /// \brief Build a new atomic type given its value type.
983 ///
984 /// By default, performs semantic analysis when building the atomic type.
985 /// Subclasses may override this routine to provide different behavior.
986 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
987
Douglas Gregord1067e52009-08-06 06:41:21 +0000988 /// \brief Build a new template name given a nested name specifier, a flag
989 /// indicating whether the "template" keyword was provided, and the template
990 /// that the template name refers to.
991 ///
992 /// By default, builds the new template name directly. Subclasses may override
993 /// this routine to provide different behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000994 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +0000995 bool TemplateKW,
996 TemplateDecl *Template);
997
Douglas Gregord1067e52009-08-06 06:41:21 +0000998 /// \brief Build a new template name given a nested name specifier and the
999 /// name that is referred to as a template.
1000 ///
1001 /// By default, performs semantic analysis to determine whether the name can
1002 /// be resolved to a specific template, then builds the appropriate kind of
1003 /// template name. Subclasses may override this routine to provide different
1004 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00001005 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1006 const IdentifierInfo &Name,
1007 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00001008 QualType ObjectType,
1009 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +00001010
Douglas Gregorca1bdd72009-11-04 00:56:37 +00001011 /// \brief Build a new template name given a nested name specifier and the
1012 /// overloaded operator name that is referred to as a template.
1013 ///
1014 /// By default, performs semantic analysis to determine whether the name can
1015 /// be resolved to a specific template, then builds the appropriate kind of
1016 /// template name. Subclasses may override this routine to provide different
1017 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00001018 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00001019 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00001020 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00001021 QualType ObjectType);
Douglas Gregor1aee05d2011-01-15 06:45:20 +00001022
1023 /// \brief Build a new template name given a template template parameter pack
Chad Rosier4a9d7952012-08-08 18:46:20 +00001024 /// and the
Douglas Gregor1aee05d2011-01-15 06:45:20 +00001025 ///
1026 /// By default, performs semantic analysis to determine whether the name can
1027 /// be resolved to a specific template, then builds the appropriate kind of
1028 /// template name. Subclasses may override this routine to provide different
1029 /// behavior.
1030 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1031 const TemplateArgument &ArgPack) {
1032 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1033 }
1034
Douglas Gregor43959a92009-08-20 07:17:43 +00001035 /// \brief Build a new compound statement.
1036 ///
1037 /// By default, performs semantic analysis to build the new statement.
1038 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001039 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001040 MultiStmtArg Statements,
1041 SourceLocation RBraceLoc,
1042 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +00001043 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00001044 IsStmtExpr);
1045 }
1046
1047 /// \brief Build a new case statement.
1048 ///
1049 /// By default, performs semantic analysis to build the new statement.
1050 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001051 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001052 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001053 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001054 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001055 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001056 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001057 ColonLoc);
1058 }
Mike Stump1eb44332009-09-09 15:08:12 +00001059
Douglas Gregor43959a92009-08-20 07:17:43 +00001060 /// \brief Attach the body to a new case statement.
1061 ///
1062 /// By default, performs semantic analysis to build the new statement.
1063 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001064 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001065 getSema().ActOnCaseStmtBody(S, Body);
1066 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +00001067 }
Mike Stump1eb44332009-09-09 15:08:12 +00001068
Douglas Gregor43959a92009-08-20 07:17:43 +00001069 /// \brief Build a new default statement.
1070 ///
1071 /// By default, performs semantic analysis to build the new statement.
1072 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001073 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001074 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001075 Stmt *SubStmt) {
1076 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +00001077 /*CurScope=*/0);
1078 }
Mike Stump1eb44332009-09-09 15:08:12 +00001079
Douglas Gregor43959a92009-08-20 07:17:43 +00001080 /// \brief Build a new label statement.
1081 ///
1082 /// By default, performs semantic analysis to build the new statement.
1083 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001084 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1085 SourceLocation ColonLoc, Stmt *SubStmt) {
1086 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregor43959a92009-08-20 07:17:43 +00001087 }
Mike Stump1eb44332009-09-09 15:08:12 +00001088
Richard Smith534986f2012-04-14 00:33:13 +00001089 /// \brief Build a new label statement.
1090 ///
1091 /// By default, performs semantic analysis to build the new statement.
1092 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko49908902012-07-09 10:04:07 +00001093 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1094 ArrayRef<const Attr*> Attrs,
Richard Smith534986f2012-04-14 00:33:13 +00001095 Stmt *SubStmt) {
1096 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1097 }
1098
Douglas Gregor43959a92009-08-20 07:17:43 +00001099 /// \brief Build a new "if" statement.
1100 ///
1101 /// By default, performs semantic analysis to build the new statement.
1102 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001103 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001104 VarDecl *CondVar, Stmt *Then,
Chris Lattner57ad3782011-02-17 20:34:02 +00001105 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001106 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +00001107 }
Mike Stump1eb44332009-09-09 15:08:12 +00001108
Douglas Gregor43959a92009-08-20 07:17:43 +00001109 /// \brief Start building a new switch statement.
1110 ///
1111 /// By default, performs semantic analysis to build the new statement.
1112 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001113 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001114 Expr *Cond, VarDecl *CondVar) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001115 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001116 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001117 }
Mike Stump1eb44332009-09-09 15:08:12 +00001118
Douglas Gregor43959a92009-08-20 07:17:43 +00001119 /// \brief Attach the body to the switch statement.
1120 ///
1121 /// By default, performs semantic analysis to build the new statement.
1122 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001123 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001124 Stmt *Switch, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001125 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001126 }
1127
1128 /// \brief Build a new while statement.
1129 ///
1130 /// By default, performs semantic analysis to build the new statement.
1131 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001132 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1133 VarDecl *CondVar, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001134 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001135 }
Mike Stump1eb44332009-09-09 15:08:12 +00001136
Douglas Gregor43959a92009-08-20 07:17:43 +00001137 /// \brief Build a new do-while statement.
1138 ///
1139 /// By default, performs semantic analysis to build the new statement.
1140 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001141 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001142 SourceLocation WhileLoc, SourceLocation LParenLoc,
1143 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001144 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1145 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001146 }
1147
1148 /// \brief Build a new for statement.
1149 ///
1150 /// By default, performs semantic analysis to build the new statement.
1151 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001152 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001153 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001154 VarDecl *CondVar, Sema::FullExprArg Inc,
1155 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001156 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001157 CondVar, Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001158 }
Mike Stump1eb44332009-09-09 15:08:12 +00001159
Douglas Gregor43959a92009-08-20 07:17:43 +00001160 /// \brief Build a new goto statement.
1161 ///
1162 /// By default, performs semantic analysis to build the new statement.
1163 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001164 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1165 LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001166 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregor43959a92009-08-20 07:17:43 +00001167 }
1168
1169 /// \brief Build a new indirect goto statement.
1170 ///
1171 /// By default, performs semantic analysis to build the new statement.
1172 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001173 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001174 SourceLocation StarLoc,
1175 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001176 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001177 }
Mike Stump1eb44332009-09-09 15:08:12 +00001178
Douglas Gregor43959a92009-08-20 07:17:43 +00001179 /// \brief Build a new return statement.
1180 ///
1181 /// By default, performs semantic analysis to build the new statement.
1182 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001183 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001184 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001185 }
Mike Stump1eb44332009-09-09 15:08:12 +00001186
Douglas Gregor43959a92009-08-20 07:17:43 +00001187 /// \brief Build a new declaration statement.
1188 ///
1189 /// By default, performs semantic analysis to build the new statement.
1190 /// Subclasses may override this routine to provide different behavior.
Rafael Espindola4549d7f2013-07-09 12:05:01 +00001191 StmtResult RebuildDeclStmt(llvm::MutableArrayRef<Decl *> Decls,
1192 SourceLocation StartLoc, SourceLocation EndLoc) {
1193 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith406c38e2011-02-23 00:37:57 +00001194 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001195 }
Mike Stump1eb44332009-09-09 15:08:12 +00001196
Anders Carlsson703e3942010-01-24 05:50:09 +00001197 /// \brief Build a new inline asm statement.
1198 ///
1199 /// By default, performs semantic analysis to build the new statement.
1200 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001201 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1202 bool IsVolatile, unsigned NumOutputs,
1203 unsigned NumInputs, IdentifierInfo **Names,
1204 MultiExprArg Constraints, MultiExprArg Exprs,
1205 Expr *AsmString, MultiExprArg Clobbers,
1206 SourceLocation RParenLoc) {
1207 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1208 NumInputs, Names, Constraints, Exprs,
1209 AsmString, Clobbers, RParenLoc);
Anders Carlsson703e3942010-01-24 05:50:09 +00001210 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001211
Chad Rosier8cd64b42012-06-11 20:47:18 +00001212 /// \brief Build a new MS style inline asm statement.
1213 ///
1214 /// By default, performs semantic analysis to build the new statement.
1215 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001216 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallaeeacf72013-05-03 00:10:13 +00001217 ArrayRef<Token> AsmToks,
1218 StringRef AsmString,
1219 unsigned NumOutputs, unsigned NumInputs,
1220 ArrayRef<StringRef> Constraints,
1221 ArrayRef<StringRef> Clobbers,
1222 ArrayRef<Expr*> Exprs,
1223 SourceLocation EndLoc) {
1224 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1225 NumOutputs, NumInputs,
1226 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier8cd64b42012-06-11 20:47:18 +00001227 }
1228
James Dennett699c9042012-06-15 07:13:21 +00001229 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001230 ///
1231 /// By default, performs semantic analysis to build the new statement.
1232 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001233 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001234 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001235 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001236 Stmt *Finally) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001237 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001238 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001239 }
1240
Douglas Gregorbe270a02010-04-26 17:57:08 +00001241 /// \brief Rebuild an Objective-C exception declaration.
1242 ///
1243 /// By default, performs semantic analysis to build the new declaration.
1244 /// Subclasses may override this routine to provide different behavior.
1245 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1246 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001247 return getSema().BuildObjCExceptionDecl(TInfo, T,
1248 ExceptionDecl->getInnerLocStart(),
1249 ExceptionDecl->getLocation(),
1250 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001251 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001252
James Dennett699c9042012-06-15 07:13:21 +00001253 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorbe270a02010-04-26 17:57:08 +00001254 ///
1255 /// By default, performs semantic analysis to build the new statement.
1256 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001257 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001258 SourceLocation RParenLoc,
1259 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001260 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001261 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001262 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001263 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001264
James Dennett699c9042012-06-15 07:13:21 +00001265 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001266 ///
1267 /// By default, performs semantic analysis to build the new statement.
1268 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001269 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001270 Stmt *Body) {
1271 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001272 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001273
James Dennett699c9042012-06-15 07:13:21 +00001274 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001275 ///
1276 /// By default, performs semantic analysis to build the new statement.
1277 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001278 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001279 Expr *Operand) {
1280 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001281 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001282
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00001283 /// \brief Build a new OpenMP parallel directive.
1284 ///
1285 /// By default, performs semantic analysis to build the new statement.
1286 /// Subclasses may override this routine to provide different behavior.
1287 StmtResult RebuildOMPParallelDirective(ArrayRef<OMPClause *> Clauses,
1288 Stmt *AStmt,
1289 SourceLocation StartLoc,
1290 SourceLocation EndLoc) {
1291 return getSema().ActOnOpenMPParallelDirective(Clauses, AStmt,
1292 StartLoc, EndLoc);
1293 }
1294
1295 /// \brief Build a new OpenMP 'default' clause.
1296 ///
1297 /// By default, performs semantic analysis to build the new statement.
1298 /// Subclasses may override this routine to provide different behavior.
1299 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1300 SourceLocation KindKwLoc,
1301 SourceLocation StartLoc,
1302 SourceLocation LParenLoc,
1303 SourceLocation EndLoc) {
1304 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1305 StartLoc, LParenLoc, EndLoc);
1306 }
1307
1308 /// \brief Build a new OpenMP 'private' clause.
1309 ///
1310 /// By default, performs semantic analysis to build the new statement.
1311 /// Subclasses may override this routine to provide different behavior.
1312 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1313 SourceLocation StartLoc,
1314 SourceLocation LParenLoc,
1315 SourceLocation EndLoc) {
1316 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1317 EndLoc);
1318 }
1319
Alexey Bataevd195bc32013-10-01 05:32:34 +00001320 /// \brief Build a new OpenMP 'firstprivate' clause.
1321 ///
1322 /// By default, performs semantic analysis to build the new statement.
1323 /// Subclasses may override this routine to provide different behavior.
1324 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1325 SourceLocation StartLoc,
1326 SourceLocation LParenLoc,
1327 SourceLocation EndLoc) {
1328 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1329 EndLoc);
1330 }
1331
Alexey Bataev0c018352013-09-06 18:03:48 +00001332 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1333 SourceLocation StartLoc,
1334 SourceLocation LParenLoc,
1335 SourceLocation EndLoc) {
1336 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1337 EndLoc);
1338 }
1339
James Dennett699c9042012-06-15 07:13:21 +00001340 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCall07524032011-07-27 21:50:02 +00001341 ///
1342 /// By default, performs semantic analysis to build the new statement.
1343 /// Subclasses may override this routine to provide different behavior.
1344 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1345 Expr *object) {
1346 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1347 }
1348
James Dennett699c9042012-06-15 07:13:21 +00001349 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001350 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001351 /// By default, performs semantic analysis to build the new statement.
1352 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001353 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall07524032011-07-27 21:50:02 +00001354 Expr *Object, Stmt *Body) {
1355 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001356 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001357
James Dennett699c9042012-06-15 07:13:21 +00001358 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCallf85e1932011-06-15 23:02:42 +00001359 ///
1360 /// By default, performs semantic analysis to build the new statement.
1361 /// Subclasses may override this routine to provide different behavior.
1362 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1363 Stmt *Body) {
1364 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1365 }
John McCall990567c2011-07-27 01:07:15 +00001366
Douglas Gregorc3203e72010-04-22 23:10:45 +00001367 /// \brief Build a new Objective-C fast enumeration statement.
1368 ///
1369 /// By default, performs semantic analysis to build the new statement.
1370 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001371 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001372 Stmt *Element,
1373 Expr *Collection,
1374 SourceLocation RParenLoc,
1375 Stmt *Body) {
Sam Panzerbc20bbb2012-08-16 21:47:25 +00001376 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001377 Element,
John McCall9ae2f072010-08-23 23:25:46 +00001378 Collection,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001379 RParenLoc);
1380 if (ForEachStmt.isInvalid())
1381 return StmtError();
1382
1383 return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001384 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001385
Douglas Gregor43959a92009-08-20 07:17:43 +00001386 /// \brief Build a new C++ exception declaration.
1387 ///
1388 /// By default, performs semantic analysis to build the new decaration.
1389 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001390 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001391 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001392 SourceLocation StartLoc,
1393 SourceLocation IdLoc,
1394 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001395 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1396 StartLoc, IdLoc, Id);
1397 if (Var)
1398 getSema().CurContext->addDecl(Var);
1399 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001400 }
1401
1402 /// \brief Build a new C++ catch statement.
1403 ///
1404 /// By default, performs semantic analysis to build the new statement.
1405 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001406 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001407 VarDecl *ExceptionDecl,
1408 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001409 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1410 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001411 }
Mike Stump1eb44332009-09-09 15:08:12 +00001412
Douglas Gregor43959a92009-08-20 07:17:43 +00001413 /// \brief Build a new C++ try statement.
1414 ///
1415 /// By default, performs semantic analysis to build the new statement.
1416 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelm21adb0c2013-08-22 09:20:03 +00001417 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1418 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001419 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00001420 }
Mike Stump1eb44332009-09-09 15:08:12 +00001421
Richard Smithad762fc2011-04-14 22:09:26 +00001422 /// \brief Build a new C++0x range-based for statement.
1423 ///
1424 /// By default, performs semantic analysis to build the new statement.
1425 /// Subclasses may override this routine to provide different behavior.
1426 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1427 SourceLocation ColonLoc,
1428 Stmt *Range, Stmt *BeginEnd,
1429 Expr *Cond, Expr *Inc,
1430 Stmt *LoopVar,
1431 SourceLocation RParenLoc) {
Douglas Gregor6f96f4b2013-04-08 18:40:13 +00001432 // If we've just learned that the range is actually an Objective-C
1433 // collection, treat this as an Objective-C fast enumeration loop.
1434 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1435 if (RangeStmt->isSingleDecl()) {
1436 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39b60dc2013-05-02 18:35:56 +00001437 if (RangeVar->isInvalidDecl())
1438 return StmtError();
1439
Douglas Gregor6f96f4b2013-04-08 18:40:13 +00001440 Expr *RangeExpr = RangeVar->getInit();
1441 if (!RangeExpr->isTypeDependent() &&
1442 RangeExpr->getType()->isObjCObjectPointerType())
1443 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1444 RParenLoc);
1445 }
1446 }
1447 }
1448
Richard Smithad762fc2011-04-14 22:09:26 +00001449 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smith8b533d92012-09-20 21:52:32 +00001450 Cond, Inc, LoopVar, RParenLoc,
1451 Sema::BFRK_Rebuild);
Richard Smithad762fc2011-04-14 22:09:26 +00001452 }
Douglas Gregorba0513d2011-10-25 01:33:02 +00001453
1454 /// \brief Build a new C++0x range-based for statement.
1455 ///
1456 /// By default, performs semantic analysis to build the new statement.
1457 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001458 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregorba0513d2011-10-25 01:33:02 +00001459 bool IsIfExists,
1460 NestedNameSpecifierLoc QualifierLoc,
1461 DeclarationNameInfo NameInfo,
1462 Stmt *Nested) {
1463 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1464 QualifierLoc, NameInfo, Nested);
1465 }
1466
Richard Smithad762fc2011-04-14 22:09:26 +00001467 /// \brief Attach body to a C++0x range-based for statement.
1468 ///
1469 /// By default, performs semantic analysis to finish the new statement.
1470 /// Subclasses may override this routine to provide different behavior.
1471 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1472 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1473 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001474
David Majnemerfc210492013-10-15 09:33:02 +00001475 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
1476 Stmt *TryBlock, Stmt *Handler) {
1477 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley28bbe4b2011-04-28 01:08:34 +00001478 }
1479
David Majnemerfc210492013-10-15 09:33:02 +00001480 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley28bbe4b2011-04-28 01:08:34 +00001481 Stmt *Block) {
David Majnemerfc210492013-10-15 09:33:02 +00001482 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley28bbe4b2011-04-28 01:08:34 +00001483 }
1484
David Majnemerfc210492013-10-15 09:33:02 +00001485 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
1486 return getSema().ActOnSEHFinallyBlock(Loc, Block);
John Wiegley28bbe4b2011-04-28 01:08:34 +00001487 }
1488
Douglas Gregorb98b1992009-08-11 05:31:07 +00001489 /// \brief Build a new expression that references a declaration.
1490 ///
1491 /// By default, performs semantic analysis to build the new expression.
1492 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001493 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001494 LookupResult &R,
1495 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001496 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1497 }
1498
1499
1500 /// \brief Build a new expression that references a declaration.
1501 ///
1502 /// By default, performs semantic analysis to build the new expression.
1503 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001504 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001505 ValueDecl *VD,
1506 const DeclarationNameInfo &NameInfo,
1507 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001508 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001509 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001510
1511 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001512
1513 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001514 }
Mike Stump1eb44332009-09-09 15:08:12 +00001515
Douglas Gregorb98b1992009-08-11 05:31:07 +00001516 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001517 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001518 /// By default, performs semantic analysis to build the new expression.
1519 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001520 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001521 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001522 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001523 }
1524
Douglas Gregora71d8192009-09-04 17:36:40 +00001525 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001526 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001527 /// By default, performs semantic analysis to build the new expression.
1528 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001529 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001530 SourceLocation OperatorLoc,
1531 bool isArrow,
1532 CXXScopeSpec &SS,
1533 TypeSourceInfo *ScopeType,
1534 SourceLocation CCLoc,
1535 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001536 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001537
Douglas Gregorb98b1992009-08-11 05:31:07 +00001538 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001539 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001540 /// By default, performs semantic analysis to build the new expression.
1541 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001542 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001543 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001544 Expr *SubExpr) {
1545 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001546 }
Mike Stump1eb44332009-09-09 15:08:12 +00001547
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001548 /// \brief Build a new builtin offsetof expression.
1549 ///
1550 /// By default, performs semantic analysis to build the new expression.
1551 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001552 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001553 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001554 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001555 unsigned NumComponents,
1556 SourceLocation RParenLoc) {
1557 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1558 NumComponents, RParenLoc);
1559 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001560
1561 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001562 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001563 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001564 /// By default, performs semantic analysis to build the new expression.
1565 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001566 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1567 SourceLocation OpLoc,
1568 UnaryExprOrTypeTrait ExprKind,
1569 SourceRange R) {
1570 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001571 }
1572
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001573 /// \brief Build a new sizeof, alignof or vec step expression with an
1574 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001575 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001576 /// By default, performs semantic analysis to build the new expression.
1577 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001578 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1579 UnaryExprOrTypeTrait ExprKind,
1580 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001581 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001582 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001583 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001584 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001585
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001586 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001587 }
Mike Stump1eb44332009-09-09 15:08:12 +00001588
Douglas Gregorb98b1992009-08-11 05:31:07 +00001589 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001590 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001591 /// By default, performs semantic analysis to build the new expression.
1592 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001593 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001594 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001595 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001596 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001597 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1598 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001599 RBracketLoc);
1600 }
1601
1602 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001603 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001604 /// By default, performs semantic analysis to build the new expression.
1605 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001606 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001607 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001608 SourceLocation RParenLoc,
1609 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001610 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001611 Args, RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001612 }
1613
1614 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001615 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001616 /// By default, performs semantic analysis to build the new expression.
1617 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001618 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001619 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001620 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001621 SourceLocation TemplateKWLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001622 const DeclarationNameInfo &MemberNameInfo,
1623 ValueDecl *Member,
1624 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001625 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001626 NamedDecl *FirstQualifierInScope) {
Richard Smith9138b4e2011-10-26 19:06:56 +00001627 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1628 isArrow);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001629 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001630 // We have a reference to an unnamed field. This is always the
1631 // base of an anonymous struct/union member access, i.e. the
1632 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001633 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001634 assert(Member->getType()->isRecordType() &&
1635 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001636
Richard Smith9138b4e2011-10-26 19:06:56 +00001637 BaseResult =
1638 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley429bb272011-04-08 18:41:53 +00001639 QualifierLoc.getNestedNameSpecifier(),
1640 FoundDecl, Member);
1641 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001642 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001643 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001644 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001645 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001646 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001647 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001648 cast<FieldDecl>(Member)->getType(),
1649 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001650 return getSema().Owned(ME);
1651 }
Mike Stump1eb44332009-09-09 15:08:12 +00001652
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001653 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001654 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001655
John Wiegley429bb272011-04-08 18:41:53 +00001656 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001657 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001658
John McCall6bb80172010-03-30 21:47:33 +00001659 // FIXME: this involves duplicating earlier analysis in a lot of
1660 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001661 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001662 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001663 R.resolveKind();
1664
John McCall9ae2f072010-08-23 23:25:46 +00001665 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001666 SS, TemplateKWLoc,
1667 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001668 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001669 }
Mike Stump1eb44332009-09-09 15:08:12 +00001670
Douglas Gregorb98b1992009-08-11 05:31:07 +00001671 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001672 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001673 /// By default, performs semantic analysis to build the new expression.
1674 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001675 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001676 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001677 Expr *LHS, Expr *RHS) {
1678 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001679 }
1680
1681 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001682 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001683 /// By default, performs semantic analysis to build the new expression.
1684 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001685 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001686 SourceLocation QuestionLoc,
1687 Expr *LHS,
1688 SourceLocation ColonLoc,
1689 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001690 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1691 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001692 }
1693
Douglas Gregorb98b1992009-08-11 05:31:07 +00001694 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001695 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001696 /// By default, performs semantic analysis to build the new expression.
1697 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001698 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001699 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001700 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001701 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001702 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001703 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001704 }
Mike Stump1eb44332009-09-09 15:08:12 +00001705
Douglas Gregorb98b1992009-08-11 05:31:07 +00001706 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001707 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001708 /// By default, performs semantic analysis to build the new expression.
1709 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001710 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001711 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001712 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001713 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001714 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001715 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001716 }
Mike Stump1eb44332009-09-09 15:08:12 +00001717
Douglas Gregorb98b1992009-08-11 05:31:07 +00001718 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001719 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001720 /// By default, performs semantic analysis to build the new expression.
1721 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001722 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001723 SourceLocation OpLoc,
1724 SourceLocation AccessorLoc,
1725 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001726
John McCall129e2df2009-11-30 22:42:35 +00001727 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001728 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001729 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001730 OpLoc, /*IsArrow*/ false,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001731 SS, SourceLocation(),
1732 /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001733 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001734 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001735 }
Mike Stump1eb44332009-09-09 15:08:12 +00001736
Douglas Gregorb98b1992009-08-11 05:31:07 +00001737 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001738 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001739 /// By default, performs semantic analysis to build the new expression.
1740 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001741 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001742 MultiExprArg Inits,
1743 SourceLocation RBraceLoc,
1744 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001745 ExprResult Result
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001746 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregore48319a2009-11-09 17:16:50 +00001747 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001748 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00001749
Douglas Gregore48319a2009-11-09 17:16:50 +00001750 // Patch in the result type we were given, which may have been computed
1751 // when the initial InitListExpr was built.
1752 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1753 ILE->setType(ResultTy);
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001754 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001755 }
Mike Stump1eb44332009-09-09 15:08:12 +00001756
Douglas Gregorb98b1992009-08-11 05:31:07 +00001757 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001758 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001759 /// By default, performs semantic analysis to build the new expression.
1760 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001761 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001762 MultiExprArg ArrayExprs,
1763 SourceLocation EqualOrColonLoc,
1764 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001765 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001766 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001767 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001768 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001769 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001770 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001771
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001772 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001773 }
Mike Stump1eb44332009-09-09 15:08:12 +00001774
Douglas Gregorb98b1992009-08-11 05:31:07 +00001775 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001776 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001777 /// By default, builds the implicit value initialization without performing
1778 /// any semantic analysis. Subclasses may override this routine to provide
1779 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001780 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001781 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1782 }
Mike Stump1eb44332009-09-09 15:08:12 +00001783
Douglas Gregorb98b1992009-08-11 05:31:07 +00001784 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001785 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001786 /// By default, performs semantic analysis to build the new expression.
1787 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001788 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001789 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001790 SourceLocation RParenLoc) {
1791 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001792 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001793 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001794 }
1795
1796 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001797 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001798 /// By default, performs semantic analysis to build the new expression.
1799 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001800 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +00001801 MultiExprArg SubExprs,
1802 SourceLocation RParenLoc) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001803 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001804 }
Mike Stump1eb44332009-09-09 15:08:12 +00001805
Douglas Gregorb98b1992009-08-11 05:31:07 +00001806 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001807 ///
1808 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001809 /// rather than attempting to map the label statement itself.
1810 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001811 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001812 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001813 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001814 }
Mike Stump1eb44332009-09-09 15:08:12 +00001815
Douglas Gregorb98b1992009-08-11 05:31:07 +00001816 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001817 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001818 /// By default, performs semantic analysis to build the new expression.
1819 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001820 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001821 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001822 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001823 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001824 }
Mike Stump1eb44332009-09-09 15:08:12 +00001825
Douglas Gregorb98b1992009-08-11 05:31:07 +00001826 /// \brief Build a new __builtin_choose_expr expression.
1827 ///
1828 /// By default, performs semantic analysis to build the new expression.
1829 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001830 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001831 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001832 SourceLocation RParenLoc) {
1833 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001834 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001835 RParenLoc);
1836 }
Mike Stump1eb44332009-09-09 15:08:12 +00001837
Peter Collingbournef111d932011-04-15 00:35:48 +00001838 /// \brief Build a new generic selection expression.
1839 ///
1840 /// By default, performs semantic analysis to build the new expression.
1841 /// Subclasses may override this routine to provide different behavior.
1842 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1843 SourceLocation DefaultLoc,
1844 SourceLocation RParenLoc,
1845 Expr *ControllingExpr,
Dmitri Gribenko80613222013-05-10 13:06:58 +00001846 ArrayRef<TypeSourceInfo *> Types,
1847 ArrayRef<Expr *> Exprs) {
Peter Collingbournef111d932011-04-15 00:35:48 +00001848 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko80613222013-05-10 13:06:58 +00001849 ControllingExpr, Types, Exprs);
Peter Collingbournef111d932011-04-15 00:35:48 +00001850 }
1851
Douglas Gregorb98b1992009-08-11 05:31:07 +00001852 /// \brief Build a new overloaded operator call expression.
1853 ///
1854 /// By default, performs semantic analysis to build the new expression.
1855 /// The semantic analysis provides the behavior of template instantiation,
1856 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001857 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001858 /// argument-dependent lookup, etc. Subclasses may override this routine to
1859 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001860 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001861 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001862 Expr *Callee,
1863 Expr *First,
1864 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001865
1866 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001867 /// reinterpret_cast.
1868 ///
1869 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001870 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001871 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001872 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001873 Stmt::StmtClass Class,
1874 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001875 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001876 SourceLocation RAngleLoc,
1877 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001878 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001879 SourceLocation RParenLoc) {
1880 switch (Class) {
1881 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001882 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001883 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001884 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001885
1886 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001887 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001888 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001889 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001890
Douglas Gregorb98b1992009-08-11 05:31:07 +00001891 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001892 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001893 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001894 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001895 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001896
Douglas Gregorb98b1992009-08-11 05:31:07 +00001897 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001898 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001899 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001900 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001901
Douglas Gregorb98b1992009-08-11 05:31:07 +00001902 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001903 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001904 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001905 }
Mike Stump1eb44332009-09-09 15:08:12 +00001906
Douglas Gregorb98b1992009-08-11 05:31:07 +00001907 /// \brief Build a new C++ static_cast expression.
1908 ///
1909 /// By default, performs semantic analysis to build the new expression.
1910 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001911 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001912 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001913 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001914 SourceLocation RAngleLoc,
1915 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001916 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001917 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001918 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001919 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001920 SourceRange(LAngleLoc, RAngleLoc),
1921 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001922 }
1923
1924 /// \brief Build a new C++ dynamic_cast expression.
1925 ///
1926 /// By default, performs semantic analysis to build the new expression.
1927 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001928 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001929 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001930 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001931 SourceLocation RAngleLoc,
1932 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001933 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001934 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001935 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001936 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001937 SourceRange(LAngleLoc, RAngleLoc),
1938 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001939 }
1940
1941 /// \brief Build a new C++ reinterpret_cast expression.
1942 ///
1943 /// By default, performs semantic analysis to build the new expression.
1944 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001945 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001946 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001947 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001948 SourceLocation RAngleLoc,
1949 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001950 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001951 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001952 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001953 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001954 SourceRange(LAngleLoc, RAngleLoc),
1955 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001956 }
1957
1958 /// \brief Build a new C++ const_cast expression.
1959 ///
1960 /// By default, performs semantic analysis to build the new expression.
1961 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001962 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001963 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001964 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001965 SourceLocation RAngleLoc,
1966 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001967 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001968 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001969 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001970 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001971 SourceRange(LAngleLoc, RAngleLoc),
1972 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001973 }
Mike Stump1eb44332009-09-09 15:08:12 +00001974
Douglas Gregorb98b1992009-08-11 05:31:07 +00001975 /// \brief Build a new C++ functional-style cast expression.
1976 ///
1977 /// By default, performs semantic analysis to build the new expression.
1978 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001979 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1980 SourceLocation LParenLoc,
1981 Expr *Sub,
1982 SourceLocation RParenLoc) {
1983 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001984 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001985 RParenLoc);
1986 }
Mike Stump1eb44332009-09-09 15:08:12 +00001987
Douglas Gregorb98b1992009-08-11 05:31:07 +00001988 /// \brief Build a new C++ typeid(type) expression.
1989 ///
1990 /// By default, performs semantic analysis to build the new expression.
1991 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001992 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001993 SourceLocation TypeidLoc,
1994 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001995 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001996 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001997 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001998 }
Mike Stump1eb44332009-09-09 15:08:12 +00001999
Francois Pichet01b7c302010-09-08 12:20:18 +00002000
Douglas Gregorb98b1992009-08-11 05:31:07 +00002001 /// \brief Build a new C++ typeid(expr) expression.
2002 ///
2003 /// By default, performs semantic analysis to build the new expression.
2004 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002005 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00002006 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00002007 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002008 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002009 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00002010 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002011 }
2012
Francois Pichet01b7c302010-09-08 12:20:18 +00002013 /// \brief Build a new C++ __uuidof(type) expression.
2014 ///
2015 /// By default, performs semantic analysis to build the new expression.
2016 /// Subclasses may override this routine to provide different behavior.
2017 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2018 SourceLocation TypeidLoc,
2019 TypeSourceInfo *Operand,
2020 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002021 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet01b7c302010-09-08 12:20:18 +00002022 RParenLoc);
2023 }
2024
2025 /// \brief Build a new C++ __uuidof(expr) expression.
2026 ///
2027 /// By default, performs semantic analysis to build the new expression.
2028 /// Subclasses may override this routine to provide different behavior.
2029 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2030 SourceLocation TypeidLoc,
2031 Expr *Operand,
2032 SourceLocation RParenLoc) {
2033 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2034 RParenLoc);
2035 }
2036
Douglas Gregorb98b1992009-08-11 05:31:07 +00002037 /// \brief Build a new C++ "this" expression.
2038 ///
2039 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00002040 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00002041 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002042 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00002043 QualType ThisType,
2044 bool isImplicit) {
Eli Friedmanb69b42c2012-01-11 02:36:31 +00002045 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002046 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00002047 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
2048 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002049 }
2050
2051 /// \brief Build a new C++ throw expression.
2052 ///
2053 /// By default, performs semantic analysis to build the new expression.
2054 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00002055 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2056 bool IsThrownVariableInScope) {
2057 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002058 }
2059
2060 /// \brief Build a new C++ default-argument expression.
2061 ///
2062 /// By default, builds a new default-argument expression, which does not
2063 /// require any semantic analysis. Subclasses may override this routine to
2064 /// provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002065 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00002066 ParmVarDecl *Param) {
2067 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
2068 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002069 }
2070
Richard Smithc3bf52c2013-04-20 22:23:05 +00002071 /// \brief Build a new C++11 default-initialization expression.
2072 ///
2073 /// By default, builds a new default field initialization expression, which
2074 /// does not require any semantic analysis. Subclasses may override this
2075 /// routine to provide different behavior.
2076 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2077 FieldDecl *Field) {
2078 return getSema().Owned(CXXDefaultInitExpr::Create(getSema().Context, Loc,
2079 Field));
2080 }
2081
Douglas Gregorb98b1992009-08-11 05:31:07 +00002082 /// \brief Build a new C++ zero-initialization expression.
2083 ///
2084 /// By default, performs semantic analysis to build the new expression.
2085 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002086 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2087 SourceLocation LParenLoc,
2088 SourceLocation RParenLoc) {
2089 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002090 None, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002091 }
Mike Stump1eb44332009-09-09 15:08:12 +00002092
Douglas Gregorb98b1992009-08-11 05:31:07 +00002093 /// \brief Build a new C++ "new" expression.
2094 ///
2095 /// By default, performs semantic analysis to build the new expression.
2096 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002097 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002098 bool UseGlobal,
2099 SourceLocation PlacementLParen,
2100 MultiExprArg PlacementArgs,
2101 SourceLocation PlacementRParen,
2102 SourceRange TypeIdParens,
2103 QualType AllocatedType,
2104 TypeSourceInfo *AllocatedTypeInfo,
2105 Expr *ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002106 SourceRange DirectInitRange,
2107 Expr *Initializer) {
Mike Stump1eb44332009-09-09 15:08:12 +00002108 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002109 PlacementLParen,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002110 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002111 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00002112 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002113 AllocatedType,
2114 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00002115 ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002116 DirectInitRange,
2117 Initializer);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002118 }
Mike Stump1eb44332009-09-09 15:08:12 +00002119
Douglas Gregorb98b1992009-08-11 05:31:07 +00002120 /// \brief Build a new C++ "delete" expression.
2121 ///
2122 /// By default, performs semantic analysis to build the new expression.
2123 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002124 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002125 bool IsGlobalDelete,
2126 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002127 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002128 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002129 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002130 }
Mike Stump1eb44332009-09-09 15:08:12 +00002131
Douglas Gregorb98b1992009-08-11 05:31:07 +00002132 /// \brief Build a new unary type trait expression.
2133 ///
2134 /// By default, performs semantic analysis to build the new expression.
2135 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002136 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00002137 SourceLocation StartLoc,
2138 TypeSourceInfo *T,
2139 SourceLocation RParenLoc) {
2140 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002141 }
2142
Francois Pichet6ad6f282010-12-07 00:08:36 +00002143 /// \brief Build a new binary type trait expression.
2144 ///
2145 /// By default, performs semantic analysis to build the new expression.
2146 /// Subclasses may override this routine to provide different behavior.
2147 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
2148 SourceLocation StartLoc,
2149 TypeSourceInfo *LhsT,
2150 TypeSourceInfo *RhsT,
2151 SourceLocation RParenLoc) {
2152 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
2153 }
2154
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00002155 /// \brief Build a new type trait expression.
2156 ///
2157 /// By default, performs semantic analysis to build the new expression.
2158 /// Subclasses may override this routine to provide different behavior.
2159 ExprResult RebuildTypeTrait(TypeTrait Trait,
2160 SourceLocation StartLoc,
2161 ArrayRef<TypeSourceInfo *> Args,
2162 SourceLocation RParenLoc) {
2163 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2164 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002165
John Wiegley21ff2e52011-04-28 00:16:57 +00002166 /// \brief Build a new array type trait expression.
2167 ///
2168 /// By default, performs semantic analysis to build the new expression.
2169 /// Subclasses may override this routine to provide different behavior.
2170 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2171 SourceLocation StartLoc,
2172 TypeSourceInfo *TSInfo,
2173 Expr *DimExpr,
2174 SourceLocation RParenLoc) {
2175 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2176 }
2177
John Wiegley55262202011-04-25 06:54:41 +00002178 /// \brief Build a new expression trait expression.
2179 ///
2180 /// By default, performs semantic analysis to build the new expression.
2181 /// Subclasses may override this routine to provide different behavior.
2182 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2183 SourceLocation StartLoc,
2184 Expr *Queried,
2185 SourceLocation RParenLoc) {
2186 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2187 }
2188
Mike Stump1eb44332009-09-09 15:08:12 +00002189 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002190 /// expression.
2191 ///
2192 /// By default, performs semantic analysis to build the new expression.
2193 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002194 ExprResult RebuildDependentScopeDeclRefExpr(
2195 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002196 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002197 const DeclarationNameInfo &NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00002198 const TemplateArgumentListInfo *TemplateArgs,
2199 bool IsAddressOfOperand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002200 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002201 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002202
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002203 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002204 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002205 NameInfo, TemplateArgs);
John McCallf7a1a742009-11-24 19:00:30 +00002206
Richard Smithefeeccf2012-10-21 03:28:35 +00002207 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo,
2208 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002209 }
2210
2211 /// \brief Build a new template-id expression.
2212 ///
2213 /// By default, performs semantic analysis to build the new expression.
2214 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002215 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002216 SourceLocation TemplateKWLoc,
2217 LookupResult &R,
2218 bool RequiresADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002219 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002220 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2221 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002222 }
2223
2224 /// \brief Build a new object-construction expression.
2225 ///
2226 /// By default, performs semantic analysis to build the new expression.
2227 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002228 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002229 SourceLocation Loc,
2230 CXXConstructorDecl *Constructor,
2231 bool IsElidable,
2232 MultiExprArg Args,
2233 bool HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002234 bool ListInitialization,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002235 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002236 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002237 SourceRange ParenRange) {
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00002238 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002239 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002240 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002241 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002242
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002243 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002244 ConvertedArgs,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002245 HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002246 ListInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002247 RequiresZeroInit, ConstructKind,
2248 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002249 }
2250
2251 /// \brief Build a new object-construction expression.
2252 ///
2253 /// By default, performs semantic analysis to build the new expression.
2254 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002255 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2256 SourceLocation LParenLoc,
2257 MultiExprArg Args,
2258 SourceLocation RParenLoc) {
2259 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002260 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002261 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002262 RParenLoc);
2263 }
2264
2265 /// \brief Build a new object-construction expression.
2266 ///
2267 /// By default, performs semantic analysis to build the new expression.
2268 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002269 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2270 SourceLocation LParenLoc,
2271 MultiExprArg Args,
2272 SourceLocation RParenLoc) {
2273 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002274 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002275 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002276 RParenLoc);
2277 }
Mike Stump1eb44332009-09-09 15:08:12 +00002278
Douglas Gregorb98b1992009-08-11 05:31:07 +00002279 /// \brief Build a new member reference expression.
2280 ///
2281 /// By default, performs semantic analysis to build the new expression.
2282 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002283 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002284 QualType BaseType,
2285 bool IsArrow,
2286 SourceLocation OperatorLoc,
2287 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002288 SourceLocation TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00002289 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002290 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002291 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002292 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002293 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002294
John McCall9ae2f072010-08-23 23:25:46 +00002295 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002296 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002297 SS, TemplateKWLoc,
2298 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002299 MemberNameInfo,
2300 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002301 }
2302
John McCall129e2df2009-11-30 22:42:35 +00002303 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002304 ///
2305 /// By default, performs semantic analysis to build the new expression.
2306 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002307 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2308 SourceLocation OperatorLoc,
2309 bool IsArrow,
2310 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002311 SourceLocation TemplateKWLoc,
Richard Smith9138b4e2011-10-26 19:06:56 +00002312 NamedDecl *FirstQualifierInScope,
2313 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002314 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002315 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002316 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002317
John McCall9ae2f072010-08-23 23:25:46 +00002318 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002319 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002320 SS, TemplateKWLoc,
2321 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00002322 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002323 }
Mike Stump1eb44332009-09-09 15:08:12 +00002324
Sebastian Redl2e156222010-09-10 20:55:43 +00002325 /// \brief Build a new noexcept expression.
2326 ///
2327 /// By default, performs semantic analysis to build the new expression.
2328 /// Subclasses may override this routine to provide different behavior.
2329 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2330 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2331 }
2332
Douglas Gregoree8aff02011-01-04 17:33:58 +00002333 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002334 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2335 SourceLocation PackLoc,
Douglas Gregoree8aff02011-01-04 17:33:58 +00002336 SourceLocation RParenLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002337 Optional<unsigned> Length) {
Douglas Gregor089e8932011-10-10 18:59:29 +00002338 if (Length)
Chad Rosier4a9d7952012-08-08 18:46:20 +00002339 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2340 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002341 RParenLoc, *Length);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002342
2343 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2344 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002345 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002346 }
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002347
Patrick Beardeb382ec2012-04-19 00:25:12 +00002348 /// \brief Build a new Objective-C boxed expression.
2349 ///
2350 /// By default, performs semantic analysis to build the new expression.
2351 /// Subclasses may override this routine to provide different behavior.
2352 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2353 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2354 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002355
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002356 /// \brief Build a new Objective-C array literal.
2357 ///
2358 /// By default, performs semantic analysis to build the new expression.
2359 /// Subclasses may override this routine to provide different behavior.
2360 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2361 Expr **Elements, unsigned NumElements) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002362 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002363 MultiExprArg(Elements, NumElements));
2364 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002365
2366 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002367 Expr *Base, Expr *Key,
2368 ObjCMethodDecl *getterMethod,
2369 ObjCMethodDecl *setterMethod) {
2370 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2371 getterMethod, setterMethod);
2372 }
2373
2374 /// \brief Build a new Objective-C dictionary literal.
2375 ///
2376 /// By default, performs semantic analysis to build the new expression.
2377 /// Subclasses may override this routine to provide different behavior.
2378 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2379 ObjCDictionaryElement *Elements,
2380 unsigned NumElements) {
2381 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2382 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002383
James Dennett699c9042012-06-15 07:13:21 +00002384 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregorb98b1992009-08-11 05:31:07 +00002385 ///
2386 /// By default, performs semantic analysis to build the new expression.
2387 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002388 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002389 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002390 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002391 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002392 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002393 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002394
Douglas Gregor92e986e2010-04-22 16:44:27 +00002395 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002396 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002397 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002398 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002399 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002400 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002401 MultiExprArg Args,
2402 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002403 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2404 ReceiverTypeInfo->getType(),
2405 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002406 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002407 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002408 }
2409
2410 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002411 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002412 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002413 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002414 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002415 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002416 MultiExprArg Args,
2417 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002418 return SemaRef.BuildInstanceMessage(Receiver,
2419 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002420 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002421 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002422 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002423 }
2424
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002425 /// \brief Build a new Objective-C ivar reference expression.
2426 ///
2427 /// By default, performs semantic analysis to build the new expression.
2428 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002429 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002430 SourceLocation IvarLoc,
2431 bool IsArrow, bool IsFreeIvar) {
2432 // FIXME: We lose track of the IsFreeIvar bit.
2433 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002434 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002435 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2436 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002437 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002438 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002439 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002440 false);
John Wiegley429bb272011-04-08 18:41:53 +00002441 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002442 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002443
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002444 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002445 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002446
John Wiegley429bb272011-04-08 18:41:53 +00002447 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002448 /*FIXME:*/IvarLoc, IsArrow,
2449 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002450 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002451 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002452 /*TemplateArgs=*/0);
2453 }
Douglas Gregore3303542010-04-26 20:47:02 +00002454
2455 /// \brief Build a new Objective-C property reference expression.
2456 ///
2457 /// By default, performs semantic analysis to build the new expression.
2458 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002459 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002460 ObjCPropertyDecl *Property,
2461 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002462 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002463 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002464 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2465 Sema::LookupMemberName);
2466 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002467 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002468 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002469 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002470 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002471 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002472
Douglas Gregore3303542010-04-26 20:47:02 +00002473 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002474 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002475
John Wiegley429bb272011-04-08 18:41:53 +00002476 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002477 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002478 SS, SourceLocation(),
Douglas Gregore3303542010-04-26 20:47:02 +00002479 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002480 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002481 /*TemplateArgs=*/0);
2482 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002483
John McCall12f78a62010-12-02 01:19:52 +00002484 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002485 ///
2486 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002487 /// Subclasses may override this routine to provide different behavior.
2488 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2489 ObjCMethodDecl *Getter,
2490 ObjCMethodDecl *Setter,
2491 SourceLocation PropertyLoc) {
2492 // Since these expressions can only be value-dependent, we do not
2493 // need to perform semantic analysis again.
2494 return Owned(
2495 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2496 VK_LValue, OK_ObjCProperty,
2497 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002498 }
2499
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002500 /// \brief Build a new Objective-C "isa" expression.
2501 ///
2502 /// By default, performs semantic analysis to build the new expression.
2503 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002504 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002505 SourceLocation OpLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002506 bool IsArrow) {
2507 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002508 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002509 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2510 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002511 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002512 OpLoc,
John McCalld226f652010-08-21 09:40:31 +00002513 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002514 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002515 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002516
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002517 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002518 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002519
John Wiegley429bb272011-04-08 18:41:53 +00002520 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002521 OpLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002522 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002523 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002524 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002525 /*TemplateArgs=*/0);
2526 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002527
Douglas Gregorb98b1992009-08-11 05:31:07 +00002528 /// \brief Build a new shuffle vector expression.
2529 ///
2530 /// By default, performs semantic analysis to build the new expression.
2531 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002532 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002533 MultiExprArg SubExprs,
2534 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002535 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002536 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002537 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2538 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2539 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikie3bc93e32012-12-19 00:45:41 +00002540 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002541
Douglas Gregorb98b1992009-08-11 05:31:07 +00002542 // Build a reference to the __builtin_shufflevector builtin
David Blaikie3bc93e32012-12-19 00:45:41 +00002543 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002544 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2545 SemaRef.Context.BuiltinFnTy,
2546 VK_RValue, BuiltinLoc);
2547 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2548 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
2549 CK_BuiltinFnToFnPtr).take();
Mike Stump1eb44332009-09-09 15:08:12 +00002550
2551 // Build the CallExpr
John Wiegley429bb272011-04-08 18:41:53 +00002552 ExprResult TheCall = SemaRef.Owned(
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002553 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, SubExprs,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002554 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002555 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002556 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002557
Douglas Gregorb98b1992009-08-11 05:31:07 +00002558 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002559 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002560 }
John McCall43fed0d2010-11-12 08:19:04 +00002561
Hal Finkel414a1bd2013-09-18 03:29:45 +00002562 /// \brief Build a new convert vector expression.
2563 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2564 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2565 SourceLocation RParenLoc) {
2566 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2567 BuiltinLoc, RParenLoc);
2568 }
2569
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002570 /// \brief Build a new template argument pack expansion.
2571 ///
2572 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002573 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002574 /// different behavior.
2575 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002576 SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002577 Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002578 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002579 case TemplateArgument::Expression: {
2580 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002581 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2582 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002583 if (Result.isInvalid())
2584 return TemplateArgumentLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002585
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002586 return TemplateArgumentLoc(Result.get(), Result.get());
2587 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002588
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002589 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002590 return TemplateArgumentLoc(TemplateArgument(
2591 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002592 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002593 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002594 Pattern.getTemplateNameLoc(),
2595 EllipsisLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002596
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002597 case TemplateArgument::Null:
2598 case TemplateArgument::Integral:
2599 case TemplateArgument::Declaration:
2600 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002601 case TemplateArgument::TemplateExpansion:
Eli Friedmand7a6b162012-09-26 02:36:12 +00002602 case TemplateArgument::NullPtr:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002603 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002604
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002605 case TemplateArgument::Type:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002606 if (TypeSourceInfo *Expansion
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002607 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002608 EllipsisLoc,
2609 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002610 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2611 Expansion);
2612 break;
2613 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002614
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002615 return TemplateArgumentLoc();
2616 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002617
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002618 /// \brief Build a new expression pack expansion.
2619 ///
2620 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002621 /// for an expression. Subclasses may override this routine to provide
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002622 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002623 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002624 Optional<unsigned> NumExpansions) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002625 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002626 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002627
2628 /// \brief Build a new atomic operation expression.
2629 ///
2630 /// By default, performs semantic analysis to build the new expression.
2631 /// Subclasses may override this routine to provide different behavior.
2632 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2633 MultiExprArg SubExprs,
2634 QualType RetTy,
2635 AtomicExpr::AtomicOp Op,
2636 SourceLocation RParenLoc) {
2637 // Just create the expression; there is not any interesting semantic
2638 // analysis here because we can't actually build an AtomicExpr until
2639 // we are sure it is semantically sound.
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002640 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002641 RParenLoc);
2642 }
2643
John McCall43fed0d2010-11-12 08:19:04 +00002644private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002645 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2646 QualType ObjectType,
2647 NamedDecl *FirstQualifierInScope,
2648 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002649
2650 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2651 QualType ObjectType,
2652 NamedDecl *FirstQualifierInScope,
2653 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002654};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002655
Douglas Gregor43959a92009-08-20 07:17:43 +00002656template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002657StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002658 if (!S)
2659 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002660
Douglas Gregor43959a92009-08-20 07:17:43 +00002661 switch (S->getStmtClass()) {
2662 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002663
Douglas Gregor43959a92009-08-20 07:17:43 +00002664 // Transform individual statement nodes
2665#define STMT(Node, Parent) \
2666 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002667#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002668#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002669#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002670
Douglas Gregor43959a92009-08-20 07:17:43 +00002671 // Transform expressions by calling TransformExpr.
2672#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002673#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002674#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002675#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002676 {
John McCall60d7b3a2010-08-24 06:29:42 +00002677 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002678 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002679 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002680
Richard Smith41956372013-01-14 22:39:08 +00002681 return getSema().ActOnExprStmt(E);
Douglas Gregor43959a92009-08-20 07:17:43 +00002682 }
Mike Stump1eb44332009-09-09 15:08:12 +00002683 }
2684
John McCall3fa5cae2010-10-26 07:05:15 +00002685 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002686}
Mike Stump1eb44332009-09-09 15:08:12 +00002687
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00002688template<typename Derived>
2689OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2690 if (!S)
2691 return S;
2692
2693 switch (S->getClauseKind()) {
2694 default: break;
2695 // Transform individual clause nodes
2696#define OPENMP_CLAUSE(Name, Class) \
2697 case OMPC_ ## Name : \
2698 return getDerived().Transform ## Class(cast<Class>(S));
2699#include "clang/Basic/OpenMPKinds.def"
2700 }
2701
2702 return S;
2703}
2704
Mike Stump1eb44332009-09-09 15:08:12 +00002705
Douglas Gregor670444e2009-08-04 22:27:00 +00002706template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002707ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002708 if (!E)
2709 return SemaRef.Owned(E);
2710
2711 switch (E->getStmtClass()) {
2712 case Stmt::NoStmtClass: break;
2713#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002714#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002715#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002716 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002717#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002718 }
2719
John McCall3fa5cae2010-10-26 07:05:15 +00002720 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002721}
2722
2723template<typename Derived>
Richard Smithc83c2302012-12-19 01:39:02 +00002724ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2725 bool CXXDirectInit) {
2726 // Initializers are instantiated like expressions, except that various outer
2727 // layers are stripped.
2728 if (!Init)
2729 return SemaRef.Owned(Init);
2730
2731 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2732 Init = ExprTemp->getSubExpr();
2733
Richard Smith858c2c32013-05-30 22:40:16 +00002734 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2735 Init = MTE->GetTemporaryExpr();
2736
Richard Smithc83c2302012-12-19 01:39:02 +00002737 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2738 Init = Binder->getSubExpr();
2739
2740 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2741 Init = ICE->getSubExprAsWritten();
2742
Richard Smith7c3e6152013-06-12 22:31:48 +00002743 if (CXXStdInitializerListExpr *ILE =
2744 dyn_cast<CXXStdInitializerListExpr>(Init))
2745 return TransformInitializer(ILE->getSubExpr(), CXXDirectInit);
2746
Richard Smith5cf15892012-12-21 08:13:35 +00002747 // If this is not a direct-initializer, we only need to reconstruct
2748 // InitListExprs. Other forms of copy-initialization will be a no-op if
2749 // the initializer is already the right type.
2750 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2751 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2752 return getDerived().TransformExpr(Init);
2753
2754 // Revert value-initialization back to empty parens.
2755 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2756 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002757 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith5cf15892012-12-21 08:13:35 +00002758 Parens.getEnd());
2759 }
2760
2761 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2762 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002763 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith5cf15892012-12-21 08:13:35 +00002764 SourceLocation());
2765
2766 // Revert initialization by constructor back to a parenthesized or braced list
2767 // of expressions. Any other form of initializer can just be reused directly.
2768 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithc83c2302012-12-19 01:39:02 +00002769 return getDerived().TransformExpr(Init);
2770
2771 SmallVector<Expr*, 8> NewArgs;
2772 bool ArgChanged = false;
2773 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2774 /*IsCall*/true, NewArgs, &ArgChanged))
2775 return ExprError();
2776
2777 // If this was list initialization, revert to list form.
2778 if (Construct->isListInitialization())
2779 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2780 Construct->getLocEnd(),
2781 Construct->getType());
2782
Richard Smithc83c2302012-12-19 01:39:02 +00002783 // Build a ParenListExpr to represent anything else.
Enea Zaffanella1245a542013-09-07 05:49:53 +00002784 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smithc83c2302012-12-19 01:39:02 +00002785 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2786 Parens.getEnd());
2787}
2788
2789template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00002790bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2791 unsigned NumInputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002792 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002793 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002794 bool *ArgChanged) {
2795 for (unsigned I = 0; I != NumInputs; ++I) {
2796 // If requested, drop call arguments that need to be dropped.
2797 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2798 if (ArgChanged)
2799 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002800
Douglas Gregoraa165f82011-01-03 19:04:46 +00002801 break;
2802 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002803
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002804 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2805 Expr *Pattern = Expansion->getPattern();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002806
Chris Lattner686775d2011-07-20 06:58:45 +00002807 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002808 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2809 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002810
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002811 // Determine whether the set of unexpanded parameter packs can and should
2812 // be expanded.
2813 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002814 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00002815 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2816 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002817 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2818 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002819 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002820 Expand, RetainExpansion,
2821 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002822 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002823
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002824 if (!Expand) {
2825 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00002826 // transformation on the pack expansion, producing another pack
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002827 // expansion.
2828 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2829 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2830 if (OutPattern.isInvalid())
2831 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002832
2833 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002834 Expansion->getEllipsisLoc(),
2835 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002836 if (Out.isInvalid())
2837 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002838
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002839 if (ArgChanged)
2840 *ArgChanged = true;
2841 Outputs.push_back(Out.get());
2842 continue;
2843 }
John McCallc8fc90a2011-07-06 07:30:07 +00002844
2845 // Record right away that the argument was changed. This needs
2846 // to happen even if the array expands to nothing.
2847 if (ArgChanged) *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002848
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002849 // The transform has determined that we should perform an elementwise
2850 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002851 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002852 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2853 ExprResult Out = getDerived().TransformExpr(Pattern);
2854 if (Out.isInvalid())
2855 return true;
2856
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002857 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002858 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2859 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002860 if (Out.isInvalid())
2861 return true;
2862 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002863
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002864 Outputs.push_back(Out.get());
2865 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002866
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002867 continue;
2868 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002869
Richard Smithc83c2302012-12-19 01:39:02 +00002870 ExprResult Result =
2871 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
2872 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregoraa165f82011-01-03 19:04:46 +00002873 if (Result.isInvalid())
2874 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002875
Douglas Gregoraa165f82011-01-03 19:04:46 +00002876 if (Result.get() != Inputs[I] && ArgChanged)
2877 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002878
2879 Outputs.push_back(Result.get());
Douglas Gregoraa165f82011-01-03 19:04:46 +00002880 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002881
Douglas Gregoraa165f82011-01-03 19:04:46 +00002882 return false;
2883}
2884
2885template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002886NestedNameSpecifierLoc
2887TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2888 NestedNameSpecifierLoc NNS,
2889 QualType ObjectType,
2890 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002891 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002892 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002893 Qualifier = Qualifier.getPrefix())
2894 Qualifiers.push_back(Qualifier);
2895
2896 CXXScopeSpec SS;
2897 while (!Qualifiers.empty()) {
2898 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2899 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002900
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002901 switch (QNNS->getKind()) {
2902 case NestedNameSpecifier::Identifier:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002903 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002904 *QNNS->getAsIdentifier(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002905 Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002906 Q.getLocalEndLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002907 ObjectType, false, SS,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002908 FirstQualifierInScope, false))
2909 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002910
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002911 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002912
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002913 case NestedNameSpecifier::Namespace: {
2914 NamespaceDecl *NS
2915 = cast_or_null<NamespaceDecl>(
2916 getDerived().TransformDecl(
2917 Q.getLocalBeginLoc(),
2918 QNNS->getAsNamespace()));
2919 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2920 break;
2921 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002922
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002923 case NestedNameSpecifier::NamespaceAlias: {
2924 NamespaceAliasDecl *Alias
2925 = cast_or_null<NamespaceAliasDecl>(
2926 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2927 QNNS->getAsNamespaceAlias()));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002928 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002929 Q.getLocalEndLoc());
2930 break;
2931 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002932
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002933 case NestedNameSpecifier::Global:
2934 // There is no meaningful transformation that one could perform on the
2935 // global scope.
2936 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2937 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002938
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002939 case NestedNameSpecifier::TypeSpecWithTemplate:
2940 case NestedNameSpecifier::TypeSpec: {
2941 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2942 FirstQualifierInScope, SS);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002943
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002944 if (!TL)
2945 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002946
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002947 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith80ad52f2013-01-02 11:42:31 +00002948 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002949 TL.getType()->isEnumeralType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002950 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002951 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002952 if (TL.getType()->isEnumeralType())
2953 SemaRef.Diag(TL.getBeginLoc(),
2954 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002955 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2956 Q.getLocalEndLoc());
2957 break;
2958 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002959 // If the nested-name-specifier is an invalid type def, don't emit an
2960 // error because a previous error should have already been emitted.
David Blaikie39e6ab42013-02-18 22:06:02 +00002961 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
2962 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002963 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieu00c93a12011-05-07 01:36:37 +00002964 << TL.getType() << SS.getRange();
2965 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002966 return NestedNameSpecifierLoc();
2967 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002968 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002969
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002970 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002971 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002972 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002973 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002974
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002975 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002976 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002977 !getDerived().AlwaysRebuild())
2978 return NNS;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002979
2980 // If we can re-use the source-location data from the original
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002981 // nested-name-specifier, do so.
2982 if (SS.location_size() == NNS.getDataLength() &&
2983 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2984 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2985
2986 // Allocate new nested-name-specifier location information.
2987 return SS.getWithLocInContext(SemaRef.Context);
2988}
2989
2990template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002991DeclarationNameInfo
2992TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002993::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002994 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002995 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002996 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002997
2998 switch (Name.getNameKind()) {
2999 case DeclarationName::Identifier:
3000 case DeclarationName::ObjCZeroArgSelector:
3001 case DeclarationName::ObjCOneArgSelector:
3002 case DeclarationName::ObjCMultiArgSelector:
3003 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00003004 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00003005 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00003006 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00003007
Douglas Gregor81499bb2009-09-03 22:13:48 +00003008 case DeclarationName::CXXConstructorName:
3009 case DeclarationName::CXXDestructorName:
3010 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00003011 TypeSourceInfo *NewTInfo;
3012 CanQualType NewCanTy;
3013 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00003014 NewTInfo = getDerived().TransformType(OldTInfo);
3015 if (!NewTInfo)
3016 return DeclarationNameInfo();
3017 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00003018 }
3019 else {
3020 NewTInfo = 0;
3021 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00003022 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00003023 if (NewT.isNull())
3024 return DeclarationNameInfo();
3025 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3026 }
Mike Stump1eb44332009-09-09 15:08:12 +00003027
Abramo Bagnara25777432010-08-11 22:01:17 +00003028 DeclarationName NewName
3029 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3030 NewCanTy);
3031 DeclarationNameInfo NewNameInfo(NameInfo);
3032 NewNameInfo.setName(NewName);
3033 NewNameInfo.setNamedTypeInfo(NewTInfo);
3034 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00003035 }
Mike Stump1eb44332009-09-09 15:08:12 +00003036 }
3037
David Blaikieb219cfc2011-09-23 05:06:16 +00003038 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00003039}
3040
3041template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003042TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003043TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3044 TemplateName Name,
3045 SourceLocation NameLoc,
3046 QualType ObjectType,
3047 NamedDecl *FirstQualifierInScope) {
3048 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3049 TemplateDecl *Template = QTN->getTemplateDecl();
3050 assert(Template && "qualified template name must refer to a template");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003051
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003052 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00003053 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003054 Template));
3055 if (!TransTemplate)
3056 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003057
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003058 if (!getDerived().AlwaysRebuild() &&
3059 SS.getScopeRep() == QTN->getQualifier() &&
3060 TransTemplate == Template)
3061 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003062
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003063 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3064 TransTemplate);
3065 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003066
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003067 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3068 if (SS.getScopeRep()) {
3069 // These apply to the scope specifier, not the template.
3070 ObjectType = QualType();
3071 FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003072 }
3073
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003074 if (!getDerived().AlwaysRebuild() &&
3075 SS.getScopeRep() == DTN->getQualifier() &&
3076 ObjectType.isNull())
3077 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003078
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003079 if (DTN->isIdentifier()) {
3080 return getDerived().RebuildTemplateName(SS,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003081 *DTN->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003082 NameLoc,
3083 ObjectType,
3084 FirstQualifierInScope);
3085 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003086
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003087 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3088 ObjectType);
3089 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003090
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003091 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3092 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00003093 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003094 Template));
3095 if (!TransTemplate)
3096 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003097
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003098 if (!getDerived().AlwaysRebuild() &&
3099 TransTemplate == Template)
3100 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003101
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003102 return TemplateName(TransTemplate);
3103 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003104
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003105 if (SubstTemplateTemplateParmPackStorage *SubstPack
3106 = Name.getAsSubstTemplateTemplateParmPack()) {
3107 TemplateTemplateParmDecl *TransParam
3108 = cast_or_null<TemplateTemplateParmDecl>(
3109 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3110 if (!TransParam)
3111 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003112
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003113 if (!getDerived().AlwaysRebuild() &&
3114 TransParam == SubstPack->getParameterPack())
3115 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003116
3117 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003118 SubstPack->getArgumentPack());
3119 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003120
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003121 // These should be getting filtered out before they reach the AST.
3122 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003123}
3124
3125template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00003126void TreeTransform<Derived>::InventTemplateArgumentLoc(
3127 const TemplateArgument &Arg,
3128 TemplateArgumentLoc &Output) {
3129 SourceLocation Loc = getDerived().getBaseLocation();
3130 switch (Arg.getKind()) {
3131 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003132 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00003133 break;
3134
3135 case TemplateArgument::Type:
3136 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00003137 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier4a9d7952012-08-08 18:46:20 +00003138
John McCall833ca992009-10-29 08:12:44 +00003139 break;
3140
Douglas Gregor788cd062009-11-11 01:00:40 +00003141 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003142 case TemplateArgument::TemplateExpansion: {
3143 NestedNameSpecifierLocBuilder Builder;
3144 TemplateName Template = Arg.getAsTemplate();
3145 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3146 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3147 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3148 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003149
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003150 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier4a9d7952012-08-08 18:46:20 +00003151 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003152 Builder.getWithLocInContext(SemaRef.Context),
3153 Loc);
3154 else
Chad Rosier4a9d7952012-08-08 18:46:20 +00003155 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003156 Builder.getWithLocInContext(SemaRef.Context),
3157 Loc, Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003158
Douglas Gregor788cd062009-11-11 01:00:40 +00003159 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003160 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003161
John McCall833ca992009-10-29 08:12:44 +00003162 case TemplateArgument::Expression:
3163 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3164 break;
3165
3166 case TemplateArgument::Declaration:
3167 case TemplateArgument::Integral:
3168 case TemplateArgument::Pack:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003169 case TemplateArgument::NullPtr:
John McCall828bff22009-10-29 18:45:58 +00003170 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00003171 break;
3172 }
3173}
3174
3175template<typename Derived>
3176bool TreeTransform<Derived>::TransformTemplateArgument(
3177 const TemplateArgumentLoc &Input,
3178 TemplateArgumentLoc &Output) {
3179 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00003180 switch (Arg.getKind()) {
3181 case TemplateArgument::Null:
3182 case TemplateArgument::Integral:
Eli Friedman511e3ae2012-09-25 01:02:42 +00003183 case TemplateArgument::Pack:
3184 case TemplateArgument::Declaration:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003185 case TemplateArgument::NullPtr:
3186 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump1eb44332009-09-09 15:08:12 +00003187
Douglas Gregor670444e2009-08-04 22:27:00 +00003188 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00003189 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00003190 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00003191 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00003192
3193 DI = getDerived().TransformType(DI);
3194 if (!DI) return true;
3195
3196 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3197 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003198 }
Mike Stump1eb44332009-09-09 15:08:12 +00003199
Douglas Gregor788cd062009-11-11 01:00:40 +00003200 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003201 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3202 if (QualifierLoc) {
3203 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3204 if (!QualifierLoc)
3205 return true;
3206 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003207
Douglas Gregor1d752d72011-03-02 18:46:51 +00003208 CXXScopeSpec SS;
3209 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00003210 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00003211 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3212 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00003213 if (Template.isNull())
3214 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003215
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003216 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00003217 Input.getTemplateNameLoc());
3218 return false;
3219 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003220
3221 case TemplateArgument::TemplateExpansion:
3222 llvm_unreachable("Caller should expand pack expansions");
3223
Douglas Gregor670444e2009-08-04 22:27:00 +00003224 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00003225 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00003226 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003227 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003228
John McCall833ca992009-10-29 08:12:44 +00003229 Expr *InputExpr = Input.getSourceExpression();
3230 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3231
Chris Lattner223de242011-04-25 20:37:58 +00003232 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003233 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00003234 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00003235 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00003236 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003237 }
Douglas Gregor670444e2009-08-04 22:27:00 +00003238 }
Mike Stump1eb44332009-09-09 15:08:12 +00003239
Douglas Gregor670444e2009-08-04 22:27:00 +00003240 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003241 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003242}
3243
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003244/// \brief Iterator adaptor that invents template argument location information
3245/// for each of the template arguments in its underlying iterator.
3246template<typename Derived, typename InputIterator>
3247class TemplateArgumentLocInventIterator {
3248 TreeTransform<Derived> &Self;
3249 InputIterator Iter;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003250
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003251public:
3252 typedef TemplateArgumentLoc value_type;
3253 typedef TemplateArgumentLoc reference;
3254 typedef typename std::iterator_traits<InputIterator>::difference_type
3255 difference_type;
3256 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003257
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003258 class pointer {
3259 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003260
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003261 public:
3262 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003263
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003264 const TemplateArgumentLoc *operator->() const { return &Arg; }
3265 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00003266
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003267 TemplateArgumentLocInventIterator() { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003268
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003269 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3270 InputIterator Iter)
3271 : Self(Self), Iter(Iter) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003272
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003273 TemplateArgumentLocInventIterator &operator++() {
3274 ++Iter;
3275 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003276 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003277
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003278 TemplateArgumentLocInventIterator operator++(int) {
3279 TemplateArgumentLocInventIterator Old(*this);
3280 ++(*this);
3281 return Old;
3282 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003283
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003284 reference operator*() const {
3285 TemplateArgumentLoc Result;
3286 Self.InventTemplateArgumentLoc(*Iter, Result);
3287 return Result;
3288 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003289
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003290 pointer operator->() const { return pointer(**this); }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003291
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003292 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3293 const TemplateArgumentLocInventIterator &Y) {
3294 return X.Iter == Y.Iter;
3295 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003296
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003297 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3298 const TemplateArgumentLocInventIterator &Y) {
3299 return X.Iter != Y.Iter;
3300 }
3301};
Chad Rosier4a9d7952012-08-08 18:46:20 +00003302
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003303template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003304template<typename InputIterator>
3305bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3306 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003307 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003308 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003309 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003310 TemplateArgumentLoc In = *First;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003311
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003312 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3313 // Unpack argument packs, which we translate them into separate
3314 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003315 // FIXME: We could do much better if we could guarantee that the
3316 // TemplateArgumentLocInfo for the pack expansion would be usable for
3317 // all of the template arguments in the argument pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003318 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003319 TemplateArgument::pack_iterator>
3320 PackLocIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003321 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003322 In.getArgument().pack_begin()),
3323 PackLocIterator(*this,
3324 In.getArgument().pack_end()),
3325 Outputs))
3326 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003327
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003328 continue;
3329 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003330
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003331 if (In.getArgument().isPackExpansion()) {
3332 // We have a pack expansion, for which we will be substituting into
3333 // the pattern.
3334 SourceLocation Ellipsis;
David Blaikiedc84cd52013-02-20 22:23:23 +00003335 Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003336 TemplateArgumentLoc Pattern
Eli Friedman850cf512013-06-20 04:11:21 +00003337 = getSema().getTemplateArgumentPackExpansionPattern(
3338 In, Ellipsis, OrigNumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003339
Chris Lattner686775d2011-07-20 06:58:45 +00003340 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003341 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3342 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003343
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003344 // Determine whether the set of unexpanded parameter packs can and should
3345 // be expanded.
3346 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003347 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00003348 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003349 if (getDerived().TryExpandParameterPacks(Ellipsis,
3350 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003351 Unexpanded,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003352 Expand,
Douglas Gregord3731192011-01-10 07:32:04 +00003353 RetainExpansion,
3354 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003355 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003356
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003357 if (!Expand) {
3358 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00003359 // transformation on the pack expansion, producing another pack
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003360 // expansion.
3361 TemplateArgumentLoc OutPattern;
3362 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3363 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3364 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003365
Douglas Gregorcded4f62011-01-14 17:04:44 +00003366 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3367 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003368 if (Out.getArgument().isNull())
3369 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003370
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003371 Outputs.addArgument(Out);
3372 continue;
3373 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003374
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003375 // The transform has determined that we should perform an elementwise
3376 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003377 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003378 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3379
3380 if (getDerived().TransformTemplateArgument(Pattern, Out))
3381 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003382
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003383 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003384 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3385 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003386 if (Out.getArgument().isNull())
3387 return true;
3388 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003389
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003390 Outputs.addArgument(Out);
3391 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003392
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003393 // If we're supposed to retain a pack expansion, do so by temporarily
3394 // forgetting the partially-substituted parameter pack.
3395 if (RetainExpansion) {
3396 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003397
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003398 if (getDerived().TransformTemplateArgument(Pattern, Out))
3399 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003400
Douglas Gregorcded4f62011-01-14 17:04:44 +00003401 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3402 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003403 if (Out.getArgument().isNull())
3404 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003405
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003406 Outputs.addArgument(Out);
3407 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003408
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003409 continue;
3410 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003411
3412 // The simple case:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003413 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003414 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003415
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003416 Outputs.addArgument(Out);
3417 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003418
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003419 return false;
3420
3421}
3422
Douglas Gregor577f75a2009-08-04 16:50:30 +00003423//===----------------------------------------------------------------------===//
3424// Type transformation
3425//===----------------------------------------------------------------------===//
3426
3427template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003428QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003429 if (getDerived().AlreadyTransformed(T))
3430 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003431
John McCalla2becad2009-10-21 00:40:46 +00003432 // Temporary workaround. All of these transformations should
3433 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003434 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3435 getDerived().getBaseLocation());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003436
John McCall43fed0d2010-11-12 08:19:04 +00003437 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003438
John McCalla2becad2009-10-21 00:40:46 +00003439 if (!NewDI)
3440 return QualType();
3441
3442 return NewDI->getType();
3443}
3444
3445template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003446TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003447 // Refine the base location to the type's location.
3448 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3449 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003450 if (getDerived().AlreadyTransformed(DI->getType()))
3451 return DI;
3452
3453 TypeLocBuilder TLB;
3454
3455 TypeLoc TL = DI->getTypeLoc();
3456 TLB.reserve(TL.getFullDataSize());
3457
John McCall43fed0d2010-11-12 08:19:04 +00003458 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003459 if (Result.isNull())
3460 return 0;
3461
John McCalla93c9342009-12-07 02:54:59 +00003462 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003463}
3464
3465template<typename Derived>
3466QualType
John McCall43fed0d2010-11-12 08:19:04 +00003467TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003468 switch (T.getTypeLocClass()) {
3469#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie39e6ab42013-02-18 22:06:02 +00003470#define TYPELOC(CLASS, PARENT) \
3471 case TypeLoc::CLASS: \
3472 return getDerived().Transform##CLASS##Type(TLB, \
3473 T.castAs<CLASS##TypeLoc>());
John McCalla2becad2009-10-21 00:40:46 +00003474#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003475 }
Mike Stump1eb44332009-09-09 15:08:12 +00003476
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003477 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003478}
3479
3480/// FIXME: By default, this routine adds type qualifiers only to types
3481/// that can have qualifiers, and silently suppresses those qualifiers
3482/// that are not permitted (e.g., qualifiers on reference or function
3483/// types). This is the right thing for template instantiation, but
3484/// probably not for other clients.
3485template<typename Derived>
3486QualType
3487TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003488 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003489 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003490
John McCall43fed0d2010-11-12 08:19:04 +00003491 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003492 if (Result.isNull())
3493 return QualType();
3494
3495 // Silently suppress qualifiers if the result type can't be qualified.
3496 // FIXME: this is the right thing for template instantiation, but
3497 // probably not for other clients.
3498 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003499 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003500
John McCallf85e1932011-06-15 23:02:42 +00003501 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003502 // resulting type.
3503 if (Quals.hasObjCLifetime()) {
3504 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3505 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003506 else if (Result.getObjCLifetime()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003507 // Objective-C ARC:
Douglas Gregore559ca12011-06-17 22:11:49 +00003508 // A lifetime qualifier applied to a substituted template parameter
3509 // overrides the lifetime qualifier from the template argument.
Douglas Gregor92d13872013-01-17 23:59:28 +00003510 const AutoType *AutoTy;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003511 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore559ca12011-06-17 22:11:49 +00003512 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3513 QualType Replacement = SubstTypeParam->getReplacementType();
3514 Qualifiers Qs = Replacement.getQualifiers();
3515 Qs.removeObjCLifetime();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003516 Replacement
Douglas Gregore559ca12011-06-17 22:11:49 +00003517 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3518 Qs);
3519 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier4a9d7952012-08-08 18:46:20 +00003520 SubstTypeParam->getReplacedParameter(),
Douglas Gregore559ca12011-06-17 22:11:49 +00003521 Replacement);
3522 TLB.TypeWasModifiedSafely(Result);
Douglas Gregor92d13872013-01-17 23:59:28 +00003523 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3524 // 'auto' types behave the same way as template parameters.
3525 QualType Deduced = AutoTy->getDeducedType();
3526 Qualifiers Qs = Deduced.getQualifiers();
3527 Qs.removeObjCLifetime();
3528 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3529 Qs);
Faisal Valifad9e132013-09-26 19:54:12 +00003530 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3531 AutoTy->isDependentType());
Douglas Gregor92d13872013-01-17 23:59:28 +00003532 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore559ca12011-06-17 22:11:49 +00003533 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003534 // Otherwise, complain about the addition of a qualifier to an
3535 // already-qualified type.
Eli Friedman44ee0a72013-06-07 20:31:48 +00003536 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003537 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003538 << Result << R;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003539
Douglas Gregore559ca12011-06-17 22:11:49 +00003540 Quals.removeObjCLifetime();
3541 }
3542 }
3543 }
John McCall28654742010-06-05 06:41:15 +00003544 if (!Quals.empty()) {
3545 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smith9807a2e2013-03-27 23:36:39 +00003546 // BuildQualifiedType might not add qualifiers if they are invalid.
3547 if (Result.hasLocalQualifiers())
3548 TLB.push<QualifiedTypeLoc>(Result);
John McCall28654742010-06-05 06:41:15 +00003549 // No location information to preserve.
3550 }
John McCalla2becad2009-10-21 00:40:46 +00003551
3552 return Result;
3553}
3554
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003555template<typename Derived>
3556TypeLoc
3557TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3558 QualType ObjectType,
3559 NamedDecl *UnqualLookup,
3560 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003561 QualType T = TL.getType();
3562 if (getDerived().AlreadyTransformed(T))
3563 return TL;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003564
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003565 TypeLocBuilder TLB;
3566 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003567
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003568 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003569 TemplateSpecializationTypeLoc SpecTL =
3570 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003571
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003572 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003573 getDerived().TransformTemplateName(SS,
3574 SpecTL.getTypePtr()->getTemplateName(),
3575 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003576 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003577 if (Template.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003578 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003579
3580 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003581 Template);
3582 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003583 DependentTemplateSpecializationTypeLoc SpecTL =
3584 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003585
Douglas Gregora88f09f2011-02-28 17:23:35 +00003586 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003587 = getDerived().RebuildTemplateName(SS,
3588 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003589 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003590 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003591 if (Template.isNull())
3592 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003593
3594 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003595 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003596 Template,
3597 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003598 } else {
3599 // Nothing special needs to be done for these.
3600 Result = getDerived().TransformType(TLB, TL);
3601 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003602
3603 if (Result.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003604 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003605
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003606 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3607}
3608
Douglas Gregorb71d8212011-03-02 18:32:08 +00003609template<typename Derived>
3610TypeSourceInfo *
3611TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3612 QualType ObjectType,
3613 NamedDecl *UnqualLookup,
3614 CXXScopeSpec &SS) {
3615 // FIXME: Painfully copy-paste from the above!
Chad Rosier4a9d7952012-08-08 18:46:20 +00003616
Douglas Gregorb71d8212011-03-02 18:32:08 +00003617 QualType T = TSInfo->getType();
3618 if (getDerived().AlreadyTransformed(T))
3619 return TSInfo;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003620
Douglas Gregorb71d8212011-03-02 18:32:08 +00003621 TypeLocBuilder TLB;
3622 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003623
Douglas Gregorb71d8212011-03-02 18:32:08 +00003624 TypeLoc TL = TSInfo->getTypeLoc();
3625 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003626 TemplateSpecializationTypeLoc SpecTL =
3627 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003628
Douglas Gregorb71d8212011-03-02 18:32:08 +00003629 TemplateName Template
3630 = getDerived().TransformTemplateName(SS,
3631 SpecTL.getTypePtr()->getTemplateName(),
3632 SpecTL.getTemplateNameLoc(),
3633 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003634 if (Template.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003635 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003636
3637 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003638 Template);
3639 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003640 DependentTemplateSpecializationTypeLoc SpecTL =
3641 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003642
Douglas Gregorb71d8212011-03-02 18:32:08 +00003643 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003644 = getDerived().RebuildTemplateName(SS,
3645 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003646 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003647 ObjectType, UnqualLookup);
3648 if (Template.isNull())
3649 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003650
3651 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003652 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003653 Template,
3654 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003655 } else {
3656 // Nothing special needs to be done for these.
3657 Result = getDerived().TransformType(TLB, TL);
3658 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003659
3660 if (Result.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003661 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003662
Douglas Gregorb71d8212011-03-02 18:32:08 +00003663 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3664}
3665
John McCalla2becad2009-10-21 00:40:46 +00003666template <class TyLoc> static inline
3667QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3668 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3669 NewT.setNameLoc(T.getNameLoc());
3670 return T.getType();
3671}
3672
John McCalla2becad2009-10-21 00:40:46 +00003673template<typename Derived>
3674QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003675 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003676 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3677 NewT.setBuiltinLoc(T.getBuiltinLoc());
3678 if (T.needsExtraLocalData())
3679 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3680 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003681}
Mike Stump1eb44332009-09-09 15:08:12 +00003682
Douglas Gregor577f75a2009-08-04 16:50:30 +00003683template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003684QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003685 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003686 // FIXME: recurse?
3687 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003688}
Mike Stump1eb44332009-09-09 15:08:12 +00003689
Douglas Gregor577f75a2009-08-04 16:50:30 +00003690template<typename Derived>
Reid Kleckner12df2462013-06-24 17:51:48 +00003691QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3692 DecayedTypeLoc TL) {
3693 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3694 if (OriginalType.isNull())
3695 return QualType();
3696
3697 QualType Result = TL.getType();
3698 if (getDerived().AlwaysRebuild() ||
3699 OriginalType != TL.getOriginalLoc().getType())
3700 Result = SemaRef.Context.getDecayedType(OriginalType);
3701 TLB.push<DecayedTypeLoc>(Result);
3702 // Nothing to set for DecayedTypeLoc.
3703 return Result;
3704}
3705
3706template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003707QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003708 PointerTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003709 QualType PointeeType
3710 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003711 if (PointeeType.isNull())
3712 return QualType();
3713
3714 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003715 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003716 // A dependent pointer type 'T *' has is being transformed such
3717 // that an Objective-C class type is being replaced for 'T'. The
3718 // resulting pointer type is an ObjCObjectPointerType, not a
3719 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003720 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003721
John McCallc12c5bb2010-05-15 11:32:37 +00003722 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3723 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003724 return Result;
3725 }
John McCall43fed0d2010-11-12 08:19:04 +00003726
Douglas Gregor92e986e2010-04-22 16:44:27 +00003727 if (getDerived().AlwaysRebuild() ||
3728 PointeeType != TL.getPointeeLoc().getType()) {
3729 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3730 if (Result.isNull())
3731 return QualType();
3732 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003733
John McCallf85e1932011-06-15 23:02:42 +00003734 // Objective-C ARC can add lifetime qualifiers to the type that we're
3735 // pointing to.
3736 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003737
Douglas Gregor92e986e2010-04-22 16:44:27 +00003738 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3739 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003740 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003741}
Mike Stump1eb44332009-09-09 15:08:12 +00003742
3743template<typename Derived>
3744QualType
John McCalla2becad2009-10-21 00:40:46 +00003745TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003746 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003747 QualType PointeeType
Chad Rosier4a9d7952012-08-08 18:46:20 +00003748 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3749 if (PointeeType.isNull())
3750 return QualType();
3751
3752 QualType Result = TL.getType();
3753 if (getDerived().AlwaysRebuild() ||
3754 PointeeType != TL.getPointeeLoc().getType()) {
3755 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003756 TL.getSigilLoc());
3757 if (Result.isNull())
3758 return QualType();
3759 }
3760
Douglas Gregor39968ad2010-04-22 16:50:51 +00003761 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003762 NewT.setSigilLoc(TL.getSigilLoc());
3763 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003764}
3765
John McCall85737a72009-10-30 00:06:24 +00003766/// Transforms a reference type. Note that somewhat paradoxically we
3767/// don't care whether the type itself is an l-value type or an r-value
3768/// type; we only care if the type was *written* as an l-value type
3769/// or an r-value type.
3770template<typename Derived>
3771QualType
3772TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003773 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003774 const ReferenceType *T = TL.getTypePtr();
3775
3776 // Note that this works with the pointee-as-written.
3777 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3778 if (PointeeType.isNull())
3779 return QualType();
3780
3781 QualType Result = TL.getType();
3782 if (getDerived().AlwaysRebuild() ||
3783 PointeeType != T->getPointeeTypeAsWritten()) {
3784 Result = getDerived().RebuildReferenceType(PointeeType,
3785 T->isSpelledAsLValue(),
3786 TL.getSigilLoc());
3787 if (Result.isNull())
3788 return QualType();
3789 }
3790
John McCallf85e1932011-06-15 23:02:42 +00003791 // Objective-C ARC can add lifetime qualifiers to the type that we're
3792 // referring to.
3793 TLB.TypeWasModifiedSafely(
3794 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3795
John McCall85737a72009-10-30 00:06:24 +00003796 // r-value references can be rebuilt as l-value references.
3797 ReferenceTypeLoc NewTL;
3798 if (isa<LValueReferenceType>(Result))
3799 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3800 else
3801 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3802 NewTL.setSigilLoc(TL.getSigilLoc());
3803
3804 return Result;
3805}
3806
Mike Stump1eb44332009-09-09 15:08:12 +00003807template<typename Derived>
3808QualType
John McCalla2becad2009-10-21 00:40:46 +00003809TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003810 LValueReferenceTypeLoc TL) {
3811 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003812}
3813
Mike Stump1eb44332009-09-09 15:08:12 +00003814template<typename Derived>
3815QualType
John McCalla2becad2009-10-21 00:40:46 +00003816TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003817 RValueReferenceTypeLoc TL) {
3818 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003819}
Mike Stump1eb44332009-09-09 15:08:12 +00003820
Douglas Gregor577f75a2009-08-04 16:50:30 +00003821template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003822QualType
John McCalla2becad2009-10-21 00:40:46 +00003823TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003824 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003825 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003826 if (PointeeType.isNull())
3827 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003828
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003829 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3830 TypeSourceInfo* NewClsTInfo = 0;
3831 if (OldClsTInfo) {
3832 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3833 if (!NewClsTInfo)
3834 return QualType();
3835 }
3836
3837 const MemberPointerType *T = TL.getTypePtr();
3838 QualType OldClsType = QualType(T->getClass(), 0);
3839 QualType NewClsType;
3840 if (NewClsTInfo)
3841 NewClsType = NewClsTInfo->getType();
3842 else {
3843 NewClsType = getDerived().TransformType(OldClsType);
3844 if (NewClsType.isNull())
3845 return QualType();
3846 }
Mike Stump1eb44332009-09-09 15:08:12 +00003847
John McCalla2becad2009-10-21 00:40:46 +00003848 QualType Result = TL.getType();
3849 if (getDerived().AlwaysRebuild() ||
3850 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003851 NewClsType != OldClsType) {
3852 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003853 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003854 if (Result.isNull())
3855 return QualType();
3856 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003857
John McCalla2becad2009-10-21 00:40:46 +00003858 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3859 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003860 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003861
3862 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003863}
3864
Mike Stump1eb44332009-09-09 15:08:12 +00003865template<typename Derived>
3866QualType
John McCalla2becad2009-10-21 00:40:46 +00003867TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003868 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003869 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003870 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003871 if (ElementType.isNull())
3872 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003873
John McCalla2becad2009-10-21 00:40:46 +00003874 QualType Result = TL.getType();
3875 if (getDerived().AlwaysRebuild() ||
3876 ElementType != T->getElementType()) {
3877 Result = getDerived().RebuildConstantArrayType(ElementType,
3878 T->getSizeModifier(),
3879 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003880 T->getIndexTypeCVRQualifiers(),
3881 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003882 if (Result.isNull())
3883 return QualType();
3884 }
Eli Friedman457a3772012-01-25 22:19:07 +00003885
3886 // We might have either a ConstantArrayType or a VariableArrayType now:
3887 // a ConstantArrayType is allowed to have an element type which is a
3888 // VariableArrayType if the type is dependent. Fortunately, all array
3889 // types have the same location layout.
3890 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003891 NewTL.setLBracketLoc(TL.getLBracketLoc());
3892 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003893
John McCalla2becad2009-10-21 00:40:46 +00003894 Expr *Size = TL.getSizeExpr();
3895 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003896 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3897 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003898 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003899 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003900 }
3901 NewTL.setSizeExpr(Size);
3902
3903 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003904}
Mike Stump1eb44332009-09-09 15:08:12 +00003905
Douglas Gregor577f75a2009-08-04 16:50:30 +00003906template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003907QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003908 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003909 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003910 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003911 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003912 if (ElementType.isNull())
3913 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003914
John McCalla2becad2009-10-21 00:40:46 +00003915 QualType Result = TL.getType();
3916 if (getDerived().AlwaysRebuild() ||
3917 ElementType != T->getElementType()) {
3918 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003919 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003920 T->getIndexTypeCVRQualifiers(),
3921 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003922 if (Result.isNull())
3923 return QualType();
3924 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003925
John McCalla2becad2009-10-21 00:40:46 +00003926 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3927 NewTL.setLBracketLoc(TL.getLBracketLoc());
3928 NewTL.setRBracketLoc(TL.getRBracketLoc());
3929 NewTL.setSizeExpr(0);
3930
3931 return Result;
3932}
3933
3934template<typename Derived>
3935QualType
3936TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003937 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003938 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003939 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3940 if (ElementType.isNull())
3941 return QualType();
3942
John McCall60d7b3a2010-08-24 06:29:42 +00003943 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003944 = getDerived().TransformExpr(T->getSizeExpr());
3945 if (SizeResult.isInvalid())
3946 return QualType();
3947
John McCall9ae2f072010-08-23 23:25:46 +00003948 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003949
3950 QualType Result = TL.getType();
3951 if (getDerived().AlwaysRebuild() ||
3952 ElementType != T->getElementType() ||
3953 Size != T->getSizeExpr()) {
3954 Result = getDerived().RebuildVariableArrayType(ElementType,
3955 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003956 Size,
John McCalla2becad2009-10-21 00:40:46 +00003957 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003958 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003959 if (Result.isNull())
3960 return QualType();
3961 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003962
John McCalla2becad2009-10-21 00:40:46 +00003963 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3964 NewTL.setLBracketLoc(TL.getLBracketLoc());
3965 NewTL.setRBracketLoc(TL.getRBracketLoc());
3966 NewTL.setSizeExpr(Size);
3967
3968 return Result;
3969}
3970
3971template<typename Derived>
3972QualType
3973TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003974 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003975 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003976 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3977 if (ElementType.isNull())
3978 return QualType();
3979
Richard Smithf6702a32011-12-20 02:08:33 +00003980 // Array bounds are constant expressions.
3981 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3982 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003983
John McCall3b657512011-01-19 10:06:00 +00003984 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3985 Expr *origSize = TL.getSizeExpr();
3986 if (!origSize) origSize = T->getSizeExpr();
3987
3988 ExprResult sizeResult
3989 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003990 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003991 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003992 return QualType();
3993
John McCall3b657512011-01-19 10:06:00 +00003994 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003995
3996 QualType Result = TL.getType();
3997 if (getDerived().AlwaysRebuild() ||
3998 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003999 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00004000 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4001 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00004002 size,
John McCalla2becad2009-10-21 00:40:46 +00004003 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00004004 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00004005 if (Result.isNull())
4006 return QualType();
4007 }
John McCalla2becad2009-10-21 00:40:46 +00004008
4009 // We might have any sort of array type now, but fortunately they
4010 // all have the same location layout.
4011 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4012 NewTL.setLBracketLoc(TL.getLBracketLoc());
4013 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00004014 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00004015
4016 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004017}
Mike Stump1eb44332009-09-09 15:08:12 +00004018
4019template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00004020QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00004021 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004022 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004023 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004024
4025 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00004026 QualType ElementType = getDerived().TransformType(T->getElementType());
4027 if (ElementType.isNull())
4028 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004029
Richard Smithf6702a32011-12-20 02:08:33 +00004030 // Vector sizes are constant expressions.
4031 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4032 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00004033
John McCall60d7b3a2010-08-24 06:29:42 +00004034 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00004035 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004036 if (Size.isInvalid())
4037 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004038
John McCalla2becad2009-10-21 00:40:46 +00004039 QualType Result = TL.getType();
4040 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00004041 ElementType != T->getElementType() ||
4042 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00004043 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00004044 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00004045 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00004046 if (Result.isNull())
4047 return QualType();
4048 }
John McCalla2becad2009-10-21 00:40:46 +00004049
4050 // Result might be dependent or not.
4051 if (isa<DependentSizedExtVectorType>(Result)) {
4052 DependentSizedExtVectorTypeLoc NewTL
4053 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4054 NewTL.setNameLoc(TL.getNameLoc());
4055 } else {
4056 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4057 NewTL.setNameLoc(TL.getNameLoc());
4058 }
4059
4060 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004061}
Mike Stump1eb44332009-09-09 15:08:12 +00004062
4063template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004064QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004065 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004066 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004067 QualType ElementType = getDerived().TransformType(T->getElementType());
4068 if (ElementType.isNull())
4069 return QualType();
4070
John McCalla2becad2009-10-21 00:40:46 +00004071 QualType Result = TL.getType();
4072 if (getDerived().AlwaysRebuild() ||
4073 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00004074 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00004075 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00004076 if (Result.isNull())
4077 return QualType();
4078 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004079
John McCalla2becad2009-10-21 00:40:46 +00004080 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4081 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00004082
John McCalla2becad2009-10-21 00:40:46 +00004083 return Result;
4084}
4085
4086template<typename Derived>
4087QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004088 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004089 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004090 QualType ElementType = getDerived().TransformType(T->getElementType());
4091 if (ElementType.isNull())
4092 return QualType();
4093
4094 QualType Result = TL.getType();
4095 if (getDerived().AlwaysRebuild() ||
4096 ElementType != T->getElementType()) {
4097 Result = getDerived().RebuildExtVectorType(ElementType,
4098 T->getNumElements(),
4099 /*FIXME*/ SourceLocation());
4100 if (Result.isNull())
4101 return QualType();
4102 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004103
John McCalla2becad2009-10-21 00:40:46 +00004104 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4105 NewTL.setNameLoc(TL.getNameLoc());
4106
4107 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004108}
Mike Stump1eb44332009-09-09 15:08:12 +00004109
David Blaikiedc84cd52013-02-20 22:23:23 +00004110template <typename Derived>
4111ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4112 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4113 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00004114 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004115 TypeSourceInfo *NewDI = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004116
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004117 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004118 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004119 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004120 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00004121 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004122
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004123 TypeLocBuilder TLB;
4124 TypeLoc NewTL = OldDI->getTypeLoc();
4125 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004126
4127 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004128 OldExpansionTL.getPatternLoc());
4129 if (Result.isNull())
4130 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004131
4132 Result = RebuildPackExpansionType(Result,
4133 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004134 OldExpansionTL.getEllipsisLoc(),
4135 NumExpansions);
4136 if (Result.isNull())
4137 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004138
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004139 PackExpansionTypeLoc NewExpansionTL
4140 = TLB.push<PackExpansionTypeLoc>(Result);
4141 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4142 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4143 } else
4144 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00004145 if (!NewDI)
4146 return 0;
4147
John McCallfb44de92011-05-01 22:35:37 +00004148 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00004149 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00004150
4151 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4152 OldParm->getDeclContext(),
4153 OldParm->getInnerLocStart(),
4154 OldParm->getLocation(),
4155 OldParm->getIdentifier(),
4156 NewDI->getType(),
4157 NewDI,
4158 OldParm->getStorageClass(),
John McCallfb44de92011-05-01 22:35:37 +00004159 /* DefArg */ NULL);
4160 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4161 OldParm->getFunctionScopeIndex() + indexAdjustment);
4162 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00004163}
4164
4165template<typename Derived>
4166bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00004167 TransformFunctionTypeParams(SourceLocation Loc,
4168 ParmVarDecl **Params, unsigned NumParams,
4169 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00004170 SmallVectorImpl<QualType> &OutParamTypes,
4171 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00004172 int indexAdjustment = 0;
4173
Douglas Gregora009b592011-01-07 00:20:55 +00004174 for (unsigned i = 0; i != NumParams; ++i) {
4175 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00004176 assert(OldParm->getFunctionScopeIndex() == i);
4177
David Blaikiedc84cd52013-02-20 22:23:23 +00004178 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004179 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004180 if (OldParm->isParameterPack()) {
4181 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00004182 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00004183
Douglas Gregor603cfb42011-01-05 23:12:31 +00004184 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004185 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00004186 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004187 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4188 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004189 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4190
Douglas Gregor603cfb42011-01-05 23:12:31 +00004191 // Determine whether we should expand the parameter packs.
4192 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004193 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004194 Optional<unsigned> OrigNumExpansions =
4195 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004196 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004197 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4198 Pattern.getSourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004199 Unexpanded,
4200 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004201 RetainExpansion,
4202 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004203 return true;
4204 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004205
Douglas Gregor603cfb42011-01-05 23:12:31 +00004206 if (ShouldExpand) {
4207 // Expand the function parameter pack into multiple, separate
4208 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00004209 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00004210 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004211 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004212 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004213 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004214 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004215 OrigNumExpansions,
4216 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004217 if (!NewParm)
4218 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004219
Douglas Gregora009b592011-01-07 00:20:55 +00004220 OutParamTypes.push_back(NewParm->getType());
4221 if (PVars)
4222 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004223 }
Douglas Gregord3731192011-01-10 07:32:04 +00004224
4225 // If we're supposed to retain a pack expansion, do so by temporarily
4226 // forgetting the partially-substituted parameter pack.
4227 if (RetainExpansion) {
4228 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004229 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004230 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004231 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004232 OrigNumExpansions,
4233 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00004234 if (!NewParm)
4235 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004236
Douglas Gregord3731192011-01-10 07:32:04 +00004237 OutParamTypes.push_back(NewParm->getType());
4238 if (PVars)
4239 PVars->push_back(NewParm);
4240 }
4241
John McCallfb44de92011-05-01 22:35:37 +00004242 // The next parameter should have the same adjustment as the
4243 // last thing we pushed, but we post-incremented indexAdjustment
4244 // on every push. Also, if we push nothing, the adjustment should
4245 // go down by one.
4246 indexAdjustment--;
4247
Douglas Gregor603cfb42011-01-05 23:12:31 +00004248 // We're done with the pack expansion.
4249 continue;
4250 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004251
4252 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004253 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004254 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4255 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004256 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004257 NumExpansions,
4258 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004259 } else {
David Blaikiedc84cd52013-02-20 22:23:23 +00004260 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie66874fb2013-02-21 01:47:18 +00004261 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004262 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004263
John McCall21ef0fa2010-03-11 09:03:00 +00004264 if (!NewParm)
4265 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004266
Douglas Gregora009b592011-01-07 00:20:55 +00004267 OutParamTypes.push_back(NewParm->getType());
4268 if (PVars)
4269 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004270 continue;
4271 }
John McCall21ef0fa2010-03-11 09:03:00 +00004272
4273 // Deal with the possibility that we don't have a parameter
4274 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004275 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004276 bool IsPackExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004277 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004278 QualType NewType;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004279 if (const PackExpansionType *Expansion
Douglas Gregor603cfb42011-01-05 23:12:31 +00004280 = dyn_cast<PackExpansionType>(OldType)) {
4281 // We have a function parameter pack that may need to be expanded.
4282 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004283 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004284 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004285
Douglas Gregor603cfb42011-01-05 23:12:31 +00004286 // Determine whether we should expand the parameter packs.
4287 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004288 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004289 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004290 Unexpanded,
4291 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004292 RetainExpansion,
4293 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004294 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004295 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004296
Douglas Gregor603cfb42011-01-05 23:12:31 +00004297 if (ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004298 // Expand the function parameter pack into multiple, separate
Douglas Gregor603cfb42011-01-05 23:12:31 +00004299 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004300 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004301 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4302 QualType NewType = getDerived().TransformType(Pattern);
4303 if (NewType.isNull())
4304 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004305
Douglas Gregora009b592011-01-07 00:20:55 +00004306 OutParamTypes.push_back(NewType);
4307 if (PVars)
4308 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004309 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004310
Douglas Gregor603cfb42011-01-05 23:12:31 +00004311 // We're done with the pack expansion.
4312 continue;
4313 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004314
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004315 // If we're supposed to retain a pack expansion, do so by temporarily
4316 // forgetting the partially-substituted parameter pack.
4317 if (RetainExpansion) {
4318 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4319 QualType NewType = getDerived().TransformType(Pattern);
4320 if (NewType.isNull())
4321 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004322
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004323 OutParamTypes.push_back(NewType);
4324 if (PVars)
4325 PVars->push_back(0);
4326 }
Douglas Gregord3731192011-01-10 07:32:04 +00004327
Chad Rosier4a9d7952012-08-08 18:46:20 +00004328 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004329 // expansion.
4330 OldType = Expansion->getPattern();
4331 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004332 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4333 NewType = getDerived().TransformType(OldType);
4334 } else {
4335 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004336 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004337
Douglas Gregor603cfb42011-01-05 23:12:31 +00004338 if (NewType.isNull())
4339 return true;
4340
4341 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004342 NewType = getSema().Context.getPackExpansionType(NewType,
4343 NumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004344
Douglas Gregora009b592011-01-07 00:20:55 +00004345 OutParamTypes.push_back(NewType);
4346 if (PVars)
4347 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004348 }
4349
John McCallfb44de92011-05-01 22:35:37 +00004350#ifndef NDEBUG
4351 if (PVars) {
4352 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4353 if (ParmVarDecl *parm = (*PVars)[i])
4354 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004355 }
John McCallfb44de92011-05-01 22:35:37 +00004356#endif
4357
4358 return false;
4359}
John McCall21ef0fa2010-03-11 09:03:00 +00004360
4361template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004362QualType
John McCalla2becad2009-10-21 00:40:46 +00004363TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004364 FunctionProtoTypeLoc TL) {
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004365 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4366}
4367
4368template<typename Derived>
4369QualType
4370TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4371 FunctionProtoTypeLoc TL,
4372 CXXRecordDecl *ThisContext,
4373 unsigned ThisTypeQuals) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004374 // Transform the parameters and return type.
4375 //
Richard Smithe6975e92012-04-17 00:58:00 +00004376 // We are required to instantiate the params and return type in source order.
Douglas Gregordab60ad2010-10-01 18:44:50 +00004377 // When the function has a trailing return type, we instantiate the
4378 // parameters before the return type, since the return type can then refer
4379 // to the parameters themselves (via decltype, sizeof, etc.).
4380 //
Chris Lattner686775d2011-07-20 06:58:45 +00004381 SmallVector<QualType, 4> ParamTypes;
4382 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004383 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004384
Douglas Gregordab60ad2010-10-01 18:44:50 +00004385 QualType ResultType;
4386
Richard Smith9fbf3272012-08-14 22:51:13 +00004387 if (T->hasTrailingReturn()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004388 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004389 TL.getParmArray(),
4390 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004391 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004392 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004393 return QualType();
4394
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004395 {
4396 // C++11 [expr.prim.general]p3:
Chad Rosier4a9d7952012-08-08 18:46:20 +00004397 // If a declaration declares a member function or member function
4398 // template of a class X, the expression this is a prvalue of type
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004399 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier4a9d7952012-08-08 18:46:20 +00004400 // and the end of the function-definition, member-declarator, or
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004401 // declarator.
4402 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004403
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004404 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4405 if (ResultType.isNull())
4406 return QualType();
4407 }
Douglas Gregordab60ad2010-10-01 18:44:50 +00004408 }
4409 else {
4410 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4411 if (ResultType.isNull())
4412 return QualType();
4413
Chad Rosier4a9d7952012-08-08 18:46:20 +00004414 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004415 TL.getParmArray(),
4416 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004417 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004418 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004419 return QualType();
4420 }
4421
Richard Smithe6975e92012-04-17 00:58:00 +00004422 // FIXME: Need to transform the exception-specification too.
4423
John McCalla2becad2009-10-21 00:40:46 +00004424 QualType Result = TL.getType();
4425 if (getDerived().AlwaysRebuild() ||
4426 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004427 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004428 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
Jordan Rosebea522f2013-03-08 21:51:21 +00004429 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00004430 T->getExtProtoInfo());
John McCalla2becad2009-10-21 00:40:46 +00004431 if (Result.isNull())
4432 return QualType();
4433 }
Mike Stump1eb44332009-09-09 15:08:12 +00004434
John McCalla2becad2009-10-21 00:40:46 +00004435 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004436 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004437 NewTL.setLParenLoc(TL.getLParenLoc());
4438 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004439 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004440 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4441 NewTL.setArg(i, ParamDecls[i]);
4442
4443 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004444}
Mike Stump1eb44332009-09-09 15:08:12 +00004445
Douglas Gregor577f75a2009-08-04 16:50:30 +00004446template<typename Derived>
4447QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004448 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004449 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004450 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004451 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4452 if (ResultType.isNull())
4453 return QualType();
4454
4455 QualType Result = TL.getType();
4456 if (getDerived().AlwaysRebuild() ||
4457 ResultType != T->getResultType())
4458 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4459
4460 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004461 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004462 NewTL.setLParenLoc(TL.getLParenLoc());
4463 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004464 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004465
4466 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004467}
Mike Stump1eb44332009-09-09 15:08:12 +00004468
John McCalled976492009-12-04 22:46:56 +00004469template<typename Derived> QualType
4470TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004471 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004472 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004473 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004474 if (!D)
4475 return QualType();
4476
4477 QualType Result = TL.getType();
4478 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4479 Result = getDerived().RebuildUnresolvedUsingType(D);
4480 if (Result.isNull())
4481 return QualType();
4482 }
4483
4484 // We might get an arbitrary type spec type back. We should at
4485 // least always get a type spec type, though.
4486 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4487 NewTL.setNameLoc(TL.getNameLoc());
4488
4489 return Result;
4490}
4491
Douglas Gregor577f75a2009-08-04 16:50:30 +00004492template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004493QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004494 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004495 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004496 TypedefNameDecl *Typedef
4497 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4498 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004499 if (!Typedef)
4500 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004501
John McCalla2becad2009-10-21 00:40:46 +00004502 QualType Result = TL.getType();
4503 if (getDerived().AlwaysRebuild() ||
4504 Typedef != T->getDecl()) {
4505 Result = getDerived().RebuildTypedefType(Typedef);
4506 if (Result.isNull())
4507 return QualType();
4508 }
Mike Stump1eb44332009-09-09 15:08:12 +00004509
John McCalla2becad2009-10-21 00:40:46 +00004510 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4511 NewTL.setNameLoc(TL.getNameLoc());
4512
4513 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004514}
Mike Stump1eb44332009-09-09 15:08:12 +00004515
Douglas Gregor577f75a2009-08-04 16:50:30 +00004516template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004517QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004518 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004519 // typeof expressions are not potentially evaluated contexts
Eli Friedman80bfa3d2012-09-26 04:34:21 +00004520 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4521 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00004522
John McCall60d7b3a2010-08-24 06:29:42 +00004523 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004524 if (E.isInvalid())
4525 return QualType();
4526
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004527 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4528 if (E.isInvalid())
4529 return QualType();
4530
John McCalla2becad2009-10-21 00:40:46 +00004531 QualType Result = TL.getType();
4532 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004533 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004534 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004535 if (Result.isNull())
4536 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004537 }
John McCalla2becad2009-10-21 00:40:46 +00004538 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004539
John McCalla2becad2009-10-21 00:40:46 +00004540 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004541 NewTL.setTypeofLoc(TL.getTypeofLoc());
4542 NewTL.setLParenLoc(TL.getLParenLoc());
4543 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004544
4545 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004546}
Mike Stump1eb44332009-09-09 15:08:12 +00004547
4548template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004549QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004550 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004551 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4552 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4553 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004554 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004555
John McCalla2becad2009-10-21 00:40:46 +00004556 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004557 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4558 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004559 if (Result.isNull())
4560 return QualType();
4561 }
Mike Stump1eb44332009-09-09 15:08:12 +00004562
John McCalla2becad2009-10-21 00:40:46 +00004563 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004564 NewTL.setTypeofLoc(TL.getTypeofLoc());
4565 NewTL.setLParenLoc(TL.getLParenLoc());
4566 NewTL.setRParenLoc(TL.getRParenLoc());
4567 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004568
4569 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004570}
Mike Stump1eb44332009-09-09 15:08:12 +00004571
4572template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004573QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004574 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004575 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004576
Douglas Gregor670444e2009-08-04 22:27:00 +00004577 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004578 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4579 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004580
John McCall60d7b3a2010-08-24 06:29:42 +00004581 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004582 if (E.isInvalid())
4583 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004584
Richard Smith76f3f692012-02-22 02:04:18 +00004585 E = getSema().ActOnDecltypeExpression(E.take());
4586 if (E.isInvalid())
4587 return QualType();
4588
John McCalla2becad2009-10-21 00:40:46 +00004589 QualType Result = TL.getType();
4590 if (getDerived().AlwaysRebuild() ||
4591 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004592 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004593 if (Result.isNull())
4594 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004595 }
John McCalla2becad2009-10-21 00:40:46 +00004596 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004597
John McCalla2becad2009-10-21 00:40:46 +00004598 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4599 NewTL.setNameLoc(TL.getNameLoc());
4600
4601 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004602}
4603
4604template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004605QualType TreeTransform<Derived>::TransformUnaryTransformType(
4606 TypeLocBuilder &TLB,
4607 UnaryTransformTypeLoc TL) {
4608 QualType Result = TL.getType();
4609 if (Result->isDependentType()) {
4610 const UnaryTransformType *T = TL.getTypePtr();
4611 QualType NewBase =
4612 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4613 Result = getDerived().RebuildUnaryTransformType(NewBase,
4614 T->getUTTKind(),
4615 TL.getKWLoc());
4616 if (Result.isNull())
4617 return QualType();
4618 }
4619
4620 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4621 NewTL.setKWLoc(TL.getKWLoc());
4622 NewTL.setParensRange(TL.getParensRange());
4623 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4624 return Result;
4625}
4626
4627template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004628QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4629 AutoTypeLoc TL) {
4630 const AutoType *T = TL.getTypePtr();
4631 QualType OldDeduced = T->getDeducedType();
4632 QualType NewDeduced;
4633 if (!OldDeduced.isNull()) {
4634 NewDeduced = getDerived().TransformType(OldDeduced);
4635 if (NewDeduced.isNull())
4636 return QualType();
4637 }
4638
4639 QualType Result = TL.getType();
Richard Smithdc7a4f52013-04-30 13:56:41 +00004640 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4641 T->isDependentType()) {
Richard Smitha2c36462013-04-26 16:15:35 +00004642 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith34b41d92011-02-20 03:19:35 +00004643 if (Result.isNull())
4644 return QualType();
4645 }
4646
4647 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4648 NewTL.setNameLoc(TL.getNameLoc());
4649
4650 return Result;
4651}
4652
4653template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004654QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004655 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004656 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004657 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004658 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4659 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004660 if (!Record)
4661 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004662
John McCalla2becad2009-10-21 00:40:46 +00004663 QualType Result = TL.getType();
4664 if (getDerived().AlwaysRebuild() ||
4665 Record != T->getDecl()) {
4666 Result = getDerived().RebuildRecordType(Record);
4667 if (Result.isNull())
4668 return QualType();
4669 }
Mike Stump1eb44332009-09-09 15:08:12 +00004670
John McCalla2becad2009-10-21 00:40:46 +00004671 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4672 NewTL.setNameLoc(TL.getNameLoc());
4673
4674 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004675}
Mike Stump1eb44332009-09-09 15:08:12 +00004676
4677template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004678QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004679 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004680 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004681 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004682 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4683 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004684 if (!Enum)
4685 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004686
John McCalla2becad2009-10-21 00:40:46 +00004687 QualType Result = TL.getType();
4688 if (getDerived().AlwaysRebuild() ||
4689 Enum != T->getDecl()) {
4690 Result = getDerived().RebuildEnumType(Enum);
4691 if (Result.isNull())
4692 return QualType();
4693 }
Mike Stump1eb44332009-09-09 15:08:12 +00004694
John McCalla2becad2009-10-21 00:40:46 +00004695 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4696 NewTL.setNameLoc(TL.getNameLoc());
4697
4698 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004699}
John McCall7da24312009-09-05 00:15:47 +00004700
John McCall3cb0ebd2010-03-10 03:28:59 +00004701template<typename Derived>
4702QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4703 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004704 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004705 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4706 TL.getTypePtr()->getDecl());
4707 if (!D) return QualType();
4708
4709 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4710 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4711 return T;
4712}
4713
Douglas Gregor577f75a2009-08-04 16:50:30 +00004714template<typename Derived>
4715QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004716 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004717 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004718 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004719}
4720
Mike Stump1eb44332009-09-09 15:08:12 +00004721template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004722QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004723 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004724 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004725 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004726
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004727 // Substitute into the replacement type, which itself might involve something
4728 // that needs to be transformed. This only tends to occur with default
4729 // template arguments of template template parameters.
4730 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4731 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4732 if (Replacement.isNull())
4733 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004734
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004735 // Always canonicalize the replacement type.
4736 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4737 QualType Result
Chad Rosier4a9d7952012-08-08 18:46:20 +00004738 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004739 Replacement);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004740
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004741 // Propagate type-source information.
4742 SubstTemplateTypeParmTypeLoc NewTL
4743 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4744 NewTL.setNameLoc(TL.getNameLoc());
4745 return Result;
4746
John McCall49a832b2009-10-18 09:09:24 +00004747}
4748
4749template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004750QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4751 TypeLocBuilder &TLB,
4752 SubstTemplateTypeParmPackTypeLoc TL) {
4753 return TransformTypeSpecType(TLB, TL);
4754}
4755
4756template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004757QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004758 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004759 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004760 const TemplateSpecializationType *T = TL.getTypePtr();
4761
Douglas Gregor1d752d72011-03-02 18:46:51 +00004762 // The nested-name-specifier never matters in a TemplateSpecializationType,
4763 // because we can't have a dependent nested-name-specifier anyway.
4764 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004765 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004766 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4767 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004768 if (Template.isNull())
4769 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004770
John McCall43fed0d2010-11-12 08:19:04 +00004771 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4772}
4773
Eli Friedmanb001de72011-10-06 23:00:33 +00004774template<typename Derived>
4775QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4776 AtomicTypeLoc TL) {
4777 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4778 if (ValueType.isNull())
4779 return QualType();
4780
4781 QualType Result = TL.getType();
4782 if (getDerived().AlwaysRebuild() ||
4783 ValueType != TL.getValueLoc().getType()) {
4784 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4785 if (Result.isNull())
4786 return QualType();
4787 }
4788
4789 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4790 NewTL.setKWLoc(TL.getKWLoc());
4791 NewTL.setLParenLoc(TL.getLParenLoc());
4792 NewTL.setRParenLoc(TL.getRParenLoc());
4793
4794 return Result;
4795}
4796
Chad Rosier4a9d7952012-08-08 18:46:20 +00004797 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004798 /// container that provides a \c getArgLoc() member function.
4799 ///
4800 /// This iterator is intended to be used with the iterator form of
4801 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4802 template<typename ArgLocContainer>
4803 class TemplateArgumentLocContainerIterator {
4804 ArgLocContainer *Container;
4805 unsigned Index;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004806
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004807 public:
4808 typedef TemplateArgumentLoc value_type;
4809 typedef TemplateArgumentLoc reference;
4810 typedef int difference_type;
4811 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004812
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004813 class pointer {
4814 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004815
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004816 public:
4817 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004818
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004819 const TemplateArgumentLoc *operator->() const {
4820 return &Arg;
4821 }
4822 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004823
4824
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004825 TemplateArgumentLocContainerIterator() {}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004826
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004827 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4828 unsigned Index)
4829 : Container(&Container), Index(Index) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004830
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004831 TemplateArgumentLocContainerIterator &operator++() {
4832 ++Index;
4833 return *this;
4834 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004835
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004836 TemplateArgumentLocContainerIterator operator++(int) {
4837 TemplateArgumentLocContainerIterator Old(*this);
4838 ++(*this);
4839 return Old;
4840 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004841
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004842 TemplateArgumentLoc operator*() const {
4843 return Container->getArgLoc(Index);
4844 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004845
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004846 pointer operator->() const {
4847 return pointer(Container->getArgLoc(Index));
4848 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004849
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004850 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004851 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004852 return X.Container == Y.Container && X.Index == Y.Index;
4853 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004854
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004855 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004856 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004857 return !(X == Y);
4858 }
4859 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004860
4861
John McCall43fed0d2010-11-12 08:19:04 +00004862template <typename Derived>
4863QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4864 TypeLocBuilder &TLB,
4865 TemplateSpecializationTypeLoc TL,
4866 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004867 TemplateArgumentListInfo NewTemplateArgs;
4868 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4869 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004870 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4871 ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004872 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004873 ArgIterator(TL, TL.getNumArgs()),
4874 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004875 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004876
John McCall833ca992009-10-29 08:12:44 +00004877 // FIXME: maybe don't rebuild if all the template arguments are the same.
4878
4879 QualType Result =
4880 getDerived().RebuildTemplateSpecializationType(Template,
4881 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004882 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004883
4884 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004885 // Specializations of template template parameters are represented as
4886 // TemplateSpecializationTypes, and substitution of type alias templates
4887 // within a dependent context can transform them into
4888 // DependentTemplateSpecializationTypes.
4889 if (isa<DependentTemplateSpecializationType>(Result)) {
4890 DependentTemplateSpecializationTypeLoc NewTL
4891 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004892 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004893 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004894 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004895 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004896 NewTL.setLAngleLoc(TL.getLAngleLoc());
4897 NewTL.setRAngleLoc(TL.getRAngleLoc());
4898 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4899 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4900 return Result;
4901 }
4902
John McCall833ca992009-10-29 08:12:44 +00004903 TemplateSpecializationTypeLoc NewTL
4904 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004905 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004906 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4907 NewTL.setLAngleLoc(TL.getLAngleLoc());
4908 NewTL.setRAngleLoc(TL.getRAngleLoc());
4909 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4910 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004911 }
Mike Stump1eb44332009-09-09 15:08:12 +00004912
John McCall833ca992009-10-29 08:12:44 +00004913 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004914}
Mike Stump1eb44332009-09-09 15:08:12 +00004915
Douglas Gregora88f09f2011-02-28 17:23:35 +00004916template <typename Derived>
4917QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4918 TypeLocBuilder &TLB,
4919 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004920 TemplateName Template,
4921 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004922 TemplateArgumentListInfo NewTemplateArgs;
4923 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4924 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4925 typedef TemplateArgumentLocContainerIterator<
4926 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004927 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004928 ArgIterator(TL, TL.getNumArgs()),
4929 NewTemplateArgs))
4930 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004931
Douglas Gregora88f09f2011-02-28 17:23:35 +00004932 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier4a9d7952012-08-08 18:46:20 +00004933
Douglas Gregora88f09f2011-02-28 17:23:35 +00004934 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4935 QualType Result
4936 = getSema().Context.getDependentTemplateSpecializationType(
4937 TL.getTypePtr()->getKeyword(),
4938 DTN->getQualifier(),
4939 DTN->getIdentifier(),
4940 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004941
Douglas Gregora88f09f2011-02-28 17:23:35 +00004942 DependentTemplateSpecializationTypeLoc NewTL
4943 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004944 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004945 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004946 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004947 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004948 NewTL.setLAngleLoc(TL.getLAngleLoc());
4949 NewTL.setRAngleLoc(TL.getRAngleLoc());
4950 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4951 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4952 return Result;
4953 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004954
4955 QualType Result
Douglas Gregora88f09f2011-02-28 17:23:35 +00004956 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004957 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004958 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004959
Douglas Gregora88f09f2011-02-28 17:23:35 +00004960 if (!Result.isNull()) {
4961 /// FIXME: Wrap this in an elaborated-type-specifier?
4962 TemplateSpecializationTypeLoc NewTL
4963 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004964 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004965 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004966 NewTL.setLAngleLoc(TL.getLAngleLoc());
4967 NewTL.setRAngleLoc(TL.getRAngleLoc());
4968 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4969 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4970 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004971
Douglas Gregora88f09f2011-02-28 17:23:35 +00004972 return Result;
4973}
4974
Mike Stump1eb44332009-09-09 15:08:12 +00004975template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004976QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004977TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004978 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004979 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004980
Douglas Gregor9e876872011-03-01 18:12:44 +00004981 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004982 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004983 if (TL.getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004984 QualifierLoc
Douglas Gregor9e876872011-03-01 18:12:44 +00004985 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4986 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004987 return QualType();
4988 }
Mike Stump1eb44332009-09-09 15:08:12 +00004989
John McCall43fed0d2010-11-12 08:19:04 +00004990 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4991 if (NamedT.isNull())
4992 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004993
Richard Smith3e4c6c42011-05-05 21:57:07 +00004994 // C++0x [dcl.type.elab]p2:
4995 // If the identifier resolves to a typedef-name or the simple-template-id
4996 // resolves to an alias template specialization, the
4997 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004998 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4999 if (const TemplateSpecializationType *TST =
5000 NamedT->getAs<TemplateSpecializationType>()) {
5001 TemplateName Template = TST->getTemplateName();
5002 if (TypeAliasTemplateDecl *TAT =
5003 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
5004 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5005 diag::err_tag_reference_non_tag) << 4;
5006 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5007 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00005008 }
5009 }
5010
John McCalla2becad2009-10-21 00:40:46 +00005011 QualType Result = TL.getType();
5012 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00005013 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005014 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00005015 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00005016 T->getKeyword(),
Douglas Gregor9e876872011-03-01 18:12:44 +00005017 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00005018 if (Result.isNull())
5019 return QualType();
5020 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00005021
Abramo Bagnara465d41b2010-05-11 21:36:43 +00005022 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005023 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00005024 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00005025 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00005026}
Mike Stump1eb44332009-09-09 15:08:12 +00005027
5028template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00005029QualType TreeTransform<Derived>::TransformAttributedType(
5030 TypeLocBuilder &TLB,
5031 AttributedTypeLoc TL) {
5032 const AttributedType *oldType = TL.getTypePtr();
5033 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5034 if (modifiedType.isNull())
5035 return QualType();
5036
5037 QualType result = TL.getType();
5038
5039 // FIXME: dependent operand expressions?
5040 if (getDerived().AlwaysRebuild() ||
5041 modifiedType != oldType->getModifiedType()) {
5042 // TODO: this is really lame; we should really be rebuilding the
5043 // equivalent type from first principles.
5044 QualType equivalentType
5045 = getDerived().TransformType(oldType->getEquivalentType());
5046 if (equivalentType.isNull())
5047 return QualType();
5048 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5049 modifiedType,
5050 equivalentType);
5051 }
5052
5053 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5054 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5055 if (TL.hasAttrOperand())
5056 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5057 if (TL.hasAttrExprOperand())
5058 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5059 else if (TL.hasAttrEnumOperand())
5060 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5061
5062 return result;
5063}
5064
5065template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00005066QualType
5067TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5068 ParenTypeLoc TL) {
5069 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5070 if (Inner.isNull())
5071 return QualType();
5072
5073 QualType Result = TL.getType();
5074 if (getDerived().AlwaysRebuild() ||
5075 Inner != TL.getInnerLoc().getType()) {
5076 Result = getDerived().RebuildParenType(Inner);
5077 if (Result.isNull())
5078 return QualType();
5079 }
5080
5081 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5082 NewTL.setLParenLoc(TL.getLParenLoc());
5083 NewTL.setRParenLoc(TL.getRParenLoc());
5084 return Result;
5085}
5086
5087template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00005088QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005089 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00005090 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00005091
Douglas Gregor2494dd02011-03-01 01:34:45 +00005092 NestedNameSpecifierLoc QualifierLoc
5093 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5094 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00005095 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00005096
John McCall33500952010-06-11 00:33:02 +00005097 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00005098 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00005099 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00005100 QualifierLoc,
5101 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00005102 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00005103 if (Result.isNull())
5104 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005105
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005106 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5107 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00005108 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5109
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005110 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005111 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00005112 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00005113 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005114 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005115 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00005116 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005117 NewTL.setNameLoc(TL.getNameLoc());
5118 }
John McCalla2becad2009-10-21 00:40:46 +00005119 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00005120}
Mike Stump1eb44332009-09-09 15:08:12 +00005121
Douglas Gregor577f75a2009-08-04 16:50:30 +00005122template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00005123QualType TreeTransform<Derived>::
5124 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005125 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005126 NestedNameSpecifierLoc QualifierLoc;
5127 if (TL.getQualifierLoc()) {
5128 QualifierLoc
5129 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5130 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00005131 return QualType();
5132 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005133
John McCall43fed0d2010-11-12 08:19:04 +00005134 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005135 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00005136}
5137
5138template<typename Derived>
5139QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005140TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5141 DependentTemplateSpecializationTypeLoc TL,
5142 NestedNameSpecifierLoc QualifierLoc) {
5143 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005144
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005145 TemplateArgumentListInfo NewTemplateArgs;
5146 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5147 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005148
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005149 typedef TemplateArgumentLocContainerIterator<
5150 DependentTemplateSpecializationTypeLoc> ArgIterator;
5151 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5152 ArgIterator(TL, TL.getNumArgs()),
5153 NewTemplateArgs))
5154 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005155
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005156 QualType Result
5157 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5158 QualifierLoc,
5159 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005160 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005161 NewTemplateArgs);
5162 if (Result.isNull())
5163 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005164
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005165 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5166 QualType NamedT = ElabT->getNamedType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005167
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005168 // Copy information relevant to the template specialization.
5169 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005170 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005171 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005172 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005173 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5174 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005175 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005176 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005177
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005178 // Copy information relevant to the elaborated type.
5179 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005180 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005181 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005182 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5183 DependentTemplateSpecializationTypeLoc SpecTL
5184 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005185 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005186 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005187 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005188 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005189 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5190 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005191 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005192 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005193 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005194 TemplateSpecializationTypeLoc SpecTL
5195 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005196 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005197 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005198 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5199 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005200 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005201 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005202 }
5203 return Result;
5204}
5205
5206template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00005207QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5208 PackExpansionTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005209 QualType Pattern
5210 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005211 if (Pattern.isNull())
5212 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005213
5214 QualType Result = TL.getType();
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005215 if (getDerived().AlwaysRebuild() ||
5216 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005217 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005218 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00005219 TL.getEllipsisLoc(),
5220 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005221 if (Result.isNull())
5222 return QualType();
5223 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005224
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005225 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5226 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5227 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00005228}
5229
5230template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005231QualType
5232TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005233 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005234 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005235 TLB.pushFullCopy(TL);
5236 return TL.getType();
5237}
5238
5239template<typename Derived>
5240QualType
5241TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005242 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005243 // ObjCObjectType is never dependent.
5244 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005245 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005246}
Mike Stump1eb44332009-09-09 15:08:12 +00005247
5248template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005249QualType
5250TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005251 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005252 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005253 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005254 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005255}
5256
Douglas Gregor577f75a2009-08-04 16:50:30 +00005257//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005258// Statement transformation
5259//===----------------------------------------------------------------------===//
5260template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005261StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005262TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005263 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005264}
5265
5266template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005267StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005268TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5269 return getDerived().TransformCompoundStmt(S, false);
5270}
5271
5272template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005273StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005274TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005275 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005276 Sema::CompoundScopeRAII CompoundScope(getSema());
5277
John McCall7114cba2010-08-27 19:56:05 +00005278 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005279 bool SubStmtChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005280 SmallVector<Stmt*, 8> Statements;
Douglas Gregor43959a92009-08-20 07:17:43 +00005281 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5282 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005283 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005284 if (Result.isInvalid()) {
5285 // Immediately fail if this was a DeclStmt, since it's very
5286 // likely that this will cause problems for future statements.
5287 if (isa<DeclStmt>(*B))
5288 return StmtError();
5289
5290 // Otherwise, just keep processing substatements and fail later.
5291 SubStmtInvalid = true;
5292 continue;
5293 }
Mike Stump1eb44332009-09-09 15:08:12 +00005294
Douglas Gregor43959a92009-08-20 07:17:43 +00005295 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5296 Statements.push_back(Result.takeAs<Stmt>());
5297 }
Mike Stump1eb44332009-09-09 15:08:12 +00005298
John McCall7114cba2010-08-27 19:56:05 +00005299 if (SubStmtInvalid)
5300 return StmtError();
5301
Douglas Gregor43959a92009-08-20 07:17:43 +00005302 if (!getDerived().AlwaysRebuild() &&
5303 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005304 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005305
5306 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005307 Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00005308 S->getRBracLoc(),
5309 IsStmtExpr);
5310}
Mike Stump1eb44332009-09-09 15:08:12 +00005311
Douglas Gregor43959a92009-08-20 07:17:43 +00005312template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005313StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005314TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005315 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005316 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005317 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5318 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005319
Eli Friedman264c1f82009-11-19 03:14:00 +00005320 // Transform the left-hand case value.
5321 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005322 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005323 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005324 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005325
Eli Friedman264c1f82009-11-19 03:14:00 +00005326 // Transform the right-hand case value (for the GNU case-range extension).
5327 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005328 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005329 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005330 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005331 }
Mike Stump1eb44332009-09-09 15:08:12 +00005332
Douglas Gregor43959a92009-08-20 07:17:43 +00005333 // Build the case statement.
5334 // Case statements are always rebuilt so that they will attached to their
5335 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005336 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005337 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005338 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005339 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005340 S->getColonLoc());
5341 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005342 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005343
Douglas Gregor43959a92009-08-20 07:17:43 +00005344 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005345 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005346 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005347 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005348
Douglas Gregor43959a92009-08-20 07:17:43 +00005349 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005350 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005351}
5352
5353template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005354StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005355TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005356 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005357 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005358 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005359 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005360
Douglas Gregor43959a92009-08-20 07:17:43 +00005361 // Default statements are always rebuilt
5362 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005363 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005364}
Mike Stump1eb44332009-09-09 15:08:12 +00005365
Douglas Gregor43959a92009-08-20 07:17:43 +00005366template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005367StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005368TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005369 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005370 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005371 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005372
Chris Lattner57ad3782011-02-17 20:34:02 +00005373 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5374 S->getDecl());
5375 if (!LD)
5376 return StmtError();
Richard Smith534986f2012-04-14 00:33:13 +00005377
5378
Douglas Gregor43959a92009-08-20 07:17:43 +00005379 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005380 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005381 cast<LabelDecl>(LD), SourceLocation(),
5382 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
Richard Smith534986f2012-04-14 00:33:13 +00005387TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5388 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5389 if (SubStmt.isInvalid())
5390 return StmtError();
5391
5392 // TODO: transform attributes
5393 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5394 return S;
5395
5396 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5397 S->getAttrs(),
5398 SubStmt.get());
5399}
5400
5401template<typename Derived>
5402StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005403TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005404 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005405 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005406 VarDecl *ConditionVar = 0;
5407 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005408 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005409 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005410 getDerived().TransformDefinition(
5411 S->getConditionVariable()->getLocation(),
5412 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005413 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005414 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005415 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005416 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005417
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005418 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005419 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005420
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005421 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005422 if (S->getCond()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005423 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005424 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005425 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005426 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005427
John McCall9ae2f072010-08-23 23:25:46 +00005428 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005429 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005430 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005431
John McCall9ae2f072010-08-23 23:25:46 +00005432 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5433 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005434 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005435
Douglas Gregor43959a92009-08-20 07:17:43 +00005436 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005437 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005438 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005439 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005440
Douglas Gregor43959a92009-08-20 07:17:43 +00005441 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005442 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005443 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005444 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005445
Douglas Gregor43959a92009-08-20 07:17:43 +00005446 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005447 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005448 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005449 Then.get() == S->getThen() &&
5450 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005451 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005452
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005453 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005454 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005455 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005456}
5457
5458template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005459StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005460TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005461 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005462 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005463 VarDecl *ConditionVar = 0;
5464 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005465 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005466 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005467 getDerived().TransformDefinition(
5468 S->getConditionVariable()->getLocation(),
5469 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005470 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005471 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005472 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005473 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005474
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005475 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005476 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005477 }
Mike Stump1eb44332009-09-09 15:08:12 +00005478
Douglas Gregor43959a92009-08-20 07:17:43 +00005479 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005480 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005481 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005482 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005483 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005484 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005485
Douglas Gregor43959a92009-08-20 07:17:43 +00005486 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005487 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005488 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005489 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005490
Douglas Gregor43959a92009-08-20 07:17:43 +00005491 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005492 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5493 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005494}
Mike Stump1eb44332009-09-09 15:08:12 +00005495
Douglas Gregor43959a92009-08-20 07:17:43 +00005496template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005497StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005498TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005499 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005500 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005501 VarDecl *ConditionVar = 0;
5502 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005503 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005504 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005505 getDerived().TransformDefinition(
5506 S->getConditionVariable()->getLocation(),
5507 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005508 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005509 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005510 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005511 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005512
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005513 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005514 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005515
5516 if (S->getCond()) {
5517 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005518 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005519 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005520 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005521 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005522 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005523 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005524 }
Mike Stump1eb44332009-09-09 15:08:12 +00005525
John McCall9ae2f072010-08-23 23:25:46 +00005526 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5527 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005528 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005529
Douglas Gregor43959a92009-08-20 07:17:43 +00005530 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005531 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005532 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005533 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005534
Douglas Gregor43959a92009-08-20 07:17:43 +00005535 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005536 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005537 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005538 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005539 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005540
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005541 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005542 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005543}
Mike Stump1eb44332009-09-09 15:08:12 +00005544
Douglas Gregor43959a92009-08-20 07:17:43 +00005545template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005546StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005547TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005548 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005549 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005550 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005551 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005552
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005553 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005554 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005555 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005556 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005557
Douglas Gregor43959a92009-08-20 07:17:43 +00005558 if (!getDerived().AlwaysRebuild() &&
5559 Cond.get() == S->getCond() &&
5560 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005561 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005562
John McCall9ae2f072010-08-23 23:25:46 +00005563 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5564 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005565 S->getRParenLoc());
5566}
Mike Stump1eb44332009-09-09 15:08:12 +00005567
Douglas Gregor43959a92009-08-20 07:17:43 +00005568template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005569StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005570TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005571 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005572 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005573 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005574 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005575
Douglas Gregor43959a92009-08-20 07:17:43 +00005576 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005577 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005578 VarDecl *ConditionVar = 0;
5579 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005580 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005581 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005582 getDerived().TransformDefinition(
5583 S->getConditionVariable()->getLocation(),
5584 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005585 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005586 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005587 } else {
5588 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005589
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005590 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005591 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005592
5593 if (S->getCond()) {
5594 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005595 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005596 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005597 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005598 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005599
John McCall9ae2f072010-08-23 23:25:46 +00005600 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005601 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005602 }
Mike Stump1eb44332009-09-09 15:08:12 +00005603
Chad Rosier4a9d7952012-08-08 18:46:20 +00005604 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCall9ae2f072010-08-23 23:25:46 +00005605 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005606 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005607
Douglas Gregor43959a92009-08-20 07:17:43 +00005608 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005609 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005610 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005611 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005612
Richard Smith41956372013-01-14 22:39:08 +00005613 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCall9ae2f072010-08-23 23:25:46 +00005614 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005615 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005616
Douglas Gregor43959a92009-08-20 07:17:43 +00005617 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005618 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005619 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005620 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005621
Douglas Gregor43959a92009-08-20 07:17:43 +00005622 if (!getDerived().AlwaysRebuild() &&
5623 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005624 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005625 Inc.get() == S->getInc() &&
5626 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005627 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005628
Douglas Gregor43959a92009-08-20 07:17:43 +00005629 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005630 Init.get(), FullCond, ConditionVar,
5631 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005632}
5633
5634template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005635StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005636TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005637 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5638 S->getLabel());
5639 if (!LD)
5640 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005641
Douglas Gregor43959a92009-08-20 07:17:43 +00005642 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005643 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005644 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005645}
5646
5647template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005648StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005649TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005650 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005651 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005652 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005653 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005654
Douglas Gregor43959a92009-08-20 07:17:43 +00005655 if (!getDerived().AlwaysRebuild() &&
5656 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005657 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005658
5659 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005660 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005661}
5662
5663template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005664StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005665TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005666 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005667}
Mike Stump1eb44332009-09-09 15:08:12 +00005668
Douglas Gregor43959a92009-08-20 07:17:43 +00005669template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005670StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005671TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005672 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005673}
Mike Stump1eb44332009-09-09 15:08:12 +00005674
Douglas Gregor43959a92009-08-20 07:17:43 +00005675template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005676StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005677TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005678 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005679 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005680 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005681
Mike Stump1eb44332009-09-09 15:08:12 +00005682 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005683 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005684 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005685}
Mike Stump1eb44332009-09-09 15:08:12 +00005686
Douglas Gregor43959a92009-08-20 07:17:43 +00005687template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005688StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005689TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005690 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005691 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005692 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5693 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005694 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5695 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005696 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005697 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005698
Douglas Gregor43959a92009-08-20 07:17:43 +00005699 if (Transformed != *D)
5700 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005701
Douglas Gregor43959a92009-08-20 07:17:43 +00005702 Decls.push_back(Transformed);
5703 }
Mike Stump1eb44332009-09-09 15:08:12 +00005704
Douglas Gregor43959a92009-08-20 07:17:43 +00005705 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005706 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005707
Rafael Espindola4549d7f2013-07-09 12:05:01 +00005708 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005709}
Mike Stump1eb44332009-09-09 15:08:12 +00005710
Douglas Gregor43959a92009-08-20 07:17:43 +00005711template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005712StmtResult
Chad Rosierdf5faf52012-08-25 00:11:56 +00005713TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005714
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005715 SmallVector<Expr*, 8> Constraints;
5716 SmallVector<Expr*, 8> Exprs;
Chris Lattner686775d2011-07-20 06:58:45 +00005717 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005718
John McCall60d7b3a2010-08-24 06:29:42 +00005719 ExprResult AsmString;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005720 SmallVector<Expr*, 8> Clobbers;
Anders Carlsson703e3942010-01-24 05:50:09 +00005721
5722 bool ExprsChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005723
Anders Carlsson703e3942010-01-24 05:50:09 +00005724 // Go through the outputs.
5725 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005726 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005727
Anders Carlsson703e3942010-01-24 05:50:09 +00005728 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005729 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005730
Anders Carlsson703e3942010-01-24 05:50:09 +00005731 // Transform the output expr.
5732 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005733 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005734 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005735 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005736
Anders Carlsson703e3942010-01-24 05:50:09 +00005737 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005738
John McCall9ae2f072010-08-23 23:25:46 +00005739 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005740 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005741
Anders Carlsson703e3942010-01-24 05:50:09 +00005742 // Go through the inputs.
5743 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005744 Names.push_back(S->getInputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005745
Anders Carlsson703e3942010-01-24 05:50:09 +00005746 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005747 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005748
Anders Carlsson703e3942010-01-24 05:50:09 +00005749 // Transform the input expr.
5750 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005751 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005752 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005753 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005754
Anders Carlsson703e3942010-01-24 05:50:09 +00005755 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005756
John McCall9ae2f072010-08-23 23:25:46 +00005757 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005758 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005759
Anders Carlsson703e3942010-01-24 05:50:09 +00005760 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005761 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005762
5763 // Go through the clobbers.
5764 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosier5c7f5942012-08-27 23:28:41 +00005765 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005766
5767 // No need to transform the asm string literal.
5768 AsmString = SemaRef.Owned(S->getAsmString());
Chad Rosierdf5faf52012-08-25 00:11:56 +00005769 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5770 S->isVolatile(), S->getNumOutputs(),
5771 S->getNumInputs(), Names.data(),
5772 Constraints, Exprs, AsmString.get(),
5773 Clobbers, S->getRParenLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005774}
5775
Chad Rosier8cd64b42012-06-11 20:47:18 +00005776template<typename Derived>
5777StmtResult
5778TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier79efe242012-08-07 00:29:06 +00005779 ArrayRef<Token> AsmToks =
5780 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier62f22b82012-08-08 19:48:07 +00005781
John McCallaeeacf72013-05-03 00:10:13 +00005782 bool HadError = false, HadChange = false;
5783
5784 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5785 SmallVector<Expr*, 8> TransformedExprs;
5786 TransformedExprs.reserve(SrcExprs.size());
5787 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5788 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5789 if (!Result.isUsable()) {
5790 HadError = true;
5791 } else {
5792 HadChange |= (Result.get() != SrcExprs[i]);
5793 TransformedExprs.push_back(Result.take());
5794 }
5795 }
5796
5797 if (HadError) return StmtError();
5798 if (!HadChange && !getDerived().AlwaysRebuild())
5799 return Owned(S);
5800
Chad Rosier7bd092b2012-08-15 16:53:30 +00005801 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallaeeacf72013-05-03 00:10:13 +00005802 AsmToks, S->getAsmString(),
5803 S->getNumOutputs(), S->getNumInputs(),
5804 S->getAllConstraints(), S->getClobbers(),
5805 TransformedExprs, S->getEndLoc());
Chad Rosier8cd64b42012-06-11 20:47:18 +00005806}
Douglas Gregor43959a92009-08-20 07:17:43 +00005807
5808template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005809StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005810TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005811 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005812 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005813 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005814 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005815
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005816 // Transform the @catch statements (if present).
5817 bool AnyCatchChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005818 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005819 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005820 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005821 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005822 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005823 if (Catch.get() != S->getCatchStmt(I))
5824 AnyCatchChanged = true;
5825 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005826 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005827
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005828 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005829 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005830 if (S->getFinallyStmt()) {
5831 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5832 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005833 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005834 }
5835
5836 // If nothing changed, just retain this statement.
5837 if (!getDerived().AlwaysRebuild() &&
5838 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005839 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005840 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005841 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005842
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005843 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005844 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005845 CatchStmts, Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005846}
Mike Stump1eb44332009-09-09 15:08:12 +00005847
Douglas Gregor43959a92009-08-20 07:17:43 +00005848template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005849StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005850TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005851 // Transform the @catch parameter, if there is one.
5852 VarDecl *Var = 0;
5853 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5854 TypeSourceInfo *TSInfo = 0;
5855 if (FromVar->getTypeSourceInfo()) {
5856 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5857 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005858 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005859 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005860
Douglas Gregorbe270a02010-04-26 17:57:08 +00005861 QualType T;
5862 if (TSInfo)
5863 T = TSInfo->getType();
5864 else {
5865 T = getDerived().TransformType(FromVar->getType());
5866 if (T.isNull())
Chad Rosier4a9d7952012-08-08 18:46:20 +00005867 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005868 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005869
Douglas Gregorbe270a02010-04-26 17:57:08 +00005870 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5871 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005872 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005873 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005874
John McCall60d7b3a2010-08-24 06:29:42 +00005875 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005876 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005877 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005878
5879 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005880 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005881 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005882}
Mike Stump1eb44332009-09-09 15:08:12 +00005883
Douglas Gregor43959a92009-08-20 07:17:43 +00005884template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005885StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005886TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005887 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005888 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005889 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005890 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005891
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005892 // If nothing changed, just retain this statement.
5893 if (!getDerived().AlwaysRebuild() &&
5894 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005895 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005896
5897 // Build a new statement.
5898 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005899 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005900}
Mike Stump1eb44332009-09-09 15:08:12 +00005901
Douglas Gregor43959a92009-08-20 07:17:43 +00005902template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005903StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005904TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005905 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005906 if (S->getThrowExpr()) {
5907 Operand = getDerived().TransformExpr(S->getThrowExpr());
5908 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005909 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005910 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005911
Douglas Gregord1377b22010-04-22 21:44:01 +00005912 if (!getDerived().AlwaysRebuild() &&
5913 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005914 return getSema().Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005915
John McCall9ae2f072010-08-23 23:25:46 +00005916 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005917}
Mike Stump1eb44332009-09-09 15:08:12 +00005918
Douglas Gregor43959a92009-08-20 07:17:43 +00005919template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005920StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005921TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005922 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005923 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005924 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005925 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005926 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005927 Object =
5928 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5929 Object.get());
5930 if (Object.isInvalid())
5931 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005932
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005933 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005934 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005935 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005936 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005937
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005938 // If nothing change, just retain the current statement.
5939 if (!getDerived().AlwaysRebuild() &&
5940 Object.get() == S->getSynchExpr() &&
5941 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005942 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005943
5944 // Build a new statement.
5945 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005946 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005947}
5948
5949template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005950StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005951TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5952 ObjCAutoreleasePoolStmt *S) {
5953 // Transform the body.
5954 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5955 if (Body.isInvalid())
5956 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005957
John McCallf85e1932011-06-15 23:02:42 +00005958 // If nothing changed, just retain this statement.
5959 if (!getDerived().AlwaysRebuild() &&
5960 Body.get() == S->getSubStmt())
5961 return SemaRef.Owned(S);
5962
5963 // Build a new statement.
5964 return getDerived().RebuildObjCAutoreleasePoolStmt(
5965 S->getAtLoc(), Body.get());
5966}
5967
5968template<typename Derived>
5969StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005970TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005971 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005972 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005973 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005974 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005975 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005976
Douglas Gregorc3203e72010-04-22 23:10:45 +00005977 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005978 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005979 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005980 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005981
Douglas Gregorc3203e72010-04-22 23:10:45 +00005982 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005983 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005984 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005985 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005986
Douglas Gregorc3203e72010-04-22 23:10:45 +00005987 // If nothing changed, just retain this statement.
5988 if (!getDerived().AlwaysRebuild() &&
5989 Element.get() == S->getElement() &&
5990 Collection.get() == S->getCollection() &&
5991 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005992 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005993
Douglas Gregorc3203e72010-04-22 23:10:45 +00005994 // Build a new statement.
5995 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005996 Element.get(),
5997 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005998 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005999 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00006000}
6001
David Majnemer2c4a01d2013-10-15 09:50:08 +00006002template <typename Derived>
6003StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00006004 // Transform the exception declaration, if any.
6005 VarDecl *Var = 0;
David Majnemer2c4a01d2013-10-15 09:50:08 +00006006 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6007 TypeSourceInfo *T =
6008 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor83cb9422010-09-09 17:09:21 +00006009 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006010 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00006011
David Majnemer2c4a01d2013-10-15 09:50:08 +00006012 Var = getDerived().RebuildExceptionDecl(
6013 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6014 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00006015 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00006016 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00006017 }
Mike Stump1eb44332009-09-09 15:08:12 +00006018
Douglas Gregor43959a92009-08-20 07:17:43 +00006019 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00006020 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00006021 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006022 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00006023
David Majnemer2c4a01d2013-10-15 09:50:08 +00006024 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregor43959a92009-08-20 07:17:43 +00006025 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00006026 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00006027
David Majnemer2c4a01d2013-10-15 09:50:08 +00006028 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00006029}
Mike Stump1eb44332009-09-09 15:08:12 +00006030
David Majnemer2c4a01d2013-10-15 09:50:08 +00006031template <typename Derived>
6032StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00006033 // Transform the try block itself.
David Majnemer2c4a01d2013-10-15 09:50:08 +00006034 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregor43959a92009-08-20 07:17:43 +00006035 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006036 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00006037
Douglas Gregor43959a92009-08-20 07:17:43 +00006038 // Transform the handlers.
6039 bool HandlerChanged = false;
David Majnemer2c4a01d2013-10-15 09:50:08 +00006040 SmallVector<Stmt *, 8> Handlers;
Douglas Gregor43959a92009-08-20 07:17:43 +00006041 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer2c4a01d2013-10-15 09:50:08 +00006042 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregor43959a92009-08-20 07:17:43 +00006043 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006044 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00006045
Douglas Gregor43959a92009-08-20 07:17:43 +00006046 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
6047 Handlers.push_back(Handler.takeAs<Stmt>());
6048 }
Mike Stump1eb44332009-09-09 15:08:12 +00006049
David Majnemer2c4a01d2013-10-15 09:50:08 +00006050 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00006051 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006052 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00006053
John McCall9ae2f072010-08-23 23:25:46 +00006054 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006055 Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00006056}
Mike Stump1eb44332009-09-09 15:08:12 +00006057
Richard Smithad762fc2011-04-14 22:09:26 +00006058template<typename Derived>
6059StmtResult
6060TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6061 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6062 if (Range.isInvalid())
6063 return StmtError();
6064
6065 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6066 if (BeginEnd.isInvalid())
6067 return StmtError();
6068
6069 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6070 if (Cond.isInvalid())
6071 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00006072 if (Cond.get())
6073 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
6074 if (Cond.isInvalid())
6075 return StmtError();
6076 if (Cond.get())
6077 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00006078
6079 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6080 if (Inc.isInvalid())
6081 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00006082 if (Inc.get())
6083 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00006084
6085 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6086 if (LoopVar.isInvalid())
6087 return StmtError();
6088
6089 StmtResult NewStmt = S;
6090 if (getDerived().AlwaysRebuild() ||
6091 Range.get() != S->getRangeStmt() ||
6092 BeginEnd.get() != S->getBeginEndStmt() ||
6093 Cond.get() != S->getCond() ||
6094 Inc.get() != S->getInc() ||
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006095 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smithad762fc2011-04-14 22:09:26 +00006096 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6097 S->getColonLoc(), Range.get(),
6098 BeginEnd.get(), Cond.get(),
6099 Inc.get(), LoopVar.get(),
6100 S->getRParenLoc());
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006101 if (NewStmt.isInvalid())
6102 return StmtError();
6103 }
Richard Smithad762fc2011-04-14 22:09:26 +00006104
6105 StmtResult Body = getDerived().TransformStmt(S->getBody());
6106 if (Body.isInvalid())
6107 return StmtError();
6108
6109 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6110 // it now so we have a new statement to attach the body to.
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006111 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smithad762fc2011-04-14 22:09:26 +00006112 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6113 S->getColonLoc(), Range.get(),
6114 BeginEnd.get(), Cond.get(),
6115 Inc.get(), LoopVar.get(),
6116 S->getRParenLoc());
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006117 if (NewStmt.isInvalid())
6118 return StmtError();
6119 }
Richard Smithad762fc2011-04-14 22:09:26 +00006120
6121 if (NewStmt.get() == S)
6122 return SemaRef.Owned(S);
6123
6124 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6125}
6126
John Wiegley28bbe4b2011-04-28 01:08:34 +00006127template<typename Derived>
6128StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00006129TreeTransform<Derived>::TransformMSDependentExistsStmt(
6130 MSDependentExistsStmt *S) {
6131 // Transform the nested-name-specifier, if any.
6132 NestedNameSpecifierLoc QualifierLoc;
6133 if (S->getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006134 QualifierLoc
Douglas Gregorba0513d2011-10-25 01:33:02 +00006135 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6136 if (!QualifierLoc)
6137 return StmtError();
6138 }
6139
6140 // Transform the declaration name.
6141 DeclarationNameInfo NameInfo = S->getNameInfo();
6142 if (NameInfo.getName()) {
6143 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6144 if (!NameInfo.getName())
6145 return StmtError();
6146 }
6147
6148 // Check whether anything changed.
6149 if (!getDerived().AlwaysRebuild() &&
6150 QualifierLoc == S->getQualifierLoc() &&
6151 NameInfo.getName() == S->getNameInfo().getName())
6152 return S;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006153
Douglas Gregorba0513d2011-10-25 01:33:02 +00006154 // Determine whether this name exists, if we can.
6155 CXXScopeSpec SS;
6156 SS.Adopt(QualifierLoc);
6157 bool Dependent = false;
6158 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
6159 case Sema::IER_Exists:
6160 if (S->isIfExists())
6161 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006162
Douglas Gregorba0513d2011-10-25 01:33:02 +00006163 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6164
6165 case Sema::IER_DoesNotExist:
6166 if (S->isIfNotExists())
6167 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006168
Douglas Gregorba0513d2011-10-25 01:33:02 +00006169 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006170
Douglas Gregorba0513d2011-10-25 01:33:02 +00006171 case Sema::IER_Dependent:
6172 Dependent = true;
6173 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006174
Douglas Gregor65019ac2011-10-25 03:44:56 +00006175 case Sema::IER_Error:
6176 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00006177 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006178
Douglas Gregorba0513d2011-10-25 01:33:02 +00006179 // We need to continue with the instantiation, so do so now.
6180 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6181 if (SubStmt.isInvalid())
6182 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006183
Douglas Gregorba0513d2011-10-25 01:33:02 +00006184 // If we have resolved the name, just transform to the substatement.
6185 if (!Dependent)
6186 return SubStmt;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006187
Douglas Gregorba0513d2011-10-25 01:33:02 +00006188 // The name is still dependent, so build a dependent expression again.
6189 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6190 S->isIfExists(),
6191 QualifierLoc,
6192 NameInfo,
6193 SubStmt.get());
6194}
6195
6196template<typename Derived>
John McCall76da55d2013-04-16 07:28:30 +00006197ExprResult
6198TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6199 NestedNameSpecifierLoc QualifierLoc;
6200 if (E->getQualifierLoc()) {
6201 QualifierLoc
6202 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6203 if (!QualifierLoc)
6204 return ExprError();
6205 }
6206
6207 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6208 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6209 if (!PD)
6210 return ExprError();
6211
6212 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6213 if (Base.isInvalid())
6214 return ExprError();
6215
6216 return new (SemaRef.getASTContext())
6217 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6218 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6219 QualifierLoc, E->getMemberLoc());
6220}
6221
David Majnemerfc210492013-10-15 09:33:02 +00006222template <typename Derived>
6223StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7752a742013-10-15 09:30:14 +00006224 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfc210492013-10-15 09:33:02 +00006225 if (TryBlock.isInvalid())
6226 return StmtError();
John Wiegley28bbe4b2011-04-28 01:08:34 +00006227
6228 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7752a742013-10-15 09:30:14 +00006229 if (Handler.isInvalid())
6230 return StmtError();
6231
David Majnemerfc210492013-10-15 09:33:02 +00006232 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6233 Handler.get() == S->getHandler())
John Wiegley28bbe4b2011-04-28 01:08:34 +00006234 return SemaRef.Owned(S);
6235
David Majnemerfc210492013-10-15 09:33:02 +00006236 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
6237 TryBlock.take(), Handler.take());
John Wiegley28bbe4b2011-04-28 01:08:34 +00006238}
6239
David Majnemerfc210492013-10-15 09:33:02 +00006240template <typename Derived>
6241StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7752a742013-10-15 09:30:14 +00006242 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfc210492013-10-15 09:33:02 +00006243 if (Block.isInvalid())
6244 return StmtError();
John Wiegley28bbe4b2011-04-28 01:08:34 +00006245
David Majnemerfc210492013-10-15 09:33:02 +00006246 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.take());
John Wiegley28bbe4b2011-04-28 01:08:34 +00006247}
6248
David Majnemerfc210492013-10-15 09:33:02 +00006249template <typename Derived>
6250StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley28bbe4b2011-04-28 01:08:34 +00006251 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfc210492013-10-15 09:33:02 +00006252 if (FilterExpr.isInvalid())
6253 return StmtError();
John Wiegley28bbe4b2011-04-28 01:08:34 +00006254
David Majnemer7752a742013-10-15 09:30:14 +00006255 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfc210492013-10-15 09:33:02 +00006256 if (Block.isInvalid())
6257 return StmtError();
John Wiegley28bbe4b2011-04-28 01:08:34 +00006258
David Majnemerfc210492013-10-15 09:33:02 +00006259 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.take(),
John Wiegley28bbe4b2011-04-28 01:08:34 +00006260 Block.take());
6261}
6262
David Majnemerfc210492013-10-15 09:33:02 +00006263template <typename Derived>
6264StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6265 if (isa<SEHFinallyStmt>(Handler))
John Wiegley28bbe4b2011-04-28 01:08:34 +00006266 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6267 else
6268 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6269}
6270
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006271template<typename Derived>
6272StmtResult
6273TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
Alexey Bataev0c018352013-09-06 18:03:48 +00006274 DeclarationNameInfo DirName;
6275 getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, 0);
6276
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006277 // Transform the clauses
Alexey Bataev0c018352013-09-06 18:03:48 +00006278 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006279 ArrayRef<OMPClause *> Clauses = D->clauses();
6280 TClauses.reserve(Clauses.size());
6281 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6282 I != E; ++I) {
6283 if (*I) {
6284 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataev0c018352013-09-06 18:03:48 +00006285 if (!Clause) {
6286 getSema().EndOpenMPDSABlock(0);
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006287 return StmtError();
Alexey Bataev0c018352013-09-06 18:03:48 +00006288 }
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006289 TClauses.push_back(Clause);
6290 }
6291 else {
6292 TClauses.push_back(0);
6293 }
6294 }
Alexey Bataev0c018352013-09-06 18:03:48 +00006295 if (!D->getAssociatedStmt()) {
6296 getSema().EndOpenMPDSABlock(0);
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006297 return StmtError();
Alexey Bataev0c018352013-09-06 18:03:48 +00006298 }
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006299 StmtResult AssociatedStmt =
6300 getDerived().TransformStmt(D->getAssociatedStmt());
Alexey Bataev0c018352013-09-06 18:03:48 +00006301 if (AssociatedStmt.isInvalid()) {
6302 getSema().EndOpenMPDSABlock(0);
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006303 return StmtError();
Alexey Bataev0c018352013-09-06 18:03:48 +00006304 }
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006305
Alexey Bataev0c018352013-09-06 18:03:48 +00006306 StmtResult Res = getDerived().RebuildOMPParallelDirective(TClauses,
6307 AssociatedStmt.take(),
6308 D->getLocStart(),
6309 D->getLocEnd());
6310 getSema().EndOpenMPDSABlock(Res.get());
6311 return Res;
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006312}
6313
6314template<typename Derived>
6315OMPClause *
6316TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
6317 return getDerived().RebuildOMPDefaultClause(C->getDefaultKind(),
6318 C->getDefaultKindKwLoc(),
6319 C->getLocStart(),
6320 C->getLParenLoc(),
6321 C->getLocEnd());
6322}
6323
6324template<typename Derived>
6325OMPClause *
6326TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev0c018352013-09-06 18:03:48 +00006327 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006328 Vars.reserve(C->varlist_size());
Alexey Bataev543c4ae2013-09-24 03:17:45 +00006329 for (OMPPrivateClause::varlist_iterator I = C->varlist_begin(),
6330 E = C->varlist_end();
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006331 I != E; ++I) {
6332 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6333 if (EVar.isInvalid())
6334 return 0;
6335 Vars.push_back(EVar.take());
6336 }
6337 return getDerived().RebuildOMPPrivateClause(Vars,
6338 C->getLocStart(),
6339 C->getLParenLoc(),
6340 C->getLocEnd());
6341}
6342
Alexey Bataev0c018352013-09-06 18:03:48 +00006343template<typename Derived>
6344OMPClause *
Alexey Bataevd195bc32013-10-01 05:32:34 +00006345TreeTransform<Derived>::TransformOMPFirstprivateClause(
6346 OMPFirstprivateClause *C) {
6347 llvm::SmallVector<Expr *, 16> Vars;
6348 Vars.reserve(C->varlist_size());
6349 for (OMPFirstprivateClause::varlist_iterator I = C->varlist_begin(),
6350 E = C->varlist_end();
6351 I != E; ++I) {
6352 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6353 if (EVar.isInvalid())
6354 return 0;
6355 Vars.push_back(EVar.take());
6356 }
6357 return getDerived().RebuildOMPFirstprivateClause(Vars,
6358 C->getLocStart(),
6359 C->getLParenLoc(),
6360 C->getLocEnd());
6361}
6362
6363template<typename Derived>
6364OMPClause *
Alexey Bataev0c018352013-09-06 18:03:48 +00006365TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
6366 llvm::SmallVector<Expr *, 16> Vars;
6367 Vars.reserve(C->varlist_size());
Alexey Bataev543c4ae2013-09-24 03:17:45 +00006368 for (OMPSharedClause::varlist_iterator I = C->varlist_begin(),
6369 E = C->varlist_end();
Alexey Bataev0c018352013-09-06 18:03:48 +00006370 I != E; ++I) {
6371 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6372 if (EVar.isInvalid())
6373 return 0;
6374 Vars.push_back(EVar.take());
6375 }
6376 return getDerived().RebuildOMPSharedClause(Vars,
6377 C->getLocStart(),
6378 C->getLParenLoc(),
6379 C->getLocEnd());
6380}
6381
Douglas Gregor43959a92009-08-20 07:17:43 +00006382//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00006383// Expression transformation
6384//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006385template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006386ExprResult
John McCall454feb92009-12-08 09:21:05 +00006387TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006388 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006389}
Mike Stump1eb44332009-09-09 15:08:12 +00006390
6391template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006392ExprResult
John McCall454feb92009-12-08 09:21:05 +00006393TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006394 NestedNameSpecifierLoc QualifierLoc;
6395 if (E->getQualifierLoc()) {
6396 QualifierLoc
6397 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6398 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006399 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006400 }
John McCalldbd872f2009-12-08 09:08:17 +00006401
6402 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006403 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6404 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006405 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006406 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006407
John McCallec8045d2010-08-17 21:27:17 +00006408 DeclarationNameInfo NameInfo = E->getNameInfo();
6409 if (NameInfo.getName()) {
6410 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6411 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006412 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006413 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006414
6415 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006416 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006417 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006418 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006419 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006420
6421 // Mark it referenced in the new context regardless.
6422 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006423 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006424
John McCall3fa5cae2010-10-26 07:05:15 +00006425 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006426 }
John McCalldbd872f2009-12-08 09:08:17 +00006427
6428 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006429 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006430 TemplateArgs = &TransArgs;
6431 TransArgs.setLAngleLoc(E->getLAngleLoc());
6432 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006433 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6434 E->getNumTemplateArgs(),
6435 TransArgs))
6436 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006437 }
6438
Chad Rosier4a9d7952012-08-08 18:46:20 +00006439 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregor40d96a62011-02-28 21:54:11 +00006440 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006441}
Mike Stump1eb44332009-09-09 15:08:12 +00006442
Douglas Gregorb98b1992009-08-11 05:31:07 +00006443template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006444ExprResult
John McCall454feb92009-12-08 09:21:05 +00006445TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006446 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006447}
Mike Stump1eb44332009-09-09 15:08:12 +00006448
Douglas Gregorb98b1992009-08-11 05:31:07 +00006449template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006450ExprResult
John McCall454feb92009-12-08 09:21:05 +00006451TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006452 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006453}
Mike Stump1eb44332009-09-09 15:08:12 +00006454
Douglas Gregorb98b1992009-08-11 05:31:07 +00006455template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006456ExprResult
John McCall454feb92009-12-08 09:21:05 +00006457TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006458 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006459}
Mike Stump1eb44332009-09-09 15:08:12 +00006460
Douglas Gregorb98b1992009-08-11 05:31:07 +00006461template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006462ExprResult
John McCall454feb92009-12-08 09:21:05 +00006463TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006464 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006465}
Mike Stump1eb44332009-09-09 15:08:12 +00006466
Douglas Gregorb98b1992009-08-11 05:31:07 +00006467template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006468ExprResult
John McCall454feb92009-12-08 09:21:05 +00006469TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006470 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006471}
6472
6473template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006474ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006475TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis391ca9f2013-04-09 01:17:02 +00006476 if (FunctionDecl *FD = E->getDirectCallee())
6477 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smith9fcce652012-03-07 08:35:16 +00006478 return SemaRef.MaybeBindToTemporary(E);
6479}
6480
6481template<typename Derived>
6482ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006483TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6484 ExprResult ControllingExpr =
6485 getDerived().TransformExpr(E->getControllingExpr());
6486 if (ControllingExpr.isInvalid())
6487 return ExprError();
6488
Chris Lattner686775d2011-07-20 06:58:45 +00006489 SmallVector<Expr *, 4> AssocExprs;
6490 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006491 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6492 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6493 if (TS) {
6494 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6495 if (!AssocType)
6496 return ExprError();
6497 AssocTypes.push_back(AssocType);
6498 } else {
6499 AssocTypes.push_back(0);
6500 }
6501
6502 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6503 if (AssocExpr.isInvalid())
6504 return ExprError();
6505 AssocExprs.push_back(AssocExpr.release());
6506 }
6507
6508 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6509 E->getDefaultLoc(),
6510 E->getRParenLoc(),
6511 ControllingExpr.release(),
Dmitri Gribenko80613222013-05-10 13:06:58 +00006512 AssocTypes,
6513 AssocExprs);
Peter Collingbournef111d932011-04-15 00:35:48 +00006514}
6515
6516template<typename Derived>
6517ExprResult
John McCall454feb92009-12-08 09:21:05 +00006518TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006519 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006520 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006521 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006522
Douglas Gregorb98b1992009-08-11 05:31:07 +00006523 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006524 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006525
John McCall9ae2f072010-08-23 23:25:46 +00006526 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006527 E->getRParen());
6528}
6529
Richard Smithefeeccf2012-10-21 03:28:35 +00006530/// \brief The operand of a unary address-of operator has special rules: it's
6531/// allowed to refer to a non-static member of a class even if there's no 'this'
6532/// object available.
6533template<typename Derived>
6534ExprResult
6535TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6536 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6537 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6538 else
6539 return getDerived().TransformExpr(E);
6540}
6541
Mike Stump1eb44332009-09-09 15:08:12 +00006542template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006543ExprResult
John McCall454feb92009-12-08 09:21:05 +00006544TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smith82b00012013-05-21 23:29:46 +00006545 ExprResult SubExpr;
6546 if (E->getOpcode() == UO_AddrOf)
6547 SubExpr = TransformAddressOfOperand(E->getSubExpr());
6548 else
6549 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006550 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006551 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006552
Douglas Gregorb98b1992009-08-11 05:31:07 +00006553 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006554 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006555
Douglas Gregorb98b1992009-08-11 05:31:07 +00006556 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6557 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006558 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006559}
Mike Stump1eb44332009-09-09 15:08:12 +00006560
Douglas Gregorb98b1992009-08-11 05:31:07 +00006561template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006562ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006563TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6564 // Transform the type.
6565 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6566 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006567 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006568
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006569 // Transform all of the components into components similar to what the
6570 // parser uses.
Chad Rosier4a9d7952012-08-08 18:46:20 +00006571 // FIXME: It would be slightly more efficient in the non-dependent case to
6572 // just map FieldDecls, rather than requiring the rebuilder to look for
6573 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006574 // template code that we don't care.
6575 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006576 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006577 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006578 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006579 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6580 const Node &ON = E->getComponent(I);
6581 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006582 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006583 Comp.LocStart = ON.getSourceRange().getBegin();
6584 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006585 switch (ON.getKind()) {
6586 case Node::Array: {
6587 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006588 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006589 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006590 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006591
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006592 ExprChanged = ExprChanged || Index.get() != FromIndex;
6593 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006594 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006595 break;
6596 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006597
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006598 case Node::Field:
6599 case Node::Identifier:
6600 Comp.isBrackets = false;
6601 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006602 if (!Comp.U.IdentInfo)
6603 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006604
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006605 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006606
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006607 case Node::Base:
6608 // Will be recomputed during the rebuild.
6609 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006610 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006611
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006612 Components.push_back(Comp);
6613 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006614
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006615 // If nothing changed, retain the existing expression.
6616 if (!getDerived().AlwaysRebuild() &&
6617 Type == E->getTypeSourceInfo() &&
6618 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006619 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006620
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006621 // Build a new offsetof expression.
6622 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6623 Components.data(), Components.size(),
6624 E->getRParenLoc());
6625}
6626
6627template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006628ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006629TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6630 assert(getDerived().AlreadyTransformed(E->getType()) &&
6631 "opaque value expression requires transformation");
6632 return SemaRef.Owned(E);
6633}
6634
6635template<typename Derived>
6636ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006637TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006638 // Rebuild the syntactic form. The original syntactic form has
6639 // opaque-value expressions in it, so strip those away and rebuild
6640 // the result. This is a really awful way of doing this, but the
6641 // better solution (rebuilding the semantic expressions and
6642 // rebinding OVEs as necessary) doesn't work; we'd need
6643 // TreeTransform to not strip away implicit conversions.
6644 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6645 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006646 if (result.isInvalid()) return ExprError();
6647
6648 // If that gives us a pseudo-object result back, the pseudo-object
6649 // expression must have been an lvalue-to-rvalue conversion which we
6650 // should reapply.
6651 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6652 result = SemaRef.checkPseudoObjectRValue(result.take());
6653
6654 return result;
6655}
6656
6657template<typename Derived>
6658ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006659TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6660 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006661 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006662 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006663
John McCalla93c9342009-12-07 02:54:59 +00006664 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006665 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006666 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006667
John McCall5ab75172009-11-04 07:28:41 +00006668 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006669 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006670
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006671 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6672 E->getKind(),
6673 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006674 }
Mike Stump1eb44332009-09-09 15:08:12 +00006675
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006676 // C++0x [expr.sizeof]p1:
6677 // The operand is either an expression, which is an unevaluated operand
6678 // [...]
Eli Friedman80bfa3d2012-09-26 04:34:21 +00006679 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6680 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00006681
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006682 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6683 if (SubExpr.isInvalid())
6684 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006685
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006686 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6687 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006688
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006689 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6690 E->getOperatorLoc(),
6691 E->getKind(),
6692 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006693}
Mike Stump1eb44332009-09-09 15:08:12 +00006694
Douglas Gregorb98b1992009-08-11 05:31:07 +00006695template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006696ExprResult
John McCall454feb92009-12-08 09:21:05 +00006697TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006698 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006699 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006700 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006701
John McCall60d7b3a2010-08-24 06:29:42 +00006702 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006703 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006704 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006705
6706
Douglas Gregorb98b1992009-08-11 05:31:07 +00006707 if (!getDerived().AlwaysRebuild() &&
6708 LHS.get() == E->getLHS() &&
6709 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006710 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006711
John McCall9ae2f072010-08-23 23:25:46 +00006712 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006713 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006714 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006715 E->getRBracketLoc());
6716}
Mike Stump1eb44332009-09-09 15:08:12 +00006717
6718template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006719ExprResult
John McCall454feb92009-12-08 09:21:05 +00006720TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006721 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006722 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006723 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006724 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006725
6726 // Transform arguments.
6727 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006728 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006729 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006730 &ArgChanged))
6731 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006732
Douglas Gregorb98b1992009-08-11 05:31:07 +00006733 if (!getDerived().AlwaysRebuild() &&
6734 Callee.get() == E->getCallee() &&
6735 !ArgChanged)
Dmitri Gribenko1ad23d62012-09-10 21:20:09 +00006736 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006737
Douglas Gregorb98b1992009-08-11 05:31:07 +00006738 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006739 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006740 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006741 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006742 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006743 E->getRParenLoc());
6744}
Mike Stump1eb44332009-09-09 15:08:12 +00006745
6746template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006747ExprResult
John McCall454feb92009-12-08 09:21:05 +00006748TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006749 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006750 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006751 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006752
Douglas Gregor40d96a62011-02-28 21:54:11 +00006753 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006754 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006755 QualifierLoc
6756 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006757
Douglas Gregor40d96a62011-02-28 21:54:11 +00006758 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006759 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006760 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006761 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006762
Eli Friedmanf595cc42009-12-04 06:40:45 +00006763 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006764 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6765 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006766 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006767 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006768
John McCall6bb80172010-03-30 21:47:33 +00006769 NamedDecl *FoundDecl = E->getFoundDecl();
6770 if (FoundDecl == E->getMemberDecl()) {
6771 FoundDecl = Member;
6772 } else {
6773 FoundDecl = cast_or_null<NamedDecl>(
6774 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6775 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006776 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006777 }
6778
Douglas Gregorb98b1992009-08-11 05:31:07 +00006779 if (!getDerived().AlwaysRebuild() &&
6780 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006781 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006782 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006783 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006784 !E->hasExplicitTemplateArgs()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006785
Anders Carlsson1f240322009-12-22 05:24:09 +00006786 // Mark it referenced in the new context regardless.
6787 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006788 SemaRef.MarkMemberReferenced(E);
6789
John McCall3fa5cae2010-10-26 07:05:15 +00006790 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006791 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006792
John McCalld5532b62009-11-23 01:53:49 +00006793 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006794 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006795 TransArgs.setLAngleLoc(E->getLAngleLoc());
6796 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006797 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6798 E->getNumTemplateArgs(),
6799 TransArgs))
6800 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006801 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006802
Douglas Gregorb98b1992009-08-11 05:31:07 +00006803 // FIXME: Bogus source location for the operator
6804 SourceLocation FakeOperatorLoc
6805 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6806
John McCallc2233c52010-01-15 08:34:02 +00006807 // FIXME: to do this check properly, we will need to preserve the
6808 // first-qualifier-in-scope here, just in case we had a dependent
6809 // base (and therefore couldn't do the check) and a
6810 // nested-name-qualifier (and therefore could do the lookup).
6811 NamedDecl *FirstQualifierInScope = 0;
6812
John McCall9ae2f072010-08-23 23:25:46 +00006813 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006814 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006815 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006816 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006817 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006818 Member,
John McCall6bb80172010-03-30 21:47:33 +00006819 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006820 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006821 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006822 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006823}
Mike Stump1eb44332009-09-09 15:08:12 +00006824
Douglas Gregorb98b1992009-08-11 05:31:07 +00006825template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006826ExprResult
John McCall454feb92009-12-08 09:21:05 +00006827TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006828 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006829 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006830 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006831
John McCall60d7b3a2010-08-24 06:29:42 +00006832 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006833 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006834 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006835
Douglas Gregorb98b1992009-08-11 05:31:07 +00006836 if (!getDerived().AlwaysRebuild() &&
6837 LHS.get() == E->getLHS() &&
6838 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006839 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006840
Lang Hamesbe9af122012-10-02 04:45:10 +00006841 Sema::FPContractStateRAII FPContractState(getSema());
6842 getSema().FPFeatures.fp_contract = E->isFPContractable();
6843
Douglas Gregorb98b1992009-08-11 05:31:07 +00006844 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006845 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006846}
6847
Mike Stump1eb44332009-09-09 15:08:12 +00006848template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006849ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006850TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006851 CompoundAssignOperator *E) {
6852 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006853}
Mike Stump1eb44332009-09-09 15:08:12 +00006854
Douglas Gregorb98b1992009-08-11 05:31:07 +00006855template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006856ExprResult TreeTransform<Derived>::
6857TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6858 // Just rebuild the common and RHS expressions and see whether we
6859 // get any changes.
6860
6861 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6862 if (commonExpr.isInvalid())
6863 return ExprError();
6864
6865 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6866 if (rhs.isInvalid())
6867 return ExprError();
6868
6869 if (!getDerived().AlwaysRebuild() &&
6870 commonExpr.get() == e->getCommon() &&
6871 rhs.get() == e->getFalseExpr())
6872 return SemaRef.Owned(e);
6873
6874 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6875 e->getQuestionLoc(),
6876 0,
6877 e->getColonLoc(),
6878 rhs.get());
6879}
6880
6881template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006882ExprResult
John McCall454feb92009-12-08 09:21:05 +00006883TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006884 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006885 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006886 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006887
John McCall60d7b3a2010-08-24 06:29:42 +00006888 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006889 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006890 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006891
John McCall60d7b3a2010-08-24 06:29:42 +00006892 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006893 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006894 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006895
Douglas Gregorb98b1992009-08-11 05:31:07 +00006896 if (!getDerived().AlwaysRebuild() &&
6897 Cond.get() == E->getCond() &&
6898 LHS.get() == E->getLHS() &&
6899 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006900 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006901
John McCall9ae2f072010-08-23 23:25:46 +00006902 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006903 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006904 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006905 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006906 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006907}
Mike Stump1eb44332009-09-09 15:08:12 +00006908
6909template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006910ExprResult
John McCall454feb92009-12-08 09:21:05 +00006911TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006912 // Implicit casts are eliminated during transformation, since they
6913 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006914 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006915}
Mike Stump1eb44332009-09-09 15:08:12 +00006916
Douglas Gregorb98b1992009-08-11 05:31:07 +00006917template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006918ExprResult
John McCall454feb92009-12-08 09:21:05 +00006919TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006920 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6921 if (!Type)
6922 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006923
John McCall60d7b3a2010-08-24 06:29:42 +00006924 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006925 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006926 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006927 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006928
Douglas Gregorb98b1992009-08-11 05:31:07 +00006929 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006930 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006931 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006932 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006933
John McCall9d125032010-01-15 18:39:57 +00006934 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006935 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006936 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006937 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006938}
Mike Stump1eb44332009-09-09 15:08:12 +00006939
Douglas Gregorb98b1992009-08-11 05:31:07 +00006940template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006941ExprResult
John McCall454feb92009-12-08 09:21:05 +00006942TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006943 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6944 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6945 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006946 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006947
John McCall60d7b3a2010-08-24 06:29:42 +00006948 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006949 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006950 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006951
Douglas Gregorb98b1992009-08-11 05:31:07 +00006952 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006953 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006954 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006955 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006956
John McCall1d7d8d62010-01-19 22:33:45 +00006957 // Note: the expression type doesn't necessarily match the
6958 // type-as-written, but that's okay, because it should always be
6959 // derivable from the initializer.
6960
John McCall42f56b52010-01-18 19:35:47 +00006961 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006962 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006963 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006964}
Mike Stump1eb44332009-09-09 15:08:12 +00006965
Douglas Gregorb98b1992009-08-11 05:31:07 +00006966template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006967ExprResult
John McCall454feb92009-12-08 09:21:05 +00006968TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006969 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006970 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006971 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006972
Douglas Gregorb98b1992009-08-11 05:31:07 +00006973 if (!getDerived().AlwaysRebuild() &&
6974 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006975 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006976
Douglas Gregorb98b1992009-08-11 05:31:07 +00006977 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006978 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006979 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006980 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006981 E->getAccessorLoc(),
6982 E->getAccessor());
6983}
Mike Stump1eb44332009-09-09 15:08:12 +00006984
Douglas Gregorb98b1992009-08-11 05:31:07 +00006985template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006986ExprResult
John McCall454feb92009-12-08 09:21:05 +00006987TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006988 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006989
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006990 SmallVector<Expr*, 4> Inits;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006991 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006992 Inits, &InitChanged))
6993 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006994
Douglas Gregorb98b1992009-08-11 05:31:07 +00006995 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006996 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006997
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006998 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00006999 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007000}
Mike Stump1eb44332009-09-09 15:08:12 +00007001
Douglas Gregorb98b1992009-08-11 05:31:07 +00007002template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007003ExprResult
John McCall454feb92009-12-08 09:21:05 +00007004TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007005 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00007006
Douglas Gregor43959a92009-08-20 07:17:43 +00007007 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00007008 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007009 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007010 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007011
Douglas Gregor43959a92009-08-20 07:17:43 +00007012 // transform the designators.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007013 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregorb98b1992009-08-11 05:31:07 +00007014 bool ExprChanged = false;
7015 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
7016 DEnd = E->designators_end();
7017 D != DEnd; ++D) {
7018 if (D->isFieldDesignator()) {
7019 Desig.AddDesignator(Designator::getField(D->getFieldName(),
7020 D->getDotLoc(),
7021 D->getFieldLoc()));
7022 continue;
7023 }
Mike Stump1eb44332009-09-09 15:08:12 +00007024
Douglas Gregorb98b1992009-08-11 05:31:07 +00007025 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00007026 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007027 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007028 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007029
7030 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007031 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00007032
Douglas Gregorb98b1992009-08-11 05:31:07 +00007033 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
7034 ArrayExprs.push_back(Index.release());
7035 continue;
7036 }
Mike Stump1eb44332009-09-09 15:08:12 +00007037
Douglas Gregorb98b1992009-08-11 05:31:07 +00007038 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00007039 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00007040 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7041 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007042 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007043
John McCall60d7b3a2010-08-24 06:29:42 +00007044 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007045 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007046 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007047
7048 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007049 End.get(),
7050 D->getLBracketLoc(),
7051 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00007052
Douglas Gregorb98b1992009-08-11 05:31:07 +00007053 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7054 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00007055
Douglas Gregorb98b1992009-08-11 05:31:07 +00007056 ArrayExprs.push_back(Start.release());
7057 ArrayExprs.push_back(End.release());
7058 }
Mike Stump1eb44332009-09-09 15:08:12 +00007059
Douglas Gregorb98b1992009-08-11 05:31:07 +00007060 if (!getDerived().AlwaysRebuild() &&
7061 Init.get() == E->getInit() &&
7062 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007063 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007064
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007065 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007066 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007067 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007068}
Mike Stump1eb44332009-09-09 15:08:12 +00007069
Douglas Gregorb98b1992009-08-11 05:31:07 +00007070template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007071ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007072TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00007073 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00007074 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007075
Douglas Gregor5557b252009-10-28 00:29:27 +00007076 // FIXME: Will we ever have proper type location here? Will we actually
7077 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00007078 QualType T = getDerived().TransformType(E->getType());
7079 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007080 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007081
Douglas Gregorb98b1992009-08-11 05:31:07 +00007082 if (!getDerived().AlwaysRebuild() &&
7083 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00007084 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007085
Douglas Gregorb98b1992009-08-11 05:31:07 +00007086 return getDerived().RebuildImplicitValueInitExpr(T);
7087}
Mike Stump1eb44332009-09-09 15:08:12 +00007088
Douglas Gregorb98b1992009-08-11 05:31:07 +00007089template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007090ExprResult
John McCall454feb92009-12-08 09:21:05 +00007091TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00007092 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7093 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007094 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007095
John McCall60d7b3a2010-08-24 06:29:42 +00007096 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007097 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007098 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007099
Douglas Gregorb98b1992009-08-11 05:31:07 +00007100 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00007101 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007102 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007103 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007104
John McCall9ae2f072010-08-23 23:25:46 +00007105 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00007106 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007107}
7108
7109template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007110ExprResult
John McCall454feb92009-12-08 09:21:05 +00007111TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007112 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007113 SmallVector<Expr*, 4> Inits;
Douglas Gregoraa165f82011-01-03 19:04:46 +00007114 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7115 &ArgumentChanged))
7116 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007117
Douglas Gregorb98b1992009-08-11 05:31:07 +00007118 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007119 Inits,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007120 E->getRParenLoc());
7121}
Mike Stump1eb44332009-09-09 15:08:12 +00007122
Douglas Gregorb98b1992009-08-11 05:31:07 +00007123/// \brief Transform an address-of-label expression.
7124///
7125/// By default, the transformation of an address-of-label expression always
7126/// rebuilds the expression, so that the label identifier can be resolved to
7127/// the corresponding label statement by semantic analysis.
7128template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007129ExprResult
John McCall454feb92009-12-08 09:21:05 +00007130TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00007131 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7132 E->getLabel());
7133 if (!LD)
7134 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007135
Douglas Gregorb98b1992009-08-11 05:31:07 +00007136 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00007137 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007138}
Mike Stump1eb44332009-09-09 15:08:12 +00007139
7140template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00007141ExprResult
John McCall454feb92009-12-08 09:21:05 +00007142TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00007143 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00007144 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00007145 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00007146 if (SubStmt.isInvalid()) {
7147 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00007148 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00007149 }
Mike Stump1eb44332009-09-09 15:08:12 +00007150
Douglas Gregorb98b1992009-08-11 05:31:07 +00007151 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00007152 SubStmt.get() == E->getSubStmt()) {
7153 // Calling this an 'error' is unintuitive, but it does the right thing.
7154 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00007155 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00007156 }
Mike Stump1eb44332009-09-09 15:08:12 +00007157
7158 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007159 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007160 E->getRParenLoc());
7161}
Mike Stump1eb44332009-09-09 15:08:12 +00007162
Douglas Gregorb98b1992009-08-11 05:31:07 +00007163template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007164ExprResult
John McCall454feb92009-12-08 09:21:05 +00007165TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007166 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007167 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007168 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007169
John McCall60d7b3a2010-08-24 06:29:42 +00007170 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007171 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007172 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007173
John McCall60d7b3a2010-08-24 06:29:42 +00007174 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007175 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007176 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007177
Douglas Gregorb98b1992009-08-11 05:31:07 +00007178 if (!getDerived().AlwaysRebuild() &&
7179 Cond.get() == E->getCond() &&
7180 LHS.get() == E->getLHS() &&
7181 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00007182 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007183
Douglas Gregorb98b1992009-08-11 05:31:07 +00007184 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007185 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007186 E->getRParenLoc());
7187}
Mike Stump1eb44332009-09-09 15:08:12 +00007188
Douglas Gregorb98b1992009-08-11 05:31:07 +00007189template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007190ExprResult
John McCall454feb92009-12-08 09:21:05 +00007191TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007192 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007193}
7194
7195template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007196ExprResult
John McCall454feb92009-12-08 09:21:05 +00007197TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00007198 switch (E->getOperator()) {
7199 case OO_New:
7200 case OO_Delete:
7201 case OO_Array_New:
7202 case OO_Array_Delete:
7203 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier4a9d7952012-08-08 18:46:20 +00007204
Douglas Gregor668d6d92009-12-13 20:44:55 +00007205 case OO_Call: {
7206 // This is a call to an object's operator().
7207 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7208
7209 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00007210 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00007211 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007212 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00007213
7214 // FIXME: Poor location information
7215 SourceLocation FakeLParenLoc
7216 = SemaRef.PP.getLocForEndOfToken(
7217 static_cast<Expr *>(Object.get())->getLocEnd());
7218
7219 // Transform the call arguments.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007220 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007221 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007222 Args))
7223 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00007224
John McCall9ae2f072010-08-23 23:25:46 +00007225 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007226 Args,
Douglas Gregor668d6d92009-12-13 20:44:55 +00007227 E->getLocEnd());
7228 }
7229
7230#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7231 case OO_##Name:
7232#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7233#include "clang/Basic/OperatorKinds.def"
7234 case OO_Subscript:
7235 // Handled below.
7236 break;
7237
7238 case OO_Conditional:
7239 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00007240
7241 case OO_None:
7242 case NUM_OVERLOADED_OPERATORS:
7243 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00007244 }
7245
John McCall60d7b3a2010-08-24 06:29:42 +00007246 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007247 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007248 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007249
Richard Smithefeeccf2012-10-21 03:28:35 +00007250 ExprResult First;
7251 if (E->getOperator() == OO_Amp)
7252 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7253 else
7254 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007255 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007256 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007257
John McCall60d7b3a2010-08-24 06:29:42 +00007258 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00007259 if (E->getNumArgs() == 2) {
7260 Second = getDerived().TransformExpr(E->getArg(1));
7261 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007262 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007263 }
Mike Stump1eb44332009-09-09 15:08:12 +00007264
Douglas Gregorb98b1992009-08-11 05:31:07 +00007265 if (!getDerived().AlwaysRebuild() &&
7266 Callee.get() == E->getCallee() &&
7267 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00007268 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00007269 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007270
Lang Hamesbe9af122012-10-02 04:45:10 +00007271 Sema::FPContractStateRAII FPContractState(getSema());
7272 getSema().FPFeatures.fp_contract = E->isFPContractable();
7273
Douglas Gregorb98b1992009-08-11 05:31:07 +00007274 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7275 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007276 Callee.get(),
7277 First.get(),
7278 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007279}
Mike Stump1eb44332009-09-09 15:08:12 +00007280
Douglas Gregorb98b1992009-08-11 05:31:07 +00007281template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007282ExprResult
John McCall454feb92009-12-08 09:21:05 +00007283TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7284 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007285}
Mike Stump1eb44332009-09-09 15:08:12 +00007286
Douglas Gregorb98b1992009-08-11 05:31:07 +00007287template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007288ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00007289TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7290 // Transform the callee.
7291 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7292 if (Callee.isInvalid())
7293 return ExprError();
7294
7295 // Transform exec config.
7296 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7297 if (EC.isInvalid())
7298 return ExprError();
7299
7300 // Transform arguments.
7301 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007302 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007303 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007304 &ArgChanged))
7305 return ExprError();
7306
7307 if (!getDerived().AlwaysRebuild() &&
7308 Callee.get() == E->getCallee() &&
7309 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00007310 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00007311
7312 // FIXME: Wrong source location information for the '('.
7313 SourceLocation FakeLParenLoc
7314 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7315 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007316 Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007317 E->getRParenLoc(), EC.get());
7318}
7319
7320template<typename Derived>
7321ExprResult
John McCall454feb92009-12-08 09:21:05 +00007322TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007323 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7324 if (!Type)
7325 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007326
John McCall60d7b3a2010-08-24 06:29:42 +00007327 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007328 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007329 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007330 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007331
Douglas Gregorb98b1992009-08-11 05:31:07 +00007332 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007333 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007334 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007335 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007336 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00007337 E->getStmtClass(),
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007338 E->getAngleBrackets().getBegin(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007339 Type,
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007340 E->getAngleBrackets().getEnd(),
7341 // FIXME. this should be '(' location
7342 E->getAngleBrackets().getEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00007343 SubExpr.get(),
Abramo Bagnara6cf7d7d2012-10-15 21:08:58 +00007344 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007345}
Mike Stump1eb44332009-09-09 15:08:12 +00007346
Douglas Gregorb98b1992009-08-11 05:31:07 +00007347template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007348ExprResult
John McCall454feb92009-12-08 09:21:05 +00007349TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7350 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007351}
Mike Stump1eb44332009-09-09 15:08:12 +00007352
7353template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007354ExprResult
John McCall454feb92009-12-08 09:21:05 +00007355TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7356 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007357}
7358
Douglas Gregorb98b1992009-08-11 05:31:07 +00007359template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007360ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007361TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007362 CXXReinterpretCastExpr *E) {
7363 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007364}
Mike Stump1eb44332009-09-09 15:08:12 +00007365
Douglas Gregorb98b1992009-08-11 05:31:07 +00007366template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007367ExprResult
John McCall454feb92009-12-08 09:21:05 +00007368TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7369 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007370}
Mike Stump1eb44332009-09-09 15:08:12 +00007371
Douglas Gregorb98b1992009-08-11 05:31:07 +00007372template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007373ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007374TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007375 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007376 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7377 if (!Type)
7378 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007379
John McCall60d7b3a2010-08-24 06:29:42 +00007380 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007381 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007382 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007383 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007384
Douglas Gregorb98b1992009-08-11 05:31:07 +00007385 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007386 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007387 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007388 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007389
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007390 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedmancdd4b782013-08-15 22:02:56 +00007391 E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007392 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007393 E->getRParenLoc());
7394}
Mike Stump1eb44332009-09-09 15:08:12 +00007395
Douglas Gregorb98b1992009-08-11 05:31:07 +00007396template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007397ExprResult
John McCall454feb92009-12-08 09:21:05 +00007398TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007399 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007400 TypeSourceInfo *TInfo
7401 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7402 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007403 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007404
Douglas Gregorb98b1992009-08-11 05:31:07 +00007405 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007406 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007407 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007408
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007409 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7410 E->getLocStart(),
7411 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007412 E->getLocEnd());
7413 }
Mike Stump1eb44332009-09-09 15:08:12 +00007414
Eli Friedmanef331b72012-01-20 01:26:23 +00007415 // We don't know whether the subexpression is potentially evaluated until
7416 // after we perform semantic analysis. We speculatively assume it is
7417 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007418 // potentially evaluated.
Eli Friedman80bfa3d2012-09-26 04:34:21 +00007419 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7420 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00007421
John McCall60d7b3a2010-08-24 06:29:42 +00007422 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007423 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007424 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007425
Douglas Gregorb98b1992009-08-11 05:31:07 +00007426 if (!getDerived().AlwaysRebuild() &&
7427 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007428 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007429
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007430 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7431 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007432 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007433 E->getLocEnd());
7434}
7435
7436template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007437ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007438TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7439 if (E->isTypeOperand()) {
7440 TypeSourceInfo *TInfo
7441 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7442 if (!TInfo)
7443 return ExprError();
7444
7445 if (!getDerived().AlwaysRebuild() &&
7446 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007447 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007448
Douglas Gregor3c52a212011-03-06 17:40:41 +00007449 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007450 E->getLocStart(),
7451 TInfo,
7452 E->getLocEnd());
7453 }
7454
Francois Pichet01b7c302010-09-08 12:20:18 +00007455 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7456
7457 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7458 if (SubExpr.isInvalid())
7459 return ExprError();
7460
7461 if (!getDerived().AlwaysRebuild() &&
7462 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007463 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007464
7465 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7466 E->getLocStart(),
7467 SubExpr.get(),
7468 E->getLocEnd());
7469}
7470
7471template<typename Derived>
7472ExprResult
John McCall454feb92009-12-08 09:21:05 +00007473TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007474 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007475}
Mike Stump1eb44332009-09-09 15:08:12 +00007476
Douglas Gregorb98b1992009-08-11 05:31:07 +00007477template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007478ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007479TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007480 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007481 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007482}
Mike Stump1eb44332009-09-09 15:08:12 +00007483
Douglas Gregorb98b1992009-08-11 05:31:07 +00007484template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007485ExprResult
John McCall454feb92009-12-08 09:21:05 +00007486TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithcafeb942013-06-07 02:33:37 +00007487 QualType T = getSema().getCurrentThisType();
Mike Stump1eb44332009-09-09 15:08:12 +00007488
Douglas Gregorec79d872012-02-24 17:41:38 +00007489 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7490 // Make sure that we capture 'this'.
7491 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007492 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007493 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007494
Douglas Gregor828a1972010-01-07 23:12:05 +00007495 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007496}
Mike Stump1eb44332009-09-09 15:08:12 +00007497
Douglas Gregorb98b1992009-08-11 05:31:07 +00007498template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007499ExprResult
John McCall454feb92009-12-08 09:21:05 +00007500TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007501 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007502 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007503 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007504
Douglas Gregorb98b1992009-08-11 05:31:07 +00007505 if (!getDerived().AlwaysRebuild() &&
7506 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007507 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007508
Douglas Gregorbca01b42011-07-06 22:04:06 +00007509 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7510 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007511}
Mike Stump1eb44332009-09-09 15:08:12 +00007512
Douglas Gregorb98b1992009-08-11 05:31:07 +00007513template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007514ExprResult
John McCall454feb92009-12-08 09:21:05 +00007515TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007516 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007517 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7518 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007519 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007520 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007521
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007522 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007523 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007524 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007525
Douglas Gregor036aed12009-12-23 23:03:06 +00007526 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007527}
Mike Stump1eb44332009-09-09 15:08:12 +00007528
Douglas Gregorb98b1992009-08-11 05:31:07 +00007529template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007530ExprResult
Richard Smithc3bf52c2013-04-20 22:23:05 +00007531TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
7532 FieldDecl *Field
7533 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
7534 E->getField()));
7535 if (!Field)
7536 return ExprError();
7537
7538 if (!getDerived().AlwaysRebuild() && Field == E->getField())
7539 return SemaRef.Owned(E);
7540
7541 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
7542}
7543
7544template<typename Derived>
7545ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007546TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7547 CXXScalarValueInitExpr *E) {
7548 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7549 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007550 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007551
Douglas Gregorb98b1992009-08-11 05:31:07 +00007552 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007553 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007554 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007555
Chad Rosier4a9d7952012-08-08 18:46:20 +00007556 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregorab6677e2010-09-08 00:15:04 +00007557 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007558 E->getRParenLoc());
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
John McCall454feb92009-12-08 09:21:05 +00007563TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007564 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007565 TypeSourceInfo *AllocTypeInfo
7566 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7567 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007568 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007569
Douglas Gregorb98b1992009-08-11 05:31:07 +00007570 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007571 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007572 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007573 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007574
Douglas Gregorb98b1992009-08-11 05:31:07 +00007575 // Transform the placement arguments (if any).
7576 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007577 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007578 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregoraa165f82011-01-03 19:04:46 +00007579 E->getNumPlacementArgs(), true,
7580 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007581 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007582
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007583 // Transform the initializer (if any).
7584 Expr *OldInit = E->getInitializer();
7585 ExprResult NewInit;
7586 if (OldInit)
7587 NewInit = getDerived().TransformExpr(OldInit);
7588 if (NewInit.isInvalid())
7589 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007590
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007591 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007592 FunctionDecl *OperatorNew = 0;
7593 if (E->getOperatorNew()) {
7594 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007595 getDerived().TransformDecl(E->getLocStart(),
7596 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007597 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007598 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007599 }
7600
7601 FunctionDecl *OperatorDelete = 0;
7602 if (E->getOperatorDelete()) {
7603 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007604 getDerived().TransformDecl(E->getLocStart(),
7605 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007606 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007607 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007608 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007609
Douglas Gregorb98b1992009-08-11 05:31:07 +00007610 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007611 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007612 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007613 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007614 OperatorNew == E->getOperatorNew() &&
7615 OperatorDelete == E->getOperatorDelete() &&
7616 !ArgumentChanged) {
7617 // Mark any declarations we need as referenced.
7618 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007619 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007620 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007621 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007622 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007623
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007624 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007625 QualType ElementType
7626 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7627 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7628 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7629 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007630 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007631 }
7632 }
7633 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007634
John McCall3fa5cae2010-10-26 07:05:15 +00007635 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007636 }
Mike Stump1eb44332009-09-09 15:08:12 +00007637
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007638 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007639 if (!ArraySize.get()) {
7640 // If no array size was specified, but the new expression was
7641 // instantiated with an array type (e.g., "new T" where T is
7642 // instantiated with "int[4]"), extract the outer bound from the
7643 // array type as our array size. We do this with constant and
7644 // dependently-sized array types.
7645 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7646 if (!ArrayT) {
7647 // Do nothing
7648 } else if (const ConstantArrayType *ConsArrayT
7649 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007650 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007651 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier4a9d7952012-08-08 18:46:20 +00007652 ConsArrayT->getSize(),
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007653 SemaRef.Context.getSizeType(),
7654 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007655 AllocType = ConsArrayT->getElementType();
7656 } else if (const DependentSizedArrayType *DepArrayT
7657 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7658 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007659 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007660 AllocType = DepArrayT->getElementType();
7661 }
7662 }
7663 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007664
Douglas Gregorb98b1992009-08-11 05:31:07 +00007665 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7666 E->isGlobalNew(),
7667 /*FIXME:*/E->getLocStart(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007668 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007669 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007670 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007671 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007672 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007673 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007674 E->getDirectInitRange(),
7675 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007676}
Mike Stump1eb44332009-09-09 15:08:12 +00007677
Douglas Gregorb98b1992009-08-11 05:31:07 +00007678template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007679ExprResult
John McCall454feb92009-12-08 09:21:05 +00007680TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007681 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007682 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007683 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007684
Douglas Gregor1af74512010-02-26 00:38:10 +00007685 // Transform the delete operator, if known.
7686 FunctionDecl *OperatorDelete = 0;
7687 if (E->getOperatorDelete()) {
7688 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007689 getDerived().TransformDecl(E->getLocStart(),
7690 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007691 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007692 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007693 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007694
Douglas Gregorb98b1992009-08-11 05:31:07 +00007695 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007696 Operand.get() == E->getArgument() &&
7697 OperatorDelete == E->getOperatorDelete()) {
7698 // Mark any declarations we need as referenced.
7699 // FIXME: instantiation-specific.
7700 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007701 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007702
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007703 if (!E->getArgument()->isTypeDependent()) {
7704 QualType Destroyed = SemaRef.Context.getBaseElementType(
7705 E->getDestroyedType());
7706 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7707 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007708 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedman5f2987c2012-02-02 03:46:19 +00007709 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007710 }
7711 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007712
John McCall3fa5cae2010-10-26 07:05:15 +00007713 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007714 }
Mike Stump1eb44332009-09-09 15:08:12 +00007715
Douglas Gregorb98b1992009-08-11 05:31:07 +00007716 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7717 E->isGlobalDelete(),
7718 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007719 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007720}
Mike Stump1eb44332009-09-09 15:08:12 +00007721
Douglas Gregorb98b1992009-08-11 05:31:07 +00007722template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007723ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007724TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007725 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007726 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007727 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007728 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007729
John McCallb3d87482010-08-24 05:47:05 +00007730 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007731 bool MayBePseudoDestructor = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007732 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007733 E->getOperatorLoc(),
7734 E->isArrow()? tok::arrow : tok::period,
7735 ObjectTypePtr,
7736 MayBePseudoDestructor);
7737 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007738 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007739
John McCallb3d87482010-08-24 05:47:05 +00007740 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007741 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7742 if (QualifierLoc) {
7743 QualifierLoc
7744 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7745 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007746 return ExprError();
7747 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007748 CXXScopeSpec SS;
7749 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007750
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007751 PseudoDestructorTypeStorage Destroyed;
7752 if (E->getDestroyedTypeInfo()) {
7753 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007754 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007755 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007756 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007757 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007758 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007759 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007760 // We aren't likely to be able to resolve the identifier down to a type
7761 // now anyway, so just retain the identifier.
7762 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7763 E->getDestroyedTypeLoc());
7764 } else {
7765 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007766 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007767 *E->getDestroyedTypeIdentifier(),
7768 E->getDestroyedTypeLoc(),
7769 /*Scope=*/0,
7770 SS, ObjectTypePtr,
7771 false);
7772 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007773 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007774
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007775 Destroyed
7776 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7777 E->getDestroyedTypeLoc());
7778 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007779
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007780 TypeSourceInfo *ScopeTypeInfo = 0;
7781 if (E->getScopeTypeInfo()) {
Douglas Gregor303b96f2013-03-08 21:25:01 +00007782 CXXScopeSpec EmptySS;
7783 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
7784 E->getScopeTypeInfo(), ObjectType, 0, EmptySS);
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007785 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007786 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007787 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007788
John McCall9ae2f072010-08-23 23:25:46 +00007789 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007790 E->getOperatorLoc(),
7791 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007792 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007793 ScopeTypeInfo,
7794 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007795 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007796 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007797}
Mike Stump1eb44332009-09-09 15:08:12 +00007798
Douglas Gregora71d8192009-09-04 17:36:40 +00007799template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007800ExprResult
John McCallba135432009-11-21 08:51:07 +00007801TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007802 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007803 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7804 Sema::LookupOrdinaryName);
7805
7806 // Transform all the decls.
7807 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7808 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007809 NamedDecl *InstD = static_cast<NamedDecl*>(
7810 getDerived().TransformDecl(Old->getNameLoc(),
7811 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007812 if (!InstD) {
7813 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7814 // This can happen because of dependent hiding.
7815 if (isa<UsingShadowDecl>(*I))
7816 continue;
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007817 else {
7818 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00007819 return ExprError();
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007820 }
John McCall9f54ad42009-12-10 09:41:52 +00007821 }
John McCallf7a1a742009-11-24 19:00:30 +00007822
7823 // Expand using declarations.
7824 if (isa<UsingDecl>(InstD)) {
7825 UsingDecl *UD = cast<UsingDecl>(InstD);
7826 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7827 E = UD->shadow_end(); I != E; ++I)
7828 R.addDecl(*I);
7829 continue;
7830 }
7831
7832 R.addDecl(InstD);
7833 }
7834
7835 // Resolve a kind, but don't do any further analysis. If it's
7836 // ambiguous, the callee needs to deal with it.
7837 R.resolveKind();
7838
7839 // Rebuild the nested-name qualifier, if present.
7840 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007841 if (Old->getQualifierLoc()) {
7842 NestedNameSpecifierLoc QualifierLoc
7843 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7844 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007845 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007846
Douglas Gregor4c9be892011-02-28 20:01:57 +00007847 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007848 }
7849
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007850 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007851 CXXRecordDecl *NamingClass
7852 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7853 Old->getNameLoc(),
7854 Old->getNamingClass()));
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007855 if (!NamingClass) {
7856 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00007857 return ExprError();
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007858 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007859
Douglas Gregor66c45152010-04-27 16:10:10 +00007860 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007861 }
7862
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007863 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7864
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007865 // If we have neither explicit template arguments, nor the template keyword,
7866 // it's a normal declaration name.
7867 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007868 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7869
7870 // If we have template arguments, rebuild them, then rebuild the
7871 // templateid expression.
7872 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola02e221b2012-08-28 04:13:54 +00007873 if (Old->hasExplicitTemplateArgs() &&
7874 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregorfcc12532010-12-20 17:31:10 +00007875 Old->getNumTemplateArgs(),
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007876 TransArgs)) {
7877 R.clear();
Douglas Gregorfcc12532010-12-20 17:31:10 +00007878 return ExprError();
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007879 }
John McCallf7a1a742009-11-24 19:00:30 +00007880
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007881 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007882 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007883}
Mike Stump1eb44332009-09-09 15:08:12 +00007884
Douglas Gregorb98b1992009-08-11 05:31:07 +00007885template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007886ExprResult
John McCall454feb92009-12-08 09:21:05 +00007887TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007888 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7889 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007890 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007891
Douglas Gregorb98b1992009-08-11 05:31:07 +00007892 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007893 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007894 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007895
Mike Stump1eb44332009-09-09 15:08:12 +00007896 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007897 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007898 T,
7899 E->getLocEnd());
7900}
Mike Stump1eb44332009-09-09 15:08:12 +00007901
Douglas Gregorb98b1992009-08-11 05:31:07 +00007902template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007903ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007904TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7905 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7906 if (!LhsT)
7907 return ExprError();
7908
7909 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7910 if (!RhsT)
7911 return ExprError();
7912
7913 if (!getDerived().AlwaysRebuild() &&
7914 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7915 return SemaRef.Owned(E);
7916
7917 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7918 E->getLocStart(),
7919 LhsT, RhsT,
7920 E->getLocEnd());
7921}
7922
7923template<typename Derived>
7924ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007925TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7926 bool ArgChanged = false;
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00007927 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007928 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7929 TypeSourceInfo *From = E->getArg(I);
7930 TypeLoc FromTL = From->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00007931 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007932 TypeLocBuilder TLB;
7933 TLB.reserve(FromTL.getFullDataSize());
7934 QualType To = getDerived().TransformType(TLB, FromTL);
7935 if (To.isNull())
7936 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007937
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007938 if (To == From->getType())
7939 Args.push_back(From);
7940 else {
7941 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7942 ArgChanged = true;
7943 }
7944 continue;
7945 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007946
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007947 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007948
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007949 // We have a pack expansion. Instantiate it.
David Blaikie39e6ab42013-02-18 22:06:02 +00007950 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007951 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7952 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7953 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007954
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007955 // Determine whether the set of unexpanded parameter packs can and should
7956 // be expanded.
7957 bool Expand = true;
7958 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00007959 Optional<unsigned> OrigNumExpansions =
7960 ExpansionTL.getTypePtr()->getNumExpansions();
7961 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007962 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7963 PatternTL.getSourceRange(),
7964 Unexpanded,
7965 Expand, RetainExpansion,
7966 NumExpansions))
7967 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007968
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007969 if (!Expand) {
7970 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00007971 // transformation on the pack expansion, producing another pack
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007972 // expansion.
7973 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007974
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007975 TypeLocBuilder TLB;
7976 TLB.reserve(From->getTypeLoc().getFullDataSize());
7977
7978 QualType To = getDerived().TransformType(TLB, PatternTL);
7979 if (To.isNull())
7980 return ExprError();
7981
Chad Rosier4a9d7952012-08-08 18:46:20 +00007982 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007983 PatternTL.getSourceRange(),
7984 ExpansionTL.getEllipsisLoc(),
7985 NumExpansions);
7986 if (To.isNull())
7987 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007988
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007989 PackExpansionTypeLoc ToExpansionTL
7990 = TLB.push<PackExpansionTypeLoc>(To);
7991 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7992 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7993 continue;
7994 }
7995
7996 // Expand the pack expansion by substituting for each argument in the
7997 // pack(s).
7998 for (unsigned I = 0; I != *NumExpansions; ++I) {
7999 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
8000 TypeLocBuilder TLB;
8001 TLB.reserve(PatternTL.getFullDataSize());
8002 QualType To = getDerived().TransformType(TLB, PatternTL);
8003 if (To.isNull())
8004 return ExprError();
8005
Eli Friedman20cfeca2013-07-19 21:49:32 +00008006 if (To->containsUnexpandedParameterPack()) {
8007 To = getDerived().RebuildPackExpansionType(To,
8008 PatternTL.getSourceRange(),
8009 ExpansionTL.getEllipsisLoc(),
8010 NumExpansions);
8011 if (To.isNull())
8012 return ExprError();
8013
8014 PackExpansionTypeLoc ToExpansionTL
8015 = TLB.push<PackExpansionTypeLoc>(To);
8016 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8017 }
8018
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008019 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8020 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008021
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008022 if (!RetainExpansion)
8023 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008024
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008025 // If we're supposed to retain a pack expansion, do so by temporarily
8026 // forgetting the partially-substituted parameter pack.
8027 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
8028
8029 TypeLocBuilder TLB;
8030 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008031
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008032 QualType To = getDerived().TransformType(TLB, PatternTL);
8033 if (To.isNull())
8034 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008035
8036 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008037 PatternTL.getSourceRange(),
8038 ExpansionTL.getEllipsisLoc(),
8039 NumExpansions);
8040 if (To.isNull())
8041 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008042
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008043 PackExpansionTypeLoc ToExpansionTL
8044 = TLB.push<PackExpansionTypeLoc>(To);
8045 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8046 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8047 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008048
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008049 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8050 return SemaRef.Owned(E);
8051
8052 return getDerived().RebuildTypeTrait(E->getTrait(),
8053 E->getLocStart(),
8054 Args,
8055 E->getLocEnd());
8056}
8057
8058template<typename Derived>
8059ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00008060TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8061 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
8062 if (!T)
8063 return ExprError();
8064
8065 if (!getDerived().AlwaysRebuild() &&
8066 T == E->getQueriedTypeSourceInfo())
8067 return SemaRef.Owned(E);
8068
8069 ExprResult SubExpr;
8070 {
8071 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8072 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8073 if (SubExpr.isInvalid())
8074 return ExprError();
8075
8076 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
8077 return SemaRef.Owned(E);
8078 }
8079
8080 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8081 E->getLocStart(),
8082 T,
8083 SubExpr.get(),
8084 E->getLocEnd());
8085}
8086
8087template<typename Derived>
8088ExprResult
John Wiegley55262202011-04-25 06:54:41 +00008089TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8090 ExprResult SubExpr;
8091 {
8092 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8093 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8094 if (SubExpr.isInvalid())
8095 return ExprError();
8096
8097 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
8098 return SemaRef.Owned(E);
8099 }
8100
8101 return getDerived().RebuildExpressionTrait(
8102 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8103}
8104
8105template<typename Derived>
8106ExprResult
John McCall865d4472009-11-19 22:55:06 +00008107TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008108 DependentScopeDeclRefExpr *E) {
Richard Smithefeeccf2012-10-21 03:28:35 +00008109 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
8110}
8111
8112template<typename Derived>
8113ExprResult
8114TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8115 DependentScopeDeclRefExpr *E,
8116 bool IsAddressOfOperand) {
Reid Kleckner8690cee2013-10-15 18:38:02 +00008117 assert(E->getQualifierLoc());
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008118 NestedNameSpecifierLoc QualifierLoc
8119 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8120 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008121 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008122 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00008123
John McCall43fed0d2010-11-12 08:19:04 +00008124 // TODO: If this is a conversion-function-id, verify that the
8125 // destination type name (if present) resolves the same way after
8126 // instantiation as it did in the local scope.
8127
Abramo Bagnara25777432010-08-11 22:01:17 +00008128 DeclarationNameInfo NameInfo
8129 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8130 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008131 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008132
John McCallf7a1a742009-11-24 19:00:30 +00008133 if (!E->hasExplicitTemplateArgs()) {
8134 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008135 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008136 // Note: it is sufficient to compare the Name component of NameInfo:
8137 // if name has not changed, DNLoc has not changed either.
8138 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00008139 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008140
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008141 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008142 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00008143 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00008144 /*TemplateArgs*/ 0,
8145 IsAddressOfOperand);
Douglas Gregorf17bb742009-10-22 17:20:55 +00008146 }
John McCalld5532b62009-11-23 01:53:49 +00008147
8148 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008149 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8150 E->getNumTemplateArgs(),
8151 TransArgs))
8152 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00008153
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008154 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008155 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00008156 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00008157 &TransArgs,
8158 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008159}
8160
8161template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008162ExprResult
John McCall454feb92009-12-08 09:21:05 +00008163TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithc83c2302012-12-19 01:39:02 +00008164 // CXXConstructExprs other than for list-initialization and
8165 // CXXTemporaryObjectExpr are always implicit, so when we have
8166 // a 1-argument construction we just transform that argument.
Richard Smith73ed67c2012-11-26 08:32:48 +00008167 if ((E->getNumArgs() == 1 ||
8168 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithc83c2302012-12-19 01:39:02 +00008169 (!getDerived().DropCallArgument(E->getArg(0))) &&
8170 !E->isListInitialization())
Douglas Gregor321725d2010-02-03 03:01:57 +00008171 return getDerived().TransformExpr(E->getArg(0));
8172
Douglas Gregorb98b1992009-08-11 05:31:07 +00008173 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8174
8175 QualType T = getDerived().TransformType(E->getType());
8176 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00008177 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00008178
8179 CXXConstructorDecl *Constructor
8180 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008181 getDerived().TransformDecl(E->getLocStart(),
8182 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008183 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00008184 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008185
Douglas Gregorb98b1992009-08-11 05:31:07 +00008186 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008187 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008188 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008189 &ArgumentChanged))
8190 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008191
Douglas Gregorb98b1992009-08-11 05:31:07 +00008192 if (!getDerived().AlwaysRebuild() &&
8193 T == E->getType() &&
8194 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00008195 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00008196 // Mark the constructor as referenced.
8197 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00008198 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00008199 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00008200 }
Mike Stump1eb44332009-09-09 15:08:12 +00008201
Douglas Gregor4411d2e2009-12-14 16:27:04 +00008202 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8203 Constructor, E->isElidable(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008204 Args,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00008205 E->hadMultipleCandidates(),
Richard Smithc83c2302012-12-19 01:39:02 +00008206 E->isListInitialization(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00008207 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00008208 E->getConstructionKind(),
Enea Zaffanella1245a542013-09-07 05:49:53 +00008209 E->getParenOrBraceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008210}
Mike Stump1eb44332009-09-09 15:08:12 +00008211
Douglas Gregorb98b1992009-08-11 05:31:07 +00008212/// \brief Transform a C++ temporary-binding expression.
8213///
Douglas Gregor51326552009-12-24 18:51:59 +00008214/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8215/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00008216template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008217ExprResult
John McCall454feb92009-12-08 09:21:05 +00008218TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00008219 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008220}
Mike Stump1eb44332009-09-09 15:08:12 +00008221
John McCall4765fa02010-12-06 08:20:24 +00008222/// \brief Transform a C++ expression that contains cleanups that should
8223/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00008224///
John McCall4765fa02010-12-06 08:20:24 +00008225/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00008226/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00008227template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008228ExprResult
John McCall4765fa02010-12-06 08:20:24 +00008229TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00008230 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008231}
Mike Stump1eb44332009-09-09 15:08:12 +00008232
Douglas Gregorb98b1992009-08-11 05:31:07 +00008233template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008234ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008235TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00008236 CXXTemporaryObjectExpr *E) {
8237 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8238 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008239 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008240
Douglas Gregorb98b1992009-08-11 05:31:07 +00008241 CXXConstructorDecl *Constructor
8242 = cast_or_null<CXXConstructorDecl>(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008243 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008244 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008245 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00008246 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008247
Douglas Gregorb98b1992009-08-11 05:31:07 +00008248 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008249 SmallVector<Expr*, 8> Args;
Douglas Gregorb98b1992009-08-11 05:31:07 +00008250 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008251 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008252 &ArgumentChanged))
8253 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008254
Douglas Gregorb98b1992009-08-11 05:31:07 +00008255 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008256 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008257 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00008258 !ArgumentChanged) {
8259 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00008260 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00008261 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00008262 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008263
Richard Smithc83c2302012-12-19 01:39:02 +00008264 // FIXME: Pass in E->isListInitialization().
Douglas Gregorab6677e2010-09-08 00:15:04 +00008265 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8266 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008267 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008268 E->getLocEnd());
8269}
Mike Stump1eb44332009-09-09 15:08:12 +00008270
Douglas Gregorb98b1992009-08-11 05:31:07 +00008271template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008272ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00008273TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Faisal Valifad9e132013-09-26 19:54:12 +00008274
Faisal Valia3d311e2013-10-23 06:44:28 +00008275 getSema().PushLambdaScope();
8276 LambdaScopeInfo *LSI = getSema().getCurLambda();
8277 // Transform the template parameters, and add them to the current
8278 // instantiation scope. The null case is handled correctly.
8279 LSI->GLTemplateParameterList = getDerived().TransformTemplateParameterList(
8280 E->getTemplateParameterList());
8281
8282 // Check to see if the TypeSourceInfo of the call operator needs to
8283 // be transformed, and if so do the transformation in the
8284 // CurrentInstantiationScope.
8285
8286 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
8287 FunctionProtoTypeLoc OldCallOpFPTL =
8288 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
8289 TypeSourceInfo *NewCallOpTSI = 0;
8290
8291 const bool CallOpWasAlreadyTransformed =
8292 getDerived().AlreadyTransformed(OldCallOpTSI->getType());
8293
8294 // Use the Old Call Operator's TypeSourceInfo if it is already transformed.
8295 if (CallOpWasAlreadyTransformed)
8296 NewCallOpTSI = OldCallOpTSI;
8297 else {
8298 // Transform the TypeSourceInfo of the Original Lambda's Call Operator.
8299 // The transformation MUST be done in the CurrentInstantiationScope since
8300 // it introduces a mapping of the original to the newly created
8301 // transformed parameters.
8302
8303 TypeLocBuilder NewCallOpTLBuilder;
8304 QualType NewCallOpType = TransformFunctionProtoType(NewCallOpTLBuilder,
8305 OldCallOpFPTL,
8306 0, 0);
8307 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
8308 NewCallOpType);
Faisal Valifad9e132013-09-26 19:54:12 +00008309 }
Faisal Valia3d311e2013-10-23 06:44:28 +00008310 // Extract the ParmVarDecls from the NewCallOpTSI and add them to
8311 // the vector below - this will be used to synthesize the
8312 // NewCallOperator. Additionally, add the parameters of the untransformed
8313 // lambda call operator to the CurrentInstantiationScope.
8314 SmallVector<ParmVarDecl *, 4> Params;
8315 {
8316 FunctionProtoTypeLoc NewCallOpFPTL =
8317 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>();
8318 ParmVarDecl **NewParamDeclArray = NewCallOpFPTL.getParmArray();
8319 const unsigned NewNumArgs = NewCallOpFPTL.getNumArgs();
8320
8321 for (unsigned I = 0; I < NewNumArgs; ++I) {
8322 // If this call operator's type does not require transformation,
8323 // the parameters do not get added to the current instantiation scope,
8324 // - so ADD them! This allows the following to compile when the enclosing
8325 // template is specialized and the entire lambda expression has to be
8326 // transformed.
8327 // template<class T> void foo(T t) {
8328 // auto L = [](auto a) {
8329 // auto M = [](char b) { <-- note: non-generic lambda
8330 // auto N = [](auto c) {
8331 // int x = sizeof(a);
8332 // x = sizeof(b); <-- specifically this line
8333 // x = sizeof(c);
8334 // };
8335 // };
8336 // };
8337 // }
8338 // foo('a')
8339 if (CallOpWasAlreadyTransformed)
8340 getDerived().transformedLocalDecl(NewParamDeclArray[I],
8341 NewParamDeclArray[I]);
8342 // Add to Params array, so these parameters can be used to create
8343 // the newly transformed call operator.
8344 Params.push_back(NewParamDeclArray[I]);
8345 }
8346 }
8347
8348 if (!NewCallOpTSI)
Douglas Gregordfca6f52012-02-13 22:00:16 +00008349 return ExprError();
8350
Eli Friedman8da8a662012-09-19 01:18:11 +00008351 // Create the local class that will describe the lambda.
8352 CXXRecordDecl *Class
8353 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Valia3d311e2013-10-23 06:44:28 +00008354 NewCallOpTSI,
Faisal Valibef582b2013-10-23 16:10:50 +00008355 /*KnownDependent=*/false,
8356 E->getCaptureDefault());
8357
Eli Friedman8da8a662012-09-19 01:18:11 +00008358 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8359
Douglas Gregordfca6f52012-02-13 22:00:16 +00008360 // Build the call operator.
Faisal Valia3d311e2013-10-23 06:44:28 +00008361 CXXMethodDecl *NewCallOperator
Douglas Gregordfca6f52012-02-13 22:00:16 +00008362 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Faisal Valia3d311e2013-10-23 06:44:28 +00008363 NewCallOpTSI,
Douglas Gregorc6889e72012-02-14 22:28:59 +00008364 E->getCallOperator()->getLocEnd(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00008365 Params);
Faisal Valia3d311e2013-10-23 06:44:28 +00008366 LSI->CallOperator = NewCallOperator;
Rafael Espindolaf003acd2013-10-04 14:28:51 +00008367
Faisal Valia3d311e2013-10-23 06:44:28 +00008368 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
8369
8370 return getDerived().TransformLambdaScope(E, NewCallOperator);
Richard Smith612409e2012-07-25 03:56:55 +00008371}
8372
8373template<typename Derived>
8374ExprResult
8375TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
8376 CXXMethodDecl *CallOperator) {
Richard Smith0d8e9642013-05-16 06:20:58 +00008377 bool Invalid = false;
8378
8379 // Transform any init-capture expressions before entering the scope of the
8380 // lambda.
Robert Wilhelme7205c02013-08-10 12:33:24 +00008381 SmallVector<ExprResult, 8> InitCaptureExprs;
Richard Smith0d8e9642013-05-16 06:20:58 +00008382 InitCaptureExprs.resize(E->explicit_capture_end() -
8383 E->explicit_capture_begin());
8384 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8385 CEnd = E->capture_end();
8386 C != CEnd; ++C) {
8387 if (!C->isInitCapture())
8388 continue;
8389 InitCaptureExprs[C - E->capture_begin()] =
Richard Smith04fa7a32013-09-28 04:02:39 +00008390 getDerived().TransformInitializer(
8391 C->getCapturedVar()->getInit(),
8392 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith0d8e9642013-05-16 06:20:58 +00008393 }
8394
Douglas Gregord5387e82012-02-14 00:00:48 +00008395 // Introduce the context of the call operator.
8396 Sema::ContextRAII SavedContext(getSema(), CallOperator);
8397
Faisal Valifad9e132013-09-26 19:54:12 +00008398 LambdaScopeInfo *const LSI = getSema().getCurLambda();
Douglas Gregordfca6f52012-02-13 22:00:16 +00008399 // Enter the scope of the lambda.
Faisal Valifad9e132013-09-26 19:54:12 +00008400 getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008401 E->getCaptureDefault(),
James Dennettf68af642013-08-09 23:08:25 +00008402 E->getCaptureDefaultLoc(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008403 E->hasExplicitParameters(),
8404 E->hasExplicitResultType(),
8405 E->isMutable());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008406
Douglas Gregordfca6f52012-02-13 22:00:16 +00008407 // Transform captures.
Douglas Gregordfca6f52012-02-13 22:00:16 +00008408 bool FinishedExplicitCaptures = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008409 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008410 CEnd = E->capture_end();
8411 C != CEnd; ++C) {
8412 // When we hit the first implicit capture, tell Sema that we've finished
8413 // the list of explicit captures.
8414 if (!FinishedExplicitCaptures && C->isImplicit()) {
8415 getSema().finishLambdaExplicitCaptures(LSI);
8416 FinishedExplicitCaptures = true;
8417 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008418
Douglas Gregordfca6f52012-02-13 22:00:16 +00008419 // Capturing 'this' is trivial.
8420 if (C->capturesThis()) {
8421 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8422 continue;
8423 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008424
Richard Smith0d8e9642013-05-16 06:20:58 +00008425 // Rebuild init-captures, including the implied field declaration.
8426 if (C->isInitCapture()) {
8427 ExprResult Init = InitCaptureExprs[C - E->capture_begin()];
8428 if (Init.isInvalid()) {
8429 Invalid = true;
8430 continue;
8431 }
Richard Smith04fa7a32013-09-28 04:02:39 +00008432 VarDecl *OldVD = C->getCapturedVar();
8433 VarDecl *NewVD = getSema().checkInitCapture(
8434 C->getLocation(), OldVD->getType()->isReferenceType(),
8435 OldVD->getIdentifier(), Init.take());
8436 if (!NewVD)
Richard Smith0d8e9642013-05-16 06:20:58 +00008437 Invalid = true;
8438 else
Richard Smith04fa7a32013-09-28 04:02:39 +00008439 getDerived().transformedLocalDecl(OldVD, NewVD);
8440 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smith0d8e9642013-05-16 06:20:58 +00008441 continue;
8442 }
8443
8444 assert(C->capturesVariable() && "unexpected kind of lambda capture");
8445
Douglas Gregora7365242012-02-14 19:27:52 +00008446 // Determine the capture kind for Sema.
8447 Sema::TryCaptureKind Kind
8448 = C->isImplicit()? Sema::TryCapture_Implicit
8449 : C->getCaptureKind() == LCK_ByCopy
8450 ? Sema::TryCapture_ExplicitByVal
8451 : Sema::TryCapture_ExplicitByRef;
8452 SourceLocation EllipsisLoc;
8453 if (C->isPackExpansion()) {
8454 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8455 bool ShouldExpand = false;
8456 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008457 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008458 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8459 C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008460 Unexpanded,
8461 ShouldExpand, RetainExpansion,
Richard Smith0d8e9642013-05-16 06:20:58 +00008462 NumExpansions)) {
8463 Invalid = true;
8464 continue;
8465 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008466
Douglas Gregora7365242012-02-14 19:27:52 +00008467 if (ShouldExpand) {
8468 // The transform has determined that we should perform an expansion;
8469 // transform and capture each of the arguments.
8470 // expansion of the pattern. Do so.
8471 VarDecl *Pack = C->getCapturedVar();
8472 for (unsigned I = 0; I != *NumExpansions; ++I) {
8473 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8474 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008475 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008476 Pack));
8477 if (!CapturedVar) {
8478 Invalid = true;
8479 continue;
8480 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008481
Douglas Gregora7365242012-02-14 19:27:52 +00008482 // Capture the transformed variable.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008483 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8484 }
Douglas Gregora7365242012-02-14 19:27:52 +00008485 continue;
8486 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008487
Douglas Gregora7365242012-02-14 19:27:52 +00008488 EllipsisLoc = C->getEllipsisLoc();
8489 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008490
Douglas Gregordfca6f52012-02-13 22:00:16 +00008491 // Transform the captured variable.
8492 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008493 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008494 C->getCapturedVar()));
8495 if (!CapturedVar) {
8496 Invalid = true;
8497 continue;
8498 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008499
Douglas Gregordfca6f52012-02-13 22:00:16 +00008500 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00008501 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008502 }
8503 if (!FinishedExplicitCaptures)
8504 getSema().finishLambdaExplicitCaptures(LSI);
8505
Douglas Gregordfca6f52012-02-13 22:00:16 +00008506
8507 // Enter a new evaluation context to insulate the lambda from any
8508 // cleanups from the enclosing full-expression.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008509 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008510
8511 if (Invalid) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008512 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregordfca6f52012-02-13 22:00:16 +00008513 /*IsInstantiation=*/true);
8514 return ExprError();
8515 }
8516
8517 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00008518 StmtResult Body = getDerived().TransformStmt(E->getBody());
8519 if (Body.isInvalid()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008520 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregord5387e82012-02-14 00:00:48 +00008521 /*IsInstantiation=*/true);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008522 return ExprError();
Douglas Gregord5387e82012-02-14 00:00:48 +00008523 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00008524
Chad Rosier4a9d7952012-08-08 18:46:20 +00008525 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00008526 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00008527}
8528
8529template<typename Derived>
8530ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008531TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00008532 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00008533 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8534 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008535 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008536
Douglas Gregorb98b1992009-08-11 05:31:07 +00008537 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008538 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008539 Args.reserve(E->arg_size());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008540 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008541 &ArgumentChanged))
8542 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008543
Douglas Gregorb98b1992009-08-11 05:31:07 +00008544 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008545 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008546 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008547 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008548
Douglas Gregorb98b1992009-08-11 05:31:07 +00008549 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00008550 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008551 E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008552 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008553 E->getRParenLoc());
8554}
Mike Stump1eb44332009-09-09 15:08:12 +00008555
Douglas Gregorb98b1992009-08-11 05:31:07 +00008556template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008557ExprResult
John McCall865d4472009-11-19 22:55:06 +00008558TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008559 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008560 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008561 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008562 Expr *OldBase;
8563 QualType BaseType;
8564 QualType ObjectType;
8565 if (!E->isImplicitAccess()) {
8566 OldBase = E->getBase();
8567 Base = getDerived().TransformExpr(OldBase);
8568 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008569 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008570
John McCallaa81e162009-12-01 22:10:20 +00008571 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008572 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008573 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008574 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008575 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008576 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008577 ObjectTy,
8578 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008579 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008580 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008581
John McCallb3d87482010-08-24 05:47:05 +00008582 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008583 BaseType = ((Expr*) Base.get())->getType();
8584 } else {
8585 OldBase = 0;
8586 BaseType = getDerived().TransformType(E->getBaseType());
8587 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8588 }
Mike Stump1eb44332009-09-09 15:08:12 +00008589
Douglas Gregor6cd21982009-10-20 05:58:46 +00008590 // Transform the first part of the nested-name-specifier that qualifies
8591 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008592 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008593 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008594 E->getFirstQualifierFoundInScope(),
8595 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008596
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008597 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008598 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008599 QualifierLoc
8600 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8601 ObjectType,
8602 FirstQualifierInScope);
8603 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008604 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008605 }
Mike Stump1eb44332009-09-09 15:08:12 +00008606
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008607 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8608
John McCall43fed0d2010-11-12 08:19:04 +00008609 // TODO: If this is a conversion-function-id, verify that the
8610 // destination type name (if present) resolves the same way after
8611 // instantiation as it did in the local scope.
8612
Abramo Bagnara25777432010-08-11 22:01:17 +00008613 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008614 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008615 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008616 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008617
John McCallaa81e162009-12-01 22:10:20 +00008618 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008619 // This is a reference to a member without an explicitly-specified
8620 // template argument list. Optimize for this common case.
8621 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008622 Base.get() == OldBase &&
8623 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008624 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008625 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008626 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008627 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008628
John McCall9ae2f072010-08-23 23:25:46 +00008629 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008630 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008631 E->isArrow(),
8632 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008633 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008634 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008635 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008636 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008637 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008638 }
8639
John McCalld5532b62009-11-23 01:53:49 +00008640 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008641 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8642 E->getNumTemplateArgs(),
8643 TransArgs))
8644 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008645
John McCall9ae2f072010-08-23 23:25:46 +00008646 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008647 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008648 E->isArrow(),
8649 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008650 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008651 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008652 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008653 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008654 &TransArgs);
8655}
8656
8657template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008658ExprResult
John McCall454feb92009-12-08 09:21:05 +00008659TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008660 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008661 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008662 QualType BaseType;
8663 if (!Old->isImplicitAccess()) {
8664 Base = getDerived().TransformExpr(Old->getBase());
8665 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008666 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008667 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8668 Old->isArrow());
8669 if (Base.isInvalid())
8670 return ExprError();
8671 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008672 } else {
8673 BaseType = getDerived().TransformType(Old->getBaseType());
8674 }
John McCall129e2df2009-11-30 22:42:35 +00008675
Douglas Gregor4c9be892011-02-28 20:01:57 +00008676 NestedNameSpecifierLoc QualifierLoc;
8677 if (Old->getQualifierLoc()) {
8678 QualifierLoc
8679 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8680 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008681 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008682 }
8683
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008684 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8685
Abramo Bagnara25777432010-08-11 22:01:17 +00008686 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008687 Sema::LookupOrdinaryName);
8688
8689 // Transform all the decls.
8690 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8691 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008692 NamedDecl *InstD = static_cast<NamedDecl*>(
8693 getDerived().TransformDecl(Old->getMemberLoc(),
8694 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008695 if (!InstD) {
8696 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8697 // This can happen because of dependent hiding.
8698 if (isa<UsingShadowDecl>(*I))
8699 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008700 else {
8701 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008702 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008703 }
John McCall9f54ad42009-12-10 09:41:52 +00008704 }
John McCall129e2df2009-11-30 22:42:35 +00008705
8706 // Expand using declarations.
8707 if (isa<UsingDecl>(InstD)) {
8708 UsingDecl *UD = cast<UsingDecl>(InstD);
8709 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8710 E = UD->shadow_end(); I != E; ++I)
8711 R.addDecl(*I);
8712 continue;
8713 }
8714
8715 R.addDecl(InstD);
8716 }
8717
8718 R.resolveKind();
8719
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008720 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008721 if (Old->getNamingClass()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008722 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008723 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008724 Old->getMemberLoc(),
8725 Old->getNamingClass()));
8726 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008727 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008728
Douglas Gregor66c45152010-04-27 16:10:10 +00008729 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008730 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008731
John McCall129e2df2009-11-30 22:42:35 +00008732 TemplateArgumentListInfo TransArgs;
8733 if (Old->hasExplicitTemplateArgs()) {
8734 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8735 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008736 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8737 Old->getNumTemplateArgs(),
8738 TransArgs))
8739 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008740 }
John McCallc2233c52010-01-15 08:34:02 +00008741
8742 // FIXME: to do this check properly, we will need to preserve the
8743 // first-qualifier-in-scope here, just in case we had a dependent
8744 // base (and therefore couldn't do the check) and a
8745 // nested-name-qualifier (and therefore could do the lookup).
8746 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008747
John McCall9ae2f072010-08-23 23:25:46 +00008748 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008749 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008750 Old->getOperatorLoc(),
8751 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008752 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008753 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008754 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008755 R,
8756 (Old->hasExplicitTemplateArgs()
8757 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008758}
8759
8760template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008761ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008762TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008763 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008764 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8765 if (SubExpr.isInvalid())
8766 return ExprError();
8767
8768 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008769 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008770
8771 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8772}
8773
8774template<typename Derived>
8775ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008776TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008777 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8778 if (Pattern.isInvalid())
8779 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008780
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008781 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8782 return SemaRef.Owned(E);
8783
Douglas Gregor67fd1252011-01-14 21:20:45 +00008784 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8785 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008786}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008787
8788template<typename Derived>
8789ExprResult
8790TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8791 // If E is not value-dependent, then nothing will change when we transform it.
8792 // Note: This is an instantiation-centric view.
8793 if (!E->isValueDependent())
8794 return SemaRef.Owned(E);
8795
8796 // Note: None of the implementations of TryExpandParameterPacks can ever
8797 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier4a9d7952012-08-08 18:46:20 +00008798 // so
Douglas Gregoree8aff02011-01-04 17:33:58 +00008799 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8800 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008801 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008802 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008803 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008804 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008805 ShouldExpand, RetainExpansion,
8806 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008807 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008808
Douglas Gregor089e8932011-10-10 18:59:29 +00008809 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008810 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008811
Douglas Gregor089e8932011-10-10 18:59:29 +00008812 NamedDecl *Pack = E->getPack();
8813 if (!ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008814 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008815 Pack));
8816 if (!Pack)
8817 return ExprError();
8818 }
8819
Chad Rosier4a9d7952012-08-08 18:46:20 +00008820
Douglas Gregoree8aff02011-01-04 17:33:58 +00008821 // We now know the length of the parameter pack, so build a new expression
8822 // that stores that length.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008823 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8824 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008825 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008826}
8827
Douglas Gregorbe230c32011-01-03 17:17:50 +00008828template<typename Derived>
8829ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008830TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8831 SubstNonTypeTemplateParmPackExpr *E) {
8832 // Default behavior is to do nothing with this transformation.
8833 return SemaRef.Owned(E);
8834}
8835
8836template<typename Derived>
8837ExprResult
John McCall91a57552011-07-15 05:09:51 +00008838TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8839 SubstNonTypeTemplateParmExpr *E) {
8840 // Default behavior is to do nothing with this transformation.
8841 return SemaRef.Owned(E);
8842}
8843
8844template<typename Derived>
8845ExprResult
Richard Smith9a4db032012-09-12 00:56:43 +00008846TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8847 // Default behavior is to do nothing with this transformation.
8848 return SemaRef.Owned(E);
8849}
8850
8851template<typename Derived>
8852ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008853TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8854 MaterializeTemporaryExpr *E) {
8855 return getDerived().TransformExpr(E->GetTemporaryExpr());
8856}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008857
Douglas Gregor03e80032011-06-21 17:03:29 +00008858template<typename Derived>
8859ExprResult
Richard Smith7c3e6152013-06-12 22:31:48 +00008860TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
8861 CXXStdInitializerListExpr *E) {
8862 return getDerived().TransformExpr(E->getSubExpr());
8863}
8864
8865template<typename Derived>
8866ExprResult
John McCall454feb92009-12-08 09:21:05 +00008867TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008868 return SemaRef.MaybeBindToTemporary(E);
8869}
8870
8871template<typename Derived>
8872ExprResult
8873TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008874 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008875}
8876
8877template<typename Derived>
8878ExprResult
Patrick Beardeb382ec2012-04-19 00:25:12 +00008879TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8880 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8881 if (SubExpr.isInvalid())
8882 return ExprError();
8883
8884 if (!getDerived().AlwaysRebuild() &&
8885 SubExpr.get() == E->getSubExpr())
8886 return SemaRef.Owned(E);
8887
8888 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008889}
8890
8891template<typename Derived>
8892ExprResult
8893TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8894 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008895 SmallVector<Expr *, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008896 bool ArgChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008897 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008898 /*IsCall=*/false, Elements, &ArgChanged))
8899 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008900
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008901 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8902 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008903
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008904 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8905 Elements.data(),
8906 Elements.size());
8907}
8908
8909template<typename Derived>
8910ExprResult
8911TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008912 ObjCDictionaryLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008913 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008914 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008915 bool ArgChanged = false;
8916 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8917 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008918
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008919 if (OrigElement.isPackExpansion()) {
8920 // This key/value element is a pack expansion.
8921 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8922 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8923 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8924 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8925
8926 // Determine whether the set of unexpanded parameter packs can
8927 // and should be expanded.
8928 bool Expand = true;
8929 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008930 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8931 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008932 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8933 OrigElement.Value->getLocEnd());
8934 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8935 PatternRange,
8936 Unexpanded,
8937 Expand, RetainExpansion,
8938 NumExpansions))
8939 return ExprError();
8940
8941 if (!Expand) {
8942 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00008943 // transformation on the pack expansion, producing another pack
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008944 // expansion.
8945 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8946 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8947 if (Key.isInvalid())
8948 return ExprError();
8949
8950 if (Key.get() != OrigElement.Key)
8951 ArgChanged = true;
8952
8953 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8954 if (Value.isInvalid())
8955 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008956
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008957 if (Value.get() != OrigElement.Value)
8958 ArgChanged = true;
8959
Chad Rosier4a9d7952012-08-08 18:46:20 +00008960 ObjCDictionaryElement Expansion = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008961 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8962 };
8963 Elements.push_back(Expansion);
8964 continue;
8965 }
8966
8967 // Record right away that the argument was changed. This needs
8968 // to happen even if the array expands to nothing.
8969 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008970
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008971 // The transform has determined that we should perform an elementwise
8972 // expansion of the pattern. Do so.
8973 for (unsigned I = 0; I != *NumExpansions; ++I) {
8974 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8975 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8976 if (Key.isInvalid())
8977 return ExprError();
8978
8979 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8980 if (Value.isInvalid())
8981 return ExprError();
8982
Chad Rosier4a9d7952012-08-08 18:46:20 +00008983 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008984 Key.get(), Value.get(), SourceLocation(), NumExpansions
8985 };
8986
8987 // If any unexpanded parameter packs remain, we still have a
8988 // pack expansion.
8989 if (Key.get()->containsUnexpandedParameterPack() ||
8990 Value.get()->containsUnexpandedParameterPack())
8991 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008992
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008993 Elements.push_back(Element);
8994 }
8995
8996 // We've finished with this pack expansion.
8997 continue;
8998 }
8999
9000 // Transform and check key.
9001 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9002 if (Key.isInvalid())
9003 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009004
Ted Kremenekebcb57a2012-03-06 20:05:56 +00009005 if (Key.get() != OrigElement.Key)
9006 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00009007
Ted Kremenekebcb57a2012-03-06 20:05:56 +00009008 // Transform and check value.
9009 ExprResult Value
9010 = getDerived().TransformExpr(OrigElement.Value);
9011 if (Value.isInvalid())
9012 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009013
Ted Kremenekebcb57a2012-03-06 20:05:56 +00009014 if (Value.get() != OrigElement.Value)
9015 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00009016
9017 ObjCDictionaryElement Element = {
David Blaikie66874fb2013-02-21 01:47:18 +00009018 Key.get(), Value.get(), SourceLocation(), None
Ted Kremenekebcb57a2012-03-06 20:05:56 +00009019 };
9020 Elements.push_back(Element);
9021 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00009022
Ted Kremenekebcb57a2012-03-06 20:05:56 +00009023 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9024 return SemaRef.MaybeBindToTemporary(E);
9025
9026 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
9027 Elements.data(),
9028 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009029}
9030
Mike Stump1eb44332009-09-09 15:08:12 +00009031template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009032ExprResult
John McCall454feb92009-12-08 09:21:05 +00009033TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00009034 TypeSourceInfo *EncodedTypeInfo
9035 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
9036 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00009037 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009038
Douglas Gregorb98b1992009-08-11 05:31:07 +00009039 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00009040 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00009041 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009042
9043 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00009044 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00009045 E->getRParenLoc());
9046}
Mike Stump1eb44332009-09-09 15:08:12 +00009047
Douglas Gregorb98b1992009-08-11 05:31:07 +00009048template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00009049ExprResult TreeTransform<Derived>::
9050TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCall93b64572013-04-11 02:14:26 +00009051 // This is a kind of implicit conversion, and it needs to get dropped
9052 // and recomputed for the same general reasons that ImplicitCastExprs
9053 // do, as well a more specific one: this expression is only valid when
9054 // it appears *immediately* as an argument expression.
9055 return getDerived().TransformExpr(E->getSubExpr());
John McCallf85e1932011-06-15 23:02:42 +00009056}
9057
9058template<typename Derived>
9059ExprResult TreeTransform<Derived>::
9060TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00009061 TypeSourceInfo *TSInfo
John McCallf85e1932011-06-15 23:02:42 +00009062 = getDerived().TransformType(E->getTypeInfoAsWritten());
9063 if (!TSInfo)
9064 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009065
John McCallf85e1932011-06-15 23:02:42 +00009066 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009067 if (Result.isInvalid())
John McCallf85e1932011-06-15 23:02:42 +00009068 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009069
John McCallf85e1932011-06-15 23:02:42 +00009070 if (!getDerived().AlwaysRebuild() &&
9071 TSInfo == E->getTypeInfoAsWritten() &&
9072 Result.get() == E->getSubExpr())
9073 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009074
John McCallf85e1932011-06-15 23:02:42 +00009075 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00009076 E->getBridgeKeywordLoc(), TSInfo,
John McCallf85e1932011-06-15 23:02:42 +00009077 Result.get());
9078}
9079
9080template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009081ExprResult
John McCall454feb92009-12-08 09:21:05 +00009082TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00009083 // Transform arguments.
9084 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00009085 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00009086 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009087 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00009088 &ArgChanged))
9089 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009090
Douglas Gregor92e986e2010-04-22 16:44:27 +00009091 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
9092 // Class message: transform the receiver type.
9093 TypeSourceInfo *ReceiverTypeInfo
9094 = getDerived().TransformType(E->getClassReceiverTypeInfo());
9095 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00009096 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009097
Douglas Gregor92e986e2010-04-22 16:44:27 +00009098 // If nothing changed, just retain the existing message send.
9099 if (!getDerived().AlwaysRebuild() &&
9100 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00009101 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00009102
9103 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00009104 SmallVector<SourceLocation, 16> SelLocs;
9105 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00009106 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
9107 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00009108 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00009109 E->getMethodDecl(),
9110 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009111 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00009112 E->getRightLoc());
9113 }
9114
9115 // Instance message: transform the receiver
9116 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
9117 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00009118 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00009119 = getDerived().TransformExpr(E->getInstanceReceiver());
9120 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009121 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00009122
9123 // If nothing changed, just retain the existing message send.
9124 if (!getDerived().AlwaysRebuild() &&
9125 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00009126 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009127
Douglas Gregor92e986e2010-04-22 16:44:27 +00009128 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00009129 SmallVector<SourceLocation, 16> SelLocs;
9130 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00009131 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00009132 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00009133 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00009134 E->getMethodDecl(),
9135 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009136 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00009137 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009138}
9139
Mike Stump1eb44332009-09-09 15:08:12 +00009140template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009141ExprResult
John McCall454feb92009-12-08 09:21:05 +00009142TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00009143 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009144}
9145
Mike Stump1eb44332009-09-09 15:08:12 +00009146template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009147ExprResult
John McCall454feb92009-12-08 09:21:05 +00009148TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00009149 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009150}
9151
Mike Stump1eb44332009-09-09 15:08:12 +00009152template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009153ExprResult
John McCall454feb92009-12-08 09:21:05 +00009154TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009155 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00009156 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009157 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009158 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009159
9160 // We don't need to transform the ivar; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00009161
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009162 // If nothing changed, just retain the existing expression.
9163 if (!getDerived().AlwaysRebuild() &&
9164 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00009165 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009166
John McCall9ae2f072010-08-23 23:25:46 +00009167 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009168 E->getLocation(),
9169 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009170}
9171
Mike Stump1eb44332009-09-09 15:08:12 +00009172template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009173ExprResult
John McCall454feb92009-12-08 09:21:05 +00009174TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00009175 // 'super' and types never change. Property never changes. Just
9176 // retain the existing expression.
9177 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00009178 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009179
Douglas Gregore3303542010-04-26 20:47:02 +00009180 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00009181 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00009182 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009183 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009184
Douglas Gregore3303542010-04-26 20:47:02 +00009185 // We don't need to transform the property; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00009186
Douglas Gregore3303542010-04-26 20:47:02 +00009187 // If nothing changed, just retain the existing expression.
9188 if (!getDerived().AlwaysRebuild() &&
9189 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00009190 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009191
John McCall12f78a62010-12-02 01:19:52 +00009192 if (E->isExplicitProperty())
9193 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9194 E->getExplicitProperty(),
9195 E->getLocation());
9196
9197 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00009198 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00009199 E->getImplicitPropertyGetter(),
9200 E->getImplicitPropertySetter(),
9201 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009202}
9203
Mike Stump1eb44332009-09-09 15:08:12 +00009204template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009205ExprResult
Ted Kremenekebcb57a2012-03-06 20:05:56 +00009206TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
9207 // Transform the base expression.
9208 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9209 if (Base.isInvalid())
9210 return ExprError();
9211
9212 // Transform the key expression.
9213 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
9214 if (Key.isInvalid())
9215 return ExprError();
9216
9217 // If nothing changed, just retain the existing expression.
9218 if (!getDerived().AlwaysRebuild() &&
9219 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
9220 return SemaRef.Owned(E);
9221
Chad Rosier4a9d7952012-08-08 18:46:20 +00009222 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00009223 Base.get(), Key.get(),
9224 E->getAtIndexMethodDecl(),
9225 E->setAtIndexMethodDecl());
9226}
9227
9228template<typename Derived>
9229ExprResult
John McCall454feb92009-12-08 09:21:05 +00009230TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009231 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00009232 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009233 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009234 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009235
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009236 // If nothing changed, just retain the existing expression.
9237 if (!getDerived().AlwaysRebuild() &&
9238 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00009239 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009240
John McCall9ae2f072010-08-23 23:25:46 +00009241 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00009242 E->getOpLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009243 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009244}
9245
Mike Stump1eb44332009-09-09 15:08:12 +00009246template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009247ExprResult
John McCall454feb92009-12-08 09:21:05 +00009248TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009249 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00009250 SmallVector<Expr*, 8> SubExprs;
Douglas Gregoraa165f82011-01-03 19:04:46 +00009251 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009252 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00009253 SubExprs, &ArgumentChanged))
9254 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009255
Douglas Gregorb98b1992009-08-11 05:31:07 +00009256 if (!getDerived().AlwaysRebuild() &&
9257 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00009258 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00009259
Douglas Gregorb98b1992009-08-11 05:31:07 +00009260 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009261 SubExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00009262 E->getRParenLoc());
9263}
9264
Mike Stump1eb44332009-09-09 15:08:12 +00009265template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009266ExprResult
Hal Finkel414a1bd2013-09-18 03:29:45 +00009267TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
9268 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
9269 if (SrcExpr.isInvalid())
9270 return ExprError();
9271
9272 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9273 if (!Type)
9274 return ExprError();
9275
9276 if (!getDerived().AlwaysRebuild() &&
9277 Type == E->getTypeSourceInfo() &&
9278 SrcExpr.get() == E->getSrcExpr())
9279 return SemaRef.Owned(E);
9280
9281 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
9282 SrcExpr.get(), Type,
9283 E->getRParenLoc());
9284}
9285
9286template<typename Derived>
9287ExprResult
John McCall454feb92009-12-08 09:21:05 +00009288TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00009289 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009290
John McCallc6ac9c32011-02-04 18:33:18 +00009291 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
9292 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
9293
9294 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00009295 blockScope->TheDecl->setBlockMissingReturnType(
9296 oldBlock->blockMissingReturnType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009297
Chris Lattner686775d2011-07-20 06:58:45 +00009298 SmallVector<ParmVarDecl*, 4> params;
9299 SmallVector<QualType, 4> paramTypes;
Chad Rosier4a9d7952012-08-08 18:46:20 +00009300
Fariborz Jahaniana729da22010-07-09 18:44:02 +00009301 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00009302 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
9303 oldBlock->param_begin(),
9304 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009305 0, paramTypes, &params)) {
9306 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00009307 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009308 }
John McCallc6ac9c32011-02-04 18:33:18 +00009309
Jordan Rose09189892013-03-08 22:25:36 +00009310 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00009311 QualType exprResultType =
9312 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00009313
Jordan Rosebea522f2013-03-08 21:51:21 +00009314 QualType functionType =
9315 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rose09189892013-03-08 22:25:36 +00009316 exprFunctionType->getExtProtoInfo());
John McCallc6ac9c32011-02-04 18:33:18 +00009317 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00009318
9319 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00009320 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00009321 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00009322
9323 if (!oldBlock->blockMissingReturnType()) {
9324 blockScope->HasImplicitReturnType = false;
9325 blockScope->ReturnType = exprResultType;
9326 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00009327
John McCall711c52b2011-01-05 12:14:39 +00009328 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00009329 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009330 if (body.isInvalid()) {
9331 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00009332 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009333 }
John McCall711c52b2011-01-05 12:14:39 +00009334
John McCallc6ac9c32011-02-04 18:33:18 +00009335#ifndef NDEBUG
9336 // In builds with assertions, make sure that we captured everything we
9337 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00009338 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
9339 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
9340 e = oldBlock->capture_end(); i != e; ++i) {
9341 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00009342
Douglas Gregorfc921372011-05-20 15:32:55 +00009343 // Ignore parameter packs.
9344 if (isa<ParmVarDecl>(oldCapture) &&
9345 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9346 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00009347
Douglas Gregorfc921372011-05-20 15:32:55 +00009348 VarDecl *newCapture =
9349 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9350 oldCapture));
9351 assert(blockScope->CaptureMap.count(newCapture));
9352 }
Douglas Gregorec79d872012-02-24 17:41:38 +00009353 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00009354 }
9355#endif
9356
9357 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
9358 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009359}
9360
Mike Stump1eb44332009-09-09 15:08:12 +00009361template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009362ExprResult
Tanya Lattner61eee0c2011-06-04 00:47:47 +00009363TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00009364 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00009365}
Eli Friedman276b0612011-10-11 02:20:01 +00009366
9367template<typename Derived>
9368ExprResult
9369TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009370 QualType RetTy = getDerived().TransformType(E->getType());
9371 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00009372 SmallVector<Expr*, 8> SubExprs;
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009373 SubExprs.reserve(E->getNumSubExprs());
9374 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9375 SubExprs, &ArgumentChanged))
9376 return ExprError();
9377
9378 if (!getDerived().AlwaysRebuild() &&
9379 !ArgumentChanged)
9380 return SemaRef.Owned(E);
9381
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009382 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009383 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00009384}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009385
Douglas Gregorb98b1992009-08-11 05:31:07 +00009386//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00009387// Type reconstruction
9388//===----------------------------------------------------------------------===//
9389
Mike Stump1eb44332009-09-09 15:08:12 +00009390template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00009391QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9392 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00009393 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009394 getDerived().getBaseEntity());
9395}
9396
Mike Stump1eb44332009-09-09 15:08:12 +00009397template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00009398QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9399 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00009400 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009401 getDerived().getBaseEntity());
9402}
9403
Mike Stump1eb44332009-09-09 15:08:12 +00009404template<typename Derived>
9405QualType
John McCall85737a72009-10-30 00:06:24 +00009406TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9407 bool WrittenAsLValue,
9408 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00009409 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00009410 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009411}
9412
9413template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009414QualType
John McCall85737a72009-10-30 00:06:24 +00009415TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9416 QualType ClassType,
9417 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00009418 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00009419 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009420}
9421
9422template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009423QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00009424TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9425 ArrayType::ArraySizeModifier SizeMod,
9426 const llvm::APInt *Size,
9427 Expr *SizeExpr,
9428 unsigned IndexTypeQuals,
9429 SourceRange BracketsRange) {
9430 if (SizeExpr || !Size)
9431 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9432 IndexTypeQuals, BracketsRange,
9433 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00009434
9435 QualType Types[] = {
9436 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9437 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9438 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00009439 };
Craig Topperb9602322013-07-15 03:38:40 +00009440 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009441 QualType SizeType;
9442 for (unsigned I = 0; I != NumTypes; ++I)
9443 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9444 SizeType = Types[I];
9445 break;
9446 }
Mike Stump1eb44332009-09-09 15:08:12 +00009447
Eli Friedman01f276d2012-01-25 23:20:27 +00009448 // Note that we can return a VariableArrayType here in the case where
9449 // the element type was a dependent VariableArrayType.
9450 IntegerLiteral *ArraySize
9451 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9452 /*FIXME*/BracketsRange.getBegin());
9453 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009454 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00009455 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009456}
Mike Stump1eb44332009-09-09 15:08:12 +00009457
Douglas Gregor577f75a2009-08-04 16:50:30 +00009458template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009459QualType
9460TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009461 ArrayType::ArraySizeModifier SizeMod,
9462 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00009463 unsigned IndexTypeQuals,
9464 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009465 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00009466 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009467}
9468
9469template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009470QualType
Mike Stump1eb44332009-09-09 15:08:12 +00009471TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009472 ArrayType::ArraySizeModifier SizeMod,
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, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00009476 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009477}
Mike Stump1eb44332009-09-09 15:08:12 +00009478
Douglas Gregor577f75a2009-08-04 16:50:30 +00009479template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009480QualType
9481TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009482 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009483 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009484 unsigned IndexTypeQuals,
9485 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009486 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009487 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009488 IndexTypeQuals, BracketsRange);
9489}
9490
9491template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009492QualType
9493TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009494 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009495 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009496 unsigned IndexTypeQuals,
9497 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009498 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009499 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009500 IndexTypeQuals, BracketsRange);
9501}
9502
9503template<typename Derived>
9504QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00009505 unsigned NumElements,
9506 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00009507 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00009508 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009509}
Mike Stump1eb44332009-09-09 15:08:12 +00009510
Douglas Gregor577f75a2009-08-04 16:50:30 +00009511template<typename Derived>
9512QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9513 unsigned NumElements,
9514 SourceLocation AttributeLoc) {
9515 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9516 NumElements, true);
9517 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00009518 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9519 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00009520 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009521}
Mike Stump1eb44332009-09-09 15:08:12 +00009522
Douglas Gregor577f75a2009-08-04 16:50:30 +00009523template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009524QualType
9525TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00009526 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009527 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00009528 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009529}
Mike Stump1eb44332009-09-09 15:08:12 +00009530
Douglas Gregor577f75a2009-08-04 16:50:30 +00009531template<typename Derived>
Jordan Rosebea522f2013-03-08 21:51:21 +00009532QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9533 QualType T,
9534 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00009535 const FunctionProtoType::ExtProtoInfo &EPI) {
9536 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009537 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00009538 getDerived().getBaseEntity(),
Jordan Rose09189892013-03-08 22:25:36 +00009539 EPI);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009540}
Mike Stump1eb44332009-09-09 15:08:12 +00009541
Douglas Gregor577f75a2009-08-04 16:50:30 +00009542template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00009543QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9544 return SemaRef.Context.getFunctionNoProtoType(T);
9545}
9546
9547template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00009548QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9549 assert(D && "no decl found");
9550 if (D->isInvalidDecl()) return QualType();
9551
Douglas Gregor92e986e2010-04-22 16:44:27 +00009552 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00009553 TypeDecl *Ty;
9554 if (isa<UsingDecl>(D)) {
9555 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanella8d030c72013-07-22 10:54:09 +00009556 assert(Using->hasTypename() &&
John McCalled976492009-12-04 22:46:56 +00009557 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9558
9559 // A valid resolved using typename decl points to exactly one type decl.
9560 assert(++Using->shadow_begin() == Using->shadow_end());
9561 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009562
John McCalled976492009-12-04 22:46:56 +00009563 } else {
9564 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9565 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9566 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9567 }
9568
9569 return SemaRef.Context.getTypeDeclType(Ty);
9570}
9571
9572template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009573QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9574 SourceLocation Loc) {
9575 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009576}
9577
9578template<typename Derived>
9579QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9580 return SemaRef.Context.getTypeOfType(Underlying);
9581}
9582
9583template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009584QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9585 SourceLocation Loc) {
9586 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009587}
9588
9589template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009590QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9591 UnaryTransformType::UTTKind UKind,
9592 SourceLocation Loc) {
9593 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9594}
9595
9596template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009597QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009598 TemplateName Template,
9599 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009600 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009601 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009602}
Mike Stump1eb44332009-09-09 15:08:12 +00009603
Douglas Gregordcee1a12009-08-06 05:28:30 +00009604template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009605QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9606 SourceLocation KWLoc) {
9607 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9608}
9609
9610template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009611TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009612TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009613 bool TemplateKW,
9614 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009615 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009616 Template);
9617}
9618
9619template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009620TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009621TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9622 const IdentifierInfo &Name,
9623 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009624 QualType ObjectType,
9625 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009626 UnqualifiedId TemplateName;
9627 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009628 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009629 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009630 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009631 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009632 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009633 /*EnteringContext=*/false,
9634 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009635 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009636}
Mike Stump1eb44332009-09-09 15:08:12 +00009637
Douglas Gregorb98b1992009-08-11 05:31:07 +00009638template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009639TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009640TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009641 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009642 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009643 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009644 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009645 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009646 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009647 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009648 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009649 Sema::TemplateTy Template;
9650 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009651 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009652 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009653 /*EnteringContext=*/false,
9654 Template);
Serge Pavlov18062392013-08-27 13:15:56 +00009655 return Template.get();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009656}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009657
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009658template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009659ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009660TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9661 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009662 Expr *OrigCallee,
9663 Expr *First,
9664 Expr *Second) {
9665 Expr *Callee = OrigCallee->IgnoreParenCasts();
9666 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009667
Douglas Gregorb98b1992009-08-11 05:31:07 +00009668 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009669 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009670 if (!First->getType()->isOverloadableType() &&
9671 !Second->getType()->isOverloadableType())
9672 return getSema().CreateBuiltinArraySubscriptExpr(First,
9673 Callee->getLocStart(),
9674 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009675 } else if (Op == OO_Arrow) {
9676 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009677 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9678 } else if (Second == 0 || isPostIncDec) {
9679 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009680 // The argument is not of overloadable type, so try to create a
9681 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009682 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009683 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009684
John McCall9ae2f072010-08-23 23:25:46 +00009685 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009686 }
9687 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009688 if (!First->getType()->isOverloadableType() &&
9689 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009690 // Neither of the arguments is an overloadable type, so try to
9691 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009692 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009693 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009694 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009695 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009696 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009697
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009698 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009699 }
9700 }
Mike Stump1eb44332009-09-09 15:08:12 +00009701
9702 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009703 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009704 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009705
John McCall9ae2f072010-08-23 23:25:46 +00009706 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009707 assert(ULE->requiresADL());
9708
9709 // FIXME: Do we have to check
9710 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009711 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009712 } else {
Richard Smithf6411662012-11-28 21:47:39 +00009713 // If we've resolved this to a particular non-member function, just call
9714 // that function. If we resolved it to a member function,
9715 // CreateOverloaded* will find that function for us.
9716 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9717 if (!isa<CXXMethodDecl>(ND))
9718 Functions.addDecl(ND);
John McCallba135432009-11-21 08:51:07 +00009719 }
Mike Stump1eb44332009-09-09 15:08:12 +00009720
Douglas Gregorb98b1992009-08-11 05:31:07 +00009721 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009722 Expr *Args[2] = { First, Second };
9723 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009724
Douglas Gregorb98b1992009-08-11 05:31:07 +00009725 // Create the overloaded operator invocation for unary operators.
9726 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009727 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009728 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009729 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009730 }
Mike Stump1eb44332009-09-09 15:08:12 +00009731
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009732 if (Op == OO_Subscript) {
9733 SourceLocation LBrace;
9734 SourceLocation RBrace;
9735
9736 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9737 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9738 LBrace = SourceLocation::getFromRawEncoding(
9739 NameLoc.CXXOperatorName.BeginOpNameLoc);
9740 RBrace = SourceLocation::getFromRawEncoding(
9741 NameLoc.CXXOperatorName.EndOpNameLoc);
9742 } else {
9743 LBrace = Callee->getLocStart();
9744 RBrace = OpLoc;
9745 }
9746
9747 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9748 First, Second);
9749 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009750
Douglas Gregorb98b1992009-08-11 05:31:07 +00009751 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009752 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009753 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009754 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9755 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009756 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009757
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009758 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009759}
Mike Stump1eb44332009-09-09 15:08:12 +00009760
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009761template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00009762ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009763TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009764 SourceLocation OperatorLoc,
9765 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009766 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009767 TypeSourceInfo *ScopeType,
9768 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009769 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009770 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009771 QualType BaseType = Base->getType();
9772 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009773 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00009774 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009775 !BaseType->getAs<PointerType>()->getPointeeType()
9776 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009777 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009778 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009779 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009780 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009781 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009782 /*FIXME?*/true);
9783 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009784
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009785 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009786 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9787 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9788 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9789 NameInfo.setNamedTypeInfo(DestroyedType);
9790
Richard Smith6314db92012-05-15 06:15:11 +00009791 // The scope type is now known to be a valid nested name specifier
9792 // component. Tack it on to the end of the nested name specifier.
9793 if (ScopeType)
9794 SS.Extend(SemaRef.Context, SourceLocation(),
9795 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnara25777432010-08-11 22:01:17 +00009796
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009797 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009798 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009799 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009800 SS, TemplateKWLoc,
9801 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009802 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009803 /*TemplateArgs*/ 0);
9804}
9805
Tareq A. Siraj051303c2013-04-16 18:53:08 +00009806template<typename Derived>
9807StmtResult
9808TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan9fd6b8f2013-05-04 03:59:06 +00009809 SourceLocation Loc = S->getLocStart();
9810 unsigned NumParams = S->getCapturedDecl()->getNumParams();
9811 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/0,
9812 S->getCapturedRegionKind(), NumParams);
9813 StmtResult Body = getDerived().TransformStmt(S->getCapturedStmt());
9814
9815 if (Body.isInvalid()) {
9816 getSema().ActOnCapturedRegionError();
9817 return StmtError();
9818 }
9819
9820 return getSema().ActOnCapturedRegionEnd(Body.take());
Tareq A. Siraj051303c2013-04-16 18:53:08 +00009821}
9822
Douglas Gregor577f75a2009-08-04 16:50:30 +00009823} // end namespace clang
9824
9825#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H