blob: 89e23ef46052f155fd4a389e33bbbfca7284180e [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"
Douglas Gregorb98b1992009-08-11 05:31:07 +000027#include "clang/Lex/Preprocessor.h"
Chandler Carruth55fc8732012-12-04 09:13:33 +000028#include "clang/Sema/Designator.h"
29#include "clang/Sema/Lookup.h"
30#include "clang/Sema/Ownership.h"
31#include "clang/Sema/ParsedTemplate.h"
32#include "clang/Sema/ScopeInfo.h"
33#include "clang/Sema/SemaDiagnostic.h"
34#include "clang/Sema/SemaInternal.h"
David Blaikiea71f9d02011-09-22 02:34:54 +000035#include "llvm/ADT/ArrayRef.h"
John McCalla2becad2009-10-21 00:40:46 +000036#include "llvm/Support/ErrorHandling.h"
Douglas Gregor577f75a2009-08-04 16:50:30 +000037#include <algorithm>
38
39namespace clang {
John McCall781472f2010-08-25 08:40:02 +000040using namespace sema;
Mike Stump1eb44332009-09-09 15:08:12 +000041
Douglas Gregor577f75a2009-08-04 16:50:30 +000042/// \brief A semantic tree transformation that allows one to transform one
43/// abstract syntax tree into another.
44///
Mike Stump1eb44332009-09-09 15:08:12 +000045/// A new tree transformation is defined by creating a new subclass \c X of
46/// \c TreeTransform<X> and then overriding certain operations to provide
47/// behavior specific to that transformation. For example, template
Douglas Gregor577f75a2009-08-04 16:50:30 +000048/// instantiation is implemented as a tree transformation where the
49/// transformation of TemplateTypeParmType nodes involves substituting the
50/// template arguments for their corresponding template parameters; a similar
51/// transformation is performed for non-type template parameters and
52/// template template parameters.
53///
54/// This tree-transformation template uses static polymorphism to allow
Mike Stump1eb44332009-09-09 15:08:12 +000055/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregor577f75a2009-08-04 16:50:30 +000056/// override any of the transformation or rebuild operators by providing an
57/// operation with the same signature as the default implementation. The
58/// overridding function should not be virtual.
59///
60/// Semantic tree transformations are split into two stages, either of which
61/// can be replaced by a subclass. The "transform" step transforms an AST node
62/// or the parts of an AST node using the various transformation functions,
63/// then passes the pieces on to the "rebuild" step, which constructs a new AST
64/// node of the appropriate kind from the pieces. The default transformation
65/// routines recursively transform the operands to composite AST nodes (e.g.,
66/// the pointee type of a PointerType node) and, if any of those operand nodes
67/// were changed by the transformation, invokes the rebuild operation to create
68/// a new AST node.
69///
Mike Stump1eb44332009-09-09 15:08:12 +000070/// Subclasses can customize the transformation at various levels. The
Douglas Gregor670444e2009-08-04 22:27:00 +000071/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregor9151c112011-03-02 18:50:38 +000072/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregor577f75a2009-08-04 16:50:30 +000073/// TransformTemplateName(), or TransformTemplateArgument() with entirely
74/// new implementations.
75///
76/// For more fine-grained transformations, subclasses can replace any of the
77/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregor43959a92009-08-20 07:17:43 +000078/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregor577f75a2009-08-04 16:50:30 +000079/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump1eb44332009-09-09 15:08:12 +000080/// to substitute template arguments for their corresponding template
Douglas Gregor577f75a2009-08-04 16:50:30 +000081/// parameters. Additionally, subclasses can override the \c RebuildXXX
82/// functions to control how AST nodes are rebuilt when their operands change.
83/// By default, \c TreeTransform will invoke semantic analysis to rebuild
84/// AST nodes. However, certain other tree transformations (e.g, cloning) may
85/// be able to use more efficient rebuild steps.
86///
87/// There are a handful of other functions that can be overridden, allowing one
Mike Stump1eb44332009-09-09 15:08:12 +000088/// to avoid traversing nodes that don't need any transformation
Douglas Gregor577f75a2009-08-04 16:50:30 +000089/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
90/// operands have not changed (\c AlwaysRebuild()), and customize the
91/// default locations and entity names used for type-checking
92/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregor577f75a2009-08-04 16:50:30 +000093template<typename Derived>
94class TreeTransform {
Douglas Gregord3731192011-01-10 07:32:04 +000095 /// \brief Private RAII object that helps us forget and then re-remember
96 /// the template argument corresponding to a partially-substituted parameter
97 /// pack.
98 class ForgetPartiallySubstitutedPackRAII {
99 Derived &Self;
100 TemplateArgument Old;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000101
Douglas Gregord3731192011-01-10 07:32:04 +0000102 public:
103 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
104 Old = Self.ForgetPartiallySubstitutedPack();
105 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000106
Douglas Gregord3731192011-01-10 07:32:04 +0000107 ~ForgetPartiallySubstitutedPackRAII() {
108 Self.RememberPartiallySubstitutedPack(Old);
109 }
110 };
Chad Rosier4a9d7952012-08-08 18:46:20 +0000111
Douglas Gregor577f75a2009-08-04 16:50:30 +0000112protected:
113 Sema &SemaRef;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000114
Douglas Gregordfca6f52012-02-13 22:00:16 +0000115 /// \brief The set of local declarations that have been transformed, for
116 /// cases where we are forced to build new declarations within the transformer
117 /// rather than in the subclass (e.g., lambda closure types).
118 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000119
Mike Stump1eb44332009-09-09 15:08:12 +0000120public:
Douglas Gregor577f75a2009-08-04 16:50:30 +0000121 /// \brief Initializes a new tree transformer.
Douglas Gregorb99268b2010-12-21 00:52:54 +0000122 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000123
Douglas Gregor577f75a2009-08-04 16:50:30 +0000124 /// \brief Retrieves a reference to the derived class.
125 Derived &getDerived() { return static_cast<Derived&>(*this); }
126
127 /// \brief Retrieves a reference to the derived class.
Mike Stump1eb44332009-09-09 15:08:12 +0000128 const Derived &getDerived() const {
129 return static_cast<const Derived&>(*this);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000130 }
131
John McCall60d7b3a2010-08-24 06:29:42 +0000132 static inline ExprResult Owned(Expr *E) { return E; }
133 static inline StmtResult Owned(Stmt *S) { return S; }
John McCall9ae2f072010-08-23 23:25:46 +0000134
Douglas Gregor577f75a2009-08-04 16:50:30 +0000135 /// \brief Retrieves a reference to the semantic analysis object used for
136 /// this tree transform.
137 Sema &getSema() const { return SemaRef; }
Mike Stump1eb44332009-09-09 15:08:12 +0000138
Douglas Gregor577f75a2009-08-04 16:50:30 +0000139 /// \brief Whether the transformation should always rebuild AST nodes, even
140 /// if none of the children have changed.
141 ///
142 /// Subclasses may override this function to specify when the transformation
143 /// should rebuild all AST nodes.
144 bool AlwaysRebuild() { return false; }
Mike Stump1eb44332009-09-09 15:08:12 +0000145
Douglas Gregor577f75a2009-08-04 16:50:30 +0000146 /// \brief Returns the location of the entity being transformed, if that
147 /// information was not available elsewhere in the AST.
148 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000149 /// By default, returns no source-location information. Subclasses can
Douglas Gregor577f75a2009-08-04 16:50:30 +0000150 /// provide an alternative implementation that provides better location
151 /// information.
152 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump1eb44332009-09-09 15:08:12 +0000153
Douglas Gregor577f75a2009-08-04 16:50:30 +0000154 /// \brief Returns the name of the entity being transformed, if that
155 /// information was not available elsewhere in the AST.
156 ///
157 /// By default, returns an empty name. Subclasses can provide an alternative
158 /// implementation with a more precise name.
159 DeclarationName getBaseEntity() { return DeclarationName(); }
160
Douglas Gregorb98b1992009-08-11 05:31:07 +0000161 /// \brief Sets the "base" location and entity when that
162 /// information is known based on another transformation.
163 ///
164 /// By default, the source location and entity are ignored. Subclasses can
165 /// override this function to provide a customized implementation.
166 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000167
Douglas Gregorb98b1992009-08-11 05:31:07 +0000168 /// \brief RAII object that temporarily sets the base location and entity
169 /// used for reporting diagnostics in types.
170 class TemporaryBase {
171 TreeTransform &Self;
172 SourceLocation OldLocation;
173 DeclarationName OldEntity;
Mike Stump1eb44332009-09-09 15:08:12 +0000174
Douglas Gregorb98b1992009-08-11 05:31:07 +0000175 public:
176 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump1eb44332009-09-09 15:08:12 +0000177 DeclarationName Entity) : Self(Self) {
Douglas Gregorb98b1992009-08-11 05:31:07 +0000178 OldLocation = Self.getDerived().getBaseLocation();
179 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000180
Douglas Gregorae201f72011-01-25 17:51:48 +0000181 if (Location.isValid())
182 Self.getDerived().setBase(Location, Entity);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000183 }
Mike Stump1eb44332009-09-09 15:08:12 +0000184
Douglas Gregorb98b1992009-08-11 05:31:07 +0000185 ~TemporaryBase() {
186 Self.getDerived().setBase(OldLocation, OldEntity);
187 }
188 };
Mike Stump1eb44332009-09-09 15:08:12 +0000189
190 /// \brief Determine whether the given type \p T has already been
Douglas Gregor577f75a2009-08-04 16:50:30 +0000191 /// transformed.
192 ///
193 /// Subclasses can provide an alternative implementation of this routine
Mike Stump1eb44332009-09-09 15:08:12 +0000194 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregor577f75a2009-08-04 16:50:30 +0000195 /// not change. For example, template instantiation need not traverse
196 /// non-dependent types.
197 bool AlreadyTransformed(QualType T) {
198 return T.isNull();
199 }
200
Douglas Gregor6eef5192009-12-14 19:27:10 +0000201 /// \brief Determine whether the given call argument should be dropped, e.g.,
202 /// because it is a default argument.
203 ///
204 /// Subclasses can provide an alternative implementation of this routine to
205 /// determine which kinds of call arguments get dropped. By default,
206 /// CXXDefaultArgument nodes are dropped (prior to transformation).
207 bool DropCallArgument(Expr *E) {
208 return E->isDefaultArgument();
209 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000210
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000211 /// \brief Determine whether we should expand a pack expansion with the
212 /// given set of parameter packs into separate arguments by repeatedly
213 /// transforming the pattern.
214 ///
Douglas Gregorb99268b2010-12-21 00:52:54 +0000215 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000216 /// Subclasses can override this routine to provide different behavior.
217 ///
218 /// \param EllipsisLoc The location of the ellipsis that identifies the
219 /// pack expansion.
220 ///
221 /// \param PatternRange The source range that covers the entire pattern of
222 /// the pack expansion.
223 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000224 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000225 /// pattern.
226 ///
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000227 /// \param ShouldExpand Will be set to \c true if the transformer should
228 /// expand the corresponding pack expansions into separate arguments. When
229 /// set, \c NumExpansions must also be set.
230 ///
Douglas Gregord3731192011-01-10 07:32:04 +0000231 /// \param RetainExpansion Whether the caller should add an unexpanded
232 /// pack expansion after all of the expanded arguments. This is used
233 /// when extending explicitly-specified template argument packs per
234 /// C++0x [temp.arg.explicit]p9.
235 ///
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000236 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregorcded4f62011-01-14 17:04:44 +0000237 /// the expanded form of the corresponding pack expansion. This is both an
238 /// input and an output parameter, which can be set by the caller if the
239 /// number of expansions is known a priori (e.g., due to a prior substitution)
240 /// and will be set by the callee when the number of expansions is known.
241 /// The callee must set this value when \c ShouldExpand is \c true; it may
242 /// set this value in other cases.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000243 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000244 /// \returns true if an error occurred (e.g., because the parameter packs
245 /// are to be instantiated with arguments of different lengths), false
246 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000247 /// must be set.
248 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
249 SourceRange PatternRange,
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +0000250 ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000251 bool &ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +0000252 bool &RetainExpansion,
David Blaikiedc84cd52013-02-20 22:23:23 +0000253 Optional<unsigned> &NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000254 ShouldExpand = false;
255 return false;
256 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000257
Douglas Gregord3731192011-01-10 07:32:04 +0000258 /// \brief "Forget" about the partially-substituted pack template argument,
259 /// when performing an instantiation that must preserve the parameter pack
260 /// use.
261 ///
262 /// This routine is meant to be overridden by the template instantiator.
263 TemplateArgument ForgetPartiallySubstitutedPack() {
264 return TemplateArgument();
265 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000266
Douglas Gregord3731192011-01-10 07:32:04 +0000267 /// \brief "Remember" the partially-substituted pack template argument
268 /// after performing an instantiation that must preserve the parameter pack
269 /// use.
270 ///
271 /// This routine is meant to be overridden by the template instantiator.
272 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000273
Douglas Gregor12c9c002011-01-07 16:43:16 +0000274 /// \brief Note to the derived class when a function parameter pack is
275 /// being expanded.
276 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000277
Douglas Gregor577f75a2009-08-04 16:50:30 +0000278 /// \brief Transforms the given type into another type.
279 ///
John McCalla2becad2009-10-21 00:40:46 +0000280 /// By default, this routine transforms a type by creating a
John McCalla93c9342009-12-07 02:54:59 +0000281 /// TypeSourceInfo for it and delegating to the appropriate
John McCalla2becad2009-10-21 00:40:46 +0000282 /// function. This is expensive, but we don't mind, because
283 /// this method is deprecated anyway; all users should be
John McCalla93c9342009-12-07 02:54:59 +0000284 /// switched to storing TypeSourceInfos.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000285 ///
286 /// \returns the transformed type.
John McCall43fed0d2010-11-12 08:19:04 +0000287 QualType TransformType(QualType T);
Mike Stump1eb44332009-09-09 15:08:12 +0000288
John McCalla2becad2009-10-21 00:40:46 +0000289 /// \brief Transforms the given type-with-location into a new
290 /// type-with-location.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000291 ///
John McCalla2becad2009-10-21 00:40:46 +0000292 /// By default, this routine transforms a type by delegating to the
293 /// appropriate TransformXXXType to build a new type. Subclasses
294 /// may override this function (to take over all type
295 /// transformations) or some set of the TransformXXXType functions
296 /// to alter the transformation.
John McCall43fed0d2010-11-12 08:19:04 +0000297 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCalla2becad2009-10-21 00:40:46 +0000298
299 /// \brief Transform the given type-with-location into a new
300 /// type, collecting location information in the given builder
301 /// as necessary.
302 ///
John McCall43fed0d2010-11-12 08:19:04 +0000303 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump1eb44332009-09-09 15:08:12 +0000304
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000305 /// \brief Transform the given statement.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000306 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000307 /// By default, this routine transforms a statement by delegating to the
Douglas Gregor43959a92009-08-20 07:17:43 +0000308 /// appropriate TransformXXXStmt function to transform a specific kind of
309 /// statement or the TransformExpr() function to transform an expression.
310 /// Subclasses may override this function to transform statements using some
311 /// other mechanism.
312 ///
313 /// \returns the transformed statement.
John McCall60d7b3a2010-08-24 06:29:42 +0000314 StmtResult TransformStmt(Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +0000315
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000316 /// \brief Transform the given expression.
317 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000318 /// By default, this routine transforms an expression by delegating to the
319 /// appropriate TransformXXXExpr function to build a new expression.
320 /// Subclasses may override this function to transform expressions using some
321 /// other mechanism.
322 ///
323 /// \returns the transformed expression.
John McCall60d7b3a2010-08-24 06:29:42 +0000324 ExprResult TransformExpr(Expr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000325
Richard Smithc83c2302012-12-19 01:39:02 +0000326 /// \brief Transform the given initializer.
327 ///
328 /// By default, this routine transforms an initializer by stripping off the
329 /// semantic nodes added by initialization, then passing the result to
330 /// TransformExpr or TransformExprs.
331 ///
332 /// \returns the transformed initializer.
333 ExprResult TransformInitializer(Expr *Init, bool CXXDirectInit);
334
Douglas Gregoraa165f82011-01-03 19:04:46 +0000335 /// \brief Transform the given list of expressions.
336 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000337 /// This routine transforms a list of expressions by invoking
338 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregoraa165f82011-01-03 19:04:46 +0000339 /// support for variadic templates by expanding any pack expansions (if the
340 /// derived class permits such expansion) along the way. When pack expansions
341 /// are present, the number of outputs may not equal the number of inputs.
342 ///
343 /// \param Inputs The set of expressions to be transformed.
344 ///
345 /// \param NumInputs The number of expressions in \c Inputs.
346 ///
347 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier4a9d7952012-08-08 18:46:20 +0000348 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregoraa165f82011-01-03 19:04:46 +0000349 /// be.
350 ///
351 /// \param Outputs The transformed input expressions will be added to this
352 /// vector.
353 ///
354 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
355 /// due to transformation.
356 ///
357 /// \returns true if an error occurred, false otherwise.
358 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +0000359 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +0000360 bool *ArgChanged = 0);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000361
Douglas Gregor577f75a2009-08-04 16:50:30 +0000362 /// \brief Transform the given declaration, which is referenced from a type
363 /// or expression.
364 ///
Douglas Gregordfca6f52012-02-13 22:00:16 +0000365 /// By default, acts as the identity function on declarations, unless the
366 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregordcee1a12009-08-06 05:28:30 +0000367 /// may override this function to provide alternate behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000368 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregordfca6f52012-02-13 22:00:16 +0000369 llvm::DenseMap<Decl *, Decl *>::iterator Known
370 = TransformedLocalDecls.find(D);
371 if (Known != TransformedLocalDecls.end())
372 return Known->second;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000373
374 return D;
Douglas Gregordfca6f52012-02-13 22:00:16 +0000375 }
Douglas Gregor43959a92009-08-20 07:17:43 +0000376
Chad Rosier4a9d7952012-08-08 18:46:20 +0000377 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregordfca6f52012-02-13 22:00:16 +0000378 /// place them on the new declaration.
379 ///
380 /// By default, this operation does nothing. Subclasses may override this
381 /// behavior to transform attributes.
382 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000383
Douglas Gregordfca6f52012-02-13 22:00:16 +0000384 /// \brief Note that a local declaration has been transformed by this
385 /// transformer.
386 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000387 /// Local declarations are typically transformed via a call to
Douglas Gregordfca6f52012-02-13 22:00:16 +0000388 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
389 /// the transformer itself has to transform the declarations. This routine
390 /// can be overridden by a subclass that keeps track of such mappings.
391 void transformedLocalDecl(Decl *Old, Decl *New) {
392 TransformedLocalDecls[Old] = New;
393 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000394
Douglas Gregor43959a92009-08-20 07:17:43 +0000395 /// \brief Transform the definition of the given declaration.
396 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000397 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregor43959a92009-08-20 07:17:43 +0000398 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000399 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
400 return getDerived().TransformDecl(Loc, D);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000401 }
Mike Stump1eb44332009-09-09 15:08:12 +0000402
Douglas Gregor6cd21982009-10-20 05:58:46 +0000403 /// \brief Transform the given declaration, which was the first part of a
404 /// nested-name-specifier in a member access expression.
405 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000406 /// This specific declaration transformation only applies to the first
Douglas Gregor6cd21982009-10-20 05:58:46 +0000407 /// identifier in a nested-name-specifier of a member access expression, e.g.,
408 /// the \c T in \c x->T::member
409 ///
410 /// By default, invokes TransformDecl() to transform the declaration.
411 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000412 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
413 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregor6cd21982009-10-20 05:58:46 +0000414 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000415
Douglas Gregorc22b5ff2011-02-25 02:25:35 +0000416 /// \brief Transform the given nested-name-specifier with source-location
417 /// information.
418 ///
419 /// By default, transforms all of the types and declarations within the
420 /// nested-name-specifier. Subclasses may override this function to provide
421 /// alternate behavior.
422 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
423 NestedNameSpecifierLoc NNS,
424 QualType ObjectType = QualType(),
425 NamedDecl *FirstQualifierInScope = 0);
426
Douglas Gregor81499bb2009-09-03 22:13:48 +0000427 /// \brief Transform the given declaration name.
428 ///
429 /// By default, transforms the types of conversion function, constructor,
430 /// and destructor names and then (if needed) rebuilds the declaration name.
431 /// Identifiers and selectors are returned unmodified. Sublcasses may
432 /// override this function to provide alternate behavior.
Abramo Bagnara25777432010-08-11 22:01:17 +0000433 DeclarationNameInfo
John McCall43fed0d2010-11-12 08:19:04 +0000434 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump1eb44332009-09-09 15:08:12 +0000435
Douglas Gregor577f75a2009-08-04 16:50:30 +0000436 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000437 ///
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000438 /// \param SS The nested-name-specifier that qualifies the template
439 /// name. This nested-name-specifier must already have been transformed.
440 ///
441 /// \param Name The template name to transform.
442 ///
443 /// \param NameLoc The source location of the template name.
444 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000445 /// \param ObjectType If we're translating a template name within a member
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000446 /// access expression, this is the type of the object whose member template
447 /// is being referenced.
448 ///
449 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
450 /// also refers to a name within the current (lexical) scope, this is the
451 /// declaration it refers to.
452 ///
453 /// By default, transforms the template name by transforming the declarations
454 /// and nested-name-specifiers that occur within the template name.
455 /// Subclasses may override this function to provide alternate behavior.
456 TemplateName TransformTemplateName(CXXScopeSpec &SS,
457 TemplateName Name,
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000458 SourceLocation NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000459 QualType ObjectType = QualType(),
460 NamedDecl *FirstQualifierInScope = 0);
461
Douglas Gregor577f75a2009-08-04 16:50:30 +0000462 /// \brief Transform the given template argument.
463 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000464 /// By default, this operation transforms the type, expression, or
465 /// declaration stored within the template argument and constructs a
Douglas Gregor670444e2009-08-04 22:27:00 +0000466 /// new template argument from the transformed result. Subclasses may
467 /// override this function to provide alternate behavior.
John McCall833ca992009-10-29 08:12:44 +0000468 ///
469 /// Returns true if there was an error.
470 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
471 TemplateArgumentLoc &Output);
472
Douglas Gregorfcc12532010-12-20 17:31:10 +0000473 /// \brief Transform the given set of template arguments.
474 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000475 /// By default, this operation transforms all of the template arguments
Douglas Gregorfcc12532010-12-20 17:31:10 +0000476 /// in the input set using \c TransformTemplateArgument(), and appends
477 /// the transformed arguments to the output list.
478 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000479 /// Note that this overload of \c TransformTemplateArguments() is merely
480 /// a convenience function. Subclasses that wish to override this behavior
481 /// should override the iterator-based member template version.
482 ///
Douglas Gregorfcc12532010-12-20 17:31:10 +0000483 /// \param Inputs The set of template arguments to be transformed.
484 ///
485 /// \param NumInputs The number of template arguments in \p Inputs.
486 ///
487 /// \param Outputs The set of transformed template arguments output by this
488 /// routine.
489 ///
490 /// Returns true if an error occurred.
491 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
492 unsigned NumInputs,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000493 TemplateArgumentListInfo &Outputs) {
494 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
495 }
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000496
497 /// \brief Transform the given set of template arguments.
498 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000499 /// By default, this operation transforms all of the template arguments
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000500 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier4a9d7952012-08-08 18:46:20 +0000501 /// the transformed arguments to the output list.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000502 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000503 /// \param First An iterator to the first template argument.
504 ///
505 /// \param Last An iterator one step past the last template argument.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000506 ///
507 /// \param Outputs The set of transformed template arguments output by this
508 /// routine.
509 ///
510 /// Returns true if an error occurred.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000511 template<typename InputIterator>
512 bool TransformTemplateArguments(InputIterator First,
513 InputIterator Last,
514 TemplateArgumentListInfo &Outputs);
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000515
John McCall833ca992009-10-29 08:12:44 +0000516 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
517 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
518 TemplateArgumentLoc &ArgLoc);
519
John McCalla93c9342009-12-07 02:54:59 +0000520 /// \brief Fakes up a TypeSourceInfo for a type.
521 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
522 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall833ca992009-10-29 08:12:44 +0000523 getDerived().getBaseLocation());
524 }
Mike Stump1eb44332009-09-09 15:08:12 +0000525
John McCalla2becad2009-10-21 00:40:46 +0000526#define ABSTRACT_TYPELOC(CLASS, PARENT)
527#define TYPELOC(CLASS, PARENT) \
John McCall43fed0d2010-11-12 08:19:04 +0000528 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCalla2becad2009-10-21 00:40:46 +0000529#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000530
Douglas Gregorcefc3af2012-04-16 07:05:22 +0000531 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
532 FunctionProtoTypeLoc TL,
533 CXXRecordDecl *ThisContext,
534 unsigned ThisTypeQuals);
535
John Wiegley28bbe4b2011-04-28 01:08:34 +0000536 StmtResult
537 TransformSEHHandler(Stmt *Handler);
538
Chad Rosier4a9d7952012-08-08 18:46:20 +0000539 QualType
John McCall43fed0d2010-11-12 08:19:04 +0000540 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
541 TemplateSpecializationTypeLoc TL,
542 TemplateName Template);
543
Chad Rosier4a9d7952012-08-08 18:46:20 +0000544 QualType
John McCall43fed0d2010-11-12 08:19:04 +0000545 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
546 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +0000547 TemplateName Template,
548 CXXScopeSpec &SS);
Douglas Gregora88f09f2011-02-28 17:23:35 +0000549
Chad Rosier4a9d7952012-08-08 18:46:20 +0000550 QualType
Douglas Gregora88f09f2011-02-28 17:23:35 +0000551 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000552 DependentTemplateSpecializationTypeLoc TL,
553 NestedNameSpecifierLoc QualifierLoc);
554
John McCall21ef0fa2010-03-11 09:03:00 +0000555 /// \brief Transforms the parameters of a function type into the
556 /// given vectors.
557 ///
558 /// The result vectors should be kept in sync; null entries in the
559 /// variables vector are acceptable.
560 ///
561 /// Return true on error.
Douglas Gregora009b592011-01-07 00:20:55 +0000562 bool TransformFunctionTypeParams(SourceLocation Loc,
563 ParmVarDecl **Params, unsigned NumParams,
564 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +0000565 SmallVectorImpl<QualType> &PTypes,
566 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall21ef0fa2010-03-11 09:03:00 +0000567
568 /// \brief Transforms a single function-type parameter. Return null
569 /// on error.
John McCallfb44de92011-05-01 22:35:37 +0000570 ///
571 /// \param indexAdjustment - A number to add to the parameter's
572 /// scope index; can be negative
Douglas Gregor6a24bfd2011-01-14 22:40:04 +0000573 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +0000574 int indexAdjustment,
David Blaikiedc84cd52013-02-20 22:23:23 +0000575 Optional<unsigned> NumExpansions,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +0000576 bool ExpectParameterPack);
John McCall21ef0fa2010-03-11 09:03:00 +0000577
John McCall43fed0d2010-11-12 08:19:04 +0000578 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall833ca992009-10-29 08:12:44 +0000579
John McCall60d7b3a2010-08-24 06:29:42 +0000580 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
581 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000582
Richard Smith612409e2012-07-25 03:56:55 +0000583 /// \brief Transform the captures and body of a lambda expression.
584 ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator);
585
Richard Smithefeeccf2012-10-21 03:28:35 +0000586 ExprResult TransformAddressOfOperand(Expr *E);
587 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
588 bool IsAddressOfOperand);
589
Douglas Gregor43959a92009-08-20 07:17:43 +0000590#define STMT(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000591 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000592#define EXPR(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000593 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000594#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000595#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000596
Douglas Gregor577f75a2009-08-04 16:50:30 +0000597 /// \brief Build a new pointer type given its pointee type.
598 ///
599 /// By default, performs semantic analysis when building the pointer type.
600 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000601 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000602
603 /// \brief Build a new block pointer type given its pointee type.
604 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000605 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000606 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000607 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000608
John McCall85737a72009-10-30 00:06:24 +0000609 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000610 ///
John McCall85737a72009-10-30 00:06:24 +0000611 /// By default, performs semantic analysis when building the
612 /// reference type. Subclasses may override this routine to provide
613 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000614 ///
John McCall85737a72009-10-30 00:06:24 +0000615 /// \param LValue whether the type was written with an lvalue sigil
616 /// or an rvalue sigil.
617 QualType RebuildReferenceType(QualType ReferentType,
618 bool LValue,
619 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000620
Douglas Gregor577f75a2009-08-04 16:50:30 +0000621 /// \brief Build a new member pointer type given the pointee type and the
622 /// class type it refers into.
623 ///
624 /// By default, performs semantic analysis when building the member pointer
625 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000626 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
627 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000628
Douglas Gregor577f75a2009-08-04 16:50:30 +0000629 /// \brief Build a new array type given the element type, size
630 /// modifier, size of the array (if known), size expression, and index type
631 /// qualifiers.
632 ///
633 /// By default, performs semantic analysis when building the array type.
634 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000635 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000636 QualType RebuildArrayType(QualType ElementType,
637 ArrayType::ArraySizeModifier SizeMod,
638 const llvm::APInt *Size,
639 Expr *SizeExpr,
640 unsigned IndexTypeQuals,
641 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000642
Douglas Gregor577f75a2009-08-04 16:50:30 +0000643 /// \brief Build a new constant array type given the element type, size
644 /// modifier, (known) size of the array, and index type qualifiers.
645 ///
646 /// By default, performs semantic analysis when building the array type.
647 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000648 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000649 ArrayType::ArraySizeModifier SizeMod,
650 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000651 unsigned IndexTypeQuals,
652 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000653
Douglas Gregor577f75a2009-08-04 16:50:30 +0000654 /// \brief Build a new incomplete array type given the element type, size
655 /// modifier, and index type qualifiers.
656 ///
657 /// By default, performs semantic analysis when building the array type.
658 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000659 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000660 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000661 unsigned IndexTypeQuals,
662 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000663
Mike Stump1eb44332009-09-09 15:08:12 +0000664 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000665 /// size modifier, size expression, and index type qualifiers.
666 ///
667 /// By default, performs semantic analysis when building the array type.
668 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000669 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000670 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000671 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000672 unsigned IndexTypeQuals,
673 SourceRange BracketsRange);
674
Mike Stump1eb44332009-09-09 15:08:12 +0000675 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000676 /// size modifier, size expression, and index type qualifiers.
677 ///
678 /// By default, performs semantic analysis when building the array type.
679 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000680 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000681 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000682 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000683 unsigned IndexTypeQuals,
684 SourceRange BracketsRange);
685
686 /// \brief Build a new vector type given the element type and
687 /// number of elements.
688 ///
689 /// By default, performs semantic analysis when building the vector type.
690 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000691 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000692 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000693
Douglas Gregor577f75a2009-08-04 16:50:30 +0000694 /// \brief Build a new extended vector type given the element type and
695 /// number of elements.
696 ///
697 /// By default, performs semantic analysis when building the vector type.
698 /// Subclasses may override this routine to provide different behavior.
699 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
700 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000701
702 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000703 /// given the element type and number of elements.
704 ///
705 /// By default, performs semantic analysis when building the vector type.
706 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000707 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000708 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000709 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000710
Douglas Gregor577f75a2009-08-04 16:50:30 +0000711 /// \brief Build a new function type.
712 ///
713 /// By default, performs semantic analysis when building the function type.
714 /// Subclasses may override this routine to provide different behavior.
715 QualType RebuildFunctionProtoType(QualType T,
Jordan Rosebea522f2013-03-08 21:51:21 +0000716 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +0000717 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump1eb44332009-09-09 15:08:12 +0000718
John McCalla2becad2009-10-21 00:40:46 +0000719 /// \brief Build a new unprototyped function type.
720 QualType RebuildFunctionNoProtoType(QualType ResultType);
721
John McCalled976492009-12-04 22:46:56 +0000722 /// \brief Rebuild an unresolved typename type, given the decl that
723 /// the UnresolvedUsingTypenameDecl was transformed to.
724 QualType RebuildUnresolvedUsingType(Decl *D);
725
Douglas Gregor577f75a2009-08-04 16:50:30 +0000726 /// \brief Build a new typedef type.
Richard Smith162e1c12011-04-15 14:24:37 +0000727 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregor577f75a2009-08-04 16:50:30 +0000728 return SemaRef.Context.getTypeDeclType(Typedef);
729 }
730
731 /// \brief Build a new class/struct/union type.
732 QualType RebuildRecordType(RecordDecl *Record) {
733 return SemaRef.Context.getTypeDeclType(Record);
734 }
735
736 /// \brief Build a new Enum type.
737 QualType RebuildEnumType(EnumDecl *Enum) {
738 return SemaRef.Context.getTypeDeclType(Enum);
739 }
John McCall7da24312009-09-05 00:15:47 +0000740
Mike Stump1eb44332009-09-09 15:08:12 +0000741 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000742 ///
743 /// By default, performs semantic analysis when building the typeof type.
744 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000745 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000746
Mike Stump1eb44332009-09-09 15:08:12 +0000747 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000748 ///
749 /// By default, builds a new TypeOfType with the given underlying type.
750 QualType RebuildTypeOfType(QualType Underlying);
751
Sean Huntca63c202011-05-24 22:41:36 +0000752 /// \brief Build a new unary transform type.
753 QualType RebuildUnaryTransformType(QualType BaseType,
754 UnaryTransformType::UTTKind UKind,
755 SourceLocation Loc);
756
Richard Smitha2c36462013-04-26 16:15:35 +0000757 /// \brief Build a new C++11 decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000758 ///
759 /// By default, performs semantic analysis when building the decltype type.
760 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000761 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000762
Richard Smitha2c36462013-04-26 16:15:35 +0000763 /// \brief Build a new C++11 auto type.
Richard Smith34b41d92011-02-20 03:19:35 +0000764 ///
765 /// By default, builds a new AutoType with the given deduced type.
Richard Smitha2c36462013-04-26 16:15:35 +0000766 QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) {
Richard Smithdc7a4f52013-04-30 13:56:41 +0000767 // Note, IsDependent is always false here: we implicitly convert an 'auto'
768 // which has been deduced to a dependent type into an undeduced 'auto', so
769 // that we'll retry deduction after the transformation.
Richard Smitha2c36462013-04-26 16:15:35 +0000770 return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto);
Richard Smith34b41d92011-02-20 03:19:35 +0000771 }
772
Douglas Gregor577f75a2009-08-04 16:50:30 +0000773 /// \brief Build a new template specialization type.
774 ///
775 /// By default, performs semantic analysis when building the template
776 /// specialization type. Subclasses may override this routine to provide
777 /// different behavior.
778 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000779 SourceLocation TemplateLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000780 TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000781
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000782 /// \brief Build a new parenthesized type.
783 ///
784 /// By default, builds a new ParenType type from the inner type.
785 /// Subclasses may override this routine to provide different behavior.
786 QualType RebuildParenType(QualType InnerType) {
787 return SemaRef.Context.getParenType(InnerType);
788 }
789
Douglas Gregor577f75a2009-08-04 16:50:30 +0000790 /// \brief Build a new qualified name type.
791 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000792 /// By default, builds a new ElaboratedType type from the keyword,
793 /// the nested-name-specifier and the named type.
794 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000795 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
796 ElaboratedTypeKeyword Keyword,
Douglas Gregor9e876872011-03-01 18:12:44 +0000797 NestedNameSpecifierLoc QualifierLoc,
798 QualType Named) {
Chad Rosier4a9d7952012-08-08 18:46:20 +0000799 return SemaRef.Context.getElaboratedType(Keyword,
800 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor9e876872011-03-01 18:12:44 +0000801 Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000802 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000803
804 /// \brief Build a new typename type that refers to a template-id.
805 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000806 /// By default, builds a new DependentNameType type from the
807 /// nested-name-specifier and the given type. Subclasses may override
808 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000809 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000810 ElaboratedTypeKeyword Keyword,
811 NestedNameSpecifierLoc QualifierLoc,
812 const IdentifierInfo *Name,
813 SourceLocation NameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000814 TemplateArgumentListInfo &Args) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000815 // Rebuild the template name.
816 // TODO: avoid TemplateName abstraction
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000817 CXXScopeSpec SS;
818 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000819 TemplateName InstName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000820 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000821
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000822 if (InstName.isNull())
823 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000824
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000825 // If it's still dependent, make a dependent specialization.
826 if (InstName.getAsDependentTemplateName())
Chad Rosier4a9d7952012-08-08 18:46:20 +0000827 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
828 QualifierLoc.getNestedNameSpecifier(),
829 Name,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000830 Args);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000831
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000832 // Otherwise, make an elaborated type wrapping a non-dependent
833 // specialization.
834 QualType T =
835 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
836 if (T.isNull()) return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000837
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000838 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
839 return T;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000840
841 return SemaRef.Context.getElaboratedType(Keyword,
842 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000843 T);
844 }
845
Douglas Gregor577f75a2009-08-04 16:50:30 +0000846 /// \brief Build a new typename type that refers to an identifier.
847 ///
848 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000849 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000850 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000851 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000852 SourceLocation KeywordLoc,
Douglas Gregor2494dd02011-03-01 01:34:45 +0000853 NestedNameSpecifierLoc QualifierLoc,
854 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000855 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000856 CXXScopeSpec SS;
Douglas Gregor2494dd02011-03-01 01:34:45 +0000857 SS.Adopt(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000858
Douglas Gregor2494dd02011-03-01 01:34:45 +0000859 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000860 // If the name is still dependent, just build a new dependent name type.
861 if (!SemaRef.computeDeclContext(SS))
Chad Rosier4a9d7952012-08-08 18:46:20 +0000862 return SemaRef.Context.getDependentNameType(Keyword,
863 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000864 Id);
Douglas Gregor40336422010-03-31 22:19:08 +0000865 }
866
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000867 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor2494dd02011-03-01 01:34:45 +0000868 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregore29425b2011-02-28 22:42:13 +0000869 *Id, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000870
871 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
872
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000873 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000874 // into a non-dependent elaborated-type-specifier. Find the tag we're
875 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000876 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000877 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
878 if (!DC)
879 return QualType();
880
John McCall56138762010-05-27 06:40:31 +0000881 if (SemaRef.RequireCompleteDeclContext(SS, DC))
882 return QualType();
883
Douglas Gregor40336422010-03-31 22:19:08 +0000884 TagDecl *Tag = 0;
885 SemaRef.LookupQualifiedName(Result, DC);
886 switch (Result.getResultKind()) {
887 case LookupResult::NotFound:
888 case LookupResult::NotFoundInCurrentInstantiation:
889 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000890
Douglas Gregor40336422010-03-31 22:19:08 +0000891 case LookupResult::Found:
892 Tag = Result.getAsSingle<TagDecl>();
893 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000894
Douglas Gregor40336422010-03-31 22:19:08 +0000895 case LookupResult::FoundOverloaded:
896 case LookupResult::FoundUnresolvedValue:
897 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier4a9d7952012-08-08 18:46:20 +0000898
Douglas Gregor40336422010-03-31 22:19:08 +0000899 case LookupResult::Ambiguous:
900 // Let the LookupResult structure handle ambiguities.
901 return QualType();
902 }
903
904 if (!Tag) {
Nick Lewycky446e4022011-01-24 19:01:04 +0000905 // Check where the name exists but isn't a tag type and use that to emit
906 // better diagnostics.
907 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
908 SemaRef.LookupQualifiedName(Result, DC);
909 switch (Result.getResultKind()) {
910 case LookupResult::Found:
911 case LookupResult::FoundOverloaded:
912 case LookupResult::FoundUnresolvedValue: {
Richard Smith3e4c6c42011-05-05 21:57:07 +0000913 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky446e4022011-01-24 19:01:04 +0000914 unsigned Kind = 0;
915 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smith162e1c12011-04-15 14:24:37 +0000916 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
917 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky446e4022011-01-24 19:01:04 +0000918 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
919 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
920 break;
Richard Smith3e4c6c42011-05-05 21:57:07 +0000921 }
Nick Lewycky446e4022011-01-24 19:01:04 +0000922 default:
923 // FIXME: Would be nice to highlight just the source range.
924 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
925 << Kind << Id << DC;
926 break;
927 }
Douglas Gregor40336422010-03-31 22:19:08 +0000928 return QualType();
929 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000930
Richard Trieubbf34c02011-06-10 03:11:26 +0000931 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
932 IdLoc, *Id)) {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000933 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000934 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
935 return QualType();
936 }
937
938 // Build the elaborated-type-specifier type.
939 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000940 return SemaRef.Context.getElaboratedType(Keyword,
941 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000942 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000943 }
Mike Stump1eb44332009-09-09 15:08:12 +0000944
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000945 /// \brief Build a new pack expansion type.
946 ///
947 /// By default, builds a new PackExpansionType type from the given pattern.
948 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000949 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000950 SourceRange PatternRange,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000951 SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +0000952 Optional<unsigned> NumExpansions) {
Douglas Gregorcded4f62011-01-14 17:04:44 +0000953 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
954 NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000955 }
956
Eli Friedmanb001de72011-10-06 23:00:33 +0000957 /// \brief Build a new atomic type given its value type.
958 ///
959 /// By default, performs semantic analysis when building the atomic type.
960 /// Subclasses may override this routine to provide different behavior.
961 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
962
Douglas Gregord1067e52009-08-06 06:41:21 +0000963 /// \brief Build a new template name given a nested name specifier, a flag
964 /// indicating whether the "template" keyword was provided, and the template
965 /// that the template name refers to.
966 ///
967 /// By default, builds the new template name directly. Subclasses may override
968 /// this routine to provide different behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000969 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +0000970 bool TemplateKW,
971 TemplateDecl *Template);
972
Douglas Gregord1067e52009-08-06 06:41:21 +0000973 /// \brief Build a new template name given a nested name specifier and the
974 /// name that is referred to as a template.
975 ///
976 /// By default, performs semantic analysis to determine whether the name can
977 /// be resolved to a specific template, then builds the appropriate kind of
978 /// template name. Subclasses may override this routine to provide different
979 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000980 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
981 const IdentifierInfo &Name,
982 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +0000983 QualType ObjectType,
984 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +0000985
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000986 /// \brief Build a new template name given a nested name specifier and the
987 /// overloaded operator name that is referred to as a template.
988 ///
989 /// By default, performs semantic analysis to determine whether the name can
990 /// be resolved to a specific template, then builds the appropriate kind of
991 /// template name. Subclasses may override this routine to provide different
992 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000993 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000994 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000995 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000996 QualType ObjectType);
Douglas Gregor1aee05d2011-01-15 06:45:20 +0000997
998 /// \brief Build a new template name given a template template parameter pack
Chad Rosier4a9d7952012-08-08 18:46:20 +0000999 /// and the
Douglas Gregor1aee05d2011-01-15 06:45:20 +00001000 ///
1001 /// By default, performs semantic analysis to determine whether the name can
1002 /// be resolved to a specific template, then builds the appropriate kind of
1003 /// template name. Subclasses may override this routine to provide different
1004 /// behavior.
1005 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1006 const TemplateArgument &ArgPack) {
1007 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1008 }
1009
Douglas Gregor43959a92009-08-20 07:17:43 +00001010 /// \brief Build a new compound statement.
1011 ///
1012 /// By default, performs semantic analysis to build the new statement.
1013 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001014 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001015 MultiStmtArg Statements,
1016 SourceLocation RBraceLoc,
1017 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +00001018 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00001019 IsStmtExpr);
1020 }
1021
1022 /// \brief Build a new case statement.
1023 ///
1024 /// By default, performs semantic analysis to build the new statement.
1025 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001026 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001027 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001028 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001029 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001030 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001031 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001032 ColonLoc);
1033 }
Mike Stump1eb44332009-09-09 15:08:12 +00001034
Douglas Gregor43959a92009-08-20 07:17:43 +00001035 /// \brief Attach the body to a new case statement.
1036 ///
1037 /// By default, performs semantic analysis to build the new statement.
1038 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001039 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001040 getSema().ActOnCaseStmtBody(S, Body);
1041 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +00001042 }
Mike Stump1eb44332009-09-09 15:08:12 +00001043
Douglas Gregor43959a92009-08-20 07:17:43 +00001044 /// \brief Build a new default statement.
1045 ///
1046 /// By default, performs semantic analysis to build the new statement.
1047 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001048 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001049 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001050 Stmt *SubStmt) {
1051 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +00001052 /*CurScope=*/0);
1053 }
Mike Stump1eb44332009-09-09 15:08:12 +00001054
Douglas Gregor43959a92009-08-20 07:17:43 +00001055 /// \brief Build a new label statement.
1056 ///
1057 /// By default, performs semantic analysis to build the new statement.
1058 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001059 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1060 SourceLocation ColonLoc, Stmt *SubStmt) {
1061 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregor43959a92009-08-20 07:17:43 +00001062 }
Mike Stump1eb44332009-09-09 15:08:12 +00001063
Richard Smith534986f2012-04-14 00:33:13 +00001064 /// \brief Build a new label statement.
1065 ///
1066 /// By default, performs semantic analysis to build the new statement.
1067 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko49908902012-07-09 10:04:07 +00001068 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1069 ArrayRef<const Attr*> Attrs,
Richard Smith534986f2012-04-14 00:33:13 +00001070 Stmt *SubStmt) {
1071 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1072 }
1073
Douglas Gregor43959a92009-08-20 07:17:43 +00001074 /// \brief Build a new "if" statement.
1075 ///
1076 /// By default, performs semantic analysis to build the new statement.
1077 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001078 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001079 VarDecl *CondVar, Stmt *Then,
Chris Lattner57ad3782011-02-17 20:34:02 +00001080 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001081 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +00001082 }
Mike Stump1eb44332009-09-09 15:08:12 +00001083
Douglas Gregor43959a92009-08-20 07:17:43 +00001084 /// \brief Start building a new switch statement.
1085 ///
1086 /// By default, performs semantic analysis to build the new statement.
1087 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001088 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001089 Expr *Cond, VarDecl *CondVar) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001090 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001091 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001092 }
Mike Stump1eb44332009-09-09 15:08:12 +00001093
Douglas Gregor43959a92009-08-20 07:17:43 +00001094 /// \brief Attach the body to the switch 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 RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001099 Stmt *Switch, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001100 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001101 }
1102
1103 /// \brief Build a new while statement.
1104 ///
1105 /// By default, performs semantic analysis to build the new statement.
1106 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001107 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1108 VarDecl *CondVar, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001109 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001110 }
Mike Stump1eb44332009-09-09 15:08:12 +00001111
Douglas Gregor43959a92009-08-20 07:17:43 +00001112 /// \brief Build a new do-while statement.
1113 ///
1114 /// By default, performs semantic analysis to build the new statement.
1115 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001116 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001117 SourceLocation WhileLoc, SourceLocation LParenLoc,
1118 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001119 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1120 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001121 }
1122
1123 /// \brief Build a new for statement.
1124 ///
1125 /// By default, performs semantic analysis to build the new statement.
1126 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001127 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001128 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001129 VarDecl *CondVar, Sema::FullExprArg Inc,
1130 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001131 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001132 CondVar, Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001133 }
Mike Stump1eb44332009-09-09 15:08:12 +00001134
Douglas Gregor43959a92009-08-20 07:17:43 +00001135 /// \brief Build a new goto statement.
1136 ///
1137 /// By default, performs semantic analysis to build the new statement.
1138 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001139 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1140 LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001141 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregor43959a92009-08-20 07:17:43 +00001142 }
1143
1144 /// \brief Build a new indirect goto statement.
1145 ///
1146 /// By default, performs semantic analysis to build the new statement.
1147 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001148 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001149 SourceLocation StarLoc,
1150 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001151 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001152 }
Mike Stump1eb44332009-09-09 15:08:12 +00001153
Douglas Gregor43959a92009-08-20 07:17:43 +00001154 /// \brief Build a new return statement.
1155 ///
1156 /// By default, performs semantic analysis to build the new statement.
1157 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001158 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001159 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001160 }
Mike Stump1eb44332009-09-09 15:08:12 +00001161
Douglas Gregor43959a92009-08-20 07:17:43 +00001162 /// \brief Build a new declaration statement.
1163 ///
1164 /// By default, performs semantic analysis to build the new statement.
1165 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001166 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +00001167 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001168 SourceLocation EndLoc) {
Richard Smith406c38e2011-02-23 00:37:57 +00001169 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1170 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001171 }
Mike Stump1eb44332009-09-09 15:08:12 +00001172
Anders Carlsson703e3942010-01-24 05:50:09 +00001173 /// \brief Build a new inline asm statement.
1174 ///
1175 /// By default, performs semantic analysis to build the new statement.
1176 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001177 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1178 bool IsVolatile, unsigned NumOutputs,
1179 unsigned NumInputs, IdentifierInfo **Names,
1180 MultiExprArg Constraints, MultiExprArg Exprs,
1181 Expr *AsmString, MultiExprArg Clobbers,
1182 SourceLocation RParenLoc) {
1183 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1184 NumInputs, Names, Constraints, Exprs,
1185 AsmString, Clobbers, RParenLoc);
Anders Carlsson703e3942010-01-24 05:50:09 +00001186 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001187
Chad Rosier8cd64b42012-06-11 20:47:18 +00001188 /// \brief Build a new MS style inline asm statement.
1189 ///
1190 /// By default, performs semantic analysis to build the new statement.
1191 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001192 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallaeeacf72013-05-03 00:10:13 +00001193 ArrayRef<Token> AsmToks,
1194 StringRef AsmString,
1195 unsigned NumOutputs, unsigned NumInputs,
1196 ArrayRef<StringRef> Constraints,
1197 ArrayRef<StringRef> Clobbers,
1198 ArrayRef<Expr*> Exprs,
1199 SourceLocation EndLoc) {
1200 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1201 NumOutputs, NumInputs,
1202 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier8cd64b42012-06-11 20:47:18 +00001203 }
1204
James Dennett699c9042012-06-15 07:13:21 +00001205 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001206 ///
1207 /// By default, performs semantic analysis to build the new statement.
1208 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001209 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001210 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001211 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001212 Stmt *Finally) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001213 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001214 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001215 }
1216
Douglas Gregorbe270a02010-04-26 17:57:08 +00001217 /// \brief Rebuild an Objective-C exception declaration.
1218 ///
1219 /// By default, performs semantic analysis to build the new declaration.
1220 /// Subclasses may override this routine to provide different behavior.
1221 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1222 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001223 return getSema().BuildObjCExceptionDecl(TInfo, T,
1224 ExceptionDecl->getInnerLocStart(),
1225 ExceptionDecl->getLocation(),
1226 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001227 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001228
James Dennett699c9042012-06-15 07:13:21 +00001229 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorbe270a02010-04-26 17:57:08 +00001230 ///
1231 /// By default, performs semantic analysis to build the new statement.
1232 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001233 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001234 SourceLocation RParenLoc,
1235 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001236 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001237 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001238 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001239 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001240
James Dennett699c9042012-06-15 07:13:21 +00001241 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001242 ///
1243 /// By default, performs semantic analysis to build the new statement.
1244 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001245 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001246 Stmt *Body) {
1247 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001248 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001249
James Dennett699c9042012-06-15 07:13:21 +00001250 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001251 ///
1252 /// By default, performs semantic analysis to build the new statement.
1253 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001254 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001255 Expr *Operand) {
1256 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001257 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001258
James Dennett699c9042012-06-15 07:13:21 +00001259 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCall07524032011-07-27 21:50:02 +00001260 ///
1261 /// By default, performs semantic analysis to build the new statement.
1262 /// Subclasses may override this routine to provide different behavior.
1263 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1264 Expr *object) {
1265 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1266 }
1267
James Dennett699c9042012-06-15 07:13:21 +00001268 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001269 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001270 /// By default, performs semantic analysis to build the new statement.
1271 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001272 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall07524032011-07-27 21:50:02 +00001273 Expr *Object, Stmt *Body) {
1274 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001275 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001276
James Dennett699c9042012-06-15 07:13:21 +00001277 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCallf85e1932011-06-15 23:02:42 +00001278 ///
1279 /// By default, performs semantic analysis to build the new statement.
1280 /// Subclasses may override this routine to provide different behavior.
1281 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1282 Stmt *Body) {
1283 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1284 }
John McCall990567c2011-07-27 01:07:15 +00001285
Douglas Gregorc3203e72010-04-22 23:10:45 +00001286 /// \brief Build a new Objective-C fast enumeration statement.
1287 ///
1288 /// By default, performs semantic analysis to build the new statement.
1289 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001290 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001291 Stmt *Element,
1292 Expr *Collection,
1293 SourceLocation RParenLoc,
1294 Stmt *Body) {
Sam Panzerbc20bbb2012-08-16 21:47:25 +00001295 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001296 Element,
John McCall9ae2f072010-08-23 23:25:46 +00001297 Collection,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001298 RParenLoc);
1299 if (ForEachStmt.isInvalid())
1300 return StmtError();
1301
1302 return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001303 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001304
Douglas Gregor43959a92009-08-20 07:17:43 +00001305 /// \brief Build a new C++ exception declaration.
1306 ///
1307 /// By default, performs semantic analysis to build the new decaration.
1308 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001309 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001310 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001311 SourceLocation StartLoc,
1312 SourceLocation IdLoc,
1313 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001314 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1315 StartLoc, IdLoc, Id);
1316 if (Var)
1317 getSema().CurContext->addDecl(Var);
1318 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001319 }
1320
1321 /// \brief Build a new C++ catch statement.
1322 ///
1323 /// By default, performs semantic analysis to build the new statement.
1324 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001325 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001326 VarDecl *ExceptionDecl,
1327 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001328 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1329 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001330 }
Mike Stump1eb44332009-09-09 15:08:12 +00001331
Douglas Gregor43959a92009-08-20 07:17:43 +00001332 /// \brief Build a new C++ try statement.
1333 ///
1334 /// 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 RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001337 Stmt *TryBlock,
1338 MultiStmtArg Handlers) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001339 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00001340 }
Mike Stump1eb44332009-09-09 15:08:12 +00001341
Richard Smithad762fc2011-04-14 22:09:26 +00001342 /// \brief Build a new C++0x range-based for statement.
1343 ///
1344 /// By default, performs semantic analysis to build the new statement.
1345 /// Subclasses may override this routine to provide different behavior.
1346 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1347 SourceLocation ColonLoc,
1348 Stmt *Range, Stmt *BeginEnd,
1349 Expr *Cond, Expr *Inc,
1350 Stmt *LoopVar,
1351 SourceLocation RParenLoc) {
Douglas Gregor6f96f4b2013-04-08 18:40:13 +00001352 // If we've just learned that the range is actually an Objective-C
1353 // collection, treat this as an Objective-C fast enumeration loop.
1354 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1355 if (RangeStmt->isSingleDecl()) {
1356 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39b60dc2013-05-02 18:35:56 +00001357 if (RangeVar->isInvalidDecl())
1358 return StmtError();
1359
Douglas Gregor6f96f4b2013-04-08 18:40:13 +00001360 Expr *RangeExpr = RangeVar->getInit();
1361 if (!RangeExpr->isTypeDependent() &&
1362 RangeExpr->getType()->isObjCObjectPointerType())
1363 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1364 RParenLoc);
1365 }
1366 }
1367 }
1368
Richard Smithad762fc2011-04-14 22:09:26 +00001369 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smith8b533d92012-09-20 21:52:32 +00001370 Cond, Inc, LoopVar, RParenLoc,
1371 Sema::BFRK_Rebuild);
Richard Smithad762fc2011-04-14 22:09:26 +00001372 }
Douglas Gregorba0513d2011-10-25 01:33:02 +00001373
1374 /// \brief Build a new C++0x range-based for statement.
1375 ///
1376 /// By default, performs semantic analysis to build the new statement.
1377 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001378 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregorba0513d2011-10-25 01:33:02 +00001379 bool IsIfExists,
1380 NestedNameSpecifierLoc QualifierLoc,
1381 DeclarationNameInfo NameInfo,
1382 Stmt *Nested) {
1383 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1384 QualifierLoc, NameInfo, Nested);
1385 }
1386
Richard Smithad762fc2011-04-14 22:09:26 +00001387 /// \brief Attach body to a C++0x range-based for statement.
1388 ///
1389 /// By default, performs semantic analysis to finish the new statement.
1390 /// Subclasses may override this routine to provide different behavior.
1391 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1392 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1393 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001394
John Wiegley28bbe4b2011-04-28 01:08:34 +00001395 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1396 SourceLocation TryLoc,
1397 Stmt *TryBlock,
1398 Stmt *Handler) {
1399 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1400 }
1401
1402 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1403 Expr *FilterExpr,
1404 Stmt *Block) {
1405 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1406 }
1407
1408 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1409 Stmt *Block) {
1410 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1411 }
1412
Douglas Gregorb98b1992009-08-11 05:31:07 +00001413 /// \brief Build a new expression that references a declaration.
1414 ///
1415 /// By default, performs semantic analysis to build the new expression.
1416 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001417 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001418 LookupResult &R,
1419 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001420 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1421 }
1422
1423
1424 /// \brief Build a new expression that references a declaration.
1425 ///
1426 /// By default, performs semantic analysis to build the new expression.
1427 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001428 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001429 ValueDecl *VD,
1430 const DeclarationNameInfo &NameInfo,
1431 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001432 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001433 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001434
1435 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001436
1437 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001438 }
Mike Stump1eb44332009-09-09 15:08:12 +00001439
Douglas Gregorb98b1992009-08-11 05:31:07 +00001440 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001441 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001442 /// By default, performs semantic analysis to build the new expression.
1443 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001444 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001445 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001446 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001447 }
1448
Douglas Gregora71d8192009-09-04 17:36:40 +00001449 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001450 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001451 /// By default, performs semantic analysis to build the new expression.
1452 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001453 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001454 SourceLocation OperatorLoc,
1455 bool isArrow,
1456 CXXScopeSpec &SS,
1457 TypeSourceInfo *ScopeType,
1458 SourceLocation CCLoc,
1459 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001460 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001461
Douglas Gregorb98b1992009-08-11 05:31:07 +00001462 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001463 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001464 /// By default, performs semantic analysis to build the new expression.
1465 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001466 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001467 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001468 Expr *SubExpr) {
1469 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001470 }
Mike Stump1eb44332009-09-09 15:08:12 +00001471
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001472 /// \brief Build a new builtin offsetof expression.
1473 ///
1474 /// By default, performs semantic analysis to build the new expression.
1475 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001476 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001477 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001478 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001479 unsigned NumComponents,
1480 SourceLocation RParenLoc) {
1481 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1482 NumComponents, RParenLoc);
1483 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001484
1485 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001486 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001487 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001488 /// By default, performs semantic analysis to build the new expression.
1489 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001490 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1491 SourceLocation OpLoc,
1492 UnaryExprOrTypeTrait ExprKind,
1493 SourceRange R) {
1494 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001495 }
1496
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001497 /// \brief Build a new sizeof, alignof or vec step expression with an
1498 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001499 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001500 /// By default, performs semantic analysis to build the new expression.
1501 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001502 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1503 UnaryExprOrTypeTrait ExprKind,
1504 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001505 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001506 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001507 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001508 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001509
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001510 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001511 }
Mike Stump1eb44332009-09-09 15:08:12 +00001512
Douglas Gregorb98b1992009-08-11 05:31:07 +00001513 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001514 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001515 /// By default, performs semantic analysis to build the new expression.
1516 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001517 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001518 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001519 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001520 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001521 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1522 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001523 RBracketLoc);
1524 }
1525
1526 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001527 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001528 /// By default, performs semantic analysis to build the new expression.
1529 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001530 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001531 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001532 SourceLocation RParenLoc,
1533 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001534 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001535 Args, RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001536 }
1537
1538 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001539 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001540 /// By default, performs semantic analysis to build the new expression.
1541 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001542 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001543 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001544 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001545 SourceLocation TemplateKWLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001546 const DeclarationNameInfo &MemberNameInfo,
1547 ValueDecl *Member,
1548 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001549 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001550 NamedDecl *FirstQualifierInScope) {
Richard Smith9138b4e2011-10-26 19:06:56 +00001551 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1552 isArrow);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001553 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001554 // We have a reference to an unnamed field. This is always the
1555 // base of an anonymous struct/union member access, i.e. the
1556 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001557 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001558 assert(Member->getType()->isRecordType() &&
1559 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001560
Richard Smith9138b4e2011-10-26 19:06:56 +00001561 BaseResult =
1562 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley429bb272011-04-08 18:41:53 +00001563 QualifierLoc.getNestedNameSpecifier(),
1564 FoundDecl, Member);
1565 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001566 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001567 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001568 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001569 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001570 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001571 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001572 cast<FieldDecl>(Member)->getType(),
1573 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001574 return getSema().Owned(ME);
1575 }
Mike Stump1eb44332009-09-09 15:08:12 +00001576
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001577 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001578 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001579
John Wiegley429bb272011-04-08 18:41:53 +00001580 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001581 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001582
John McCall6bb80172010-03-30 21:47:33 +00001583 // FIXME: this involves duplicating earlier analysis in a lot of
1584 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001585 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001586 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001587 R.resolveKind();
1588
John McCall9ae2f072010-08-23 23:25:46 +00001589 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001590 SS, TemplateKWLoc,
1591 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001592 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001593 }
Mike Stump1eb44332009-09-09 15:08:12 +00001594
Douglas Gregorb98b1992009-08-11 05:31:07 +00001595 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001596 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001597 /// By default, performs semantic analysis to build the new expression.
1598 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001599 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001600 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001601 Expr *LHS, Expr *RHS) {
1602 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001603 }
1604
1605 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001606 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001607 /// By default, performs semantic analysis to build the new expression.
1608 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001609 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001610 SourceLocation QuestionLoc,
1611 Expr *LHS,
1612 SourceLocation ColonLoc,
1613 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001614 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1615 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001616 }
1617
Douglas Gregorb98b1992009-08-11 05:31:07 +00001618 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001619 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001620 /// By default, performs semantic analysis to build the new expression.
1621 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001622 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001623 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001624 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001625 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001626 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001627 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001628 }
Mike Stump1eb44332009-09-09 15:08:12 +00001629
Douglas Gregorb98b1992009-08-11 05:31:07 +00001630 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001631 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001632 /// By default, performs semantic analysis to build the new expression.
1633 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001634 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001635 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001636 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001637 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001638 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001639 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001640 }
Mike Stump1eb44332009-09-09 15:08:12 +00001641
Douglas Gregorb98b1992009-08-11 05:31:07 +00001642 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001643 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001644 /// By default, performs semantic analysis to build the new expression.
1645 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001646 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001647 SourceLocation OpLoc,
1648 SourceLocation AccessorLoc,
1649 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001650
John McCall129e2df2009-11-30 22:42:35 +00001651 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001652 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001653 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001654 OpLoc, /*IsArrow*/ false,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001655 SS, SourceLocation(),
1656 /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001657 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001658 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001659 }
Mike Stump1eb44332009-09-09 15:08:12 +00001660
Douglas Gregorb98b1992009-08-11 05:31:07 +00001661 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001662 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001663 /// By default, performs semantic analysis to build the new expression.
1664 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001665 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001666 MultiExprArg Inits,
1667 SourceLocation RBraceLoc,
1668 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001669 ExprResult Result
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001670 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregore48319a2009-11-09 17:16:50 +00001671 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001672 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00001673
Douglas Gregore48319a2009-11-09 17:16:50 +00001674 // Patch in the result type we were given, which may have been computed
1675 // when the initial InitListExpr was built.
1676 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1677 ILE->setType(ResultTy);
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001678 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001679 }
Mike Stump1eb44332009-09-09 15:08:12 +00001680
Douglas Gregorb98b1992009-08-11 05:31:07 +00001681 /// \brief Build a new designated initializer 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 RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001686 MultiExprArg ArrayExprs,
1687 SourceLocation EqualOrColonLoc,
1688 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001689 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001690 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001691 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001692 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001693 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001694 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001695
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001696 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001697 }
Mike Stump1eb44332009-09-09 15:08:12 +00001698
Douglas Gregorb98b1992009-08-11 05:31:07 +00001699 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001700 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001701 /// By default, builds the implicit value initialization without performing
1702 /// any semantic analysis. Subclasses may override this routine to provide
1703 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001704 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001705 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1706 }
Mike Stump1eb44332009-09-09 15:08:12 +00001707
Douglas Gregorb98b1992009-08-11 05:31:07 +00001708 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001709 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001710 /// By default, performs semantic analysis to build the new expression.
1711 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001712 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001713 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001714 SourceLocation RParenLoc) {
1715 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001716 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001717 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001718 }
1719
1720 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001721 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001722 /// By default, performs semantic analysis to build the new expression.
1723 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001724 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +00001725 MultiExprArg SubExprs,
1726 SourceLocation RParenLoc) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001727 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001728 }
Mike Stump1eb44332009-09-09 15:08:12 +00001729
Douglas Gregorb98b1992009-08-11 05:31:07 +00001730 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001731 ///
1732 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001733 /// rather than attempting to map the label statement itself.
1734 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001735 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001736 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001737 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001738 }
Mike Stump1eb44332009-09-09 15:08:12 +00001739
Douglas Gregorb98b1992009-08-11 05:31:07 +00001740 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001741 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001742 /// By default, performs semantic analysis to build the new expression.
1743 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001744 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001745 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001746 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001747 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001748 }
Mike Stump1eb44332009-09-09 15:08:12 +00001749
Douglas Gregorb98b1992009-08-11 05:31:07 +00001750 /// \brief Build a new __builtin_choose_expr expression.
1751 ///
1752 /// By default, performs semantic analysis to build the new expression.
1753 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001754 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001755 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001756 SourceLocation RParenLoc) {
1757 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001758 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001759 RParenLoc);
1760 }
Mike Stump1eb44332009-09-09 15:08:12 +00001761
Peter Collingbournef111d932011-04-15 00:35:48 +00001762 /// \brief Build a new generic selection expression.
1763 ///
1764 /// By default, performs semantic analysis to build the new expression.
1765 /// Subclasses may override this routine to provide different behavior.
1766 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1767 SourceLocation DefaultLoc,
1768 SourceLocation RParenLoc,
1769 Expr *ControllingExpr,
1770 TypeSourceInfo **Types,
1771 Expr **Exprs,
1772 unsigned NumAssocs) {
1773 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1774 ControllingExpr, Types, Exprs,
1775 NumAssocs);
1776 }
1777
Douglas Gregorb98b1992009-08-11 05:31:07 +00001778 /// \brief Build a new overloaded operator call expression.
1779 ///
1780 /// By default, performs semantic analysis to build the new expression.
1781 /// The semantic analysis provides the behavior of template instantiation,
1782 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001783 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001784 /// argument-dependent lookup, etc. Subclasses may override this routine to
1785 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001786 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001787 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001788 Expr *Callee,
1789 Expr *First,
1790 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001791
1792 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001793 /// reinterpret_cast.
1794 ///
1795 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001796 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001797 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001798 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001799 Stmt::StmtClass Class,
1800 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001801 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001802 SourceLocation RAngleLoc,
1803 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001804 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001805 SourceLocation RParenLoc) {
1806 switch (Class) {
1807 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001808 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001809 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001810 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001811
1812 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001813 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001814 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001815 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001816
Douglas Gregorb98b1992009-08-11 05:31:07 +00001817 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001818 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001819 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001820 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001821 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001822
Douglas Gregorb98b1992009-08-11 05:31:07 +00001823 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001824 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001825 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001826 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001827
Douglas Gregorb98b1992009-08-11 05:31:07 +00001828 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001829 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001830 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001831 }
Mike Stump1eb44332009-09-09 15:08:12 +00001832
Douglas Gregorb98b1992009-08-11 05:31:07 +00001833 /// \brief Build a new C++ static_cast expression.
1834 ///
1835 /// By default, performs semantic analysis to build the new expression.
1836 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001837 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001838 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001839 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001840 SourceLocation RAngleLoc,
1841 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001842 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001843 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001844 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001845 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001846 SourceRange(LAngleLoc, RAngleLoc),
1847 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001848 }
1849
1850 /// \brief Build a new C++ dynamic_cast expression.
1851 ///
1852 /// By default, performs semantic analysis to build the new expression.
1853 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001854 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001855 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001856 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001857 SourceLocation RAngleLoc,
1858 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001859 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001860 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001861 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001862 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001863 SourceRange(LAngleLoc, RAngleLoc),
1864 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001865 }
1866
1867 /// \brief Build a new C++ reinterpret_cast expression.
1868 ///
1869 /// By default, performs semantic analysis to build the new expression.
1870 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001871 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001872 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001873 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001874 SourceLocation RAngleLoc,
1875 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001876 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001877 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001878 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001879 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001880 SourceRange(LAngleLoc, RAngleLoc),
1881 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001882 }
1883
1884 /// \brief Build a new C++ const_cast expression.
1885 ///
1886 /// By default, performs semantic analysis to build the new expression.
1887 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001888 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001889 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001890 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001891 SourceLocation RAngleLoc,
1892 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001893 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001894 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001895 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001896 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001897 SourceRange(LAngleLoc, RAngleLoc),
1898 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001899 }
Mike Stump1eb44332009-09-09 15:08:12 +00001900
Douglas Gregorb98b1992009-08-11 05:31:07 +00001901 /// \brief Build a new C++ functional-style cast expression.
1902 ///
1903 /// By default, performs semantic analysis to build the new expression.
1904 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001905 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1906 SourceLocation LParenLoc,
1907 Expr *Sub,
1908 SourceLocation RParenLoc) {
1909 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001910 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001911 RParenLoc);
1912 }
Mike Stump1eb44332009-09-09 15:08:12 +00001913
Douglas Gregorb98b1992009-08-11 05:31:07 +00001914 /// \brief Build a new C++ typeid(type) expression.
1915 ///
1916 /// By default, performs semantic analysis to build the new expression.
1917 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001918 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001919 SourceLocation TypeidLoc,
1920 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001921 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001922 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001923 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001924 }
Mike Stump1eb44332009-09-09 15:08:12 +00001925
Francois Pichet01b7c302010-09-08 12:20:18 +00001926
Douglas Gregorb98b1992009-08-11 05:31:07 +00001927 /// \brief Build a new C++ typeid(expr) expression.
1928 ///
1929 /// By default, performs semantic analysis to build the new expression.
1930 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001931 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001932 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001933 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001934 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001935 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001936 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001937 }
1938
Francois Pichet01b7c302010-09-08 12:20:18 +00001939 /// \brief Build a new C++ __uuidof(type) expression.
1940 ///
1941 /// By default, performs semantic analysis to build the new expression.
1942 /// Subclasses may override this routine to provide different behavior.
1943 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1944 SourceLocation TypeidLoc,
1945 TypeSourceInfo *Operand,
1946 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001947 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet01b7c302010-09-08 12:20:18 +00001948 RParenLoc);
1949 }
1950
1951 /// \brief Build a new C++ __uuidof(expr) expression.
1952 ///
1953 /// By default, performs semantic analysis to build the new expression.
1954 /// Subclasses may override this routine to provide different behavior.
1955 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1956 SourceLocation TypeidLoc,
1957 Expr *Operand,
1958 SourceLocation RParenLoc) {
1959 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1960 RParenLoc);
1961 }
1962
Douglas Gregorb98b1992009-08-11 05:31:07 +00001963 /// \brief Build a new C++ "this" expression.
1964 ///
1965 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001966 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001967 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001968 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001969 QualType ThisType,
1970 bool isImplicit) {
Eli Friedmanb69b42c2012-01-11 02:36:31 +00001971 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001972 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001973 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1974 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001975 }
1976
1977 /// \brief Build a new C++ throw expression.
1978 ///
1979 /// By default, performs semantic analysis to build the new expression.
1980 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00001981 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1982 bool IsThrownVariableInScope) {
1983 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001984 }
1985
1986 /// \brief Build a new C++ default-argument expression.
1987 ///
1988 /// By default, builds a new default-argument expression, which does not
1989 /// require any semantic analysis. Subclasses may override this routine to
1990 /// provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001991 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001992 ParmVarDecl *Param) {
1993 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1994 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001995 }
1996
Richard Smithc3bf52c2013-04-20 22:23:05 +00001997 /// \brief Build a new C++11 default-initialization expression.
1998 ///
1999 /// By default, builds a new default field initialization expression, which
2000 /// does not require any semantic analysis. Subclasses may override this
2001 /// routine to provide different behavior.
2002 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2003 FieldDecl *Field) {
2004 return getSema().Owned(CXXDefaultInitExpr::Create(getSema().Context, Loc,
2005 Field));
2006 }
2007
Douglas Gregorb98b1992009-08-11 05:31:07 +00002008 /// \brief Build a new C++ zero-initialization expression.
2009 ///
2010 /// By default, performs semantic analysis to build the new expression.
2011 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002012 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2013 SourceLocation LParenLoc,
2014 SourceLocation RParenLoc) {
2015 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002016 None, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002017 }
Mike Stump1eb44332009-09-09 15:08:12 +00002018
Douglas Gregorb98b1992009-08-11 05:31:07 +00002019 /// \brief Build a new C++ "new" expression.
2020 ///
2021 /// By default, performs semantic analysis to build the new expression.
2022 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002023 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002024 bool UseGlobal,
2025 SourceLocation PlacementLParen,
2026 MultiExprArg PlacementArgs,
2027 SourceLocation PlacementRParen,
2028 SourceRange TypeIdParens,
2029 QualType AllocatedType,
2030 TypeSourceInfo *AllocatedTypeInfo,
2031 Expr *ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002032 SourceRange DirectInitRange,
2033 Expr *Initializer) {
Mike Stump1eb44332009-09-09 15:08:12 +00002034 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002035 PlacementLParen,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002036 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002037 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00002038 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002039 AllocatedType,
2040 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00002041 ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002042 DirectInitRange,
2043 Initializer);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002044 }
Mike Stump1eb44332009-09-09 15:08:12 +00002045
Douglas Gregorb98b1992009-08-11 05:31:07 +00002046 /// \brief Build a new C++ "delete" expression.
2047 ///
2048 /// By default, performs semantic analysis to build the new expression.
2049 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002050 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002051 bool IsGlobalDelete,
2052 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002053 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002054 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002055 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002056 }
Mike Stump1eb44332009-09-09 15:08:12 +00002057
Douglas Gregorb98b1992009-08-11 05:31:07 +00002058 /// \brief Build a new unary type trait expression.
2059 ///
2060 /// By default, performs semantic analysis to build the new expression.
2061 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002062 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00002063 SourceLocation StartLoc,
2064 TypeSourceInfo *T,
2065 SourceLocation RParenLoc) {
2066 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002067 }
2068
Francois Pichet6ad6f282010-12-07 00:08:36 +00002069 /// \brief Build a new binary type trait expression.
2070 ///
2071 /// By default, performs semantic analysis to build the new expression.
2072 /// Subclasses may override this routine to provide different behavior.
2073 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
2074 SourceLocation StartLoc,
2075 TypeSourceInfo *LhsT,
2076 TypeSourceInfo *RhsT,
2077 SourceLocation RParenLoc) {
2078 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
2079 }
2080
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00002081 /// \brief Build a new type trait expression.
2082 ///
2083 /// By default, performs semantic analysis to build the new expression.
2084 /// Subclasses may override this routine to provide different behavior.
2085 ExprResult RebuildTypeTrait(TypeTrait Trait,
2086 SourceLocation StartLoc,
2087 ArrayRef<TypeSourceInfo *> Args,
2088 SourceLocation RParenLoc) {
2089 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2090 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002091
John Wiegley21ff2e52011-04-28 00:16:57 +00002092 /// \brief Build a new array type trait expression.
2093 ///
2094 /// By default, performs semantic analysis to build the new expression.
2095 /// Subclasses may override this routine to provide different behavior.
2096 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2097 SourceLocation StartLoc,
2098 TypeSourceInfo *TSInfo,
2099 Expr *DimExpr,
2100 SourceLocation RParenLoc) {
2101 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2102 }
2103
John Wiegley55262202011-04-25 06:54:41 +00002104 /// \brief Build a new expression trait expression.
2105 ///
2106 /// By default, performs semantic analysis to build the new expression.
2107 /// Subclasses may override this routine to provide different behavior.
2108 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2109 SourceLocation StartLoc,
2110 Expr *Queried,
2111 SourceLocation RParenLoc) {
2112 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2113 }
2114
Mike Stump1eb44332009-09-09 15:08:12 +00002115 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002116 /// expression.
2117 ///
2118 /// By default, performs semantic analysis to build the new expression.
2119 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002120 ExprResult RebuildDependentScopeDeclRefExpr(
2121 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002122 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002123 const DeclarationNameInfo &NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00002124 const TemplateArgumentListInfo *TemplateArgs,
2125 bool IsAddressOfOperand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002126 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002127 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002128
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002129 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002130 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002131 NameInfo, TemplateArgs);
John McCallf7a1a742009-11-24 19:00:30 +00002132
Richard Smithefeeccf2012-10-21 03:28:35 +00002133 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo,
2134 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002135 }
2136
2137 /// \brief Build a new template-id expression.
2138 ///
2139 /// By default, performs semantic analysis to build the new expression.
2140 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002141 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002142 SourceLocation TemplateKWLoc,
2143 LookupResult &R,
2144 bool RequiresADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002145 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002146 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2147 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002148 }
2149
2150 /// \brief Build a new object-construction expression.
2151 ///
2152 /// By default, performs semantic analysis to build the new expression.
2153 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002154 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002155 SourceLocation Loc,
2156 CXXConstructorDecl *Constructor,
2157 bool IsElidable,
2158 MultiExprArg Args,
2159 bool HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002160 bool ListInitialization,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002161 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002162 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002163 SourceRange ParenRange) {
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00002164 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002165 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002166 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002167 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002168
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002169 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002170 ConvertedArgs,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002171 HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002172 ListInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002173 RequiresZeroInit, ConstructKind,
2174 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002175 }
2176
2177 /// \brief Build a new object-construction expression.
2178 ///
2179 /// By default, performs semantic analysis to build the new expression.
2180 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002181 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2182 SourceLocation LParenLoc,
2183 MultiExprArg Args,
2184 SourceLocation RParenLoc) {
2185 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002186 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002187 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002188 RParenLoc);
2189 }
2190
2191 /// \brief Build a new object-construction expression.
2192 ///
2193 /// By default, performs semantic analysis to build the new expression.
2194 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002195 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2196 SourceLocation LParenLoc,
2197 MultiExprArg Args,
2198 SourceLocation RParenLoc) {
2199 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002200 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002201 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002202 RParenLoc);
2203 }
Mike Stump1eb44332009-09-09 15:08:12 +00002204
Douglas Gregorb98b1992009-08-11 05:31:07 +00002205 /// \brief Build a new member reference expression.
2206 ///
2207 /// By default, performs semantic analysis to build the new expression.
2208 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002209 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002210 QualType BaseType,
2211 bool IsArrow,
2212 SourceLocation OperatorLoc,
2213 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002214 SourceLocation TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00002215 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002216 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002217 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002218 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002219 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002220
John McCall9ae2f072010-08-23 23:25:46 +00002221 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002222 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002223 SS, TemplateKWLoc,
2224 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002225 MemberNameInfo,
2226 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002227 }
2228
John McCall129e2df2009-11-30 22:42:35 +00002229 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002230 ///
2231 /// By default, performs semantic analysis to build the new expression.
2232 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002233 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2234 SourceLocation OperatorLoc,
2235 bool IsArrow,
2236 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002237 SourceLocation TemplateKWLoc,
Richard Smith9138b4e2011-10-26 19:06:56 +00002238 NamedDecl *FirstQualifierInScope,
2239 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002240 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002241 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002242 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002243
John McCall9ae2f072010-08-23 23:25:46 +00002244 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002245 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002246 SS, TemplateKWLoc,
2247 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00002248 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002249 }
Mike Stump1eb44332009-09-09 15:08:12 +00002250
Sebastian Redl2e156222010-09-10 20:55:43 +00002251 /// \brief Build a new noexcept expression.
2252 ///
2253 /// By default, performs semantic analysis to build the new expression.
2254 /// Subclasses may override this routine to provide different behavior.
2255 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2256 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2257 }
2258
Douglas Gregoree8aff02011-01-04 17:33:58 +00002259 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002260 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2261 SourceLocation PackLoc,
Douglas Gregoree8aff02011-01-04 17:33:58 +00002262 SourceLocation RParenLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002263 Optional<unsigned> Length) {
Douglas Gregor089e8932011-10-10 18:59:29 +00002264 if (Length)
Chad Rosier4a9d7952012-08-08 18:46:20 +00002265 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2266 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002267 RParenLoc, *Length);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002268
2269 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2270 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002271 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002272 }
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002273
Patrick Beardeb382ec2012-04-19 00:25:12 +00002274 /// \brief Build a new Objective-C boxed expression.
2275 ///
2276 /// By default, performs semantic analysis to build the new expression.
2277 /// Subclasses may override this routine to provide different behavior.
2278 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2279 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2280 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002281
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002282 /// \brief Build a new Objective-C array literal.
2283 ///
2284 /// By default, performs semantic analysis to build the new expression.
2285 /// Subclasses may override this routine to provide different behavior.
2286 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2287 Expr **Elements, unsigned NumElements) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002288 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002289 MultiExprArg(Elements, NumElements));
2290 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002291
2292 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002293 Expr *Base, Expr *Key,
2294 ObjCMethodDecl *getterMethod,
2295 ObjCMethodDecl *setterMethod) {
2296 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2297 getterMethod, setterMethod);
2298 }
2299
2300 /// \brief Build a new Objective-C dictionary literal.
2301 ///
2302 /// By default, performs semantic analysis to build the new expression.
2303 /// Subclasses may override this routine to provide different behavior.
2304 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2305 ObjCDictionaryElement *Elements,
2306 unsigned NumElements) {
2307 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2308 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002309
James Dennett699c9042012-06-15 07:13:21 +00002310 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregorb98b1992009-08-11 05:31:07 +00002311 ///
2312 /// By default, performs semantic analysis to build the new expression.
2313 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002314 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002315 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002316 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002317 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002318 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002319 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002320
Douglas Gregor92e986e2010-04-22 16:44:27 +00002321 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002322 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002323 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002324 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002325 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002326 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002327 MultiExprArg Args,
2328 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002329 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2330 ReceiverTypeInfo->getType(),
2331 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002332 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002333 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002334 }
2335
2336 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002337 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002338 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002339 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002340 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002341 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002342 MultiExprArg Args,
2343 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002344 return SemaRef.BuildInstanceMessage(Receiver,
2345 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002346 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002347 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002348 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002349 }
2350
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002351 /// \brief Build a new Objective-C ivar reference expression.
2352 ///
2353 /// By default, performs semantic analysis to build the new expression.
2354 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002355 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002356 SourceLocation IvarLoc,
2357 bool IsArrow, bool IsFreeIvar) {
2358 // FIXME: We lose track of the IsFreeIvar bit.
2359 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002360 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002361 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2362 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002363 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002364 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002365 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002366 false);
John Wiegley429bb272011-04-08 18:41:53 +00002367 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002368 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002369
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002370 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002371 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002372
John Wiegley429bb272011-04-08 18:41:53 +00002373 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002374 /*FIXME:*/IvarLoc, IsArrow,
2375 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002376 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002377 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002378 /*TemplateArgs=*/0);
2379 }
Douglas Gregore3303542010-04-26 20:47:02 +00002380
2381 /// \brief Build a new Objective-C property reference expression.
2382 ///
2383 /// By default, performs semantic analysis to build the new expression.
2384 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002385 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002386 ObjCPropertyDecl *Property,
2387 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002388 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002389 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002390 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2391 Sema::LookupMemberName);
2392 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002393 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002394 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002395 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002396 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002397 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002398
Douglas Gregore3303542010-04-26 20:47:02 +00002399 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002400 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002401
John Wiegley429bb272011-04-08 18:41:53 +00002402 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002403 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002404 SS, SourceLocation(),
Douglas Gregore3303542010-04-26 20:47:02 +00002405 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002406 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002407 /*TemplateArgs=*/0);
2408 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002409
John McCall12f78a62010-12-02 01:19:52 +00002410 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002411 ///
2412 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002413 /// Subclasses may override this routine to provide different behavior.
2414 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2415 ObjCMethodDecl *Getter,
2416 ObjCMethodDecl *Setter,
2417 SourceLocation PropertyLoc) {
2418 // Since these expressions can only be value-dependent, we do not
2419 // need to perform semantic analysis again.
2420 return Owned(
2421 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2422 VK_LValue, OK_ObjCProperty,
2423 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002424 }
2425
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002426 /// \brief Build a new Objective-C "isa" expression.
2427 ///
2428 /// By default, performs semantic analysis to build the new expression.
2429 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002430 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002431 SourceLocation OpLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002432 bool IsArrow) {
2433 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002434 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002435 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2436 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002437 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002438 OpLoc,
John McCalld226f652010-08-21 09:40:31 +00002439 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002440 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002441 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002442
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002443 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002444 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002445
John Wiegley429bb272011-04-08 18:41:53 +00002446 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002447 OpLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002448 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002449 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002450 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002451 /*TemplateArgs=*/0);
2452 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002453
Douglas Gregorb98b1992009-08-11 05:31:07 +00002454 /// \brief Build a new shuffle vector expression.
2455 ///
2456 /// By default, performs semantic analysis to build the new expression.
2457 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002458 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002459 MultiExprArg SubExprs,
2460 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002461 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002462 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002463 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2464 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2465 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikie3bc93e32012-12-19 00:45:41 +00002466 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002467
Douglas Gregorb98b1992009-08-11 05:31:07 +00002468 // Build a reference to the __builtin_shufflevector builtin
David Blaikie3bc93e32012-12-19 00:45:41 +00002469 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002470 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2471 SemaRef.Context.BuiltinFnTy,
2472 VK_RValue, BuiltinLoc);
2473 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2474 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
2475 CK_BuiltinFnToFnPtr).take();
Mike Stump1eb44332009-09-09 15:08:12 +00002476
2477 // Build the CallExpr
John Wiegley429bb272011-04-08 18:41:53 +00002478 ExprResult TheCall = SemaRef.Owned(
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002479 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, SubExprs,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002480 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002481 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002482 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002483
Douglas Gregorb98b1992009-08-11 05:31:07 +00002484 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002485 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002486 }
John McCall43fed0d2010-11-12 08:19:04 +00002487
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002488 /// \brief Build a new template argument pack expansion.
2489 ///
2490 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002491 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002492 /// different behavior.
2493 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002494 SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002495 Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002496 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002497 case TemplateArgument::Expression: {
2498 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002499 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2500 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002501 if (Result.isInvalid())
2502 return TemplateArgumentLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002503
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002504 return TemplateArgumentLoc(Result.get(), Result.get());
2505 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002506
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002507 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002508 return TemplateArgumentLoc(TemplateArgument(
2509 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002510 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002511 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002512 Pattern.getTemplateNameLoc(),
2513 EllipsisLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002514
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002515 case TemplateArgument::Null:
2516 case TemplateArgument::Integral:
2517 case TemplateArgument::Declaration:
2518 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002519 case TemplateArgument::TemplateExpansion:
Eli Friedmand7a6b162012-09-26 02:36:12 +00002520 case TemplateArgument::NullPtr:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002521 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002522
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002523 case TemplateArgument::Type:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002524 if (TypeSourceInfo *Expansion
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002525 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002526 EllipsisLoc,
2527 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002528 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2529 Expansion);
2530 break;
2531 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002532
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002533 return TemplateArgumentLoc();
2534 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002535
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002536 /// \brief Build a new expression pack expansion.
2537 ///
2538 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002539 /// for an expression. Subclasses may override this routine to provide
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002540 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002541 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002542 Optional<unsigned> NumExpansions) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002543 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002544 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002545
2546 /// \brief Build a new atomic operation expression.
2547 ///
2548 /// By default, performs semantic analysis to build the new expression.
2549 /// Subclasses may override this routine to provide different behavior.
2550 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2551 MultiExprArg SubExprs,
2552 QualType RetTy,
2553 AtomicExpr::AtomicOp Op,
2554 SourceLocation RParenLoc) {
2555 // Just create the expression; there is not any interesting semantic
2556 // analysis here because we can't actually build an AtomicExpr until
2557 // we are sure it is semantically sound.
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002558 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002559 RParenLoc);
2560 }
2561
John McCall43fed0d2010-11-12 08:19:04 +00002562private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002563 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2564 QualType ObjectType,
2565 NamedDecl *FirstQualifierInScope,
2566 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002567
2568 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2569 QualType ObjectType,
2570 NamedDecl *FirstQualifierInScope,
2571 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002572};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002573
Douglas Gregor43959a92009-08-20 07:17:43 +00002574template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002575StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002576 if (!S)
2577 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002578
Douglas Gregor43959a92009-08-20 07:17:43 +00002579 switch (S->getStmtClass()) {
2580 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002581
Douglas Gregor43959a92009-08-20 07:17:43 +00002582 // Transform individual statement nodes
2583#define STMT(Node, Parent) \
2584 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002585#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002586#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002587#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002588
Douglas Gregor43959a92009-08-20 07:17:43 +00002589 // Transform expressions by calling TransformExpr.
2590#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002591#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002592#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002593#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002594 {
John McCall60d7b3a2010-08-24 06:29:42 +00002595 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002596 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002597 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002598
Richard Smith41956372013-01-14 22:39:08 +00002599 return getSema().ActOnExprStmt(E);
Douglas Gregor43959a92009-08-20 07:17:43 +00002600 }
Mike Stump1eb44332009-09-09 15:08:12 +00002601 }
2602
John McCall3fa5cae2010-10-26 07:05:15 +00002603 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002604}
Mike Stump1eb44332009-09-09 15:08:12 +00002605
2606
Douglas Gregor670444e2009-08-04 22:27:00 +00002607template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002608ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002609 if (!E)
2610 return SemaRef.Owned(E);
2611
2612 switch (E->getStmtClass()) {
2613 case Stmt::NoStmtClass: break;
2614#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002615#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002616#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002617 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002618#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002619 }
2620
John McCall3fa5cae2010-10-26 07:05:15 +00002621 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002622}
2623
2624template<typename Derived>
Richard Smithc83c2302012-12-19 01:39:02 +00002625ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2626 bool CXXDirectInit) {
2627 // Initializers are instantiated like expressions, except that various outer
2628 // layers are stripped.
2629 if (!Init)
2630 return SemaRef.Owned(Init);
2631
2632 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2633 Init = ExprTemp->getSubExpr();
2634
2635 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2636 Init = Binder->getSubExpr();
2637
2638 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2639 Init = ICE->getSubExprAsWritten();
2640
Richard Smith5cf15892012-12-21 08:13:35 +00002641 // If this is not a direct-initializer, we only need to reconstruct
2642 // InitListExprs. Other forms of copy-initialization will be a no-op if
2643 // the initializer is already the right type.
2644 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2645 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2646 return getDerived().TransformExpr(Init);
2647
2648 // Revert value-initialization back to empty parens.
2649 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2650 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002651 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith5cf15892012-12-21 08:13:35 +00002652 Parens.getEnd());
2653 }
2654
2655 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2656 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002657 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith5cf15892012-12-21 08:13:35 +00002658 SourceLocation());
2659
2660 // Revert initialization by constructor back to a parenthesized or braced list
2661 // of expressions. Any other form of initializer can just be reused directly.
2662 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithc83c2302012-12-19 01:39:02 +00002663 return getDerived().TransformExpr(Init);
2664
2665 SmallVector<Expr*, 8> NewArgs;
2666 bool ArgChanged = false;
2667 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2668 /*IsCall*/true, NewArgs, &ArgChanged))
2669 return ExprError();
2670
2671 // If this was list initialization, revert to list form.
2672 if (Construct->isListInitialization())
2673 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2674 Construct->getLocEnd(),
2675 Construct->getType());
2676
Richard Smithc83c2302012-12-19 01:39:02 +00002677 // Build a ParenListExpr to represent anything else.
2678 SourceRange Parens = Construct->getParenRange();
2679 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2680 Parens.getEnd());
2681}
2682
2683template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00002684bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2685 unsigned NumInputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002686 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002687 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002688 bool *ArgChanged) {
2689 for (unsigned I = 0; I != NumInputs; ++I) {
2690 // If requested, drop call arguments that need to be dropped.
2691 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2692 if (ArgChanged)
2693 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002694
Douglas Gregoraa165f82011-01-03 19:04:46 +00002695 break;
2696 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002697
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002698 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2699 Expr *Pattern = Expansion->getPattern();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002700
Chris Lattner686775d2011-07-20 06:58:45 +00002701 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002702 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2703 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002704
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002705 // Determine whether the set of unexpanded parameter packs can and should
2706 // be expanded.
2707 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002708 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00002709 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2710 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002711 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2712 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002713 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002714 Expand, RetainExpansion,
2715 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002716 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002717
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002718 if (!Expand) {
2719 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00002720 // transformation on the pack expansion, producing another pack
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002721 // expansion.
2722 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2723 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2724 if (OutPattern.isInvalid())
2725 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002726
2727 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002728 Expansion->getEllipsisLoc(),
2729 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002730 if (Out.isInvalid())
2731 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002732
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002733 if (ArgChanged)
2734 *ArgChanged = true;
2735 Outputs.push_back(Out.get());
2736 continue;
2737 }
John McCallc8fc90a2011-07-06 07:30:07 +00002738
2739 // Record right away that the argument was changed. This needs
2740 // to happen even if the array expands to nothing.
2741 if (ArgChanged) *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002742
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002743 // The transform has determined that we should perform an elementwise
2744 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002745 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002746 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2747 ExprResult Out = getDerived().TransformExpr(Pattern);
2748 if (Out.isInvalid())
2749 return true;
2750
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002751 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002752 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2753 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002754 if (Out.isInvalid())
2755 return true;
2756 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002757
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002758 Outputs.push_back(Out.get());
2759 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002760
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002761 continue;
2762 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002763
Richard Smithc83c2302012-12-19 01:39:02 +00002764 ExprResult Result =
2765 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
2766 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregoraa165f82011-01-03 19:04:46 +00002767 if (Result.isInvalid())
2768 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002769
Douglas Gregoraa165f82011-01-03 19:04:46 +00002770 if (Result.get() != Inputs[I] && ArgChanged)
2771 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002772
2773 Outputs.push_back(Result.get());
Douglas Gregoraa165f82011-01-03 19:04:46 +00002774 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002775
Douglas Gregoraa165f82011-01-03 19:04:46 +00002776 return false;
2777}
2778
2779template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002780NestedNameSpecifierLoc
2781TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2782 NestedNameSpecifierLoc NNS,
2783 QualType ObjectType,
2784 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002785 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002786 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002787 Qualifier = Qualifier.getPrefix())
2788 Qualifiers.push_back(Qualifier);
2789
2790 CXXScopeSpec SS;
2791 while (!Qualifiers.empty()) {
2792 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2793 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002794
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002795 switch (QNNS->getKind()) {
2796 case NestedNameSpecifier::Identifier:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002797 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002798 *QNNS->getAsIdentifier(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002799 Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002800 Q.getLocalEndLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002801 ObjectType, false, SS,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002802 FirstQualifierInScope, false))
2803 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002804
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002805 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002806
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002807 case NestedNameSpecifier::Namespace: {
2808 NamespaceDecl *NS
2809 = cast_or_null<NamespaceDecl>(
2810 getDerived().TransformDecl(
2811 Q.getLocalBeginLoc(),
2812 QNNS->getAsNamespace()));
2813 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2814 break;
2815 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002816
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002817 case NestedNameSpecifier::NamespaceAlias: {
2818 NamespaceAliasDecl *Alias
2819 = cast_or_null<NamespaceAliasDecl>(
2820 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2821 QNNS->getAsNamespaceAlias()));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002822 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002823 Q.getLocalEndLoc());
2824 break;
2825 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002826
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002827 case NestedNameSpecifier::Global:
2828 // There is no meaningful transformation that one could perform on the
2829 // global scope.
2830 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2831 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002832
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002833 case NestedNameSpecifier::TypeSpecWithTemplate:
2834 case NestedNameSpecifier::TypeSpec: {
2835 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2836 FirstQualifierInScope, SS);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002837
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002838 if (!TL)
2839 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002840
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002841 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith80ad52f2013-01-02 11:42:31 +00002842 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002843 TL.getType()->isEnumeralType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002844 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002845 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002846 if (TL.getType()->isEnumeralType())
2847 SemaRef.Diag(TL.getBeginLoc(),
2848 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002849 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2850 Q.getLocalEndLoc());
2851 break;
2852 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002853 // If the nested-name-specifier is an invalid type def, don't emit an
2854 // error because a previous error should have already been emitted.
David Blaikie39e6ab42013-02-18 22:06:02 +00002855 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
2856 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002857 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieu00c93a12011-05-07 01:36:37 +00002858 << TL.getType() << SS.getRange();
2859 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002860 return NestedNameSpecifierLoc();
2861 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002862 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002863
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002864 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002865 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002866 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002867 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002868
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002869 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002870 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002871 !getDerived().AlwaysRebuild())
2872 return NNS;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002873
2874 // If we can re-use the source-location data from the original
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002875 // nested-name-specifier, do so.
2876 if (SS.location_size() == NNS.getDataLength() &&
2877 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2878 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2879
2880 // Allocate new nested-name-specifier location information.
2881 return SS.getWithLocInContext(SemaRef.Context);
2882}
2883
2884template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002885DeclarationNameInfo
2886TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002887::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002888 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002889 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002890 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002891
2892 switch (Name.getNameKind()) {
2893 case DeclarationName::Identifier:
2894 case DeclarationName::ObjCZeroArgSelector:
2895 case DeclarationName::ObjCOneArgSelector:
2896 case DeclarationName::ObjCMultiArgSelector:
2897 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002898 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002899 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002900 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002901
Douglas Gregor81499bb2009-09-03 22:13:48 +00002902 case DeclarationName::CXXConstructorName:
2903 case DeclarationName::CXXDestructorName:
2904 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002905 TypeSourceInfo *NewTInfo;
2906 CanQualType NewCanTy;
2907 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002908 NewTInfo = getDerived().TransformType(OldTInfo);
2909 if (!NewTInfo)
2910 return DeclarationNameInfo();
2911 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002912 }
2913 else {
2914 NewTInfo = 0;
2915 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002916 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002917 if (NewT.isNull())
2918 return DeclarationNameInfo();
2919 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2920 }
Mike Stump1eb44332009-09-09 15:08:12 +00002921
Abramo Bagnara25777432010-08-11 22:01:17 +00002922 DeclarationName NewName
2923 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2924 NewCanTy);
2925 DeclarationNameInfo NewNameInfo(NameInfo);
2926 NewNameInfo.setName(NewName);
2927 NewNameInfo.setNamedTypeInfo(NewTInfo);
2928 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002929 }
Mike Stump1eb44332009-09-09 15:08:12 +00002930 }
2931
David Blaikieb219cfc2011-09-23 05:06:16 +00002932 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00002933}
2934
2935template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002936TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002937TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2938 TemplateName Name,
2939 SourceLocation NameLoc,
2940 QualType ObjectType,
2941 NamedDecl *FirstQualifierInScope) {
2942 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2943 TemplateDecl *Template = QTN->getTemplateDecl();
2944 assert(Template && "qualified template name must refer to a template");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002945
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002946 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00002947 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002948 Template));
2949 if (!TransTemplate)
2950 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002951
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002952 if (!getDerived().AlwaysRebuild() &&
2953 SS.getScopeRep() == QTN->getQualifier() &&
2954 TransTemplate == Template)
2955 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002956
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002957 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2958 TransTemplate);
2959 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002960
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002961 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2962 if (SS.getScopeRep()) {
2963 // These apply to the scope specifier, not the template.
2964 ObjectType = QualType();
2965 FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002966 }
2967
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002968 if (!getDerived().AlwaysRebuild() &&
2969 SS.getScopeRep() == DTN->getQualifier() &&
2970 ObjectType.isNull())
2971 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002972
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002973 if (DTN->isIdentifier()) {
2974 return getDerived().RebuildTemplateName(SS,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002975 *DTN->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002976 NameLoc,
2977 ObjectType,
2978 FirstQualifierInScope);
2979 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002980
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002981 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2982 ObjectType);
2983 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002984
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002985 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2986 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00002987 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002988 Template));
2989 if (!TransTemplate)
2990 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002991
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002992 if (!getDerived().AlwaysRebuild() &&
2993 TransTemplate == Template)
2994 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002995
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002996 return TemplateName(TransTemplate);
2997 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002998
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002999 if (SubstTemplateTemplateParmPackStorage *SubstPack
3000 = Name.getAsSubstTemplateTemplateParmPack()) {
3001 TemplateTemplateParmDecl *TransParam
3002 = cast_or_null<TemplateTemplateParmDecl>(
3003 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3004 if (!TransParam)
3005 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003006
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003007 if (!getDerived().AlwaysRebuild() &&
3008 TransParam == SubstPack->getParameterPack())
3009 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003010
3011 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003012 SubstPack->getArgumentPack());
3013 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003014
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003015 // These should be getting filtered out before they reach the AST.
3016 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003017}
3018
3019template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00003020void TreeTransform<Derived>::InventTemplateArgumentLoc(
3021 const TemplateArgument &Arg,
3022 TemplateArgumentLoc &Output) {
3023 SourceLocation Loc = getDerived().getBaseLocation();
3024 switch (Arg.getKind()) {
3025 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003026 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00003027 break;
3028
3029 case TemplateArgument::Type:
3030 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00003031 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier4a9d7952012-08-08 18:46:20 +00003032
John McCall833ca992009-10-29 08:12:44 +00003033 break;
3034
Douglas Gregor788cd062009-11-11 01:00:40 +00003035 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003036 case TemplateArgument::TemplateExpansion: {
3037 NestedNameSpecifierLocBuilder Builder;
3038 TemplateName Template = Arg.getAsTemplate();
3039 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3040 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3041 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3042 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003043
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003044 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier4a9d7952012-08-08 18:46:20 +00003045 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003046 Builder.getWithLocInContext(SemaRef.Context),
3047 Loc);
3048 else
Chad Rosier4a9d7952012-08-08 18:46:20 +00003049 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003050 Builder.getWithLocInContext(SemaRef.Context),
3051 Loc, Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003052
Douglas Gregor788cd062009-11-11 01:00:40 +00003053 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003054 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003055
John McCall833ca992009-10-29 08:12:44 +00003056 case TemplateArgument::Expression:
3057 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3058 break;
3059
3060 case TemplateArgument::Declaration:
3061 case TemplateArgument::Integral:
3062 case TemplateArgument::Pack:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003063 case TemplateArgument::NullPtr:
John McCall828bff22009-10-29 18:45:58 +00003064 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00003065 break;
3066 }
3067}
3068
3069template<typename Derived>
3070bool TreeTransform<Derived>::TransformTemplateArgument(
3071 const TemplateArgumentLoc &Input,
3072 TemplateArgumentLoc &Output) {
3073 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00003074 switch (Arg.getKind()) {
3075 case TemplateArgument::Null:
3076 case TemplateArgument::Integral:
Eli Friedman511e3ae2012-09-25 01:02:42 +00003077 case TemplateArgument::Pack:
3078 case TemplateArgument::Declaration:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003079 case TemplateArgument::NullPtr:
3080 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump1eb44332009-09-09 15:08:12 +00003081
Douglas Gregor670444e2009-08-04 22:27:00 +00003082 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00003083 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00003084 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00003085 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00003086
3087 DI = getDerived().TransformType(DI);
3088 if (!DI) return true;
3089
3090 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3091 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003092 }
Mike Stump1eb44332009-09-09 15:08:12 +00003093
Douglas Gregor788cd062009-11-11 01:00:40 +00003094 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003095 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3096 if (QualifierLoc) {
3097 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3098 if (!QualifierLoc)
3099 return true;
3100 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003101
Douglas Gregor1d752d72011-03-02 18:46:51 +00003102 CXXScopeSpec SS;
3103 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00003104 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00003105 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3106 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00003107 if (Template.isNull())
3108 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003109
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003110 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00003111 Input.getTemplateNameLoc());
3112 return false;
3113 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003114
3115 case TemplateArgument::TemplateExpansion:
3116 llvm_unreachable("Caller should expand pack expansions");
3117
Douglas Gregor670444e2009-08-04 22:27:00 +00003118 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00003119 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00003120 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003121 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003122
John McCall833ca992009-10-29 08:12:44 +00003123 Expr *InputExpr = Input.getSourceExpression();
3124 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3125
Chris Lattner223de242011-04-25 20:37:58 +00003126 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003127 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00003128 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00003129 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00003130 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003131 }
Douglas Gregor670444e2009-08-04 22:27:00 +00003132 }
Mike Stump1eb44332009-09-09 15:08:12 +00003133
Douglas Gregor670444e2009-08-04 22:27:00 +00003134 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003135 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003136}
3137
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003138/// \brief Iterator adaptor that invents template argument location information
3139/// for each of the template arguments in its underlying iterator.
3140template<typename Derived, typename InputIterator>
3141class TemplateArgumentLocInventIterator {
3142 TreeTransform<Derived> &Self;
3143 InputIterator Iter;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003144
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003145public:
3146 typedef TemplateArgumentLoc value_type;
3147 typedef TemplateArgumentLoc reference;
3148 typedef typename std::iterator_traits<InputIterator>::difference_type
3149 difference_type;
3150 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003151
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003152 class pointer {
3153 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003154
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003155 public:
3156 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003157
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003158 const TemplateArgumentLoc *operator->() const { return &Arg; }
3159 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00003160
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003161 TemplateArgumentLocInventIterator() { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003162
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003163 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3164 InputIterator Iter)
3165 : Self(Self), Iter(Iter) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003166
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003167 TemplateArgumentLocInventIterator &operator++() {
3168 ++Iter;
3169 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003170 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003171
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003172 TemplateArgumentLocInventIterator operator++(int) {
3173 TemplateArgumentLocInventIterator Old(*this);
3174 ++(*this);
3175 return Old;
3176 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003177
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003178 reference operator*() const {
3179 TemplateArgumentLoc Result;
3180 Self.InventTemplateArgumentLoc(*Iter, Result);
3181 return Result;
3182 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003183
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003184 pointer operator->() const { return pointer(**this); }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003185
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003186 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3187 const TemplateArgumentLocInventIterator &Y) {
3188 return X.Iter == Y.Iter;
3189 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003190
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003191 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3192 const TemplateArgumentLocInventIterator &Y) {
3193 return X.Iter != Y.Iter;
3194 }
3195};
Chad Rosier4a9d7952012-08-08 18:46:20 +00003196
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003197template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003198template<typename InputIterator>
3199bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3200 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003201 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003202 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003203 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003204 TemplateArgumentLoc In = *First;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003205
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003206 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3207 // Unpack argument packs, which we translate them into separate
3208 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003209 // FIXME: We could do much better if we could guarantee that the
3210 // TemplateArgumentLocInfo for the pack expansion would be usable for
3211 // all of the template arguments in the argument pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003212 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003213 TemplateArgument::pack_iterator>
3214 PackLocIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003215 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003216 In.getArgument().pack_begin()),
3217 PackLocIterator(*this,
3218 In.getArgument().pack_end()),
3219 Outputs))
3220 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003221
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003222 continue;
3223 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003224
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003225 if (In.getArgument().isPackExpansion()) {
3226 // We have a pack expansion, for which we will be substituting into
3227 // the pattern.
3228 SourceLocation Ellipsis;
David Blaikiedc84cd52013-02-20 22:23:23 +00003229 Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003230 TemplateArgumentLoc Pattern
Chad Rosier4a9d7952012-08-08 18:46:20 +00003231 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
Douglas Gregorcded4f62011-01-14 17:04:44 +00003232 getSema().Context);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003233
Chris Lattner686775d2011-07-20 06:58:45 +00003234 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003235 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3236 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003237
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003238 // Determine whether the set of unexpanded parameter packs can and should
3239 // be expanded.
3240 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003241 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00003242 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003243 if (getDerived().TryExpandParameterPacks(Ellipsis,
3244 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003245 Unexpanded,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003246 Expand,
Douglas Gregord3731192011-01-10 07:32:04 +00003247 RetainExpansion,
3248 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003249 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003250
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003251 if (!Expand) {
3252 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00003253 // transformation on the pack expansion, producing another pack
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003254 // expansion.
3255 TemplateArgumentLoc OutPattern;
3256 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3257 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3258 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003259
Douglas Gregorcded4f62011-01-14 17:04:44 +00003260 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3261 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003262 if (Out.getArgument().isNull())
3263 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003264
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003265 Outputs.addArgument(Out);
3266 continue;
3267 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003268
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003269 // The transform has determined that we should perform an elementwise
3270 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003271 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003272 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3273
3274 if (getDerived().TransformTemplateArgument(Pattern, Out))
3275 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003276
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003277 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003278 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3279 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003280 if (Out.getArgument().isNull())
3281 return true;
3282 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003283
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003284 Outputs.addArgument(Out);
3285 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003286
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003287 // If we're supposed to retain a pack expansion, do so by temporarily
3288 // forgetting the partially-substituted parameter pack.
3289 if (RetainExpansion) {
3290 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003291
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003292 if (getDerived().TransformTemplateArgument(Pattern, Out))
3293 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003294
Douglas Gregorcded4f62011-01-14 17:04:44 +00003295 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3296 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003297 if (Out.getArgument().isNull())
3298 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003299
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003300 Outputs.addArgument(Out);
3301 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003302
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003303 continue;
3304 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003305
3306 // The simple case:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003307 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003308 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003309
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003310 Outputs.addArgument(Out);
3311 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003312
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003313 return false;
3314
3315}
3316
Douglas Gregor577f75a2009-08-04 16:50:30 +00003317//===----------------------------------------------------------------------===//
3318// Type transformation
3319//===----------------------------------------------------------------------===//
3320
3321template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003322QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003323 if (getDerived().AlreadyTransformed(T))
3324 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003325
John McCalla2becad2009-10-21 00:40:46 +00003326 // Temporary workaround. All of these transformations should
3327 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003328 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3329 getDerived().getBaseLocation());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003330
John McCall43fed0d2010-11-12 08:19:04 +00003331 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003332
John McCalla2becad2009-10-21 00:40:46 +00003333 if (!NewDI)
3334 return QualType();
3335
3336 return NewDI->getType();
3337}
3338
3339template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003340TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003341 // Refine the base location to the type's location.
3342 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3343 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003344 if (getDerived().AlreadyTransformed(DI->getType()))
3345 return DI;
3346
3347 TypeLocBuilder TLB;
3348
3349 TypeLoc TL = DI->getTypeLoc();
3350 TLB.reserve(TL.getFullDataSize());
3351
John McCall43fed0d2010-11-12 08:19:04 +00003352 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003353 if (Result.isNull())
3354 return 0;
3355
John McCalla93c9342009-12-07 02:54:59 +00003356 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003357}
3358
3359template<typename Derived>
3360QualType
John McCall43fed0d2010-11-12 08:19:04 +00003361TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003362 switch (T.getTypeLocClass()) {
3363#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie39e6ab42013-02-18 22:06:02 +00003364#define TYPELOC(CLASS, PARENT) \
3365 case TypeLoc::CLASS: \
3366 return getDerived().Transform##CLASS##Type(TLB, \
3367 T.castAs<CLASS##TypeLoc>());
John McCalla2becad2009-10-21 00:40:46 +00003368#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003369 }
Mike Stump1eb44332009-09-09 15:08:12 +00003370
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003371 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003372}
3373
3374/// FIXME: By default, this routine adds type qualifiers only to types
3375/// that can have qualifiers, and silently suppresses those qualifiers
3376/// that are not permitted (e.g., qualifiers on reference or function
3377/// types). This is the right thing for template instantiation, but
3378/// probably not for other clients.
3379template<typename Derived>
3380QualType
3381TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003382 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003383 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003384
John McCall43fed0d2010-11-12 08:19:04 +00003385 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003386 if (Result.isNull())
3387 return QualType();
3388
3389 // Silently suppress qualifiers if the result type can't be qualified.
3390 // FIXME: this is the right thing for template instantiation, but
3391 // probably not for other clients.
3392 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003393 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003394
John McCallf85e1932011-06-15 23:02:42 +00003395 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003396 // resulting type.
3397 if (Quals.hasObjCLifetime()) {
3398 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3399 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003400 else if (Result.getObjCLifetime()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003401 // Objective-C ARC:
Douglas Gregore559ca12011-06-17 22:11:49 +00003402 // A lifetime qualifier applied to a substituted template parameter
3403 // overrides the lifetime qualifier from the template argument.
Douglas Gregor92d13872013-01-17 23:59:28 +00003404 const AutoType *AutoTy;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003405 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore559ca12011-06-17 22:11:49 +00003406 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3407 QualType Replacement = SubstTypeParam->getReplacementType();
3408 Qualifiers Qs = Replacement.getQualifiers();
3409 Qs.removeObjCLifetime();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003410 Replacement
Douglas Gregore559ca12011-06-17 22:11:49 +00003411 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3412 Qs);
3413 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier4a9d7952012-08-08 18:46:20 +00003414 SubstTypeParam->getReplacedParameter(),
Douglas Gregore559ca12011-06-17 22:11:49 +00003415 Replacement);
3416 TLB.TypeWasModifiedSafely(Result);
Douglas Gregor92d13872013-01-17 23:59:28 +00003417 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3418 // 'auto' types behave the same way as template parameters.
3419 QualType Deduced = AutoTy->getDeducedType();
3420 Qualifiers Qs = Deduced.getQualifiers();
3421 Qs.removeObjCLifetime();
3422 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3423 Qs);
Richard Smitha2c36462013-04-26 16:15:35 +00003424 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto());
Douglas Gregor92d13872013-01-17 23:59:28 +00003425 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore559ca12011-06-17 22:11:49 +00003426 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003427 // Otherwise, complain about the addition of a qualifier to an
3428 // already-qualified type.
3429 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003430 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003431 << Result << R;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003432
Douglas Gregore559ca12011-06-17 22:11:49 +00003433 Quals.removeObjCLifetime();
3434 }
3435 }
3436 }
John McCall28654742010-06-05 06:41:15 +00003437 if (!Quals.empty()) {
3438 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smith9807a2e2013-03-27 23:36:39 +00003439 // BuildQualifiedType might not add qualifiers if they are invalid.
3440 if (Result.hasLocalQualifiers())
3441 TLB.push<QualifiedTypeLoc>(Result);
John McCall28654742010-06-05 06:41:15 +00003442 // No location information to preserve.
3443 }
John McCalla2becad2009-10-21 00:40:46 +00003444
3445 return Result;
3446}
3447
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003448template<typename Derived>
3449TypeLoc
3450TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3451 QualType ObjectType,
3452 NamedDecl *UnqualLookup,
3453 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003454 QualType T = TL.getType();
3455 if (getDerived().AlreadyTransformed(T))
3456 return TL;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003457
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003458 TypeLocBuilder TLB;
3459 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003460
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003461 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003462 TemplateSpecializationTypeLoc SpecTL =
3463 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003464
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003465 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003466 getDerived().TransformTemplateName(SS,
3467 SpecTL.getTypePtr()->getTemplateName(),
3468 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003469 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003470 if (Template.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003471 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003472
3473 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003474 Template);
3475 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003476 DependentTemplateSpecializationTypeLoc SpecTL =
3477 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003478
Douglas Gregora88f09f2011-02-28 17:23:35 +00003479 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003480 = getDerived().RebuildTemplateName(SS,
3481 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003482 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003483 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003484 if (Template.isNull())
3485 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003486
3487 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003488 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003489 Template,
3490 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003491 } else {
3492 // Nothing special needs to be done for these.
3493 Result = getDerived().TransformType(TLB, TL);
3494 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003495
3496 if (Result.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003497 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003498
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003499 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3500}
3501
Douglas Gregorb71d8212011-03-02 18:32:08 +00003502template<typename Derived>
3503TypeSourceInfo *
3504TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3505 QualType ObjectType,
3506 NamedDecl *UnqualLookup,
3507 CXXScopeSpec &SS) {
3508 // FIXME: Painfully copy-paste from the above!
Chad Rosier4a9d7952012-08-08 18:46:20 +00003509
Douglas Gregorb71d8212011-03-02 18:32:08 +00003510 QualType T = TSInfo->getType();
3511 if (getDerived().AlreadyTransformed(T))
3512 return TSInfo;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003513
Douglas Gregorb71d8212011-03-02 18:32:08 +00003514 TypeLocBuilder TLB;
3515 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003516
Douglas Gregorb71d8212011-03-02 18:32:08 +00003517 TypeLoc TL = TSInfo->getTypeLoc();
3518 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003519 TemplateSpecializationTypeLoc SpecTL =
3520 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003521
Douglas Gregorb71d8212011-03-02 18:32:08 +00003522 TemplateName Template
3523 = getDerived().TransformTemplateName(SS,
3524 SpecTL.getTypePtr()->getTemplateName(),
3525 SpecTL.getTemplateNameLoc(),
3526 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003527 if (Template.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003528 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003529
3530 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003531 Template);
3532 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003533 DependentTemplateSpecializationTypeLoc SpecTL =
3534 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003535
Douglas Gregorb71d8212011-03-02 18:32:08 +00003536 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003537 = getDerived().RebuildTemplateName(SS,
3538 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003539 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003540 ObjectType, UnqualLookup);
3541 if (Template.isNull())
3542 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003543
3544 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003545 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003546 Template,
3547 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003548 } else {
3549 // Nothing special needs to be done for these.
3550 Result = getDerived().TransformType(TLB, TL);
3551 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003552
3553 if (Result.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003554 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003555
Douglas Gregorb71d8212011-03-02 18:32:08 +00003556 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3557}
3558
John McCalla2becad2009-10-21 00:40:46 +00003559template <class TyLoc> static inline
3560QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3561 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3562 NewT.setNameLoc(T.getNameLoc());
3563 return T.getType();
3564}
3565
John McCalla2becad2009-10-21 00:40:46 +00003566template<typename Derived>
3567QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003568 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003569 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3570 NewT.setBuiltinLoc(T.getBuiltinLoc());
3571 if (T.needsExtraLocalData())
3572 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3573 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003574}
Mike Stump1eb44332009-09-09 15:08:12 +00003575
Douglas Gregor577f75a2009-08-04 16:50:30 +00003576template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003577QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003578 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003579 // FIXME: recurse?
3580 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003581}
Mike Stump1eb44332009-09-09 15:08:12 +00003582
Douglas Gregor577f75a2009-08-04 16:50:30 +00003583template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003584QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003585 PointerTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003586 QualType PointeeType
3587 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003588 if (PointeeType.isNull())
3589 return QualType();
3590
3591 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003592 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003593 // A dependent pointer type 'T *' has is being transformed such
3594 // that an Objective-C class type is being replaced for 'T'. The
3595 // resulting pointer type is an ObjCObjectPointerType, not a
3596 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003597 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003598
John McCallc12c5bb2010-05-15 11:32:37 +00003599 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3600 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003601 return Result;
3602 }
John McCall43fed0d2010-11-12 08:19:04 +00003603
Douglas Gregor92e986e2010-04-22 16:44:27 +00003604 if (getDerived().AlwaysRebuild() ||
3605 PointeeType != TL.getPointeeLoc().getType()) {
3606 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3607 if (Result.isNull())
3608 return QualType();
3609 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003610
John McCallf85e1932011-06-15 23:02:42 +00003611 // Objective-C ARC can add lifetime qualifiers to the type that we're
3612 // pointing to.
3613 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003614
Douglas Gregor92e986e2010-04-22 16:44:27 +00003615 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3616 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003617 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003618}
Mike Stump1eb44332009-09-09 15:08:12 +00003619
3620template<typename Derived>
3621QualType
John McCalla2becad2009-10-21 00:40:46 +00003622TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003623 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003624 QualType PointeeType
Chad Rosier4a9d7952012-08-08 18:46:20 +00003625 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3626 if (PointeeType.isNull())
3627 return QualType();
3628
3629 QualType Result = TL.getType();
3630 if (getDerived().AlwaysRebuild() ||
3631 PointeeType != TL.getPointeeLoc().getType()) {
3632 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003633 TL.getSigilLoc());
3634 if (Result.isNull())
3635 return QualType();
3636 }
3637
Douglas Gregor39968ad2010-04-22 16:50:51 +00003638 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003639 NewT.setSigilLoc(TL.getSigilLoc());
3640 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003641}
3642
John McCall85737a72009-10-30 00:06:24 +00003643/// Transforms a reference type. Note that somewhat paradoxically we
3644/// don't care whether the type itself is an l-value type or an r-value
3645/// type; we only care if the type was *written* as an l-value type
3646/// or an r-value type.
3647template<typename Derived>
3648QualType
3649TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003650 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003651 const ReferenceType *T = TL.getTypePtr();
3652
3653 // Note that this works with the pointee-as-written.
3654 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3655 if (PointeeType.isNull())
3656 return QualType();
3657
3658 QualType Result = TL.getType();
3659 if (getDerived().AlwaysRebuild() ||
3660 PointeeType != T->getPointeeTypeAsWritten()) {
3661 Result = getDerived().RebuildReferenceType(PointeeType,
3662 T->isSpelledAsLValue(),
3663 TL.getSigilLoc());
3664 if (Result.isNull())
3665 return QualType();
3666 }
3667
John McCallf85e1932011-06-15 23:02:42 +00003668 // Objective-C ARC can add lifetime qualifiers to the type that we're
3669 // referring to.
3670 TLB.TypeWasModifiedSafely(
3671 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3672
John McCall85737a72009-10-30 00:06:24 +00003673 // r-value references can be rebuilt as l-value references.
3674 ReferenceTypeLoc NewTL;
3675 if (isa<LValueReferenceType>(Result))
3676 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3677 else
3678 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3679 NewTL.setSigilLoc(TL.getSigilLoc());
3680
3681 return Result;
3682}
3683
Mike Stump1eb44332009-09-09 15:08:12 +00003684template<typename Derived>
3685QualType
John McCalla2becad2009-10-21 00:40:46 +00003686TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003687 LValueReferenceTypeLoc TL) {
3688 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003689}
3690
Mike Stump1eb44332009-09-09 15:08:12 +00003691template<typename Derived>
3692QualType
John McCalla2becad2009-10-21 00:40:46 +00003693TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003694 RValueReferenceTypeLoc TL) {
3695 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003696}
Mike Stump1eb44332009-09-09 15:08:12 +00003697
Douglas Gregor577f75a2009-08-04 16:50:30 +00003698template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003699QualType
John McCalla2becad2009-10-21 00:40:46 +00003700TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003701 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003702 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003703 if (PointeeType.isNull())
3704 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003705
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003706 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3707 TypeSourceInfo* NewClsTInfo = 0;
3708 if (OldClsTInfo) {
3709 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3710 if (!NewClsTInfo)
3711 return QualType();
3712 }
3713
3714 const MemberPointerType *T = TL.getTypePtr();
3715 QualType OldClsType = QualType(T->getClass(), 0);
3716 QualType NewClsType;
3717 if (NewClsTInfo)
3718 NewClsType = NewClsTInfo->getType();
3719 else {
3720 NewClsType = getDerived().TransformType(OldClsType);
3721 if (NewClsType.isNull())
3722 return QualType();
3723 }
Mike Stump1eb44332009-09-09 15:08:12 +00003724
John McCalla2becad2009-10-21 00:40:46 +00003725 QualType Result = TL.getType();
3726 if (getDerived().AlwaysRebuild() ||
3727 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003728 NewClsType != OldClsType) {
3729 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003730 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003731 if (Result.isNull())
3732 return QualType();
3733 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003734
John McCalla2becad2009-10-21 00:40:46 +00003735 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3736 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003737 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003738
3739 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003740}
3741
Mike Stump1eb44332009-09-09 15:08:12 +00003742template<typename Derived>
3743QualType
John McCalla2becad2009-10-21 00:40:46 +00003744TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003745 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003746 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003747 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003748 if (ElementType.isNull())
3749 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003750
John McCalla2becad2009-10-21 00:40:46 +00003751 QualType Result = TL.getType();
3752 if (getDerived().AlwaysRebuild() ||
3753 ElementType != T->getElementType()) {
3754 Result = getDerived().RebuildConstantArrayType(ElementType,
3755 T->getSizeModifier(),
3756 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003757 T->getIndexTypeCVRQualifiers(),
3758 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003759 if (Result.isNull())
3760 return QualType();
3761 }
Eli Friedman457a3772012-01-25 22:19:07 +00003762
3763 // We might have either a ConstantArrayType or a VariableArrayType now:
3764 // a ConstantArrayType is allowed to have an element type which is a
3765 // VariableArrayType if the type is dependent. Fortunately, all array
3766 // types have the same location layout.
3767 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003768 NewTL.setLBracketLoc(TL.getLBracketLoc());
3769 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003770
John McCalla2becad2009-10-21 00:40:46 +00003771 Expr *Size = TL.getSizeExpr();
3772 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003773 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3774 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003775 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003776 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003777 }
3778 NewTL.setSizeExpr(Size);
3779
3780 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003781}
Mike Stump1eb44332009-09-09 15:08:12 +00003782
Douglas Gregor577f75a2009-08-04 16:50:30 +00003783template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003784QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003785 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003786 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003787 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003788 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003789 if (ElementType.isNull())
3790 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003791
John McCalla2becad2009-10-21 00:40:46 +00003792 QualType Result = TL.getType();
3793 if (getDerived().AlwaysRebuild() ||
3794 ElementType != T->getElementType()) {
3795 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003796 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003797 T->getIndexTypeCVRQualifiers(),
3798 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003799 if (Result.isNull())
3800 return QualType();
3801 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003802
John McCalla2becad2009-10-21 00:40:46 +00003803 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3804 NewTL.setLBracketLoc(TL.getLBracketLoc());
3805 NewTL.setRBracketLoc(TL.getRBracketLoc());
3806 NewTL.setSizeExpr(0);
3807
3808 return Result;
3809}
3810
3811template<typename Derived>
3812QualType
3813TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003814 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003815 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003816 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3817 if (ElementType.isNull())
3818 return QualType();
3819
John McCall60d7b3a2010-08-24 06:29:42 +00003820 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003821 = getDerived().TransformExpr(T->getSizeExpr());
3822 if (SizeResult.isInvalid())
3823 return QualType();
3824
John McCall9ae2f072010-08-23 23:25:46 +00003825 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003826
3827 QualType Result = TL.getType();
3828 if (getDerived().AlwaysRebuild() ||
3829 ElementType != T->getElementType() ||
3830 Size != T->getSizeExpr()) {
3831 Result = getDerived().RebuildVariableArrayType(ElementType,
3832 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003833 Size,
John McCalla2becad2009-10-21 00:40:46 +00003834 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003835 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003836 if (Result.isNull())
3837 return QualType();
3838 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003839
John McCalla2becad2009-10-21 00:40:46 +00003840 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3841 NewTL.setLBracketLoc(TL.getLBracketLoc());
3842 NewTL.setRBracketLoc(TL.getRBracketLoc());
3843 NewTL.setSizeExpr(Size);
3844
3845 return Result;
3846}
3847
3848template<typename Derived>
3849QualType
3850TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003851 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003852 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003853 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3854 if (ElementType.isNull())
3855 return QualType();
3856
Richard Smithf6702a32011-12-20 02:08:33 +00003857 // Array bounds are constant expressions.
3858 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3859 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003860
John McCall3b657512011-01-19 10:06:00 +00003861 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3862 Expr *origSize = TL.getSizeExpr();
3863 if (!origSize) origSize = T->getSizeExpr();
3864
3865 ExprResult sizeResult
3866 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003867 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003868 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003869 return QualType();
3870
John McCall3b657512011-01-19 10:06:00 +00003871 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003872
3873 QualType Result = TL.getType();
3874 if (getDerived().AlwaysRebuild() ||
3875 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003876 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003877 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3878 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003879 size,
John McCalla2becad2009-10-21 00:40:46 +00003880 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003881 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003882 if (Result.isNull())
3883 return QualType();
3884 }
John McCalla2becad2009-10-21 00:40:46 +00003885
3886 // We might have any sort of array type now, but fortunately they
3887 // all have the same location layout.
3888 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3889 NewTL.setLBracketLoc(TL.getLBracketLoc());
3890 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003891 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003892
3893 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003894}
Mike Stump1eb44332009-09-09 15:08:12 +00003895
3896template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003897QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003898 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003899 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003900 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003901
3902 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003903 QualType ElementType = getDerived().TransformType(T->getElementType());
3904 if (ElementType.isNull())
3905 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003906
Richard Smithf6702a32011-12-20 02:08:33 +00003907 // Vector sizes are constant expressions.
3908 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3909 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003910
John McCall60d7b3a2010-08-24 06:29:42 +00003911 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00003912 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003913 if (Size.isInvalid())
3914 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003915
John McCalla2becad2009-10-21 00:40:46 +00003916 QualType Result = TL.getType();
3917 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003918 ElementType != T->getElementType() ||
3919 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003920 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003921 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003922 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003923 if (Result.isNull())
3924 return QualType();
3925 }
John McCalla2becad2009-10-21 00:40:46 +00003926
3927 // Result might be dependent or not.
3928 if (isa<DependentSizedExtVectorType>(Result)) {
3929 DependentSizedExtVectorTypeLoc NewTL
3930 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3931 NewTL.setNameLoc(TL.getNameLoc());
3932 } else {
3933 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3934 NewTL.setNameLoc(TL.getNameLoc());
3935 }
3936
3937 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003938}
Mike Stump1eb44332009-09-09 15:08:12 +00003939
3940template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003941QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003942 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003943 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003944 QualType ElementType = getDerived().TransformType(T->getElementType());
3945 if (ElementType.isNull())
3946 return QualType();
3947
John McCalla2becad2009-10-21 00:40:46 +00003948 QualType Result = TL.getType();
3949 if (getDerived().AlwaysRebuild() ||
3950 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003951 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003952 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003953 if (Result.isNull())
3954 return QualType();
3955 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003956
John McCalla2becad2009-10-21 00:40:46 +00003957 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3958 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003959
John McCalla2becad2009-10-21 00:40:46 +00003960 return Result;
3961}
3962
3963template<typename Derived>
3964QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003965 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003966 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003967 QualType ElementType = getDerived().TransformType(T->getElementType());
3968 if (ElementType.isNull())
3969 return QualType();
3970
3971 QualType Result = TL.getType();
3972 if (getDerived().AlwaysRebuild() ||
3973 ElementType != T->getElementType()) {
3974 Result = getDerived().RebuildExtVectorType(ElementType,
3975 T->getNumElements(),
3976 /*FIXME*/ SourceLocation());
3977 if (Result.isNull())
3978 return QualType();
3979 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003980
John McCalla2becad2009-10-21 00:40:46 +00003981 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3982 NewTL.setNameLoc(TL.getNameLoc());
3983
3984 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003985}
Mike Stump1eb44332009-09-09 15:08:12 +00003986
David Blaikiedc84cd52013-02-20 22:23:23 +00003987template <typename Derived>
3988ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
3989 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
3990 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00003991 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003992 TypeSourceInfo *NewDI = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003993
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003994 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003995 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003996 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003997 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00003998 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003999
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004000 TypeLocBuilder TLB;
4001 TypeLoc NewTL = OldDI->getTypeLoc();
4002 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004003
4004 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004005 OldExpansionTL.getPatternLoc());
4006 if (Result.isNull())
4007 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004008
4009 Result = RebuildPackExpansionType(Result,
4010 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004011 OldExpansionTL.getEllipsisLoc(),
4012 NumExpansions);
4013 if (Result.isNull())
4014 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004015
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004016 PackExpansionTypeLoc NewExpansionTL
4017 = TLB.push<PackExpansionTypeLoc>(Result);
4018 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4019 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4020 } else
4021 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00004022 if (!NewDI)
4023 return 0;
4024
John McCallfb44de92011-05-01 22:35:37 +00004025 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00004026 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00004027
4028 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4029 OldParm->getDeclContext(),
4030 OldParm->getInnerLocStart(),
4031 OldParm->getLocation(),
4032 OldParm->getIdentifier(),
4033 NewDI->getType(),
4034 NewDI,
4035 OldParm->getStorageClass(),
John McCallfb44de92011-05-01 22:35:37 +00004036 /* DefArg */ NULL);
4037 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4038 OldParm->getFunctionScopeIndex() + indexAdjustment);
4039 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00004040}
4041
4042template<typename Derived>
4043bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00004044 TransformFunctionTypeParams(SourceLocation Loc,
4045 ParmVarDecl **Params, unsigned NumParams,
4046 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00004047 SmallVectorImpl<QualType> &OutParamTypes,
4048 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00004049 int indexAdjustment = 0;
4050
Douglas Gregora009b592011-01-07 00:20:55 +00004051 for (unsigned i = 0; i != NumParams; ++i) {
4052 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00004053 assert(OldParm->getFunctionScopeIndex() == i);
4054
David Blaikiedc84cd52013-02-20 22:23:23 +00004055 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004056 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004057 if (OldParm->isParameterPack()) {
4058 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00004059 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00004060
Douglas Gregor603cfb42011-01-05 23:12:31 +00004061 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004062 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00004063 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004064 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4065 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004066 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4067
Douglas Gregor603cfb42011-01-05 23:12:31 +00004068 // Determine whether we should expand the parameter packs.
4069 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004070 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004071 Optional<unsigned> OrigNumExpansions =
4072 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004073 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004074 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4075 Pattern.getSourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004076 Unexpanded,
4077 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004078 RetainExpansion,
4079 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004080 return true;
4081 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004082
Douglas Gregor603cfb42011-01-05 23:12:31 +00004083 if (ShouldExpand) {
4084 // Expand the function parameter pack into multiple, separate
4085 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00004086 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00004087 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004088 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004089 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004090 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004091 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004092 OrigNumExpansions,
4093 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004094 if (!NewParm)
4095 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004096
Douglas Gregora009b592011-01-07 00:20:55 +00004097 OutParamTypes.push_back(NewParm->getType());
4098 if (PVars)
4099 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004100 }
Douglas Gregord3731192011-01-10 07:32:04 +00004101
4102 // If we're supposed to retain a pack expansion, do so by temporarily
4103 // forgetting the partially-substituted parameter pack.
4104 if (RetainExpansion) {
4105 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004106 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004107 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004108 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004109 OrigNumExpansions,
4110 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00004111 if (!NewParm)
4112 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004113
Douglas Gregord3731192011-01-10 07:32:04 +00004114 OutParamTypes.push_back(NewParm->getType());
4115 if (PVars)
4116 PVars->push_back(NewParm);
4117 }
4118
John McCallfb44de92011-05-01 22:35:37 +00004119 // The next parameter should have the same adjustment as the
4120 // last thing we pushed, but we post-incremented indexAdjustment
4121 // on every push. Also, if we push nothing, the adjustment should
4122 // go down by one.
4123 indexAdjustment--;
4124
Douglas Gregor603cfb42011-01-05 23:12:31 +00004125 // We're done with the pack expansion.
4126 continue;
4127 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004128
4129 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004130 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004131 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4132 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004133 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004134 NumExpansions,
4135 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004136 } else {
David Blaikiedc84cd52013-02-20 22:23:23 +00004137 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie66874fb2013-02-21 01:47:18 +00004138 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004139 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004140
John McCall21ef0fa2010-03-11 09:03:00 +00004141 if (!NewParm)
4142 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004143
Douglas Gregora009b592011-01-07 00:20:55 +00004144 OutParamTypes.push_back(NewParm->getType());
4145 if (PVars)
4146 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004147 continue;
4148 }
John McCall21ef0fa2010-03-11 09:03:00 +00004149
4150 // Deal with the possibility that we don't have a parameter
4151 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004152 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004153 bool IsPackExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004154 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004155 QualType NewType;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004156 if (const PackExpansionType *Expansion
Douglas Gregor603cfb42011-01-05 23:12:31 +00004157 = dyn_cast<PackExpansionType>(OldType)) {
4158 // We have a function parameter pack that may need to be expanded.
4159 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004160 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004161 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004162
Douglas Gregor603cfb42011-01-05 23:12:31 +00004163 // Determine whether we should expand the parameter packs.
4164 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004165 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004166 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004167 Unexpanded,
4168 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004169 RetainExpansion,
4170 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004171 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004172 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004173
Douglas Gregor603cfb42011-01-05 23:12:31 +00004174 if (ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004175 // Expand the function parameter pack into multiple, separate
Douglas Gregor603cfb42011-01-05 23:12:31 +00004176 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004177 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004178 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4179 QualType NewType = getDerived().TransformType(Pattern);
4180 if (NewType.isNull())
4181 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004182
Douglas Gregora009b592011-01-07 00:20:55 +00004183 OutParamTypes.push_back(NewType);
4184 if (PVars)
4185 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004186 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004187
Douglas Gregor603cfb42011-01-05 23:12:31 +00004188 // We're done with the pack expansion.
4189 continue;
4190 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004191
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004192 // If we're supposed to retain a pack expansion, do so by temporarily
4193 // forgetting the partially-substituted parameter pack.
4194 if (RetainExpansion) {
4195 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4196 QualType NewType = getDerived().TransformType(Pattern);
4197 if (NewType.isNull())
4198 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004199
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004200 OutParamTypes.push_back(NewType);
4201 if (PVars)
4202 PVars->push_back(0);
4203 }
Douglas Gregord3731192011-01-10 07:32:04 +00004204
Chad Rosier4a9d7952012-08-08 18:46:20 +00004205 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004206 // expansion.
4207 OldType = Expansion->getPattern();
4208 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004209 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4210 NewType = getDerived().TransformType(OldType);
4211 } else {
4212 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004213 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004214
Douglas Gregor603cfb42011-01-05 23:12:31 +00004215 if (NewType.isNull())
4216 return true;
4217
4218 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004219 NewType = getSema().Context.getPackExpansionType(NewType,
4220 NumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004221
Douglas Gregora009b592011-01-07 00:20:55 +00004222 OutParamTypes.push_back(NewType);
4223 if (PVars)
4224 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004225 }
4226
John McCallfb44de92011-05-01 22:35:37 +00004227#ifndef NDEBUG
4228 if (PVars) {
4229 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4230 if (ParmVarDecl *parm = (*PVars)[i])
4231 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004232 }
John McCallfb44de92011-05-01 22:35:37 +00004233#endif
4234
4235 return false;
4236}
John McCall21ef0fa2010-03-11 09:03:00 +00004237
4238template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004239QualType
John McCalla2becad2009-10-21 00:40:46 +00004240TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004241 FunctionProtoTypeLoc TL) {
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004242 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4243}
4244
4245template<typename Derived>
4246QualType
4247TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4248 FunctionProtoTypeLoc TL,
4249 CXXRecordDecl *ThisContext,
4250 unsigned ThisTypeQuals) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004251 // Transform the parameters and return type.
4252 //
Richard Smithe6975e92012-04-17 00:58:00 +00004253 // We are required to instantiate the params and return type in source order.
Douglas Gregordab60ad2010-10-01 18:44:50 +00004254 // When the function has a trailing return type, we instantiate the
4255 // parameters before the return type, since the return type can then refer
4256 // to the parameters themselves (via decltype, sizeof, etc.).
4257 //
Chris Lattner686775d2011-07-20 06:58:45 +00004258 SmallVector<QualType, 4> ParamTypes;
4259 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004260 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004261
Douglas Gregordab60ad2010-10-01 18:44:50 +00004262 QualType ResultType;
4263
Richard Smith9fbf3272012-08-14 22:51:13 +00004264 if (T->hasTrailingReturn()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004265 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004266 TL.getParmArray(),
4267 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004268 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004269 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004270 return QualType();
4271
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004272 {
4273 // C++11 [expr.prim.general]p3:
Chad Rosier4a9d7952012-08-08 18:46:20 +00004274 // If a declaration declares a member function or member function
4275 // template of a class X, the expression this is a prvalue of type
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004276 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier4a9d7952012-08-08 18:46:20 +00004277 // and the end of the function-definition, member-declarator, or
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004278 // declarator.
4279 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004280
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004281 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4282 if (ResultType.isNull())
4283 return QualType();
4284 }
Douglas Gregordab60ad2010-10-01 18:44:50 +00004285 }
4286 else {
4287 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4288 if (ResultType.isNull())
4289 return QualType();
4290
Chad Rosier4a9d7952012-08-08 18:46:20 +00004291 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004292 TL.getParmArray(),
4293 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004294 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004295 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004296 return QualType();
4297 }
4298
Richard Smithe6975e92012-04-17 00:58:00 +00004299 // FIXME: Need to transform the exception-specification too.
4300
John McCalla2becad2009-10-21 00:40:46 +00004301 QualType Result = TL.getType();
4302 if (getDerived().AlwaysRebuild() ||
4303 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004304 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004305 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
Jordan Rosebea522f2013-03-08 21:51:21 +00004306 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00004307 T->getExtProtoInfo());
John McCalla2becad2009-10-21 00:40:46 +00004308 if (Result.isNull())
4309 return QualType();
4310 }
Mike Stump1eb44332009-09-09 15:08:12 +00004311
John McCalla2becad2009-10-21 00:40:46 +00004312 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004313 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004314 NewTL.setLParenLoc(TL.getLParenLoc());
4315 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004316 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004317 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4318 NewTL.setArg(i, ParamDecls[i]);
4319
4320 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004321}
Mike Stump1eb44332009-09-09 15:08:12 +00004322
Douglas Gregor577f75a2009-08-04 16:50:30 +00004323template<typename Derived>
4324QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004325 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004326 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004327 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004328 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4329 if (ResultType.isNull())
4330 return QualType();
4331
4332 QualType Result = TL.getType();
4333 if (getDerived().AlwaysRebuild() ||
4334 ResultType != T->getResultType())
4335 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4336
4337 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004338 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004339 NewTL.setLParenLoc(TL.getLParenLoc());
4340 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004341 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004342
4343 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004344}
Mike Stump1eb44332009-09-09 15:08:12 +00004345
John McCalled976492009-12-04 22:46:56 +00004346template<typename Derived> QualType
4347TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004348 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004349 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004350 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004351 if (!D)
4352 return QualType();
4353
4354 QualType Result = TL.getType();
4355 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4356 Result = getDerived().RebuildUnresolvedUsingType(D);
4357 if (Result.isNull())
4358 return QualType();
4359 }
4360
4361 // We might get an arbitrary type spec type back. We should at
4362 // least always get a type spec type, though.
4363 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4364 NewTL.setNameLoc(TL.getNameLoc());
4365
4366 return Result;
4367}
4368
Douglas Gregor577f75a2009-08-04 16:50:30 +00004369template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004370QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004371 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004372 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004373 TypedefNameDecl *Typedef
4374 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4375 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004376 if (!Typedef)
4377 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004378
John McCalla2becad2009-10-21 00:40:46 +00004379 QualType Result = TL.getType();
4380 if (getDerived().AlwaysRebuild() ||
4381 Typedef != T->getDecl()) {
4382 Result = getDerived().RebuildTypedefType(Typedef);
4383 if (Result.isNull())
4384 return QualType();
4385 }
Mike Stump1eb44332009-09-09 15:08:12 +00004386
John McCalla2becad2009-10-21 00:40:46 +00004387 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4388 NewTL.setNameLoc(TL.getNameLoc());
4389
4390 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004391}
Mike Stump1eb44332009-09-09 15:08:12 +00004392
Douglas Gregor577f75a2009-08-04 16:50:30 +00004393template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004394QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004395 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004396 // typeof expressions are not potentially evaluated contexts
Eli Friedman80bfa3d2012-09-26 04:34:21 +00004397 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4398 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00004399
John McCall60d7b3a2010-08-24 06:29:42 +00004400 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004401 if (E.isInvalid())
4402 return QualType();
4403
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004404 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4405 if (E.isInvalid())
4406 return QualType();
4407
John McCalla2becad2009-10-21 00:40:46 +00004408 QualType Result = TL.getType();
4409 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004410 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004411 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004412 if (Result.isNull())
4413 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004414 }
John McCalla2becad2009-10-21 00:40:46 +00004415 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004416
John McCalla2becad2009-10-21 00:40:46 +00004417 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004418 NewTL.setTypeofLoc(TL.getTypeofLoc());
4419 NewTL.setLParenLoc(TL.getLParenLoc());
4420 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004421
4422 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004423}
Mike Stump1eb44332009-09-09 15:08:12 +00004424
4425template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004426QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004427 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004428 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4429 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4430 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004431 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004432
John McCalla2becad2009-10-21 00:40:46 +00004433 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004434 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4435 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004436 if (Result.isNull())
4437 return QualType();
4438 }
Mike Stump1eb44332009-09-09 15:08:12 +00004439
John McCalla2becad2009-10-21 00:40:46 +00004440 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004441 NewTL.setTypeofLoc(TL.getTypeofLoc());
4442 NewTL.setLParenLoc(TL.getLParenLoc());
4443 NewTL.setRParenLoc(TL.getRParenLoc());
4444 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004445
4446 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004447}
Mike Stump1eb44332009-09-09 15:08:12 +00004448
4449template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004450QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004451 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004452 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004453
Douglas Gregor670444e2009-08-04 22:27:00 +00004454 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004455 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4456 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004457
John McCall60d7b3a2010-08-24 06:29:42 +00004458 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004459 if (E.isInvalid())
4460 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004461
Richard Smith76f3f692012-02-22 02:04:18 +00004462 E = getSema().ActOnDecltypeExpression(E.take());
4463 if (E.isInvalid())
4464 return QualType();
4465
John McCalla2becad2009-10-21 00:40:46 +00004466 QualType Result = TL.getType();
4467 if (getDerived().AlwaysRebuild() ||
4468 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004469 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004470 if (Result.isNull())
4471 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004472 }
John McCalla2becad2009-10-21 00:40:46 +00004473 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004474
John McCalla2becad2009-10-21 00:40:46 +00004475 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4476 NewTL.setNameLoc(TL.getNameLoc());
4477
4478 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004479}
4480
4481template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004482QualType TreeTransform<Derived>::TransformUnaryTransformType(
4483 TypeLocBuilder &TLB,
4484 UnaryTransformTypeLoc TL) {
4485 QualType Result = TL.getType();
4486 if (Result->isDependentType()) {
4487 const UnaryTransformType *T = TL.getTypePtr();
4488 QualType NewBase =
4489 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4490 Result = getDerived().RebuildUnaryTransformType(NewBase,
4491 T->getUTTKind(),
4492 TL.getKWLoc());
4493 if (Result.isNull())
4494 return QualType();
4495 }
4496
4497 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4498 NewTL.setKWLoc(TL.getKWLoc());
4499 NewTL.setParensRange(TL.getParensRange());
4500 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4501 return Result;
4502}
4503
4504template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004505QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4506 AutoTypeLoc TL) {
4507 const AutoType *T = TL.getTypePtr();
4508 QualType OldDeduced = T->getDeducedType();
4509 QualType NewDeduced;
4510 if (!OldDeduced.isNull()) {
4511 NewDeduced = getDerived().TransformType(OldDeduced);
4512 if (NewDeduced.isNull())
4513 return QualType();
4514 }
4515
4516 QualType Result = TL.getType();
Richard Smithdc7a4f52013-04-30 13:56:41 +00004517 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4518 T->isDependentType()) {
Richard Smitha2c36462013-04-26 16:15:35 +00004519 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith34b41d92011-02-20 03:19:35 +00004520 if (Result.isNull())
4521 return QualType();
4522 }
4523
4524 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4525 NewTL.setNameLoc(TL.getNameLoc());
4526
4527 return Result;
4528}
4529
4530template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004531QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004532 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004533 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004534 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004535 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4536 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004537 if (!Record)
4538 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004539
John McCalla2becad2009-10-21 00:40:46 +00004540 QualType Result = TL.getType();
4541 if (getDerived().AlwaysRebuild() ||
4542 Record != T->getDecl()) {
4543 Result = getDerived().RebuildRecordType(Record);
4544 if (Result.isNull())
4545 return QualType();
4546 }
Mike Stump1eb44332009-09-09 15:08:12 +00004547
John McCalla2becad2009-10-21 00:40:46 +00004548 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4549 NewTL.setNameLoc(TL.getNameLoc());
4550
4551 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004552}
Mike Stump1eb44332009-09-09 15:08:12 +00004553
4554template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004555QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004556 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004557 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004558 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004559 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4560 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004561 if (!Enum)
4562 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004563
John McCalla2becad2009-10-21 00:40:46 +00004564 QualType Result = TL.getType();
4565 if (getDerived().AlwaysRebuild() ||
4566 Enum != T->getDecl()) {
4567 Result = getDerived().RebuildEnumType(Enum);
4568 if (Result.isNull())
4569 return QualType();
4570 }
Mike Stump1eb44332009-09-09 15:08:12 +00004571
John McCalla2becad2009-10-21 00:40:46 +00004572 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4573 NewTL.setNameLoc(TL.getNameLoc());
4574
4575 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004576}
John McCall7da24312009-09-05 00:15:47 +00004577
John McCall3cb0ebd2010-03-10 03:28:59 +00004578template<typename Derived>
4579QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4580 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004581 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004582 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4583 TL.getTypePtr()->getDecl());
4584 if (!D) return QualType();
4585
4586 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4587 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4588 return T;
4589}
4590
Douglas Gregor577f75a2009-08-04 16:50:30 +00004591template<typename Derived>
4592QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004593 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004594 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004595 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004596}
4597
Mike Stump1eb44332009-09-09 15:08:12 +00004598template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004599QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004600 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004601 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004602 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004603
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004604 // Substitute into the replacement type, which itself might involve something
4605 // that needs to be transformed. This only tends to occur with default
4606 // template arguments of template template parameters.
4607 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4608 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4609 if (Replacement.isNull())
4610 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004611
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004612 // Always canonicalize the replacement type.
4613 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4614 QualType Result
Chad Rosier4a9d7952012-08-08 18:46:20 +00004615 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004616 Replacement);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004617
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004618 // Propagate type-source information.
4619 SubstTemplateTypeParmTypeLoc NewTL
4620 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4621 NewTL.setNameLoc(TL.getNameLoc());
4622 return Result;
4623
John McCall49a832b2009-10-18 09:09:24 +00004624}
4625
4626template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004627QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4628 TypeLocBuilder &TLB,
4629 SubstTemplateTypeParmPackTypeLoc TL) {
4630 return TransformTypeSpecType(TLB, TL);
4631}
4632
4633template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004634QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004635 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004636 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004637 const TemplateSpecializationType *T = TL.getTypePtr();
4638
Douglas Gregor1d752d72011-03-02 18:46:51 +00004639 // The nested-name-specifier never matters in a TemplateSpecializationType,
4640 // because we can't have a dependent nested-name-specifier anyway.
4641 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004642 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004643 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4644 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004645 if (Template.isNull())
4646 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004647
John McCall43fed0d2010-11-12 08:19:04 +00004648 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4649}
4650
Eli Friedmanb001de72011-10-06 23:00:33 +00004651template<typename Derived>
4652QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4653 AtomicTypeLoc TL) {
4654 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4655 if (ValueType.isNull())
4656 return QualType();
4657
4658 QualType Result = TL.getType();
4659 if (getDerived().AlwaysRebuild() ||
4660 ValueType != TL.getValueLoc().getType()) {
4661 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4662 if (Result.isNull())
4663 return QualType();
4664 }
4665
4666 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4667 NewTL.setKWLoc(TL.getKWLoc());
4668 NewTL.setLParenLoc(TL.getLParenLoc());
4669 NewTL.setRParenLoc(TL.getRParenLoc());
4670
4671 return Result;
4672}
4673
Chad Rosier4a9d7952012-08-08 18:46:20 +00004674 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004675 /// container that provides a \c getArgLoc() member function.
4676 ///
4677 /// This iterator is intended to be used with the iterator form of
4678 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4679 template<typename ArgLocContainer>
4680 class TemplateArgumentLocContainerIterator {
4681 ArgLocContainer *Container;
4682 unsigned Index;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004683
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004684 public:
4685 typedef TemplateArgumentLoc value_type;
4686 typedef TemplateArgumentLoc reference;
4687 typedef int difference_type;
4688 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004689
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004690 class pointer {
4691 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004692
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004693 public:
4694 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004695
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004696 const TemplateArgumentLoc *operator->() const {
4697 return &Arg;
4698 }
4699 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004700
4701
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004702 TemplateArgumentLocContainerIterator() {}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004703
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004704 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4705 unsigned Index)
4706 : Container(&Container), Index(Index) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004707
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004708 TemplateArgumentLocContainerIterator &operator++() {
4709 ++Index;
4710 return *this;
4711 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004712
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004713 TemplateArgumentLocContainerIterator operator++(int) {
4714 TemplateArgumentLocContainerIterator Old(*this);
4715 ++(*this);
4716 return Old;
4717 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004718
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004719 TemplateArgumentLoc operator*() const {
4720 return Container->getArgLoc(Index);
4721 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004722
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004723 pointer operator->() const {
4724 return pointer(Container->getArgLoc(Index));
4725 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004726
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004727 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004728 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004729 return X.Container == Y.Container && X.Index == Y.Index;
4730 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004731
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004732 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004733 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004734 return !(X == Y);
4735 }
4736 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004737
4738
John McCall43fed0d2010-11-12 08:19:04 +00004739template <typename Derived>
4740QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4741 TypeLocBuilder &TLB,
4742 TemplateSpecializationTypeLoc TL,
4743 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004744 TemplateArgumentListInfo NewTemplateArgs;
4745 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4746 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004747 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4748 ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004749 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004750 ArgIterator(TL, TL.getNumArgs()),
4751 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004752 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004753
John McCall833ca992009-10-29 08:12:44 +00004754 // FIXME: maybe don't rebuild if all the template arguments are the same.
4755
4756 QualType Result =
4757 getDerived().RebuildTemplateSpecializationType(Template,
4758 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004759 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004760
4761 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004762 // Specializations of template template parameters are represented as
4763 // TemplateSpecializationTypes, and substitution of type alias templates
4764 // within a dependent context can transform them into
4765 // DependentTemplateSpecializationTypes.
4766 if (isa<DependentTemplateSpecializationType>(Result)) {
4767 DependentTemplateSpecializationTypeLoc NewTL
4768 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004769 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004770 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004771 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004772 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004773 NewTL.setLAngleLoc(TL.getLAngleLoc());
4774 NewTL.setRAngleLoc(TL.getRAngleLoc());
4775 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4776 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4777 return Result;
4778 }
4779
John McCall833ca992009-10-29 08:12:44 +00004780 TemplateSpecializationTypeLoc NewTL
4781 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004782 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004783 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4784 NewTL.setLAngleLoc(TL.getLAngleLoc());
4785 NewTL.setRAngleLoc(TL.getRAngleLoc());
4786 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4787 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004788 }
Mike Stump1eb44332009-09-09 15:08:12 +00004789
John McCall833ca992009-10-29 08:12:44 +00004790 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004791}
Mike Stump1eb44332009-09-09 15:08:12 +00004792
Douglas Gregora88f09f2011-02-28 17:23:35 +00004793template <typename Derived>
4794QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4795 TypeLocBuilder &TLB,
4796 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004797 TemplateName Template,
4798 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004799 TemplateArgumentListInfo NewTemplateArgs;
4800 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4801 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4802 typedef TemplateArgumentLocContainerIterator<
4803 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004804 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004805 ArgIterator(TL, TL.getNumArgs()),
4806 NewTemplateArgs))
4807 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004808
Douglas Gregora88f09f2011-02-28 17:23:35 +00004809 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier4a9d7952012-08-08 18:46:20 +00004810
Douglas Gregora88f09f2011-02-28 17:23:35 +00004811 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4812 QualType Result
4813 = getSema().Context.getDependentTemplateSpecializationType(
4814 TL.getTypePtr()->getKeyword(),
4815 DTN->getQualifier(),
4816 DTN->getIdentifier(),
4817 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004818
Douglas Gregora88f09f2011-02-28 17:23:35 +00004819 DependentTemplateSpecializationTypeLoc NewTL
4820 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004821 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004822 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004823 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004824 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004825 NewTL.setLAngleLoc(TL.getLAngleLoc());
4826 NewTL.setRAngleLoc(TL.getRAngleLoc());
4827 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4828 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4829 return Result;
4830 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004831
4832 QualType Result
Douglas Gregora88f09f2011-02-28 17:23:35 +00004833 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004834 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004835 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004836
Douglas Gregora88f09f2011-02-28 17:23:35 +00004837 if (!Result.isNull()) {
4838 /// FIXME: Wrap this in an elaborated-type-specifier?
4839 TemplateSpecializationTypeLoc NewTL
4840 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004841 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004842 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004843 NewTL.setLAngleLoc(TL.getLAngleLoc());
4844 NewTL.setRAngleLoc(TL.getRAngleLoc());
4845 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4846 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4847 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004848
Douglas Gregora88f09f2011-02-28 17:23:35 +00004849 return Result;
4850}
4851
Mike Stump1eb44332009-09-09 15:08:12 +00004852template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004853QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004854TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004855 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004856 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004857
Douglas Gregor9e876872011-03-01 18:12:44 +00004858 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004859 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004860 if (TL.getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004861 QualifierLoc
Douglas Gregor9e876872011-03-01 18:12:44 +00004862 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4863 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004864 return QualType();
4865 }
Mike Stump1eb44332009-09-09 15:08:12 +00004866
John McCall43fed0d2010-11-12 08:19:04 +00004867 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4868 if (NamedT.isNull())
4869 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004870
Richard Smith3e4c6c42011-05-05 21:57:07 +00004871 // C++0x [dcl.type.elab]p2:
4872 // If the identifier resolves to a typedef-name or the simple-template-id
4873 // resolves to an alias template specialization, the
4874 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004875 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4876 if (const TemplateSpecializationType *TST =
4877 NamedT->getAs<TemplateSpecializationType>()) {
4878 TemplateName Template = TST->getTemplateName();
4879 if (TypeAliasTemplateDecl *TAT =
4880 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4881 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4882 diag::err_tag_reference_non_tag) << 4;
4883 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4884 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004885 }
4886 }
4887
John McCalla2becad2009-10-21 00:40:46 +00004888 QualType Result = TL.getType();
4889 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004890 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004891 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00004892 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004893 T->getKeyword(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004894 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004895 if (Result.isNull())
4896 return QualType();
4897 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004898
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004899 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004900 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004901 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004902 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004903}
Mike Stump1eb44332009-09-09 15:08:12 +00004904
4905template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004906QualType TreeTransform<Derived>::TransformAttributedType(
4907 TypeLocBuilder &TLB,
4908 AttributedTypeLoc TL) {
4909 const AttributedType *oldType = TL.getTypePtr();
4910 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4911 if (modifiedType.isNull())
4912 return QualType();
4913
4914 QualType result = TL.getType();
4915
4916 // FIXME: dependent operand expressions?
4917 if (getDerived().AlwaysRebuild() ||
4918 modifiedType != oldType->getModifiedType()) {
4919 // TODO: this is really lame; we should really be rebuilding the
4920 // equivalent type from first principles.
4921 QualType equivalentType
4922 = getDerived().TransformType(oldType->getEquivalentType());
4923 if (equivalentType.isNull())
4924 return QualType();
4925 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4926 modifiedType,
4927 equivalentType);
4928 }
4929
4930 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4931 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4932 if (TL.hasAttrOperand())
4933 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4934 if (TL.hasAttrExprOperand())
4935 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4936 else if (TL.hasAttrEnumOperand())
4937 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4938
4939 return result;
4940}
4941
4942template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004943QualType
4944TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4945 ParenTypeLoc TL) {
4946 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4947 if (Inner.isNull())
4948 return QualType();
4949
4950 QualType Result = TL.getType();
4951 if (getDerived().AlwaysRebuild() ||
4952 Inner != TL.getInnerLoc().getType()) {
4953 Result = getDerived().RebuildParenType(Inner);
4954 if (Result.isNull())
4955 return QualType();
4956 }
4957
4958 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4959 NewTL.setLParenLoc(TL.getLParenLoc());
4960 NewTL.setRParenLoc(TL.getRParenLoc());
4961 return Result;
4962}
4963
4964template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004965QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004966 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004967 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004968
Douglas Gregor2494dd02011-03-01 01:34:45 +00004969 NestedNameSpecifierLoc QualifierLoc
4970 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4971 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004972 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004973
John McCall33500952010-06-11 00:33:02 +00004974 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004975 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00004976 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004977 QualifierLoc,
4978 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004979 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004980 if (Result.isNull())
4981 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004982
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004983 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4984 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004985 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4986
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004987 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004988 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004989 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004990 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004991 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004992 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004993 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004994 NewTL.setNameLoc(TL.getNameLoc());
4995 }
John McCalla2becad2009-10-21 00:40:46 +00004996 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004997}
Mike Stump1eb44332009-09-09 15:08:12 +00004998
Douglas Gregor577f75a2009-08-04 16:50:30 +00004999template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00005000QualType TreeTransform<Derived>::
5001 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005002 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005003 NestedNameSpecifierLoc QualifierLoc;
5004 if (TL.getQualifierLoc()) {
5005 QualifierLoc
5006 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5007 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00005008 return QualType();
5009 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005010
John McCall43fed0d2010-11-12 08:19:04 +00005011 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005012 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00005013}
5014
5015template<typename Derived>
5016QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005017TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5018 DependentTemplateSpecializationTypeLoc TL,
5019 NestedNameSpecifierLoc QualifierLoc) {
5020 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005021
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005022 TemplateArgumentListInfo NewTemplateArgs;
5023 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5024 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005025
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005026 typedef TemplateArgumentLocContainerIterator<
5027 DependentTemplateSpecializationTypeLoc> ArgIterator;
5028 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5029 ArgIterator(TL, TL.getNumArgs()),
5030 NewTemplateArgs))
5031 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005032
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005033 QualType Result
5034 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5035 QualifierLoc,
5036 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005037 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005038 NewTemplateArgs);
5039 if (Result.isNull())
5040 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005041
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005042 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5043 QualType NamedT = ElabT->getNamedType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005044
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005045 // Copy information relevant to the template specialization.
5046 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005047 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005048 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005049 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005050 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5051 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005052 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005053 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005054
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005055 // Copy information relevant to the elaborated type.
5056 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005057 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005058 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005059 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5060 DependentTemplateSpecializationTypeLoc SpecTL
5061 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005062 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005063 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005064 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005065 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005066 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5067 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005068 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005069 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005070 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005071 TemplateSpecializationTypeLoc SpecTL
5072 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005073 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005074 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005075 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5076 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005077 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005078 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005079 }
5080 return Result;
5081}
5082
5083template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00005084QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5085 PackExpansionTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005086 QualType Pattern
5087 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005088 if (Pattern.isNull())
5089 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005090
5091 QualType Result = TL.getType();
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005092 if (getDerived().AlwaysRebuild() ||
5093 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005094 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005095 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00005096 TL.getEllipsisLoc(),
5097 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005098 if (Result.isNull())
5099 return QualType();
5100 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005101
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005102 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5103 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5104 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00005105}
5106
5107template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005108QualType
5109TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005110 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005111 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005112 TLB.pushFullCopy(TL);
5113 return TL.getType();
5114}
5115
5116template<typename Derived>
5117QualType
5118TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005119 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005120 // ObjCObjectType is never dependent.
5121 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005122 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005123}
Mike Stump1eb44332009-09-09 15:08:12 +00005124
5125template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005126QualType
5127TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005128 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005129 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005130 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005131 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005132}
5133
Douglas Gregor577f75a2009-08-04 16:50:30 +00005134//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005135// Statement transformation
5136//===----------------------------------------------------------------------===//
5137template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005138StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005139TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005140 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005141}
5142
5143template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005144StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005145TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5146 return getDerived().TransformCompoundStmt(S, false);
5147}
5148
5149template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005150StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005151TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005152 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005153 Sema::CompoundScopeRAII CompoundScope(getSema());
5154
John McCall7114cba2010-08-27 19:56:05 +00005155 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005156 bool SubStmtChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005157 SmallVector<Stmt*, 8> Statements;
Douglas Gregor43959a92009-08-20 07:17:43 +00005158 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5159 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005160 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005161 if (Result.isInvalid()) {
5162 // Immediately fail if this was a DeclStmt, since it's very
5163 // likely that this will cause problems for future statements.
5164 if (isa<DeclStmt>(*B))
5165 return StmtError();
5166
5167 // Otherwise, just keep processing substatements and fail later.
5168 SubStmtInvalid = true;
5169 continue;
5170 }
Mike Stump1eb44332009-09-09 15:08:12 +00005171
Douglas Gregor43959a92009-08-20 07:17:43 +00005172 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5173 Statements.push_back(Result.takeAs<Stmt>());
5174 }
Mike Stump1eb44332009-09-09 15:08:12 +00005175
John McCall7114cba2010-08-27 19:56:05 +00005176 if (SubStmtInvalid)
5177 return StmtError();
5178
Douglas Gregor43959a92009-08-20 07:17:43 +00005179 if (!getDerived().AlwaysRebuild() &&
5180 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005181 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005182
5183 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005184 Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00005185 S->getRBracLoc(),
5186 IsStmtExpr);
5187}
Mike Stump1eb44332009-09-09 15:08:12 +00005188
Douglas Gregor43959a92009-08-20 07:17:43 +00005189template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005190StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005191TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005192 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005193 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005194 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5195 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005196
Eli Friedman264c1f82009-11-19 03:14:00 +00005197 // Transform the left-hand case value.
5198 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005199 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005200 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005201 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005202
Eli Friedman264c1f82009-11-19 03:14:00 +00005203 // Transform the right-hand case value (for the GNU case-range extension).
5204 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005205 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005206 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005207 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005208 }
Mike Stump1eb44332009-09-09 15:08:12 +00005209
Douglas Gregor43959a92009-08-20 07:17:43 +00005210 // Build the case statement.
5211 // Case statements are always rebuilt so that they will attached to their
5212 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005213 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005214 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005215 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005216 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005217 S->getColonLoc());
5218 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005219 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005220
Douglas Gregor43959a92009-08-20 07:17:43 +00005221 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005222 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005223 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005224 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005225
Douglas Gregor43959a92009-08-20 07:17:43 +00005226 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005227 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005228}
5229
5230template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005231StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005232TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005233 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005234 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005235 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005236 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005237
Douglas Gregor43959a92009-08-20 07:17:43 +00005238 // Default statements are always rebuilt
5239 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005240 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005241}
Mike Stump1eb44332009-09-09 15:08:12 +00005242
Douglas Gregor43959a92009-08-20 07:17:43 +00005243template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005244StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005245TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005246 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005247 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005248 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005249
Chris Lattner57ad3782011-02-17 20:34:02 +00005250 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5251 S->getDecl());
5252 if (!LD)
5253 return StmtError();
Richard Smith534986f2012-04-14 00:33:13 +00005254
5255
Douglas Gregor43959a92009-08-20 07:17:43 +00005256 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005257 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005258 cast<LabelDecl>(LD), SourceLocation(),
5259 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005260}
Mike Stump1eb44332009-09-09 15:08:12 +00005261
Douglas Gregor43959a92009-08-20 07:17:43 +00005262template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005263StmtResult
Richard Smith534986f2012-04-14 00:33:13 +00005264TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5265 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5266 if (SubStmt.isInvalid())
5267 return StmtError();
5268
5269 // TODO: transform attributes
5270 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5271 return S;
5272
5273 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5274 S->getAttrs(),
5275 SubStmt.get());
5276}
5277
5278template<typename Derived>
5279StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005280TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005281 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005282 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005283 VarDecl *ConditionVar = 0;
5284 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005285 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005286 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005287 getDerived().TransformDefinition(
5288 S->getConditionVariable()->getLocation(),
5289 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005290 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005291 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005292 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005293 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005294
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005295 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005296 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005297
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005298 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005299 if (S->getCond()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005300 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005301 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005302 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005303 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005304
John McCall9ae2f072010-08-23 23:25:46 +00005305 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005306 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005307 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005308
John McCall9ae2f072010-08-23 23:25:46 +00005309 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5310 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005311 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005312
Douglas Gregor43959a92009-08-20 07:17:43 +00005313 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005314 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005315 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005316 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005317
Douglas Gregor43959a92009-08-20 07:17:43 +00005318 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005319 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005320 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005321 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005322
Douglas Gregor43959a92009-08-20 07:17:43 +00005323 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005324 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005325 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005326 Then.get() == S->getThen() &&
5327 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005328 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005329
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005330 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005331 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005332 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005333}
5334
5335template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005336StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005337TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005338 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005339 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005340 VarDecl *ConditionVar = 0;
5341 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005342 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005343 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005344 getDerived().TransformDefinition(
5345 S->getConditionVariable()->getLocation(),
5346 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005347 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005348 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005349 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005350 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005351
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005352 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005353 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005354 }
Mike Stump1eb44332009-09-09 15:08:12 +00005355
Douglas Gregor43959a92009-08-20 07:17:43 +00005356 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005357 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005358 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005359 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005360 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005361 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005362
Douglas Gregor43959a92009-08-20 07:17:43 +00005363 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005364 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005365 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005366 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005367
Douglas Gregor43959a92009-08-20 07:17:43 +00005368 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005369 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5370 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005371}
Mike Stump1eb44332009-09-09 15:08:12 +00005372
Douglas Gregor43959a92009-08-20 07:17:43 +00005373template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005374StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005375TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005376 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005377 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005378 VarDecl *ConditionVar = 0;
5379 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005380 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005381 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005382 getDerived().TransformDefinition(
5383 S->getConditionVariable()->getLocation(),
5384 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005385 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005386 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005387 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005388 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005389
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005390 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005391 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005392
5393 if (S->getCond()) {
5394 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005395 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005396 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005397 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005398 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005399 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005400 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005401 }
Mike Stump1eb44332009-09-09 15:08:12 +00005402
John McCall9ae2f072010-08-23 23:25:46 +00005403 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5404 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005405 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005406
Douglas Gregor43959a92009-08-20 07:17:43 +00005407 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005408 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005409 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005410 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005411
Douglas Gregor43959a92009-08-20 07:17:43 +00005412 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005413 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005414 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005415 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005416 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005417
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005418 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005419 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005420}
Mike Stump1eb44332009-09-09 15:08:12 +00005421
Douglas Gregor43959a92009-08-20 07:17:43 +00005422template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005423StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005424TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005425 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005426 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005427 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005428 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005429
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005430 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005431 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005432 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005433 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005434
Douglas Gregor43959a92009-08-20 07:17:43 +00005435 if (!getDerived().AlwaysRebuild() &&
5436 Cond.get() == S->getCond() &&
5437 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005438 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005439
John McCall9ae2f072010-08-23 23:25:46 +00005440 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5441 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005442 S->getRParenLoc());
5443}
Mike Stump1eb44332009-09-09 15:08:12 +00005444
Douglas Gregor43959a92009-08-20 07:17:43 +00005445template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005446StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005447TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005448 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005449 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005450 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005451 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005452
Douglas Gregor43959a92009-08-20 07:17:43 +00005453 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005454 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005455 VarDecl *ConditionVar = 0;
5456 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005457 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005458 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005459 getDerived().TransformDefinition(
5460 S->getConditionVariable()->getLocation(),
5461 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005462 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005463 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005464 } else {
5465 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005466
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005467 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005468 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005469
5470 if (S->getCond()) {
5471 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005472 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005473 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005474 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005475 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005476
John McCall9ae2f072010-08-23 23:25:46 +00005477 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005478 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005479 }
Mike Stump1eb44332009-09-09 15:08:12 +00005480
Chad Rosier4a9d7952012-08-08 18:46:20 +00005481 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCall9ae2f072010-08-23 23:25:46 +00005482 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005483 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005484
Douglas Gregor43959a92009-08-20 07:17:43 +00005485 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005486 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005487 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005488 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005489
Richard Smith41956372013-01-14 22:39:08 +00005490 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCall9ae2f072010-08-23 23:25:46 +00005491 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005492 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005493
Douglas Gregor43959a92009-08-20 07:17:43 +00005494 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005495 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005496 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005497 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005498
Douglas Gregor43959a92009-08-20 07:17:43 +00005499 if (!getDerived().AlwaysRebuild() &&
5500 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005501 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005502 Inc.get() == S->getInc() &&
5503 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005504 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005505
Douglas Gregor43959a92009-08-20 07:17:43 +00005506 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005507 Init.get(), FullCond, ConditionVar,
5508 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005509}
5510
5511template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005512StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005513TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005514 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5515 S->getLabel());
5516 if (!LD)
5517 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005518
Douglas Gregor43959a92009-08-20 07:17:43 +00005519 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005520 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005521 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005522}
5523
5524template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005525StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005526TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005527 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005528 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005529 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005530 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005531
Douglas Gregor43959a92009-08-20 07:17:43 +00005532 if (!getDerived().AlwaysRebuild() &&
5533 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005534 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005535
5536 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005537 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005538}
5539
5540template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005541StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005542TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005543 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005544}
Mike Stump1eb44332009-09-09 15:08:12 +00005545
Douglas Gregor43959a92009-08-20 07:17:43 +00005546template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005547StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005548TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005549 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005550}
Mike Stump1eb44332009-09-09 15:08:12 +00005551
Douglas Gregor43959a92009-08-20 07:17:43 +00005552template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005553StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005554TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005555 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005556 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005557 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005558
Mike Stump1eb44332009-09-09 15:08:12 +00005559 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005560 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005561 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005562}
Mike Stump1eb44332009-09-09 15:08:12 +00005563
Douglas Gregor43959a92009-08-20 07:17:43 +00005564template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005565StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005566TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005567 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005568 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005569 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5570 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005571 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5572 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005573 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005574 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005575
Douglas Gregor43959a92009-08-20 07:17:43 +00005576 if (Transformed != *D)
5577 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005578
Douglas Gregor43959a92009-08-20 07:17:43 +00005579 Decls.push_back(Transformed);
5580 }
Mike Stump1eb44332009-09-09 15:08:12 +00005581
Douglas Gregor43959a92009-08-20 07:17:43 +00005582 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005583 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005584
5585 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005586 S->getStartLoc(), S->getEndLoc());
5587}
Mike Stump1eb44332009-09-09 15:08:12 +00005588
Douglas Gregor43959a92009-08-20 07:17:43 +00005589template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005590StmtResult
Chad Rosierdf5faf52012-08-25 00:11:56 +00005591TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005592
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005593 SmallVector<Expr*, 8> Constraints;
5594 SmallVector<Expr*, 8> Exprs;
Chris Lattner686775d2011-07-20 06:58:45 +00005595 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005596
John McCall60d7b3a2010-08-24 06:29:42 +00005597 ExprResult AsmString;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005598 SmallVector<Expr*, 8> Clobbers;
Anders Carlsson703e3942010-01-24 05:50:09 +00005599
5600 bool ExprsChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005601
Anders Carlsson703e3942010-01-24 05:50:09 +00005602 // Go through the outputs.
5603 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005604 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005605
Anders Carlsson703e3942010-01-24 05:50:09 +00005606 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005607 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005608
Anders Carlsson703e3942010-01-24 05:50:09 +00005609 // Transform the output expr.
5610 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005611 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005612 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005613 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005614
Anders Carlsson703e3942010-01-24 05:50:09 +00005615 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005616
John McCall9ae2f072010-08-23 23:25:46 +00005617 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005618 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005619
Anders Carlsson703e3942010-01-24 05:50:09 +00005620 // Go through the inputs.
5621 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005622 Names.push_back(S->getInputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005623
Anders Carlsson703e3942010-01-24 05:50:09 +00005624 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005625 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005626
Anders Carlsson703e3942010-01-24 05:50:09 +00005627 // Transform the input expr.
5628 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005629 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005630 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005631 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005632
Anders Carlsson703e3942010-01-24 05:50:09 +00005633 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005634
John McCall9ae2f072010-08-23 23:25:46 +00005635 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005636 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005637
Anders Carlsson703e3942010-01-24 05:50:09 +00005638 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005639 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005640
5641 // Go through the clobbers.
5642 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosier5c7f5942012-08-27 23:28:41 +00005643 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005644
5645 // No need to transform the asm string literal.
5646 AsmString = SemaRef.Owned(S->getAsmString());
Chad Rosierdf5faf52012-08-25 00:11:56 +00005647 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5648 S->isVolatile(), S->getNumOutputs(),
5649 S->getNumInputs(), Names.data(),
5650 Constraints, Exprs, AsmString.get(),
5651 Clobbers, S->getRParenLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005652}
5653
Chad Rosier8cd64b42012-06-11 20:47:18 +00005654template<typename Derived>
5655StmtResult
5656TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier79efe242012-08-07 00:29:06 +00005657 ArrayRef<Token> AsmToks =
5658 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier62f22b82012-08-08 19:48:07 +00005659
John McCallaeeacf72013-05-03 00:10:13 +00005660 bool HadError = false, HadChange = false;
5661
5662 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5663 SmallVector<Expr*, 8> TransformedExprs;
5664 TransformedExprs.reserve(SrcExprs.size());
5665 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5666 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5667 if (!Result.isUsable()) {
5668 HadError = true;
5669 } else {
5670 HadChange |= (Result.get() != SrcExprs[i]);
5671 TransformedExprs.push_back(Result.take());
5672 }
5673 }
5674
5675 if (HadError) return StmtError();
5676 if (!HadChange && !getDerived().AlwaysRebuild())
5677 return Owned(S);
5678
Chad Rosier7bd092b2012-08-15 16:53:30 +00005679 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallaeeacf72013-05-03 00:10:13 +00005680 AsmToks, S->getAsmString(),
5681 S->getNumOutputs(), S->getNumInputs(),
5682 S->getAllConstraints(), S->getClobbers(),
5683 TransformedExprs, S->getEndLoc());
Chad Rosier8cd64b42012-06-11 20:47:18 +00005684}
Douglas Gregor43959a92009-08-20 07:17:43 +00005685
5686template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005687StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005688TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005689 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005690 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005691 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005692 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005693
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005694 // Transform the @catch statements (if present).
5695 bool AnyCatchChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005696 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005697 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005698 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005699 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005700 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005701 if (Catch.get() != S->getCatchStmt(I))
5702 AnyCatchChanged = true;
5703 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005704 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005705
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005706 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005707 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005708 if (S->getFinallyStmt()) {
5709 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5710 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005711 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005712 }
5713
5714 // If nothing changed, just retain this statement.
5715 if (!getDerived().AlwaysRebuild() &&
5716 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005717 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005718 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005719 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005720
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005721 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005722 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005723 CatchStmts, Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005724}
Mike Stump1eb44332009-09-09 15:08:12 +00005725
Douglas Gregor43959a92009-08-20 07:17:43 +00005726template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005727StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005728TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005729 // Transform the @catch parameter, if there is one.
5730 VarDecl *Var = 0;
5731 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5732 TypeSourceInfo *TSInfo = 0;
5733 if (FromVar->getTypeSourceInfo()) {
5734 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5735 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005736 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005737 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005738
Douglas Gregorbe270a02010-04-26 17:57:08 +00005739 QualType T;
5740 if (TSInfo)
5741 T = TSInfo->getType();
5742 else {
5743 T = getDerived().TransformType(FromVar->getType());
5744 if (T.isNull())
Chad Rosier4a9d7952012-08-08 18:46:20 +00005745 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005746 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005747
Douglas Gregorbe270a02010-04-26 17:57:08 +00005748 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5749 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005750 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005751 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005752
John McCall60d7b3a2010-08-24 06:29:42 +00005753 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005754 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005755 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005756
5757 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005758 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005759 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005760}
Mike Stump1eb44332009-09-09 15:08:12 +00005761
Douglas Gregor43959a92009-08-20 07:17:43 +00005762template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005763StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005764TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005765 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005766 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005767 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005768 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005769
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005770 // If nothing changed, just retain this statement.
5771 if (!getDerived().AlwaysRebuild() &&
5772 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005773 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005774
5775 // Build a new statement.
5776 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005777 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005778}
Mike Stump1eb44332009-09-09 15:08:12 +00005779
Douglas Gregor43959a92009-08-20 07:17:43 +00005780template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005781StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005782TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005783 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005784 if (S->getThrowExpr()) {
5785 Operand = getDerived().TransformExpr(S->getThrowExpr());
5786 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005787 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005788 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005789
Douglas Gregord1377b22010-04-22 21:44:01 +00005790 if (!getDerived().AlwaysRebuild() &&
5791 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005792 return getSema().Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005793
John McCall9ae2f072010-08-23 23:25:46 +00005794 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005795}
Mike Stump1eb44332009-09-09 15:08:12 +00005796
Douglas Gregor43959a92009-08-20 07:17:43 +00005797template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005798StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005799TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005800 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005801 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005802 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005803 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005804 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005805 Object =
5806 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5807 Object.get());
5808 if (Object.isInvalid())
5809 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005810
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005811 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005812 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005813 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005814 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005815
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005816 // If nothing change, just retain the current statement.
5817 if (!getDerived().AlwaysRebuild() &&
5818 Object.get() == S->getSynchExpr() &&
5819 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005820 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005821
5822 // Build a new statement.
5823 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005824 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005825}
5826
5827template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005828StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005829TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5830 ObjCAutoreleasePoolStmt *S) {
5831 // Transform the body.
5832 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5833 if (Body.isInvalid())
5834 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005835
John McCallf85e1932011-06-15 23:02:42 +00005836 // If nothing changed, just retain this statement.
5837 if (!getDerived().AlwaysRebuild() &&
5838 Body.get() == S->getSubStmt())
5839 return SemaRef.Owned(S);
5840
5841 // Build a new statement.
5842 return getDerived().RebuildObjCAutoreleasePoolStmt(
5843 S->getAtLoc(), Body.get());
5844}
5845
5846template<typename Derived>
5847StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005848TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005849 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005850 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005851 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005852 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005853 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005854
Douglas Gregorc3203e72010-04-22 23:10:45 +00005855 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005856 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005857 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005858 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005859
Douglas Gregorc3203e72010-04-22 23:10:45 +00005860 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005861 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005862 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005863 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005864
Douglas Gregorc3203e72010-04-22 23:10:45 +00005865 // If nothing changed, just retain this statement.
5866 if (!getDerived().AlwaysRebuild() &&
5867 Element.get() == S->getElement() &&
5868 Collection.get() == S->getCollection() &&
5869 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005870 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005871
Douglas Gregorc3203e72010-04-22 23:10:45 +00005872 // Build a new statement.
5873 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005874 Element.get(),
5875 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005876 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005877 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005878}
5879
5880
5881template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005882StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005883TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5884 // Transform the exception declaration, if any.
5885 VarDecl *Var = 0;
5886 if (S->getExceptionDecl()) {
5887 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005888 TypeSourceInfo *T = getDerived().TransformType(
5889 ExceptionDecl->getTypeSourceInfo());
5890 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005891 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005892
Douglas Gregor83cb9422010-09-09 17:09:21 +00005893 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005894 ExceptionDecl->getInnerLocStart(),
5895 ExceptionDecl->getLocation(),
5896 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005897 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005898 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005899 }
Mike Stump1eb44332009-09-09 15:08:12 +00005900
Douglas Gregor43959a92009-08-20 07:17:43 +00005901 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005902 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005903 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005904 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005905
Douglas Gregor43959a92009-08-20 07:17:43 +00005906 if (!getDerived().AlwaysRebuild() &&
5907 !Var &&
5908 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005909 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005910
5911 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5912 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005913 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005914}
Mike Stump1eb44332009-09-09 15:08:12 +00005915
Douglas Gregor43959a92009-08-20 07:17:43 +00005916template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005917StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005918TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5919 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005920 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005921 = getDerived().TransformCompoundStmt(S->getTryBlock());
5922 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005923 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005924
Douglas Gregor43959a92009-08-20 07:17:43 +00005925 // Transform the handlers.
5926 bool HandlerChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005927 SmallVector<Stmt*, 8> Handlers;
Douglas Gregor43959a92009-08-20 07:17:43 +00005928 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005929 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005930 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5931 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005932 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005933
Douglas Gregor43959a92009-08-20 07:17:43 +00005934 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5935 Handlers.push_back(Handler.takeAs<Stmt>());
5936 }
Mike Stump1eb44332009-09-09 15:08:12 +00005937
Douglas Gregor43959a92009-08-20 07:17:43 +00005938 if (!getDerived().AlwaysRebuild() &&
5939 TryBlock.get() == S->getTryBlock() &&
5940 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005941 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005942
John McCall9ae2f072010-08-23 23:25:46 +00005943 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005944 Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00005945}
Mike Stump1eb44332009-09-09 15:08:12 +00005946
Richard Smithad762fc2011-04-14 22:09:26 +00005947template<typename Derived>
5948StmtResult
5949TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5950 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5951 if (Range.isInvalid())
5952 return StmtError();
5953
5954 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5955 if (BeginEnd.isInvalid())
5956 return StmtError();
5957
5958 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5959 if (Cond.isInvalid())
5960 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005961 if (Cond.get())
5962 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
5963 if (Cond.isInvalid())
5964 return StmtError();
5965 if (Cond.get())
5966 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005967
5968 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5969 if (Inc.isInvalid())
5970 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005971 if (Inc.get())
5972 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005973
5974 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5975 if (LoopVar.isInvalid())
5976 return StmtError();
5977
5978 StmtResult NewStmt = S;
5979 if (getDerived().AlwaysRebuild() ||
5980 Range.get() != S->getRangeStmt() ||
5981 BeginEnd.get() != S->getBeginEndStmt() ||
5982 Cond.get() != S->getCond() ||
5983 Inc.get() != S->getInc() ||
Douglas Gregor39b60dc2013-05-02 18:35:56 +00005984 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smithad762fc2011-04-14 22:09:26 +00005985 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5986 S->getColonLoc(), Range.get(),
5987 BeginEnd.get(), Cond.get(),
5988 Inc.get(), LoopVar.get(),
5989 S->getRParenLoc());
Douglas Gregor39b60dc2013-05-02 18:35:56 +00005990 if (NewStmt.isInvalid())
5991 return StmtError();
5992 }
Richard Smithad762fc2011-04-14 22:09:26 +00005993
5994 StmtResult Body = getDerived().TransformStmt(S->getBody());
5995 if (Body.isInvalid())
5996 return StmtError();
5997
5998 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5999 // it now so we have a new statement to attach the body to.
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006000 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smithad762fc2011-04-14 22:09:26 +00006001 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6002 S->getColonLoc(), Range.get(),
6003 BeginEnd.get(), Cond.get(),
6004 Inc.get(), LoopVar.get(),
6005 S->getRParenLoc());
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006006 if (NewStmt.isInvalid())
6007 return StmtError();
6008 }
Richard Smithad762fc2011-04-14 22:09:26 +00006009
6010 if (NewStmt.get() == S)
6011 return SemaRef.Owned(S);
6012
6013 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6014}
6015
John Wiegley28bbe4b2011-04-28 01:08:34 +00006016template<typename Derived>
6017StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00006018TreeTransform<Derived>::TransformMSDependentExistsStmt(
6019 MSDependentExistsStmt *S) {
6020 // Transform the nested-name-specifier, if any.
6021 NestedNameSpecifierLoc QualifierLoc;
6022 if (S->getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006023 QualifierLoc
Douglas Gregorba0513d2011-10-25 01:33:02 +00006024 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6025 if (!QualifierLoc)
6026 return StmtError();
6027 }
6028
6029 // Transform the declaration name.
6030 DeclarationNameInfo NameInfo = S->getNameInfo();
6031 if (NameInfo.getName()) {
6032 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6033 if (!NameInfo.getName())
6034 return StmtError();
6035 }
6036
6037 // Check whether anything changed.
6038 if (!getDerived().AlwaysRebuild() &&
6039 QualifierLoc == S->getQualifierLoc() &&
6040 NameInfo.getName() == S->getNameInfo().getName())
6041 return S;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006042
Douglas Gregorba0513d2011-10-25 01:33:02 +00006043 // Determine whether this name exists, if we can.
6044 CXXScopeSpec SS;
6045 SS.Adopt(QualifierLoc);
6046 bool Dependent = false;
6047 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
6048 case Sema::IER_Exists:
6049 if (S->isIfExists())
6050 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006051
Douglas Gregorba0513d2011-10-25 01:33:02 +00006052 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6053
6054 case Sema::IER_DoesNotExist:
6055 if (S->isIfNotExists())
6056 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006057
Douglas Gregorba0513d2011-10-25 01:33:02 +00006058 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006059
Douglas Gregorba0513d2011-10-25 01:33:02 +00006060 case Sema::IER_Dependent:
6061 Dependent = true;
6062 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006063
Douglas Gregor65019ac2011-10-25 03:44:56 +00006064 case Sema::IER_Error:
6065 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00006066 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006067
Douglas Gregorba0513d2011-10-25 01:33:02 +00006068 // We need to continue with the instantiation, so do so now.
6069 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6070 if (SubStmt.isInvalid())
6071 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006072
Douglas Gregorba0513d2011-10-25 01:33:02 +00006073 // If we have resolved the name, just transform to the substatement.
6074 if (!Dependent)
6075 return SubStmt;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006076
Douglas Gregorba0513d2011-10-25 01:33:02 +00006077 // The name is still dependent, so build a dependent expression again.
6078 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6079 S->isIfExists(),
6080 QualifierLoc,
6081 NameInfo,
6082 SubStmt.get());
6083}
6084
6085template<typename Derived>
John McCall76da55d2013-04-16 07:28:30 +00006086ExprResult
6087TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6088 NestedNameSpecifierLoc QualifierLoc;
6089 if (E->getQualifierLoc()) {
6090 QualifierLoc
6091 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6092 if (!QualifierLoc)
6093 return ExprError();
6094 }
6095
6096 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6097 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6098 if (!PD)
6099 return ExprError();
6100
6101 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6102 if (Base.isInvalid())
6103 return ExprError();
6104
6105 return new (SemaRef.getASTContext())
6106 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6107 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6108 QualifierLoc, E->getMemberLoc());
6109}
6110
6111template<typename Derived>
Douglas Gregorba0513d2011-10-25 01:33:02 +00006112StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00006113TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
6114 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
6115 if(TryBlock.isInvalid()) return StmtError();
6116
6117 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
6118 if(!getDerived().AlwaysRebuild() &&
6119 TryBlock.get() == S->getTryBlock() &&
6120 Handler.get() == S->getHandler())
6121 return SemaRef.Owned(S);
6122
6123 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
6124 S->getTryLoc(),
6125 TryBlock.take(),
6126 Handler.take());
6127}
6128
6129template<typename Derived>
6130StmtResult
6131TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
6132 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6133 if(Block.isInvalid()) return StmtError();
6134
6135 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
6136 Block.take());
6137}
6138
6139template<typename Derived>
6140StmtResult
6141TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
6142 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
6143 if(FilterExpr.isInvalid()) return StmtError();
6144
6145 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6146 if(Block.isInvalid()) return StmtError();
6147
6148 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
6149 FilterExpr.take(),
6150 Block.take());
6151}
6152
6153template<typename Derived>
6154StmtResult
6155TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6156 if(isa<SEHFinallyStmt>(Handler))
6157 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6158 else
6159 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6160}
6161
Douglas Gregor43959a92009-08-20 07:17:43 +00006162//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00006163// Expression transformation
6164//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006165template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006166ExprResult
John McCall454feb92009-12-08 09:21:05 +00006167TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006168 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006169}
Mike Stump1eb44332009-09-09 15:08:12 +00006170
6171template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006172ExprResult
John McCall454feb92009-12-08 09:21:05 +00006173TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006174 NestedNameSpecifierLoc QualifierLoc;
6175 if (E->getQualifierLoc()) {
6176 QualifierLoc
6177 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6178 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006179 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006180 }
John McCalldbd872f2009-12-08 09:08:17 +00006181
6182 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006183 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6184 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006185 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006186 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006187
John McCallec8045d2010-08-17 21:27:17 +00006188 DeclarationNameInfo NameInfo = E->getNameInfo();
6189 if (NameInfo.getName()) {
6190 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6191 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006192 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006193 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006194
6195 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006196 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006197 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006198 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006199 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006200
6201 // Mark it referenced in the new context regardless.
6202 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006203 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006204
John McCall3fa5cae2010-10-26 07:05:15 +00006205 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006206 }
John McCalldbd872f2009-12-08 09:08:17 +00006207
6208 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006209 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006210 TemplateArgs = &TransArgs;
6211 TransArgs.setLAngleLoc(E->getLAngleLoc());
6212 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006213 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6214 E->getNumTemplateArgs(),
6215 TransArgs))
6216 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006217 }
6218
Chad Rosier4a9d7952012-08-08 18:46:20 +00006219 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregor40d96a62011-02-28 21:54:11 +00006220 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006221}
Mike Stump1eb44332009-09-09 15:08:12 +00006222
Douglas Gregorb98b1992009-08-11 05:31:07 +00006223template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006224ExprResult
John McCall454feb92009-12-08 09:21:05 +00006225TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006226 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006227}
Mike Stump1eb44332009-09-09 15:08:12 +00006228
Douglas Gregorb98b1992009-08-11 05:31:07 +00006229template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006230ExprResult
John McCall454feb92009-12-08 09:21:05 +00006231TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006232 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006233}
Mike Stump1eb44332009-09-09 15:08:12 +00006234
Douglas Gregorb98b1992009-08-11 05:31:07 +00006235template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006236ExprResult
John McCall454feb92009-12-08 09:21:05 +00006237TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006238 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006239}
Mike Stump1eb44332009-09-09 15:08:12 +00006240
Douglas Gregorb98b1992009-08-11 05:31:07 +00006241template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006242ExprResult
John McCall454feb92009-12-08 09:21:05 +00006243TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006244 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006245}
Mike Stump1eb44332009-09-09 15:08:12 +00006246
Douglas Gregorb98b1992009-08-11 05:31:07 +00006247template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006248ExprResult
John McCall454feb92009-12-08 09:21:05 +00006249TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006250 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006251}
6252
6253template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006254ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006255TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis391ca9f2013-04-09 01:17:02 +00006256 if (FunctionDecl *FD = E->getDirectCallee())
6257 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smith9fcce652012-03-07 08:35:16 +00006258 return SemaRef.MaybeBindToTemporary(E);
6259}
6260
6261template<typename Derived>
6262ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006263TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6264 ExprResult ControllingExpr =
6265 getDerived().TransformExpr(E->getControllingExpr());
6266 if (ControllingExpr.isInvalid())
6267 return ExprError();
6268
Chris Lattner686775d2011-07-20 06:58:45 +00006269 SmallVector<Expr *, 4> AssocExprs;
6270 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006271 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6272 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6273 if (TS) {
6274 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6275 if (!AssocType)
6276 return ExprError();
6277 AssocTypes.push_back(AssocType);
6278 } else {
6279 AssocTypes.push_back(0);
6280 }
6281
6282 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6283 if (AssocExpr.isInvalid())
6284 return ExprError();
6285 AssocExprs.push_back(AssocExpr.release());
6286 }
6287
6288 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6289 E->getDefaultLoc(),
6290 E->getRParenLoc(),
6291 ControllingExpr.release(),
6292 AssocTypes.data(),
6293 AssocExprs.data(),
6294 E->getNumAssocs());
6295}
6296
6297template<typename Derived>
6298ExprResult
John McCall454feb92009-12-08 09:21:05 +00006299TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006300 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006301 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006302 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006303
Douglas Gregorb98b1992009-08-11 05:31:07 +00006304 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006305 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006306
John McCall9ae2f072010-08-23 23:25:46 +00006307 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006308 E->getRParen());
6309}
6310
Richard Smithefeeccf2012-10-21 03:28:35 +00006311/// \brief The operand of a unary address-of operator has special rules: it's
6312/// allowed to refer to a non-static member of a class even if there's no 'this'
6313/// object available.
6314template<typename Derived>
6315ExprResult
6316TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6317 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6318 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6319 else
6320 return getDerived().TransformExpr(E);
6321}
6322
Mike Stump1eb44332009-09-09 15:08:12 +00006323template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006324ExprResult
John McCall454feb92009-12-08 09:21:05 +00006325TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smithefeeccf2012-10-21 03:28:35 +00006326 ExprResult SubExpr = TransformAddressOfOperand(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006327 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006328 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006329
Douglas Gregorb98b1992009-08-11 05:31:07 +00006330 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006331 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006332
Douglas Gregorb98b1992009-08-11 05:31:07 +00006333 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6334 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006335 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006336}
Mike Stump1eb44332009-09-09 15:08:12 +00006337
Douglas Gregorb98b1992009-08-11 05:31:07 +00006338template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006339ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006340TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6341 // Transform the type.
6342 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6343 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006344 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006345
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006346 // Transform all of the components into components similar to what the
6347 // parser uses.
Chad Rosier4a9d7952012-08-08 18:46:20 +00006348 // FIXME: It would be slightly more efficient in the non-dependent case to
6349 // just map FieldDecls, rather than requiring the rebuilder to look for
6350 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006351 // template code that we don't care.
6352 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006353 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006354 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006355 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006356 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6357 const Node &ON = E->getComponent(I);
6358 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006359 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006360 Comp.LocStart = ON.getSourceRange().getBegin();
6361 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006362 switch (ON.getKind()) {
6363 case Node::Array: {
6364 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006365 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006366 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006367 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006368
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006369 ExprChanged = ExprChanged || Index.get() != FromIndex;
6370 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006371 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006372 break;
6373 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006374
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006375 case Node::Field:
6376 case Node::Identifier:
6377 Comp.isBrackets = false;
6378 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006379 if (!Comp.U.IdentInfo)
6380 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006381
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006382 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006383
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006384 case Node::Base:
6385 // Will be recomputed during the rebuild.
6386 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006387 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006388
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006389 Components.push_back(Comp);
6390 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006391
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006392 // If nothing changed, retain the existing expression.
6393 if (!getDerived().AlwaysRebuild() &&
6394 Type == E->getTypeSourceInfo() &&
6395 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006396 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006397
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006398 // Build a new offsetof expression.
6399 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6400 Components.data(), Components.size(),
6401 E->getRParenLoc());
6402}
6403
6404template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006405ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006406TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6407 assert(getDerived().AlreadyTransformed(E->getType()) &&
6408 "opaque value expression requires transformation");
6409 return SemaRef.Owned(E);
6410}
6411
6412template<typename Derived>
6413ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006414TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006415 // Rebuild the syntactic form. The original syntactic form has
6416 // opaque-value expressions in it, so strip those away and rebuild
6417 // the result. This is a really awful way of doing this, but the
6418 // better solution (rebuilding the semantic expressions and
6419 // rebinding OVEs as necessary) doesn't work; we'd need
6420 // TreeTransform to not strip away implicit conversions.
6421 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6422 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006423 if (result.isInvalid()) return ExprError();
6424
6425 // If that gives us a pseudo-object result back, the pseudo-object
6426 // expression must have been an lvalue-to-rvalue conversion which we
6427 // should reapply.
6428 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6429 result = SemaRef.checkPseudoObjectRValue(result.take());
6430
6431 return result;
6432}
6433
6434template<typename Derived>
6435ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006436TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6437 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006438 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006439 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006440
John McCalla93c9342009-12-07 02:54:59 +00006441 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006442 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006443 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006444
John McCall5ab75172009-11-04 07:28:41 +00006445 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006446 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006447
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006448 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6449 E->getKind(),
6450 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006451 }
Mike Stump1eb44332009-09-09 15:08:12 +00006452
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006453 // C++0x [expr.sizeof]p1:
6454 // The operand is either an expression, which is an unevaluated operand
6455 // [...]
Eli Friedman80bfa3d2012-09-26 04:34:21 +00006456 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6457 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00006458
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006459 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6460 if (SubExpr.isInvalid())
6461 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006462
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006463 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6464 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006465
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006466 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6467 E->getOperatorLoc(),
6468 E->getKind(),
6469 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006470}
Mike Stump1eb44332009-09-09 15:08:12 +00006471
Douglas Gregorb98b1992009-08-11 05:31:07 +00006472template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006473ExprResult
John McCall454feb92009-12-08 09:21:05 +00006474TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006475 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006476 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006477 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006478
John McCall60d7b3a2010-08-24 06:29:42 +00006479 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006480 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006481 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006482
6483
Douglas Gregorb98b1992009-08-11 05:31:07 +00006484 if (!getDerived().AlwaysRebuild() &&
6485 LHS.get() == E->getLHS() &&
6486 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006487 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006488
John McCall9ae2f072010-08-23 23:25:46 +00006489 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006490 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006491 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006492 E->getRBracketLoc());
6493}
Mike Stump1eb44332009-09-09 15:08:12 +00006494
6495template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006496ExprResult
John McCall454feb92009-12-08 09:21:05 +00006497TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006498 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006499 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006500 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006501 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006502
6503 // Transform arguments.
6504 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006505 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006506 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006507 &ArgChanged))
6508 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006509
Douglas Gregorb98b1992009-08-11 05:31:07 +00006510 if (!getDerived().AlwaysRebuild() &&
6511 Callee.get() == E->getCallee() &&
6512 !ArgChanged)
Dmitri Gribenko1ad23d62012-09-10 21:20:09 +00006513 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006514
Douglas Gregorb98b1992009-08-11 05:31:07 +00006515 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006516 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006517 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006518 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006519 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006520 E->getRParenLoc());
6521}
Mike Stump1eb44332009-09-09 15:08:12 +00006522
6523template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006524ExprResult
John McCall454feb92009-12-08 09:21:05 +00006525TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006526 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006527 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006528 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006529
Douglas Gregor40d96a62011-02-28 21:54:11 +00006530 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006531 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006532 QualifierLoc
6533 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006534
Douglas Gregor40d96a62011-02-28 21:54:11 +00006535 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006536 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006537 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006538 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006539
Eli Friedmanf595cc42009-12-04 06:40:45 +00006540 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006541 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6542 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006543 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006544 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006545
John McCall6bb80172010-03-30 21:47:33 +00006546 NamedDecl *FoundDecl = E->getFoundDecl();
6547 if (FoundDecl == E->getMemberDecl()) {
6548 FoundDecl = Member;
6549 } else {
6550 FoundDecl = cast_or_null<NamedDecl>(
6551 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6552 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006553 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006554 }
6555
Douglas Gregorb98b1992009-08-11 05:31:07 +00006556 if (!getDerived().AlwaysRebuild() &&
6557 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006558 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006559 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006560 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006561 !E->hasExplicitTemplateArgs()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006562
Anders Carlsson1f240322009-12-22 05:24:09 +00006563 // Mark it referenced in the new context regardless.
6564 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006565 SemaRef.MarkMemberReferenced(E);
6566
John McCall3fa5cae2010-10-26 07:05:15 +00006567 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006568 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006569
John McCalld5532b62009-11-23 01:53:49 +00006570 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006571 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006572 TransArgs.setLAngleLoc(E->getLAngleLoc());
6573 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006574 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6575 E->getNumTemplateArgs(),
6576 TransArgs))
6577 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006578 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006579
Douglas Gregorb98b1992009-08-11 05:31:07 +00006580 // FIXME: Bogus source location for the operator
6581 SourceLocation FakeOperatorLoc
6582 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6583
John McCallc2233c52010-01-15 08:34:02 +00006584 // FIXME: to do this check properly, we will need to preserve the
6585 // first-qualifier-in-scope here, just in case we had a dependent
6586 // base (and therefore couldn't do the check) and a
6587 // nested-name-qualifier (and therefore could do the lookup).
6588 NamedDecl *FirstQualifierInScope = 0;
6589
John McCall9ae2f072010-08-23 23:25:46 +00006590 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006591 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006592 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006593 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006594 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006595 Member,
John McCall6bb80172010-03-30 21:47:33 +00006596 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006597 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006598 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006599 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006600}
Mike Stump1eb44332009-09-09 15:08:12 +00006601
Douglas Gregorb98b1992009-08-11 05:31:07 +00006602template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006603ExprResult
John McCall454feb92009-12-08 09:21:05 +00006604TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006605 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006606 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006607 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006608
John McCall60d7b3a2010-08-24 06:29:42 +00006609 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006610 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006611 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006612
Douglas Gregorb98b1992009-08-11 05:31:07 +00006613 if (!getDerived().AlwaysRebuild() &&
6614 LHS.get() == E->getLHS() &&
6615 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006616 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006617
Lang Hamesbe9af122012-10-02 04:45:10 +00006618 Sema::FPContractStateRAII FPContractState(getSema());
6619 getSema().FPFeatures.fp_contract = E->isFPContractable();
6620
Douglas Gregorb98b1992009-08-11 05:31:07 +00006621 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006622 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006623}
6624
Mike Stump1eb44332009-09-09 15:08:12 +00006625template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006626ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006627TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006628 CompoundAssignOperator *E) {
6629 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006630}
Mike Stump1eb44332009-09-09 15:08:12 +00006631
Douglas Gregorb98b1992009-08-11 05:31:07 +00006632template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006633ExprResult TreeTransform<Derived>::
6634TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6635 // Just rebuild the common and RHS expressions and see whether we
6636 // get any changes.
6637
6638 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6639 if (commonExpr.isInvalid())
6640 return ExprError();
6641
6642 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6643 if (rhs.isInvalid())
6644 return ExprError();
6645
6646 if (!getDerived().AlwaysRebuild() &&
6647 commonExpr.get() == e->getCommon() &&
6648 rhs.get() == e->getFalseExpr())
6649 return SemaRef.Owned(e);
6650
6651 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6652 e->getQuestionLoc(),
6653 0,
6654 e->getColonLoc(),
6655 rhs.get());
6656}
6657
6658template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006659ExprResult
John McCall454feb92009-12-08 09:21:05 +00006660TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006661 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006662 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006663 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006664
John McCall60d7b3a2010-08-24 06:29:42 +00006665 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006666 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006667 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006668
John McCall60d7b3a2010-08-24 06:29:42 +00006669 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006670 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006671 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006672
Douglas Gregorb98b1992009-08-11 05:31:07 +00006673 if (!getDerived().AlwaysRebuild() &&
6674 Cond.get() == E->getCond() &&
6675 LHS.get() == E->getLHS() &&
6676 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006677 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006678
John McCall9ae2f072010-08-23 23:25:46 +00006679 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006680 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006681 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006682 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006683 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006684}
Mike Stump1eb44332009-09-09 15:08:12 +00006685
6686template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006687ExprResult
John McCall454feb92009-12-08 09:21:05 +00006688TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006689 // Implicit casts are eliminated during transformation, since they
6690 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006691 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006692}
Mike Stump1eb44332009-09-09 15:08:12 +00006693
Douglas Gregorb98b1992009-08-11 05:31:07 +00006694template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006695ExprResult
John McCall454feb92009-12-08 09:21:05 +00006696TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006697 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6698 if (!Type)
6699 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006700
John McCall60d7b3a2010-08-24 06:29:42 +00006701 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006702 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006703 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006704 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006705
Douglas Gregorb98b1992009-08-11 05:31:07 +00006706 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006707 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006708 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006709 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006710
John McCall9d125032010-01-15 18:39:57 +00006711 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006712 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006713 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006714 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006715}
Mike Stump1eb44332009-09-09 15:08:12 +00006716
Douglas Gregorb98b1992009-08-11 05:31:07 +00006717template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006718ExprResult
John McCall454feb92009-12-08 09:21:05 +00006719TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006720 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6721 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6722 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006723 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006724
John McCall60d7b3a2010-08-24 06:29:42 +00006725 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006726 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006727 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006728
Douglas Gregorb98b1992009-08-11 05:31:07 +00006729 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006730 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006731 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006732 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006733
John McCall1d7d8d62010-01-19 22:33:45 +00006734 // Note: the expression type doesn't necessarily match the
6735 // type-as-written, but that's okay, because it should always be
6736 // derivable from the initializer.
6737
John McCall42f56b52010-01-18 19:35:47 +00006738 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006739 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006740 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006741}
Mike Stump1eb44332009-09-09 15:08:12 +00006742
Douglas Gregorb98b1992009-08-11 05:31:07 +00006743template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006744ExprResult
John McCall454feb92009-12-08 09:21:05 +00006745TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006746 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006747 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006748 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006749
Douglas Gregorb98b1992009-08-11 05:31:07 +00006750 if (!getDerived().AlwaysRebuild() &&
6751 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006752 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006753
Douglas Gregorb98b1992009-08-11 05:31:07 +00006754 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006755 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006756 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006757 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006758 E->getAccessorLoc(),
6759 E->getAccessor());
6760}
Mike Stump1eb44332009-09-09 15:08:12 +00006761
Douglas Gregorb98b1992009-08-11 05:31:07 +00006762template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006763ExprResult
John McCall454feb92009-12-08 09:21:05 +00006764TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006765 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006766
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006767 SmallVector<Expr*, 4> Inits;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006768 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006769 Inits, &InitChanged))
6770 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006771
Douglas Gregorb98b1992009-08-11 05:31:07 +00006772 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006773 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006774
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006775 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00006776 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006777}
Mike Stump1eb44332009-09-09 15:08:12 +00006778
Douglas Gregorb98b1992009-08-11 05:31:07 +00006779template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006780ExprResult
John McCall454feb92009-12-08 09:21:05 +00006781TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006782 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006783
Douglas Gregor43959a92009-08-20 07:17:43 +00006784 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006785 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006786 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006787 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006788
Douglas Gregor43959a92009-08-20 07:17:43 +00006789 // transform the designators.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006790 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006791 bool ExprChanged = false;
6792 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6793 DEnd = E->designators_end();
6794 D != DEnd; ++D) {
6795 if (D->isFieldDesignator()) {
6796 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6797 D->getDotLoc(),
6798 D->getFieldLoc()));
6799 continue;
6800 }
Mike Stump1eb44332009-09-09 15:08:12 +00006801
Douglas Gregorb98b1992009-08-11 05:31:07 +00006802 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006803 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006804 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006805 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006806
6807 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006808 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006809
Douglas Gregorb98b1992009-08-11 05:31:07 +00006810 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6811 ArrayExprs.push_back(Index.release());
6812 continue;
6813 }
Mike Stump1eb44332009-09-09 15:08:12 +00006814
Douglas Gregorb98b1992009-08-11 05:31:07 +00006815 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006816 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006817 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6818 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006819 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006820
John McCall60d7b3a2010-08-24 06:29:42 +00006821 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006822 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006823 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006824
6825 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006826 End.get(),
6827 D->getLBracketLoc(),
6828 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006829
Douglas Gregorb98b1992009-08-11 05:31:07 +00006830 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6831 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006832
Douglas Gregorb98b1992009-08-11 05:31:07 +00006833 ArrayExprs.push_back(Start.release());
6834 ArrayExprs.push_back(End.release());
6835 }
Mike Stump1eb44332009-09-09 15:08:12 +00006836
Douglas Gregorb98b1992009-08-11 05:31:07 +00006837 if (!getDerived().AlwaysRebuild() &&
6838 Init.get() == E->getInit() &&
6839 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006840 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006841
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006842 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006843 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006844 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006845}
Mike Stump1eb44332009-09-09 15:08:12 +00006846
Douglas Gregorb98b1992009-08-11 05:31:07 +00006847template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006848ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006849TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006850 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006851 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006852
Douglas Gregor5557b252009-10-28 00:29:27 +00006853 // FIXME: Will we ever have proper type location here? Will we actually
6854 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006855 QualType T = getDerived().TransformType(E->getType());
6856 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006857 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006858
Douglas Gregorb98b1992009-08-11 05:31:07 +00006859 if (!getDerived().AlwaysRebuild() &&
6860 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006861 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006862
Douglas Gregorb98b1992009-08-11 05:31:07 +00006863 return getDerived().RebuildImplicitValueInitExpr(T);
6864}
Mike Stump1eb44332009-09-09 15:08:12 +00006865
Douglas Gregorb98b1992009-08-11 05:31:07 +00006866template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006867ExprResult
John McCall454feb92009-12-08 09:21:05 +00006868TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006869 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6870 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006871 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006872
John McCall60d7b3a2010-08-24 06:29:42 +00006873 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006874 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006875 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006876
Douglas Gregorb98b1992009-08-11 05:31:07 +00006877 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006878 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006879 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006880 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006881
John McCall9ae2f072010-08-23 23:25:46 +00006882 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006883 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006884}
6885
6886template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006887ExprResult
John McCall454feb92009-12-08 09:21:05 +00006888TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006889 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006890 SmallVector<Expr*, 4> Inits;
Douglas Gregoraa165f82011-01-03 19:04:46 +00006891 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6892 &ArgumentChanged))
6893 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006894
Douglas Gregorb98b1992009-08-11 05:31:07 +00006895 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006896 Inits,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006897 E->getRParenLoc());
6898}
Mike Stump1eb44332009-09-09 15:08:12 +00006899
Douglas Gregorb98b1992009-08-11 05:31:07 +00006900/// \brief Transform an address-of-label expression.
6901///
6902/// By default, the transformation of an address-of-label expression always
6903/// rebuilds the expression, so that the label identifier can be resolved to
6904/// the corresponding label statement by semantic analysis.
6905template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006906ExprResult
John McCall454feb92009-12-08 09:21:05 +00006907TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006908 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6909 E->getLabel());
6910 if (!LD)
6911 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006912
Douglas Gregorb98b1992009-08-11 05:31:07 +00006913 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006914 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006915}
Mike Stump1eb44332009-09-09 15:08:12 +00006916
6917template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00006918ExprResult
John McCall454feb92009-12-08 09:21:05 +00006919TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00006920 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00006921 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006922 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00006923 if (SubStmt.isInvalid()) {
6924 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00006925 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00006926 }
Mike Stump1eb44332009-09-09 15:08:12 +00006927
Douglas Gregorb98b1992009-08-11 05:31:07 +00006928 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00006929 SubStmt.get() == E->getSubStmt()) {
6930 // Calling this an 'error' is unintuitive, but it does the right thing.
6931 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00006932 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00006933 }
Mike Stump1eb44332009-09-09 15:08:12 +00006934
6935 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006936 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006937 E->getRParenLoc());
6938}
Mike Stump1eb44332009-09-09 15:08:12 +00006939
Douglas Gregorb98b1992009-08-11 05:31:07 +00006940template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006941ExprResult
John McCall454feb92009-12-08 09:21:05 +00006942TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006943 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006944 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006945 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006946
John McCall60d7b3a2010-08-24 06:29:42 +00006947 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006948 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006949 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006950
John McCall60d7b3a2010-08-24 06:29:42 +00006951 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006952 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006953 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006954
Douglas Gregorb98b1992009-08-11 05:31:07 +00006955 if (!getDerived().AlwaysRebuild() &&
6956 Cond.get() == E->getCond() &&
6957 LHS.get() == E->getLHS() &&
6958 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006959 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006960
Douglas Gregorb98b1992009-08-11 05:31:07 +00006961 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006962 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006963 E->getRParenLoc());
6964}
Mike Stump1eb44332009-09-09 15:08:12 +00006965
Douglas Gregorb98b1992009-08-11 05:31:07 +00006966template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006967ExprResult
John McCall454feb92009-12-08 09:21:05 +00006968TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006969 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006970}
6971
6972template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006973ExprResult
John McCall454feb92009-12-08 09:21:05 +00006974TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006975 switch (E->getOperator()) {
6976 case OO_New:
6977 case OO_Delete:
6978 case OO_Array_New:
6979 case OO_Array_Delete:
6980 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier4a9d7952012-08-08 18:46:20 +00006981
Douglas Gregor668d6d92009-12-13 20:44:55 +00006982 case OO_Call: {
6983 // This is a call to an object's operator().
6984 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6985
6986 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006987 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006988 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006989 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006990
6991 // FIXME: Poor location information
6992 SourceLocation FakeLParenLoc
6993 = SemaRef.PP.getLocForEndOfToken(
6994 static_cast<Expr *>(Object.get())->getLocEnd());
6995
6996 // Transform the call arguments.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006997 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006998 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006999 Args))
7000 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00007001
John McCall9ae2f072010-08-23 23:25:46 +00007002 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007003 Args,
Douglas Gregor668d6d92009-12-13 20:44:55 +00007004 E->getLocEnd());
7005 }
7006
7007#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7008 case OO_##Name:
7009#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7010#include "clang/Basic/OperatorKinds.def"
7011 case OO_Subscript:
7012 // Handled below.
7013 break;
7014
7015 case OO_Conditional:
7016 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00007017
7018 case OO_None:
7019 case NUM_OVERLOADED_OPERATORS:
7020 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00007021 }
7022
John McCall60d7b3a2010-08-24 06:29:42 +00007023 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007024 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007025 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007026
Richard Smithefeeccf2012-10-21 03:28:35 +00007027 ExprResult First;
7028 if (E->getOperator() == OO_Amp)
7029 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7030 else
7031 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007032 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007033 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007034
John McCall60d7b3a2010-08-24 06:29:42 +00007035 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00007036 if (E->getNumArgs() == 2) {
7037 Second = getDerived().TransformExpr(E->getArg(1));
7038 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007039 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007040 }
Mike Stump1eb44332009-09-09 15:08:12 +00007041
Douglas Gregorb98b1992009-08-11 05:31:07 +00007042 if (!getDerived().AlwaysRebuild() &&
7043 Callee.get() == E->getCallee() &&
7044 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00007045 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00007046 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007047
Lang Hamesbe9af122012-10-02 04:45:10 +00007048 Sema::FPContractStateRAII FPContractState(getSema());
7049 getSema().FPFeatures.fp_contract = E->isFPContractable();
7050
Douglas Gregorb98b1992009-08-11 05:31:07 +00007051 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7052 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007053 Callee.get(),
7054 First.get(),
7055 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007056}
Mike Stump1eb44332009-09-09 15:08:12 +00007057
Douglas Gregorb98b1992009-08-11 05:31:07 +00007058template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007059ExprResult
John McCall454feb92009-12-08 09:21:05 +00007060TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7061 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007062}
Mike Stump1eb44332009-09-09 15:08:12 +00007063
Douglas Gregorb98b1992009-08-11 05:31:07 +00007064template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007065ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00007066TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7067 // Transform the callee.
7068 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7069 if (Callee.isInvalid())
7070 return ExprError();
7071
7072 // Transform exec config.
7073 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7074 if (EC.isInvalid())
7075 return ExprError();
7076
7077 // Transform arguments.
7078 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007079 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007080 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007081 &ArgChanged))
7082 return ExprError();
7083
7084 if (!getDerived().AlwaysRebuild() &&
7085 Callee.get() == E->getCallee() &&
7086 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00007087 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00007088
7089 // FIXME: Wrong source location information for the '('.
7090 SourceLocation FakeLParenLoc
7091 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7092 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007093 Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007094 E->getRParenLoc(), EC.get());
7095}
7096
7097template<typename Derived>
7098ExprResult
John McCall454feb92009-12-08 09:21:05 +00007099TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007100 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7101 if (!Type)
7102 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007103
John McCall60d7b3a2010-08-24 06:29:42 +00007104 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007105 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007106 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007107 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007108
Douglas Gregorb98b1992009-08-11 05:31:07 +00007109 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007110 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007111 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007112 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007113 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00007114 E->getStmtClass(),
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007115 E->getAngleBrackets().getBegin(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007116 Type,
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007117 E->getAngleBrackets().getEnd(),
7118 // FIXME. this should be '(' location
7119 E->getAngleBrackets().getEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00007120 SubExpr.get(),
Abramo Bagnara6cf7d7d2012-10-15 21:08:58 +00007121 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007122}
Mike Stump1eb44332009-09-09 15:08:12 +00007123
Douglas Gregorb98b1992009-08-11 05:31:07 +00007124template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007125ExprResult
John McCall454feb92009-12-08 09:21:05 +00007126TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7127 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007128}
Mike Stump1eb44332009-09-09 15:08:12 +00007129
7130template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007131ExprResult
John McCall454feb92009-12-08 09:21:05 +00007132TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7133 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007134}
7135
Douglas Gregorb98b1992009-08-11 05:31:07 +00007136template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007137ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007138TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007139 CXXReinterpretCastExpr *E) {
7140 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007141}
Mike Stump1eb44332009-09-09 15:08:12 +00007142
Douglas Gregorb98b1992009-08-11 05:31:07 +00007143template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007144ExprResult
John McCall454feb92009-12-08 09:21:05 +00007145TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7146 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007147}
Mike Stump1eb44332009-09-09 15:08:12 +00007148
Douglas Gregorb98b1992009-08-11 05:31:07 +00007149template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007150ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007151TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007152 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007153 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7154 if (!Type)
7155 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007156
John McCall60d7b3a2010-08-24 06:29:42 +00007157 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007158 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007159 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007160 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007161
Douglas Gregorb98b1992009-08-11 05:31:07 +00007162 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007163 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007164 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007165 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007166
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007167 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007168 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007169 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007170 E->getRParenLoc());
7171}
Mike Stump1eb44332009-09-09 15:08:12 +00007172
Douglas Gregorb98b1992009-08-11 05:31:07 +00007173template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007174ExprResult
John McCall454feb92009-12-08 09:21:05 +00007175TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007176 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007177 TypeSourceInfo *TInfo
7178 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7179 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007180 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007181
Douglas Gregorb98b1992009-08-11 05:31:07 +00007182 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007183 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007184 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007185
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007186 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7187 E->getLocStart(),
7188 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007189 E->getLocEnd());
7190 }
Mike Stump1eb44332009-09-09 15:08:12 +00007191
Eli Friedmanef331b72012-01-20 01:26:23 +00007192 // We don't know whether the subexpression is potentially evaluated until
7193 // after we perform semantic analysis. We speculatively assume it is
7194 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007195 // potentially evaluated.
Eli Friedman80bfa3d2012-09-26 04:34:21 +00007196 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7197 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00007198
John McCall60d7b3a2010-08-24 06:29:42 +00007199 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007200 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007201 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007202
Douglas Gregorb98b1992009-08-11 05:31:07 +00007203 if (!getDerived().AlwaysRebuild() &&
7204 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007205 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007206
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007207 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7208 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007209 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007210 E->getLocEnd());
7211}
7212
7213template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007214ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007215TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7216 if (E->isTypeOperand()) {
7217 TypeSourceInfo *TInfo
7218 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7219 if (!TInfo)
7220 return ExprError();
7221
7222 if (!getDerived().AlwaysRebuild() &&
7223 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007224 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007225
Douglas Gregor3c52a212011-03-06 17:40:41 +00007226 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007227 E->getLocStart(),
7228 TInfo,
7229 E->getLocEnd());
7230 }
7231
Francois Pichet01b7c302010-09-08 12:20:18 +00007232 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7233
7234 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7235 if (SubExpr.isInvalid())
7236 return ExprError();
7237
7238 if (!getDerived().AlwaysRebuild() &&
7239 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007240 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007241
7242 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7243 E->getLocStart(),
7244 SubExpr.get(),
7245 E->getLocEnd());
7246}
7247
7248template<typename Derived>
7249ExprResult
John McCall454feb92009-12-08 09:21:05 +00007250TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007251 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007252}
Mike Stump1eb44332009-09-09 15:08:12 +00007253
Douglas Gregorb98b1992009-08-11 05:31:07 +00007254template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007255ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007256TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007257 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007258 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007259}
Mike Stump1eb44332009-09-09 15:08:12 +00007260
Douglas Gregorb98b1992009-08-11 05:31:07 +00007261template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007262ExprResult
John McCall454feb92009-12-08 09:21:05 +00007263TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007264 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00007265 QualType T;
7266 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
7267 T = MD->getThisType(getSema().Context);
Douglas Gregore4743be2013-03-08 22:43:48 +00007268 else if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(DC)) {
Richard Smith7a614d82011-06-11 17:19:42 +00007269 T = getSema().Context.getPointerType(
Douglas Gregore4743be2013-03-08 22:43:48 +00007270 getSema().Context.getRecordType(Record));
7271 } else {
7272 assert(SemaRef.Context.getDiagnostics().hasErrorOccurred() &&
7273 "this in the wrong scope?");
7274 return ExprError();
7275 }
Mike Stump1eb44332009-09-09 15:08:12 +00007276
Douglas Gregorec79d872012-02-24 17:41:38 +00007277 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7278 // Make sure that we capture 'this'.
7279 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007280 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007281 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007282
Douglas Gregor828a1972010-01-07 23:12:05 +00007283 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007284}
Mike Stump1eb44332009-09-09 15:08:12 +00007285
Douglas Gregorb98b1992009-08-11 05:31:07 +00007286template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007287ExprResult
John McCall454feb92009-12-08 09:21:05 +00007288TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007289 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007290 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007291 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007292
Douglas Gregorb98b1992009-08-11 05:31:07 +00007293 if (!getDerived().AlwaysRebuild() &&
7294 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007295 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007296
Douglas Gregorbca01b42011-07-06 22:04:06 +00007297 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7298 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007299}
Mike Stump1eb44332009-09-09 15:08:12 +00007300
Douglas Gregorb98b1992009-08-11 05:31:07 +00007301template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007302ExprResult
John McCall454feb92009-12-08 09:21:05 +00007303TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007304 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007305 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7306 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007307 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007308 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007309
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007310 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007311 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007312 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007313
Douglas Gregor036aed12009-12-23 23:03:06 +00007314 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007315}
Mike Stump1eb44332009-09-09 15:08:12 +00007316
Douglas Gregorb98b1992009-08-11 05:31:07 +00007317template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007318ExprResult
Richard Smithc3bf52c2013-04-20 22:23:05 +00007319TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
7320 FieldDecl *Field
7321 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
7322 E->getField()));
7323 if (!Field)
7324 return ExprError();
7325
7326 if (!getDerived().AlwaysRebuild() && Field == E->getField())
7327 return SemaRef.Owned(E);
7328
7329 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
7330}
7331
7332template<typename Derived>
7333ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007334TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7335 CXXScalarValueInitExpr *E) {
7336 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7337 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007338 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007339
Douglas Gregorb98b1992009-08-11 05:31:07 +00007340 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007341 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007342 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007343
Chad Rosier4a9d7952012-08-08 18:46:20 +00007344 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregorab6677e2010-09-08 00:15:04 +00007345 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007346 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007347}
Mike Stump1eb44332009-09-09 15:08:12 +00007348
Douglas Gregorb98b1992009-08-11 05:31:07 +00007349template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007350ExprResult
John McCall454feb92009-12-08 09:21:05 +00007351TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007352 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007353 TypeSourceInfo *AllocTypeInfo
7354 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7355 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007356 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007357
Douglas Gregorb98b1992009-08-11 05:31:07 +00007358 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007359 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007360 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007361 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007362
Douglas Gregorb98b1992009-08-11 05:31:07 +00007363 // Transform the placement arguments (if any).
7364 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007365 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007366 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregoraa165f82011-01-03 19:04:46 +00007367 E->getNumPlacementArgs(), true,
7368 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007369 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007370
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007371 // Transform the initializer (if any).
7372 Expr *OldInit = E->getInitializer();
7373 ExprResult NewInit;
7374 if (OldInit)
7375 NewInit = getDerived().TransformExpr(OldInit);
7376 if (NewInit.isInvalid())
7377 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007378
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007379 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007380 FunctionDecl *OperatorNew = 0;
7381 if (E->getOperatorNew()) {
7382 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007383 getDerived().TransformDecl(E->getLocStart(),
7384 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007385 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007386 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007387 }
7388
7389 FunctionDecl *OperatorDelete = 0;
7390 if (E->getOperatorDelete()) {
7391 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007392 getDerived().TransformDecl(E->getLocStart(),
7393 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007394 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007395 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007396 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007397
Douglas Gregorb98b1992009-08-11 05:31:07 +00007398 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007399 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007400 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007401 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007402 OperatorNew == E->getOperatorNew() &&
7403 OperatorDelete == E->getOperatorDelete() &&
7404 !ArgumentChanged) {
7405 // Mark any declarations we need as referenced.
7406 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007407 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007408 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007409 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007410 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007411
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007412 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007413 QualType ElementType
7414 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7415 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7416 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7417 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007418 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007419 }
7420 }
7421 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007422
John McCall3fa5cae2010-10-26 07:05:15 +00007423 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007424 }
Mike Stump1eb44332009-09-09 15:08:12 +00007425
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007426 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007427 if (!ArraySize.get()) {
7428 // If no array size was specified, but the new expression was
7429 // instantiated with an array type (e.g., "new T" where T is
7430 // instantiated with "int[4]"), extract the outer bound from the
7431 // array type as our array size. We do this with constant and
7432 // dependently-sized array types.
7433 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7434 if (!ArrayT) {
7435 // Do nothing
7436 } else if (const ConstantArrayType *ConsArrayT
7437 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007438 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007439 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier4a9d7952012-08-08 18:46:20 +00007440 ConsArrayT->getSize(),
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007441 SemaRef.Context.getSizeType(),
7442 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007443 AllocType = ConsArrayT->getElementType();
7444 } else if (const DependentSizedArrayType *DepArrayT
7445 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7446 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007447 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007448 AllocType = DepArrayT->getElementType();
7449 }
7450 }
7451 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007452
Douglas Gregorb98b1992009-08-11 05:31:07 +00007453 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7454 E->isGlobalNew(),
7455 /*FIXME:*/E->getLocStart(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007456 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007457 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007458 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007459 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007460 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007461 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007462 E->getDirectInitRange(),
7463 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007464}
Mike Stump1eb44332009-09-09 15:08:12 +00007465
Douglas Gregorb98b1992009-08-11 05:31:07 +00007466template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007467ExprResult
John McCall454feb92009-12-08 09:21:05 +00007468TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007469 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007470 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007471 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007472
Douglas Gregor1af74512010-02-26 00:38:10 +00007473 // Transform the delete operator, if known.
7474 FunctionDecl *OperatorDelete = 0;
7475 if (E->getOperatorDelete()) {
7476 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007477 getDerived().TransformDecl(E->getLocStart(),
7478 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007479 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007480 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007481 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007482
Douglas Gregorb98b1992009-08-11 05:31:07 +00007483 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007484 Operand.get() == E->getArgument() &&
7485 OperatorDelete == E->getOperatorDelete()) {
7486 // Mark any declarations we need as referenced.
7487 // FIXME: instantiation-specific.
7488 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007489 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007490
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007491 if (!E->getArgument()->isTypeDependent()) {
7492 QualType Destroyed = SemaRef.Context.getBaseElementType(
7493 E->getDestroyedType());
7494 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7495 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007496 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedman5f2987c2012-02-02 03:46:19 +00007497 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007498 }
7499 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007500
John McCall3fa5cae2010-10-26 07:05:15 +00007501 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007502 }
Mike Stump1eb44332009-09-09 15:08:12 +00007503
Douglas Gregorb98b1992009-08-11 05:31:07 +00007504 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7505 E->isGlobalDelete(),
7506 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007507 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007508}
Mike Stump1eb44332009-09-09 15:08:12 +00007509
Douglas Gregorb98b1992009-08-11 05:31:07 +00007510template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007511ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007512TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007513 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007514 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007515 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007516 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007517
John McCallb3d87482010-08-24 05:47:05 +00007518 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007519 bool MayBePseudoDestructor = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007520 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007521 E->getOperatorLoc(),
7522 E->isArrow()? tok::arrow : tok::period,
7523 ObjectTypePtr,
7524 MayBePseudoDestructor);
7525 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007526 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007527
John McCallb3d87482010-08-24 05:47:05 +00007528 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007529 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7530 if (QualifierLoc) {
7531 QualifierLoc
7532 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7533 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007534 return ExprError();
7535 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007536 CXXScopeSpec SS;
7537 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007538
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007539 PseudoDestructorTypeStorage Destroyed;
7540 if (E->getDestroyedTypeInfo()) {
7541 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007542 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007543 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007544 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007545 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007546 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007547 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007548 // We aren't likely to be able to resolve the identifier down to a type
7549 // now anyway, so just retain the identifier.
7550 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7551 E->getDestroyedTypeLoc());
7552 } else {
7553 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007554 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007555 *E->getDestroyedTypeIdentifier(),
7556 E->getDestroyedTypeLoc(),
7557 /*Scope=*/0,
7558 SS, ObjectTypePtr,
7559 false);
7560 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007561 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007562
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007563 Destroyed
7564 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7565 E->getDestroyedTypeLoc());
7566 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007567
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007568 TypeSourceInfo *ScopeTypeInfo = 0;
7569 if (E->getScopeTypeInfo()) {
Douglas Gregor303b96f2013-03-08 21:25:01 +00007570 CXXScopeSpec EmptySS;
7571 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
7572 E->getScopeTypeInfo(), ObjectType, 0, EmptySS);
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007573 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007574 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007575 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007576
John McCall9ae2f072010-08-23 23:25:46 +00007577 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007578 E->getOperatorLoc(),
7579 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007580 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007581 ScopeTypeInfo,
7582 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007583 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007584 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007585}
Mike Stump1eb44332009-09-09 15:08:12 +00007586
Douglas Gregora71d8192009-09-04 17:36:40 +00007587template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007588ExprResult
John McCallba135432009-11-21 08:51:07 +00007589TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007590 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007591 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7592 Sema::LookupOrdinaryName);
7593
7594 // Transform all the decls.
7595 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7596 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007597 NamedDecl *InstD = static_cast<NamedDecl*>(
7598 getDerived().TransformDecl(Old->getNameLoc(),
7599 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007600 if (!InstD) {
7601 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7602 // This can happen because of dependent hiding.
7603 if (isa<UsingShadowDecl>(*I))
7604 continue;
7605 else
John McCallf312b1e2010-08-26 23:41:50 +00007606 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007607 }
John McCallf7a1a742009-11-24 19:00:30 +00007608
7609 // Expand using declarations.
7610 if (isa<UsingDecl>(InstD)) {
7611 UsingDecl *UD = cast<UsingDecl>(InstD);
7612 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7613 E = UD->shadow_end(); I != E; ++I)
7614 R.addDecl(*I);
7615 continue;
7616 }
7617
7618 R.addDecl(InstD);
7619 }
7620
7621 // Resolve a kind, but don't do any further analysis. If it's
7622 // ambiguous, the callee needs to deal with it.
7623 R.resolveKind();
7624
7625 // Rebuild the nested-name qualifier, if present.
7626 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007627 if (Old->getQualifierLoc()) {
7628 NestedNameSpecifierLoc QualifierLoc
7629 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7630 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007631 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007632
Douglas Gregor4c9be892011-02-28 20:01:57 +00007633 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007634 }
7635
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007636 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007637 CXXRecordDecl *NamingClass
7638 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7639 Old->getNameLoc(),
7640 Old->getNamingClass()));
7641 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007642 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007643
Douglas Gregor66c45152010-04-27 16:10:10 +00007644 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007645 }
7646
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007647 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7648
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007649 // If we have neither explicit template arguments, nor the template keyword,
7650 // it's a normal declaration name.
7651 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007652 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7653
7654 // If we have template arguments, rebuild them, then rebuild the
7655 // templateid expression.
7656 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola02e221b2012-08-28 04:13:54 +00007657 if (Old->hasExplicitTemplateArgs() &&
7658 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregorfcc12532010-12-20 17:31:10 +00007659 Old->getNumTemplateArgs(),
7660 TransArgs))
7661 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007662
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007663 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007664 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007665}
Mike Stump1eb44332009-09-09 15:08:12 +00007666
Douglas Gregorb98b1992009-08-11 05:31:07 +00007667template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007668ExprResult
John McCall454feb92009-12-08 09:21:05 +00007669TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007670 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7671 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007672 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007673
Douglas Gregorb98b1992009-08-11 05:31:07 +00007674 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007675 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007676 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007677
Mike Stump1eb44332009-09-09 15:08:12 +00007678 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007679 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007680 T,
7681 E->getLocEnd());
7682}
Mike Stump1eb44332009-09-09 15:08:12 +00007683
Douglas Gregorb98b1992009-08-11 05:31:07 +00007684template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007685ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007686TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7687 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7688 if (!LhsT)
7689 return ExprError();
7690
7691 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7692 if (!RhsT)
7693 return ExprError();
7694
7695 if (!getDerived().AlwaysRebuild() &&
7696 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7697 return SemaRef.Owned(E);
7698
7699 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7700 E->getLocStart(),
7701 LhsT, RhsT,
7702 E->getLocEnd());
7703}
7704
7705template<typename Derived>
7706ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007707TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7708 bool ArgChanged = false;
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00007709 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007710 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7711 TypeSourceInfo *From = E->getArg(I);
7712 TypeLoc FromTL = From->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00007713 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007714 TypeLocBuilder TLB;
7715 TLB.reserve(FromTL.getFullDataSize());
7716 QualType To = getDerived().TransformType(TLB, FromTL);
7717 if (To.isNull())
7718 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007719
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007720 if (To == From->getType())
7721 Args.push_back(From);
7722 else {
7723 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7724 ArgChanged = true;
7725 }
7726 continue;
7727 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007728
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007729 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007730
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007731 // We have a pack expansion. Instantiate it.
David Blaikie39e6ab42013-02-18 22:06:02 +00007732 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007733 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7734 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7735 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007736
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007737 // Determine whether the set of unexpanded parameter packs can and should
7738 // be expanded.
7739 bool Expand = true;
7740 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00007741 Optional<unsigned> OrigNumExpansions =
7742 ExpansionTL.getTypePtr()->getNumExpansions();
7743 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007744 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7745 PatternTL.getSourceRange(),
7746 Unexpanded,
7747 Expand, RetainExpansion,
7748 NumExpansions))
7749 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007750
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007751 if (!Expand) {
7752 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00007753 // transformation on the pack expansion, producing another pack
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007754 // expansion.
7755 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007756
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007757 TypeLocBuilder TLB;
7758 TLB.reserve(From->getTypeLoc().getFullDataSize());
7759
7760 QualType To = getDerived().TransformType(TLB, PatternTL);
7761 if (To.isNull())
7762 return ExprError();
7763
Chad Rosier4a9d7952012-08-08 18:46:20 +00007764 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007765 PatternTL.getSourceRange(),
7766 ExpansionTL.getEllipsisLoc(),
7767 NumExpansions);
7768 if (To.isNull())
7769 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007770
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007771 PackExpansionTypeLoc ToExpansionTL
7772 = TLB.push<PackExpansionTypeLoc>(To);
7773 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7774 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7775 continue;
7776 }
7777
7778 // Expand the pack expansion by substituting for each argument in the
7779 // pack(s).
7780 for (unsigned I = 0; I != *NumExpansions; ++I) {
7781 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7782 TypeLocBuilder TLB;
7783 TLB.reserve(PatternTL.getFullDataSize());
7784 QualType To = getDerived().TransformType(TLB, PatternTL);
7785 if (To.isNull())
7786 return ExprError();
7787
7788 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7789 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007790
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007791 if (!RetainExpansion)
7792 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007793
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007794 // If we're supposed to retain a pack expansion, do so by temporarily
7795 // forgetting the partially-substituted parameter pack.
7796 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7797
7798 TypeLocBuilder TLB;
7799 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007800
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007801 QualType To = getDerived().TransformType(TLB, PatternTL);
7802 if (To.isNull())
7803 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007804
7805 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007806 PatternTL.getSourceRange(),
7807 ExpansionTL.getEllipsisLoc(),
7808 NumExpansions);
7809 if (To.isNull())
7810 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007811
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007812 PackExpansionTypeLoc ToExpansionTL
7813 = TLB.push<PackExpansionTypeLoc>(To);
7814 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7815 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7816 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007817
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007818 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7819 return SemaRef.Owned(E);
7820
7821 return getDerived().RebuildTypeTrait(E->getTrait(),
7822 E->getLocStart(),
7823 Args,
7824 E->getLocEnd());
7825}
7826
7827template<typename Derived>
7828ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007829TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7830 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7831 if (!T)
7832 return ExprError();
7833
7834 if (!getDerived().AlwaysRebuild() &&
7835 T == E->getQueriedTypeSourceInfo())
7836 return SemaRef.Owned(E);
7837
7838 ExprResult SubExpr;
7839 {
7840 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7841 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7842 if (SubExpr.isInvalid())
7843 return ExprError();
7844
7845 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7846 return SemaRef.Owned(E);
7847 }
7848
7849 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7850 E->getLocStart(),
7851 T,
7852 SubExpr.get(),
7853 E->getLocEnd());
7854}
7855
7856template<typename Derived>
7857ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007858TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7859 ExprResult SubExpr;
7860 {
7861 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7862 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7863 if (SubExpr.isInvalid())
7864 return ExprError();
7865
7866 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7867 return SemaRef.Owned(E);
7868 }
7869
7870 return getDerived().RebuildExpressionTrait(
7871 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7872}
7873
7874template<typename Derived>
7875ExprResult
John McCall865d4472009-11-19 22:55:06 +00007876TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007877 DependentScopeDeclRefExpr *E) {
Richard Smithefeeccf2012-10-21 03:28:35 +00007878 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
7879}
7880
7881template<typename Derived>
7882ExprResult
7883TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
7884 DependentScopeDeclRefExpr *E,
7885 bool IsAddressOfOperand) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007886 NestedNameSpecifierLoc QualifierLoc
7887 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7888 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007889 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007890 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00007891
John McCall43fed0d2010-11-12 08:19:04 +00007892 // TODO: If this is a conversion-function-id, verify that the
7893 // destination type name (if present) resolves the same way after
7894 // instantiation as it did in the local scope.
7895
Abramo Bagnara25777432010-08-11 22:01:17 +00007896 DeclarationNameInfo NameInfo
7897 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7898 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007899 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007900
John McCallf7a1a742009-11-24 19:00:30 +00007901 if (!E->hasExplicitTemplateArgs()) {
7902 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007903 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007904 // Note: it is sufficient to compare the Name component of NameInfo:
7905 // if name has not changed, DNLoc has not changed either.
7906 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007907 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007908
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007909 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007910 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007911 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00007912 /*TemplateArgs*/ 0,
7913 IsAddressOfOperand);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007914 }
John McCalld5532b62009-11-23 01:53:49 +00007915
7916 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007917 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7918 E->getNumTemplateArgs(),
7919 TransArgs))
7920 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007921
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007922 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007923 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007924 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00007925 &TransArgs,
7926 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007927}
7928
7929template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007930ExprResult
John McCall454feb92009-12-08 09:21:05 +00007931TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithc83c2302012-12-19 01:39:02 +00007932 // CXXConstructExprs other than for list-initialization and
7933 // CXXTemporaryObjectExpr are always implicit, so when we have
7934 // a 1-argument construction we just transform that argument.
Richard Smith73ed67c2012-11-26 08:32:48 +00007935 if ((E->getNumArgs() == 1 ||
7936 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithc83c2302012-12-19 01:39:02 +00007937 (!getDerived().DropCallArgument(E->getArg(0))) &&
7938 !E->isListInitialization())
Douglas Gregor321725d2010-02-03 03:01:57 +00007939 return getDerived().TransformExpr(E->getArg(0));
7940
Douglas Gregorb98b1992009-08-11 05:31:07 +00007941 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7942
7943 QualType T = getDerived().TransformType(E->getType());
7944 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007945 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007946
7947 CXXConstructorDecl *Constructor
7948 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007949 getDerived().TransformDecl(E->getLocStart(),
7950 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007951 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007952 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007953
Douglas Gregorb98b1992009-08-11 05:31:07 +00007954 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007955 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007956 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007957 &ArgumentChanged))
7958 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007959
Douglas Gregorb98b1992009-08-11 05:31:07 +00007960 if (!getDerived().AlwaysRebuild() &&
7961 T == E->getType() &&
7962 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007963 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007964 // Mark the constructor as referenced.
7965 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007966 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007967 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007968 }
Mike Stump1eb44332009-09-09 15:08:12 +00007969
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007970 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7971 Constructor, E->isElidable(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007972 Args,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007973 E->hadMultipleCandidates(),
Richard Smithc83c2302012-12-19 01:39:02 +00007974 E->isListInitialization(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007975 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007976 E->getConstructionKind(),
7977 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007978}
Mike Stump1eb44332009-09-09 15:08:12 +00007979
Douglas Gregorb98b1992009-08-11 05:31:07 +00007980/// \brief Transform a C++ temporary-binding expression.
7981///
Douglas Gregor51326552009-12-24 18:51:59 +00007982/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7983/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007984template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007985ExprResult
John McCall454feb92009-12-08 09:21:05 +00007986TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007987 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007988}
Mike Stump1eb44332009-09-09 15:08:12 +00007989
John McCall4765fa02010-12-06 08:20:24 +00007990/// \brief Transform a C++ expression that contains cleanups that should
7991/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007992///
John McCall4765fa02010-12-06 08:20:24 +00007993/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007994/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007995template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007996ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007997TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007998 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007999}
Mike Stump1eb44332009-09-09 15:08:12 +00008000
Douglas Gregorb98b1992009-08-11 05:31:07 +00008001template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008002ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008003TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00008004 CXXTemporaryObjectExpr *E) {
8005 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8006 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008007 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008008
Douglas Gregorb98b1992009-08-11 05:31:07 +00008009 CXXConstructorDecl *Constructor
8010 = cast_or_null<CXXConstructorDecl>(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008011 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008012 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008013 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00008014 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008015
Douglas Gregorb98b1992009-08-11 05:31:07 +00008016 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008017 SmallVector<Expr*, 8> Args;
Douglas Gregorb98b1992009-08-11 05:31:07 +00008018 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008019 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008020 &ArgumentChanged))
8021 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008022
Douglas Gregorb98b1992009-08-11 05:31:07 +00008023 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008024 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008025 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00008026 !ArgumentChanged) {
8027 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00008028 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00008029 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00008030 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008031
Richard Smithc83c2302012-12-19 01:39:02 +00008032 // FIXME: Pass in E->isListInitialization().
Douglas Gregorab6677e2010-09-08 00:15:04 +00008033 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8034 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008035 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008036 E->getLocEnd());
8037}
Mike Stump1eb44332009-09-09 15:08:12 +00008038
Douglas Gregorb98b1992009-08-11 05:31:07 +00008039template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008040ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00008041TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Douglas Gregordfca6f52012-02-13 22:00:16 +00008042 // Transform the type of the lambda parameters and start the definition of
8043 // the lambda itself.
8044 TypeSourceInfo *MethodTy
Chad Rosier4a9d7952012-08-08 18:46:20 +00008045 = TransformType(E->getCallOperator()->getTypeSourceInfo());
Douglas Gregordfca6f52012-02-13 22:00:16 +00008046 if (!MethodTy)
8047 return ExprError();
8048
Eli Friedman8da8a662012-09-19 01:18:11 +00008049 // Create the local class that will describe the lambda.
8050 CXXRecordDecl *Class
8051 = getSema().createLambdaClosureType(E->getIntroducerRange(),
8052 MethodTy,
8053 /*KnownDependent=*/false);
8054 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8055
Douglas Gregorc6889e72012-02-14 22:28:59 +00008056 // Transform lambda parameters.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008057 SmallVector<QualType, 4> ParamTypes;
8058 SmallVector<ParmVarDecl *, 4> Params;
Douglas Gregorc6889e72012-02-14 22:28:59 +00008059 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
8060 E->getCallOperator()->param_begin(),
8061 E->getCallOperator()->param_size(),
8062 0, ParamTypes, &Params))
Richard Smith612409e2012-07-25 03:56:55 +00008063 return ExprError();
Douglas Gregorc6889e72012-02-14 22:28:59 +00008064
Douglas Gregordfca6f52012-02-13 22:00:16 +00008065 // Build the call operator.
8066 CXXMethodDecl *CallOperator
8067 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00008068 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00008069 E->getCallOperator()->getLocEnd(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00008070 Params);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008071 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
Douglas Gregord5387e82012-02-14 00:00:48 +00008072
Richard Smith612409e2012-07-25 03:56:55 +00008073 return getDerived().TransformLambdaScope(E, CallOperator);
8074}
8075
8076template<typename Derived>
8077ExprResult
8078TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
8079 CXXMethodDecl *CallOperator) {
Douglas Gregord5387e82012-02-14 00:00:48 +00008080 // Introduce the context of the call operator.
8081 Sema::ContextRAII SavedContext(getSema(), CallOperator);
8082
Douglas Gregordfca6f52012-02-13 22:00:16 +00008083 // Enter the scope of the lambda.
8084 sema::LambdaScopeInfo *LSI
8085 = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(),
8086 E->getCaptureDefault(),
8087 E->hasExplicitParameters(),
8088 E->hasExplicitResultType(),
8089 E->isMutable());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008090
Douglas Gregordfca6f52012-02-13 22:00:16 +00008091 // Transform captures.
Richard Smith612409e2012-07-25 03:56:55 +00008092 bool Invalid = false;
Douglas Gregordfca6f52012-02-13 22:00:16 +00008093 bool FinishedExplicitCaptures = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008094 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008095 CEnd = E->capture_end();
8096 C != CEnd; ++C) {
8097 // When we hit the first implicit capture, tell Sema that we've finished
8098 // the list of explicit captures.
8099 if (!FinishedExplicitCaptures && C->isImplicit()) {
8100 getSema().finishLambdaExplicitCaptures(LSI);
8101 FinishedExplicitCaptures = true;
8102 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008103
Douglas Gregordfca6f52012-02-13 22:00:16 +00008104 // Capturing 'this' is trivial.
8105 if (C->capturesThis()) {
8106 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8107 continue;
8108 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008109
Douglas Gregora7365242012-02-14 19:27:52 +00008110 // Determine the capture kind for Sema.
8111 Sema::TryCaptureKind Kind
8112 = C->isImplicit()? Sema::TryCapture_Implicit
8113 : C->getCaptureKind() == LCK_ByCopy
8114 ? Sema::TryCapture_ExplicitByVal
8115 : Sema::TryCapture_ExplicitByRef;
8116 SourceLocation EllipsisLoc;
8117 if (C->isPackExpansion()) {
8118 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8119 bool ShouldExpand = false;
8120 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008121 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008122 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8123 C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008124 Unexpanded,
8125 ShouldExpand, RetainExpansion,
8126 NumExpansions))
8127 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008128
Douglas Gregora7365242012-02-14 19:27:52 +00008129 if (ShouldExpand) {
8130 // The transform has determined that we should perform an expansion;
8131 // transform and capture each of the arguments.
8132 // expansion of the pattern. Do so.
8133 VarDecl *Pack = C->getCapturedVar();
8134 for (unsigned I = 0; I != *NumExpansions; ++I) {
8135 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8136 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008137 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008138 Pack));
8139 if (!CapturedVar) {
8140 Invalid = true;
8141 continue;
8142 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008143
Douglas Gregora7365242012-02-14 19:27:52 +00008144 // Capture the transformed variable.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008145 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8146 }
Douglas Gregora7365242012-02-14 19:27:52 +00008147 continue;
8148 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008149
Douglas Gregora7365242012-02-14 19:27:52 +00008150 EllipsisLoc = C->getEllipsisLoc();
8151 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008152
Douglas Gregordfca6f52012-02-13 22:00:16 +00008153 // Transform the captured variable.
8154 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008155 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008156 C->getCapturedVar()));
8157 if (!CapturedVar) {
8158 Invalid = true;
8159 continue;
8160 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008161
Douglas Gregordfca6f52012-02-13 22:00:16 +00008162 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00008163 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008164 }
8165 if (!FinishedExplicitCaptures)
8166 getSema().finishLambdaExplicitCaptures(LSI);
8167
Douglas Gregordfca6f52012-02-13 22:00:16 +00008168
8169 // Enter a new evaluation context to insulate the lambda from any
8170 // cleanups from the enclosing full-expression.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008171 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008172
8173 if (Invalid) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008174 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregordfca6f52012-02-13 22:00:16 +00008175 /*IsInstantiation=*/true);
8176 return ExprError();
8177 }
8178
8179 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00008180 StmtResult Body = getDerived().TransformStmt(E->getBody());
8181 if (Body.isInvalid()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008182 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregord5387e82012-02-14 00:00:48 +00008183 /*IsInstantiation=*/true);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008184 return ExprError();
Douglas Gregord5387e82012-02-14 00:00:48 +00008185 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00008186
Chad Rosier4a9d7952012-08-08 18:46:20 +00008187 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00008188 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00008189}
8190
8191template<typename Derived>
8192ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008193TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00008194 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00008195 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8196 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008197 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008198
Douglas Gregorb98b1992009-08-11 05:31:07 +00008199 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008200 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008201 Args.reserve(E->arg_size());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008202 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008203 &ArgumentChanged))
8204 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008205
Douglas Gregorb98b1992009-08-11 05:31:07 +00008206 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008207 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008208 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008209 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008210
Douglas Gregorb98b1992009-08-11 05:31:07 +00008211 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00008212 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008213 E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008214 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008215 E->getRParenLoc());
8216}
Mike Stump1eb44332009-09-09 15:08:12 +00008217
Douglas Gregorb98b1992009-08-11 05:31:07 +00008218template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008219ExprResult
John McCall865d4472009-11-19 22:55:06 +00008220TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008221 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008222 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008223 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008224 Expr *OldBase;
8225 QualType BaseType;
8226 QualType ObjectType;
8227 if (!E->isImplicitAccess()) {
8228 OldBase = E->getBase();
8229 Base = getDerived().TransformExpr(OldBase);
8230 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008231 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008232
John McCallaa81e162009-12-01 22:10:20 +00008233 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008234 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008235 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008236 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008237 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008238 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008239 ObjectTy,
8240 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008241 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008242 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008243
John McCallb3d87482010-08-24 05:47:05 +00008244 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008245 BaseType = ((Expr*) Base.get())->getType();
8246 } else {
8247 OldBase = 0;
8248 BaseType = getDerived().TransformType(E->getBaseType());
8249 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8250 }
Mike Stump1eb44332009-09-09 15:08:12 +00008251
Douglas Gregor6cd21982009-10-20 05:58:46 +00008252 // Transform the first part of the nested-name-specifier that qualifies
8253 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008254 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008255 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008256 E->getFirstQualifierFoundInScope(),
8257 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008258
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008259 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008260 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008261 QualifierLoc
8262 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8263 ObjectType,
8264 FirstQualifierInScope);
8265 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008266 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008267 }
Mike Stump1eb44332009-09-09 15:08:12 +00008268
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008269 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8270
John McCall43fed0d2010-11-12 08:19:04 +00008271 // TODO: If this is a conversion-function-id, verify that the
8272 // destination type name (if present) resolves the same way after
8273 // instantiation as it did in the local scope.
8274
Abramo Bagnara25777432010-08-11 22:01:17 +00008275 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008276 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008277 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008278 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008279
John McCallaa81e162009-12-01 22:10:20 +00008280 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008281 // This is a reference to a member without an explicitly-specified
8282 // template argument list. Optimize for this common case.
8283 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008284 Base.get() == OldBase &&
8285 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008286 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008287 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008288 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008289 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008290
John McCall9ae2f072010-08-23 23:25:46 +00008291 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008292 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008293 E->isArrow(),
8294 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008295 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008296 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008297 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008298 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008299 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008300 }
8301
John McCalld5532b62009-11-23 01:53:49 +00008302 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008303 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8304 E->getNumTemplateArgs(),
8305 TransArgs))
8306 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008307
John McCall9ae2f072010-08-23 23:25:46 +00008308 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008309 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008310 E->isArrow(),
8311 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008312 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008313 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008314 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008315 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008316 &TransArgs);
8317}
8318
8319template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008320ExprResult
John McCall454feb92009-12-08 09:21:05 +00008321TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008322 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008323 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008324 QualType BaseType;
8325 if (!Old->isImplicitAccess()) {
8326 Base = getDerived().TransformExpr(Old->getBase());
8327 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008328 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008329 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8330 Old->isArrow());
8331 if (Base.isInvalid())
8332 return ExprError();
8333 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008334 } else {
8335 BaseType = getDerived().TransformType(Old->getBaseType());
8336 }
John McCall129e2df2009-11-30 22:42:35 +00008337
Douglas Gregor4c9be892011-02-28 20:01:57 +00008338 NestedNameSpecifierLoc QualifierLoc;
8339 if (Old->getQualifierLoc()) {
8340 QualifierLoc
8341 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8342 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008343 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008344 }
8345
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008346 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8347
Abramo Bagnara25777432010-08-11 22:01:17 +00008348 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008349 Sema::LookupOrdinaryName);
8350
8351 // Transform all the decls.
8352 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8353 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008354 NamedDecl *InstD = static_cast<NamedDecl*>(
8355 getDerived().TransformDecl(Old->getMemberLoc(),
8356 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008357 if (!InstD) {
8358 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8359 // This can happen because of dependent hiding.
8360 if (isa<UsingShadowDecl>(*I))
8361 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008362 else {
8363 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008364 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008365 }
John McCall9f54ad42009-12-10 09:41:52 +00008366 }
John McCall129e2df2009-11-30 22:42:35 +00008367
8368 // Expand using declarations.
8369 if (isa<UsingDecl>(InstD)) {
8370 UsingDecl *UD = cast<UsingDecl>(InstD);
8371 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8372 E = UD->shadow_end(); I != E; ++I)
8373 R.addDecl(*I);
8374 continue;
8375 }
8376
8377 R.addDecl(InstD);
8378 }
8379
8380 R.resolveKind();
8381
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008382 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008383 if (Old->getNamingClass()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008384 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008385 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008386 Old->getMemberLoc(),
8387 Old->getNamingClass()));
8388 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008389 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008390
Douglas Gregor66c45152010-04-27 16:10:10 +00008391 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008392 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008393
John McCall129e2df2009-11-30 22:42:35 +00008394 TemplateArgumentListInfo TransArgs;
8395 if (Old->hasExplicitTemplateArgs()) {
8396 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8397 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008398 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8399 Old->getNumTemplateArgs(),
8400 TransArgs))
8401 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008402 }
John McCallc2233c52010-01-15 08:34:02 +00008403
8404 // FIXME: to do this check properly, we will need to preserve the
8405 // first-qualifier-in-scope here, just in case we had a dependent
8406 // base (and therefore couldn't do the check) and a
8407 // nested-name-qualifier (and therefore could do the lookup).
8408 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008409
John McCall9ae2f072010-08-23 23:25:46 +00008410 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008411 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008412 Old->getOperatorLoc(),
8413 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008414 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008415 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008416 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008417 R,
8418 (Old->hasExplicitTemplateArgs()
8419 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008420}
8421
8422template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008423ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008424TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008425 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008426 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8427 if (SubExpr.isInvalid())
8428 return ExprError();
8429
8430 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008431 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008432
8433 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8434}
8435
8436template<typename Derived>
8437ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008438TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008439 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8440 if (Pattern.isInvalid())
8441 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008442
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008443 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8444 return SemaRef.Owned(E);
8445
Douglas Gregor67fd1252011-01-14 21:20:45 +00008446 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8447 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008448}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008449
8450template<typename Derived>
8451ExprResult
8452TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8453 // If E is not value-dependent, then nothing will change when we transform it.
8454 // Note: This is an instantiation-centric view.
8455 if (!E->isValueDependent())
8456 return SemaRef.Owned(E);
8457
8458 // Note: None of the implementations of TryExpandParameterPacks can ever
8459 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier4a9d7952012-08-08 18:46:20 +00008460 // so
Douglas Gregoree8aff02011-01-04 17:33:58 +00008461 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8462 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008463 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008464 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008465 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008466 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008467 ShouldExpand, RetainExpansion,
8468 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008469 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008470
Douglas Gregor089e8932011-10-10 18:59:29 +00008471 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008472 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008473
Douglas Gregor089e8932011-10-10 18:59:29 +00008474 NamedDecl *Pack = E->getPack();
8475 if (!ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008476 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008477 Pack));
8478 if (!Pack)
8479 return ExprError();
8480 }
8481
Chad Rosier4a9d7952012-08-08 18:46:20 +00008482
Douglas Gregoree8aff02011-01-04 17:33:58 +00008483 // We now know the length of the parameter pack, so build a new expression
8484 // that stores that length.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008485 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8486 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008487 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008488}
8489
Douglas Gregorbe230c32011-01-03 17:17:50 +00008490template<typename Derived>
8491ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008492TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8493 SubstNonTypeTemplateParmPackExpr *E) {
8494 // Default behavior is to do nothing with this transformation.
8495 return SemaRef.Owned(E);
8496}
8497
8498template<typename Derived>
8499ExprResult
John McCall91a57552011-07-15 05:09:51 +00008500TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8501 SubstNonTypeTemplateParmExpr *E) {
8502 // Default behavior is to do nothing with this transformation.
8503 return SemaRef.Owned(E);
8504}
8505
8506template<typename Derived>
8507ExprResult
Richard Smith9a4db032012-09-12 00:56:43 +00008508TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8509 // Default behavior is to do nothing with this transformation.
8510 return SemaRef.Owned(E);
8511}
8512
8513template<typename Derived>
8514ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008515TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8516 MaterializeTemporaryExpr *E) {
8517 return getDerived().TransformExpr(E->GetTemporaryExpr());
8518}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008519
Douglas Gregor03e80032011-06-21 17:03:29 +00008520template<typename Derived>
8521ExprResult
John McCall454feb92009-12-08 09:21:05 +00008522TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008523 return SemaRef.MaybeBindToTemporary(E);
8524}
8525
8526template<typename Derived>
8527ExprResult
8528TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008529 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008530}
8531
8532template<typename Derived>
8533ExprResult
Patrick Beardeb382ec2012-04-19 00:25:12 +00008534TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8535 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8536 if (SubExpr.isInvalid())
8537 return ExprError();
8538
8539 if (!getDerived().AlwaysRebuild() &&
8540 SubExpr.get() == E->getSubExpr())
8541 return SemaRef.Owned(E);
8542
8543 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008544}
8545
8546template<typename Derived>
8547ExprResult
8548TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8549 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008550 SmallVector<Expr *, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008551 bool ArgChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008552 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008553 /*IsCall=*/false, Elements, &ArgChanged))
8554 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008555
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008556 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8557 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008558
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008559 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8560 Elements.data(),
8561 Elements.size());
8562}
8563
8564template<typename Derived>
8565ExprResult
8566TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008567 ObjCDictionaryLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008568 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008569 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008570 bool ArgChanged = false;
8571 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8572 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008573
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008574 if (OrigElement.isPackExpansion()) {
8575 // This key/value element is a pack expansion.
8576 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8577 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8578 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8579 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8580
8581 // Determine whether the set of unexpanded parameter packs can
8582 // and should be expanded.
8583 bool Expand = true;
8584 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008585 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8586 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008587 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8588 OrigElement.Value->getLocEnd());
8589 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8590 PatternRange,
8591 Unexpanded,
8592 Expand, RetainExpansion,
8593 NumExpansions))
8594 return ExprError();
8595
8596 if (!Expand) {
8597 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00008598 // transformation on the pack expansion, producing another pack
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008599 // expansion.
8600 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8601 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8602 if (Key.isInvalid())
8603 return ExprError();
8604
8605 if (Key.get() != OrigElement.Key)
8606 ArgChanged = true;
8607
8608 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8609 if (Value.isInvalid())
8610 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008611
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008612 if (Value.get() != OrigElement.Value)
8613 ArgChanged = true;
8614
Chad Rosier4a9d7952012-08-08 18:46:20 +00008615 ObjCDictionaryElement Expansion = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008616 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8617 };
8618 Elements.push_back(Expansion);
8619 continue;
8620 }
8621
8622 // Record right away that the argument was changed. This needs
8623 // to happen even if the array expands to nothing.
8624 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008625
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008626 // The transform has determined that we should perform an elementwise
8627 // expansion of the pattern. Do so.
8628 for (unsigned I = 0; I != *NumExpansions; ++I) {
8629 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8630 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8631 if (Key.isInvalid())
8632 return ExprError();
8633
8634 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8635 if (Value.isInvalid())
8636 return ExprError();
8637
Chad Rosier4a9d7952012-08-08 18:46:20 +00008638 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008639 Key.get(), Value.get(), SourceLocation(), NumExpansions
8640 };
8641
8642 // If any unexpanded parameter packs remain, we still have a
8643 // pack expansion.
8644 if (Key.get()->containsUnexpandedParameterPack() ||
8645 Value.get()->containsUnexpandedParameterPack())
8646 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008647
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008648 Elements.push_back(Element);
8649 }
8650
8651 // We've finished with this pack expansion.
8652 continue;
8653 }
8654
8655 // Transform and check key.
8656 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8657 if (Key.isInvalid())
8658 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008659
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008660 if (Key.get() != OrigElement.Key)
8661 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008662
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008663 // Transform and check value.
8664 ExprResult Value
8665 = getDerived().TransformExpr(OrigElement.Value);
8666 if (Value.isInvalid())
8667 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008668
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008669 if (Value.get() != OrigElement.Value)
8670 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008671
8672 ObjCDictionaryElement Element = {
David Blaikie66874fb2013-02-21 01:47:18 +00008673 Key.get(), Value.get(), SourceLocation(), None
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008674 };
8675 Elements.push_back(Element);
8676 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008677
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008678 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8679 return SemaRef.MaybeBindToTemporary(E);
8680
8681 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8682 Elements.data(),
8683 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008684}
8685
Mike Stump1eb44332009-09-09 15:08:12 +00008686template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008687ExprResult
John McCall454feb92009-12-08 09:21:05 +00008688TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008689 TypeSourceInfo *EncodedTypeInfo
8690 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8691 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008692 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008693
Douglas Gregorb98b1992009-08-11 05:31:07 +00008694 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008695 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008696 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008697
8698 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008699 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008700 E->getRParenLoc());
8701}
Mike Stump1eb44332009-09-09 15:08:12 +00008702
Douglas Gregorb98b1992009-08-11 05:31:07 +00008703template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00008704ExprResult TreeTransform<Derived>::
8705TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCall93b64572013-04-11 02:14:26 +00008706 // This is a kind of implicit conversion, and it needs to get dropped
8707 // and recomputed for the same general reasons that ImplicitCastExprs
8708 // do, as well a more specific one: this expression is only valid when
8709 // it appears *immediately* as an argument expression.
8710 return getDerived().TransformExpr(E->getSubExpr());
John McCallf85e1932011-06-15 23:02:42 +00008711}
8712
8713template<typename Derived>
8714ExprResult TreeTransform<Derived>::
8715TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008716 TypeSourceInfo *TSInfo
John McCallf85e1932011-06-15 23:02:42 +00008717 = getDerived().TransformType(E->getTypeInfoAsWritten());
8718 if (!TSInfo)
8719 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008720
John McCallf85e1932011-06-15 23:02:42 +00008721 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008722 if (Result.isInvalid())
John McCallf85e1932011-06-15 23:02:42 +00008723 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008724
John McCallf85e1932011-06-15 23:02:42 +00008725 if (!getDerived().AlwaysRebuild() &&
8726 TSInfo == E->getTypeInfoAsWritten() &&
8727 Result.get() == E->getSubExpr())
8728 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008729
John McCallf85e1932011-06-15 23:02:42 +00008730 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00008731 E->getBridgeKeywordLoc(), TSInfo,
John McCallf85e1932011-06-15 23:02:42 +00008732 Result.get());
8733}
8734
8735template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008736ExprResult
John McCall454feb92009-12-08 09:21:05 +00008737TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008738 // Transform arguments.
8739 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008740 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008741 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008742 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008743 &ArgChanged))
8744 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008745
Douglas Gregor92e986e2010-04-22 16:44:27 +00008746 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8747 // Class message: transform the receiver type.
8748 TypeSourceInfo *ReceiverTypeInfo
8749 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8750 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008751 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008752
Douglas Gregor92e986e2010-04-22 16:44:27 +00008753 // If nothing changed, just retain the existing message send.
8754 if (!getDerived().AlwaysRebuild() &&
8755 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008756 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008757
8758 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008759 SmallVector<SourceLocation, 16> SelLocs;
8760 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008761 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8762 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008763 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008764 E->getMethodDecl(),
8765 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008766 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008767 E->getRightLoc());
8768 }
8769
8770 // Instance message: transform the receiver
8771 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8772 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00008773 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00008774 = getDerived().TransformExpr(E->getInstanceReceiver());
8775 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008776 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00008777
8778 // If nothing changed, just retain the existing message send.
8779 if (!getDerived().AlwaysRebuild() &&
8780 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008781 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008782
Douglas Gregor92e986e2010-04-22 16:44:27 +00008783 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008784 SmallVector<SourceLocation, 16> SelLocs;
8785 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00008786 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00008787 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008788 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008789 E->getMethodDecl(),
8790 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008791 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008792 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008793}
8794
Mike Stump1eb44332009-09-09 15:08:12 +00008795template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008796ExprResult
John McCall454feb92009-12-08 09:21:05 +00008797TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008798 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008799}
8800
Mike Stump1eb44332009-09-09 15:08:12 +00008801template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008802ExprResult
John McCall454feb92009-12-08 09:21:05 +00008803TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008804 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008805}
8806
Mike Stump1eb44332009-09-09 15:08:12 +00008807template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008808ExprResult
John McCall454feb92009-12-08 09:21:05 +00008809TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008810 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008811 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008812 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008813 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008814
8815 // We don't need to transform the ivar; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008816
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008817 // If nothing changed, just retain the existing expression.
8818 if (!getDerived().AlwaysRebuild() &&
8819 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008820 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008821
John McCall9ae2f072010-08-23 23:25:46 +00008822 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008823 E->getLocation(),
8824 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008825}
8826
Mike Stump1eb44332009-09-09 15:08:12 +00008827template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008828ExprResult
John McCall454feb92009-12-08 09:21:05 +00008829TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00008830 // 'super' and types never change. Property never changes. Just
8831 // retain the existing expression.
8832 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00008833 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008834
Douglas Gregore3303542010-04-26 20:47:02 +00008835 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008836 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00008837 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008838 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008839
Douglas Gregore3303542010-04-26 20:47:02 +00008840 // We don't need to transform the property; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008841
Douglas Gregore3303542010-04-26 20:47:02 +00008842 // If nothing changed, just retain the existing expression.
8843 if (!getDerived().AlwaysRebuild() &&
8844 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008845 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008846
John McCall12f78a62010-12-02 01:19:52 +00008847 if (E->isExplicitProperty())
8848 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8849 E->getExplicitProperty(),
8850 E->getLocation());
8851
8852 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00008853 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00008854 E->getImplicitPropertyGetter(),
8855 E->getImplicitPropertySetter(),
8856 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008857}
8858
Mike Stump1eb44332009-09-09 15:08:12 +00008859template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008860ExprResult
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008861TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
8862 // Transform the base expression.
8863 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
8864 if (Base.isInvalid())
8865 return ExprError();
8866
8867 // Transform the key expression.
8868 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
8869 if (Key.isInvalid())
8870 return ExprError();
8871
8872 // If nothing changed, just retain the existing expression.
8873 if (!getDerived().AlwaysRebuild() &&
8874 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
8875 return SemaRef.Owned(E);
8876
Chad Rosier4a9d7952012-08-08 18:46:20 +00008877 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008878 Base.get(), Key.get(),
8879 E->getAtIndexMethodDecl(),
8880 E->setAtIndexMethodDecl());
8881}
8882
8883template<typename Derived>
8884ExprResult
John McCall454feb92009-12-08 09:21:05 +00008885TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008886 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008887 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008888 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008889 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008890
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008891 // If nothing changed, just retain the existing expression.
8892 if (!getDerived().AlwaysRebuild() &&
8893 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008894 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008895
John McCall9ae2f072010-08-23 23:25:46 +00008896 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00008897 E->getOpLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008898 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008899}
8900
Mike Stump1eb44332009-09-09 15:08:12 +00008901template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008902ExprResult
John McCall454feb92009-12-08 09:21:05 +00008903TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008904 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008905 SmallVector<Expr*, 8> SubExprs;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008906 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008907 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008908 SubExprs, &ArgumentChanged))
8909 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008910
Douglas Gregorb98b1992009-08-11 05:31:07 +00008911 if (!getDerived().AlwaysRebuild() &&
8912 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008913 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008914
Douglas Gregorb98b1992009-08-11 05:31:07 +00008915 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008916 SubExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008917 E->getRParenLoc());
8918}
8919
Mike Stump1eb44332009-09-09 15:08:12 +00008920template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008921ExprResult
John McCall454feb92009-12-08 09:21:05 +00008922TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008923 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008924
John McCallc6ac9c32011-02-04 18:33:18 +00008925 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8926 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8927
8928 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00008929 blockScope->TheDecl->setBlockMissingReturnType(
8930 oldBlock->blockMissingReturnType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008931
Chris Lattner686775d2011-07-20 06:58:45 +00008932 SmallVector<ParmVarDecl*, 4> params;
8933 SmallVector<QualType, 4> paramTypes;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008934
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008935 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008936 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8937 oldBlock->param_begin(),
8938 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008939 0, paramTypes, &params)) {
8940 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00008941 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008942 }
John McCallc6ac9c32011-02-04 18:33:18 +00008943
Jordan Rose09189892013-03-08 22:25:36 +00008944 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00008945 QualType exprResultType =
8946 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00008947
8948 // Don't allow returning a objc interface by value.
Eli Friedman84b007f2012-01-26 03:00:14 +00008949 if (exprResultType->isObjCObjectType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008950 getSema().Diag(E->getCaretLocation(),
8951 diag::err_object_cannot_be_passed_returned_by_value)
Eli Friedman84b007f2012-01-26 03:00:14 +00008952 << 0 << exprResultType;
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008953 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregora779d9c2011-01-19 21:32:01 +00008954 return ExprError();
8955 }
John McCall711c52b2011-01-05 12:14:39 +00008956
Jordan Rosebea522f2013-03-08 21:51:21 +00008957 QualType functionType =
8958 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rose09189892013-03-08 22:25:36 +00008959 exprFunctionType->getExtProtoInfo());
John McCallc6ac9c32011-02-04 18:33:18 +00008960 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00008961
8962 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00008963 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00008964 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00008965
8966 if (!oldBlock->blockMissingReturnType()) {
8967 blockScope->HasImplicitReturnType = false;
8968 blockScope->ReturnType = exprResultType;
8969 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008970
John McCall711c52b2011-01-05 12:14:39 +00008971 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00008972 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008973 if (body.isInvalid()) {
8974 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00008975 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008976 }
John McCall711c52b2011-01-05 12:14:39 +00008977
John McCallc6ac9c32011-02-04 18:33:18 +00008978#ifndef NDEBUG
8979 // In builds with assertions, make sure that we captured everything we
8980 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00008981 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8982 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8983 e = oldBlock->capture_end(); i != e; ++i) {
8984 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00008985
Douglas Gregorfc921372011-05-20 15:32:55 +00008986 // Ignore parameter packs.
8987 if (isa<ParmVarDecl>(oldCapture) &&
8988 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8989 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00008990
Douglas Gregorfc921372011-05-20 15:32:55 +00008991 VarDecl *newCapture =
8992 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8993 oldCapture));
8994 assert(blockScope->CaptureMap.count(newCapture));
8995 }
Douglas Gregorec79d872012-02-24 17:41:38 +00008996 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00008997 }
8998#endif
8999
9000 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
9001 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009002}
9003
Mike Stump1eb44332009-09-09 15:08:12 +00009004template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009005ExprResult
Tanya Lattner61eee0c2011-06-04 00:47:47 +00009006TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00009007 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00009008}
Eli Friedman276b0612011-10-11 02:20:01 +00009009
9010template<typename Derived>
9011ExprResult
9012TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009013 QualType RetTy = getDerived().TransformType(E->getType());
9014 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00009015 SmallVector<Expr*, 8> SubExprs;
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009016 SubExprs.reserve(E->getNumSubExprs());
9017 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9018 SubExprs, &ArgumentChanged))
9019 return ExprError();
9020
9021 if (!getDerived().AlwaysRebuild() &&
9022 !ArgumentChanged)
9023 return SemaRef.Owned(E);
9024
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009025 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009026 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00009027}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009028
Douglas Gregorb98b1992009-08-11 05:31:07 +00009029//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00009030// Type reconstruction
9031//===----------------------------------------------------------------------===//
9032
Mike Stump1eb44332009-09-09 15:08:12 +00009033template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00009034QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9035 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00009036 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009037 getDerived().getBaseEntity());
9038}
9039
Mike Stump1eb44332009-09-09 15:08:12 +00009040template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00009041QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9042 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00009043 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009044 getDerived().getBaseEntity());
9045}
9046
Mike Stump1eb44332009-09-09 15:08:12 +00009047template<typename Derived>
9048QualType
John McCall85737a72009-10-30 00:06:24 +00009049TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9050 bool WrittenAsLValue,
9051 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00009052 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00009053 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009054}
9055
9056template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009057QualType
John McCall85737a72009-10-30 00:06:24 +00009058TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9059 QualType ClassType,
9060 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00009061 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00009062 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009063}
9064
9065template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009066QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00009067TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9068 ArrayType::ArraySizeModifier SizeMod,
9069 const llvm::APInt *Size,
9070 Expr *SizeExpr,
9071 unsigned IndexTypeQuals,
9072 SourceRange BracketsRange) {
9073 if (SizeExpr || !Size)
9074 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9075 IndexTypeQuals, BracketsRange,
9076 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00009077
9078 QualType Types[] = {
9079 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9080 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9081 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00009082 };
9083 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
9084 QualType SizeType;
9085 for (unsigned I = 0; I != NumTypes; ++I)
9086 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9087 SizeType = Types[I];
9088 break;
9089 }
Mike Stump1eb44332009-09-09 15:08:12 +00009090
Eli Friedman01f276d2012-01-25 23:20:27 +00009091 // Note that we can return a VariableArrayType here in the case where
9092 // the element type was a dependent VariableArrayType.
9093 IntegerLiteral *ArraySize
9094 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9095 /*FIXME*/BracketsRange.getBegin());
9096 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009097 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00009098 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009099}
Mike Stump1eb44332009-09-09 15:08:12 +00009100
Douglas Gregor577f75a2009-08-04 16:50:30 +00009101template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009102QualType
9103TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009104 ArrayType::ArraySizeModifier SizeMod,
9105 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00009106 unsigned IndexTypeQuals,
9107 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009108 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00009109 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009110}
9111
9112template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009113QualType
Mike Stump1eb44332009-09-09 15:08:12 +00009114TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009115 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00009116 unsigned IndexTypeQuals,
9117 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009118 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00009119 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009120}
Mike Stump1eb44332009-09-09 15:08:12 +00009121
Douglas Gregor577f75a2009-08-04 16:50:30 +00009122template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009123QualType
9124TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009125 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009126 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009127 unsigned IndexTypeQuals,
9128 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009129 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009130 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009131 IndexTypeQuals, BracketsRange);
9132}
9133
9134template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009135QualType
9136TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009137 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009138 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009139 unsigned IndexTypeQuals,
9140 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009141 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009142 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009143 IndexTypeQuals, BracketsRange);
9144}
9145
9146template<typename Derived>
9147QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00009148 unsigned NumElements,
9149 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00009150 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00009151 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009152}
Mike Stump1eb44332009-09-09 15:08:12 +00009153
Douglas Gregor577f75a2009-08-04 16:50:30 +00009154template<typename Derived>
9155QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9156 unsigned NumElements,
9157 SourceLocation AttributeLoc) {
9158 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9159 NumElements, true);
9160 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00009161 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9162 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00009163 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009164}
Mike Stump1eb44332009-09-09 15:08:12 +00009165
Douglas Gregor577f75a2009-08-04 16:50:30 +00009166template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009167QualType
9168TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00009169 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009170 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00009171 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009172}
Mike Stump1eb44332009-09-09 15:08:12 +00009173
Douglas Gregor577f75a2009-08-04 16:50:30 +00009174template<typename Derived>
Jordan Rosebea522f2013-03-08 21:51:21 +00009175QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9176 QualType T,
9177 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00009178 const FunctionProtoType::ExtProtoInfo &EPI) {
9179 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009180 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00009181 getDerived().getBaseEntity(),
Jordan Rose09189892013-03-08 22:25:36 +00009182 EPI);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009183}
Mike Stump1eb44332009-09-09 15:08:12 +00009184
Douglas Gregor577f75a2009-08-04 16:50:30 +00009185template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00009186QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9187 return SemaRef.Context.getFunctionNoProtoType(T);
9188}
9189
9190template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00009191QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9192 assert(D && "no decl found");
9193 if (D->isInvalidDecl()) return QualType();
9194
Douglas Gregor92e986e2010-04-22 16:44:27 +00009195 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00009196 TypeDecl *Ty;
9197 if (isa<UsingDecl>(D)) {
9198 UsingDecl *Using = cast<UsingDecl>(D);
9199 assert(Using->isTypeName() &&
9200 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9201
9202 // A valid resolved using typename decl points to exactly one type decl.
9203 assert(++Using->shadow_begin() == Using->shadow_end());
9204 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009205
John McCalled976492009-12-04 22:46:56 +00009206 } else {
9207 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9208 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9209 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9210 }
9211
9212 return SemaRef.Context.getTypeDeclType(Ty);
9213}
9214
9215template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009216QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9217 SourceLocation Loc) {
9218 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009219}
9220
9221template<typename Derived>
9222QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9223 return SemaRef.Context.getTypeOfType(Underlying);
9224}
9225
9226template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009227QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9228 SourceLocation Loc) {
9229 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009230}
9231
9232template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009233QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9234 UnaryTransformType::UTTKind UKind,
9235 SourceLocation Loc) {
9236 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9237}
9238
9239template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009240QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009241 TemplateName Template,
9242 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009243 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009244 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009245}
Mike Stump1eb44332009-09-09 15:08:12 +00009246
Douglas Gregordcee1a12009-08-06 05:28:30 +00009247template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009248QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9249 SourceLocation KWLoc) {
9250 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9251}
9252
9253template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009254TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009255TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009256 bool TemplateKW,
9257 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009258 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009259 Template);
9260}
9261
9262template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009263TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009264TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9265 const IdentifierInfo &Name,
9266 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009267 QualType ObjectType,
9268 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009269 UnqualifiedId TemplateName;
9270 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009271 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009272 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009273 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009274 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009275 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009276 /*EnteringContext=*/false,
9277 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009278 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009279}
Mike Stump1eb44332009-09-09 15:08:12 +00009280
Douglas Gregorb98b1992009-08-11 05:31:07 +00009281template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009282TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009283TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009284 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009285 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009286 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009287 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009288 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009289 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009290 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009291 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009292 Sema::TemplateTy Template;
9293 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009294 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009295 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009296 /*EnteringContext=*/false,
9297 Template);
9298 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009299}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009300
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009301template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009302ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009303TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9304 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009305 Expr *OrigCallee,
9306 Expr *First,
9307 Expr *Second) {
9308 Expr *Callee = OrigCallee->IgnoreParenCasts();
9309 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009310
Douglas Gregorb98b1992009-08-11 05:31:07 +00009311 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009312 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009313 if (!First->getType()->isOverloadableType() &&
9314 !Second->getType()->isOverloadableType())
9315 return getSema().CreateBuiltinArraySubscriptExpr(First,
9316 Callee->getLocStart(),
9317 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009318 } else if (Op == OO_Arrow) {
9319 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009320 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9321 } else if (Second == 0 || isPostIncDec) {
9322 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009323 // The argument is not of overloadable type, so try to create a
9324 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009325 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009326 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009327
John McCall9ae2f072010-08-23 23:25:46 +00009328 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009329 }
9330 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009331 if (!First->getType()->isOverloadableType() &&
9332 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009333 // Neither of the arguments is an overloadable type, so try to
9334 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009335 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009336 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009337 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009338 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009339 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009340
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009341 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009342 }
9343 }
Mike Stump1eb44332009-09-09 15:08:12 +00009344
9345 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009346 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009347 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009348
John McCall9ae2f072010-08-23 23:25:46 +00009349 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009350 assert(ULE->requiresADL());
9351
9352 // FIXME: Do we have to check
9353 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009354 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009355 } else {
Richard Smithf6411662012-11-28 21:47:39 +00009356 // If we've resolved this to a particular non-member function, just call
9357 // that function. If we resolved it to a member function,
9358 // CreateOverloaded* will find that function for us.
9359 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9360 if (!isa<CXXMethodDecl>(ND))
9361 Functions.addDecl(ND);
John McCallba135432009-11-21 08:51:07 +00009362 }
Mike Stump1eb44332009-09-09 15:08:12 +00009363
Douglas Gregorb98b1992009-08-11 05:31:07 +00009364 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009365 Expr *Args[2] = { First, Second };
9366 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009367
Douglas Gregorb98b1992009-08-11 05:31:07 +00009368 // Create the overloaded operator invocation for unary operators.
9369 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009370 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009371 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009372 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009373 }
Mike Stump1eb44332009-09-09 15:08:12 +00009374
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009375 if (Op == OO_Subscript) {
9376 SourceLocation LBrace;
9377 SourceLocation RBrace;
9378
9379 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9380 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9381 LBrace = SourceLocation::getFromRawEncoding(
9382 NameLoc.CXXOperatorName.BeginOpNameLoc);
9383 RBrace = SourceLocation::getFromRawEncoding(
9384 NameLoc.CXXOperatorName.EndOpNameLoc);
9385 } else {
9386 LBrace = Callee->getLocStart();
9387 RBrace = OpLoc;
9388 }
9389
9390 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9391 First, Second);
9392 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009393
Douglas Gregorb98b1992009-08-11 05:31:07 +00009394 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009395 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009396 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009397 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9398 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009399 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009400
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009401 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009402}
Mike Stump1eb44332009-09-09 15:08:12 +00009403
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009404template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00009405ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009406TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009407 SourceLocation OperatorLoc,
9408 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009409 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009410 TypeSourceInfo *ScopeType,
9411 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009412 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009413 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009414 QualType BaseType = Base->getType();
9415 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009416 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00009417 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009418 !BaseType->getAs<PointerType>()->getPointeeType()
9419 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009420 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009421 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009422 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009423 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009424 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009425 /*FIXME?*/true);
9426 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009427
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009428 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009429 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9430 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9431 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9432 NameInfo.setNamedTypeInfo(DestroyedType);
9433
Richard Smith6314db92012-05-15 06:15:11 +00009434 // The scope type is now known to be a valid nested name specifier
9435 // component. Tack it on to the end of the nested name specifier.
9436 if (ScopeType)
9437 SS.Extend(SemaRef.Context, SourceLocation(),
9438 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnara25777432010-08-11 22:01:17 +00009439
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009440 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009441 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009442 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009443 SS, TemplateKWLoc,
9444 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009445 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009446 /*TemplateArgs*/ 0);
9447}
9448
Tareq A. Siraj051303c2013-04-16 18:53:08 +00009449template<typename Derived>
9450StmtResult
9451TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan9fd6b8f2013-05-04 03:59:06 +00009452 SourceLocation Loc = S->getLocStart();
9453 unsigned NumParams = S->getCapturedDecl()->getNumParams();
9454 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/0,
9455 S->getCapturedRegionKind(), NumParams);
9456 StmtResult Body = getDerived().TransformStmt(S->getCapturedStmt());
9457
9458 if (Body.isInvalid()) {
9459 getSema().ActOnCapturedRegionError();
9460 return StmtError();
9461 }
9462
9463 return getSema().ActOnCapturedRegionEnd(Body.take());
Tareq A. Siraj051303c2013-04-16 18:53:08 +00009464}
9465
Douglas Gregor577f75a2009-08-04 16:50:30 +00009466} // end namespace clang
9467
9468#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H