blob: b91c73b075be6466686be09094b8c33d546b4d50 [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
John Wiegley28bbe4b2011-04-28 01:08:34 +0000547 StmtResult
548 TransformSEHHandler(Stmt *Handler);
549
Chad Rosier4a9d7952012-08-08 18:46:20 +0000550 QualType
John McCall43fed0d2010-11-12 08:19:04 +0000551 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
552 TemplateSpecializationTypeLoc TL,
553 TemplateName Template);
554
Chad Rosier4a9d7952012-08-08 18:46:20 +0000555 QualType
John McCall43fed0d2010-11-12 08:19:04 +0000556 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
557 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +0000558 TemplateName Template,
559 CXXScopeSpec &SS);
Douglas Gregora88f09f2011-02-28 17:23:35 +0000560
Chad Rosier4a9d7952012-08-08 18:46:20 +0000561 QualType
Douglas Gregora88f09f2011-02-28 17:23:35 +0000562 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000563 DependentTemplateSpecializationTypeLoc TL,
564 NestedNameSpecifierLoc QualifierLoc);
565
John McCall21ef0fa2010-03-11 09:03:00 +0000566 /// \brief Transforms the parameters of a function type into the
567 /// given vectors.
568 ///
569 /// The result vectors should be kept in sync; null entries in the
570 /// variables vector are acceptable.
571 ///
572 /// Return true on error.
Douglas Gregora009b592011-01-07 00:20:55 +0000573 bool TransformFunctionTypeParams(SourceLocation Loc,
574 ParmVarDecl **Params, unsigned NumParams,
575 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +0000576 SmallVectorImpl<QualType> &PTypes,
577 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall21ef0fa2010-03-11 09:03:00 +0000578
579 /// \brief Transforms a single function-type parameter. Return null
580 /// on error.
John McCallfb44de92011-05-01 22:35:37 +0000581 ///
582 /// \param indexAdjustment - A number to add to the parameter's
583 /// scope index; can be negative
Douglas Gregor6a24bfd2011-01-14 22:40:04 +0000584 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +0000585 int indexAdjustment,
David Blaikiedc84cd52013-02-20 22:23:23 +0000586 Optional<unsigned> NumExpansions,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +0000587 bool ExpectParameterPack);
John McCall21ef0fa2010-03-11 09:03:00 +0000588
John McCall43fed0d2010-11-12 08:19:04 +0000589 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall833ca992009-10-29 08:12:44 +0000590
John McCall60d7b3a2010-08-24 06:29:42 +0000591 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
592 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000593
Richard Smith612409e2012-07-25 03:56:55 +0000594 /// \brief Transform the captures and body of a lambda expression.
595 ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator);
596
Richard Smithefeeccf2012-10-21 03:28:35 +0000597 ExprResult TransformAddressOfOperand(Expr *E);
598 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
599 bool IsAddressOfOperand);
600
Eli Friedman1ac6c932013-09-06 01:13:30 +0000601// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
602// amount of stack usage with clang.
Douglas Gregor43959a92009-08-20 07:17:43 +0000603#define STMT(Node, Parent) \
Eli Friedman1ac6c932013-09-06 01:13:30 +0000604 LLVM_ATTRIBUTE_NOINLINE \
John McCall60d7b3a2010-08-24 06:29:42 +0000605 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000606#define EXPR(Node, Parent) \
Eli Friedman1ac6c932013-09-06 01:13:30 +0000607 LLVM_ATTRIBUTE_NOINLINE \
John McCall60d7b3a2010-08-24 06:29:42 +0000608 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000609#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000610#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000611
Alexey Bataev4fa7eab2013-07-19 03:13:43 +0000612#define OPENMP_CLAUSE(Name, Class) \
Eli Friedman1ac6c932013-09-06 01:13:30 +0000613 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev4fa7eab2013-07-19 03:13:43 +0000614 OMPClause *Transform ## Class(Class *S);
615#include "clang/Basic/OpenMPKinds.def"
616
Douglas Gregor577f75a2009-08-04 16:50:30 +0000617 /// \brief Build a new pointer type given its pointee type.
618 ///
619 /// By default, performs semantic analysis when building the pointer type.
620 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000621 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000622
623 /// \brief Build a new block pointer type given its pointee type.
624 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000625 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000626 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000627 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000628
John McCall85737a72009-10-30 00:06:24 +0000629 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000630 ///
John McCall85737a72009-10-30 00:06:24 +0000631 /// By default, performs semantic analysis when building the
632 /// reference type. Subclasses may override this routine to provide
633 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000634 ///
John McCall85737a72009-10-30 00:06:24 +0000635 /// \param LValue whether the type was written with an lvalue sigil
636 /// or an rvalue sigil.
637 QualType RebuildReferenceType(QualType ReferentType,
638 bool LValue,
639 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000640
Douglas Gregor577f75a2009-08-04 16:50:30 +0000641 /// \brief Build a new member pointer type given the pointee type and the
642 /// class type it refers into.
643 ///
644 /// By default, performs semantic analysis when building the member pointer
645 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000646 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
647 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000648
Douglas Gregor577f75a2009-08-04 16:50:30 +0000649 /// \brief Build a new array type given the element type, size
650 /// modifier, size of the array (if known), size expression, and index type
651 /// qualifiers.
652 ///
653 /// By default, performs semantic analysis when building the array type.
654 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000655 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000656 QualType RebuildArrayType(QualType ElementType,
657 ArrayType::ArraySizeModifier SizeMod,
658 const llvm::APInt *Size,
659 Expr *SizeExpr,
660 unsigned IndexTypeQuals,
661 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000662
Douglas Gregor577f75a2009-08-04 16:50:30 +0000663 /// \brief Build a new constant array type given the element type, size
664 /// modifier, (known) size of the array, and index type qualifiers.
665 ///
666 /// By default, performs semantic analysis when building the array type.
667 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000668 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000669 ArrayType::ArraySizeModifier SizeMod,
670 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000671 unsigned IndexTypeQuals,
672 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000673
Douglas Gregor577f75a2009-08-04 16:50:30 +0000674 /// \brief Build a new incomplete array type given the element type, size
675 /// modifier, and index type qualifiers.
676 ///
677 /// By default, performs semantic analysis when building the array type.
678 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000679 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000680 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000681 unsigned IndexTypeQuals,
682 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000683
Mike Stump1eb44332009-09-09 15:08:12 +0000684 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000685 /// size modifier, size expression, and index type qualifiers.
686 ///
687 /// By default, performs semantic analysis when building the array type.
688 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000689 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000690 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000691 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000692 unsigned IndexTypeQuals,
693 SourceRange BracketsRange);
694
Mike Stump1eb44332009-09-09 15:08:12 +0000695 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000696 /// size modifier, size expression, and index type qualifiers.
697 ///
698 /// By default, performs semantic analysis when building the array type.
699 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000700 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000701 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000702 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000703 unsigned IndexTypeQuals,
704 SourceRange BracketsRange);
705
706 /// \brief Build a new vector type given the element type and
707 /// number of elements.
708 ///
709 /// By default, performs semantic analysis when building the vector type.
710 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000711 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000712 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000713
Douglas Gregor577f75a2009-08-04 16:50:30 +0000714 /// \brief Build a new extended vector type given the element type and
715 /// number of elements.
716 ///
717 /// By default, performs semantic analysis when building the vector type.
718 /// Subclasses may override this routine to provide different behavior.
719 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
720 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000721
722 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000723 /// given the element type and number of elements.
724 ///
725 /// By default, performs semantic analysis when building the vector type.
726 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000727 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000728 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000729 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000730
Douglas Gregor577f75a2009-08-04 16:50:30 +0000731 /// \brief Build a new function type.
732 ///
733 /// By default, performs semantic analysis when building the function type.
734 /// Subclasses may override this routine to provide different behavior.
735 QualType RebuildFunctionProtoType(QualType T,
Jordan Rosebea522f2013-03-08 21:51:21 +0000736 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +0000737 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump1eb44332009-09-09 15:08:12 +0000738
John McCalla2becad2009-10-21 00:40:46 +0000739 /// \brief Build a new unprototyped function type.
740 QualType RebuildFunctionNoProtoType(QualType ResultType);
741
John McCalled976492009-12-04 22:46:56 +0000742 /// \brief Rebuild an unresolved typename type, given the decl that
743 /// the UnresolvedUsingTypenameDecl was transformed to.
744 QualType RebuildUnresolvedUsingType(Decl *D);
745
Douglas Gregor577f75a2009-08-04 16:50:30 +0000746 /// \brief Build a new typedef type.
Richard Smith162e1c12011-04-15 14:24:37 +0000747 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregor577f75a2009-08-04 16:50:30 +0000748 return SemaRef.Context.getTypeDeclType(Typedef);
749 }
750
751 /// \brief Build a new class/struct/union type.
752 QualType RebuildRecordType(RecordDecl *Record) {
753 return SemaRef.Context.getTypeDeclType(Record);
754 }
755
756 /// \brief Build a new Enum type.
757 QualType RebuildEnumType(EnumDecl *Enum) {
758 return SemaRef.Context.getTypeDeclType(Enum);
759 }
John McCall7da24312009-09-05 00:15:47 +0000760
Mike Stump1eb44332009-09-09 15:08:12 +0000761 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000762 ///
763 /// By default, performs semantic analysis when building the typeof type.
764 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000765 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000766
Mike Stump1eb44332009-09-09 15:08:12 +0000767 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000768 ///
769 /// By default, builds a new TypeOfType with the given underlying type.
770 QualType RebuildTypeOfType(QualType Underlying);
771
Sean Huntca63c202011-05-24 22:41:36 +0000772 /// \brief Build a new unary transform type.
773 QualType RebuildUnaryTransformType(QualType BaseType,
774 UnaryTransformType::UTTKind UKind,
775 SourceLocation Loc);
776
Richard Smitha2c36462013-04-26 16:15:35 +0000777 /// \brief Build a new C++11 decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000778 ///
779 /// By default, performs semantic analysis when building the decltype type.
780 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000781 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000782
Richard Smitha2c36462013-04-26 16:15:35 +0000783 /// \brief Build a new C++11 auto type.
Richard Smith34b41d92011-02-20 03:19:35 +0000784 ///
785 /// By default, builds a new AutoType with the given deduced type.
Richard Smitha2c36462013-04-26 16:15:35 +0000786 QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) {
Richard Smithdc7a4f52013-04-30 13:56:41 +0000787 // Note, IsDependent is always false here: we implicitly convert an 'auto'
788 // which has been deduced to a dependent type into an undeduced 'auto', so
789 // that we'll retry deduction after the transformation.
Manuel Klimek152b4e42013-08-22 12:12:24 +0000790 return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto);
Richard Smith34b41d92011-02-20 03:19:35 +0000791 }
792
Douglas Gregor577f75a2009-08-04 16:50:30 +0000793 /// \brief Build a new template specialization type.
794 ///
795 /// By default, performs semantic analysis when building the template
796 /// specialization type. Subclasses may override this routine to provide
797 /// different behavior.
798 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000799 SourceLocation TemplateLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000800 TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000801
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000802 /// \brief Build a new parenthesized type.
803 ///
804 /// By default, builds a new ParenType type from the inner type.
805 /// Subclasses may override this routine to provide different behavior.
806 QualType RebuildParenType(QualType InnerType) {
807 return SemaRef.Context.getParenType(InnerType);
808 }
809
Douglas Gregor577f75a2009-08-04 16:50:30 +0000810 /// \brief Build a new qualified name type.
811 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000812 /// By default, builds a new ElaboratedType type from the keyword,
813 /// the nested-name-specifier and the named type.
814 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000815 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
816 ElaboratedTypeKeyword Keyword,
Douglas Gregor9e876872011-03-01 18:12:44 +0000817 NestedNameSpecifierLoc QualifierLoc,
818 QualType Named) {
Chad Rosier4a9d7952012-08-08 18:46:20 +0000819 return SemaRef.Context.getElaboratedType(Keyword,
820 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor9e876872011-03-01 18:12:44 +0000821 Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000822 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000823
824 /// \brief Build a new typename type that refers to a template-id.
825 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000826 /// By default, builds a new DependentNameType type from the
827 /// nested-name-specifier and the given type. Subclasses may override
828 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000829 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000830 ElaboratedTypeKeyword Keyword,
831 NestedNameSpecifierLoc QualifierLoc,
832 const IdentifierInfo *Name,
833 SourceLocation NameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000834 TemplateArgumentListInfo &Args) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000835 // Rebuild the template name.
836 // TODO: avoid TemplateName abstraction
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000837 CXXScopeSpec SS;
838 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000839 TemplateName InstName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000840 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000841
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000842 if (InstName.isNull())
843 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000844
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000845 // If it's still dependent, make a dependent specialization.
846 if (InstName.getAsDependentTemplateName())
Chad Rosier4a9d7952012-08-08 18:46:20 +0000847 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
848 QualifierLoc.getNestedNameSpecifier(),
849 Name,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000850 Args);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000851
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000852 // Otherwise, make an elaborated type wrapping a non-dependent
853 // specialization.
854 QualType T =
855 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
856 if (T.isNull()) return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000857
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000858 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
859 return T;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000860
861 return SemaRef.Context.getElaboratedType(Keyword,
862 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000863 T);
864 }
865
Douglas Gregor577f75a2009-08-04 16:50:30 +0000866 /// \brief Build a new typename type that refers to an identifier.
867 ///
868 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000869 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000870 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000871 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000872 SourceLocation KeywordLoc,
Douglas Gregor2494dd02011-03-01 01:34:45 +0000873 NestedNameSpecifierLoc QualifierLoc,
874 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000875 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000876 CXXScopeSpec SS;
Douglas Gregor2494dd02011-03-01 01:34:45 +0000877 SS.Adopt(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000878
Douglas Gregor2494dd02011-03-01 01:34:45 +0000879 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000880 // If the name is still dependent, just build a new dependent name type.
881 if (!SemaRef.computeDeclContext(SS))
Chad Rosier4a9d7952012-08-08 18:46:20 +0000882 return SemaRef.Context.getDependentNameType(Keyword,
883 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000884 Id);
Douglas Gregor40336422010-03-31 22:19:08 +0000885 }
886
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000887 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor2494dd02011-03-01 01:34:45 +0000888 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregore29425b2011-02-28 22:42:13 +0000889 *Id, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000890
891 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
892
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000893 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000894 // into a non-dependent elaborated-type-specifier. Find the tag we're
895 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000896 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000897 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
898 if (!DC)
899 return QualType();
900
John McCall56138762010-05-27 06:40:31 +0000901 if (SemaRef.RequireCompleteDeclContext(SS, DC))
902 return QualType();
903
Douglas Gregor40336422010-03-31 22:19:08 +0000904 TagDecl *Tag = 0;
905 SemaRef.LookupQualifiedName(Result, DC);
906 switch (Result.getResultKind()) {
907 case LookupResult::NotFound:
908 case LookupResult::NotFoundInCurrentInstantiation:
909 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000910
Douglas Gregor40336422010-03-31 22:19:08 +0000911 case LookupResult::Found:
912 Tag = Result.getAsSingle<TagDecl>();
913 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000914
Douglas Gregor40336422010-03-31 22:19:08 +0000915 case LookupResult::FoundOverloaded:
916 case LookupResult::FoundUnresolvedValue:
917 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier4a9d7952012-08-08 18:46:20 +0000918
Douglas Gregor40336422010-03-31 22:19:08 +0000919 case LookupResult::Ambiguous:
920 // Let the LookupResult structure handle ambiguities.
921 return QualType();
922 }
923
924 if (!Tag) {
Nick Lewycky446e4022011-01-24 19:01:04 +0000925 // Check where the name exists but isn't a tag type and use that to emit
926 // better diagnostics.
927 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
928 SemaRef.LookupQualifiedName(Result, DC);
929 switch (Result.getResultKind()) {
930 case LookupResult::Found:
931 case LookupResult::FoundOverloaded:
932 case LookupResult::FoundUnresolvedValue: {
Richard Smith3e4c6c42011-05-05 21:57:07 +0000933 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky446e4022011-01-24 19:01:04 +0000934 unsigned Kind = 0;
935 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smith162e1c12011-04-15 14:24:37 +0000936 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
937 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky446e4022011-01-24 19:01:04 +0000938 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
939 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
940 break;
Richard Smith3e4c6c42011-05-05 21:57:07 +0000941 }
Nick Lewycky446e4022011-01-24 19:01:04 +0000942 default:
943 // FIXME: Would be nice to highlight just the source range.
944 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
945 << Kind << Id << DC;
946 break;
947 }
Douglas Gregor40336422010-03-31 22:19:08 +0000948 return QualType();
949 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000950
Richard Trieubbf34c02011-06-10 03:11:26 +0000951 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
952 IdLoc, *Id)) {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000953 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000954 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
955 return QualType();
956 }
957
958 // Build the elaborated-type-specifier type.
959 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000960 return SemaRef.Context.getElaboratedType(Keyword,
961 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000962 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000963 }
Mike Stump1eb44332009-09-09 15:08:12 +0000964
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000965 /// \brief Build a new pack expansion type.
966 ///
967 /// By default, builds a new PackExpansionType type from the given pattern.
968 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000969 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000970 SourceRange PatternRange,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000971 SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +0000972 Optional<unsigned> NumExpansions) {
Douglas Gregorcded4f62011-01-14 17:04:44 +0000973 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
974 NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000975 }
976
Eli Friedmanb001de72011-10-06 23:00:33 +0000977 /// \brief Build a new atomic type given its value type.
978 ///
979 /// By default, performs semantic analysis when building the atomic type.
980 /// Subclasses may override this routine to provide different behavior.
981 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
982
Douglas Gregord1067e52009-08-06 06:41:21 +0000983 /// \brief Build a new template name given a nested name specifier, a flag
984 /// indicating whether the "template" keyword was provided, and the template
985 /// that the template name refers to.
986 ///
987 /// By default, builds the new template name directly. Subclasses may override
988 /// this routine to provide different behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000989 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +0000990 bool TemplateKW,
991 TemplateDecl *Template);
992
Douglas Gregord1067e52009-08-06 06:41:21 +0000993 /// \brief Build a new template name given a nested name specifier and the
994 /// name that is referred to as a template.
995 ///
996 /// By default, performs semantic analysis to determine whether the name can
997 /// be resolved to a specific template, then builds the appropriate kind of
998 /// template name. Subclasses may override this routine to provide different
999 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00001000 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1001 const IdentifierInfo &Name,
1002 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00001003 QualType ObjectType,
1004 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +00001005
Douglas Gregorca1bdd72009-11-04 00:56:37 +00001006 /// \brief Build a new template name given a nested name specifier and the
1007 /// overloaded operator name that is referred to as a template.
1008 ///
1009 /// By default, performs semantic analysis to determine whether the name can
1010 /// be resolved to a specific template, then builds the appropriate kind of
1011 /// template name. Subclasses may override this routine to provide different
1012 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00001013 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00001014 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00001015 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00001016 QualType ObjectType);
Douglas Gregor1aee05d2011-01-15 06:45:20 +00001017
1018 /// \brief Build a new template name given a template template parameter pack
Chad Rosier4a9d7952012-08-08 18:46:20 +00001019 /// and the
Douglas Gregor1aee05d2011-01-15 06:45:20 +00001020 ///
1021 /// By default, performs semantic analysis to determine whether the name can
1022 /// be resolved to a specific template, then builds the appropriate kind of
1023 /// template name. Subclasses may override this routine to provide different
1024 /// behavior.
1025 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1026 const TemplateArgument &ArgPack) {
1027 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1028 }
1029
Douglas Gregor43959a92009-08-20 07:17:43 +00001030 /// \brief Build a new compound statement.
1031 ///
1032 /// By default, performs semantic analysis to build the new statement.
1033 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001034 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001035 MultiStmtArg Statements,
1036 SourceLocation RBraceLoc,
1037 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +00001038 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00001039 IsStmtExpr);
1040 }
1041
1042 /// \brief Build a new case statement.
1043 ///
1044 /// By default, performs semantic analysis to build the new statement.
1045 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001046 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001047 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001048 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001049 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001050 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001051 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001052 ColonLoc);
1053 }
Mike Stump1eb44332009-09-09 15:08:12 +00001054
Douglas Gregor43959a92009-08-20 07:17:43 +00001055 /// \brief Attach the body to a new case statement.
1056 ///
1057 /// By default, performs semantic analysis to build the new statement.
1058 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001059 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001060 getSema().ActOnCaseStmtBody(S, Body);
1061 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +00001062 }
Mike Stump1eb44332009-09-09 15:08:12 +00001063
Douglas Gregor43959a92009-08-20 07:17:43 +00001064 /// \brief Build a new default statement.
1065 ///
1066 /// By default, performs semantic analysis to build the new statement.
1067 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001068 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001069 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001070 Stmt *SubStmt) {
1071 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +00001072 /*CurScope=*/0);
1073 }
Mike Stump1eb44332009-09-09 15:08:12 +00001074
Douglas Gregor43959a92009-08-20 07:17:43 +00001075 /// \brief Build a new label statement.
1076 ///
1077 /// By default, performs semantic analysis to build the new statement.
1078 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001079 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1080 SourceLocation ColonLoc, Stmt *SubStmt) {
1081 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregor43959a92009-08-20 07:17:43 +00001082 }
Mike Stump1eb44332009-09-09 15:08:12 +00001083
Richard Smith534986f2012-04-14 00:33:13 +00001084 /// \brief Build a new label statement.
1085 ///
1086 /// By default, performs semantic analysis to build the new statement.
1087 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko49908902012-07-09 10:04:07 +00001088 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1089 ArrayRef<const Attr*> Attrs,
Richard Smith534986f2012-04-14 00:33:13 +00001090 Stmt *SubStmt) {
1091 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1092 }
1093
Douglas Gregor43959a92009-08-20 07:17:43 +00001094 /// \brief Build a new "if" statement.
1095 ///
1096 /// By default, performs semantic analysis to build the new statement.
1097 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001098 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001099 VarDecl *CondVar, Stmt *Then,
Chris Lattner57ad3782011-02-17 20:34:02 +00001100 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001101 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +00001102 }
Mike Stump1eb44332009-09-09 15:08:12 +00001103
Douglas Gregor43959a92009-08-20 07:17:43 +00001104 /// \brief Start building a new switch statement.
1105 ///
1106 /// By default, performs semantic analysis to build the new statement.
1107 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001108 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001109 Expr *Cond, VarDecl *CondVar) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001110 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001111 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001112 }
Mike Stump1eb44332009-09-09 15:08:12 +00001113
Douglas Gregor43959a92009-08-20 07:17:43 +00001114 /// \brief Attach the body to the switch statement.
1115 ///
1116 /// By default, performs semantic analysis to build the new statement.
1117 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001118 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001119 Stmt *Switch, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001120 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001121 }
1122
1123 /// \brief Build a new while statement.
1124 ///
1125 /// By default, performs semantic analysis to build the new statement.
1126 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001127 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1128 VarDecl *CondVar, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001129 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001130 }
Mike Stump1eb44332009-09-09 15:08:12 +00001131
Douglas Gregor43959a92009-08-20 07:17:43 +00001132 /// \brief Build a new do-while statement.
1133 ///
1134 /// By default, performs semantic analysis to build the new statement.
1135 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001136 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001137 SourceLocation WhileLoc, SourceLocation LParenLoc,
1138 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001139 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1140 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001141 }
1142
1143 /// \brief Build a new for statement.
1144 ///
1145 /// By default, performs semantic analysis to build the new statement.
1146 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001147 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001148 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001149 VarDecl *CondVar, Sema::FullExprArg Inc,
1150 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001151 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001152 CondVar, Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001153 }
Mike Stump1eb44332009-09-09 15:08:12 +00001154
Douglas Gregor43959a92009-08-20 07:17:43 +00001155 /// \brief Build a new goto statement.
1156 ///
1157 /// By default, performs semantic analysis to build the new statement.
1158 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001159 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1160 LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001161 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregor43959a92009-08-20 07:17:43 +00001162 }
1163
1164 /// \brief Build a new indirect goto statement.
1165 ///
1166 /// By default, performs semantic analysis to build the new statement.
1167 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001168 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001169 SourceLocation StarLoc,
1170 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001171 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001172 }
Mike Stump1eb44332009-09-09 15:08:12 +00001173
Douglas Gregor43959a92009-08-20 07:17:43 +00001174 /// \brief Build a new return statement.
1175 ///
1176 /// By default, performs semantic analysis to build the new statement.
1177 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001178 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001179 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001180 }
Mike Stump1eb44332009-09-09 15:08:12 +00001181
Douglas Gregor43959a92009-08-20 07:17:43 +00001182 /// \brief Build a new declaration statement.
1183 ///
1184 /// By default, performs semantic analysis to build the new statement.
1185 /// Subclasses may override this routine to provide different behavior.
Rafael Espindola4549d7f2013-07-09 12:05:01 +00001186 StmtResult RebuildDeclStmt(llvm::MutableArrayRef<Decl *> Decls,
1187 SourceLocation StartLoc, SourceLocation EndLoc) {
1188 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith406c38e2011-02-23 00:37:57 +00001189 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001190 }
Mike Stump1eb44332009-09-09 15:08:12 +00001191
Anders Carlsson703e3942010-01-24 05:50:09 +00001192 /// \brief Build a new inline asm statement.
1193 ///
1194 /// By default, performs semantic analysis to build the new statement.
1195 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001196 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1197 bool IsVolatile, unsigned NumOutputs,
1198 unsigned NumInputs, IdentifierInfo **Names,
1199 MultiExprArg Constraints, MultiExprArg Exprs,
1200 Expr *AsmString, MultiExprArg Clobbers,
1201 SourceLocation RParenLoc) {
1202 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1203 NumInputs, Names, Constraints, Exprs,
1204 AsmString, Clobbers, RParenLoc);
Anders Carlsson703e3942010-01-24 05:50:09 +00001205 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001206
Chad Rosier8cd64b42012-06-11 20:47:18 +00001207 /// \brief Build a new MS style inline asm statement.
1208 ///
1209 /// By default, performs semantic analysis to build the new statement.
1210 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001211 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallaeeacf72013-05-03 00:10:13 +00001212 ArrayRef<Token> AsmToks,
1213 StringRef AsmString,
1214 unsigned NumOutputs, unsigned NumInputs,
1215 ArrayRef<StringRef> Constraints,
1216 ArrayRef<StringRef> Clobbers,
1217 ArrayRef<Expr*> Exprs,
1218 SourceLocation EndLoc) {
1219 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1220 NumOutputs, NumInputs,
1221 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier8cd64b42012-06-11 20:47:18 +00001222 }
1223
James Dennett699c9042012-06-15 07:13:21 +00001224 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001225 ///
1226 /// By default, performs semantic analysis to build the new statement.
1227 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001228 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001229 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001230 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001231 Stmt *Finally) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001232 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001233 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001234 }
1235
Douglas Gregorbe270a02010-04-26 17:57:08 +00001236 /// \brief Rebuild an Objective-C exception declaration.
1237 ///
1238 /// By default, performs semantic analysis to build the new declaration.
1239 /// Subclasses may override this routine to provide different behavior.
1240 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1241 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001242 return getSema().BuildObjCExceptionDecl(TInfo, T,
1243 ExceptionDecl->getInnerLocStart(),
1244 ExceptionDecl->getLocation(),
1245 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001246 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001247
James Dennett699c9042012-06-15 07:13:21 +00001248 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorbe270a02010-04-26 17:57:08 +00001249 ///
1250 /// By default, performs semantic analysis to build the new statement.
1251 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001252 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001253 SourceLocation RParenLoc,
1254 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001255 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001256 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001257 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001258 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001259
James Dennett699c9042012-06-15 07:13:21 +00001260 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001261 ///
1262 /// By default, performs semantic analysis to build the new statement.
1263 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001264 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001265 Stmt *Body) {
1266 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001267 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001268
James Dennett699c9042012-06-15 07:13:21 +00001269 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001270 ///
1271 /// By default, performs semantic analysis to build the new statement.
1272 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001273 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001274 Expr *Operand) {
1275 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001276 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001277
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00001278 /// \brief Build a new OpenMP parallel directive.
1279 ///
1280 /// By default, performs semantic analysis to build the new statement.
1281 /// Subclasses may override this routine to provide different behavior.
1282 StmtResult RebuildOMPParallelDirective(ArrayRef<OMPClause *> Clauses,
1283 Stmt *AStmt,
1284 SourceLocation StartLoc,
1285 SourceLocation EndLoc) {
1286 return getSema().ActOnOpenMPParallelDirective(Clauses, AStmt,
1287 StartLoc, EndLoc);
1288 }
1289
1290 /// \brief Build a new OpenMP 'default' clause.
1291 ///
1292 /// By default, performs semantic analysis to build the new statement.
1293 /// Subclasses may override this routine to provide different behavior.
1294 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1295 SourceLocation KindKwLoc,
1296 SourceLocation StartLoc,
1297 SourceLocation LParenLoc,
1298 SourceLocation EndLoc) {
1299 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1300 StartLoc, LParenLoc, EndLoc);
1301 }
1302
1303 /// \brief Build a new OpenMP 'private' clause.
1304 ///
1305 /// By default, performs semantic analysis to build the new statement.
1306 /// Subclasses may override this routine to provide different behavior.
1307 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1308 SourceLocation StartLoc,
1309 SourceLocation LParenLoc,
1310 SourceLocation EndLoc) {
1311 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1312 EndLoc);
1313 }
1314
Alexey Bataev0c018352013-09-06 18:03:48 +00001315 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1316 SourceLocation StartLoc,
1317 SourceLocation LParenLoc,
1318 SourceLocation EndLoc) {
1319 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1320 EndLoc);
1321 }
1322
James Dennett699c9042012-06-15 07:13:21 +00001323 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCall07524032011-07-27 21:50:02 +00001324 ///
1325 /// By default, performs semantic analysis to build the new statement.
1326 /// Subclasses may override this routine to provide different behavior.
1327 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1328 Expr *object) {
1329 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1330 }
1331
James Dennett699c9042012-06-15 07:13:21 +00001332 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001333 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001334 /// By default, performs semantic analysis to build the new statement.
1335 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001336 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall07524032011-07-27 21:50:02 +00001337 Expr *Object, Stmt *Body) {
1338 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001339 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001340
James Dennett699c9042012-06-15 07:13:21 +00001341 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCallf85e1932011-06-15 23:02:42 +00001342 ///
1343 /// By default, performs semantic analysis to build the new statement.
1344 /// Subclasses may override this routine to provide different behavior.
1345 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1346 Stmt *Body) {
1347 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1348 }
John McCall990567c2011-07-27 01:07:15 +00001349
Douglas Gregorc3203e72010-04-22 23:10:45 +00001350 /// \brief Build a new Objective-C fast enumeration statement.
1351 ///
1352 /// By default, performs semantic analysis to build the new statement.
1353 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001354 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001355 Stmt *Element,
1356 Expr *Collection,
1357 SourceLocation RParenLoc,
1358 Stmt *Body) {
Sam Panzerbc20bbb2012-08-16 21:47:25 +00001359 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001360 Element,
John McCall9ae2f072010-08-23 23:25:46 +00001361 Collection,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001362 RParenLoc);
1363 if (ForEachStmt.isInvalid())
1364 return StmtError();
1365
1366 return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001367 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001368
Douglas Gregor43959a92009-08-20 07:17:43 +00001369 /// \brief Build a new C++ exception declaration.
1370 ///
1371 /// By default, performs semantic analysis to build the new decaration.
1372 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001373 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001374 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001375 SourceLocation StartLoc,
1376 SourceLocation IdLoc,
1377 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001378 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1379 StartLoc, IdLoc, Id);
1380 if (Var)
1381 getSema().CurContext->addDecl(Var);
1382 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001383 }
1384
1385 /// \brief Build a new C++ catch statement.
1386 ///
1387 /// By default, performs semantic analysis to build the new statement.
1388 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001389 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001390 VarDecl *ExceptionDecl,
1391 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001392 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1393 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001394 }
Mike Stump1eb44332009-09-09 15:08:12 +00001395
Douglas Gregor43959a92009-08-20 07:17:43 +00001396 /// \brief Build a new C++ try statement.
1397 ///
1398 /// By default, performs semantic analysis to build the new statement.
1399 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelm21adb0c2013-08-22 09:20:03 +00001400 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1401 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001402 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00001403 }
Mike Stump1eb44332009-09-09 15:08:12 +00001404
Richard Smithad762fc2011-04-14 22:09:26 +00001405 /// \brief Build a new C++0x range-based for statement.
1406 ///
1407 /// By default, performs semantic analysis to build the new statement.
1408 /// Subclasses may override this routine to provide different behavior.
1409 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1410 SourceLocation ColonLoc,
1411 Stmt *Range, Stmt *BeginEnd,
1412 Expr *Cond, Expr *Inc,
1413 Stmt *LoopVar,
1414 SourceLocation RParenLoc) {
Douglas Gregor6f96f4b2013-04-08 18:40:13 +00001415 // If we've just learned that the range is actually an Objective-C
1416 // collection, treat this as an Objective-C fast enumeration loop.
1417 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1418 if (RangeStmt->isSingleDecl()) {
1419 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39b60dc2013-05-02 18:35:56 +00001420 if (RangeVar->isInvalidDecl())
1421 return StmtError();
1422
Douglas Gregor6f96f4b2013-04-08 18:40:13 +00001423 Expr *RangeExpr = RangeVar->getInit();
1424 if (!RangeExpr->isTypeDependent() &&
1425 RangeExpr->getType()->isObjCObjectPointerType())
1426 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1427 RParenLoc);
1428 }
1429 }
1430 }
1431
Richard Smithad762fc2011-04-14 22:09:26 +00001432 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smith8b533d92012-09-20 21:52:32 +00001433 Cond, Inc, LoopVar, RParenLoc,
1434 Sema::BFRK_Rebuild);
Richard Smithad762fc2011-04-14 22:09:26 +00001435 }
Douglas Gregorba0513d2011-10-25 01:33:02 +00001436
1437 /// \brief Build a new C++0x range-based for statement.
1438 ///
1439 /// By default, performs semantic analysis to build the new statement.
1440 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001441 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregorba0513d2011-10-25 01:33:02 +00001442 bool IsIfExists,
1443 NestedNameSpecifierLoc QualifierLoc,
1444 DeclarationNameInfo NameInfo,
1445 Stmt *Nested) {
1446 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1447 QualifierLoc, NameInfo, Nested);
1448 }
1449
Richard Smithad762fc2011-04-14 22:09:26 +00001450 /// \brief Attach body to a C++0x range-based for statement.
1451 ///
1452 /// By default, performs semantic analysis to finish the new statement.
1453 /// Subclasses may override this routine to provide different behavior.
1454 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1455 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1456 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001457
John Wiegley28bbe4b2011-04-28 01:08:34 +00001458 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1459 SourceLocation TryLoc,
1460 Stmt *TryBlock,
1461 Stmt *Handler) {
1462 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1463 }
1464
1465 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1466 Expr *FilterExpr,
1467 Stmt *Block) {
1468 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1469 }
1470
1471 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1472 Stmt *Block) {
1473 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1474 }
1475
Douglas Gregorb98b1992009-08-11 05:31:07 +00001476 /// \brief Build a new expression that references a declaration.
1477 ///
1478 /// By default, performs semantic analysis to build the new expression.
1479 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001480 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001481 LookupResult &R,
1482 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001483 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1484 }
1485
1486
1487 /// \brief Build a new expression that references a declaration.
1488 ///
1489 /// By default, performs semantic analysis to build the new expression.
1490 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001491 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001492 ValueDecl *VD,
1493 const DeclarationNameInfo &NameInfo,
1494 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001495 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001496 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001497
1498 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001499
1500 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001501 }
Mike Stump1eb44332009-09-09 15:08:12 +00001502
Douglas Gregorb98b1992009-08-11 05:31:07 +00001503 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001504 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001505 /// By default, performs semantic analysis to build the new expression.
1506 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001507 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001508 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001509 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001510 }
1511
Douglas Gregora71d8192009-09-04 17:36:40 +00001512 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001513 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001514 /// By default, performs semantic analysis to build the new expression.
1515 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001516 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001517 SourceLocation OperatorLoc,
1518 bool isArrow,
1519 CXXScopeSpec &SS,
1520 TypeSourceInfo *ScopeType,
1521 SourceLocation CCLoc,
1522 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001523 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001524
Douglas Gregorb98b1992009-08-11 05:31:07 +00001525 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001526 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +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 RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001530 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001531 Expr *SubExpr) {
1532 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001533 }
Mike Stump1eb44332009-09-09 15:08:12 +00001534
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001535 /// \brief Build a new builtin offsetof expression.
1536 ///
1537 /// By default, performs semantic analysis to build the new expression.
1538 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001539 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001540 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001541 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001542 unsigned NumComponents,
1543 SourceLocation RParenLoc) {
1544 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1545 NumComponents, RParenLoc);
1546 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001547
1548 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001549 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001550 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001551 /// By default, performs semantic analysis to build the new expression.
1552 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001553 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1554 SourceLocation OpLoc,
1555 UnaryExprOrTypeTrait ExprKind,
1556 SourceRange R) {
1557 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001558 }
1559
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001560 /// \brief Build a new sizeof, alignof or vec step expression with an
1561 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001562 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001563 /// By default, performs semantic analysis to build the new expression.
1564 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001565 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1566 UnaryExprOrTypeTrait ExprKind,
1567 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001568 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001569 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001570 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001571 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001572
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001573 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001574 }
Mike Stump1eb44332009-09-09 15:08:12 +00001575
Douglas Gregorb98b1992009-08-11 05:31:07 +00001576 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001577 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001578 /// By default, performs semantic analysis to build the new expression.
1579 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001580 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001581 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001582 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001583 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001584 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1585 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001586 RBracketLoc);
1587 }
1588
1589 /// \brief Build a new call 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 RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001594 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001595 SourceLocation RParenLoc,
1596 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001597 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001598 Args, RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001599 }
1600
1601 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001602 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001603 /// By default, performs semantic analysis to build the new expression.
1604 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001605 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001606 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001607 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001608 SourceLocation TemplateKWLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001609 const DeclarationNameInfo &MemberNameInfo,
1610 ValueDecl *Member,
1611 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001612 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001613 NamedDecl *FirstQualifierInScope) {
Richard Smith9138b4e2011-10-26 19:06:56 +00001614 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1615 isArrow);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001616 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001617 // We have a reference to an unnamed field. This is always the
1618 // base of an anonymous struct/union member access, i.e. the
1619 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001620 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001621 assert(Member->getType()->isRecordType() &&
1622 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001623
Richard Smith9138b4e2011-10-26 19:06:56 +00001624 BaseResult =
1625 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley429bb272011-04-08 18:41:53 +00001626 QualifierLoc.getNestedNameSpecifier(),
1627 FoundDecl, Member);
1628 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001629 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001630 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001631 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001632 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001633 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001634 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001635 cast<FieldDecl>(Member)->getType(),
1636 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001637 return getSema().Owned(ME);
1638 }
Mike Stump1eb44332009-09-09 15:08:12 +00001639
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001640 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001641 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001642
John Wiegley429bb272011-04-08 18:41:53 +00001643 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001644 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001645
John McCall6bb80172010-03-30 21:47:33 +00001646 // FIXME: this involves duplicating earlier analysis in a lot of
1647 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001648 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001649 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001650 R.resolveKind();
1651
John McCall9ae2f072010-08-23 23:25:46 +00001652 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001653 SS, TemplateKWLoc,
1654 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001655 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001656 }
Mike Stump1eb44332009-09-09 15:08:12 +00001657
Douglas Gregorb98b1992009-08-11 05:31:07 +00001658 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001659 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001660 /// By default, performs semantic analysis to build the new expression.
1661 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001662 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001663 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001664 Expr *LHS, Expr *RHS) {
1665 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001666 }
1667
1668 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001669 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001670 /// By default, performs semantic analysis to build the new expression.
1671 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001672 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001673 SourceLocation QuestionLoc,
1674 Expr *LHS,
1675 SourceLocation ColonLoc,
1676 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001677 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1678 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001679 }
1680
Douglas Gregorb98b1992009-08-11 05:31:07 +00001681 /// \brief Build a new C-style cast 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 RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001686 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001687 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001688 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001689 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001690 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001691 }
Mike Stump1eb44332009-09-09 15:08:12 +00001692
Douglas Gregorb98b1992009-08-11 05:31:07 +00001693 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001694 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001695 /// By default, performs semantic analysis to build the new expression.
1696 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001697 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001698 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001699 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001700 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001701 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001702 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001703 }
Mike Stump1eb44332009-09-09 15:08:12 +00001704
Douglas Gregorb98b1992009-08-11 05:31:07 +00001705 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001706 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001707 /// By default, performs semantic analysis to build the new expression.
1708 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001709 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001710 SourceLocation OpLoc,
1711 SourceLocation AccessorLoc,
1712 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001713
John McCall129e2df2009-11-30 22:42:35 +00001714 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001715 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001716 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001717 OpLoc, /*IsArrow*/ false,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001718 SS, SourceLocation(),
1719 /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001720 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001721 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001722 }
Mike Stump1eb44332009-09-09 15:08:12 +00001723
Douglas Gregorb98b1992009-08-11 05:31:07 +00001724 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001725 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001726 /// By default, performs semantic analysis to build the new expression.
1727 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001728 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001729 MultiExprArg Inits,
1730 SourceLocation RBraceLoc,
1731 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001732 ExprResult Result
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001733 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregore48319a2009-11-09 17:16:50 +00001734 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001735 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00001736
Douglas Gregore48319a2009-11-09 17:16:50 +00001737 // Patch in the result type we were given, which may have been computed
1738 // when the initial InitListExpr was built.
1739 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1740 ILE->setType(ResultTy);
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001741 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001742 }
Mike Stump1eb44332009-09-09 15:08:12 +00001743
Douglas Gregorb98b1992009-08-11 05:31:07 +00001744 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001745 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001746 /// By default, performs semantic analysis to build the new expression.
1747 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001748 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001749 MultiExprArg ArrayExprs,
1750 SourceLocation EqualOrColonLoc,
1751 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001752 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001753 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001754 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001755 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001756 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001757 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001758
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001759 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001760 }
Mike Stump1eb44332009-09-09 15:08:12 +00001761
Douglas Gregorb98b1992009-08-11 05:31:07 +00001762 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001763 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001764 /// By default, builds the implicit value initialization without performing
1765 /// any semantic analysis. Subclasses may override this routine to provide
1766 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001767 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001768 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1769 }
Mike Stump1eb44332009-09-09 15:08:12 +00001770
Douglas Gregorb98b1992009-08-11 05:31:07 +00001771 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001772 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001773 /// By default, performs semantic analysis to build the new expression.
1774 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001775 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001776 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001777 SourceLocation RParenLoc) {
1778 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001779 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001780 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001781 }
1782
1783 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001784 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001785 /// By default, performs semantic analysis to build the new expression.
1786 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001787 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +00001788 MultiExprArg SubExprs,
1789 SourceLocation RParenLoc) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001790 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001791 }
Mike Stump1eb44332009-09-09 15:08:12 +00001792
Douglas Gregorb98b1992009-08-11 05:31:07 +00001793 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001794 ///
1795 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001796 /// rather than attempting to map the label statement itself.
1797 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001798 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001799 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001800 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001801 }
Mike Stump1eb44332009-09-09 15:08:12 +00001802
Douglas Gregorb98b1992009-08-11 05:31:07 +00001803 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001804 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001805 /// By default, performs semantic analysis to build the new expression.
1806 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001807 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001808 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001809 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001810 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001811 }
Mike Stump1eb44332009-09-09 15:08:12 +00001812
Douglas Gregorb98b1992009-08-11 05:31:07 +00001813 /// \brief Build a new __builtin_choose_expr expression.
1814 ///
1815 /// By default, performs semantic analysis to build the new expression.
1816 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001817 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001818 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001819 SourceLocation RParenLoc) {
1820 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001821 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001822 RParenLoc);
1823 }
Mike Stump1eb44332009-09-09 15:08:12 +00001824
Peter Collingbournef111d932011-04-15 00:35:48 +00001825 /// \brief Build a new generic selection expression.
1826 ///
1827 /// By default, performs semantic analysis to build the new expression.
1828 /// Subclasses may override this routine to provide different behavior.
1829 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1830 SourceLocation DefaultLoc,
1831 SourceLocation RParenLoc,
1832 Expr *ControllingExpr,
Dmitri Gribenko80613222013-05-10 13:06:58 +00001833 ArrayRef<TypeSourceInfo *> Types,
1834 ArrayRef<Expr *> Exprs) {
Peter Collingbournef111d932011-04-15 00:35:48 +00001835 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko80613222013-05-10 13:06:58 +00001836 ControllingExpr, Types, Exprs);
Peter Collingbournef111d932011-04-15 00:35:48 +00001837 }
1838
Douglas Gregorb98b1992009-08-11 05:31:07 +00001839 /// \brief Build a new overloaded operator call expression.
1840 ///
1841 /// By default, performs semantic analysis to build the new expression.
1842 /// The semantic analysis provides the behavior of template instantiation,
1843 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001844 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001845 /// argument-dependent lookup, etc. Subclasses may override this routine to
1846 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001847 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001848 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001849 Expr *Callee,
1850 Expr *First,
1851 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001852
1853 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001854 /// reinterpret_cast.
1855 ///
1856 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001857 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001858 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001859 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001860 Stmt::StmtClass Class,
1861 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001862 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001863 SourceLocation RAngleLoc,
1864 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001865 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001866 SourceLocation RParenLoc) {
1867 switch (Class) {
1868 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001869 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001870 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001871 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001872
1873 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001874 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001875 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001876 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001877
Douglas Gregorb98b1992009-08-11 05:31:07 +00001878 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001879 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001880 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001881 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001882 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001883
Douglas Gregorb98b1992009-08-11 05:31:07 +00001884 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001885 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001886 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001887 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001888
Douglas Gregorb98b1992009-08-11 05:31:07 +00001889 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001890 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001891 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001892 }
Mike Stump1eb44332009-09-09 15:08:12 +00001893
Douglas Gregorb98b1992009-08-11 05:31:07 +00001894 /// \brief Build a new C++ static_cast expression.
1895 ///
1896 /// By default, performs semantic analysis to build the new expression.
1897 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001898 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001899 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001900 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001901 SourceLocation RAngleLoc,
1902 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001903 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001904 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001905 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001906 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001907 SourceRange(LAngleLoc, RAngleLoc),
1908 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001909 }
1910
1911 /// \brief Build a new C++ dynamic_cast expression.
1912 ///
1913 /// By default, performs semantic analysis to build the new expression.
1914 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001915 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001916 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001917 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001918 SourceLocation RAngleLoc,
1919 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001920 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001921 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001922 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001923 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001924 SourceRange(LAngleLoc, RAngleLoc),
1925 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001926 }
1927
1928 /// \brief Build a new C++ reinterpret_cast expression.
1929 ///
1930 /// By default, performs semantic analysis to build the new expression.
1931 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001932 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001933 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001934 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001935 SourceLocation RAngleLoc,
1936 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001937 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001938 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001939 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001940 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001941 SourceRange(LAngleLoc, RAngleLoc),
1942 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001943 }
1944
1945 /// \brief Build a new C++ const_cast expression.
1946 ///
1947 /// By default, performs semantic analysis to build the new expression.
1948 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001949 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001950 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001951 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001952 SourceLocation RAngleLoc,
1953 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001954 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001955 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001956 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001957 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001958 SourceRange(LAngleLoc, RAngleLoc),
1959 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001960 }
Mike Stump1eb44332009-09-09 15:08:12 +00001961
Douglas Gregorb98b1992009-08-11 05:31:07 +00001962 /// \brief Build a new C++ functional-style cast expression.
1963 ///
1964 /// By default, performs semantic analysis to build the new expression.
1965 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001966 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1967 SourceLocation LParenLoc,
1968 Expr *Sub,
1969 SourceLocation RParenLoc) {
1970 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001971 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001972 RParenLoc);
1973 }
Mike Stump1eb44332009-09-09 15:08:12 +00001974
Douglas Gregorb98b1992009-08-11 05:31:07 +00001975 /// \brief Build a new C++ typeid(type) expression.
1976 ///
1977 /// By default, performs semantic analysis to build the new expression.
1978 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001979 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001980 SourceLocation TypeidLoc,
1981 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001982 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001983 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001984 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001985 }
Mike Stump1eb44332009-09-09 15:08:12 +00001986
Francois Pichet01b7c302010-09-08 12:20:18 +00001987
Douglas Gregorb98b1992009-08-11 05:31:07 +00001988 /// \brief Build a new C++ typeid(expr) 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,
John McCall9ae2f072010-08-23 23:25:46 +00001994 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001995 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001996 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001997 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001998 }
1999
Francois Pichet01b7c302010-09-08 12:20:18 +00002000 /// \brief Build a new C++ __uuidof(type) expression.
2001 ///
2002 /// By default, performs semantic analysis to build the new expression.
2003 /// Subclasses may override this routine to provide different behavior.
2004 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2005 SourceLocation TypeidLoc,
2006 TypeSourceInfo *Operand,
2007 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002008 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet01b7c302010-09-08 12:20:18 +00002009 RParenLoc);
2010 }
2011
2012 /// \brief Build a new C++ __uuidof(expr) expression.
2013 ///
2014 /// By default, performs semantic analysis to build the new expression.
2015 /// Subclasses may override this routine to provide different behavior.
2016 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2017 SourceLocation TypeidLoc,
2018 Expr *Operand,
2019 SourceLocation RParenLoc) {
2020 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2021 RParenLoc);
2022 }
2023
Douglas Gregorb98b1992009-08-11 05:31:07 +00002024 /// \brief Build a new C++ "this" expression.
2025 ///
2026 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00002027 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00002028 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002029 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00002030 QualType ThisType,
2031 bool isImplicit) {
Eli Friedmanb69b42c2012-01-11 02:36:31 +00002032 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002033 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00002034 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
2035 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002036 }
2037
2038 /// \brief Build a new C++ throw expression.
2039 ///
2040 /// By default, performs semantic analysis to build the new expression.
2041 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00002042 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2043 bool IsThrownVariableInScope) {
2044 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002045 }
2046
2047 /// \brief Build a new C++ default-argument expression.
2048 ///
2049 /// By default, builds a new default-argument expression, which does not
2050 /// require any semantic analysis. Subclasses may override this routine to
2051 /// provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002052 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00002053 ParmVarDecl *Param) {
2054 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
2055 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002056 }
2057
Richard Smithc3bf52c2013-04-20 22:23:05 +00002058 /// \brief Build a new C++11 default-initialization expression.
2059 ///
2060 /// By default, builds a new default field initialization expression, which
2061 /// does not require any semantic analysis. Subclasses may override this
2062 /// routine to provide different behavior.
2063 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2064 FieldDecl *Field) {
2065 return getSema().Owned(CXXDefaultInitExpr::Create(getSema().Context, Loc,
2066 Field));
2067 }
2068
Douglas Gregorb98b1992009-08-11 05:31:07 +00002069 /// \brief Build a new C++ zero-initialization expression.
2070 ///
2071 /// By default, performs semantic analysis to build the new expression.
2072 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002073 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2074 SourceLocation LParenLoc,
2075 SourceLocation RParenLoc) {
2076 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002077 None, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002078 }
Mike Stump1eb44332009-09-09 15:08:12 +00002079
Douglas Gregorb98b1992009-08-11 05:31:07 +00002080 /// \brief Build a new C++ "new" expression.
2081 ///
2082 /// By default, performs semantic analysis to build the new expression.
2083 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002084 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002085 bool UseGlobal,
2086 SourceLocation PlacementLParen,
2087 MultiExprArg PlacementArgs,
2088 SourceLocation PlacementRParen,
2089 SourceRange TypeIdParens,
2090 QualType AllocatedType,
2091 TypeSourceInfo *AllocatedTypeInfo,
2092 Expr *ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002093 SourceRange DirectInitRange,
2094 Expr *Initializer) {
Mike Stump1eb44332009-09-09 15:08:12 +00002095 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002096 PlacementLParen,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002097 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002098 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00002099 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002100 AllocatedType,
2101 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00002102 ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002103 DirectInitRange,
2104 Initializer);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002105 }
Mike Stump1eb44332009-09-09 15:08:12 +00002106
Douglas Gregorb98b1992009-08-11 05:31:07 +00002107 /// \brief Build a new C++ "delete" expression.
2108 ///
2109 /// By default, performs semantic analysis to build the new expression.
2110 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002111 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002112 bool IsGlobalDelete,
2113 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002114 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002115 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002116 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002117 }
Mike Stump1eb44332009-09-09 15:08:12 +00002118
Douglas Gregorb98b1992009-08-11 05:31:07 +00002119 /// \brief Build a new unary type trait expression.
2120 ///
2121 /// By default, performs semantic analysis to build the new expression.
2122 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002123 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00002124 SourceLocation StartLoc,
2125 TypeSourceInfo *T,
2126 SourceLocation RParenLoc) {
2127 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002128 }
2129
Francois Pichet6ad6f282010-12-07 00:08:36 +00002130 /// \brief Build a new binary type trait expression.
2131 ///
2132 /// By default, performs semantic analysis to build the new expression.
2133 /// Subclasses may override this routine to provide different behavior.
2134 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
2135 SourceLocation StartLoc,
2136 TypeSourceInfo *LhsT,
2137 TypeSourceInfo *RhsT,
2138 SourceLocation RParenLoc) {
2139 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
2140 }
2141
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00002142 /// \brief Build a new type trait expression.
2143 ///
2144 /// By default, performs semantic analysis to build the new expression.
2145 /// Subclasses may override this routine to provide different behavior.
2146 ExprResult RebuildTypeTrait(TypeTrait Trait,
2147 SourceLocation StartLoc,
2148 ArrayRef<TypeSourceInfo *> Args,
2149 SourceLocation RParenLoc) {
2150 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2151 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002152
John Wiegley21ff2e52011-04-28 00:16:57 +00002153 /// \brief Build a new array type trait expression.
2154 ///
2155 /// By default, performs semantic analysis to build the new expression.
2156 /// Subclasses may override this routine to provide different behavior.
2157 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2158 SourceLocation StartLoc,
2159 TypeSourceInfo *TSInfo,
2160 Expr *DimExpr,
2161 SourceLocation RParenLoc) {
2162 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2163 }
2164
John Wiegley55262202011-04-25 06:54:41 +00002165 /// \brief Build a new expression trait expression.
2166 ///
2167 /// By default, performs semantic analysis to build the new expression.
2168 /// Subclasses may override this routine to provide different behavior.
2169 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2170 SourceLocation StartLoc,
2171 Expr *Queried,
2172 SourceLocation RParenLoc) {
2173 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2174 }
2175
Mike Stump1eb44332009-09-09 15:08:12 +00002176 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002177 /// expression.
2178 ///
2179 /// By default, performs semantic analysis to build the new expression.
2180 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002181 ExprResult RebuildDependentScopeDeclRefExpr(
2182 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002183 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002184 const DeclarationNameInfo &NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00002185 const TemplateArgumentListInfo *TemplateArgs,
2186 bool IsAddressOfOperand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002187 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002188 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002189
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002190 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002191 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002192 NameInfo, TemplateArgs);
John McCallf7a1a742009-11-24 19:00:30 +00002193
Richard Smithefeeccf2012-10-21 03:28:35 +00002194 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo,
2195 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002196 }
2197
2198 /// \brief Build a new template-id expression.
2199 ///
2200 /// By default, performs semantic analysis to build the new expression.
2201 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002202 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002203 SourceLocation TemplateKWLoc,
2204 LookupResult &R,
2205 bool RequiresADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002206 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002207 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2208 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002209 }
2210
2211 /// \brief Build a new object-construction 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 RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002216 SourceLocation Loc,
2217 CXXConstructorDecl *Constructor,
2218 bool IsElidable,
2219 MultiExprArg Args,
2220 bool HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002221 bool ListInitialization,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002222 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002223 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002224 SourceRange ParenRange) {
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00002225 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002226 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002227 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002228 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002229
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002230 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002231 ConvertedArgs,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002232 HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002233 ListInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002234 RequiresZeroInit, ConstructKind,
2235 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002236 }
2237
2238 /// \brief Build a new object-construction expression.
2239 ///
2240 /// By default, performs semantic analysis to build the new expression.
2241 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002242 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2243 SourceLocation LParenLoc,
2244 MultiExprArg Args,
2245 SourceLocation RParenLoc) {
2246 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002247 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002248 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002249 RParenLoc);
2250 }
2251
2252 /// \brief Build a new object-construction expression.
2253 ///
2254 /// By default, performs semantic analysis to build the new expression.
2255 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002256 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2257 SourceLocation LParenLoc,
2258 MultiExprArg Args,
2259 SourceLocation RParenLoc) {
2260 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002261 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002262 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002263 RParenLoc);
2264 }
Mike Stump1eb44332009-09-09 15:08:12 +00002265
Douglas Gregorb98b1992009-08-11 05:31:07 +00002266 /// \brief Build a new member reference expression.
2267 ///
2268 /// By default, performs semantic analysis to build the new expression.
2269 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002270 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002271 QualType BaseType,
2272 bool IsArrow,
2273 SourceLocation OperatorLoc,
2274 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002275 SourceLocation TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00002276 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002277 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002278 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002279 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002280 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002281
John McCall9ae2f072010-08-23 23:25:46 +00002282 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002283 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002284 SS, TemplateKWLoc,
2285 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002286 MemberNameInfo,
2287 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002288 }
2289
John McCall129e2df2009-11-30 22:42:35 +00002290 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002291 ///
2292 /// By default, performs semantic analysis to build the new expression.
2293 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002294 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2295 SourceLocation OperatorLoc,
2296 bool IsArrow,
2297 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002298 SourceLocation TemplateKWLoc,
Richard Smith9138b4e2011-10-26 19:06:56 +00002299 NamedDecl *FirstQualifierInScope,
2300 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002301 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002302 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002303 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002304
John McCall9ae2f072010-08-23 23:25:46 +00002305 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002306 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002307 SS, TemplateKWLoc,
2308 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00002309 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002310 }
Mike Stump1eb44332009-09-09 15:08:12 +00002311
Sebastian Redl2e156222010-09-10 20:55:43 +00002312 /// \brief Build a new noexcept expression.
2313 ///
2314 /// By default, performs semantic analysis to build the new expression.
2315 /// Subclasses may override this routine to provide different behavior.
2316 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2317 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2318 }
2319
Douglas Gregoree8aff02011-01-04 17:33:58 +00002320 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002321 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2322 SourceLocation PackLoc,
Douglas Gregoree8aff02011-01-04 17:33:58 +00002323 SourceLocation RParenLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002324 Optional<unsigned> Length) {
Douglas Gregor089e8932011-10-10 18:59:29 +00002325 if (Length)
Chad Rosier4a9d7952012-08-08 18:46:20 +00002326 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2327 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002328 RParenLoc, *Length);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002329
2330 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2331 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002332 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002333 }
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002334
Patrick Beardeb382ec2012-04-19 00:25:12 +00002335 /// \brief Build a new Objective-C boxed expression.
2336 ///
2337 /// By default, performs semantic analysis to build the new expression.
2338 /// Subclasses may override this routine to provide different behavior.
2339 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2340 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2341 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002342
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002343 /// \brief Build a new Objective-C array literal.
2344 ///
2345 /// By default, performs semantic analysis to build the new expression.
2346 /// Subclasses may override this routine to provide different behavior.
2347 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2348 Expr **Elements, unsigned NumElements) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002349 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002350 MultiExprArg(Elements, NumElements));
2351 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002352
2353 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002354 Expr *Base, Expr *Key,
2355 ObjCMethodDecl *getterMethod,
2356 ObjCMethodDecl *setterMethod) {
2357 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2358 getterMethod, setterMethod);
2359 }
2360
2361 /// \brief Build a new Objective-C dictionary literal.
2362 ///
2363 /// By default, performs semantic analysis to build the new expression.
2364 /// Subclasses may override this routine to provide different behavior.
2365 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2366 ObjCDictionaryElement *Elements,
2367 unsigned NumElements) {
2368 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2369 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002370
James Dennett699c9042012-06-15 07:13:21 +00002371 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregorb98b1992009-08-11 05:31:07 +00002372 ///
2373 /// By default, performs semantic analysis to build the new expression.
2374 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002375 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002376 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002377 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002378 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002379 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002380 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002381
Douglas Gregor92e986e2010-04-22 16:44:27 +00002382 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002383 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002384 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002385 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002386 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002387 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002388 MultiExprArg Args,
2389 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002390 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2391 ReceiverTypeInfo->getType(),
2392 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002393 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002394 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002395 }
2396
2397 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002398 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002399 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002400 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002401 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002402 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002403 MultiExprArg Args,
2404 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002405 return SemaRef.BuildInstanceMessage(Receiver,
2406 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002407 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002408 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002409 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002410 }
2411
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002412 /// \brief Build a new Objective-C ivar reference expression.
2413 ///
2414 /// By default, performs semantic analysis to build the new expression.
2415 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002416 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002417 SourceLocation IvarLoc,
2418 bool IsArrow, bool IsFreeIvar) {
2419 // FIXME: We lose track of the IsFreeIvar bit.
2420 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002421 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002422 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2423 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002424 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002425 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002426 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002427 false);
John Wiegley429bb272011-04-08 18:41:53 +00002428 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002429 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002430
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002431 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002432 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002433
John Wiegley429bb272011-04-08 18:41:53 +00002434 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002435 /*FIXME:*/IvarLoc, IsArrow,
2436 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002437 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002438 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002439 /*TemplateArgs=*/0);
2440 }
Douglas Gregore3303542010-04-26 20:47:02 +00002441
2442 /// \brief Build a new Objective-C property reference expression.
2443 ///
2444 /// By default, performs semantic analysis to build the new expression.
2445 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002446 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002447 ObjCPropertyDecl *Property,
2448 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002449 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002450 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002451 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2452 Sema::LookupMemberName);
2453 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002454 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002455 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002456 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002457 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002458 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002459
Douglas Gregore3303542010-04-26 20:47:02 +00002460 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002461 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002462
John Wiegley429bb272011-04-08 18:41:53 +00002463 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002464 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002465 SS, SourceLocation(),
Douglas Gregore3303542010-04-26 20:47:02 +00002466 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002467 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002468 /*TemplateArgs=*/0);
2469 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002470
John McCall12f78a62010-12-02 01:19:52 +00002471 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002472 ///
2473 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002474 /// Subclasses may override this routine to provide different behavior.
2475 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2476 ObjCMethodDecl *Getter,
2477 ObjCMethodDecl *Setter,
2478 SourceLocation PropertyLoc) {
2479 // Since these expressions can only be value-dependent, we do not
2480 // need to perform semantic analysis again.
2481 return Owned(
2482 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2483 VK_LValue, OK_ObjCProperty,
2484 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002485 }
2486
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002487 /// \brief Build a new Objective-C "isa" expression.
2488 ///
2489 /// By default, performs semantic analysis to build the new expression.
2490 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002491 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002492 SourceLocation OpLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002493 bool IsArrow) {
2494 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002495 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002496 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2497 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002498 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002499 OpLoc,
John McCalld226f652010-08-21 09:40:31 +00002500 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002501 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002502 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002503
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002504 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002505 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002506
John Wiegley429bb272011-04-08 18:41:53 +00002507 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002508 OpLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002509 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002510 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002511 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002512 /*TemplateArgs=*/0);
2513 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002514
Douglas Gregorb98b1992009-08-11 05:31:07 +00002515 /// \brief Build a new shuffle vector expression.
2516 ///
2517 /// By default, performs semantic analysis to build the new expression.
2518 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002519 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002520 MultiExprArg SubExprs,
2521 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002522 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002523 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002524 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2525 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2526 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikie3bc93e32012-12-19 00:45:41 +00002527 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002528
Douglas Gregorb98b1992009-08-11 05:31:07 +00002529 // Build a reference to the __builtin_shufflevector builtin
David Blaikie3bc93e32012-12-19 00:45:41 +00002530 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002531 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2532 SemaRef.Context.BuiltinFnTy,
2533 VK_RValue, BuiltinLoc);
2534 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2535 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
2536 CK_BuiltinFnToFnPtr).take();
Mike Stump1eb44332009-09-09 15:08:12 +00002537
2538 // Build the CallExpr
John Wiegley429bb272011-04-08 18:41:53 +00002539 ExprResult TheCall = SemaRef.Owned(
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002540 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, SubExprs,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002541 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002542 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002543 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002544
Douglas Gregorb98b1992009-08-11 05:31:07 +00002545 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002546 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002547 }
John McCall43fed0d2010-11-12 08:19:04 +00002548
Hal Finkel414a1bd2013-09-18 03:29:45 +00002549 /// \brief Build a new convert vector expression.
2550 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2551 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2552 SourceLocation RParenLoc) {
2553 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2554 BuiltinLoc, RParenLoc);
2555 }
2556
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002557 /// \brief Build a new template argument pack expansion.
2558 ///
2559 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002560 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002561 /// different behavior.
2562 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002563 SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002564 Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002565 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002566 case TemplateArgument::Expression: {
2567 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002568 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2569 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002570 if (Result.isInvalid())
2571 return TemplateArgumentLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002572
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002573 return TemplateArgumentLoc(Result.get(), Result.get());
2574 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002575
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002576 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002577 return TemplateArgumentLoc(TemplateArgument(
2578 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002579 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002580 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002581 Pattern.getTemplateNameLoc(),
2582 EllipsisLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002583
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002584 case TemplateArgument::Null:
2585 case TemplateArgument::Integral:
2586 case TemplateArgument::Declaration:
2587 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002588 case TemplateArgument::TemplateExpansion:
Eli Friedmand7a6b162012-09-26 02:36:12 +00002589 case TemplateArgument::NullPtr:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002590 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002591
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002592 case TemplateArgument::Type:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002593 if (TypeSourceInfo *Expansion
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002594 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002595 EllipsisLoc,
2596 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002597 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2598 Expansion);
2599 break;
2600 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002601
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002602 return TemplateArgumentLoc();
2603 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002604
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002605 /// \brief Build a new expression pack expansion.
2606 ///
2607 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002608 /// for an expression. Subclasses may override this routine to provide
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002609 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002610 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002611 Optional<unsigned> NumExpansions) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002612 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002613 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002614
2615 /// \brief Build a new atomic operation expression.
2616 ///
2617 /// By default, performs semantic analysis to build the new expression.
2618 /// Subclasses may override this routine to provide different behavior.
2619 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2620 MultiExprArg SubExprs,
2621 QualType RetTy,
2622 AtomicExpr::AtomicOp Op,
2623 SourceLocation RParenLoc) {
2624 // Just create the expression; there is not any interesting semantic
2625 // analysis here because we can't actually build an AtomicExpr until
2626 // we are sure it is semantically sound.
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002627 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002628 RParenLoc);
2629 }
2630
John McCall43fed0d2010-11-12 08:19:04 +00002631private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002632 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2633 QualType ObjectType,
2634 NamedDecl *FirstQualifierInScope,
2635 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002636
2637 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2638 QualType ObjectType,
2639 NamedDecl *FirstQualifierInScope,
2640 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002641};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002642
Douglas Gregor43959a92009-08-20 07:17:43 +00002643template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002644StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002645 if (!S)
2646 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002647
Douglas Gregor43959a92009-08-20 07:17:43 +00002648 switch (S->getStmtClass()) {
2649 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002650
Douglas Gregor43959a92009-08-20 07:17:43 +00002651 // Transform individual statement nodes
2652#define STMT(Node, Parent) \
2653 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002654#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002655#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002656#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002657
Douglas Gregor43959a92009-08-20 07:17:43 +00002658 // Transform expressions by calling TransformExpr.
2659#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002660#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002661#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002662#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002663 {
John McCall60d7b3a2010-08-24 06:29:42 +00002664 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002665 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002666 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002667
Richard Smith41956372013-01-14 22:39:08 +00002668 return getSema().ActOnExprStmt(E);
Douglas Gregor43959a92009-08-20 07:17:43 +00002669 }
Mike Stump1eb44332009-09-09 15:08:12 +00002670 }
2671
John McCall3fa5cae2010-10-26 07:05:15 +00002672 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002673}
Mike Stump1eb44332009-09-09 15:08:12 +00002674
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00002675template<typename Derived>
2676OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2677 if (!S)
2678 return S;
2679
2680 switch (S->getClauseKind()) {
2681 default: break;
2682 // Transform individual clause nodes
2683#define OPENMP_CLAUSE(Name, Class) \
2684 case OMPC_ ## Name : \
2685 return getDerived().Transform ## Class(cast<Class>(S));
2686#include "clang/Basic/OpenMPKinds.def"
2687 }
2688
2689 return S;
2690}
2691
Mike Stump1eb44332009-09-09 15:08:12 +00002692
Douglas Gregor670444e2009-08-04 22:27:00 +00002693template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002694ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002695 if (!E)
2696 return SemaRef.Owned(E);
2697
2698 switch (E->getStmtClass()) {
2699 case Stmt::NoStmtClass: break;
2700#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002701#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002702#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002703 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002704#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002705 }
2706
John McCall3fa5cae2010-10-26 07:05:15 +00002707 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002708}
2709
2710template<typename Derived>
Richard Smithc83c2302012-12-19 01:39:02 +00002711ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2712 bool CXXDirectInit) {
2713 // Initializers are instantiated like expressions, except that various outer
2714 // layers are stripped.
2715 if (!Init)
2716 return SemaRef.Owned(Init);
2717
2718 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2719 Init = ExprTemp->getSubExpr();
2720
Richard Smith858c2c32013-05-30 22:40:16 +00002721 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2722 Init = MTE->GetTemporaryExpr();
2723
Richard Smithc83c2302012-12-19 01:39:02 +00002724 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2725 Init = Binder->getSubExpr();
2726
2727 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2728 Init = ICE->getSubExprAsWritten();
2729
Richard Smith7c3e6152013-06-12 22:31:48 +00002730 if (CXXStdInitializerListExpr *ILE =
2731 dyn_cast<CXXStdInitializerListExpr>(Init))
2732 return TransformInitializer(ILE->getSubExpr(), CXXDirectInit);
2733
Richard Smith5cf15892012-12-21 08:13:35 +00002734 // If this is not a direct-initializer, we only need to reconstruct
2735 // InitListExprs. Other forms of copy-initialization will be a no-op if
2736 // the initializer is already the right type.
2737 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2738 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2739 return getDerived().TransformExpr(Init);
2740
2741 // Revert value-initialization back to empty parens.
2742 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2743 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002744 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith5cf15892012-12-21 08:13:35 +00002745 Parens.getEnd());
2746 }
2747
2748 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2749 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002750 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith5cf15892012-12-21 08:13:35 +00002751 SourceLocation());
2752
2753 // Revert initialization by constructor back to a parenthesized or braced list
2754 // of expressions. Any other form of initializer can just be reused directly.
2755 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithc83c2302012-12-19 01:39:02 +00002756 return getDerived().TransformExpr(Init);
2757
2758 SmallVector<Expr*, 8> NewArgs;
2759 bool ArgChanged = false;
2760 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2761 /*IsCall*/true, NewArgs, &ArgChanged))
2762 return ExprError();
2763
2764 // If this was list initialization, revert to list form.
2765 if (Construct->isListInitialization())
2766 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2767 Construct->getLocEnd(),
2768 Construct->getType());
2769
Richard Smithc83c2302012-12-19 01:39:02 +00002770 // Build a ParenListExpr to represent anything else.
Enea Zaffanella1245a542013-09-07 05:49:53 +00002771 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smithc83c2302012-12-19 01:39:02 +00002772 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2773 Parens.getEnd());
2774}
2775
2776template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00002777bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2778 unsigned NumInputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002779 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002780 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002781 bool *ArgChanged) {
2782 for (unsigned I = 0; I != NumInputs; ++I) {
2783 // If requested, drop call arguments that need to be dropped.
2784 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2785 if (ArgChanged)
2786 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002787
Douglas Gregoraa165f82011-01-03 19:04:46 +00002788 break;
2789 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002790
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002791 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2792 Expr *Pattern = Expansion->getPattern();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002793
Chris Lattner686775d2011-07-20 06:58:45 +00002794 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002795 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2796 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002797
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002798 // Determine whether the set of unexpanded parameter packs can and should
2799 // be expanded.
2800 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002801 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00002802 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2803 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002804 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2805 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002806 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002807 Expand, RetainExpansion,
2808 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002809 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002810
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002811 if (!Expand) {
2812 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00002813 // transformation on the pack expansion, producing another pack
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002814 // expansion.
2815 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2816 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2817 if (OutPattern.isInvalid())
2818 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002819
2820 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002821 Expansion->getEllipsisLoc(),
2822 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002823 if (Out.isInvalid())
2824 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002825
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002826 if (ArgChanged)
2827 *ArgChanged = true;
2828 Outputs.push_back(Out.get());
2829 continue;
2830 }
John McCallc8fc90a2011-07-06 07:30:07 +00002831
2832 // Record right away that the argument was changed. This needs
2833 // to happen even if the array expands to nothing.
2834 if (ArgChanged) *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002835
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002836 // The transform has determined that we should perform an elementwise
2837 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002838 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002839 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2840 ExprResult Out = getDerived().TransformExpr(Pattern);
2841 if (Out.isInvalid())
2842 return true;
2843
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002844 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002845 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2846 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002847 if (Out.isInvalid())
2848 return true;
2849 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002850
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002851 Outputs.push_back(Out.get());
2852 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002853
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002854 continue;
2855 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002856
Richard Smithc83c2302012-12-19 01:39:02 +00002857 ExprResult Result =
2858 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
2859 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregoraa165f82011-01-03 19:04:46 +00002860 if (Result.isInvalid())
2861 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002862
Douglas Gregoraa165f82011-01-03 19:04:46 +00002863 if (Result.get() != Inputs[I] && ArgChanged)
2864 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002865
2866 Outputs.push_back(Result.get());
Douglas Gregoraa165f82011-01-03 19:04:46 +00002867 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002868
Douglas Gregoraa165f82011-01-03 19:04:46 +00002869 return false;
2870}
2871
2872template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002873NestedNameSpecifierLoc
2874TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2875 NestedNameSpecifierLoc NNS,
2876 QualType ObjectType,
2877 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002878 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002879 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002880 Qualifier = Qualifier.getPrefix())
2881 Qualifiers.push_back(Qualifier);
2882
2883 CXXScopeSpec SS;
2884 while (!Qualifiers.empty()) {
2885 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2886 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002887
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002888 switch (QNNS->getKind()) {
2889 case NestedNameSpecifier::Identifier:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002890 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002891 *QNNS->getAsIdentifier(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002892 Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002893 Q.getLocalEndLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002894 ObjectType, false, SS,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002895 FirstQualifierInScope, false))
2896 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002897
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002898 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002899
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002900 case NestedNameSpecifier::Namespace: {
2901 NamespaceDecl *NS
2902 = cast_or_null<NamespaceDecl>(
2903 getDerived().TransformDecl(
2904 Q.getLocalBeginLoc(),
2905 QNNS->getAsNamespace()));
2906 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2907 break;
2908 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002909
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002910 case NestedNameSpecifier::NamespaceAlias: {
2911 NamespaceAliasDecl *Alias
2912 = cast_or_null<NamespaceAliasDecl>(
2913 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2914 QNNS->getAsNamespaceAlias()));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002915 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002916 Q.getLocalEndLoc());
2917 break;
2918 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002919
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002920 case NestedNameSpecifier::Global:
2921 // There is no meaningful transformation that one could perform on the
2922 // global scope.
2923 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2924 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002925
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002926 case NestedNameSpecifier::TypeSpecWithTemplate:
2927 case NestedNameSpecifier::TypeSpec: {
2928 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2929 FirstQualifierInScope, SS);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002930
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002931 if (!TL)
2932 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002933
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002934 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith80ad52f2013-01-02 11:42:31 +00002935 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002936 TL.getType()->isEnumeralType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002937 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002938 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002939 if (TL.getType()->isEnumeralType())
2940 SemaRef.Diag(TL.getBeginLoc(),
2941 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002942 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2943 Q.getLocalEndLoc());
2944 break;
2945 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002946 // If the nested-name-specifier is an invalid type def, don't emit an
2947 // error because a previous error should have already been emitted.
David Blaikie39e6ab42013-02-18 22:06:02 +00002948 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
2949 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002950 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieu00c93a12011-05-07 01:36:37 +00002951 << TL.getType() << SS.getRange();
2952 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002953 return NestedNameSpecifierLoc();
2954 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002955 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002956
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002957 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002958 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002959 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002960 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002961
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002962 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002963 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002964 !getDerived().AlwaysRebuild())
2965 return NNS;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002966
2967 // If we can re-use the source-location data from the original
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002968 // nested-name-specifier, do so.
2969 if (SS.location_size() == NNS.getDataLength() &&
2970 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2971 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2972
2973 // Allocate new nested-name-specifier location information.
2974 return SS.getWithLocInContext(SemaRef.Context);
2975}
2976
2977template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002978DeclarationNameInfo
2979TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002980::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002981 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002982 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002983 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002984
2985 switch (Name.getNameKind()) {
2986 case DeclarationName::Identifier:
2987 case DeclarationName::ObjCZeroArgSelector:
2988 case DeclarationName::ObjCOneArgSelector:
2989 case DeclarationName::ObjCMultiArgSelector:
2990 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002991 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002992 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002993 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002994
Douglas Gregor81499bb2009-09-03 22:13:48 +00002995 case DeclarationName::CXXConstructorName:
2996 case DeclarationName::CXXDestructorName:
2997 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002998 TypeSourceInfo *NewTInfo;
2999 CanQualType NewCanTy;
3000 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00003001 NewTInfo = getDerived().TransformType(OldTInfo);
3002 if (!NewTInfo)
3003 return DeclarationNameInfo();
3004 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00003005 }
3006 else {
3007 NewTInfo = 0;
3008 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00003009 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00003010 if (NewT.isNull())
3011 return DeclarationNameInfo();
3012 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3013 }
Mike Stump1eb44332009-09-09 15:08:12 +00003014
Abramo Bagnara25777432010-08-11 22:01:17 +00003015 DeclarationName NewName
3016 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3017 NewCanTy);
3018 DeclarationNameInfo NewNameInfo(NameInfo);
3019 NewNameInfo.setName(NewName);
3020 NewNameInfo.setNamedTypeInfo(NewTInfo);
3021 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00003022 }
Mike Stump1eb44332009-09-09 15:08:12 +00003023 }
3024
David Blaikieb219cfc2011-09-23 05:06:16 +00003025 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00003026}
3027
3028template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003029TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003030TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3031 TemplateName Name,
3032 SourceLocation NameLoc,
3033 QualType ObjectType,
3034 NamedDecl *FirstQualifierInScope) {
3035 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3036 TemplateDecl *Template = QTN->getTemplateDecl();
3037 assert(Template && "qualified template name must refer to a template");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003038
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003039 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00003040 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003041 Template));
3042 if (!TransTemplate)
3043 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003044
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003045 if (!getDerived().AlwaysRebuild() &&
3046 SS.getScopeRep() == QTN->getQualifier() &&
3047 TransTemplate == Template)
3048 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003049
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003050 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3051 TransTemplate);
3052 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003053
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003054 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3055 if (SS.getScopeRep()) {
3056 // These apply to the scope specifier, not the template.
3057 ObjectType = QualType();
3058 FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003059 }
3060
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003061 if (!getDerived().AlwaysRebuild() &&
3062 SS.getScopeRep() == DTN->getQualifier() &&
3063 ObjectType.isNull())
3064 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003065
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003066 if (DTN->isIdentifier()) {
3067 return getDerived().RebuildTemplateName(SS,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003068 *DTN->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003069 NameLoc,
3070 ObjectType,
3071 FirstQualifierInScope);
3072 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003073
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003074 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3075 ObjectType);
3076 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003077
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003078 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3079 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00003080 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003081 Template));
3082 if (!TransTemplate)
3083 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003084
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003085 if (!getDerived().AlwaysRebuild() &&
3086 TransTemplate == Template)
3087 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003088
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003089 return TemplateName(TransTemplate);
3090 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003091
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003092 if (SubstTemplateTemplateParmPackStorage *SubstPack
3093 = Name.getAsSubstTemplateTemplateParmPack()) {
3094 TemplateTemplateParmDecl *TransParam
3095 = cast_or_null<TemplateTemplateParmDecl>(
3096 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3097 if (!TransParam)
3098 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003099
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003100 if (!getDerived().AlwaysRebuild() &&
3101 TransParam == SubstPack->getParameterPack())
3102 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003103
3104 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003105 SubstPack->getArgumentPack());
3106 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003107
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003108 // These should be getting filtered out before they reach the AST.
3109 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003110}
3111
3112template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00003113void TreeTransform<Derived>::InventTemplateArgumentLoc(
3114 const TemplateArgument &Arg,
3115 TemplateArgumentLoc &Output) {
3116 SourceLocation Loc = getDerived().getBaseLocation();
3117 switch (Arg.getKind()) {
3118 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003119 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00003120 break;
3121
3122 case TemplateArgument::Type:
3123 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00003124 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier4a9d7952012-08-08 18:46:20 +00003125
John McCall833ca992009-10-29 08:12:44 +00003126 break;
3127
Douglas Gregor788cd062009-11-11 01:00:40 +00003128 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003129 case TemplateArgument::TemplateExpansion: {
3130 NestedNameSpecifierLocBuilder Builder;
3131 TemplateName Template = Arg.getAsTemplate();
3132 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3133 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3134 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3135 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003136
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003137 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier4a9d7952012-08-08 18:46:20 +00003138 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003139 Builder.getWithLocInContext(SemaRef.Context),
3140 Loc);
3141 else
Chad Rosier4a9d7952012-08-08 18:46:20 +00003142 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003143 Builder.getWithLocInContext(SemaRef.Context),
3144 Loc, Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003145
Douglas Gregor788cd062009-11-11 01:00:40 +00003146 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003147 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003148
John McCall833ca992009-10-29 08:12:44 +00003149 case TemplateArgument::Expression:
3150 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3151 break;
3152
3153 case TemplateArgument::Declaration:
3154 case TemplateArgument::Integral:
3155 case TemplateArgument::Pack:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003156 case TemplateArgument::NullPtr:
John McCall828bff22009-10-29 18:45:58 +00003157 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00003158 break;
3159 }
3160}
3161
3162template<typename Derived>
3163bool TreeTransform<Derived>::TransformTemplateArgument(
3164 const TemplateArgumentLoc &Input,
3165 TemplateArgumentLoc &Output) {
3166 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00003167 switch (Arg.getKind()) {
3168 case TemplateArgument::Null:
3169 case TemplateArgument::Integral:
Eli Friedman511e3ae2012-09-25 01:02:42 +00003170 case TemplateArgument::Pack:
3171 case TemplateArgument::Declaration:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003172 case TemplateArgument::NullPtr:
3173 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump1eb44332009-09-09 15:08:12 +00003174
Douglas Gregor670444e2009-08-04 22:27:00 +00003175 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00003176 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00003177 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00003178 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00003179
3180 DI = getDerived().TransformType(DI);
3181 if (!DI) return true;
3182
3183 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3184 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003185 }
Mike Stump1eb44332009-09-09 15:08:12 +00003186
Douglas Gregor788cd062009-11-11 01:00:40 +00003187 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003188 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3189 if (QualifierLoc) {
3190 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3191 if (!QualifierLoc)
3192 return true;
3193 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003194
Douglas Gregor1d752d72011-03-02 18:46:51 +00003195 CXXScopeSpec SS;
3196 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00003197 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00003198 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3199 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00003200 if (Template.isNull())
3201 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003202
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003203 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00003204 Input.getTemplateNameLoc());
3205 return false;
3206 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003207
3208 case TemplateArgument::TemplateExpansion:
3209 llvm_unreachable("Caller should expand pack expansions");
3210
Douglas Gregor670444e2009-08-04 22:27:00 +00003211 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00003212 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00003213 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003214 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003215
John McCall833ca992009-10-29 08:12:44 +00003216 Expr *InputExpr = Input.getSourceExpression();
3217 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3218
Chris Lattner223de242011-04-25 20:37:58 +00003219 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003220 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00003221 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00003222 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00003223 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003224 }
Douglas Gregor670444e2009-08-04 22:27:00 +00003225 }
Mike Stump1eb44332009-09-09 15:08:12 +00003226
Douglas Gregor670444e2009-08-04 22:27:00 +00003227 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003228 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003229}
3230
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003231/// \brief Iterator adaptor that invents template argument location information
3232/// for each of the template arguments in its underlying iterator.
3233template<typename Derived, typename InputIterator>
3234class TemplateArgumentLocInventIterator {
3235 TreeTransform<Derived> &Self;
3236 InputIterator Iter;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003237
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003238public:
3239 typedef TemplateArgumentLoc value_type;
3240 typedef TemplateArgumentLoc reference;
3241 typedef typename std::iterator_traits<InputIterator>::difference_type
3242 difference_type;
3243 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003244
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003245 class pointer {
3246 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003247
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003248 public:
3249 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003250
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003251 const TemplateArgumentLoc *operator->() const { return &Arg; }
3252 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00003253
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003254 TemplateArgumentLocInventIterator() { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003255
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003256 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3257 InputIterator Iter)
3258 : Self(Self), Iter(Iter) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003259
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003260 TemplateArgumentLocInventIterator &operator++() {
3261 ++Iter;
3262 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003263 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003264
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003265 TemplateArgumentLocInventIterator operator++(int) {
3266 TemplateArgumentLocInventIterator Old(*this);
3267 ++(*this);
3268 return Old;
3269 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003270
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003271 reference operator*() const {
3272 TemplateArgumentLoc Result;
3273 Self.InventTemplateArgumentLoc(*Iter, Result);
3274 return Result;
3275 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003276
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003277 pointer operator->() const { return pointer(**this); }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003278
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003279 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3280 const TemplateArgumentLocInventIterator &Y) {
3281 return X.Iter == Y.Iter;
3282 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003283
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003284 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3285 const TemplateArgumentLocInventIterator &Y) {
3286 return X.Iter != Y.Iter;
3287 }
3288};
Chad Rosier4a9d7952012-08-08 18:46:20 +00003289
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003290template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003291template<typename InputIterator>
3292bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3293 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003294 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003295 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003296 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003297 TemplateArgumentLoc In = *First;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003298
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003299 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3300 // Unpack argument packs, which we translate them into separate
3301 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003302 // FIXME: We could do much better if we could guarantee that the
3303 // TemplateArgumentLocInfo for the pack expansion would be usable for
3304 // all of the template arguments in the argument pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003305 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003306 TemplateArgument::pack_iterator>
3307 PackLocIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003308 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003309 In.getArgument().pack_begin()),
3310 PackLocIterator(*this,
3311 In.getArgument().pack_end()),
3312 Outputs))
3313 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003314
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003315 continue;
3316 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003317
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003318 if (In.getArgument().isPackExpansion()) {
3319 // We have a pack expansion, for which we will be substituting into
3320 // the pattern.
3321 SourceLocation Ellipsis;
David Blaikiedc84cd52013-02-20 22:23:23 +00003322 Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003323 TemplateArgumentLoc Pattern
Eli Friedman850cf512013-06-20 04:11:21 +00003324 = getSema().getTemplateArgumentPackExpansionPattern(
3325 In, Ellipsis, OrigNumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003326
Chris Lattner686775d2011-07-20 06:58:45 +00003327 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003328 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3329 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003330
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003331 // Determine whether the set of unexpanded parameter packs can and should
3332 // be expanded.
3333 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003334 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00003335 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003336 if (getDerived().TryExpandParameterPacks(Ellipsis,
3337 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003338 Unexpanded,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003339 Expand,
Douglas Gregord3731192011-01-10 07:32:04 +00003340 RetainExpansion,
3341 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003342 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003343
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003344 if (!Expand) {
3345 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00003346 // transformation on the pack expansion, producing another pack
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003347 // expansion.
3348 TemplateArgumentLoc OutPattern;
3349 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3350 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3351 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003352
Douglas Gregorcded4f62011-01-14 17:04:44 +00003353 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3354 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003355 if (Out.getArgument().isNull())
3356 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003357
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003358 Outputs.addArgument(Out);
3359 continue;
3360 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003361
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003362 // The transform has determined that we should perform an elementwise
3363 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003364 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003365 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3366
3367 if (getDerived().TransformTemplateArgument(Pattern, Out))
3368 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003369
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003370 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003371 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3372 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003373 if (Out.getArgument().isNull())
3374 return true;
3375 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003376
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003377 Outputs.addArgument(Out);
3378 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003379
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003380 // If we're supposed to retain a pack expansion, do so by temporarily
3381 // forgetting the partially-substituted parameter pack.
3382 if (RetainExpansion) {
3383 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003384
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003385 if (getDerived().TransformTemplateArgument(Pattern, Out))
3386 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003387
Douglas Gregorcded4f62011-01-14 17:04:44 +00003388 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3389 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003390 if (Out.getArgument().isNull())
3391 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003392
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003393 Outputs.addArgument(Out);
3394 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003395
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003396 continue;
3397 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003398
3399 // The simple case:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003400 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003401 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003402
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003403 Outputs.addArgument(Out);
3404 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003405
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003406 return false;
3407
3408}
3409
Douglas Gregor577f75a2009-08-04 16:50:30 +00003410//===----------------------------------------------------------------------===//
3411// Type transformation
3412//===----------------------------------------------------------------------===//
3413
3414template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003415QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003416 if (getDerived().AlreadyTransformed(T))
3417 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003418
John McCalla2becad2009-10-21 00:40:46 +00003419 // Temporary workaround. All of these transformations should
3420 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003421 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3422 getDerived().getBaseLocation());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003423
John McCall43fed0d2010-11-12 08:19:04 +00003424 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003425
John McCalla2becad2009-10-21 00:40:46 +00003426 if (!NewDI)
3427 return QualType();
3428
3429 return NewDI->getType();
3430}
3431
3432template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003433TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003434 // Refine the base location to the type's location.
3435 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3436 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003437 if (getDerived().AlreadyTransformed(DI->getType()))
3438 return DI;
3439
3440 TypeLocBuilder TLB;
3441
3442 TypeLoc TL = DI->getTypeLoc();
3443 TLB.reserve(TL.getFullDataSize());
3444
John McCall43fed0d2010-11-12 08:19:04 +00003445 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003446 if (Result.isNull())
3447 return 0;
3448
John McCalla93c9342009-12-07 02:54:59 +00003449 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003450}
3451
3452template<typename Derived>
3453QualType
John McCall43fed0d2010-11-12 08:19:04 +00003454TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003455 switch (T.getTypeLocClass()) {
3456#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie39e6ab42013-02-18 22:06:02 +00003457#define TYPELOC(CLASS, PARENT) \
3458 case TypeLoc::CLASS: \
3459 return getDerived().Transform##CLASS##Type(TLB, \
3460 T.castAs<CLASS##TypeLoc>());
John McCalla2becad2009-10-21 00:40:46 +00003461#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003462 }
Mike Stump1eb44332009-09-09 15:08:12 +00003463
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003464 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003465}
3466
3467/// FIXME: By default, this routine adds type qualifiers only to types
3468/// that can have qualifiers, and silently suppresses those qualifiers
3469/// that are not permitted (e.g., qualifiers on reference or function
3470/// types). This is the right thing for template instantiation, but
3471/// probably not for other clients.
3472template<typename Derived>
3473QualType
3474TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003475 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003476 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003477
John McCall43fed0d2010-11-12 08:19:04 +00003478 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003479 if (Result.isNull())
3480 return QualType();
3481
3482 // Silently suppress qualifiers if the result type can't be qualified.
3483 // FIXME: this is the right thing for template instantiation, but
3484 // probably not for other clients.
3485 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003486 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003487
John McCallf85e1932011-06-15 23:02:42 +00003488 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003489 // resulting type.
3490 if (Quals.hasObjCLifetime()) {
3491 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3492 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003493 else if (Result.getObjCLifetime()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003494 // Objective-C ARC:
Douglas Gregore559ca12011-06-17 22:11:49 +00003495 // A lifetime qualifier applied to a substituted template parameter
3496 // overrides the lifetime qualifier from the template argument.
Douglas Gregor92d13872013-01-17 23:59:28 +00003497 const AutoType *AutoTy;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003498 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore559ca12011-06-17 22:11:49 +00003499 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3500 QualType Replacement = SubstTypeParam->getReplacementType();
3501 Qualifiers Qs = Replacement.getQualifiers();
3502 Qs.removeObjCLifetime();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003503 Replacement
Douglas Gregore559ca12011-06-17 22:11:49 +00003504 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3505 Qs);
3506 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier4a9d7952012-08-08 18:46:20 +00003507 SubstTypeParam->getReplacedParameter(),
Douglas Gregore559ca12011-06-17 22:11:49 +00003508 Replacement);
3509 TLB.TypeWasModifiedSafely(Result);
Douglas Gregor92d13872013-01-17 23:59:28 +00003510 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3511 // 'auto' types behave the same way as template parameters.
3512 QualType Deduced = AutoTy->getDeducedType();
3513 Qualifiers Qs = Deduced.getQualifiers();
3514 Qs.removeObjCLifetime();
3515 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3516 Qs);
Manuel Klimek152b4e42013-08-22 12:12:24 +00003517 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto());
Douglas Gregor92d13872013-01-17 23:59:28 +00003518 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore559ca12011-06-17 22:11:49 +00003519 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003520 // Otherwise, complain about the addition of a qualifier to an
3521 // already-qualified type.
Eli Friedman44ee0a72013-06-07 20:31:48 +00003522 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003523 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003524 << Result << R;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003525
Douglas Gregore559ca12011-06-17 22:11:49 +00003526 Quals.removeObjCLifetime();
3527 }
3528 }
3529 }
John McCall28654742010-06-05 06:41:15 +00003530 if (!Quals.empty()) {
3531 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smith9807a2e2013-03-27 23:36:39 +00003532 // BuildQualifiedType might not add qualifiers if they are invalid.
3533 if (Result.hasLocalQualifiers())
3534 TLB.push<QualifiedTypeLoc>(Result);
John McCall28654742010-06-05 06:41:15 +00003535 // No location information to preserve.
3536 }
John McCalla2becad2009-10-21 00:40:46 +00003537
3538 return Result;
3539}
3540
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003541template<typename Derived>
3542TypeLoc
3543TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3544 QualType ObjectType,
3545 NamedDecl *UnqualLookup,
3546 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003547 QualType T = TL.getType();
3548 if (getDerived().AlreadyTransformed(T))
3549 return TL;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003550
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003551 TypeLocBuilder TLB;
3552 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003553
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003554 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003555 TemplateSpecializationTypeLoc SpecTL =
3556 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003557
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003558 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003559 getDerived().TransformTemplateName(SS,
3560 SpecTL.getTypePtr()->getTemplateName(),
3561 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003562 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003563 if (Template.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003564 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003565
3566 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003567 Template);
3568 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003569 DependentTemplateSpecializationTypeLoc SpecTL =
3570 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003571
Douglas Gregora88f09f2011-02-28 17:23:35 +00003572 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003573 = getDerived().RebuildTemplateName(SS,
3574 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003575 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003576 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003577 if (Template.isNull())
3578 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003579
3580 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003581 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003582 Template,
3583 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003584 } else {
3585 // Nothing special needs to be done for these.
3586 Result = getDerived().TransformType(TLB, TL);
3587 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003588
3589 if (Result.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003590 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003591
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003592 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3593}
3594
Douglas Gregorb71d8212011-03-02 18:32:08 +00003595template<typename Derived>
3596TypeSourceInfo *
3597TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3598 QualType ObjectType,
3599 NamedDecl *UnqualLookup,
3600 CXXScopeSpec &SS) {
3601 // FIXME: Painfully copy-paste from the above!
Chad Rosier4a9d7952012-08-08 18:46:20 +00003602
Douglas Gregorb71d8212011-03-02 18:32:08 +00003603 QualType T = TSInfo->getType();
3604 if (getDerived().AlreadyTransformed(T))
3605 return TSInfo;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003606
Douglas Gregorb71d8212011-03-02 18:32:08 +00003607 TypeLocBuilder TLB;
3608 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003609
Douglas Gregorb71d8212011-03-02 18:32:08 +00003610 TypeLoc TL = TSInfo->getTypeLoc();
3611 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003612 TemplateSpecializationTypeLoc SpecTL =
3613 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003614
Douglas Gregorb71d8212011-03-02 18:32:08 +00003615 TemplateName Template
3616 = getDerived().TransformTemplateName(SS,
3617 SpecTL.getTypePtr()->getTemplateName(),
3618 SpecTL.getTemplateNameLoc(),
3619 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003620 if (Template.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003621 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003622
3623 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003624 Template);
3625 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003626 DependentTemplateSpecializationTypeLoc SpecTL =
3627 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003628
Douglas Gregorb71d8212011-03-02 18:32:08 +00003629 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003630 = getDerived().RebuildTemplateName(SS,
3631 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003632 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003633 ObjectType, UnqualLookup);
3634 if (Template.isNull())
3635 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003636
3637 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003638 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003639 Template,
3640 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003641 } else {
3642 // Nothing special needs to be done for these.
3643 Result = getDerived().TransformType(TLB, TL);
3644 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003645
3646 if (Result.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003647 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003648
Douglas Gregorb71d8212011-03-02 18:32:08 +00003649 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3650}
3651
John McCalla2becad2009-10-21 00:40:46 +00003652template <class TyLoc> static inline
3653QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3654 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3655 NewT.setNameLoc(T.getNameLoc());
3656 return T.getType();
3657}
3658
John McCalla2becad2009-10-21 00:40:46 +00003659template<typename Derived>
3660QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003661 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003662 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3663 NewT.setBuiltinLoc(T.getBuiltinLoc());
3664 if (T.needsExtraLocalData())
3665 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3666 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003667}
Mike Stump1eb44332009-09-09 15:08:12 +00003668
Douglas Gregor577f75a2009-08-04 16:50:30 +00003669template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003670QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003671 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003672 // FIXME: recurse?
3673 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003674}
Mike Stump1eb44332009-09-09 15:08:12 +00003675
Douglas Gregor577f75a2009-08-04 16:50:30 +00003676template<typename Derived>
Reid Kleckner12df2462013-06-24 17:51:48 +00003677QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3678 DecayedTypeLoc TL) {
3679 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3680 if (OriginalType.isNull())
3681 return QualType();
3682
3683 QualType Result = TL.getType();
3684 if (getDerived().AlwaysRebuild() ||
3685 OriginalType != TL.getOriginalLoc().getType())
3686 Result = SemaRef.Context.getDecayedType(OriginalType);
3687 TLB.push<DecayedTypeLoc>(Result);
3688 // Nothing to set for DecayedTypeLoc.
3689 return Result;
3690}
3691
3692template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003693QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003694 PointerTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003695 QualType PointeeType
3696 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003697 if (PointeeType.isNull())
3698 return QualType();
3699
3700 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003701 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003702 // A dependent pointer type 'T *' has is being transformed such
3703 // that an Objective-C class type is being replaced for 'T'. The
3704 // resulting pointer type is an ObjCObjectPointerType, not a
3705 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003706 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003707
John McCallc12c5bb2010-05-15 11:32:37 +00003708 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3709 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003710 return Result;
3711 }
John McCall43fed0d2010-11-12 08:19:04 +00003712
Douglas Gregor92e986e2010-04-22 16:44:27 +00003713 if (getDerived().AlwaysRebuild() ||
3714 PointeeType != TL.getPointeeLoc().getType()) {
3715 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3716 if (Result.isNull())
3717 return QualType();
3718 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003719
John McCallf85e1932011-06-15 23:02:42 +00003720 // Objective-C ARC can add lifetime qualifiers to the type that we're
3721 // pointing to.
3722 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003723
Douglas Gregor92e986e2010-04-22 16:44:27 +00003724 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3725 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003726 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003727}
Mike Stump1eb44332009-09-09 15:08:12 +00003728
3729template<typename Derived>
3730QualType
John McCalla2becad2009-10-21 00:40:46 +00003731TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003732 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003733 QualType PointeeType
Chad Rosier4a9d7952012-08-08 18:46:20 +00003734 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3735 if (PointeeType.isNull())
3736 return QualType();
3737
3738 QualType Result = TL.getType();
3739 if (getDerived().AlwaysRebuild() ||
3740 PointeeType != TL.getPointeeLoc().getType()) {
3741 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003742 TL.getSigilLoc());
3743 if (Result.isNull())
3744 return QualType();
3745 }
3746
Douglas Gregor39968ad2010-04-22 16:50:51 +00003747 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003748 NewT.setSigilLoc(TL.getSigilLoc());
3749 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003750}
3751
John McCall85737a72009-10-30 00:06:24 +00003752/// Transforms a reference type. Note that somewhat paradoxically we
3753/// don't care whether the type itself is an l-value type or an r-value
3754/// type; we only care if the type was *written* as an l-value type
3755/// or an r-value type.
3756template<typename Derived>
3757QualType
3758TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003759 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003760 const ReferenceType *T = TL.getTypePtr();
3761
3762 // Note that this works with the pointee-as-written.
3763 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3764 if (PointeeType.isNull())
3765 return QualType();
3766
3767 QualType Result = TL.getType();
3768 if (getDerived().AlwaysRebuild() ||
3769 PointeeType != T->getPointeeTypeAsWritten()) {
3770 Result = getDerived().RebuildReferenceType(PointeeType,
3771 T->isSpelledAsLValue(),
3772 TL.getSigilLoc());
3773 if (Result.isNull())
3774 return QualType();
3775 }
3776
John McCallf85e1932011-06-15 23:02:42 +00003777 // Objective-C ARC can add lifetime qualifiers to the type that we're
3778 // referring to.
3779 TLB.TypeWasModifiedSafely(
3780 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3781
John McCall85737a72009-10-30 00:06:24 +00003782 // r-value references can be rebuilt as l-value references.
3783 ReferenceTypeLoc NewTL;
3784 if (isa<LValueReferenceType>(Result))
3785 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3786 else
3787 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3788 NewTL.setSigilLoc(TL.getSigilLoc());
3789
3790 return Result;
3791}
3792
Mike Stump1eb44332009-09-09 15:08:12 +00003793template<typename Derived>
3794QualType
John McCalla2becad2009-10-21 00:40:46 +00003795TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003796 LValueReferenceTypeLoc TL) {
3797 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003798}
3799
Mike Stump1eb44332009-09-09 15:08:12 +00003800template<typename Derived>
3801QualType
John McCalla2becad2009-10-21 00:40:46 +00003802TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003803 RValueReferenceTypeLoc TL) {
3804 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003805}
Mike Stump1eb44332009-09-09 15:08:12 +00003806
Douglas Gregor577f75a2009-08-04 16:50:30 +00003807template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003808QualType
John McCalla2becad2009-10-21 00:40:46 +00003809TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003810 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003811 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003812 if (PointeeType.isNull())
3813 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003814
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003815 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3816 TypeSourceInfo* NewClsTInfo = 0;
3817 if (OldClsTInfo) {
3818 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3819 if (!NewClsTInfo)
3820 return QualType();
3821 }
3822
3823 const MemberPointerType *T = TL.getTypePtr();
3824 QualType OldClsType = QualType(T->getClass(), 0);
3825 QualType NewClsType;
3826 if (NewClsTInfo)
3827 NewClsType = NewClsTInfo->getType();
3828 else {
3829 NewClsType = getDerived().TransformType(OldClsType);
3830 if (NewClsType.isNull())
3831 return QualType();
3832 }
Mike Stump1eb44332009-09-09 15:08:12 +00003833
John McCalla2becad2009-10-21 00:40:46 +00003834 QualType Result = TL.getType();
3835 if (getDerived().AlwaysRebuild() ||
3836 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003837 NewClsType != OldClsType) {
3838 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003839 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003840 if (Result.isNull())
3841 return QualType();
3842 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003843
John McCalla2becad2009-10-21 00:40:46 +00003844 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3845 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003846 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003847
3848 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003849}
3850
Mike Stump1eb44332009-09-09 15:08:12 +00003851template<typename Derived>
3852QualType
John McCalla2becad2009-10-21 00:40:46 +00003853TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003854 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003855 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003856 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003857 if (ElementType.isNull())
3858 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003859
John McCalla2becad2009-10-21 00:40:46 +00003860 QualType Result = TL.getType();
3861 if (getDerived().AlwaysRebuild() ||
3862 ElementType != T->getElementType()) {
3863 Result = getDerived().RebuildConstantArrayType(ElementType,
3864 T->getSizeModifier(),
3865 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003866 T->getIndexTypeCVRQualifiers(),
3867 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003868 if (Result.isNull())
3869 return QualType();
3870 }
Eli Friedman457a3772012-01-25 22:19:07 +00003871
3872 // We might have either a ConstantArrayType or a VariableArrayType now:
3873 // a ConstantArrayType is allowed to have an element type which is a
3874 // VariableArrayType if the type is dependent. Fortunately, all array
3875 // types have the same location layout.
3876 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003877 NewTL.setLBracketLoc(TL.getLBracketLoc());
3878 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003879
John McCalla2becad2009-10-21 00:40:46 +00003880 Expr *Size = TL.getSizeExpr();
3881 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003882 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3883 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003884 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003885 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003886 }
3887 NewTL.setSizeExpr(Size);
3888
3889 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003890}
Mike Stump1eb44332009-09-09 15:08:12 +00003891
Douglas Gregor577f75a2009-08-04 16:50:30 +00003892template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003893QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003894 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003895 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003896 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003897 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003898 if (ElementType.isNull())
3899 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003900
John McCalla2becad2009-10-21 00:40:46 +00003901 QualType Result = TL.getType();
3902 if (getDerived().AlwaysRebuild() ||
3903 ElementType != T->getElementType()) {
3904 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003905 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003906 T->getIndexTypeCVRQualifiers(),
3907 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003908 if (Result.isNull())
3909 return QualType();
3910 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003911
John McCalla2becad2009-10-21 00:40:46 +00003912 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3913 NewTL.setLBracketLoc(TL.getLBracketLoc());
3914 NewTL.setRBracketLoc(TL.getRBracketLoc());
3915 NewTL.setSizeExpr(0);
3916
3917 return Result;
3918}
3919
3920template<typename Derived>
3921QualType
3922TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003923 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003924 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003925 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3926 if (ElementType.isNull())
3927 return QualType();
3928
John McCall60d7b3a2010-08-24 06:29:42 +00003929 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003930 = getDerived().TransformExpr(T->getSizeExpr());
3931 if (SizeResult.isInvalid())
3932 return QualType();
3933
John McCall9ae2f072010-08-23 23:25:46 +00003934 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003935
3936 QualType Result = TL.getType();
3937 if (getDerived().AlwaysRebuild() ||
3938 ElementType != T->getElementType() ||
3939 Size != T->getSizeExpr()) {
3940 Result = getDerived().RebuildVariableArrayType(ElementType,
3941 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003942 Size,
John McCalla2becad2009-10-21 00:40:46 +00003943 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003944 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003945 if (Result.isNull())
3946 return QualType();
3947 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003948
John McCalla2becad2009-10-21 00:40:46 +00003949 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3950 NewTL.setLBracketLoc(TL.getLBracketLoc());
3951 NewTL.setRBracketLoc(TL.getRBracketLoc());
3952 NewTL.setSizeExpr(Size);
3953
3954 return Result;
3955}
3956
3957template<typename Derived>
3958QualType
3959TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003960 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003961 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003962 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3963 if (ElementType.isNull())
3964 return QualType();
3965
Richard Smithf6702a32011-12-20 02:08:33 +00003966 // Array bounds are constant expressions.
3967 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3968 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003969
John McCall3b657512011-01-19 10:06:00 +00003970 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3971 Expr *origSize = TL.getSizeExpr();
3972 if (!origSize) origSize = T->getSizeExpr();
3973
3974 ExprResult sizeResult
3975 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003976 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003977 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003978 return QualType();
3979
John McCall3b657512011-01-19 10:06:00 +00003980 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003981
3982 QualType Result = TL.getType();
3983 if (getDerived().AlwaysRebuild() ||
3984 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003985 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003986 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3987 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003988 size,
John McCalla2becad2009-10-21 00:40:46 +00003989 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003990 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003991 if (Result.isNull())
3992 return QualType();
3993 }
John McCalla2becad2009-10-21 00:40:46 +00003994
3995 // We might have any sort of array type now, but fortunately they
3996 // all have the same location layout.
3997 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3998 NewTL.setLBracketLoc(TL.getLBracketLoc());
3999 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00004000 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00004001
4002 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004003}
Mike Stump1eb44332009-09-09 15:08:12 +00004004
4005template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00004006QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00004007 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004008 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004009 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004010
4011 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00004012 QualType ElementType = getDerived().TransformType(T->getElementType());
4013 if (ElementType.isNull())
4014 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004015
Richard Smithf6702a32011-12-20 02:08:33 +00004016 // Vector sizes are constant expressions.
4017 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4018 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00004019
John McCall60d7b3a2010-08-24 06:29:42 +00004020 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00004021 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004022 if (Size.isInvalid())
4023 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004024
John McCalla2becad2009-10-21 00:40:46 +00004025 QualType Result = TL.getType();
4026 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00004027 ElementType != T->getElementType() ||
4028 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00004029 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00004030 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00004031 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00004032 if (Result.isNull())
4033 return QualType();
4034 }
John McCalla2becad2009-10-21 00:40:46 +00004035
4036 // Result might be dependent or not.
4037 if (isa<DependentSizedExtVectorType>(Result)) {
4038 DependentSizedExtVectorTypeLoc NewTL
4039 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4040 NewTL.setNameLoc(TL.getNameLoc());
4041 } else {
4042 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4043 NewTL.setNameLoc(TL.getNameLoc());
4044 }
4045
4046 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004047}
Mike Stump1eb44332009-09-09 15:08:12 +00004048
4049template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004050QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004051 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004052 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004053 QualType ElementType = getDerived().TransformType(T->getElementType());
4054 if (ElementType.isNull())
4055 return QualType();
4056
John McCalla2becad2009-10-21 00:40:46 +00004057 QualType Result = TL.getType();
4058 if (getDerived().AlwaysRebuild() ||
4059 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00004060 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00004061 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00004062 if (Result.isNull())
4063 return QualType();
4064 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004065
John McCalla2becad2009-10-21 00:40:46 +00004066 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4067 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00004068
John McCalla2becad2009-10-21 00:40:46 +00004069 return Result;
4070}
4071
4072template<typename Derived>
4073QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004074 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004075 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004076 QualType ElementType = getDerived().TransformType(T->getElementType());
4077 if (ElementType.isNull())
4078 return QualType();
4079
4080 QualType Result = TL.getType();
4081 if (getDerived().AlwaysRebuild() ||
4082 ElementType != T->getElementType()) {
4083 Result = getDerived().RebuildExtVectorType(ElementType,
4084 T->getNumElements(),
4085 /*FIXME*/ SourceLocation());
4086 if (Result.isNull())
4087 return QualType();
4088 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004089
John McCalla2becad2009-10-21 00:40:46 +00004090 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4091 NewTL.setNameLoc(TL.getNameLoc());
4092
4093 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004094}
Mike Stump1eb44332009-09-09 15:08:12 +00004095
David Blaikiedc84cd52013-02-20 22:23:23 +00004096template <typename Derived>
4097ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4098 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4099 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00004100 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004101 TypeSourceInfo *NewDI = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004102
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004103 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004104 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004105 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004106 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00004107 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004108
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004109 TypeLocBuilder TLB;
4110 TypeLoc NewTL = OldDI->getTypeLoc();
4111 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004112
4113 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004114 OldExpansionTL.getPatternLoc());
4115 if (Result.isNull())
4116 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004117
4118 Result = RebuildPackExpansionType(Result,
4119 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004120 OldExpansionTL.getEllipsisLoc(),
4121 NumExpansions);
4122 if (Result.isNull())
4123 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004124
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004125 PackExpansionTypeLoc NewExpansionTL
4126 = TLB.push<PackExpansionTypeLoc>(Result);
4127 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4128 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4129 } else
4130 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00004131 if (!NewDI)
4132 return 0;
4133
John McCallfb44de92011-05-01 22:35:37 +00004134 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00004135 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00004136
4137 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4138 OldParm->getDeclContext(),
4139 OldParm->getInnerLocStart(),
4140 OldParm->getLocation(),
4141 OldParm->getIdentifier(),
4142 NewDI->getType(),
4143 NewDI,
4144 OldParm->getStorageClass(),
John McCallfb44de92011-05-01 22:35:37 +00004145 /* DefArg */ NULL);
4146 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4147 OldParm->getFunctionScopeIndex() + indexAdjustment);
4148 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00004149}
4150
4151template<typename Derived>
4152bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00004153 TransformFunctionTypeParams(SourceLocation Loc,
4154 ParmVarDecl **Params, unsigned NumParams,
4155 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00004156 SmallVectorImpl<QualType> &OutParamTypes,
4157 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00004158 int indexAdjustment = 0;
4159
Douglas Gregora009b592011-01-07 00:20:55 +00004160 for (unsigned i = 0; i != NumParams; ++i) {
4161 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00004162 assert(OldParm->getFunctionScopeIndex() == i);
4163
David Blaikiedc84cd52013-02-20 22:23:23 +00004164 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004165 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004166 if (OldParm->isParameterPack()) {
4167 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00004168 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00004169
Douglas Gregor603cfb42011-01-05 23:12:31 +00004170 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004171 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00004172 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004173 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4174 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004175 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4176
Douglas Gregor603cfb42011-01-05 23:12:31 +00004177 // Determine whether we should expand the parameter packs.
4178 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004179 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004180 Optional<unsigned> OrigNumExpansions =
4181 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004182 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004183 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4184 Pattern.getSourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004185 Unexpanded,
4186 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004187 RetainExpansion,
4188 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004189 return true;
4190 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004191
Douglas Gregor603cfb42011-01-05 23:12:31 +00004192 if (ShouldExpand) {
4193 // Expand the function parameter pack into multiple, separate
4194 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00004195 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00004196 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004197 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004198 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004199 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004200 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004201 OrigNumExpansions,
4202 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004203 if (!NewParm)
4204 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004205
Douglas Gregora009b592011-01-07 00:20:55 +00004206 OutParamTypes.push_back(NewParm->getType());
4207 if (PVars)
4208 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004209 }
Douglas Gregord3731192011-01-10 07:32:04 +00004210
4211 // If we're supposed to retain a pack expansion, do so by temporarily
4212 // forgetting the partially-substituted parameter pack.
4213 if (RetainExpansion) {
4214 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004215 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004216 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004217 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004218 OrigNumExpansions,
4219 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00004220 if (!NewParm)
4221 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004222
Douglas Gregord3731192011-01-10 07:32:04 +00004223 OutParamTypes.push_back(NewParm->getType());
4224 if (PVars)
4225 PVars->push_back(NewParm);
4226 }
4227
John McCallfb44de92011-05-01 22:35:37 +00004228 // The next parameter should have the same adjustment as the
4229 // last thing we pushed, but we post-incremented indexAdjustment
4230 // on every push. Also, if we push nothing, the adjustment should
4231 // go down by one.
4232 indexAdjustment--;
4233
Douglas Gregor603cfb42011-01-05 23:12:31 +00004234 // We're done with the pack expansion.
4235 continue;
4236 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004237
4238 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004239 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004240 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4241 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004242 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004243 NumExpansions,
4244 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004245 } else {
David Blaikiedc84cd52013-02-20 22:23:23 +00004246 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie66874fb2013-02-21 01:47:18 +00004247 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004248 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004249
John McCall21ef0fa2010-03-11 09:03:00 +00004250 if (!NewParm)
4251 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004252
Douglas Gregora009b592011-01-07 00:20:55 +00004253 OutParamTypes.push_back(NewParm->getType());
4254 if (PVars)
4255 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004256 continue;
4257 }
John McCall21ef0fa2010-03-11 09:03:00 +00004258
4259 // Deal with the possibility that we don't have a parameter
4260 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004261 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004262 bool IsPackExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004263 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004264 QualType NewType;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004265 if (const PackExpansionType *Expansion
Douglas Gregor603cfb42011-01-05 23:12:31 +00004266 = dyn_cast<PackExpansionType>(OldType)) {
4267 // We have a function parameter pack that may need to be expanded.
4268 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004269 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004270 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004271
Douglas Gregor603cfb42011-01-05 23:12:31 +00004272 // Determine whether we should expand the parameter packs.
4273 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004274 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004275 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004276 Unexpanded,
4277 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004278 RetainExpansion,
4279 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004280 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004281 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004282
Douglas Gregor603cfb42011-01-05 23:12:31 +00004283 if (ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004284 // Expand the function parameter pack into multiple, separate
Douglas Gregor603cfb42011-01-05 23:12:31 +00004285 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004286 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004287 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4288 QualType NewType = getDerived().TransformType(Pattern);
4289 if (NewType.isNull())
4290 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004291
Douglas Gregora009b592011-01-07 00:20:55 +00004292 OutParamTypes.push_back(NewType);
4293 if (PVars)
4294 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004295 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004296
Douglas Gregor603cfb42011-01-05 23:12:31 +00004297 // We're done with the pack expansion.
4298 continue;
4299 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004300
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004301 // If we're supposed to retain a pack expansion, do so by temporarily
4302 // forgetting the partially-substituted parameter pack.
4303 if (RetainExpansion) {
4304 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4305 QualType NewType = getDerived().TransformType(Pattern);
4306 if (NewType.isNull())
4307 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004308
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004309 OutParamTypes.push_back(NewType);
4310 if (PVars)
4311 PVars->push_back(0);
4312 }
Douglas Gregord3731192011-01-10 07:32:04 +00004313
Chad Rosier4a9d7952012-08-08 18:46:20 +00004314 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004315 // expansion.
4316 OldType = Expansion->getPattern();
4317 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004318 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4319 NewType = getDerived().TransformType(OldType);
4320 } else {
4321 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004322 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004323
Douglas Gregor603cfb42011-01-05 23:12:31 +00004324 if (NewType.isNull())
4325 return true;
4326
4327 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004328 NewType = getSema().Context.getPackExpansionType(NewType,
4329 NumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004330
Douglas Gregora009b592011-01-07 00:20:55 +00004331 OutParamTypes.push_back(NewType);
4332 if (PVars)
4333 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004334 }
4335
John McCallfb44de92011-05-01 22:35:37 +00004336#ifndef NDEBUG
4337 if (PVars) {
4338 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4339 if (ParmVarDecl *parm = (*PVars)[i])
4340 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004341 }
John McCallfb44de92011-05-01 22:35:37 +00004342#endif
4343
4344 return false;
4345}
John McCall21ef0fa2010-03-11 09:03:00 +00004346
4347template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004348QualType
John McCalla2becad2009-10-21 00:40:46 +00004349TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004350 FunctionProtoTypeLoc TL) {
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004351 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4352}
4353
4354template<typename Derived>
4355QualType
4356TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4357 FunctionProtoTypeLoc TL,
4358 CXXRecordDecl *ThisContext,
4359 unsigned ThisTypeQuals) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004360 // Transform the parameters and return type.
4361 //
Richard Smithe6975e92012-04-17 00:58:00 +00004362 // We are required to instantiate the params and return type in source order.
Douglas Gregordab60ad2010-10-01 18:44:50 +00004363 // When the function has a trailing return type, we instantiate the
4364 // parameters before the return type, since the return type can then refer
4365 // to the parameters themselves (via decltype, sizeof, etc.).
4366 //
Chris Lattner686775d2011-07-20 06:58:45 +00004367 SmallVector<QualType, 4> ParamTypes;
4368 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004369 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004370
Douglas Gregordab60ad2010-10-01 18:44:50 +00004371 QualType ResultType;
4372
Richard Smith9fbf3272012-08-14 22:51:13 +00004373 if (T->hasTrailingReturn()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004374 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004375 TL.getParmArray(),
4376 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004377 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004378 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004379 return QualType();
4380
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004381 {
4382 // C++11 [expr.prim.general]p3:
Chad Rosier4a9d7952012-08-08 18:46:20 +00004383 // If a declaration declares a member function or member function
4384 // template of a class X, the expression this is a prvalue of type
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004385 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier4a9d7952012-08-08 18:46:20 +00004386 // and the end of the function-definition, member-declarator, or
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004387 // declarator.
4388 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004389
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004390 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4391 if (ResultType.isNull())
4392 return QualType();
4393 }
Douglas Gregordab60ad2010-10-01 18:44:50 +00004394 }
4395 else {
4396 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4397 if (ResultType.isNull())
4398 return QualType();
4399
Chad Rosier4a9d7952012-08-08 18:46:20 +00004400 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004401 TL.getParmArray(),
4402 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004403 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004404 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004405 return QualType();
4406 }
4407
Richard Smithe6975e92012-04-17 00:58:00 +00004408 // FIXME: Need to transform the exception-specification too.
4409
John McCalla2becad2009-10-21 00:40:46 +00004410 QualType Result = TL.getType();
4411 if (getDerived().AlwaysRebuild() ||
4412 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004413 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004414 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
Jordan Rosebea522f2013-03-08 21:51:21 +00004415 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00004416 T->getExtProtoInfo());
John McCalla2becad2009-10-21 00:40:46 +00004417 if (Result.isNull())
4418 return QualType();
4419 }
Mike Stump1eb44332009-09-09 15:08:12 +00004420
John McCalla2becad2009-10-21 00:40:46 +00004421 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004422 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004423 NewTL.setLParenLoc(TL.getLParenLoc());
4424 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004425 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004426 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4427 NewTL.setArg(i, ParamDecls[i]);
4428
4429 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004430}
Mike Stump1eb44332009-09-09 15:08:12 +00004431
Douglas Gregor577f75a2009-08-04 16:50:30 +00004432template<typename Derived>
4433QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004434 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004435 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004436 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004437 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4438 if (ResultType.isNull())
4439 return QualType();
4440
4441 QualType Result = TL.getType();
4442 if (getDerived().AlwaysRebuild() ||
4443 ResultType != T->getResultType())
4444 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4445
4446 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004447 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004448 NewTL.setLParenLoc(TL.getLParenLoc());
4449 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004450 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004451
4452 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004453}
Mike Stump1eb44332009-09-09 15:08:12 +00004454
John McCalled976492009-12-04 22:46:56 +00004455template<typename Derived> QualType
4456TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004457 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004458 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004459 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004460 if (!D)
4461 return QualType();
4462
4463 QualType Result = TL.getType();
4464 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4465 Result = getDerived().RebuildUnresolvedUsingType(D);
4466 if (Result.isNull())
4467 return QualType();
4468 }
4469
4470 // We might get an arbitrary type spec type back. We should at
4471 // least always get a type spec type, though.
4472 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4473 NewTL.setNameLoc(TL.getNameLoc());
4474
4475 return Result;
4476}
4477
Douglas Gregor577f75a2009-08-04 16:50:30 +00004478template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004479QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004480 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004481 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004482 TypedefNameDecl *Typedef
4483 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4484 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004485 if (!Typedef)
4486 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004487
John McCalla2becad2009-10-21 00:40:46 +00004488 QualType Result = TL.getType();
4489 if (getDerived().AlwaysRebuild() ||
4490 Typedef != T->getDecl()) {
4491 Result = getDerived().RebuildTypedefType(Typedef);
4492 if (Result.isNull())
4493 return QualType();
4494 }
Mike Stump1eb44332009-09-09 15:08:12 +00004495
John McCalla2becad2009-10-21 00:40:46 +00004496 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4497 NewTL.setNameLoc(TL.getNameLoc());
4498
4499 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004500}
Mike Stump1eb44332009-09-09 15:08:12 +00004501
Douglas Gregor577f75a2009-08-04 16:50:30 +00004502template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004503QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004504 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004505 // typeof expressions are not potentially evaluated contexts
Eli Friedman80bfa3d2012-09-26 04:34:21 +00004506 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4507 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00004508
John McCall60d7b3a2010-08-24 06:29:42 +00004509 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004510 if (E.isInvalid())
4511 return QualType();
4512
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004513 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4514 if (E.isInvalid())
4515 return QualType();
4516
John McCalla2becad2009-10-21 00:40:46 +00004517 QualType Result = TL.getType();
4518 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004519 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004520 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004521 if (Result.isNull())
4522 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004523 }
John McCalla2becad2009-10-21 00:40:46 +00004524 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004525
John McCalla2becad2009-10-21 00:40:46 +00004526 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004527 NewTL.setTypeofLoc(TL.getTypeofLoc());
4528 NewTL.setLParenLoc(TL.getLParenLoc());
4529 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004530
4531 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004532}
Mike Stump1eb44332009-09-09 15:08:12 +00004533
4534template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004535QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004536 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004537 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4538 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4539 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004540 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004541
John McCalla2becad2009-10-21 00:40:46 +00004542 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004543 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4544 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004545 if (Result.isNull())
4546 return QualType();
4547 }
Mike Stump1eb44332009-09-09 15:08:12 +00004548
John McCalla2becad2009-10-21 00:40:46 +00004549 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004550 NewTL.setTypeofLoc(TL.getTypeofLoc());
4551 NewTL.setLParenLoc(TL.getLParenLoc());
4552 NewTL.setRParenLoc(TL.getRParenLoc());
4553 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004554
4555 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004556}
Mike Stump1eb44332009-09-09 15:08:12 +00004557
4558template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004559QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004560 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004561 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004562
Douglas Gregor670444e2009-08-04 22:27:00 +00004563 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004564 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4565 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004566
John McCall60d7b3a2010-08-24 06:29:42 +00004567 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004568 if (E.isInvalid())
4569 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004570
Richard Smith76f3f692012-02-22 02:04:18 +00004571 E = getSema().ActOnDecltypeExpression(E.take());
4572 if (E.isInvalid())
4573 return QualType();
4574
John McCalla2becad2009-10-21 00:40:46 +00004575 QualType Result = TL.getType();
4576 if (getDerived().AlwaysRebuild() ||
4577 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004578 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004579 if (Result.isNull())
4580 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004581 }
John McCalla2becad2009-10-21 00:40:46 +00004582 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004583
John McCalla2becad2009-10-21 00:40:46 +00004584 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4585 NewTL.setNameLoc(TL.getNameLoc());
4586
4587 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004588}
4589
4590template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004591QualType TreeTransform<Derived>::TransformUnaryTransformType(
4592 TypeLocBuilder &TLB,
4593 UnaryTransformTypeLoc TL) {
4594 QualType Result = TL.getType();
4595 if (Result->isDependentType()) {
4596 const UnaryTransformType *T = TL.getTypePtr();
4597 QualType NewBase =
4598 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4599 Result = getDerived().RebuildUnaryTransformType(NewBase,
4600 T->getUTTKind(),
4601 TL.getKWLoc());
4602 if (Result.isNull())
4603 return QualType();
4604 }
4605
4606 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4607 NewTL.setKWLoc(TL.getKWLoc());
4608 NewTL.setParensRange(TL.getParensRange());
4609 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4610 return Result;
4611}
4612
4613template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004614QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4615 AutoTypeLoc TL) {
4616 const AutoType *T = TL.getTypePtr();
4617 QualType OldDeduced = T->getDeducedType();
4618 QualType NewDeduced;
4619 if (!OldDeduced.isNull()) {
4620 NewDeduced = getDerived().TransformType(OldDeduced);
4621 if (NewDeduced.isNull())
4622 return QualType();
4623 }
4624
4625 QualType Result = TL.getType();
Richard Smithdc7a4f52013-04-30 13:56:41 +00004626 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4627 T->isDependentType()) {
Richard Smitha2c36462013-04-26 16:15:35 +00004628 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith34b41d92011-02-20 03:19:35 +00004629 if (Result.isNull())
4630 return QualType();
4631 }
4632
4633 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4634 NewTL.setNameLoc(TL.getNameLoc());
4635
4636 return Result;
4637}
4638
4639template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004640QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004641 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004642 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004643 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004644 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4645 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004646 if (!Record)
4647 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004648
John McCalla2becad2009-10-21 00:40:46 +00004649 QualType Result = TL.getType();
4650 if (getDerived().AlwaysRebuild() ||
4651 Record != T->getDecl()) {
4652 Result = getDerived().RebuildRecordType(Record);
4653 if (Result.isNull())
4654 return QualType();
4655 }
Mike Stump1eb44332009-09-09 15:08:12 +00004656
John McCalla2becad2009-10-21 00:40:46 +00004657 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4658 NewTL.setNameLoc(TL.getNameLoc());
4659
4660 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004661}
Mike Stump1eb44332009-09-09 15:08:12 +00004662
4663template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004664QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004665 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004666 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004667 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004668 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4669 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004670 if (!Enum)
4671 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004672
John McCalla2becad2009-10-21 00:40:46 +00004673 QualType Result = TL.getType();
4674 if (getDerived().AlwaysRebuild() ||
4675 Enum != T->getDecl()) {
4676 Result = getDerived().RebuildEnumType(Enum);
4677 if (Result.isNull())
4678 return QualType();
4679 }
Mike Stump1eb44332009-09-09 15:08:12 +00004680
John McCalla2becad2009-10-21 00:40:46 +00004681 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4682 NewTL.setNameLoc(TL.getNameLoc());
4683
4684 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004685}
John McCall7da24312009-09-05 00:15:47 +00004686
John McCall3cb0ebd2010-03-10 03:28:59 +00004687template<typename Derived>
4688QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4689 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004690 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004691 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4692 TL.getTypePtr()->getDecl());
4693 if (!D) return QualType();
4694
4695 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4696 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4697 return T;
4698}
4699
Douglas Gregor577f75a2009-08-04 16:50:30 +00004700template<typename Derived>
4701QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004702 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004703 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004704 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004705}
4706
Mike Stump1eb44332009-09-09 15:08:12 +00004707template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004708QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004709 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004710 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004711 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004712
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004713 // Substitute into the replacement type, which itself might involve something
4714 // that needs to be transformed. This only tends to occur with default
4715 // template arguments of template template parameters.
4716 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4717 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4718 if (Replacement.isNull())
4719 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004720
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004721 // Always canonicalize the replacement type.
4722 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4723 QualType Result
Chad Rosier4a9d7952012-08-08 18:46:20 +00004724 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004725 Replacement);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004726
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004727 // Propagate type-source information.
4728 SubstTemplateTypeParmTypeLoc NewTL
4729 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4730 NewTL.setNameLoc(TL.getNameLoc());
4731 return Result;
4732
John McCall49a832b2009-10-18 09:09:24 +00004733}
4734
4735template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004736QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4737 TypeLocBuilder &TLB,
4738 SubstTemplateTypeParmPackTypeLoc TL) {
4739 return TransformTypeSpecType(TLB, TL);
4740}
4741
4742template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004743QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004744 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004745 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004746 const TemplateSpecializationType *T = TL.getTypePtr();
4747
Douglas Gregor1d752d72011-03-02 18:46:51 +00004748 // The nested-name-specifier never matters in a TemplateSpecializationType,
4749 // because we can't have a dependent nested-name-specifier anyway.
4750 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004751 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004752 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4753 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004754 if (Template.isNull())
4755 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004756
John McCall43fed0d2010-11-12 08:19:04 +00004757 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4758}
4759
Eli Friedmanb001de72011-10-06 23:00:33 +00004760template<typename Derived>
4761QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4762 AtomicTypeLoc TL) {
4763 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4764 if (ValueType.isNull())
4765 return QualType();
4766
4767 QualType Result = TL.getType();
4768 if (getDerived().AlwaysRebuild() ||
4769 ValueType != TL.getValueLoc().getType()) {
4770 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4771 if (Result.isNull())
4772 return QualType();
4773 }
4774
4775 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4776 NewTL.setKWLoc(TL.getKWLoc());
4777 NewTL.setLParenLoc(TL.getLParenLoc());
4778 NewTL.setRParenLoc(TL.getRParenLoc());
4779
4780 return Result;
4781}
4782
Chad Rosier4a9d7952012-08-08 18:46:20 +00004783 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004784 /// container that provides a \c getArgLoc() member function.
4785 ///
4786 /// This iterator is intended to be used with the iterator form of
4787 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4788 template<typename ArgLocContainer>
4789 class TemplateArgumentLocContainerIterator {
4790 ArgLocContainer *Container;
4791 unsigned Index;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004792
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004793 public:
4794 typedef TemplateArgumentLoc value_type;
4795 typedef TemplateArgumentLoc reference;
4796 typedef int difference_type;
4797 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004798
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004799 class pointer {
4800 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004801
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004802 public:
4803 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004804
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004805 const TemplateArgumentLoc *operator->() const {
4806 return &Arg;
4807 }
4808 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004809
4810
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004811 TemplateArgumentLocContainerIterator() {}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004812
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004813 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4814 unsigned Index)
4815 : Container(&Container), Index(Index) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004816
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004817 TemplateArgumentLocContainerIterator &operator++() {
4818 ++Index;
4819 return *this;
4820 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004821
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004822 TemplateArgumentLocContainerIterator operator++(int) {
4823 TemplateArgumentLocContainerIterator Old(*this);
4824 ++(*this);
4825 return Old;
4826 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004827
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004828 TemplateArgumentLoc operator*() const {
4829 return Container->getArgLoc(Index);
4830 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004831
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004832 pointer operator->() const {
4833 return pointer(Container->getArgLoc(Index));
4834 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004835
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004836 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004837 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004838 return X.Container == Y.Container && X.Index == Y.Index;
4839 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004840
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004841 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004842 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004843 return !(X == Y);
4844 }
4845 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004846
4847
John McCall43fed0d2010-11-12 08:19:04 +00004848template <typename Derived>
4849QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4850 TypeLocBuilder &TLB,
4851 TemplateSpecializationTypeLoc TL,
4852 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004853 TemplateArgumentListInfo NewTemplateArgs;
4854 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4855 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004856 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4857 ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004858 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004859 ArgIterator(TL, TL.getNumArgs()),
4860 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004861 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004862
John McCall833ca992009-10-29 08:12:44 +00004863 // FIXME: maybe don't rebuild if all the template arguments are the same.
4864
4865 QualType Result =
4866 getDerived().RebuildTemplateSpecializationType(Template,
4867 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004868 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004869
4870 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004871 // Specializations of template template parameters are represented as
4872 // TemplateSpecializationTypes, and substitution of type alias templates
4873 // within a dependent context can transform them into
4874 // DependentTemplateSpecializationTypes.
4875 if (isa<DependentTemplateSpecializationType>(Result)) {
4876 DependentTemplateSpecializationTypeLoc NewTL
4877 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004878 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004879 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004880 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004881 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004882 NewTL.setLAngleLoc(TL.getLAngleLoc());
4883 NewTL.setRAngleLoc(TL.getRAngleLoc());
4884 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4885 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4886 return Result;
4887 }
4888
John McCall833ca992009-10-29 08:12:44 +00004889 TemplateSpecializationTypeLoc NewTL
4890 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004891 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004892 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4893 NewTL.setLAngleLoc(TL.getLAngleLoc());
4894 NewTL.setRAngleLoc(TL.getRAngleLoc());
4895 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4896 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004897 }
Mike Stump1eb44332009-09-09 15:08:12 +00004898
John McCall833ca992009-10-29 08:12:44 +00004899 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004900}
Mike Stump1eb44332009-09-09 15:08:12 +00004901
Douglas Gregora88f09f2011-02-28 17:23:35 +00004902template <typename Derived>
4903QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4904 TypeLocBuilder &TLB,
4905 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004906 TemplateName Template,
4907 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004908 TemplateArgumentListInfo NewTemplateArgs;
4909 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4910 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4911 typedef TemplateArgumentLocContainerIterator<
4912 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004913 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004914 ArgIterator(TL, TL.getNumArgs()),
4915 NewTemplateArgs))
4916 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004917
Douglas Gregora88f09f2011-02-28 17:23:35 +00004918 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier4a9d7952012-08-08 18:46:20 +00004919
Douglas Gregora88f09f2011-02-28 17:23:35 +00004920 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4921 QualType Result
4922 = getSema().Context.getDependentTemplateSpecializationType(
4923 TL.getTypePtr()->getKeyword(),
4924 DTN->getQualifier(),
4925 DTN->getIdentifier(),
4926 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004927
Douglas Gregora88f09f2011-02-28 17:23:35 +00004928 DependentTemplateSpecializationTypeLoc NewTL
4929 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004930 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004931 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004932 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004933 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004934 NewTL.setLAngleLoc(TL.getLAngleLoc());
4935 NewTL.setRAngleLoc(TL.getRAngleLoc());
4936 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4937 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4938 return Result;
4939 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004940
4941 QualType Result
Douglas Gregora88f09f2011-02-28 17:23:35 +00004942 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004943 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004944 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004945
Douglas Gregora88f09f2011-02-28 17:23:35 +00004946 if (!Result.isNull()) {
4947 /// FIXME: Wrap this in an elaborated-type-specifier?
4948 TemplateSpecializationTypeLoc NewTL
4949 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004950 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004951 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004952 NewTL.setLAngleLoc(TL.getLAngleLoc());
4953 NewTL.setRAngleLoc(TL.getRAngleLoc());
4954 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4955 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4956 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004957
Douglas Gregora88f09f2011-02-28 17:23:35 +00004958 return Result;
4959}
4960
Mike Stump1eb44332009-09-09 15:08:12 +00004961template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004962QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004963TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004964 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004965 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004966
Douglas Gregor9e876872011-03-01 18:12:44 +00004967 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004968 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004969 if (TL.getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004970 QualifierLoc
Douglas Gregor9e876872011-03-01 18:12:44 +00004971 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4972 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004973 return QualType();
4974 }
Mike Stump1eb44332009-09-09 15:08:12 +00004975
John McCall43fed0d2010-11-12 08:19:04 +00004976 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4977 if (NamedT.isNull())
4978 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004979
Richard Smith3e4c6c42011-05-05 21:57:07 +00004980 // C++0x [dcl.type.elab]p2:
4981 // If the identifier resolves to a typedef-name or the simple-template-id
4982 // resolves to an alias template specialization, the
4983 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004984 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4985 if (const TemplateSpecializationType *TST =
4986 NamedT->getAs<TemplateSpecializationType>()) {
4987 TemplateName Template = TST->getTemplateName();
4988 if (TypeAliasTemplateDecl *TAT =
4989 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4990 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4991 diag::err_tag_reference_non_tag) << 4;
4992 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4993 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004994 }
4995 }
4996
John McCalla2becad2009-10-21 00:40:46 +00004997 QualType Result = TL.getType();
4998 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004999 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005000 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00005001 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00005002 T->getKeyword(),
Douglas Gregor9e876872011-03-01 18:12:44 +00005003 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00005004 if (Result.isNull())
5005 return QualType();
5006 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00005007
Abramo Bagnara465d41b2010-05-11 21:36:43 +00005008 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005009 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00005010 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00005011 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00005012}
Mike Stump1eb44332009-09-09 15:08:12 +00005013
5014template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00005015QualType TreeTransform<Derived>::TransformAttributedType(
5016 TypeLocBuilder &TLB,
5017 AttributedTypeLoc TL) {
5018 const AttributedType *oldType = TL.getTypePtr();
5019 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5020 if (modifiedType.isNull())
5021 return QualType();
5022
5023 QualType result = TL.getType();
5024
5025 // FIXME: dependent operand expressions?
5026 if (getDerived().AlwaysRebuild() ||
5027 modifiedType != oldType->getModifiedType()) {
5028 // TODO: this is really lame; we should really be rebuilding the
5029 // equivalent type from first principles.
5030 QualType equivalentType
5031 = getDerived().TransformType(oldType->getEquivalentType());
5032 if (equivalentType.isNull())
5033 return QualType();
5034 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5035 modifiedType,
5036 equivalentType);
5037 }
5038
5039 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5040 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5041 if (TL.hasAttrOperand())
5042 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5043 if (TL.hasAttrExprOperand())
5044 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5045 else if (TL.hasAttrEnumOperand())
5046 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5047
5048 return result;
5049}
5050
5051template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00005052QualType
5053TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5054 ParenTypeLoc TL) {
5055 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5056 if (Inner.isNull())
5057 return QualType();
5058
5059 QualType Result = TL.getType();
5060 if (getDerived().AlwaysRebuild() ||
5061 Inner != TL.getInnerLoc().getType()) {
5062 Result = getDerived().RebuildParenType(Inner);
5063 if (Result.isNull())
5064 return QualType();
5065 }
5066
5067 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5068 NewTL.setLParenLoc(TL.getLParenLoc());
5069 NewTL.setRParenLoc(TL.getRParenLoc());
5070 return Result;
5071}
5072
5073template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00005074QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005075 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00005076 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00005077
Douglas Gregor2494dd02011-03-01 01:34:45 +00005078 NestedNameSpecifierLoc QualifierLoc
5079 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5080 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00005081 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00005082
John McCall33500952010-06-11 00:33:02 +00005083 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00005084 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00005085 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00005086 QualifierLoc,
5087 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00005088 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00005089 if (Result.isNull())
5090 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005091
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005092 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5093 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00005094 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5095
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005096 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005097 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00005098 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00005099 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005100 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005101 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00005102 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005103 NewTL.setNameLoc(TL.getNameLoc());
5104 }
John McCalla2becad2009-10-21 00:40:46 +00005105 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00005106}
Mike Stump1eb44332009-09-09 15:08:12 +00005107
Douglas Gregor577f75a2009-08-04 16:50:30 +00005108template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00005109QualType TreeTransform<Derived>::
5110 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005111 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005112 NestedNameSpecifierLoc QualifierLoc;
5113 if (TL.getQualifierLoc()) {
5114 QualifierLoc
5115 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5116 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00005117 return QualType();
5118 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005119
John McCall43fed0d2010-11-12 08:19:04 +00005120 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005121 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00005122}
5123
5124template<typename Derived>
5125QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005126TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5127 DependentTemplateSpecializationTypeLoc TL,
5128 NestedNameSpecifierLoc QualifierLoc) {
5129 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005130
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005131 TemplateArgumentListInfo NewTemplateArgs;
5132 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5133 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005134
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005135 typedef TemplateArgumentLocContainerIterator<
5136 DependentTemplateSpecializationTypeLoc> ArgIterator;
5137 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5138 ArgIterator(TL, TL.getNumArgs()),
5139 NewTemplateArgs))
5140 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005141
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005142 QualType Result
5143 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5144 QualifierLoc,
5145 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005146 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005147 NewTemplateArgs);
5148 if (Result.isNull())
5149 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005150
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005151 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5152 QualType NamedT = ElabT->getNamedType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005153
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005154 // Copy information relevant to the template specialization.
5155 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005156 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005157 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005158 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005159 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5160 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005161 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005162 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005163
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005164 // Copy information relevant to the elaborated type.
5165 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005166 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005167 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005168 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5169 DependentTemplateSpecializationTypeLoc SpecTL
5170 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005171 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005172 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005173 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005174 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005175 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5176 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005177 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005178 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005179 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005180 TemplateSpecializationTypeLoc SpecTL
5181 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005182 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005183 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005184 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5185 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005186 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005187 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005188 }
5189 return Result;
5190}
5191
5192template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00005193QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5194 PackExpansionTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005195 QualType Pattern
5196 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005197 if (Pattern.isNull())
5198 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005199
5200 QualType Result = TL.getType();
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005201 if (getDerived().AlwaysRebuild() ||
5202 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005203 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005204 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00005205 TL.getEllipsisLoc(),
5206 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005207 if (Result.isNull())
5208 return QualType();
5209 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005210
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005211 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5212 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5213 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00005214}
5215
5216template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005217QualType
5218TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005219 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005220 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005221 TLB.pushFullCopy(TL);
5222 return TL.getType();
5223}
5224
5225template<typename Derived>
5226QualType
5227TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005228 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005229 // ObjCObjectType is never dependent.
5230 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005231 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005232}
Mike Stump1eb44332009-09-09 15:08:12 +00005233
5234template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005235QualType
5236TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005237 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005238 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005239 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005240 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005241}
5242
Douglas Gregor577f75a2009-08-04 16:50:30 +00005243//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005244// Statement transformation
5245//===----------------------------------------------------------------------===//
5246template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005247StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005248TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005249 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005250}
5251
5252template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005253StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005254TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5255 return getDerived().TransformCompoundStmt(S, false);
5256}
5257
5258template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005259StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005260TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005261 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005262 Sema::CompoundScopeRAII CompoundScope(getSema());
5263
John McCall7114cba2010-08-27 19:56:05 +00005264 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005265 bool SubStmtChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005266 SmallVector<Stmt*, 8> Statements;
Douglas Gregor43959a92009-08-20 07:17:43 +00005267 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5268 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005269 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005270 if (Result.isInvalid()) {
5271 // Immediately fail if this was a DeclStmt, since it's very
5272 // likely that this will cause problems for future statements.
5273 if (isa<DeclStmt>(*B))
5274 return StmtError();
5275
5276 // Otherwise, just keep processing substatements and fail later.
5277 SubStmtInvalid = true;
5278 continue;
5279 }
Mike Stump1eb44332009-09-09 15:08:12 +00005280
Douglas Gregor43959a92009-08-20 07:17:43 +00005281 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5282 Statements.push_back(Result.takeAs<Stmt>());
5283 }
Mike Stump1eb44332009-09-09 15:08:12 +00005284
John McCall7114cba2010-08-27 19:56:05 +00005285 if (SubStmtInvalid)
5286 return StmtError();
5287
Douglas Gregor43959a92009-08-20 07:17:43 +00005288 if (!getDerived().AlwaysRebuild() &&
5289 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005290 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005291
5292 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005293 Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00005294 S->getRBracLoc(),
5295 IsStmtExpr);
5296}
Mike Stump1eb44332009-09-09 15:08:12 +00005297
Douglas Gregor43959a92009-08-20 07:17:43 +00005298template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005299StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005300TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005301 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005302 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005303 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5304 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005305
Eli Friedman264c1f82009-11-19 03:14:00 +00005306 // Transform the left-hand case value.
5307 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005308 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005309 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005310 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005311
Eli Friedman264c1f82009-11-19 03:14:00 +00005312 // Transform the right-hand case value (for the GNU case-range extension).
5313 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005314 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005315 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005316 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005317 }
Mike Stump1eb44332009-09-09 15:08:12 +00005318
Douglas Gregor43959a92009-08-20 07:17:43 +00005319 // Build the case statement.
5320 // Case statements are always rebuilt so that they will attached to their
5321 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005322 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005323 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005324 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005325 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005326 S->getColonLoc());
5327 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005328 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005329
Douglas Gregor43959a92009-08-20 07:17:43 +00005330 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005331 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005332 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005333 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005334
Douglas Gregor43959a92009-08-20 07:17:43 +00005335 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005336 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005337}
5338
5339template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005340StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005341TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005342 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005343 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005344 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005345 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005346
Douglas Gregor43959a92009-08-20 07:17:43 +00005347 // Default statements are always rebuilt
5348 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005349 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005350}
Mike Stump1eb44332009-09-09 15:08:12 +00005351
Douglas Gregor43959a92009-08-20 07:17:43 +00005352template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005353StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005354TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005355 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005356 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005357 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005358
Chris Lattner57ad3782011-02-17 20:34:02 +00005359 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5360 S->getDecl());
5361 if (!LD)
5362 return StmtError();
Richard Smith534986f2012-04-14 00:33:13 +00005363
5364
Douglas Gregor43959a92009-08-20 07:17:43 +00005365 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005366 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005367 cast<LabelDecl>(LD), SourceLocation(),
5368 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005369}
Mike Stump1eb44332009-09-09 15:08:12 +00005370
Douglas Gregor43959a92009-08-20 07:17:43 +00005371template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005372StmtResult
Richard Smith534986f2012-04-14 00:33:13 +00005373TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5374 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5375 if (SubStmt.isInvalid())
5376 return StmtError();
5377
5378 // TODO: transform attributes
5379 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5380 return S;
5381
5382 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5383 S->getAttrs(),
5384 SubStmt.get());
5385}
5386
5387template<typename Derived>
5388StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005389TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005390 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005391 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005392 VarDecl *ConditionVar = 0;
5393 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005394 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005395 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005396 getDerived().TransformDefinition(
5397 S->getConditionVariable()->getLocation(),
5398 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005399 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005400 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005401 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005402 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005403
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005404 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005405 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005406
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005407 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005408 if (S->getCond()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005409 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005410 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005411 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005412 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005413
John McCall9ae2f072010-08-23 23:25:46 +00005414 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005415 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005416 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005417
John McCall9ae2f072010-08-23 23:25:46 +00005418 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5419 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005420 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005421
Douglas Gregor43959a92009-08-20 07:17:43 +00005422 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005423 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005424 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005425 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005426
Douglas Gregor43959a92009-08-20 07:17:43 +00005427 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005428 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005429 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005430 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005431
Douglas Gregor43959a92009-08-20 07:17:43 +00005432 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005433 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005434 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005435 Then.get() == S->getThen() &&
5436 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005437 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005438
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005439 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005440 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005441 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005442}
5443
5444template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005445StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005446TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005447 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005448 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005449 VarDecl *ConditionVar = 0;
5450 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005451 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005452 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005453 getDerived().TransformDefinition(
5454 S->getConditionVariable()->getLocation(),
5455 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005456 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005457 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005458 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005459 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005460
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005461 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005462 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005463 }
Mike Stump1eb44332009-09-09 15:08:12 +00005464
Douglas Gregor43959a92009-08-20 07:17:43 +00005465 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005466 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005467 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005468 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005469 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005470 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005471
Douglas Gregor43959a92009-08-20 07:17:43 +00005472 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005473 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005474 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005475 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005476
Douglas Gregor43959a92009-08-20 07:17:43 +00005477 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005478 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5479 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005480}
Mike Stump1eb44332009-09-09 15:08:12 +00005481
Douglas Gregor43959a92009-08-20 07:17:43 +00005482template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005483StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005484TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005485 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005486 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005487 VarDecl *ConditionVar = 0;
5488 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005489 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005490 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005491 getDerived().TransformDefinition(
5492 S->getConditionVariable()->getLocation(),
5493 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005494 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005495 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005496 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005497 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005498
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005499 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005500 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005501
5502 if (S->getCond()) {
5503 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005504 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005505 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005506 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005507 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005508 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005509 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005510 }
Mike Stump1eb44332009-09-09 15:08:12 +00005511
John McCall9ae2f072010-08-23 23:25:46 +00005512 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5513 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005514 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005515
Douglas Gregor43959a92009-08-20 07:17:43 +00005516 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005517 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005518 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005519 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005520
Douglas Gregor43959a92009-08-20 07:17:43 +00005521 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005522 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005523 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005524 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005525 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005526
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005527 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005528 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005529}
Mike Stump1eb44332009-09-09 15:08:12 +00005530
Douglas Gregor43959a92009-08-20 07:17:43 +00005531template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005532StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005533TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005534 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005535 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005536 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005537 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005538
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005539 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005540 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005541 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005542 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005543
Douglas Gregor43959a92009-08-20 07:17:43 +00005544 if (!getDerived().AlwaysRebuild() &&
5545 Cond.get() == S->getCond() &&
5546 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005547 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005548
John McCall9ae2f072010-08-23 23:25:46 +00005549 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5550 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005551 S->getRParenLoc());
5552}
Mike Stump1eb44332009-09-09 15:08:12 +00005553
Douglas Gregor43959a92009-08-20 07:17:43 +00005554template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005555StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005556TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005557 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005558 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005559 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005560 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005561
Douglas Gregor43959a92009-08-20 07:17:43 +00005562 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005563 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005564 VarDecl *ConditionVar = 0;
5565 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005566 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005567 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005568 getDerived().TransformDefinition(
5569 S->getConditionVariable()->getLocation(),
5570 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005571 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005572 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005573 } else {
5574 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005575
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005576 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005577 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005578
5579 if (S->getCond()) {
5580 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005581 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005582 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005583 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005584 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005585
John McCall9ae2f072010-08-23 23:25:46 +00005586 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005587 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005588 }
Mike Stump1eb44332009-09-09 15:08:12 +00005589
Chad Rosier4a9d7952012-08-08 18:46:20 +00005590 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCall9ae2f072010-08-23 23:25:46 +00005591 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005592 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005593
Douglas Gregor43959a92009-08-20 07:17:43 +00005594 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005595 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005596 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005597 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005598
Richard Smith41956372013-01-14 22:39:08 +00005599 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCall9ae2f072010-08-23 23:25:46 +00005600 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005601 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005602
Douglas Gregor43959a92009-08-20 07:17:43 +00005603 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005604 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005605 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005606 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005607
Douglas Gregor43959a92009-08-20 07:17:43 +00005608 if (!getDerived().AlwaysRebuild() &&
5609 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005610 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005611 Inc.get() == S->getInc() &&
5612 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005613 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005614
Douglas Gregor43959a92009-08-20 07:17:43 +00005615 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005616 Init.get(), FullCond, ConditionVar,
5617 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005618}
5619
5620template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005621StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005622TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005623 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5624 S->getLabel());
5625 if (!LD)
5626 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005627
Douglas Gregor43959a92009-08-20 07:17:43 +00005628 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005629 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005630 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005631}
5632
5633template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005634StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005635TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005636 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005637 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005638 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005639 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005640
Douglas Gregor43959a92009-08-20 07:17:43 +00005641 if (!getDerived().AlwaysRebuild() &&
5642 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005643 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005644
5645 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005646 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005647}
5648
5649template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005650StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005651TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005652 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005653}
Mike Stump1eb44332009-09-09 15:08:12 +00005654
Douglas Gregor43959a92009-08-20 07:17:43 +00005655template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005656StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005657TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005658 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005659}
Mike Stump1eb44332009-09-09 15:08:12 +00005660
Douglas Gregor43959a92009-08-20 07:17:43 +00005661template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005662StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005663TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005664 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005665 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005666 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005667
Mike Stump1eb44332009-09-09 15:08:12 +00005668 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005669 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005670 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005671}
Mike Stump1eb44332009-09-09 15:08:12 +00005672
Douglas Gregor43959a92009-08-20 07:17:43 +00005673template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005674StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005675TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005676 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005677 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005678 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5679 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005680 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5681 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005682 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005683 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005684
Douglas Gregor43959a92009-08-20 07:17:43 +00005685 if (Transformed != *D)
5686 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005687
Douglas Gregor43959a92009-08-20 07:17:43 +00005688 Decls.push_back(Transformed);
5689 }
Mike Stump1eb44332009-09-09 15:08:12 +00005690
Douglas Gregor43959a92009-08-20 07:17:43 +00005691 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005692 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005693
Rafael Espindola4549d7f2013-07-09 12:05:01 +00005694 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005695}
Mike Stump1eb44332009-09-09 15:08:12 +00005696
Douglas Gregor43959a92009-08-20 07:17:43 +00005697template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005698StmtResult
Chad Rosierdf5faf52012-08-25 00:11:56 +00005699TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005700
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005701 SmallVector<Expr*, 8> Constraints;
5702 SmallVector<Expr*, 8> Exprs;
Chris Lattner686775d2011-07-20 06:58:45 +00005703 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005704
John McCall60d7b3a2010-08-24 06:29:42 +00005705 ExprResult AsmString;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005706 SmallVector<Expr*, 8> Clobbers;
Anders Carlsson703e3942010-01-24 05:50:09 +00005707
5708 bool ExprsChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005709
Anders Carlsson703e3942010-01-24 05:50:09 +00005710 // Go through the outputs.
5711 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005712 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005713
Anders Carlsson703e3942010-01-24 05:50:09 +00005714 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005715 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005716
Anders Carlsson703e3942010-01-24 05:50:09 +00005717 // Transform the output expr.
5718 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005719 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005720 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005721 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005722
Anders Carlsson703e3942010-01-24 05:50:09 +00005723 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005724
John McCall9ae2f072010-08-23 23:25:46 +00005725 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005726 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005727
Anders Carlsson703e3942010-01-24 05:50:09 +00005728 // Go through the inputs.
5729 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005730 Names.push_back(S->getInputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005731
Anders Carlsson703e3942010-01-24 05:50:09 +00005732 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005733 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005734
Anders Carlsson703e3942010-01-24 05:50:09 +00005735 // Transform the input expr.
5736 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005737 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005738 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005739 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005740
Anders Carlsson703e3942010-01-24 05:50:09 +00005741 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005742
John McCall9ae2f072010-08-23 23:25:46 +00005743 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005744 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005745
Anders Carlsson703e3942010-01-24 05:50:09 +00005746 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005747 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005748
5749 // Go through the clobbers.
5750 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosier5c7f5942012-08-27 23:28:41 +00005751 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005752
5753 // No need to transform the asm string literal.
5754 AsmString = SemaRef.Owned(S->getAsmString());
Chad Rosierdf5faf52012-08-25 00:11:56 +00005755 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5756 S->isVolatile(), S->getNumOutputs(),
5757 S->getNumInputs(), Names.data(),
5758 Constraints, Exprs, AsmString.get(),
5759 Clobbers, S->getRParenLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005760}
5761
Chad Rosier8cd64b42012-06-11 20:47:18 +00005762template<typename Derived>
5763StmtResult
5764TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier79efe242012-08-07 00:29:06 +00005765 ArrayRef<Token> AsmToks =
5766 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier62f22b82012-08-08 19:48:07 +00005767
John McCallaeeacf72013-05-03 00:10:13 +00005768 bool HadError = false, HadChange = false;
5769
5770 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5771 SmallVector<Expr*, 8> TransformedExprs;
5772 TransformedExprs.reserve(SrcExprs.size());
5773 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5774 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5775 if (!Result.isUsable()) {
5776 HadError = true;
5777 } else {
5778 HadChange |= (Result.get() != SrcExprs[i]);
5779 TransformedExprs.push_back(Result.take());
5780 }
5781 }
5782
5783 if (HadError) return StmtError();
5784 if (!HadChange && !getDerived().AlwaysRebuild())
5785 return Owned(S);
5786
Chad Rosier7bd092b2012-08-15 16:53:30 +00005787 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallaeeacf72013-05-03 00:10:13 +00005788 AsmToks, S->getAsmString(),
5789 S->getNumOutputs(), S->getNumInputs(),
5790 S->getAllConstraints(), S->getClobbers(),
5791 TransformedExprs, S->getEndLoc());
Chad Rosier8cd64b42012-06-11 20:47:18 +00005792}
Douglas Gregor43959a92009-08-20 07:17:43 +00005793
5794template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005795StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005796TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005797 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005798 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005799 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005800 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005801
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005802 // Transform the @catch statements (if present).
5803 bool AnyCatchChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005804 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005805 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005806 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005807 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005808 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005809 if (Catch.get() != S->getCatchStmt(I))
5810 AnyCatchChanged = true;
5811 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005812 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005813
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005814 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005815 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005816 if (S->getFinallyStmt()) {
5817 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5818 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005819 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005820 }
5821
5822 // If nothing changed, just retain this statement.
5823 if (!getDerived().AlwaysRebuild() &&
5824 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005825 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005826 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005827 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005828
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005829 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005830 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005831 CatchStmts, Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005832}
Mike Stump1eb44332009-09-09 15:08:12 +00005833
Douglas Gregor43959a92009-08-20 07:17:43 +00005834template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005835StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005836TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005837 // Transform the @catch parameter, if there is one.
5838 VarDecl *Var = 0;
5839 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5840 TypeSourceInfo *TSInfo = 0;
5841 if (FromVar->getTypeSourceInfo()) {
5842 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5843 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005844 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005845 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005846
Douglas Gregorbe270a02010-04-26 17:57:08 +00005847 QualType T;
5848 if (TSInfo)
5849 T = TSInfo->getType();
5850 else {
5851 T = getDerived().TransformType(FromVar->getType());
5852 if (T.isNull())
Chad Rosier4a9d7952012-08-08 18:46:20 +00005853 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005854 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005855
Douglas Gregorbe270a02010-04-26 17:57:08 +00005856 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5857 if (!Var)
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
John McCall60d7b3a2010-08-24 06:29:42 +00005861 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005862 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005863 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005864
5865 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005866 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005867 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005868}
Mike Stump1eb44332009-09-09 15:08:12 +00005869
Douglas Gregor43959a92009-08-20 07:17:43 +00005870template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005871StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005872TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005873 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005874 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005875 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005876 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005877
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005878 // If nothing changed, just retain this statement.
5879 if (!getDerived().AlwaysRebuild() &&
5880 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005881 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005882
5883 // Build a new statement.
5884 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005885 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005886}
Mike Stump1eb44332009-09-09 15:08:12 +00005887
Douglas Gregor43959a92009-08-20 07:17:43 +00005888template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005889StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005890TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005891 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005892 if (S->getThrowExpr()) {
5893 Operand = getDerived().TransformExpr(S->getThrowExpr());
5894 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005895 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005896 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005897
Douglas Gregord1377b22010-04-22 21:44:01 +00005898 if (!getDerived().AlwaysRebuild() &&
5899 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005900 return getSema().Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005901
John McCall9ae2f072010-08-23 23:25:46 +00005902 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005903}
Mike Stump1eb44332009-09-09 15:08:12 +00005904
Douglas Gregor43959a92009-08-20 07:17:43 +00005905template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005906StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005907TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005908 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005909 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005910 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005911 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005912 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005913 Object =
5914 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5915 Object.get());
5916 if (Object.isInvalid())
5917 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005918
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005919 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005920 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005921 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005922 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005923
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005924 // If nothing change, just retain the current statement.
5925 if (!getDerived().AlwaysRebuild() &&
5926 Object.get() == S->getSynchExpr() &&
5927 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005928 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005929
5930 // Build a new statement.
5931 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005932 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005933}
5934
5935template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005936StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005937TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5938 ObjCAutoreleasePoolStmt *S) {
5939 // Transform the body.
5940 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5941 if (Body.isInvalid())
5942 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005943
John McCallf85e1932011-06-15 23:02:42 +00005944 // If nothing changed, just retain this statement.
5945 if (!getDerived().AlwaysRebuild() &&
5946 Body.get() == S->getSubStmt())
5947 return SemaRef.Owned(S);
5948
5949 // Build a new statement.
5950 return getDerived().RebuildObjCAutoreleasePoolStmt(
5951 S->getAtLoc(), Body.get());
5952}
5953
5954template<typename Derived>
5955StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005956TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005957 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005958 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005959 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005960 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005961 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005962
Douglas Gregorc3203e72010-04-22 23:10:45 +00005963 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005964 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005965 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005966 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005967
Douglas Gregorc3203e72010-04-22 23:10:45 +00005968 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005969 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005970 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005971 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005972
Douglas Gregorc3203e72010-04-22 23:10:45 +00005973 // If nothing changed, just retain this statement.
5974 if (!getDerived().AlwaysRebuild() &&
5975 Element.get() == S->getElement() &&
5976 Collection.get() == S->getCollection() &&
5977 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005978 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005979
Douglas Gregorc3203e72010-04-22 23:10:45 +00005980 // Build a new statement.
5981 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005982 Element.get(),
5983 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005984 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005985 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005986}
5987
5988
5989template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005990StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005991TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5992 // Transform the exception declaration, if any.
5993 VarDecl *Var = 0;
5994 if (S->getExceptionDecl()) {
5995 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005996 TypeSourceInfo *T = getDerived().TransformType(
5997 ExceptionDecl->getTypeSourceInfo());
5998 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005999 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00006000
Douglas Gregor83cb9422010-09-09 17:09:21 +00006001 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00006002 ExceptionDecl->getInnerLocStart(),
6003 ExceptionDecl->getLocation(),
6004 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00006005 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00006006 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00006007 }
Mike Stump1eb44332009-09-09 15:08:12 +00006008
Douglas Gregor43959a92009-08-20 07:17:43 +00006009 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00006010 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00006011 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006012 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00006013
Douglas Gregor43959a92009-08-20 07:17:43 +00006014 if (!getDerived().AlwaysRebuild() &&
6015 !Var &&
6016 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00006017 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00006018
6019 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
6020 Var,
John McCall9ae2f072010-08-23 23:25:46 +00006021 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00006022}
Mike Stump1eb44332009-09-09 15:08:12 +00006023
Douglas Gregor43959a92009-08-20 07:17:43 +00006024template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006025StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00006026TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
6027 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006028 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00006029 = getDerived().TransformCompoundStmt(S->getTryBlock());
6030 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006031 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00006032
Douglas Gregor43959a92009-08-20 07:17:43 +00006033 // Transform the handlers.
6034 bool HandlerChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006035 SmallVector<Stmt*, 8> Handlers;
Douglas Gregor43959a92009-08-20 07:17:43 +00006036 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00006037 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00006038 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
6039 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006040 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00006041
Douglas Gregor43959a92009-08-20 07:17:43 +00006042 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
6043 Handlers.push_back(Handler.takeAs<Stmt>());
6044 }
Mike Stump1eb44332009-09-09 15:08:12 +00006045
Douglas Gregor43959a92009-08-20 07:17:43 +00006046 if (!getDerived().AlwaysRebuild() &&
6047 TryBlock.get() == S->getTryBlock() &&
6048 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006049 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00006050
John McCall9ae2f072010-08-23 23:25:46 +00006051 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006052 Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00006053}
Mike Stump1eb44332009-09-09 15:08:12 +00006054
Richard Smithad762fc2011-04-14 22:09:26 +00006055template<typename Derived>
6056StmtResult
6057TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6058 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6059 if (Range.isInvalid())
6060 return StmtError();
6061
6062 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6063 if (BeginEnd.isInvalid())
6064 return StmtError();
6065
6066 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6067 if (Cond.isInvalid())
6068 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00006069 if (Cond.get())
6070 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
6071 if (Cond.isInvalid())
6072 return StmtError();
6073 if (Cond.get())
6074 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00006075
6076 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6077 if (Inc.isInvalid())
6078 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00006079 if (Inc.get())
6080 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00006081
6082 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6083 if (LoopVar.isInvalid())
6084 return StmtError();
6085
6086 StmtResult NewStmt = S;
6087 if (getDerived().AlwaysRebuild() ||
6088 Range.get() != S->getRangeStmt() ||
6089 BeginEnd.get() != S->getBeginEndStmt() ||
6090 Cond.get() != S->getCond() ||
6091 Inc.get() != S->getInc() ||
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006092 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smithad762fc2011-04-14 22:09:26 +00006093 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6094 S->getColonLoc(), Range.get(),
6095 BeginEnd.get(), Cond.get(),
6096 Inc.get(), LoopVar.get(),
6097 S->getRParenLoc());
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006098 if (NewStmt.isInvalid())
6099 return StmtError();
6100 }
Richard Smithad762fc2011-04-14 22:09:26 +00006101
6102 StmtResult Body = getDerived().TransformStmt(S->getBody());
6103 if (Body.isInvalid())
6104 return StmtError();
6105
6106 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6107 // it now so we have a new statement to attach the body to.
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006108 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smithad762fc2011-04-14 22:09:26 +00006109 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6110 S->getColonLoc(), Range.get(),
6111 BeginEnd.get(), Cond.get(),
6112 Inc.get(), LoopVar.get(),
6113 S->getRParenLoc());
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006114 if (NewStmt.isInvalid())
6115 return StmtError();
6116 }
Richard Smithad762fc2011-04-14 22:09:26 +00006117
6118 if (NewStmt.get() == S)
6119 return SemaRef.Owned(S);
6120
6121 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6122}
6123
John Wiegley28bbe4b2011-04-28 01:08:34 +00006124template<typename Derived>
6125StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00006126TreeTransform<Derived>::TransformMSDependentExistsStmt(
6127 MSDependentExistsStmt *S) {
6128 // Transform the nested-name-specifier, if any.
6129 NestedNameSpecifierLoc QualifierLoc;
6130 if (S->getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006131 QualifierLoc
Douglas Gregorba0513d2011-10-25 01:33:02 +00006132 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6133 if (!QualifierLoc)
6134 return StmtError();
6135 }
6136
6137 // Transform the declaration name.
6138 DeclarationNameInfo NameInfo = S->getNameInfo();
6139 if (NameInfo.getName()) {
6140 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6141 if (!NameInfo.getName())
6142 return StmtError();
6143 }
6144
6145 // Check whether anything changed.
6146 if (!getDerived().AlwaysRebuild() &&
6147 QualifierLoc == S->getQualifierLoc() &&
6148 NameInfo.getName() == S->getNameInfo().getName())
6149 return S;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006150
Douglas Gregorba0513d2011-10-25 01:33:02 +00006151 // Determine whether this name exists, if we can.
6152 CXXScopeSpec SS;
6153 SS.Adopt(QualifierLoc);
6154 bool Dependent = false;
6155 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
6156 case Sema::IER_Exists:
6157 if (S->isIfExists())
6158 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006159
Douglas Gregorba0513d2011-10-25 01:33:02 +00006160 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6161
6162 case Sema::IER_DoesNotExist:
6163 if (S->isIfNotExists())
6164 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006165
Douglas Gregorba0513d2011-10-25 01:33:02 +00006166 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006167
Douglas Gregorba0513d2011-10-25 01:33:02 +00006168 case Sema::IER_Dependent:
6169 Dependent = true;
6170 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006171
Douglas Gregor65019ac2011-10-25 03:44:56 +00006172 case Sema::IER_Error:
6173 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00006174 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006175
Douglas Gregorba0513d2011-10-25 01:33:02 +00006176 // We need to continue with the instantiation, so do so now.
6177 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6178 if (SubStmt.isInvalid())
6179 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006180
Douglas Gregorba0513d2011-10-25 01:33:02 +00006181 // If we have resolved the name, just transform to the substatement.
6182 if (!Dependent)
6183 return SubStmt;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006184
Douglas Gregorba0513d2011-10-25 01:33:02 +00006185 // The name is still dependent, so build a dependent expression again.
6186 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6187 S->isIfExists(),
6188 QualifierLoc,
6189 NameInfo,
6190 SubStmt.get());
6191}
6192
6193template<typename Derived>
John McCall76da55d2013-04-16 07:28:30 +00006194ExprResult
6195TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6196 NestedNameSpecifierLoc QualifierLoc;
6197 if (E->getQualifierLoc()) {
6198 QualifierLoc
6199 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6200 if (!QualifierLoc)
6201 return ExprError();
6202 }
6203
6204 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6205 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6206 if (!PD)
6207 return ExprError();
6208
6209 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6210 if (Base.isInvalid())
6211 return ExprError();
6212
6213 return new (SemaRef.getASTContext())
6214 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6215 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6216 QualifierLoc, E->getMemberLoc());
6217}
6218
6219template<typename Derived>
Douglas Gregorba0513d2011-10-25 01:33:02 +00006220StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00006221TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
6222 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
6223 if(TryBlock.isInvalid()) return StmtError();
6224
6225 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
6226 if(!getDerived().AlwaysRebuild() &&
6227 TryBlock.get() == S->getTryBlock() &&
6228 Handler.get() == S->getHandler())
6229 return SemaRef.Owned(S);
6230
6231 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
6232 S->getTryLoc(),
6233 TryBlock.take(),
6234 Handler.take());
6235}
6236
6237template<typename Derived>
6238StmtResult
6239TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
6240 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6241 if(Block.isInvalid()) return StmtError();
6242
6243 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
6244 Block.take());
6245}
6246
6247template<typename Derived>
6248StmtResult
6249TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
6250 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
6251 if(FilterExpr.isInvalid()) return StmtError();
6252
6253 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6254 if(Block.isInvalid()) return StmtError();
6255
6256 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
6257 FilterExpr.take(),
6258 Block.take());
6259}
6260
6261template<typename Derived>
6262StmtResult
6263TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6264 if(isa<SEHFinallyStmt>(Handler))
6265 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6266 else
6267 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6268}
6269
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006270template<typename Derived>
6271StmtResult
6272TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
Alexey Bataev0c018352013-09-06 18:03:48 +00006273 DeclarationNameInfo DirName;
6274 getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, 0);
6275
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006276 // Transform the clauses
Alexey Bataev0c018352013-09-06 18:03:48 +00006277 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006278 ArrayRef<OMPClause *> Clauses = D->clauses();
6279 TClauses.reserve(Clauses.size());
6280 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6281 I != E; ++I) {
6282 if (*I) {
6283 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataev0c018352013-09-06 18:03:48 +00006284 if (!Clause) {
6285 getSema().EndOpenMPDSABlock(0);
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006286 return StmtError();
Alexey Bataev0c018352013-09-06 18:03:48 +00006287 }
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006288 TClauses.push_back(Clause);
6289 }
6290 else {
6291 TClauses.push_back(0);
6292 }
6293 }
Alexey Bataev0c018352013-09-06 18:03:48 +00006294 if (!D->getAssociatedStmt()) {
6295 getSema().EndOpenMPDSABlock(0);
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006296 return StmtError();
Alexey Bataev0c018352013-09-06 18:03:48 +00006297 }
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006298 StmtResult AssociatedStmt =
6299 getDerived().TransformStmt(D->getAssociatedStmt());
Alexey Bataev0c018352013-09-06 18:03:48 +00006300 if (AssociatedStmt.isInvalid()) {
6301 getSema().EndOpenMPDSABlock(0);
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006302 return StmtError();
Alexey Bataev0c018352013-09-06 18:03:48 +00006303 }
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006304
Alexey Bataev0c018352013-09-06 18:03:48 +00006305 StmtResult Res = getDerived().RebuildOMPParallelDirective(TClauses,
6306 AssociatedStmt.take(),
6307 D->getLocStart(),
6308 D->getLocEnd());
6309 getSema().EndOpenMPDSABlock(Res.get());
6310 return Res;
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006311}
6312
6313template<typename Derived>
6314OMPClause *
6315TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
6316 return getDerived().RebuildOMPDefaultClause(C->getDefaultKind(),
6317 C->getDefaultKindKwLoc(),
6318 C->getLocStart(),
6319 C->getLParenLoc(),
6320 C->getLocEnd());
6321}
6322
6323template<typename Derived>
6324OMPClause *
6325TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev0c018352013-09-06 18:03:48 +00006326 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006327 Vars.reserve(C->varlist_size());
6328 for (OMPVarList<OMPPrivateClause>::varlist_iterator I = C->varlist_begin(),
6329 E = C->varlist_end();
6330 I != E; ++I) {
6331 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6332 if (EVar.isInvalid())
6333 return 0;
6334 Vars.push_back(EVar.take());
6335 }
6336 return getDerived().RebuildOMPPrivateClause(Vars,
6337 C->getLocStart(),
6338 C->getLParenLoc(),
6339 C->getLocEnd());
6340}
6341
Alexey Bataev0c018352013-09-06 18:03:48 +00006342template<typename Derived>
6343OMPClause *
6344TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
6345 llvm::SmallVector<Expr *, 16> Vars;
6346 Vars.reserve(C->varlist_size());
6347 for (OMPVarList<OMPSharedClause>::varlist_iterator I = C->varlist_begin(),
6348 E = C->varlist_end();
6349 I != E; ++I) {
6350 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6351 if (EVar.isInvalid())
6352 return 0;
6353 Vars.push_back(EVar.take());
6354 }
6355 return getDerived().RebuildOMPSharedClause(Vars,
6356 C->getLocStart(),
6357 C->getLParenLoc(),
6358 C->getLocEnd());
6359}
6360
Douglas Gregor43959a92009-08-20 07:17:43 +00006361//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00006362// Expression transformation
6363//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006364template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006365ExprResult
John McCall454feb92009-12-08 09:21:05 +00006366TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006367 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006368}
Mike Stump1eb44332009-09-09 15:08:12 +00006369
6370template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006371ExprResult
John McCall454feb92009-12-08 09:21:05 +00006372TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006373 NestedNameSpecifierLoc QualifierLoc;
6374 if (E->getQualifierLoc()) {
6375 QualifierLoc
6376 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6377 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006378 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006379 }
John McCalldbd872f2009-12-08 09:08:17 +00006380
6381 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006382 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6383 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006384 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006385 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006386
John McCallec8045d2010-08-17 21:27:17 +00006387 DeclarationNameInfo NameInfo = E->getNameInfo();
6388 if (NameInfo.getName()) {
6389 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6390 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006391 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006392 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006393
6394 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006395 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006396 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006397 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006398 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006399
6400 // Mark it referenced in the new context regardless.
6401 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006402 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006403
John McCall3fa5cae2010-10-26 07:05:15 +00006404 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006405 }
John McCalldbd872f2009-12-08 09:08:17 +00006406
6407 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006408 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006409 TemplateArgs = &TransArgs;
6410 TransArgs.setLAngleLoc(E->getLAngleLoc());
6411 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006412 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6413 E->getNumTemplateArgs(),
6414 TransArgs))
6415 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006416 }
6417
Chad Rosier4a9d7952012-08-08 18:46:20 +00006418 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregor40d96a62011-02-28 21:54:11 +00006419 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006420}
Mike Stump1eb44332009-09-09 15:08:12 +00006421
Douglas Gregorb98b1992009-08-11 05:31:07 +00006422template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006423ExprResult
John McCall454feb92009-12-08 09:21:05 +00006424TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006425 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006426}
Mike Stump1eb44332009-09-09 15:08:12 +00006427
Douglas Gregorb98b1992009-08-11 05:31:07 +00006428template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006429ExprResult
John McCall454feb92009-12-08 09:21:05 +00006430TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006431 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006432}
Mike Stump1eb44332009-09-09 15:08:12 +00006433
Douglas Gregorb98b1992009-08-11 05:31:07 +00006434template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006435ExprResult
John McCall454feb92009-12-08 09:21:05 +00006436TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006437 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006438}
Mike Stump1eb44332009-09-09 15:08:12 +00006439
Douglas Gregorb98b1992009-08-11 05:31:07 +00006440template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006441ExprResult
John McCall454feb92009-12-08 09:21:05 +00006442TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006443 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006444}
Mike Stump1eb44332009-09-09 15:08:12 +00006445
Douglas Gregorb98b1992009-08-11 05:31:07 +00006446template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006447ExprResult
John McCall454feb92009-12-08 09:21:05 +00006448TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006449 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006450}
6451
6452template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006453ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006454TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis391ca9f2013-04-09 01:17:02 +00006455 if (FunctionDecl *FD = E->getDirectCallee())
6456 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smith9fcce652012-03-07 08:35:16 +00006457 return SemaRef.MaybeBindToTemporary(E);
6458}
6459
6460template<typename Derived>
6461ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006462TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6463 ExprResult ControllingExpr =
6464 getDerived().TransformExpr(E->getControllingExpr());
6465 if (ControllingExpr.isInvalid())
6466 return ExprError();
6467
Chris Lattner686775d2011-07-20 06:58:45 +00006468 SmallVector<Expr *, 4> AssocExprs;
6469 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006470 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6471 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6472 if (TS) {
6473 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6474 if (!AssocType)
6475 return ExprError();
6476 AssocTypes.push_back(AssocType);
6477 } else {
6478 AssocTypes.push_back(0);
6479 }
6480
6481 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6482 if (AssocExpr.isInvalid())
6483 return ExprError();
6484 AssocExprs.push_back(AssocExpr.release());
6485 }
6486
6487 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6488 E->getDefaultLoc(),
6489 E->getRParenLoc(),
6490 ControllingExpr.release(),
Dmitri Gribenko80613222013-05-10 13:06:58 +00006491 AssocTypes,
6492 AssocExprs);
Peter Collingbournef111d932011-04-15 00:35:48 +00006493}
6494
6495template<typename Derived>
6496ExprResult
John McCall454feb92009-12-08 09:21:05 +00006497TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006498 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006499 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006500 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006501
Douglas Gregorb98b1992009-08-11 05:31:07 +00006502 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006503 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006504
John McCall9ae2f072010-08-23 23:25:46 +00006505 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006506 E->getRParen());
6507}
6508
Richard Smithefeeccf2012-10-21 03:28:35 +00006509/// \brief The operand of a unary address-of operator has special rules: it's
6510/// allowed to refer to a non-static member of a class even if there's no 'this'
6511/// object available.
6512template<typename Derived>
6513ExprResult
6514TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6515 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6516 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6517 else
6518 return getDerived().TransformExpr(E);
6519}
6520
Mike Stump1eb44332009-09-09 15:08:12 +00006521template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006522ExprResult
John McCall454feb92009-12-08 09:21:05 +00006523TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smith82b00012013-05-21 23:29:46 +00006524 ExprResult SubExpr;
6525 if (E->getOpcode() == UO_AddrOf)
6526 SubExpr = TransformAddressOfOperand(E->getSubExpr());
6527 else
6528 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006529 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006530 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006531
Douglas Gregorb98b1992009-08-11 05:31:07 +00006532 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006533 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006534
Douglas Gregorb98b1992009-08-11 05:31:07 +00006535 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6536 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006537 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006538}
Mike Stump1eb44332009-09-09 15:08:12 +00006539
Douglas Gregorb98b1992009-08-11 05:31:07 +00006540template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006541ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006542TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6543 // Transform the type.
6544 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6545 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006546 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006547
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006548 // Transform all of the components into components similar to what the
6549 // parser uses.
Chad Rosier4a9d7952012-08-08 18:46:20 +00006550 // FIXME: It would be slightly more efficient in the non-dependent case to
6551 // just map FieldDecls, rather than requiring the rebuilder to look for
6552 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006553 // template code that we don't care.
6554 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006555 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006556 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006557 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006558 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6559 const Node &ON = E->getComponent(I);
6560 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006561 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006562 Comp.LocStart = ON.getSourceRange().getBegin();
6563 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006564 switch (ON.getKind()) {
6565 case Node::Array: {
6566 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006567 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006568 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006569 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006570
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006571 ExprChanged = ExprChanged || Index.get() != FromIndex;
6572 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006573 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006574 break;
6575 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006576
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006577 case Node::Field:
6578 case Node::Identifier:
6579 Comp.isBrackets = false;
6580 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006581 if (!Comp.U.IdentInfo)
6582 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006583
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006584 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006585
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006586 case Node::Base:
6587 // Will be recomputed during the rebuild.
6588 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006589 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006590
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006591 Components.push_back(Comp);
6592 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006593
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006594 // If nothing changed, retain the existing expression.
6595 if (!getDerived().AlwaysRebuild() &&
6596 Type == E->getTypeSourceInfo() &&
6597 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006598 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006599
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006600 // Build a new offsetof expression.
6601 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6602 Components.data(), Components.size(),
6603 E->getRParenLoc());
6604}
6605
6606template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006607ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006608TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6609 assert(getDerived().AlreadyTransformed(E->getType()) &&
6610 "opaque value expression requires transformation");
6611 return SemaRef.Owned(E);
6612}
6613
6614template<typename Derived>
6615ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006616TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006617 // Rebuild the syntactic form. The original syntactic form has
6618 // opaque-value expressions in it, so strip those away and rebuild
6619 // the result. This is a really awful way of doing this, but the
6620 // better solution (rebuilding the semantic expressions and
6621 // rebinding OVEs as necessary) doesn't work; we'd need
6622 // TreeTransform to not strip away implicit conversions.
6623 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6624 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006625 if (result.isInvalid()) return ExprError();
6626
6627 // If that gives us a pseudo-object result back, the pseudo-object
6628 // expression must have been an lvalue-to-rvalue conversion which we
6629 // should reapply.
6630 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6631 result = SemaRef.checkPseudoObjectRValue(result.take());
6632
6633 return result;
6634}
6635
6636template<typename Derived>
6637ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006638TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6639 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006640 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006641 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006642
John McCalla93c9342009-12-07 02:54:59 +00006643 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006644 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006645 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006646
John McCall5ab75172009-11-04 07:28:41 +00006647 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006648 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006649
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006650 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6651 E->getKind(),
6652 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006653 }
Mike Stump1eb44332009-09-09 15:08:12 +00006654
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006655 // C++0x [expr.sizeof]p1:
6656 // The operand is either an expression, which is an unevaluated operand
6657 // [...]
Eli Friedman80bfa3d2012-09-26 04:34:21 +00006658 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6659 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00006660
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006661 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6662 if (SubExpr.isInvalid())
6663 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006664
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006665 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6666 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006667
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006668 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6669 E->getOperatorLoc(),
6670 E->getKind(),
6671 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006672}
Mike Stump1eb44332009-09-09 15:08:12 +00006673
Douglas Gregorb98b1992009-08-11 05:31:07 +00006674template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006675ExprResult
John McCall454feb92009-12-08 09:21:05 +00006676TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006677 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006678 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006679 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006680
John McCall60d7b3a2010-08-24 06:29:42 +00006681 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006682 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006683 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006684
6685
Douglas Gregorb98b1992009-08-11 05:31:07 +00006686 if (!getDerived().AlwaysRebuild() &&
6687 LHS.get() == E->getLHS() &&
6688 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006689 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006690
John McCall9ae2f072010-08-23 23:25:46 +00006691 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006692 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006693 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006694 E->getRBracketLoc());
6695}
Mike Stump1eb44332009-09-09 15:08:12 +00006696
6697template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006698ExprResult
John McCall454feb92009-12-08 09:21:05 +00006699TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006700 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006701 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006702 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006703 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006704
6705 // Transform arguments.
6706 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006707 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006708 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006709 &ArgChanged))
6710 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006711
Douglas Gregorb98b1992009-08-11 05:31:07 +00006712 if (!getDerived().AlwaysRebuild() &&
6713 Callee.get() == E->getCallee() &&
6714 !ArgChanged)
Dmitri Gribenko1ad23d62012-09-10 21:20:09 +00006715 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006716
Douglas Gregorb98b1992009-08-11 05:31:07 +00006717 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006718 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006719 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006720 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006721 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006722 E->getRParenLoc());
6723}
Mike Stump1eb44332009-09-09 15:08:12 +00006724
6725template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006726ExprResult
John McCall454feb92009-12-08 09:21:05 +00006727TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006728 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006729 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006730 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006731
Douglas Gregor40d96a62011-02-28 21:54:11 +00006732 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006733 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006734 QualifierLoc
6735 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006736
Douglas Gregor40d96a62011-02-28 21:54:11 +00006737 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006738 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006739 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006740 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006741
Eli Friedmanf595cc42009-12-04 06:40:45 +00006742 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006743 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6744 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006745 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006746 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006747
John McCall6bb80172010-03-30 21:47:33 +00006748 NamedDecl *FoundDecl = E->getFoundDecl();
6749 if (FoundDecl == E->getMemberDecl()) {
6750 FoundDecl = Member;
6751 } else {
6752 FoundDecl = cast_or_null<NamedDecl>(
6753 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6754 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006755 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006756 }
6757
Douglas Gregorb98b1992009-08-11 05:31:07 +00006758 if (!getDerived().AlwaysRebuild() &&
6759 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006760 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006761 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006762 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006763 !E->hasExplicitTemplateArgs()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006764
Anders Carlsson1f240322009-12-22 05:24:09 +00006765 // Mark it referenced in the new context regardless.
6766 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006767 SemaRef.MarkMemberReferenced(E);
6768
John McCall3fa5cae2010-10-26 07:05:15 +00006769 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006770 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006771
John McCalld5532b62009-11-23 01:53:49 +00006772 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006773 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006774 TransArgs.setLAngleLoc(E->getLAngleLoc());
6775 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006776 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6777 E->getNumTemplateArgs(),
6778 TransArgs))
6779 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006780 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006781
Douglas Gregorb98b1992009-08-11 05:31:07 +00006782 // FIXME: Bogus source location for the operator
6783 SourceLocation FakeOperatorLoc
6784 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6785
John McCallc2233c52010-01-15 08:34:02 +00006786 // FIXME: to do this check properly, we will need to preserve the
6787 // first-qualifier-in-scope here, just in case we had a dependent
6788 // base (and therefore couldn't do the check) and a
6789 // nested-name-qualifier (and therefore could do the lookup).
6790 NamedDecl *FirstQualifierInScope = 0;
6791
John McCall9ae2f072010-08-23 23:25:46 +00006792 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006793 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006794 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006795 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006796 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006797 Member,
John McCall6bb80172010-03-30 21:47:33 +00006798 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006799 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006800 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006801 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006802}
Mike Stump1eb44332009-09-09 15:08:12 +00006803
Douglas Gregorb98b1992009-08-11 05:31:07 +00006804template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006805ExprResult
John McCall454feb92009-12-08 09:21:05 +00006806TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006807 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006808 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006809 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006810
John McCall60d7b3a2010-08-24 06:29:42 +00006811 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006812 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006813 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006814
Douglas Gregorb98b1992009-08-11 05:31:07 +00006815 if (!getDerived().AlwaysRebuild() &&
6816 LHS.get() == E->getLHS() &&
6817 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006818 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006819
Lang Hamesbe9af122012-10-02 04:45:10 +00006820 Sema::FPContractStateRAII FPContractState(getSema());
6821 getSema().FPFeatures.fp_contract = E->isFPContractable();
6822
Douglas Gregorb98b1992009-08-11 05:31:07 +00006823 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006824 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006825}
6826
Mike Stump1eb44332009-09-09 15:08:12 +00006827template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006828ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006829TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006830 CompoundAssignOperator *E) {
6831 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006832}
Mike Stump1eb44332009-09-09 15:08:12 +00006833
Douglas Gregorb98b1992009-08-11 05:31:07 +00006834template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006835ExprResult TreeTransform<Derived>::
6836TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6837 // Just rebuild the common and RHS expressions and see whether we
6838 // get any changes.
6839
6840 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6841 if (commonExpr.isInvalid())
6842 return ExprError();
6843
6844 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6845 if (rhs.isInvalid())
6846 return ExprError();
6847
6848 if (!getDerived().AlwaysRebuild() &&
6849 commonExpr.get() == e->getCommon() &&
6850 rhs.get() == e->getFalseExpr())
6851 return SemaRef.Owned(e);
6852
6853 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6854 e->getQuestionLoc(),
6855 0,
6856 e->getColonLoc(),
6857 rhs.get());
6858}
6859
6860template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006861ExprResult
John McCall454feb92009-12-08 09:21:05 +00006862TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006863 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006864 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006865 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006866
John McCall60d7b3a2010-08-24 06:29:42 +00006867 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006868 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006869 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006870
John McCall60d7b3a2010-08-24 06:29:42 +00006871 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006872 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006873 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006874
Douglas Gregorb98b1992009-08-11 05:31:07 +00006875 if (!getDerived().AlwaysRebuild() &&
6876 Cond.get() == E->getCond() &&
6877 LHS.get() == E->getLHS() &&
6878 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006879 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006880
John McCall9ae2f072010-08-23 23:25:46 +00006881 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006882 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006883 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006884 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006885 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006886}
Mike Stump1eb44332009-09-09 15:08:12 +00006887
6888template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006889ExprResult
John McCall454feb92009-12-08 09:21:05 +00006890TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006891 // Implicit casts are eliminated during transformation, since they
6892 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006893 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006894}
Mike Stump1eb44332009-09-09 15:08:12 +00006895
Douglas Gregorb98b1992009-08-11 05:31:07 +00006896template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006897ExprResult
John McCall454feb92009-12-08 09:21:05 +00006898TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006899 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6900 if (!Type)
6901 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006902
John McCall60d7b3a2010-08-24 06:29:42 +00006903 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006904 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006905 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006906 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006907
Douglas Gregorb98b1992009-08-11 05:31:07 +00006908 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006909 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006910 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006911 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006912
John McCall9d125032010-01-15 18:39:57 +00006913 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006914 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006915 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006916 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006917}
Mike Stump1eb44332009-09-09 15:08:12 +00006918
Douglas Gregorb98b1992009-08-11 05:31:07 +00006919template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006920ExprResult
John McCall454feb92009-12-08 09:21:05 +00006921TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006922 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6923 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6924 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006925 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006926
John McCall60d7b3a2010-08-24 06:29:42 +00006927 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006928 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006929 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006930
Douglas Gregorb98b1992009-08-11 05:31:07 +00006931 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006932 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006933 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006934 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006935
John McCall1d7d8d62010-01-19 22:33:45 +00006936 // Note: the expression type doesn't necessarily match the
6937 // type-as-written, but that's okay, because it should always be
6938 // derivable from the initializer.
6939
John McCall42f56b52010-01-18 19:35:47 +00006940 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006941 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006942 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006943}
Mike Stump1eb44332009-09-09 15:08:12 +00006944
Douglas Gregorb98b1992009-08-11 05:31:07 +00006945template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006946ExprResult
John McCall454feb92009-12-08 09:21:05 +00006947TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006948 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006949 if (Base.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() &&
6953 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006954 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006955
Douglas Gregorb98b1992009-08-11 05:31:07 +00006956 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006957 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006958 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006959 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006960 E->getAccessorLoc(),
6961 E->getAccessor());
6962}
Mike Stump1eb44332009-09-09 15:08:12 +00006963
Douglas Gregorb98b1992009-08-11 05:31:07 +00006964template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006965ExprResult
John McCall454feb92009-12-08 09:21:05 +00006966TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006967 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006968
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006969 SmallVector<Expr*, 4> Inits;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006970 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006971 Inits, &InitChanged))
6972 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006973
Douglas Gregorb98b1992009-08-11 05:31:07 +00006974 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006975 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006976
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006977 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00006978 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006979}
Mike Stump1eb44332009-09-09 15:08:12 +00006980
Douglas Gregorb98b1992009-08-11 05:31:07 +00006981template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006982ExprResult
John McCall454feb92009-12-08 09:21:05 +00006983TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006984 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006985
Douglas Gregor43959a92009-08-20 07:17:43 +00006986 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006987 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006988 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006989 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006990
Douglas Gregor43959a92009-08-20 07:17:43 +00006991 // transform the designators.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006992 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006993 bool ExprChanged = false;
6994 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6995 DEnd = E->designators_end();
6996 D != DEnd; ++D) {
6997 if (D->isFieldDesignator()) {
6998 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6999 D->getDotLoc(),
7000 D->getFieldLoc()));
7001 continue;
7002 }
Mike Stump1eb44332009-09-09 15:08:12 +00007003
Douglas Gregorb98b1992009-08-11 05:31:07 +00007004 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00007005 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007006 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007007 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007008
7009 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007010 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00007011
Douglas Gregorb98b1992009-08-11 05:31:07 +00007012 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
7013 ArrayExprs.push_back(Index.release());
7014 continue;
7015 }
Mike Stump1eb44332009-09-09 15:08:12 +00007016
Douglas Gregorb98b1992009-08-11 05:31:07 +00007017 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00007018 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00007019 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7020 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007021 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007022
John McCall60d7b3a2010-08-24 06:29:42 +00007023 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007024 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007025 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007026
7027 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007028 End.get(),
7029 D->getLBracketLoc(),
7030 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00007031
Douglas Gregorb98b1992009-08-11 05:31:07 +00007032 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7033 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00007034
Douglas Gregorb98b1992009-08-11 05:31:07 +00007035 ArrayExprs.push_back(Start.release());
7036 ArrayExprs.push_back(End.release());
7037 }
Mike Stump1eb44332009-09-09 15:08:12 +00007038
Douglas Gregorb98b1992009-08-11 05:31:07 +00007039 if (!getDerived().AlwaysRebuild() &&
7040 Init.get() == E->getInit() &&
7041 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007042 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007043
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007044 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007045 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007046 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007047}
Mike Stump1eb44332009-09-09 15:08:12 +00007048
Douglas Gregorb98b1992009-08-11 05:31:07 +00007049template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007050ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007051TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00007052 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00007053 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007054
Douglas Gregor5557b252009-10-28 00:29:27 +00007055 // FIXME: Will we ever have proper type location here? Will we actually
7056 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00007057 QualType T = getDerived().TransformType(E->getType());
7058 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007059 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007060
Douglas Gregorb98b1992009-08-11 05:31:07 +00007061 if (!getDerived().AlwaysRebuild() &&
7062 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00007063 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007064
Douglas Gregorb98b1992009-08-11 05:31:07 +00007065 return getDerived().RebuildImplicitValueInitExpr(T);
7066}
Mike Stump1eb44332009-09-09 15:08:12 +00007067
Douglas Gregorb98b1992009-08-11 05:31:07 +00007068template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007069ExprResult
John McCall454feb92009-12-08 09:21:05 +00007070TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00007071 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7072 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007073 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007074
John McCall60d7b3a2010-08-24 06:29:42 +00007075 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007076 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007077 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007078
Douglas Gregorb98b1992009-08-11 05:31:07 +00007079 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00007080 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007081 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007082 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007083
John McCall9ae2f072010-08-23 23:25:46 +00007084 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00007085 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007086}
7087
7088template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007089ExprResult
John McCall454feb92009-12-08 09:21:05 +00007090TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007091 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007092 SmallVector<Expr*, 4> Inits;
Douglas Gregoraa165f82011-01-03 19:04:46 +00007093 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7094 &ArgumentChanged))
7095 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007096
Douglas Gregorb98b1992009-08-11 05:31:07 +00007097 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007098 Inits,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007099 E->getRParenLoc());
7100}
Mike Stump1eb44332009-09-09 15:08:12 +00007101
Douglas Gregorb98b1992009-08-11 05:31:07 +00007102/// \brief Transform an address-of-label expression.
7103///
7104/// By default, the transformation of an address-of-label expression always
7105/// rebuilds the expression, so that the label identifier can be resolved to
7106/// the corresponding label statement by semantic analysis.
7107template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007108ExprResult
John McCall454feb92009-12-08 09:21:05 +00007109TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00007110 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7111 E->getLabel());
7112 if (!LD)
7113 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007114
Douglas Gregorb98b1992009-08-11 05:31:07 +00007115 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00007116 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007117}
Mike Stump1eb44332009-09-09 15:08:12 +00007118
7119template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00007120ExprResult
John McCall454feb92009-12-08 09:21:05 +00007121TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00007122 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00007123 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00007124 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00007125 if (SubStmt.isInvalid()) {
7126 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00007127 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00007128 }
Mike Stump1eb44332009-09-09 15:08:12 +00007129
Douglas Gregorb98b1992009-08-11 05:31:07 +00007130 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00007131 SubStmt.get() == E->getSubStmt()) {
7132 // Calling this an 'error' is unintuitive, but it does the right thing.
7133 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00007134 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00007135 }
Mike Stump1eb44332009-09-09 15:08:12 +00007136
7137 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007138 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007139 E->getRParenLoc());
7140}
Mike Stump1eb44332009-09-09 15:08:12 +00007141
Douglas Gregorb98b1992009-08-11 05:31:07 +00007142template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007143ExprResult
John McCall454feb92009-12-08 09:21:05 +00007144TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007145 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007146 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007147 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007148
John McCall60d7b3a2010-08-24 06:29:42 +00007149 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007150 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007151 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007152
John McCall60d7b3a2010-08-24 06:29:42 +00007153 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007154 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007155 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007156
Douglas Gregorb98b1992009-08-11 05:31:07 +00007157 if (!getDerived().AlwaysRebuild() &&
7158 Cond.get() == E->getCond() &&
7159 LHS.get() == E->getLHS() &&
7160 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00007161 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007162
Douglas Gregorb98b1992009-08-11 05:31:07 +00007163 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007164 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007165 E->getRParenLoc());
7166}
Mike Stump1eb44332009-09-09 15:08:12 +00007167
Douglas Gregorb98b1992009-08-11 05:31:07 +00007168template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007169ExprResult
John McCall454feb92009-12-08 09:21:05 +00007170TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007171 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007172}
7173
7174template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007175ExprResult
John McCall454feb92009-12-08 09:21:05 +00007176TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00007177 switch (E->getOperator()) {
7178 case OO_New:
7179 case OO_Delete:
7180 case OO_Array_New:
7181 case OO_Array_Delete:
7182 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier4a9d7952012-08-08 18:46:20 +00007183
Douglas Gregor668d6d92009-12-13 20:44:55 +00007184 case OO_Call: {
7185 // This is a call to an object's operator().
7186 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7187
7188 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00007189 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00007190 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007191 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00007192
7193 // FIXME: Poor location information
7194 SourceLocation FakeLParenLoc
7195 = SemaRef.PP.getLocForEndOfToken(
7196 static_cast<Expr *>(Object.get())->getLocEnd());
7197
7198 // Transform the call arguments.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007199 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007200 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007201 Args))
7202 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00007203
John McCall9ae2f072010-08-23 23:25:46 +00007204 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007205 Args,
Douglas Gregor668d6d92009-12-13 20:44:55 +00007206 E->getLocEnd());
7207 }
7208
7209#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7210 case OO_##Name:
7211#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7212#include "clang/Basic/OperatorKinds.def"
7213 case OO_Subscript:
7214 // Handled below.
7215 break;
7216
7217 case OO_Conditional:
7218 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00007219
7220 case OO_None:
7221 case NUM_OVERLOADED_OPERATORS:
7222 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00007223 }
7224
John McCall60d7b3a2010-08-24 06:29:42 +00007225 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007226 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007227 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007228
Richard Smithefeeccf2012-10-21 03:28:35 +00007229 ExprResult First;
7230 if (E->getOperator() == OO_Amp)
7231 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7232 else
7233 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007234 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007235 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007236
John McCall60d7b3a2010-08-24 06:29:42 +00007237 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00007238 if (E->getNumArgs() == 2) {
7239 Second = getDerived().TransformExpr(E->getArg(1));
7240 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007241 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007242 }
Mike Stump1eb44332009-09-09 15:08:12 +00007243
Douglas Gregorb98b1992009-08-11 05:31:07 +00007244 if (!getDerived().AlwaysRebuild() &&
7245 Callee.get() == E->getCallee() &&
7246 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00007247 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00007248 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007249
Lang Hamesbe9af122012-10-02 04:45:10 +00007250 Sema::FPContractStateRAII FPContractState(getSema());
7251 getSema().FPFeatures.fp_contract = E->isFPContractable();
7252
Douglas Gregorb98b1992009-08-11 05:31:07 +00007253 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7254 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007255 Callee.get(),
7256 First.get(),
7257 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007258}
Mike Stump1eb44332009-09-09 15:08:12 +00007259
Douglas Gregorb98b1992009-08-11 05:31:07 +00007260template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007261ExprResult
John McCall454feb92009-12-08 09:21:05 +00007262TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7263 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007264}
Mike Stump1eb44332009-09-09 15:08:12 +00007265
Douglas Gregorb98b1992009-08-11 05:31:07 +00007266template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007267ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00007268TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7269 // Transform the callee.
7270 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7271 if (Callee.isInvalid())
7272 return ExprError();
7273
7274 // Transform exec config.
7275 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7276 if (EC.isInvalid())
7277 return ExprError();
7278
7279 // Transform arguments.
7280 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007281 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007282 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007283 &ArgChanged))
7284 return ExprError();
7285
7286 if (!getDerived().AlwaysRebuild() &&
7287 Callee.get() == E->getCallee() &&
7288 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00007289 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00007290
7291 // FIXME: Wrong source location information for the '('.
7292 SourceLocation FakeLParenLoc
7293 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7294 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007295 Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007296 E->getRParenLoc(), EC.get());
7297}
7298
7299template<typename Derived>
7300ExprResult
John McCall454feb92009-12-08 09:21:05 +00007301TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007302 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7303 if (!Type)
7304 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007305
John McCall60d7b3a2010-08-24 06:29:42 +00007306 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007307 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007308 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007309 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007310
Douglas Gregorb98b1992009-08-11 05:31:07 +00007311 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007312 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007313 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007314 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007315 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00007316 E->getStmtClass(),
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007317 E->getAngleBrackets().getBegin(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007318 Type,
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007319 E->getAngleBrackets().getEnd(),
7320 // FIXME. this should be '(' location
7321 E->getAngleBrackets().getEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00007322 SubExpr.get(),
Abramo Bagnara6cf7d7d2012-10-15 21:08:58 +00007323 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007324}
Mike Stump1eb44332009-09-09 15:08:12 +00007325
Douglas Gregorb98b1992009-08-11 05:31:07 +00007326template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007327ExprResult
John McCall454feb92009-12-08 09:21:05 +00007328TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7329 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007330}
Mike Stump1eb44332009-09-09 15:08:12 +00007331
7332template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007333ExprResult
John McCall454feb92009-12-08 09:21:05 +00007334TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7335 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007336}
7337
Douglas Gregorb98b1992009-08-11 05:31:07 +00007338template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007339ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007340TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007341 CXXReinterpretCastExpr *E) {
7342 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007343}
Mike Stump1eb44332009-09-09 15:08:12 +00007344
Douglas Gregorb98b1992009-08-11 05:31:07 +00007345template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007346ExprResult
John McCall454feb92009-12-08 09:21:05 +00007347TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7348 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007349}
Mike Stump1eb44332009-09-09 15:08:12 +00007350
Douglas Gregorb98b1992009-08-11 05:31:07 +00007351template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007352ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007353TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007354 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007355 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7356 if (!Type)
7357 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007358
John McCall60d7b3a2010-08-24 06:29:42 +00007359 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007360 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007361 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007362 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007363
Douglas Gregorb98b1992009-08-11 05:31:07 +00007364 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007365 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007366 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007367 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007368
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007369 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedmancdd4b782013-08-15 22:02:56 +00007370 E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007371 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007372 E->getRParenLoc());
7373}
Mike Stump1eb44332009-09-09 15:08:12 +00007374
Douglas Gregorb98b1992009-08-11 05:31:07 +00007375template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007376ExprResult
John McCall454feb92009-12-08 09:21:05 +00007377TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007378 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007379 TypeSourceInfo *TInfo
7380 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7381 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007382 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007383
Douglas Gregorb98b1992009-08-11 05:31:07 +00007384 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007385 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007386 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007387
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007388 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7389 E->getLocStart(),
7390 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007391 E->getLocEnd());
7392 }
Mike Stump1eb44332009-09-09 15:08:12 +00007393
Eli Friedmanef331b72012-01-20 01:26:23 +00007394 // We don't know whether the subexpression is potentially evaluated until
7395 // after we perform semantic analysis. We speculatively assume it is
7396 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007397 // potentially evaluated.
Eli Friedman80bfa3d2012-09-26 04:34:21 +00007398 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7399 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00007400
John McCall60d7b3a2010-08-24 06:29:42 +00007401 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007402 if (SubExpr.isInvalid())
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() &&
7406 SubExpr.get() == E->getExprOperand())
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(),
John McCall9ae2f072010-08-23 23:25:46 +00007411 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007412 E->getLocEnd());
7413}
7414
7415template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007416ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007417TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7418 if (E->isTypeOperand()) {
7419 TypeSourceInfo *TInfo
7420 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7421 if (!TInfo)
7422 return ExprError();
7423
7424 if (!getDerived().AlwaysRebuild() &&
7425 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007426 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007427
Douglas Gregor3c52a212011-03-06 17:40:41 +00007428 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007429 E->getLocStart(),
7430 TInfo,
7431 E->getLocEnd());
7432 }
7433
Francois Pichet01b7c302010-09-08 12:20:18 +00007434 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7435
7436 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7437 if (SubExpr.isInvalid())
7438 return ExprError();
7439
7440 if (!getDerived().AlwaysRebuild() &&
7441 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007442 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007443
7444 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7445 E->getLocStart(),
7446 SubExpr.get(),
7447 E->getLocEnd());
7448}
7449
7450template<typename Derived>
7451ExprResult
John McCall454feb92009-12-08 09:21:05 +00007452TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007453 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007454}
Mike Stump1eb44332009-09-09 15:08:12 +00007455
Douglas Gregorb98b1992009-08-11 05:31:07 +00007456template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007457ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007458TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007459 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007460 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007461}
Mike Stump1eb44332009-09-09 15:08:12 +00007462
Douglas Gregorb98b1992009-08-11 05:31:07 +00007463template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007464ExprResult
John McCall454feb92009-12-08 09:21:05 +00007465TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithcafeb942013-06-07 02:33:37 +00007466 QualType T = getSema().getCurrentThisType();
Mike Stump1eb44332009-09-09 15:08:12 +00007467
Douglas Gregorec79d872012-02-24 17:41:38 +00007468 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7469 // Make sure that we capture 'this'.
7470 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007471 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007472 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007473
Douglas Gregor828a1972010-01-07 23:12:05 +00007474 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
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
John McCall454feb92009-12-08 09:21:05 +00007479TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007480 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007481 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007482 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007483
Douglas Gregorb98b1992009-08-11 05:31:07 +00007484 if (!getDerived().AlwaysRebuild() &&
7485 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007486 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007487
Douglas Gregorbca01b42011-07-06 22:04:06 +00007488 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7489 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007490}
Mike Stump1eb44332009-09-09 15:08:12 +00007491
Douglas Gregorb98b1992009-08-11 05:31:07 +00007492template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007493ExprResult
John McCall454feb92009-12-08 09:21:05 +00007494TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007495 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007496 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7497 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007498 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007499 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007500
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007501 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007502 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007503 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007504
Douglas Gregor036aed12009-12-23 23:03:06 +00007505 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007506}
Mike Stump1eb44332009-09-09 15:08:12 +00007507
Douglas Gregorb98b1992009-08-11 05:31:07 +00007508template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007509ExprResult
Richard Smithc3bf52c2013-04-20 22:23:05 +00007510TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
7511 FieldDecl *Field
7512 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
7513 E->getField()));
7514 if (!Field)
7515 return ExprError();
7516
7517 if (!getDerived().AlwaysRebuild() && Field == E->getField())
7518 return SemaRef.Owned(E);
7519
7520 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
7521}
7522
7523template<typename Derived>
7524ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007525TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7526 CXXScalarValueInitExpr *E) {
7527 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7528 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007529 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007530
Douglas Gregorb98b1992009-08-11 05:31:07 +00007531 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007532 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007533 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007534
Chad Rosier4a9d7952012-08-08 18:46:20 +00007535 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregorab6677e2010-09-08 00:15:04 +00007536 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007537 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007538}
Mike Stump1eb44332009-09-09 15:08:12 +00007539
Douglas Gregorb98b1992009-08-11 05:31:07 +00007540template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007541ExprResult
John McCall454feb92009-12-08 09:21:05 +00007542TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007543 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007544 TypeSourceInfo *AllocTypeInfo
7545 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7546 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007547 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007548
Douglas Gregorb98b1992009-08-11 05:31:07 +00007549 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007550 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007551 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007552 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007553
Douglas Gregorb98b1992009-08-11 05:31:07 +00007554 // Transform the placement arguments (if any).
7555 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007556 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007557 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregoraa165f82011-01-03 19:04:46 +00007558 E->getNumPlacementArgs(), true,
7559 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007560 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007561
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007562 // Transform the initializer (if any).
7563 Expr *OldInit = E->getInitializer();
7564 ExprResult NewInit;
7565 if (OldInit)
7566 NewInit = getDerived().TransformExpr(OldInit);
7567 if (NewInit.isInvalid())
7568 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007569
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007570 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007571 FunctionDecl *OperatorNew = 0;
7572 if (E->getOperatorNew()) {
7573 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007574 getDerived().TransformDecl(E->getLocStart(),
7575 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007576 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007577 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007578 }
7579
7580 FunctionDecl *OperatorDelete = 0;
7581 if (E->getOperatorDelete()) {
7582 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007583 getDerived().TransformDecl(E->getLocStart(),
7584 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007585 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007586 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007587 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007588
Douglas Gregorb98b1992009-08-11 05:31:07 +00007589 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007590 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007591 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007592 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007593 OperatorNew == E->getOperatorNew() &&
7594 OperatorDelete == E->getOperatorDelete() &&
7595 !ArgumentChanged) {
7596 // Mark any declarations we need as referenced.
7597 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007598 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007599 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007600 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007601 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007602
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007603 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007604 QualType ElementType
7605 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7606 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7607 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7608 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007609 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007610 }
7611 }
7612 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007613
John McCall3fa5cae2010-10-26 07:05:15 +00007614 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007615 }
Mike Stump1eb44332009-09-09 15:08:12 +00007616
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007617 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007618 if (!ArraySize.get()) {
7619 // If no array size was specified, but the new expression was
7620 // instantiated with an array type (e.g., "new T" where T is
7621 // instantiated with "int[4]"), extract the outer bound from the
7622 // array type as our array size. We do this with constant and
7623 // dependently-sized array types.
7624 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7625 if (!ArrayT) {
7626 // Do nothing
7627 } else if (const ConstantArrayType *ConsArrayT
7628 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007629 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007630 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier4a9d7952012-08-08 18:46:20 +00007631 ConsArrayT->getSize(),
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007632 SemaRef.Context.getSizeType(),
7633 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007634 AllocType = ConsArrayT->getElementType();
7635 } else if (const DependentSizedArrayType *DepArrayT
7636 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7637 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007638 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007639 AllocType = DepArrayT->getElementType();
7640 }
7641 }
7642 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007643
Douglas Gregorb98b1992009-08-11 05:31:07 +00007644 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7645 E->isGlobalNew(),
7646 /*FIXME:*/E->getLocStart(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007647 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007648 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007649 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007650 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007651 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007652 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007653 E->getDirectInitRange(),
7654 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007655}
Mike Stump1eb44332009-09-09 15:08:12 +00007656
Douglas Gregorb98b1992009-08-11 05:31:07 +00007657template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007658ExprResult
John McCall454feb92009-12-08 09:21:05 +00007659TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007660 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007661 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007662 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007663
Douglas Gregor1af74512010-02-26 00:38:10 +00007664 // Transform the delete operator, if known.
7665 FunctionDecl *OperatorDelete = 0;
7666 if (E->getOperatorDelete()) {
7667 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007668 getDerived().TransformDecl(E->getLocStart(),
7669 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007670 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007671 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007672 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007673
Douglas Gregorb98b1992009-08-11 05:31:07 +00007674 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007675 Operand.get() == E->getArgument() &&
7676 OperatorDelete == E->getOperatorDelete()) {
7677 // Mark any declarations we need as referenced.
7678 // FIXME: instantiation-specific.
7679 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007680 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007681
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007682 if (!E->getArgument()->isTypeDependent()) {
7683 QualType Destroyed = SemaRef.Context.getBaseElementType(
7684 E->getDestroyedType());
7685 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7686 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007687 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedman5f2987c2012-02-02 03:46:19 +00007688 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007689 }
7690 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007691
John McCall3fa5cae2010-10-26 07:05:15 +00007692 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007693 }
Mike Stump1eb44332009-09-09 15:08:12 +00007694
Douglas Gregorb98b1992009-08-11 05:31:07 +00007695 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7696 E->isGlobalDelete(),
7697 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007698 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007699}
Mike Stump1eb44332009-09-09 15:08:12 +00007700
Douglas Gregorb98b1992009-08-11 05:31:07 +00007701template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007702ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007703TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007704 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007705 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007706 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007707 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007708
John McCallb3d87482010-08-24 05:47:05 +00007709 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007710 bool MayBePseudoDestructor = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007711 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007712 E->getOperatorLoc(),
7713 E->isArrow()? tok::arrow : tok::period,
7714 ObjectTypePtr,
7715 MayBePseudoDestructor);
7716 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007717 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007718
John McCallb3d87482010-08-24 05:47:05 +00007719 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007720 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7721 if (QualifierLoc) {
7722 QualifierLoc
7723 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7724 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007725 return ExprError();
7726 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007727 CXXScopeSpec SS;
7728 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007729
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007730 PseudoDestructorTypeStorage Destroyed;
7731 if (E->getDestroyedTypeInfo()) {
7732 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007733 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007734 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007735 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007736 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007737 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007738 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007739 // We aren't likely to be able to resolve the identifier down to a type
7740 // now anyway, so just retain the identifier.
7741 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7742 E->getDestroyedTypeLoc());
7743 } else {
7744 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007745 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007746 *E->getDestroyedTypeIdentifier(),
7747 E->getDestroyedTypeLoc(),
7748 /*Scope=*/0,
7749 SS, ObjectTypePtr,
7750 false);
7751 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007752 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007753
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007754 Destroyed
7755 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7756 E->getDestroyedTypeLoc());
7757 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007758
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007759 TypeSourceInfo *ScopeTypeInfo = 0;
7760 if (E->getScopeTypeInfo()) {
Douglas Gregor303b96f2013-03-08 21:25:01 +00007761 CXXScopeSpec EmptySS;
7762 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
7763 E->getScopeTypeInfo(), ObjectType, 0, EmptySS);
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007764 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007765 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007766 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007767
John McCall9ae2f072010-08-23 23:25:46 +00007768 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007769 E->getOperatorLoc(),
7770 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007771 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007772 ScopeTypeInfo,
7773 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007774 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007775 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007776}
Mike Stump1eb44332009-09-09 15:08:12 +00007777
Douglas Gregora71d8192009-09-04 17:36:40 +00007778template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007779ExprResult
John McCallba135432009-11-21 08:51:07 +00007780TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007781 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007782 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7783 Sema::LookupOrdinaryName);
7784
7785 // Transform all the decls.
7786 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7787 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007788 NamedDecl *InstD = static_cast<NamedDecl*>(
7789 getDerived().TransformDecl(Old->getNameLoc(),
7790 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007791 if (!InstD) {
7792 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7793 // This can happen because of dependent hiding.
7794 if (isa<UsingShadowDecl>(*I))
7795 continue;
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007796 else {
7797 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00007798 return ExprError();
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007799 }
John McCall9f54ad42009-12-10 09:41:52 +00007800 }
John McCallf7a1a742009-11-24 19:00:30 +00007801
7802 // Expand using declarations.
7803 if (isa<UsingDecl>(InstD)) {
7804 UsingDecl *UD = cast<UsingDecl>(InstD);
7805 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7806 E = UD->shadow_end(); I != E; ++I)
7807 R.addDecl(*I);
7808 continue;
7809 }
7810
7811 R.addDecl(InstD);
7812 }
7813
7814 // Resolve a kind, but don't do any further analysis. If it's
7815 // ambiguous, the callee needs to deal with it.
7816 R.resolveKind();
7817
7818 // Rebuild the nested-name qualifier, if present.
7819 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007820 if (Old->getQualifierLoc()) {
7821 NestedNameSpecifierLoc QualifierLoc
7822 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7823 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007824 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007825
Douglas Gregor4c9be892011-02-28 20:01:57 +00007826 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007827 }
7828
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007829 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007830 CXXRecordDecl *NamingClass
7831 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7832 Old->getNameLoc(),
7833 Old->getNamingClass()));
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007834 if (!NamingClass) {
7835 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00007836 return ExprError();
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007837 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007838
Douglas Gregor66c45152010-04-27 16:10:10 +00007839 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007840 }
7841
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007842 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7843
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007844 // If we have neither explicit template arguments, nor the template keyword,
7845 // it's a normal declaration name.
7846 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007847 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7848
7849 // If we have template arguments, rebuild them, then rebuild the
7850 // templateid expression.
7851 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola02e221b2012-08-28 04:13:54 +00007852 if (Old->hasExplicitTemplateArgs() &&
7853 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregorfcc12532010-12-20 17:31:10 +00007854 Old->getNumTemplateArgs(),
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007855 TransArgs)) {
7856 R.clear();
Douglas Gregorfcc12532010-12-20 17:31:10 +00007857 return ExprError();
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007858 }
John McCallf7a1a742009-11-24 19:00:30 +00007859
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007860 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007861 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007862}
Mike Stump1eb44332009-09-09 15:08:12 +00007863
Douglas Gregorb98b1992009-08-11 05:31:07 +00007864template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007865ExprResult
John McCall454feb92009-12-08 09:21:05 +00007866TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007867 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7868 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007869 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007870
Douglas Gregorb98b1992009-08-11 05:31:07 +00007871 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007872 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007873 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007874
Mike Stump1eb44332009-09-09 15:08:12 +00007875 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007876 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007877 T,
7878 E->getLocEnd());
7879}
Mike Stump1eb44332009-09-09 15:08:12 +00007880
Douglas Gregorb98b1992009-08-11 05:31:07 +00007881template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007882ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007883TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7884 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7885 if (!LhsT)
7886 return ExprError();
7887
7888 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7889 if (!RhsT)
7890 return ExprError();
7891
7892 if (!getDerived().AlwaysRebuild() &&
7893 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7894 return SemaRef.Owned(E);
7895
7896 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7897 E->getLocStart(),
7898 LhsT, RhsT,
7899 E->getLocEnd());
7900}
7901
7902template<typename Derived>
7903ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007904TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7905 bool ArgChanged = false;
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00007906 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007907 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7908 TypeSourceInfo *From = E->getArg(I);
7909 TypeLoc FromTL = From->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00007910 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007911 TypeLocBuilder TLB;
7912 TLB.reserve(FromTL.getFullDataSize());
7913 QualType To = getDerived().TransformType(TLB, FromTL);
7914 if (To.isNull())
7915 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007916
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007917 if (To == From->getType())
7918 Args.push_back(From);
7919 else {
7920 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7921 ArgChanged = true;
7922 }
7923 continue;
7924 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007925
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007926 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007927
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007928 // We have a pack expansion. Instantiate it.
David Blaikie39e6ab42013-02-18 22:06:02 +00007929 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007930 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7931 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7932 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007933
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007934 // Determine whether the set of unexpanded parameter packs can and should
7935 // be expanded.
7936 bool Expand = true;
7937 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00007938 Optional<unsigned> OrigNumExpansions =
7939 ExpansionTL.getTypePtr()->getNumExpansions();
7940 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007941 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7942 PatternTL.getSourceRange(),
7943 Unexpanded,
7944 Expand, RetainExpansion,
7945 NumExpansions))
7946 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007947
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007948 if (!Expand) {
7949 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00007950 // transformation on the pack expansion, producing another pack
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007951 // expansion.
7952 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007953
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007954 TypeLocBuilder TLB;
7955 TLB.reserve(From->getTypeLoc().getFullDataSize());
7956
7957 QualType To = getDerived().TransformType(TLB, PatternTL);
7958 if (To.isNull())
7959 return ExprError();
7960
Chad Rosier4a9d7952012-08-08 18:46:20 +00007961 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007962 PatternTL.getSourceRange(),
7963 ExpansionTL.getEllipsisLoc(),
7964 NumExpansions);
7965 if (To.isNull())
7966 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007967
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007968 PackExpansionTypeLoc ToExpansionTL
7969 = TLB.push<PackExpansionTypeLoc>(To);
7970 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7971 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7972 continue;
7973 }
7974
7975 // Expand the pack expansion by substituting for each argument in the
7976 // pack(s).
7977 for (unsigned I = 0; I != *NumExpansions; ++I) {
7978 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7979 TypeLocBuilder TLB;
7980 TLB.reserve(PatternTL.getFullDataSize());
7981 QualType To = getDerived().TransformType(TLB, PatternTL);
7982 if (To.isNull())
7983 return ExprError();
7984
Eli Friedman20cfeca2013-07-19 21:49:32 +00007985 if (To->containsUnexpandedParameterPack()) {
7986 To = getDerived().RebuildPackExpansionType(To,
7987 PatternTL.getSourceRange(),
7988 ExpansionTL.getEllipsisLoc(),
7989 NumExpansions);
7990 if (To.isNull())
7991 return ExprError();
7992
7993 PackExpansionTypeLoc ToExpansionTL
7994 = TLB.push<PackExpansionTypeLoc>(To);
7995 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7996 }
7997
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007998 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7999 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008000
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008001 if (!RetainExpansion)
8002 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008003
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008004 // If we're supposed to retain a pack expansion, do so by temporarily
8005 // forgetting the partially-substituted parameter pack.
8006 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
8007
8008 TypeLocBuilder TLB;
8009 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008010
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008011 QualType To = getDerived().TransformType(TLB, PatternTL);
8012 if (To.isNull())
8013 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008014
8015 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008016 PatternTL.getSourceRange(),
8017 ExpansionTL.getEllipsisLoc(),
8018 NumExpansions);
8019 if (To.isNull())
8020 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008021
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008022 PackExpansionTypeLoc ToExpansionTL
8023 = TLB.push<PackExpansionTypeLoc>(To);
8024 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8025 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8026 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008027
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008028 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8029 return SemaRef.Owned(E);
8030
8031 return getDerived().RebuildTypeTrait(E->getTrait(),
8032 E->getLocStart(),
8033 Args,
8034 E->getLocEnd());
8035}
8036
8037template<typename Derived>
8038ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00008039TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8040 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
8041 if (!T)
8042 return ExprError();
8043
8044 if (!getDerived().AlwaysRebuild() &&
8045 T == E->getQueriedTypeSourceInfo())
8046 return SemaRef.Owned(E);
8047
8048 ExprResult SubExpr;
8049 {
8050 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8051 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8052 if (SubExpr.isInvalid())
8053 return ExprError();
8054
8055 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
8056 return SemaRef.Owned(E);
8057 }
8058
8059 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8060 E->getLocStart(),
8061 T,
8062 SubExpr.get(),
8063 E->getLocEnd());
8064}
8065
8066template<typename Derived>
8067ExprResult
John Wiegley55262202011-04-25 06:54:41 +00008068TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8069 ExprResult SubExpr;
8070 {
8071 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8072 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8073 if (SubExpr.isInvalid())
8074 return ExprError();
8075
8076 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
8077 return SemaRef.Owned(E);
8078 }
8079
8080 return getDerived().RebuildExpressionTrait(
8081 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8082}
8083
8084template<typename Derived>
8085ExprResult
John McCall865d4472009-11-19 22:55:06 +00008086TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008087 DependentScopeDeclRefExpr *E) {
Richard Smithefeeccf2012-10-21 03:28:35 +00008088 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
8089}
8090
8091template<typename Derived>
8092ExprResult
8093TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8094 DependentScopeDeclRefExpr *E,
8095 bool IsAddressOfOperand) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008096 NestedNameSpecifierLoc QualifierLoc
8097 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8098 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008099 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008100 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00008101
John McCall43fed0d2010-11-12 08:19:04 +00008102 // TODO: If this is a conversion-function-id, verify that the
8103 // destination type name (if present) resolves the same way after
8104 // instantiation as it did in the local scope.
8105
Abramo Bagnara25777432010-08-11 22:01:17 +00008106 DeclarationNameInfo NameInfo
8107 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8108 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008109 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008110
John McCallf7a1a742009-11-24 19:00:30 +00008111 if (!E->hasExplicitTemplateArgs()) {
8112 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008113 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008114 // Note: it is sufficient to compare the Name component of NameInfo:
8115 // if name has not changed, DNLoc has not changed either.
8116 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00008117 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008118
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008119 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008120 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00008121 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00008122 /*TemplateArgs*/ 0,
8123 IsAddressOfOperand);
Douglas Gregorf17bb742009-10-22 17:20:55 +00008124 }
John McCalld5532b62009-11-23 01:53:49 +00008125
8126 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008127 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8128 E->getNumTemplateArgs(),
8129 TransArgs))
8130 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00008131
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008132 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008133 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00008134 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00008135 &TransArgs,
8136 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008137}
8138
8139template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008140ExprResult
John McCall454feb92009-12-08 09:21:05 +00008141TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithc83c2302012-12-19 01:39:02 +00008142 // CXXConstructExprs other than for list-initialization and
8143 // CXXTemporaryObjectExpr are always implicit, so when we have
8144 // a 1-argument construction we just transform that argument.
Richard Smith73ed67c2012-11-26 08:32:48 +00008145 if ((E->getNumArgs() == 1 ||
8146 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithc83c2302012-12-19 01:39:02 +00008147 (!getDerived().DropCallArgument(E->getArg(0))) &&
8148 !E->isListInitialization())
Douglas Gregor321725d2010-02-03 03:01:57 +00008149 return getDerived().TransformExpr(E->getArg(0));
8150
Douglas Gregorb98b1992009-08-11 05:31:07 +00008151 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8152
8153 QualType T = getDerived().TransformType(E->getType());
8154 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00008155 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00008156
8157 CXXConstructorDecl *Constructor
8158 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008159 getDerived().TransformDecl(E->getLocStart(),
8160 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008161 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00008162 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008163
Douglas Gregorb98b1992009-08-11 05:31:07 +00008164 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008165 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008166 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008167 &ArgumentChanged))
8168 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008169
Douglas Gregorb98b1992009-08-11 05:31:07 +00008170 if (!getDerived().AlwaysRebuild() &&
8171 T == E->getType() &&
8172 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00008173 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00008174 // Mark the constructor as referenced.
8175 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00008176 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00008177 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00008178 }
Mike Stump1eb44332009-09-09 15:08:12 +00008179
Douglas Gregor4411d2e2009-12-14 16:27:04 +00008180 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8181 Constructor, E->isElidable(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008182 Args,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00008183 E->hadMultipleCandidates(),
Richard Smithc83c2302012-12-19 01:39:02 +00008184 E->isListInitialization(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00008185 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00008186 E->getConstructionKind(),
Enea Zaffanella1245a542013-09-07 05:49:53 +00008187 E->getParenOrBraceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008188}
Mike Stump1eb44332009-09-09 15:08:12 +00008189
Douglas Gregorb98b1992009-08-11 05:31:07 +00008190/// \brief Transform a C++ temporary-binding expression.
8191///
Douglas Gregor51326552009-12-24 18:51:59 +00008192/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8193/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00008194template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008195ExprResult
John McCall454feb92009-12-08 09:21:05 +00008196TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00008197 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008198}
Mike Stump1eb44332009-09-09 15:08:12 +00008199
John McCall4765fa02010-12-06 08:20:24 +00008200/// \brief Transform a C++ expression that contains cleanups that should
8201/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00008202///
John McCall4765fa02010-12-06 08:20:24 +00008203/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00008204/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00008205template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008206ExprResult
John McCall4765fa02010-12-06 08:20:24 +00008207TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00008208 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008209}
Mike Stump1eb44332009-09-09 15:08:12 +00008210
Douglas Gregorb98b1992009-08-11 05:31:07 +00008211template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008212ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008213TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00008214 CXXTemporaryObjectExpr *E) {
8215 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8216 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008217 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008218
Douglas Gregorb98b1992009-08-11 05:31:07 +00008219 CXXConstructorDecl *Constructor
8220 = cast_or_null<CXXConstructorDecl>(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008221 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008222 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008223 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00008224 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008225
Douglas Gregorb98b1992009-08-11 05:31:07 +00008226 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008227 SmallVector<Expr*, 8> Args;
Douglas Gregorb98b1992009-08-11 05:31:07 +00008228 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008229 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008230 &ArgumentChanged))
8231 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008232
Douglas Gregorb98b1992009-08-11 05:31:07 +00008233 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008234 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008235 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00008236 !ArgumentChanged) {
8237 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00008238 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00008239 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00008240 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008241
Richard Smithc83c2302012-12-19 01:39:02 +00008242 // FIXME: Pass in E->isListInitialization().
Douglas Gregorab6677e2010-09-08 00:15:04 +00008243 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8244 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008245 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008246 E->getLocEnd());
8247}
Mike Stump1eb44332009-09-09 15:08:12 +00008248
Douglas Gregorb98b1992009-08-11 05:31:07 +00008249template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008250ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00008251TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Douglas Gregordfca6f52012-02-13 22:00:16 +00008252 // Transform the type of the lambda parameters and start the definition of
8253 // the lambda itself.
8254 TypeSourceInfo *MethodTy
Chad Rosier4a9d7952012-08-08 18:46:20 +00008255 = TransformType(E->getCallOperator()->getTypeSourceInfo());
Douglas Gregordfca6f52012-02-13 22:00:16 +00008256 if (!MethodTy)
8257 return ExprError();
8258
Eli Friedman8da8a662012-09-19 01:18:11 +00008259 // Create the local class that will describe the lambda.
8260 CXXRecordDecl *Class
8261 = getSema().createLambdaClosureType(E->getIntroducerRange(),
8262 MethodTy,
8263 /*KnownDependent=*/false);
8264 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8265
Douglas Gregorc6889e72012-02-14 22:28:59 +00008266 // Transform lambda parameters.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008267 SmallVector<QualType, 4> ParamTypes;
8268 SmallVector<ParmVarDecl *, 4> Params;
Douglas Gregorc6889e72012-02-14 22:28:59 +00008269 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
8270 E->getCallOperator()->param_begin(),
8271 E->getCallOperator()->param_size(),
8272 0, ParamTypes, &Params))
Richard Smith612409e2012-07-25 03:56:55 +00008273 return ExprError();
Manuel Klimek152b4e42013-08-22 12:12:24 +00008274
Douglas Gregordfca6f52012-02-13 22:00:16 +00008275 // Build the call operator.
8276 CXXMethodDecl *CallOperator
8277 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00008278 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00008279 E->getCallOperator()->getLocEnd(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00008280 Params);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008281 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
Douglas Gregord5387e82012-02-14 00:00:48 +00008282
Richard Smith612409e2012-07-25 03:56:55 +00008283 return getDerived().TransformLambdaScope(E, CallOperator);
8284}
8285
8286template<typename Derived>
8287ExprResult
8288TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
8289 CXXMethodDecl *CallOperator) {
Richard Smith0d8e9642013-05-16 06:20:58 +00008290 bool Invalid = false;
8291
8292 // Transform any init-capture expressions before entering the scope of the
8293 // lambda.
Robert Wilhelme7205c02013-08-10 12:33:24 +00008294 SmallVector<ExprResult, 8> InitCaptureExprs;
Richard Smith0d8e9642013-05-16 06:20:58 +00008295 InitCaptureExprs.resize(E->explicit_capture_end() -
8296 E->explicit_capture_begin());
8297 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8298 CEnd = E->capture_end();
8299 C != CEnd; ++C) {
8300 if (!C->isInitCapture())
8301 continue;
8302 InitCaptureExprs[C - E->capture_begin()] =
8303 getDerived().TransformExpr(E->getInitCaptureInit(C));
8304 }
8305
Douglas Gregord5387e82012-02-14 00:00:48 +00008306 // Introduce the context of the call operator.
8307 Sema::ContextRAII SavedContext(getSema(), CallOperator);
8308
Douglas Gregordfca6f52012-02-13 22:00:16 +00008309 // Enter the scope of the lambda.
Manuel Klimek152b4e42013-08-22 12:12:24 +00008310 sema::LambdaScopeInfo *LSI
8311 = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008312 E->getCaptureDefault(),
James Dennettf68af642013-08-09 23:08:25 +00008313 E->getCaptureDefaultLoc(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008314 E->hasExplicitParameters(),
8315 E->hasExplicitResultType(),
8316 E->isMutable());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008317
Douglas Gregordfca6f52012-02-13 22:00:16 +00008318 // Transform captures.
Douglas Gregordfca6f52012-02-13 22:00:16 +00008319 bool FinishedExplicitCaptures = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008320 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008321 CEnd = E->capture_end();
8322 C != CEnd; ++C) {
8323 // When we hit the first implicit capture, tell Sema that we've finished
8324 // the list of explicit captures.
8325 if (!FinishedExplicitCaptures && C->isImplicit()) {
8326 getSema().finishLambdaExplicitCaptures(LSI);
8327 FinishedExplicitCaptures = true;
8328 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008329
Douglas Gregordfca6f52012-02-13 22:00:16 +00008330 // Capturing 'this' is trivial.
8331 if (C->capturesThis()) {
8332 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8333 continue;
8334 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008335
Richard Smith0d8e9642013-05-16 06:20:58 +00008336 // Rebuild init-captures, including the implied field declaration.
8337 if (C->isInitCapture()) {
8338 ExprResult Init = InitCaptureExprs[C - E->capture_begin()];
8339 if (Init.isInvalid()) {
8340 Invalid = true;
8341 continue;
8342 }
8343 FieldDecl *OldFD = C->getInitCaptureField();
8344 FieldDecl *NewFD = getSema().checkInitCapture(
8345 C->getLocation(), OldFD->getType()->isReferenceType(),
8346 OldFD->getIdentifier(), Init.take());
8347 if (!NewFD)
8348 Invalid = true;
8349 else
8350 getDerived().transformedLocalDecl(OldFD, NewFD);
8351 continue;
8352 }
8353
8354 assert(C->capturesVariable() && "unexpected kind of lambda capture");
8355
Douglas Gregora7365242012-02-14 19:27:52 +00008356 // Determine the capture kind for Sema.
8357 Sema::TryCaptureKind Kind
8358 = C->isImplicit()? Sema::TryCapture_Implicit
8359 : C->getCaptureKind() == LCK_ByCopy
8360 ? Sema::TryCapture_ExplicitByVal
8361 : Sema::TryCapture_ExplicitByRef;
8362 SourceLocation EllipsisLoc;
8363 if (C->isPackExpansion()) {
8364 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8365 bool ShouldExpand = false;
8366 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008367 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008368 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8369 C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008370 Unexpanded,
8371 ShouldExpand, RetainExpansion,
Richard Smith0d8e9642013-05-16 06:20:58 +00008372 NumExpansions)) {
8373 Invalid = true;
8374 continue;
8375 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008376
Douglas Gregora7365242012-02-14 19:27:52 +00008377 if (ShouldExpand) {
8378 // The transform has determined that we should perform an expansion;
8379 // transform and capture each of the arguments.
8380 // expansion of the pattern. Do so.
8381 VarDecl *Pack = C->getCapturedVar();
8382 for (unsigned I = 0; I != *NumExpansions; ++I) {
8383 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8384 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008385 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008386 Pack));
8387 if (!CapturedVar) {
8388 Invalid = true;
8389 continue;
8390 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008391
Douglas Gregora7365242012-02-14 19:27:52 +00008392 // Capture the transformed variable.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008393 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8394 }
Douglas Gregora7365242012-02-14 19:27:52 +00008395 continue;
8396 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008397
Douglas Gregora7365242012-02-14 19:27:52 +00008398 EllipsisLoc = C->getEllipsisLoc();
8399 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008400
Douglas Gregordfca6f52012-02-13 22:00:16 +00008401 // Transform the captured variable.
8402 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008403 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008404 C->getCapturedVar()));
8405 if (!CapturedVar) {
8406 Invalid = true;
8407 continue;
8408 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008409
Douglas Gregordfca6f52012-02-13 22:00:16 +00008410 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00008411 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008412 }
8413 if (!FinishedExplicitCaptures)
8414 getSema().finishLambdaExplicitCaptures(LSI);
8415
Douglas Gregordfca6f52012-02-13 22:00:16 +00008416
8417 // Enter a new evaluation context to insulate the lambda from any
8418 // cleanups from the enclosing full-expression.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008419 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008420
8421 if (Invalid) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008422 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregordfca6f52012-02-13 22:00:16 +00008423 /*IsInstantiation=*/true);
8424 return ExprError();
8425 }
8426
8427 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00008428 StmtResult Body = getDerived().TransformStmt(E->getBody());
8429 if (Body.isInvalid()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008430 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregord5387e82012-02-14 00:00:48 +00008431 /*IsInstantiation=*/true);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008432 return ExprError();
Douglas Gregord5387e82012-02-14 00:00:48 +00008433 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00008434
Chad Rosier4a9d7952012-08-08 18:46:20 +00008435 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00008436 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00008437}
8438
8439template<typename Derived>
8440ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008441TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00008442 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00008443 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8444 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008445 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008446
Douglas Gregorb98b1992009-08-11 05:31:07 +00008447 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008448 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008449 Args.reserve(E->arg_size());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008450 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008451 &ArgumentChanged))
8452 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008453
Douglas Gregorb98b1992009-08-11 05:31:07 +00008454 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008455 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008456 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008457 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008458
Douglas Gregorb98b1992009-08-11 05:31:07 +00008459 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00008460 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008461 E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008462 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008463 E->getRParenLoc());
8464}
Mike Stump1eb44332009-09-09 15:08:12 +00008465
Douglas Gregorb98b1992009-08-11 05:31:07 +00008466template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008467ExprResult
John McCall865d4472009-11-19 22:55:06 +00008468TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008469 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008470 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008471 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008472 Expr *OldBase;
8473 QualType BaseType;
8474 QualType ObjectType;
8475 if (!E->isImplicitAccess()) {
8476 OldBase = E->getBase();
8477 Base = getDerived().TransformExpr(OldBase);
8478 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008479 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008480
John McCallaa81e162009-12-01 22:10:20 +00008481 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008482 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008483 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008484 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008485 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008486 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008487 ObjectTy,
8488 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008489 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008490 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008491
John McCallb3d87482010-08-24 05:47:05 +00008492 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008493 BaseType = ((Expr*) Base.get())->getType();
8494 } else {
8495 OldBase = 0;
8496 BaseType = getDerived().TransformType(E->getBaseType());
8497 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8498 }
Mike Stump1eb44332009-09-09 15:08:12 +00008499
Douglas Gregor6cd21982009-10-20 05:58:46 +00008500 // Transform the first part of the nested-name-specifier that qualifies
8501 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008502 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008503 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008504 E->getFirstQualifierFoundInScope(),
8505 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008506
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008507 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008508 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008509 QualifierLoc
8510 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8511 ObjectType,
8512 FirstQualifierInScope);
8513 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008514 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008515 }
Mike Stump1eb44332009-09-09 15:08:12 +00008516
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008517 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8518
John McCall43fed0d2010-11-12 08:19:04 +00008519 // TODO: If this is a conversion-function-id, verify that the
8520 // destination type name (if present) resolves the same way after
8521 // instantiation as it did in the local scope.
8522
Abramo Bagnara25777432010-08-11 22:01:17 +00008523 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008524 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008525 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008526 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008527
John McCallaa81e162009-12-01 22:10:20 +00008528 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008529 // This is a reference to a member without an explicitly-specified
8530 // template argument list. Optimize for this common case.
8531 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008532 Base.get() == OldBase &&
8533 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008534 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008535 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008536 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008537 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008538
John McCall9ae2f072010-08-23 23:25:46 +00008539 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008540 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008541 E->isArrow(),
8542 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008543 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008544 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008545 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008546 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008547 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008548 }
8549
John McCalld5532b62009-11-23 01:53:49 +00008550 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008551 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8552 E->getNumTemplateArgs(),
8553 TransArgs))
8554 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008555
John McCall9ae2f072010-08-23 23:25:46 +00008556 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008557 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008558 E->isArrow(),
8559 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008560 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008561 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008562 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008563 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008564 &TransArgs);
8565}
8566
8567template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008568ExprResult
John McCall454feb92009-12-08 09:21:05 +00008569TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008570 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008571 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008572 QualType BaseType;
8573 if (!Old->isImplicitAccess()) {
8574 Base = getDerived().TransformExpr(Old->getBase());
8575 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008576 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008577 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8578 Old->isArrow());
8579 if (Base.isInvalid())
8580 return ExprError();
8581 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008582 } else {
8583 BaseType = getDerived().TransformType(Old->getBaseType());
8584 }
John McCall129e2df2009-11-30 22:42:35 +00008585
Douglas Gregor4c9be892011-02-28 20:01:57 +00008586 NestedNameSpecifierLoc QualifierLoc;
8587 if (Old->getQualifierLoc()) {
8588 QualifierLoc
8589 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8590 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008591 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008592 }
8593
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008594 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8595
Abramo Bagnara25777432010-08-11 22:01:17 +00008596 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008597 Sema::LookupOrdinaryName);
8598
8599 // Transform all the decls.
8600 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8601 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008602 NamedDecl *InstD = static_cast<NamedDecl*>(
8603 getDerived().TransformDecl(Old->getMemberLoc(),
8604 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008605 if (!InstD) {
8606 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8607 // This can happen because of dependent hiding.
8608 if (isa<UsingShadowDecl>(*I))
8609 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008610 else {
8611 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008612 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008613 }
John McCall9f54ad42009-12-10 09:41:52 +00008614 }
John McCall129e2df2009-11-30 22:42:35 +00008615
8616 // Expand using declarations.
8617 if (isa<UsingDecl>(InstD)) {
8618 UsingDecl *UD = cast<UsingDecl>(InstD);
8619 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8620 E = UD->shadow_end(); I != E; ++I)
8621 R.addDecl(*I);
8622 continue;
8623 }
8624
8625 R.addDecl(InstD);
8626 }
8627
8628 R.resolveKind();
8629
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008630 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008631 if (Old->getNamingClass()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008632 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008633 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008634 Old->getMemberLoc(),
8635 Old->getNamingClass()));
8636 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008637 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008638
Douglas Gregor66c45152010-04-27 16:10:10 +00008639 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008640 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008641
John McCall129e2df2009-11-30 22:42:35 +00008642 TemplateArgumentListInfo TransArgs;
8643 if (Old->hasExplicitTemplateArgs()) {
8644 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8645 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008646 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8647 Old->getNumTemplateArgs(),
8648 TransArgs))
8649 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008650 }
John McCallc2233c52010-01-15 08:34:02 +00008651
8652 // FIXME: to do this check properly, we will need to preserve the
8653 // first-qualifier-in-scope here, just in case we had a dependent
8654 // base (and therefore couldn't do the check) and a
8655 // nested-name-qualifier (and therefore could do the lookup).
8656 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008657
John McCall9ae2f072010-08-23 23:25:46 +00008658 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008659 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008660 Old->getOperatorLoc(),
8661 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008662 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008663 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008664 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008665 R,
8666 (Old->hasExplicitTemplateArgs()
8667 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008668}
8669
8670template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008671ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008672TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008673 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008674 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8675 if (SubExpr.isInvalid())
8676 return ExprError();
8677
8678 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008679 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008680
8681 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8682}
8683
8684template<typename Derived>
8685ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008686TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008687 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8688 if (Pattern.isInvalid())
8689 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008690
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008691 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8692 return SemaRef.Owned(E);
8693
Douglas Gregor67fd1252011-01-14 21:20:45 +00008694 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8695 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008696}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008697
8698template<typename Derived>
8699ExprResult
8700TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8701 // If E is not value-dependent, then nothing will change when we transform it.
8702 // Note: This is an instantiation-centric view.
8703 if (!E->isValueDependent())
8704 return SemaRef.Owned(E);
8705
8706 // Note: None of the implementations of TryExpandParameterPacks can ever
8707 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier4a9d7952012-08-08 18:46:20 +00008708 // so
Douglas Gregoree8aff02011-01-04 17:33:58 +00008709 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8710 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008711 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008712 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008713 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008714 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008715 ShouldExpand, RetainExpansion,
8716 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008717 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008718
Douglas Gregor089e8932011-10-10 18:59:29 +00008719 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008720 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008721
Douglas Gregor089e8932011-10-10 18:59:29 +00008722 NamedDecl *Pack = E->getPack();
8723 if (!ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008724 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008725 Pack));
8726 if (!Pack)
8727 return ExprError();
8728 }
8729
Chad Rosier4a9d7952012-08-08 18:46:20 +00008730
Douglas Gregoree8aff02011-01-04 17:33:58 +00008731 // We now know the length of the parameter pack, so build a new expression
8732 // that stores that length.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008733 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8734 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008735 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008736}
8737
Douglas Gregorbe230c32011-01-03 17:17:50 +00008738template<typename Derived>
8739ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008740TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8741 SubstNonTypeTemplateParmPackExpr *E) {
8742 // Default behavior is to do nothing with this transformation.
8743 return SemaRef.Owned(E);
8744}
8745
8746template<typename Derived>
8747ExprResult
John McCall91a57552011-07-15 05:09:51 +00008748TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8749 SubstNonTypeTemplateParmExpr *E) {
8750 // Default behavior is to do nothing with this transformation.
8751 return SemaRef.Owned(E);
8752}
8753
8754template<typename Derived>
8755ExprResult
Richard Smith9a4db032012-09-12 00:56:43 +00008756TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8757 // Default behavior is to do nothing with this transformation.
8758 return SemaRef.Owned(E);
8759}
8760
8761template<typename Derived>
8762ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008763TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8764 MaterializeTemporaryExpr *E) {
8765 return getDerived().TransformExpr(E->GetTemporaryExpr());
8766}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008767
Douglas Gregor03e80032011-06-21 17:03:29 +00008768template<typename Derived>
8769ExprResult
Richard Smith7c3e6152013-06-12 22:31:48 +00008770TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
8771 CXXStdInitializerListExpr *E) {
8772 return getDerived().TransformExpr(E->getSubExpr());
8773}
8774
8775template<typename Derived>
8776ExprResult
John McCall454feb92009-12-08 09:21:05 +00008777TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008778 return SemaRef.MaybeBindToTemporary(E);
8779}
8780
8781template<typename Derived>
8782ExprResult
8783TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008784 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008785}
8786
8787template<typename Derived>
8788ExprResult
Patrick Beardeb382ec2012-04-19 00:25:12 +00008789TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8790 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8791 if (SubExpr.isInvalid())
8792 return ExprError();
8793
8794 if (!getDerived().AlwaysRebuild() &&
8795 SubExpr.get() == E->getSubExpr())
8796 return SemaRef.Owned(E);
8797
8798 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008799}
8800
8801template<typename Derived>
8802ExprResult
8803TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8804 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008805 SmallVector<Expr *, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008806 bool ArgChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008807 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008808 /*IsCall=*/false, Elements, &ArgChanged))
8809 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008810
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008811 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8812 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008813
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008814 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8815 Elements.data(),
8816 Elements.size());
8817}
8818
8819template<typename Derived>
8820ExprResult
8821TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008822 ObjCDictionaryLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008823 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008824 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008825 bool ArgChanged = false;
8826 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8827 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008828
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008829 if (OrigElement.isPackExpansion()) {
8830 // This key/value element is a pack expansion.
8831 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8832 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8833 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8834 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8835
8836 // Determine whether the set of unexpanded parameter packs can
8837 // and should be expanded.
8838 bool Expand = true;
8839 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008840 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8841 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008842 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8843 OrigElement.Value->getLocEnd());
8844 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8845 PatternRange,
8846 Unexpanded,
8847 Expand, RetainExpansion,
8848 NumExpansions))
8849 return ExprError();
8850
8851 if (!Expand) {
8852 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00008853 // transformation on the pack expansion, producing another pack
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008854 // expansion.
8855 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8856 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8857 if (Key.isInvalid())
8858 return ExprError();
8859
8860 if (Key.get() != OrigElement.Key)
8861 ArgChanged = true;
8862
8863 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8864 if (Value.isInvalid())
8865 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008866
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008867 if (Value.get() != OrigElement.Value)
8868 ArgChanged = true;
8869
Chad Rosier4a9d7952012-08-08 18:46:20 +00008870 ObjCDictionaryElement Expansion = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008871 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8872 };
8873 Elements.push_back(Expansion);
8874 continue;
8875 }
8876
8877 // Record right away that the argument was changed. This needs
8878 // to happen even if the array expands to nothing.
8879 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008880
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008881 // The transform has determined that we should perform an elementwise
8882 // expansion of the pattern. Do so.
8883 for (unsigned I = 0; I != *NumExpansions; ++I) {
8884 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8885 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8886 if (Key.isInvalid())
8887 return ExprError();
8888
8889 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8890 if (Value.isInvalid())
8891 return ExprError();
8892
Chad Rosier4a9d7952012-08-08 18:46:20 +00008893 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008894 Key.get(), Value.get(), SourceLocation(), NumExpansions
8895 };
8896
8897 // If any unexpanded parameter packs remain, we still have a
8898 // pack expansion.
8899 if (Key.get()->containsUnexpandedParameterPack() ||
8900 Value.get()->containsUnexpandedParameterPack())
8901 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008902
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008903 Elements.push_back(Element);
8904 }
8905
8906 // We've finished with this pack expansion.
8907 continue;
8908 }
8909
8910 // Transform and check key.
8911 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8912 if (Key.isInvalid())
8913 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008914
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008915 if (Key.get() != OrigElement.Key)
8916 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008917
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008918 // Transform and check value.
8919 ExprResult Value
8920 = getDerived().TransformExpr(OrigElement.Value);
8921 if (Value.isInvalid())
8922 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008923
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008924 if (Value.get() != OrigElement.Value)
8925 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008926
8927 ObjCDictionaryElement Element = {
David Blaikie66874fb2013-02-21 01:47:18 +00008928 Key.get(), Value.get(), SourceLocation(), None
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008929 };
8930 Elements.push_back(Element);
8931 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008932
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008933 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8934 return SemaRef.MaybeBindToTemporary(E);
8935
8936 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8937 Elements.data(),
8938 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008939}
8940
Mike Stump1eb44332009-09-09 15:08:12 +00008941template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008942ExprResult
John McCall454feb92009-12-08 09:21:05 +00008943TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008944 TypeSourceInfo *EncodedTypeInfo
8945 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8946 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008947 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008948
Douglas Gregorb98b1992009-08-11 05:31:07 +00008949 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008950 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008951 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008952
8953 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008954 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008955 E->getRParenLoc());
8956}
Mike Stump1eb44332009-09-09 15:08:12 +00008957
Douglas Gregorb98b1992009-08-11 05:31:07 +00008958template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00008959ExprResult TreeTransform<Derived>::
8960TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCall93b64572013-04-11 02:14:26 +00008961 // This is a kind of implicit conversion, and it needs to get dropped
8962 // and recomputed for the same general reasons that ImplicitCastExprs
8963 // do, as well a more specific one: this expression is only valid when
8964 // it appears *immediately* as an argument expression.
8965 return getDerived().TransformExpr(E->getSubExpr());
John McCallf85e1932011-06-15 23:02:42 +00008966}
8967
8968template<typename Derived>
8969ExprResult TreeTransform<Derived>::
8970TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008971 TypeSourceInfo *TSInfo
John McCallf85e1932011-06-15 23:02:42 +00008972 = getDerived().TransformType(E->getTypeInfoAsWritten());
8973 if (!TSInfo)
8974 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008975
John McCallf85e1932011-06-15 23:02:42 +00008976 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008977 if (Result.isInvalid())
John McCallf85e1932011-06-15 23:02:42 +00008978 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008979
John McCallf85e1932011-06-15 23:02:42 +00008980 if (!getDerived().AlwaysRebuild() &&
8981 TSInfo == E->getTypeInfoAsWritten() &&
8982 Result.get() == E->getSubExpr())
8983 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008984
John McCallf85e1932011-06-15 23:02:42 +00008985 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00008986 E->getBridgeKeywordLoc(), TSInfo,
John McCallf85e1932011-06-15 23:02:42 +00008987 Result.get());
8988}
8989
8990template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008991ExprResult
John McCall454feb92009-12-08 09:21:05 +00008992TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008993 // Transform arguments.
8994 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008995 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008996 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008997 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008998 &ArgChanged))
8999 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009000
Douglas Gregor92e986e2010-04-22 16:44:27 +00009001 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
9002 // Class message: transform the receiver type.
9003 TypeSourceInfo *ReceiverTypeInfo
9004 = getDerived().TransformType(E->getClassReceiverTypeInfo());
9005 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00009006 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009007
Douglas Gregor92e986e2010-04-22 16:44:27 +00009008 // If nothing changed, just retain the existing message send.
9009 if (!getDerived().AlwaysRebuild() &&
9010 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00009011 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00009012
9013 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00009014 SmallVector<SourceLocation, 16> SelLocs;
9015 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00009016 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
9017 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00009018 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00009019 E->getMethodDecl(),
9020 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009021 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00009022 E->getRightLoc());
9023 }
9024
9025 // Instance message: transform the receiver
9026 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
9027 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00009028 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00009029 = getDerived().TransformExpr(E->getInstanceReceiver());
9030 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009031 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00009032
9033 // If nothing changed, just retain the existing message send.
9034 if (!getDerived().AlwaysRebuild() &&
9035 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00009036 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009037
Douglas Gregor92e986e2010-04-22 16:44:27 +00009038 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00009039 SmallVector<SourceLocation, 16> SelLocs;
9040 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00009041 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00009042 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00009043 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00009044 E->getMethodDecl(),
9045 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009046 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00009047 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009048}
9049
Mike Stump1eb44332009-09-09 15:08:12 +00009050template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009051ExprResult
John McCall454feb92009-12-08 09:21:05 +00009052TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00009053 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009054}
9055
Mike Stump1eb44332009-09-09 15:08:12 +00009056template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009057ExprResult
John McCall454feb92009-12-08 09:21:05 +00009058TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00009059 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009060}
9061
Mike Stump1eb44332009-09-09 15:08:12 +00009062template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009063ExprResult
John McCall454feb92009-12-08 09:21:05 +00009064TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009065 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00009066 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009067 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009068 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009069
9070 // We don't need to transform the ivar; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00009071
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009072 // If nothing changed, just retain the existing expression.
9073 if (!getDerived().AlwaysRebuild() &&
9074 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00009075 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009076
John McCall9ae2f072010-08-23 23:25:46 +00009077 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009078 E->getLocation(),
9079 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009080}
9081
Mike Stump1eb44332009-09-09 15:08:12 +00009082template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009083ExprResult
John McCall454feb92009-12-08 09:21:05 +00009084TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00009085 // 'super' and types never change. Property never changes. Just
9086 // retain the existing expression.
9087 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00009088 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009089
Douglas Gregore3303542010-04-26 20:47:02 +00009090 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00009091 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00009092 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009093 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009094
Douglas Gregore3303542010-04-26 20:47:02 +00009095 // We don't need to transform the property; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00009096
Douglas Gregore3303542010-04-26 20:47:02 +00009097 // If nothing changed, just retain the existing expression.
9098 if (!getDerived().AlwaysRebuild() &&
9099 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00009100 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009101
John McCall12f78a62010-12-02 01:19:52 +00009102 if (E->isExplicitProperty())
9103 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9104 E->getExplicitProperty(),
9105 E->getLocation());
9106
9107 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00009108 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00009109 E->getImplicitPropertyGetter(),
9110 E->getImplicitPropertySetter(),
9111 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009112}
9113
Mike Stump1eb44332009-09-09 15:08:12 +00009114template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009115ExprResult
Ted Kremenekebcb57a2012-03-06 20:05:56 +00009116TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
9117 // Transform the base expression.
9118 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9119 if (Base.isInvalid())
9120 return ExprError();
9121
9122 // Transform the key expression.
9123 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
9124 if (Key.isInvalid())
9125 return ExprError();
9126
9127 // If nothing changed, just retain the existing expression.
9128 if (!getDerived().AlwaysRebuild() &&
9129 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
9130 return SemaRef.Owned(E);
9131
Chad Rosier4a9d7952012-08-08 18:46:20 +00009132 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00009133 Base.get(), Key.get(),
9134 E->getAtIndexMethodDecl(),
9135 E->setAtIndexMethodDecl());
9136}
9137
9138template<typename Derived>
9139ExprResult
John McCall454feb92009-12-08 09:21:05 +00009140TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009141 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00009142 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009143 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009144 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009145
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009146 // If nothing changed, just retain the existing expression.
9147 if (!getDerived().AlwaysRebuild() &&
9148 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00009149 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009150
John McCall9ae2f072010-08-23 23:25:46 +00009151 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00009152 E->getOpLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009153 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009154}
9155
Mike Stump1eb44332009-09-09 15:08:12 +00009156template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009157ExprResult
John McCall454feb92009-12-08 09:21:05 +00009158TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009159 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00009160 SmallVector<Expr*, 8> SubExprs;
Douglas Gregoraa165f82011-01-03 19:04:46 +00009161 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009162 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00009163 SubExprs, &ArgumentChanged))
9164 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009165
Douglas Gregorb98b1992009-08-11 05:31:07 +00009166 if (!getDerived().AlwaysRebuild() &&
9167 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00009168 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00009169
Douglas Gregorb98b1992009-08-11 05:31:07 +00009170 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009171 SubExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00009172 E->getRParenLoc());
9173}
9174
Mike Stump1eb44332009-09-09 15:08:12 +00009175template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009176ExprResult
Hal Finkel414a1bd2013-09-18 03:29:45 +00009177TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
9178 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
9179 if (SrcExpr.isInvalid())
9180 return ExprError();
9181
9182 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9183 if (!Type)
9184 return ExprError();
9185
9186 if (!getDerived().AlwaysRebuild() &&
9187 Type == E->getTypeSourceInfo() &&
9188 SrcExpr.get() == E->getSrcExpr())
9189 return SemaRef.Owned(E);
9190
9191 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
9192 SrcExpr.get(), Type,
9193 E->getRParenLoc());
9194}
9195
9196template<typename Derived>
9197ExprResult
John McCall454feb92009-12-08 09:21:05 +00009198TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00009199 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009200
John McCallc6ac9c32011-02-04 18:33:18 +00009201 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
9202 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
9203
9204 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00009205 blockScope->TheDecl->setBlockMissingReturnType(
9206 oldBlock->blockMissingReturnType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009207
Chris Lattner686775d2011-07-20 06:58:45 +00009208 SmallVector<ParmVarDecl*, 4> params;
9209 SmallVector<QualType, 4> paramTypes;
Chad Rosier4a9d7952012-08-08 18:46:20 +00009210
Fariborz Jahaniana729da22010-07-09 18:44:02 +00009211 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00009212 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
9213 oldBlock->param_begin(),
9214 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009215 0, paramTypes, &params)) {
9216 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00009217 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009218 }
John McCallc6ac9c32011-02-04 18:33:18 +00009219
Jordan Rose09189892013-03-08 22:25:36 +00009220 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00009221 QualType exprResultType =
9222 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00009223
Jordan Rosebea522f2013-03-08 21:51:21 +00009224 QualType functionType =
9225 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rose09189892013-03-08 22:25:36 +00009226 exprFunctionType->getExtProtoInfo());
John McCallc6ac9c32011-02-04 18:33:18 +00009227 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00009228
9229 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00009230 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00009231 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00009232
9233 if (!oldBlock->blockMissingReturnType()) {
9234 blockScope->HasImplicitReturnType = false;
9235 blockScope->ReturnType = exprResultType;
9236 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00009237
John McCall711c52b2011-01-05 12:14:39 +00009238 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00009239 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009240 if (body.isInvalid()) {
9241 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00009242 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009243 }
John McCall711c52b2011-01-05 12:14:39 +00009244
John McCallc6ac9c32011-02-04 18:33:18 +00009245#ifndef NDEBUG
9246 // In builds with assertions, make sure that we captured everything we
9247 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00009248 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
9249 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
9250 e = oldBlock->capture_end(); i != e; ++i) {
9251 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00009252
Douglas Gregorfc921372011-05-20 15:32:55 +00009253 // Ignore parameter packs.
9254 if (isa<ParmVarDecl>(oldCapture) &&
9255 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9256 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00009257
Douglas Gregorfc921372011-05-20 15:32:55 +00009258 VarDecl *newCapture =
9259 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9260 oldCapture));
9261 assert(blockScope->CaptureMap.count(newCapture));
9262 }
Douglas Gregorec79d872012-02-24 17:41:38 +00009263 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00009264 }
9265#endif
9266
9267 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
9268 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009269}
9270
Mike Stump1eb44332009-09-09 15:08:12 +00009271template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009272ExprResult
Tanya Lattner61eee0c2011-06-04 00:47:47 +00009273TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00009274 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00009275}
Eli Friedman276b0612011-10-11 02:20:01 +00009276
9277template<typename Derived>
9278ExprResult
9279TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009280 QualType RetTy = getDerived().TransformType(E->getType());
9281 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00009282 SmallVector<Expr*, 8> SubExprs;
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009283 SubExprs.reserve(E->getNumSubExprs());
9284 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9285 SubExprs, &ArgumentChanged))
9286 return ExprError();
9287
9288 if (!getDerived().AlwaysRebuild() &&
9289 !ArgumentChanged)
9290 return SemaRef.Owned(E);
9291
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009292 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009293 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00009294}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009295
Douglas Gregorb98b1992009-08-11 05:31:07 +00009296//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00009297// Type reconstruction
9298//===----------------------------------------------------------------------===//
9299
Mike Stump1eb44332009-09-09 15:08:12 +00009300template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00009301QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9302 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00009303 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009304 getDerived().getBaseEntity());
9305}
9306
Mike Stump1eb44332009-09-09 15:08:12 +00009307template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00009308QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9309 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00009310 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009311 getDerived().getBaseEntity());
9312}
9313
Mike Stump1eb44332009-09-09 15:08:12 +00009314template<typename Derived>
9315QualType
John McCall85737a72009-10-30 00:06:24 +00009316TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9317 bool WrittenAsLValue,
9318 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00009319 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00009320 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009321}
9322
9323template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009324QualType
John McCall85737a72009-10-30 00:06:24 +00009325TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9326 QualType ClassType,
9327 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00009328 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00009329 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009330}
9331
9332template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009333QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00009334TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9335 ArrayType::ArraySizeModifier SizeMod,
9336 const llvm::APInt *Size,
9337 Expr *SizeExpr,
9338 unsigned IndexTypeQuals,
9339 SourceRange BracketsRange) {
9340 if (SizeExpr || !Size)
9341 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9342 IndexTypeQuals, BracketsRange,
9343 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00009344
9345 QualType Types[] = {
9346 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9347 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9348 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00009349 };
Craig Topperb9602322013-07-15 03:38:40 +00009350 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009351 QualType SizeType;
9352 for (unsigned I = 0; I != NumTypes; ++I)
9353 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9354 SizeType = Types[I];
9355 break;
9356 }
Mike Stump1eb44332009-09-09 15:08:12 +00009357
Eli Friedman01f276d2012-01-25 23:20:27 +00009358 // Note that we can return a VariableArrayType here in the case where
9359 // the element type was a dependent VariableArrayType.
9360 IntegerLiteral *ArraySize
9361 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9362 /*FIXME*/BracketsRange.getBegin());
9363 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009364 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00009365 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009366}
Mike Stump1eb44332009-09-09 15:08:12 +00009367
Douglas Gregor577f75a2009-08-04 16:50:30 +00009368template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009369QualType
9370TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009371 ArrayType::ArraySizeModifier SizeMod,
9372 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00009373 unsigned IndexTypeQuals,
9374 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009375 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00009376 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009377}
9378
9379template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009380QualType
Mike Stump1eb44332009-09-09 15:08:12 +00009381TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009382 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00009383 unsigned IndexTypeQuals,
9384 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009385 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00009386 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009387}
Mike Stump1eb44332009-09-09 15:08:12 +00009388
Douglas Gregor577f75a2009-08-04 16:50:30 +00009389template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009390QualType
9391TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009392 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009393 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009394 unsigned IndexTypeQuals,
9395 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009396 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009397 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009398 IndexTypeQuals, BracketsRange);
9399}
9400
9401template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009402QualType
9403TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009404 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009405 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009406 unsigned IndexTypeQuals,
9407 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009408 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009409 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009410 IndexTypeQuals, BracketsRange);
9411}
9412
9413template<typename Derived>
9414QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00009415 unsigned NumElements,
9416 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00009417 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00009418 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009419}
Mike Stump1eb44332009-09-09 15:08:12 +00009420
Douglas Gregor577f75a2009-08-04 16:50:30 +00009421template<typename Derived>
9422QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9423 unsigned NumElements,
9424 SourceLocation AttributeLoc) {
9425 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9426 NumElements, true);
9427 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00009428 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9429 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00009430 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009431}
Mike Stump1eb44332009-09-09 15:08:12 +00009432
Douglas Gregor577f75a2009-08-04 16:50:30 +00009433template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009434QualType
9435TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00009436 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009437 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00009438 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009439}
Mike Stump1eb44332009-09-09 15:08:12 +00009440
Douglas Gregor577f75a2009-08-04 16:50:30 +00009441template<typename Derived>
Jordan Rosebea522f2013-03-08 21:51:21 +00009442QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9443 QualType T,
9444 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00009445 const FunctionProtoType::ExtProtoInfo &EPI) {
9446 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009447 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00009448 getDerived().getBaseEntity(),
Jordan Rose09189892013-03-08 22:25:36 +00009449 EPI);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009450}
Mike Stump1eb44332009-09-09 15:08:12 +00009451
Douglas Gregor577f75a2009-08-04 16:50:30 +00009452template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00009453QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9454 return SemaRef.Context.getFunctionNoProtoType(T);
9455}
9456
9457template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00009458QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9459 assert(D && "no decl found");
9460 if (D->isInvalidDecl()) return QualType();
9461
Douglas Gregor92e986e2010-04-22 16:44:27 +00009462 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00009463 TypeDecl *Ty;
9464 if (isa<UsingDecl>(D)) {
9465 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanella8d030c72013-07-22 10:54:09 +00009466 assert(Using->hasTypename() &&
John McCalled976492009-12-04 22:46:56 +00009467 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9468
9469 // A valid resolved using typename decl points to exactly one type decl.
9470 assert(++Using->shadow_begin() == Using->shadow_end());
9471 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009472
John McCalled976492009-12-04 22:46:56 +00009473 } else {
9474 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9475 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9476 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9477 }
9478
9479 return SemaRef.Context.getTypeDeclType(Ty);
9480}
9481
9482template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009483QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9484 SourceLocation Loc) {
9485 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009486}
9487
9488template<typename Derived>
9489QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9490 return SemaRef.Context.getTypeOfType(Underlying);
9491}
9492
9493template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009494QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9495 SourceLocation Loc) {
9496 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009497}
9498
9499template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009500QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9501 UnaryTransformType::UTTKind UKind,
9502 SourceLocation Loc) {
9503 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9504}
9505
9506template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009507QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009508 TemplateName Template,
9509 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009510 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009511 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009512}
Mike Stump1eb44332009-09-09 15:08:12 +00009513
Douglas Gregordcee1a12009-08-06 05:28:30 +00009514template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009515QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9516 SourceLocation KWLoc) {
9517 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9518}
9519
9520template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009521TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009522TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009523 bool TemplateKW,
9524 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009525 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009526 Template);
9527}
9528
9529template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009530TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009531TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9532 const IdentifierInfo &Name,
9533 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009534 QualType ObjectType,
9535 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009536 UnqualifiedId TemplateName;
9537 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009538 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009539 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009540 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009541 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009542 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009543 /*EnteringContext=*/false,
9544 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009545 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009546}
Mike Stump1eb44332009-09-09 15:08:12 +00009547
Douglas Gregorb98b1992009-08-11 05:31:07 +00009548template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009549TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009550TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009551 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009552 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009553 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009554 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009555 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009556 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009557 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009558 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009559 Sema::TemplateTy Template;
9560 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009561 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009562 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009563 /*EnteringContext=*/false,
9564 Template);
Serge Pavlov18062392013-08-27 13:15:56 +00009565 return Template.get();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009566}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009567
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009568template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009569ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009570TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9571 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009572 Expr *OrigCallee,
9573 Expr *First,
9574 Expr *Second) {
9575 Expr *Callee = OrigCallee->IgnoreParenCasts();
9576 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009577
Douglas Gregorb98b1992009-08-11 05:31:07 +00009578 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009579 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009580 if (!First->getType()->isOverloadableType() &&
9581 !Second->getType()->isOverloadableType())
9582 return getSema().CreateBuiltinArraySubscriptExpr(First,
9583 Callee->getLocStart(),
9584 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009585 } else if (Op == OO_Arrow) {
9586 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009587 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9588 } else if (Second == 0 || isPostIncDec) {
9589 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009590 // The argument is not of overloadable type, so try to create a
9591 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009592 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009593 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009594
John McCall9ae2f072010-08-23 23:25:46 +00009595 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009596 }
9597 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009598 if (!First->getType()->isOverloadableType() &&
9599 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009600 // Neither of the arguments is an overloadable type, so try to
9601 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009602 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009603 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009604 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009605 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009606 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009607
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009608 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009609 }
9610 }
Mike Stump1eb44332009-09-09 15:08:12 +00009611
9612 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009613 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009614 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009615
John McCall9ae2f072010-08-23 23:25:46 +00009616 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009617 assert(ULE->requiresADL());
9618
9619 // FIXME: Do we have to check
9620 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009621 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009622 } else {
Richard Smithf6411662012-11-28 21:47:39 +00009623 // If we've resolved this to a particular non-member function, just call
9624 // that function. If we resolved it to a member function,
9625 // CreateOverloaded* will find that function for us.
9626 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9627 if (!isa<CXXMethodDecl>(ND))
9628 Functions.addDecl(ND);
John McCallba135432009-11-21 08:51:07 +00009629 }
Mike Stump1eb44332009-09-09 15:08:12 +00009630
Douglas Gregorb98b1992009-08-11 05:31:07 +00009631 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009632 Expr *Args[2] = { First, Second };
9633 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009634
Douglas Gregorb98b1992009-08-11 05:31:07 +00009635 // Create the overloaded operator invocation for unary operators.
9636 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009637 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009638 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009639 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009640 }
Mike Stump1eb44332009-09-09 15:08:12 +00009641
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009642 if (Op == OO_Subscript) {
9643 SourceLocation LBrace;
9644 SourceLocation RBrace;
9645
9646 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9647 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9648 LBrace = SourceLocation::getFromRawEncoding(
9649 NameLoc.CXXOperatorName.BeginOpNameLoc);
9650 RBrace = SourceLocation::getFromRawEncoding(
9651 NameLoc.CXXOperatorName.EndOpNameLoc);
9652 } else {
9653 LBrace = Callee->getLocStart();
9654 RBrace = OpLoc;
9655 }
9656
9657 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9658 First, Second);
9659 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009660
Douglas Gregorb98b1992009-08-11 05:31:07 +00009661 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009662 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009663 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009664 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9665 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009666 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009667
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009668 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009669}
Mike Stump1eb44332009-09-09 15:08:12 +00009670
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009671template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00009672ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009673TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009674 SourceLocation OperatorLoc,
9675 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009676 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009677 TypeSourceInfo *ScopeType,
9678 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009679 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009680 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009681 QualType BaseType = Base->getType();
9682 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009683 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00009684 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009685 !BaseType->getAs<PointerType>()->getPointeeType()
9686 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009687 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009688 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009689 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009690 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009691 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009692 /*FIXME?*/true);
9693 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009694
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009695 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009696 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9697 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9698 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9699 NameInfo.setNamedTypeInfo(DestroyedType);
9700
Richard Smith6314db92012-05-15 06:15:11 +00009701 // The scope type is now known to be a valid nested name specifier
9702 // component. Tack it on to the end of the nested name specifier.
9703 if (ScopeType)
9704 SS.Extend(SemaRef.Context, SourceLocation(),
9705 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnara25777432010-08-11 22:01:17 +00009706
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009707 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009708 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009709 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009710 SS, TemplateKWLoc,
9711 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009712 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009713 /*TemplateArgs*/ 0);
9714}
9715
Tareq A. Siraj051303c2013-04-16 18:53:08 +00009716template<typename Derived>
9717StmtResult
9718TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan9fd6b8f2013-05-04 03:59:06 +00009719 SourceLocation Loc = S->getLocStart();
9720 unsigned NumParams = S->getCapturedDecl()->getNumParams();
9721 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/0,
9722 S->getCapturedRegionKind(), NumParams);
9723 StmtResult Body = getDerived().TransformStmt(S->getCapturedStmt());
9724
9725 if (Body.isInvalid()) {
9726 getSema().ActOnCapturedRegionError();
9727 return StmtError();
9728 }
9729
9730 return getSema().ActOnCapturedRegionEnd(Body.take());
Tareq A. Siraj051303c2013-04-16 18:53:08 +00009731}
9732
Douglas Gregor577f75a2009-08-04 16:50:30 +00009733} // end namespace clang
9734
9735#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H