blob: 3fcd0375d084226048f2362d4d916de9f4020c82 [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,
Dmitri Gribenko80613222013-05-10 13:06:58 +00001770 ArrayRef<TypeSourceInfo *> Types,
1771 ArrayRef<Expr *> Exprs) {
Peter Collingbournef111d932011-04-15 00:35:48 +00001772 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko80613222013-05-10 13:06:58 +00001773 ControllingExpr, Types, Exprs);
Peter Collingbournef111d932011-04-15 00:35:48 +00001774 }
1775
Douglas Gregorb98b1992009-08-11 05:31:07 +00001776 /// \brief Build a new overloaded operator call expression.
1777 ///
1778 /// By default, performs semantic analysis to build the new expression.
1779 /// The semantic analysis provides the behavior of template instantiation,
1780 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001781 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001782 /// argument-dependent lookup, etc. Subclasses may override this routine to
1783 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001784 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001785 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001786 Expr *Callee,
1787 Expr *First,
1788 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001789
1790 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001791 /// reinterpret_cast.
1792 ///
1793 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001794 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001795 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001796 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001797 Stmt::StmtClass Class,
1798 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001799 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001800 SourceLocation RAngleLoc,
1801 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001802 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001803 SourceLocation RParenLoc) {
1804 switch (Class) {
1805 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001806 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001807 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001808 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001809
1810 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001811 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001812 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001813 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001814
Douglas Gregorb98b1992009-08-11 05:31:07 +00001815 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001816 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001817 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001818 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001819 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001820
Douglas Gregorb98b1992009-08-11 05:31:07 +00001821 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001822 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001823 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001824 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001825
Douglas Gregorb98b1992009-08-11 05:31:07 +00001826 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001827 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001828 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001829 }
Mike Stump1eb44332009-09-09 15:08:12 +00001830
Douglas Gregorb98b1992009-08-11 05:31:07 +00001831 /// \brief Build a new C++ static_cast expression.
1832 ///
1833 /// By default, performs semantic analysis to build the new expression.
1834 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001835 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001836 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001837 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001838 SourceLocation RAngleLoc,
1839 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001840 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001841 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001842 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001843 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001844 SourceRange(LAngleLoc, RAngleLoc),
1845 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001846 }
1847
1848 /// \brief Build a new C++ dynamic_cast expression.
1849 ///
1850 /// By default, performs semantic analysis to build the new expression.
1851 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001852 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001853 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001854 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001855 SourceLocation RAngleLoc,
1856 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001857 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001858 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001859 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001860 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001861 SourceRange(LAngleLoc, RAngleLoc),
1862 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001863 }
1864
1865 /// \brief Build a new C++ reinterpret_cast expression.
1866 ///
1867 /// By default, performs semantic analysis to build the new expression.
1868 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001869 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001870 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001871 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001872 SourceLocation RAngleLoc,
1873 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001874 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001875 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001876 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001877 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001878 SourceRange(LAngleLoc, RAngleLoc),
1879 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001880 }
1881
1882 /// \brief Build a new C++ const_cast expression.
1883 ///
1884 /// By default, performs semantic analysis to build the new expression.
1885 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001886 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001887 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001888 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001889 SourceLocation RAngleLoc,
1890 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001891 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001892 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001893 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001894 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001895 SourceRange(LAngleLoc, RAngleLoc),
1896 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001897 }
Mike Stump1eb44332009-09-09 15:08:12 +00001898
Douglas Gregorb98b1992009-08-11 05:31:07 +00001899 /// \brief Build a new C++ functional-style cast expression.
1900 ///
1901 /// By default, performs semantic analysis to build the new expression.
1902 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001903 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1904 SourceLocation LParenLoc,
1905 Expr *Sub,
1906 SourceLocation RParenLoc) {
1907 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001908 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001909 RParenLoc);
1910 }
Mike Stump1eb44332009-09-09 15:08:12 +00001911
Douglas Gregorb98b1992009-08-11 05:31:07 +00001912 /// \brief Build a new C++ typeid(type) expression.
1913 ///
1914 /// By default, performs semantic analysis to build the new expression.
1915 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001916 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001917 SourceLocation TypeidLoc,
1918 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001919 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001920 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001921 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001922 }
Mike Stump1eb44332009-09-09 15:08:12 +00001923
Francois Pichet01b7c302010-09-08 12:20:18 +00001924
Douglas Gregorb98b1992009-08-11 05:31:07 +00001925 /// \brief Build a new C++ typeid(expr) expression.
1926 ///
1927 /// By default, performs semantic analysis to build the new expression.
1928 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001929 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001930 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001931 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001932 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001933 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001934 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001935 }
1936
Francois Pichet01b7c302010-09-08 12:20:18 +00001937 /// \brief Build a new C++ __uuidof(type) expression.
1938 ///
1939 /// By default, performs semantic analysis to build the new expression.
1940 /// Subclasses may override this routine to provide different behavior.
1941 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1942 SourceLocation TypeidLoc,
1943 TypeSourceInfo *Operand,
1944 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001945 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet01b7c302010-09-08 12:20:18 +00001946 RParenLoc);
1947 }
1948
1949 /// \brief Build a new C++ __uuidof(expr) expression.
1950 ///
1951 /// By default, performs semantic analysis to build the new expression.
1952 /// Subclasses may override this routine to provide different behavior.
1953 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1954 SourceLocation TypeidLoc,
1955 Expr *Operand,
1956 SourceLocation RParenLoc) {
1957 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1958 RParenLoc);
1959 }
1960
Douglas Gregorb98b1992009-08-11 05:31:07 +00001961 /// \brief Build a new C++ "this" expression.
1962 ///
1963 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001964 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001965 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001966 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001967 QualType ThisType,
1968 bool isImplicit) {
Eli Friedmanb69b42c2012-01-11 02:36:31 +00001969 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001970 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001971 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1972 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001973 }
1974
1975 /// \brief Build a new C++ throw expression.
1976 ///
1977 /// By default, performs semantic analysis to build the new expression.
1978 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00001979 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1980 bool IsThrownVariableInScope) {
1981 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001982 }
1983
1984 /// \brief Build a new C++ default-argument expression.
1985 ///
1986 /// By default, builds a new default-argument expression, which does not
1987 /// require any semantic analysis. Subclasses may override this routine to
1988 /// provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001989 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001990 ParmVarDecl *Param) {
1991 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1992 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001993 }
1994
Richard Smithc3bf52c2013-04-20 22:23:05 +00001995 /// \brief Build a new C++11 default-initialization expression.
1996 ///
1997 /// By default, builds a new default field initialization expression, which
1998 /// does not require any semantic analysis. Subclasses may override this
1999 /// routine to provide different behavior.
2000 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2001 FieldDecl *Field) {
2002 return getSema().Owned(CXXDefaultInitExpr::Create(getSema().Context, Loc,
2003 Field));
2004 }
2005
Douglas Gregorb98b1992009-08-11 05:31:07 +00002006 /// \brief Build a new C++ zero-initialization expression.
2007 ///
2008 /// By default, performs semantic analysis to build the new expression.
2009 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002010 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2011 SourceLocation LParenLoc,
2012 SourceLocation RParenLoc) {
2013 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002014 None, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002015 }
Mike Stump1eb44332009-09-09 15:08:12 +00002016
Douglas Gregorb98b1992009-08-11 05:31:07 +00002017 /// \brief Build a new C++ "new" expression.
2018 ///
2019 /// By default, performs semantic analysis to build the new expression.
2020 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002021 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002022 bool UseGlobal,
2023 SourceLocation PlacementLParen,
2024 MultiExprArg PlacementArgs,
2025 SourceLocation PlacementRParen,
2026 SourceRange TypeIdParens,
2027 QualType AllocatedType,
2028 TypeSourceInfo *AllocatedTypeInfo,
2029 Expr *ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002030 SourceRange DirectInitRange,
2031 Expr *Initializer) {
Mike Stump1eb44332009-09-09 15:08:12 +00002032 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002033 PlacementLParen,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002034 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002035 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00002036 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002037 AllocatedType,
2038 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00002039 ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002040 DirectInitRange,
2041 Initializer);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002042 }
Mike Stump1eb44332009-09-09 15:08:12 +00002043
Douglas Gregorb98b1992009-08-11 05:31:07 +00002044 /// \brief Build a new C++ "delete" expression.
2045 ///
2046 /// By default, performs semantic analysis to build the new expression.
2047 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002048 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002049 bool IsGlobalDelete,
2050 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002051 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002052 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002053 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002054 }
Mike Stump1eb44332009-09-09 15:08:12 +00002055
Douglas Gregorb98b1992009-08-11 05:31:07 +00002056 /// \brief Build a new unary type trait expression.
2057 ///
2058 /// By default, performs semantic analysis to build the new expression.
2059 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002060 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00002061 SourceLocation StartLoc,
2062 TypeSourceInfo *T,
2063 SourceLocation RParenLoc) {
2064 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002065 }
2066
Francois Pichet6ad6f282010-12-07 00:08:36 +00002067 /// \brief Build a new binary type trait expression.
2068 ///
2069 /// By default, performs semantic analysis to build the new expression.
2070 /// Subclasses may override this routine to provide different behavior.
2071 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
2072 SourceLocation StartLoc,
2073 TypeSourceInfo *LhsT,
2074 TypeSourceInfo *RhsT,
2075 SourceLocation RParenLoc) {
2076 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
2077 }
2078
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00002079 /// \brief Build a new type trait expression.
2080 ///
2081 /// By default, performs semantic analysis to build the new expression.
2082 /// Subclasses may override this routine to provide different behavior.
2083 ExprResult RebuildTypeTrait(TypeTrait Trait,
2084 SourceLocation StartLoc,
2085 ArrayRef<TypeSourceInfo *> Args,
2086 SourceLocation RParenLoc) {
2087 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2088 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002089
John Wiegley21ff2e52011-04-28 00:16:57 +00002090 /// \brief Build a new array type trait expression.
2091 ///
2092 /// By default, performs semantic analysis to build the new expression.
2093 /// Subclasses may override this routine to provide different behavior.
2094 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2095 SourceLocation StartLoc,
2096 TypeSourceInfo *TSInfo,
2097 Expr *DimExpr,
2098 SourceLocation RParenLoc) {
2099 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2100 }
2101
John Wiegley55262202011-04-25 06:54:41 +00002102 /// \brief Build a new expression trait expression.
2103 ///
2104 /// By default, performs semantic analysis to build the new expression.
2105 /// Subclasses may override this routine to provide different behavior.
2106 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2107 SourceLocation StartLoc,
2108 Expr *Queried,
2109 SourceLocation RParenLoc) {
2110 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2111 }
2112
Mike Stump1eb44332009-09-09 15:08:12 +00002113 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002114 /// expression.
2115 ///
2116 /// By default, performs semantic analysis to build the new expression.
2117 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002118 ExprResult RebuildDependentScopeDeclRefExpr(
2119 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002120 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002121 const DeclarationNameInfo &NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00002122 const TemplateArgumentListInfo *TemplateArgs,
2123 bool IsAddressOfOperand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002124 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002125 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002126
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002127 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002128 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002129 NameInfo, TemplateArgs);
John McCallf7a1a742009-11-24 19:00:30 +00002130
Richard Smithefeeccf2012-10-21 03:28:35 +00002131 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo,
2132 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002133 }
2134
2135 /// \brief Build a new template-id expression.
2136 ///
2137 /// By default, performs semantic analysis to build the new expression.
2138 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002139 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002140 SourceLocation TemplateKWLoc,
2141 LookupResult &R,
2142 bool RequiresADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002143 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002144 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2145 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002146 }
2147
2148 /// \brief Build a new object-construction expression.
2149 ///
2150 /// By default, performs semantic analysis to build the new expression.
2151 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002152 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002153 SourceLocation Loc,
2154 CXXConstructorDecl *Constructor,
2155 bool IsElidable,
2156 MultiExprArg Args,
2157 bool HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002158 bool ListInitialization,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002159 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002160 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002161 SourceRange ParenRange) {
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00002162 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002163 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002164 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002165 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002166
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002167 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002168 ConvertedArgs,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002169 HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002170 ListInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002171 RequiresZeroInit, ConstructKind,
2172 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002173 }
2174
2175 /// \brief Build a new object-construction expression.
2176 ///
2177 /// By default, performs semantic analysis to build the new expression.
2178 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002179 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2180 SourceLocation LParenLoc,
2181 MultiExprArg Args,
2182 SourceLocation RParenLoc) {
2183 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002184 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002185 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002186 RParenLoc);
2187 }
2188
2189 /// \brief Build a new object-construction expression.
2190 ///
2191 /// By default, performs semantic analysis to build the new expression.
2192 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002193 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2194 SourceLocation LParenLoc,
2195 MultiExprArg Args,
2196 SourceLocation RParenLoc) {
2197 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002198 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002199 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002200 RParenLoc);
2201 }
Mike Stump1eb44332009-09-09 15:08:12 +00002202
Douglas Gregorb98b1992009-08-11 05:31:07 +00002203 /// \brief Build a new member reference expression.
2204 ///
2205 /// By default, performs semantic analysis to build the new expression.
2206 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002207 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002208 QualType BaseType,
2209 bool IsArrow,
2210 SourceLocation OperatorLoc,
2211 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002212 SourceLocation TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00002213 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002214 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002215 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002216 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002217 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002218
John McCall9ae2f072010-08-23 23:25:46 +00002219 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002220 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002221 SS, TemplateKWLoc,
2222 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002223 MemberNameInfo,
2224 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002225 }
2226
John McCall129e2df2009-11-30 22:42:35 +00002227 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002228 ///
2229 /// By default, performs semantic analysis to build the new expression.
2230 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002231 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2232 SourceLocation OperatorLoc,
2233 bool IsArrow,
2234 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002235 SourceLocation TemplateKWLoc,
Richard Smith9138b4e2011-10-26 19:06:56 +00002236 NamedDecl *FirstQualifierInScope,
2237 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002238 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002239 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002240 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002241
John McCall9ae2f072010-08-23 23:25:46 +00002242 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002243 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002244 SS, TemplateKWLoc,
2245 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00002246 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002247 }
Mike Stump1eb44332009-09-09 15:08:12 +00002248
Sebastian Redl2e156222010-09-10 20:55:43 +00002249 /// \brief Build a new noexcept expression.
2250 ///
2251 /// By default, performs semantic analysis to build the new expression.
2252 /// Subclasses may override this routine to provide different behavior.
2253 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2254 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2255 }
2256
Douglas Gregoree8aff02011-01-04 17:33:58 +00002257 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002258 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2259 SourceLocation PackLoc,
Douglas Gregoree8aff02011-01-04 17:33:58 +00002260 SourceLocation RParenLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002261 Optional<unsigned> Length) {
Douglas Gregor089e8932011-10-10 18:59:29 +00002262 if (Length)
Chad Rosier4a9d7952012-08-08 18:46:20 +00002263 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2264 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002265 RParenLoc, *Length);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002266
2267 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2268 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002269 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002270 }
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002271
Patrick Beardeb382ec2012-04-19 00:25:12 +00002272 /// \brief Build a new Objective-C boxed expression.
2273 ///
2274 /// By default, performs semantic analysis to build the new expression.
2275 /// Subclasses may override this routine to provide different behavior.
2276 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2277 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2278 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002279
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002280 /// \brief Build a new Objective-C array literal.
2281 ///
2282 /// By default, performs semantic analysis to build the new expression.
2283 /// Subclasses may override this routine to provide different behavior.
2284 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2285 Expr **Elements, unsigned NumElements) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002286 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002287 MultiExprArg(Elements, NumElements));
2288 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002289
2290 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002291 Expr *Base, Expr *Key,
2292 ObjCMethodDecl *getterMethod,
2293 ObjCMethodDecl *setterMethod) {
2294 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2295 getterMethod, setterMethod);
2296 }
2297
2298 /// \brief Build a new Objective-C dictionary literal.
2299 ///
2300 /// By default, performs semantic analysis to build the new expression.
2301 /// Subclasses may override this routine to provide different behavior.
2302 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2303 ObjCDictionaryElement *Elements,
2304 unsigned NumElements) {
2305 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2306 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002307
James Dennett699c9042012-06-15 07:13:21 +00002308 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregorb98b1992009-08-11 05:31:07 +00002309 ///
2310 /// By default, performs semantic analysis to build the new expression.
2311 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002312 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002313 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002314 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002315 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002316 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002317 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002318
Douglas Gregor92e986e2010-04-22 16:44:27 +00002319 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002320 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002321 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002322 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002323 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002324 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002325 MultiExprArg Args,
2326 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002327 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2328 ReceiverTypeInfo->getType(),
2329 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002330 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002331 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002332 }
2333
2334 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002335 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002336 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002337 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002338 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002339 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002340 MultiExprArg Args,
2341 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002342 return SemaRef.BuildInstanceMessage(Receiver,
2343 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002344 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002345 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002346 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002347 }
2348
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002349 /// \brief Build a new Objective-C ivar reference expression.
2350 ///
2351 /// By default, performs semantic analysis to build the new expression.
2352 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002353 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002354 SourceLocation IvarLoc,
2355 bool IsArrow, bool IsFreeIvar) {
2356 // FIXME: We lose track of the IsFreeIvar bit.
2357 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002358 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002359 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2360 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002361 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002362 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002363 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002364 false);
John Wiegley429bb272011-04-08 18:41:53 +00002365 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002366 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002367
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002368 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002369 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002370
John Wiegley429bb272011-04-08 18:41:53 +00002371 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002372 /*FIXME:*/IvarLoc, IsArrow,
2373 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002374 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002375 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002376 /*TemplateArgs=*/0);
2377 }
Douglas Gregore3303542010-04-26 20:47:02 +00002378
2379 /// \brief Build a new Objective-C property reference expression.
2380 ///
2381 /// By default, performs semantic analysis to build the new expression.
2382 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002383 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002384 ObjCPropertyDecl *Property,
2385 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002386 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002387 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002388 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2389 Sema::LookupMemberName);
2390 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002391 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002392 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002393 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002394 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002395 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002396
Douglas Gregore3303542010-04-26 20:47:02 +00002397 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002398 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002399
John Wiegley429bb272011-04-08 18:41:53 +00002400 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002401 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002402 SS, SourceLocation(),
Douglas Gregore3303542010-04-26 20:47:02 +00002403 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002404 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002405 /*TemplateArgs=*/0);
2406 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002407
John McCall12f78a62010-12-02 01:19:52 +00002408 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002409 ///
2410 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002411 /// Subclasses may override this routine to provide different behavior.
2412 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2413 ObjCMethodDecl *Getter,
2414 ObjCMethodDecl *Setter,
2415 SourceLocation PropertyLoc) {
2416 // Since these expressions can only be value-dependent, we do not
2417 // need to perform semantic analysis again.
2418 return Owned(
2419 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2420 VK_LValue, OK_ObjCProperty,
2421 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002422 }
2423
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002424 /// \brief Build a new Objective-C "isa" expression.
2425 ///
2426 /// By default, performs semantic analysis to build the new expression.
2427 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002428 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002429 SourceLocation OpLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002430 bool IsArrow) {
2431 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002432 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002433 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2434 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002435 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002436 OpLoc,
John McCalld226f652010-08-21 09:40:31 +00002437 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002438 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002439 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002440
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002441 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002442 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002443
John Wiegley429bb272011-04-08 18:41:53 +00002444 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002445 OpLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002446 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002447 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002448 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002449 /*TemplateArgs=*/0);
2450 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002451
Douglas Gregorb98b1992009-08-11 05:31:07 +00002452 /// \brief Build a new shuffle vector expression.
2453 ///
2454 /// By default, performs semantic analysis to build the new expression.
2455 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002456 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002457 MultiExprArg SubExprs,
2458 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002459 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002460 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002461 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2462 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2463 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikie3bc93e32012-12-19 00:45:41 +00002464 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002465
Douglas Gregorb98b1992009-08-11 05:31:07 +00002466 // Build a reference to the __builtin_shufflevector builtin
David Blaikie3bc93e32012-12-19 00:45:41 +00002467 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002468 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2469 SemaRef.Context.BuiltinFnTy,
2470 VK_RValue, BuiltinLoc);
2471 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2472 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
2473 CK_BuiltinFnToFnPtr).take();
Mike Stump1eb44332009-09-09 15:08:12 +00002474
2475 // Build the CallExpr
John Wiegley429bb272011-04-08 18:41:53 +00002476 ExprResult TheCall = SemaRef.Owned(
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002477 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, SubExprs,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002478 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002479 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002480 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002481
Douglas Gregorb98b1992009-08-11 05:31:07 +00002482 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002483 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002484 }
John McCall43fed0d2010-11-12 08:19:04 +00002485
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002486 /// \brief Build a new template argument pack expansion.
2487 ///
2488 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002489 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002490 /// different behavior.
2491 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002492 SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002493 Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002494 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002495 case TemplateArgument::Expression: {
2496 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002497 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2498 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002499 if (Result.isInvalid())
2500 return TemplateArgumentLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002501
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002502 return TemplateArgumentLoc(Result.get(), Result.get());
2503 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002504
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002505 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002506 return TemplateArgumentLoc(TemplateArgument(
2507 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002508 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002509 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002510 Pattern.getTemplateNameLoc(),
2511 EllipsisLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002512
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002513 case TemplateArgument::Null:
2514 case TemplateArgument::Integral:
2515 case TemplateArgument::Declaration:
2516 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002517 case TemplateArgument::TemplateExpansion:
Eli Friedmand7a6b162012-09-26 02:36:12 +00002518 case TemplateArgument::NullPtr:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002519 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002520
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002521 case TemplateArgument::Type:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002522 if (TypeSourceInfo *Expansion
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002523 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002524 EllipsisLoc,
2525 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002526 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2527 Expansion);
2528 break;
2529 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002530
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002531 return TemplateArgumentLoc();
2532 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002533
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002534 /// \brief Build a new expression pack expansion.
2535 ///
2536 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002537 /// for an expression. Subclasses may override this routine to provide
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002538 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002539 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002540 Optional<unsigned> NumExpansions) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002541 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002542 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002543
2544 /// \brief Build a new atomic operation expression.
2545 ///
2546 /// By default, performs semantic analysis to build the new expression.
2547 /// Subclasses may override this routine to provide different behavior.
2548 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2549 MultiExprArg SubExprs,
2550 QualType RetTy,
2551 AtomicExpr::AtomicOp Op,
2552 SourceLocation RParenLoc) {
2553 // Just create the expression; there is not any interesting semantic
2554 // analysis here because we can't actually build an AtomicExpr until
2555 // we are sure it is semantically sound.
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002556 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002557 RParenLoc);
2558 }
2559
John McCall43fed0d2010-11-12 08:19:04 +00002560private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002561 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2562 QualType ObjectType,
2563 NamedDecl *FirstQualifierInScope,
2564 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002565
2566 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2567 QualType ObjectType,
2568 NamedDecl *FirstQualifierInScope,
2569 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002570};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002571
Douglas Gregor43959a92009-08-20 07:17:43 +00002572template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002573StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002574 if (!S)
2575 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002576
Douglas Gregor43959a92009-08-20 07:17:43 +00002577 switch (S->getStmtClass()) {
2578 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002579
Douglas Gregor43959a92009-08-20 07:17:43 +00002580 // Transform individual statement nodes
2581#define STMT(Node, Parent) \
2582 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002583#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002584#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002585#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002586
Douglas Gregor43959a92009-08-20 07:17:43 +00002587 // Transform expressions by calling TransformExpr.
2588#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002589#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002590#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002591#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002592 {
John McCall60d7b3a2010-08-24 06:29:42 +00002593 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002594 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002595 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002596
Richard Smith41956372013-01-14 22:39:08 +00002597 return getSema().ActOnExprStmt(E);
Douglas Gregor43959a92009-08-20 07:17:43 +00002598 }
Mike Stump1eb44332009-09-09 15:08:12 +00002599 }
2600
John McCall3fa5cae2010-10-26 07:05:15 +00002601 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002602}
Mike Stump1eb44332009-09-09 15:08:12 +00002603
2604
Douglas Gregor670444e2009-08-04 22:27:00 +00002605template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002606ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002607 if (!E)
2608 return SemaRef.Owned(E);
2609
2610 switch (E->getStmtClass()) {
2611 case Stmt::NoStmtClass: break;
2612#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002613#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002614#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002615 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002616#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002617 }
2618
John McCall3fa5cae2010-10-26 07:05:15 +00002619 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002620}
2621
2622template<typename Derived>
Richard Smithc83c2302012-12-19 01:39:02 +00002623ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2624 bool CXXDirectInit) {
2625 // Initializers are instantiated like expressions, except that various outer
2626 // layers are stripped.
2627 if (!Init)
2628 return SemaRef.Owned(Init);
2629
2630 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2631 Init = ExprTemp->getSubExpr();
2632
Richard Smith858c2c32013-05-30 22:40:16 +00002633 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2634 Init = MTE->GetTemporaryExpr();
2635
Richard Smithc83c2302012-12-19 01:39:02 +00002636 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2637 Init = Binder->getSubExpr();
2638
2639 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2640 Init = ICE->getSubExprAsWritten();
2641
Richard Smith5cf15892012-12-21 08:13:35 +00002642 // If this is not a direct-initializer, we only need to reconstruct
2643 // InitListExprs. Other forms of copy-initialization will be a no-op if
2644 // the initializer is already the right type.
2645 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2646 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2647 return getDerived().TransformExpr(Init);
2648
2649 // Revert value-initialization back to empty parens.
2650 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2651 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002652 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith5cf15892012-12-21 08:13:35 +00002653 Parens.getEnd());
2654 }
2655
2656 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2657 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002658 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith5cf15892012-12-21 08:13:35 +00002659 SourceLocation());
2660
2661 // Revert initialization by constructor back to a parenthesized or braced list
2662 // of expressions. Any other form of initializer can just be reused directly.
2663 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithc83c2302012-12-19 01:39:02 +00002664 return getDerived().TransformExpr(Init);
2665
2666 SmallVector<Expr*, 8> NewArgs;
2667 bool ArgChanged = false;
2668 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2669 /*IsCall*/true, NewArgs, &ArgChanged))
2670 return ExprError();
2671
2672 // If this was list initialization, revert to list form.
2673 if (Construct->isListInitialization())
2674 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2675 Construct->getLocEnd(),
2676 Construct->getType());
2677
Richard Smithc83c2302012-12-19 01:39:02 +00002678 // Build a ParenListExpr to represent anything else.
2679 SourceRange Parens = Construct->getParenRange();
2680 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2681 Parens.getEnd());
2682}
2683
2684template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00002685bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2686 unsigned NumInputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002687 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002688 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002689 bool *ArgChanged) {
2690 for (unsigned I = 0; I != NumInputs; ++I) {
2691 // If requested, drop call arguments that need to be dropped.
2692 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2693 if (ArgChanged)
2694 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002695
Douglas Gregoraa165f82011-01-03 19:04:46 +00002696 break;
2697 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002698
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002699 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2700 Expr *Pattern = Expansion->getPattern();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002701
Chris Lattner686775d2011-07-20 06:58:45 +00002702 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002703 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2704 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002705
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002706 // Determine whether the set of unexpanded parameter packs can and should
2707 // be expanded.
2708 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002709 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00002710 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2711 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002712 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2713 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002714 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002715 Expand, RetainExpansion,
2716 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002717 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002718
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002719 if (!Expand) {
2720 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00002721 // transformation on the pack expansion, producing another pack
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002722 // expansion.
2723 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2724 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2725 if (OutPattern.isInvalid())
2726 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002727
2728 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002729 Expansion->getEllipsisLoc(),
2730 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002731 if (Out.isInvalid())
2732 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002733
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002734 if (ArgChanged)
2735 *ArgChanged = true;
2736 Outputs.push_back(Out.get());
2737 continue;
2738 }
John McCallc8fc90a2011-07-06 07:30:07 +00002739
2740 // Record right away that the argument was changed. This needs
2741 // to happen even if the array expands to nothing.
2742 if (ArgChanged) *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002743
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002744 // The transform has determined that we should perform an elementwise
2745 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002746 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002747 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2748 ExprResult Out = getDerived().TransformExpr(Pattern);
2749 if (Out.isInvalid())
2750 return true;
2751
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002752 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002753 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2754 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002755 if (Out.isInvalid())
2756 return true;
2757 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002758
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002759 Outputs.push_back(Out.get());
2760 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002761
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002762 continue;
2763 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002764
Richard Smithc83c2302012-12-19 01:39:02 +00002765 ExprResult Result =
2766 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
2767 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregoraa165f82011-01-03 19:04:46 +00002768 if (Result.isInvalid())
2769 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002770
Douglas Gregoraa165f82011-01-03 19:04:46 +00002771 if (Result.get() != Inputs[I] && ArgChanged)
2772 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002773
2774 Outputs.push_back(Result.get());
Douglas Gregoraa165f82011-01-03 19:04:46 +00002775 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002776
Douglas Gregoraa165f82011-01-03 19:04:46 +00002777 return false;
2778}
2779
2780template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002781NestedNameSpecifierLoc
2782TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2783 NestedNameSpecifierLoc NNS,
2784 QualType ObjectType,
2785 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002786 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002787 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002788 Qualifier = Qualifier.getPrefix())
2789 Qualifiers.push_back(Qualifier);
2790
2791 CXXScopeSpec SS;
2792 while (!Qualifiers.empty()) {
2793 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2794 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002795
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002796 switch (QNNS->getKind()) {
2797 case NestedNameSpecifier::Identifier:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002798 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002799 *QNNS->getAsIdentifier(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002800 Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002801 Q.getLocalEndLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002802 ObjectType, false, SS,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002803 FirstQualifierInScope, false))
2804 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002805
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002806 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002807
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002808 case NestedNameSpecifier::Namespace: {
2809 NamespaceDecl *NS
2810 = cast_or_null<NamespaceDecl>(
2811 getDerived().TransformDecl(
2812 Q.getLocalBeginLoc(),
2813 QNNS->getAsNamespace()));
2814 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2815 break;
2816 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002817
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002818 case NestedNameSpecifier::NamespaceAlias: {
2819 NamespaceAliasDecl *Alias
2820 = cast_or_null<NamespaceAliasDecl>(
2821 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2822 QNNS->getAsNamespaceAlias()));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002823 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002824 Q.getLocalEndLoc());
2825 break;
2826 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002827
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002828 case NestedNameSpecifier::Global:
2829 // There is no meaningful transformation that one could perform on the
2830 // global scope.
2831 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2832 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002833
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002834 case NestedNameSpecifier::TypeSpecWithTemplate:
2835 case NestedNameSpecifier::TypeSpec: {
2836 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2837 FirstQualifierInScope, SS);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002838
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002839 if (!TL)
2840 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002841
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002842 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith80ad52f2013-01-02 11:42:31 +00002843 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002844 TL.getType()->isEnumeralType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002845 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002846 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002847 if (TL.getType()->isEnumeralType())
2848 SemaRef.Diag(TL.getBeginLoc(),
2849 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002850 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2851 Q.getLocalEndLoc());
2852 break;
2853 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002854 // If the nested-name-specifier is an invalid type def, don't emit an
2855 // error because a previous error should have already been emitted.
David Blaikie39e6ab42013-02-18 22:06:02 +00002856 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
2857 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002858 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieu00c93a12011-05-07 01:36:37 +00002859 << TL.getType() << SS.getRange();
2860 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002861 return NestedNameSpecifierLoc();
2862 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002863 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002864
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002865 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002866 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002867 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002868 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002869
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002870 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002871 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002872 !getDerived().AlwaysRebuild())
2873 return NNS;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002874
2875 // If we can re-use the source-location data from the original
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002876 // nested-name-specifier, do so.
2877 if (SS.location_size() == NNS.getDataLength() &&
2878 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2879 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2880
2881 // Allocate new nested-name-specifier location information.
2882 return SS.getWithLocInContext(SemaRef.Context);
2883}
2884
2885template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002886DeclarationNameInfo
2887TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002888::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002889 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002890 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002891 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002892
2893 switch (Name.getNameKind()) {
2894 case DeclarationName::Identifier:
2895 case DeclarationName::ObjCZeroArgSelector:
2896 case DeclarationName::ObjCOneArgSelector:
2897 case DeclarationName::ObjCMultiArgSelector:
2898 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002899 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002900 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002901 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002902
Douglas Gregor81499bb2009-09-03 22:13:48 +00002903 case DeclarationName::CXXConstructorName:
2904 case DeclarationName::CXXDestructorName:
2905 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002906 TypeSourceInfo *NewTInfo;
2907 CanQualType NewCanTy;
2908 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002909 NewTInfo = getDerived().TransformType(OldTInfo);
2910 if (!NewTInfo)
2911 return DeclarationNameInfo();
2912 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002913 }
2914 else {
2915 NewTInfo = 0;
2916 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002917 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002918 if (NewT.isNull())
2919 return DeclarationNameInfo();
2920 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2921 }
Mike Stump1eb44332009-09-09 15:08:12 +00002922
Abramo Bagnara25777432010-08-11 22:01:17 +00002923 DeclarationName NewName
2924 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2925 NewCanTy);
2926 DeclarationNameInfo NewNameInfo(NameInfo);
2927 NewNameInfo.setName(NewName);
2928 NewNameInfo.setNamedTypeInfo(NewTInfo);
2929 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002930 }
Mike Stump1eb44332009-09-09 15:08:12 +00002931 }
2932
David Blaikieb219cfc2011-09-23 05:06:16 +00002933 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00002934}
2935
2936template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002937TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002938TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2939 TemplateName Name,
2940 SourceLocation NameLoc,
2941 QualType ObjectType,
2942 NamedDecl *FirstQualifierInScope) {
2943 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2944 TemplateDecl *Template = QTN->getTemplateDecl();
2945 assert(Template && "qualified template name must refer to a template");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002946
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002947 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00002948 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002949 Template));
2950 if (!TransTemplate)
2951 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002952
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002953 if (!getDerived().AlwaysRebuild() &&
2954 SS.getScopeRep() == QTN->getQualifier() &&
2955 TransTemplate == Template)
2956 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002957
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002958 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2959 TransTemplate);
2960 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002961
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002962 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2963 if (SS.getScopeRep()) {
2964 // These apply to the scope specifier, not the template.
2965 ObjectType = QualType();
2966 FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002967 }
2968
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002969 if (!getDerived().AlwaysRebuild() &&
2970 SS.getScopeRep() == DTN->getQualifier() &&
2971 ObjectType.isNull())
2972 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002973
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002974 if (DTN->isIdentifier()) {
2975 return getDerived().RebuildTemplateName(SS,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002976 *DTN->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002977 NameLoc,
2978 ObjectType,
2979 FirstQualifierInScope);
2980 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002981
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002982 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2983 ObjectType);
2984 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002985
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002986 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2987 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00002988 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002989 Template));
2990 if (!TransTemplate)
2991 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002992
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002993 if (!getDerived().AlwaysRebuild() &&
2994 TransTemplate == Template)
2995 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002996
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002997 return TemplateName(TransTemplate);
2998 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002999
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003000 if (SubstTemplateTemplateParmPackStorage *SubstPack
3001 = Name.getAsSubstTemplateTemplateParmPack()) {
3002 TemplateTemplateParmDecl *TransParam
3003 = cast_or_null<TemplateTemplateParmDecl>(
3004 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3005 if (!TransParam)
3006 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003007
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003008 if (!getDerived().AlwaysRebuild() &&
3009 TransParam == SubstPack->getParameterPack())
3010 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003011
3012 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003013 SubstPack->getArgumentPack());
3014 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003015
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003016 // These should be getting filtered out before they reach the AST.
3017 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003018}
3019
3020template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00003021void TreeTransform<Derived>::InventTemplateArgumentLoc(
3022 const TemplateArgument &Arg,
3023 TemplateArgumentLoc &Output) {
3024 SourceLocation Loc = getDerived().getBaseLocation();
3025 switch (Arg.getKind()) {
3026 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003027 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00003028 break;
3029
3030 case TemplateArgument::Type:
3031 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00003032 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier4a9d7952012-08-08 18:46:20 +00003033
John McCall833ca992009-10-29 08:12:44 +00003034 break;
3035
Douglas Gregor788cd062009-11-11 01:00:40 +00003036 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003037 case TemplateArgument::TemplateExpansion: {
3038 NestedNameSpecifierLocBuilder Builder;
3039 TemplateName Template = Arg.getAsTemplate();
3040 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3041 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3042 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3043 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003044
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003045 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier4a9d7952012-08-08 18:46:20 +00003046 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003047 Builder.getWithLocInContext(SemaRef.Context),
3048 Loc);
3049 else
Chad Rosier4a9d7952012-08-08 18:46:20 +00003050 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003051 Builder.getWithLocInContext(SemaRef.Context),
3052 Loc, Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003053
Douglas Gregor788cd062009-11-11 01:00:40 +00003054 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003055 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003056
John McCall833ca992009-10-29 08:12:44 +00003057 case TemplateArgument::Expression:
3058 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3059 break;
3060
3061 case TemplateArgument::Declaration:
3062 case TemplateArgument::Integral:
3063 case TemplateArgument::Pack:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003064 case TemplateArgument::NullPtr:
John McCall828bff22009-10-29 18:45:58 +00003065 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00003066 break;
3067 }
3068}
3069
3070template<typename Derived>
3071bool TreeTransform<Derived>::TransformTemplateArgument(
3072 const TemplateArgumentLoc &Input,
3073 TemplateArgumentLoc &Output) {
3074 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00003075 switch (Arg.getKind()) {
3076 case TemplateArgument::Null:
3077 case TemplateArgument::Integral:
Eli Friedman511e3ae2012-09-25 01:02:42 +00003078 case TemplateArgument::Pack:
3079 case TemplateArgument::Declaration:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003080 case TemplateArgument::NullPtr:
3081 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump1eb44332009-09-09 15:08:12 +00003082
Douglas Gregor670444e2009-08-04 22:27:00 +00003083 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00003084 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00003085 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00003086 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00003087
3088 DI = getDerived().TransformType(DI);
3089 if (!DI) return true;
3090
3091 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3092 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003093 }
Mike Stump1eb44332009-09-09 15:08:12 +00003094
Douglas Gregor788cd062009-11-11 01:00:40 +00003095 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003096 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3097 if (QualifierLoc) {
3098 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3099 if (!QualifierLoc)
3100 return true;
3101 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003102
Douglas Gregor1d752d72011-03-02 18:46:51 +00003103 CXXScopeSpec SS;
3104 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00003105 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00003106 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3107 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00003108 if (Template.isNull())
3109 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003110
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003111 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00003112 Input.getTemplateNameLoc());
3113 return false;
3114 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003115
3116 case TemplateArgument::TemplateExpansion:
3117 llvm_unreachable("Caller should expand pack expansions");
3118
Douglas Gregor670444e2009-08-04 22:27:00 +00003119 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00003120 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00003121 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003122 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003123
John McCall833ca992009-10-29 08:12:44 +00003124 Expr *InputExpr = Input.getSourceExpression();
3125 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3126
Chris Lattner223de242011-04-25 20:37:58 +00003127 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003128 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00003129 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00003130 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00003131 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003132 }
Douglas Gregor670444e2009-08-04 22:27:00 +00003133 }
Mike Stump1eb44332009-09-09 15:08:12 +00003134
Douglas Gregor670444e2009-08-04 22:27:00 +00003135 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003136 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003137}
3138
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003139/// \brief Iterator adaptor that invents template argument location information
3140/// for each of the template arguments in its underlying iterator.
3141template<typename Derived, typename InputIterator>
3142class TemplateArgumentLocInventIterator {
3143 TreeTransform<Derived> &Self;
3144 InputIterator Iter;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003145
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003146public:
3147 typedef TemplateArgumentLoc value_type;
3148 typedef TemplateArgumentLoc reference;
3149 typedef typename std::iterator_traits<InputIterator>::difference_type
3150 difference_type;
3151 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003152
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003153 class pointer {
3154 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003155
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003156 public:
3157 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003158
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003159 const TemplateArgumentLoc *operator->() const { return &Arg; }
3160 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00003161
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003162 TemplateArgumentLocInventIterator() { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003163
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003164 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3165 InputIterator Iter)
3166 : Self(Self), Iter(Iter) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003167
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003168 TemplateArgumentLocInventIterator &operator++() {
3169 ++Iter;
3170 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003171 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003172
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003173 TemplateArgumentLocInventIterator operator++(int) {
3174 TemplateArgumentLocInventIterator Old(*this);
3175 ++(*this);
3176 return Old;
3177 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003178
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003179 reference operator*() const {
3180 TemplateArgumentLoc Result;
3181 Self.InventTemplateArgumentLoc(*Iter, Result);
3182 return Result;
3183 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003184
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003185 pointer operator->() const { return pointer(**this); }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003186
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003187 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3188 const TemplateArgumentLocInventIterator &Y) {
3189 return X.Iter == Y.Iter;
3190 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003191
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003192 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3193 const TemplateArgumentLocInventIterator &Y) {
3194 return X.Iter != Y.Iter;
3195 }
3196};
Chad Rosier4a9d7952012-08-08 18:46:20 +00003197
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003198template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003199template<typename InputIterator>
3200bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3201 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003202 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003203 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003204 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003205 TemplateArgumentLoc In = *First;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003206
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003207 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3208 // Unpack argument packs, which we translate them into separate
3209 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003210 // FIXME: We could do much better if we could guarantee that the
3211 // TemplateArgumentLocInfo for the pack expansion would be usable for
3212 // all of the template arguments in the argument pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003213 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003214 TemplateArgument::pack_iterator>
3215 PackLocIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003216 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003217 In.getArgument().pack_begin()),
3218 PackLocIterator(*this,
3219 In.getArgument().pack_end()),
3220 Outputs))
3221 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003222
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003223 continue;
3224 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003225
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003226 if (In.getArgument().isPackExpansion()) {
3227 // We have a pack expansion, for which we will be substituting into
3228 // the pattern.
3229 SourceLocation Ellipsis;
David Blaikiedc84cd52013-02-20 22:23:23 +00003230 Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003231 TemplateArgumentLoc Pattern
Chad Rosier4a9d7952012-08-08 18:46:20 +00003232 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
Douglas Gregorcded4f62011-01-14 17:04:44 +00003233 getSema().Context);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003234
Chris Lattner686775d2011-07-20 06:58:45 +00003235 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003236 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3237 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003238
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003239 // Determine whether the set of unexpanded parameter packs can and should
3240 // be expanded.
3241 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003242 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00003243 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003244 if (getDerived().TryExpandParameterPacks(Ellipsis,
3245 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003246 Unexpanded,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003247 Expand,
Douglas Gregord3731192011-01-10 07:32:04 +00003248 RetainExpansion,
3249 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003250 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003251
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003252 if (!Expand) {
3253 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00003254 // transformation on the pack expansion, producing another pack
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003255 // expansion.
3256 TemplateArgumentLoc OutPattern;
3257 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3258 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3259 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003260
Douglas Gregorcded4f62011-01-14 17:04:44 +00003261 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3262 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003263 if (Out.getArgument().isNull())
3264 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003265
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003266 Outputs.addArgument(Out);
3267 continue;
3268 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003269
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003270 // The transform has determined that we should perform an elementwise
3271 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003272 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003273 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3274
3275 if (getDerived().TransformTemplateArgument(Pattern, Out))
3276 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003277
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003278 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003279 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3280 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003281 if (Out.getArgument().isNull())
3282 return true;
3283 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003284
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003285 Outputs.addArgument(Out);
3286 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003287
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003288 // If we're supposed to retain a pack expansion, do so by temporarily
3289 // forgetting the partially-substituted parameter pack.
3290 if (RetainExpansion) {
3291 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003292
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003293 if (getDerived().TransformTemplateArgument(Pattern, Out))
3294 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003295
Douglas Gregorcded4f62011-01-14 17:04:44 +00003296 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3297 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003298 if (Out.getArgument().isNull())
3299 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003300
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003301 Outputs.addArgument(Out);
3302 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003303
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003304 continue;
3305 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003306
3307 // The simple case:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003308 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003309 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003310
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003311 Outputs.addArgument(Out);
3312 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003313
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003314 return false;
3315
3316}
3317
Douglas Gregor577f75a2009-08-04 16:50:30 +00003318//===----------------------------------------------------------------------===//
3319// Type transformation
3320//===----------------------------------------------------------------------===//
3321
3322template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003323QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003324 if (getDerived().AlreadyTransformed(T))
3325 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003326
John McCalla2becad2009-10-21 00:40:46 +00003327 // Temporary workaround. All of these transformations should
3328 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003329 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3330 getDerived().getBaseLocation());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003331
John McCall43fed0d2010-11-12 08:19:04 +00003332 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003333
John McCalla2becad2009-10-21 00:40:46 +00003334 if (!NewDI)
3335 return QualType();
3336
3337 return NewDI->getType();
3338}
3339
3340template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003341TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003342 // Refine the base location to the type's location.
3343 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3344 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003345 if (getDerived().AlreadyTransformed(DI->getType()))
3346 return DI;
3347
3348 TypeLocBuilder TLB;
3349
3350 TypeLoc TL = DI->getTypeLoc();
3351 TLB.reserve(TL.getFullDataSize());
3352
John McCall43fed0d2010-11-12 08:19:04 +00003353 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003354 if (Result.isNull())
3355 return 0;
3356
John McCalla93c9342009-12-07 02:54:59 +00003357 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003358}
3359
3360template<typename Derived>
3361QualType
John McCall43fed0d2010-11-12 08:19:04 +00003362TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003363 switch (T.getTypeLocClass()) {
3364#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie39e6ab42013-02-18 22:06:02 +00003365#define TYPELOC(CLASS, PARENT) \
3366 case TypeLoc::CLASS: \
3367 return getDerived().Transform##CLASS##Type(TLB, \
3368 T.castAs<CLASS##TypeLoc>());
John McCalla2becad2009-10-21 00:40:46 +00003369#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003370 }
Mike Stump1eb44332009-09-09 15:08:12 +00003371
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003372 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003373}
3374
3375/// FIXME: By default, this routine adds type qualifiers only to types
3376/// that can have qualifiers, and silently suppresses those qualifiers
3377/// that are not permitted (e.g., qualifiers on reference or function
3378/// types). This is the right thing for template instantiation, but
3379/// probably not for other clients.
3380template<typename Derived>
3381QualType
3382TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003383 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003384 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003385
John McCall43fed0d2010-11-12 08:19:04 +00003386 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003387 if (Result.isNull())
3388 return QualType();
3389
3390 // Silently suppress qualifiers if the result type can't be qualified.
3391 // FIXME: this is the right thing for template instantiation, but
3392 // probably not for other clients.
3393 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003394 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003395
John McCallf85e1932011-06-15 23:02:42 +00003396 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003397 // resulting type.
3398 if (Quals.hasObjCLifetime()) {
3399 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3400 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003401 else if (Result.getObjCLifetime()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003402 // Objective-C ARC:
Douglas Gregore559ca12011-06-17 22:11:49 +00003403 // A lifetime qualifier applied to a substituted template parameter
3404 // overrides the lifetime qualifier from the template argument.
Douglas Gregor92d13872013-01-17 23:59:28 +00003405 const AutoType *AutoTy;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003406 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore559ca12011-06-17 22:11:49 +00003407 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3408 QualType Replacement = SubstTypeParam->getReplacementType();
3409 Qualifiers Qs = Replacement.getQualifiers();
3410 Qs.removeObjCLifetime();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003411 Replacement
Douglas Gregore559ca12011-06-17 22:11:49 +00003412 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3413 Qs);
3414 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier4a9d7952012-08-08 18:46:20 +00003415 SubstTypeParam->getReplacedParameter(),
Douglas Gregore559ca12011-06-17 22:11:49 +00003416 Replacement);
3417 TLB.TypeWasModifiedSafely(Result);
Douglas Gregor92d13872013-01-17 23:59:28 +00003418 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3419 // 'auto' types behave the same way as template parameters.
3420 QualType Deduced = AutoTy->getDeducedType();
3421 Qualifiers Qs = Deduced.getQualifiers();
3422 Qs.removeObjCLifetime();
3423 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3424 Qs);
Richard Smitha2c36462013-04-26 16:15:35 +00003425 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto());
Douglas Gregor92d13872013-01-17 23:59:28 +00003426 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore559ca12011-06-17 22:11:49 +00003427 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003428 // Otherwise, complain about the addition of a qualifier to an
3429 // already-qualified type.
Manuel Klimek20387ef2013-06-07 11:27:53 +00003430 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003431 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003432 << Result << R;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003433
Douglas Gregore559ca12011-06-17 22:11:49 +00003434 Quals.removeObjCLifetime();
3435 }
3436 }
3437 }
John McCall28654742010-06-05 06:41:15 +00003438 if (!Quals.empty()) {
3439 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smith9807a2e2013-03-27 23:36:39 +00003440 // BuildQualifiedType might not add qualifiers if they are invalid.
3441 if (Result.hasLocalQualifiers())
3442 TLB.push<QualifiedTypeLoc>(Result);
John McCall28654742010-06-05 06:41:15 +00003443 // No location information to preserve.
3444 }
John McCalla2becad2009-10-21 00:40:46 +00003445
3446 return Result;
3447}
3448
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003449template<typename Derived>
3450TypeLoc
3451TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3452 QualType ObjectType,
3453 NamedDecl *UnqualLookup,
3454 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003455 QualType T = TL.getType();
3456 if (getDerived().AlreadyTransformed(T))
3457 return TL;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003458
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003459 TypeLocBuilder TLB;
3460 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003461
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003462 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003463 TemplateSpecializationTypeLoc SpecTL =
3464 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003465
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003466 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003467 getDerived().TransformTemplateName(SS,
3468 SpecTL.getTypePtr()->getTemplateName(),
3469 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003470 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003471 if (Template.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003472 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003473
3474 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003475 Template);
3476 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003477 DependentTemplateSpecializationTypeLoc SpecTL =
3478 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003479
Douglas Gregora88f09f2011-02-28 17:23:35 +00003480 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003481 = getDerived().RebuildTemplateName(SS,
3482 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003483 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003484 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003485 if (Template.isNull())
3486 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003487
3488 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003489 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003490 Template,
3491 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003492 } else {
3493 // Nothing special needs to be done for these.
3494 Result = getDerived().TransformType(TLB, TL);
3495 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003496
3497 if (Result.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003498 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003499
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003500 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3501}
3502
Douglas Gregorb71d8212011-03-02 18:32:08 +00003503template<typename Derived>
3504TypeSourceInfo *
3505TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3506 QualType ObjectType,
3507 NamedDecl *UnqualLookup,
3508 CXXScopeSpec &SS) {
3509 // FIXME: Painfully copy-paste from the above!
Chad Rosier4a9d7952012-08-08 18:46:20 +00003510
Douglas Gregorb71d8212011-03-02 18:32:08 +00003511 QualType T = TSInfo->getType();
3512 if (getDerived().AlreadyTransformed(T))
3513 return TSInfo;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003514
Douglas Gregorb71d8212011-03-02 18:32:08 +00003515 TypeLocBuilder TLB;
3516 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003517
Douglas Gregorb71d8212011-03-02 18:32:08 +00003518 TypeLoc TL = TSInfo->getTypeLoc();
3519 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003520 TemplateSpecializationTypeLoc SpecTL =
3521 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003522
Douglas Gregorb71d8212011-03-02 18:32:08 +00003523 TemplateName Template
3524 = getDerived().TransformTemplateName(SS,
3525 SpecTL.getTypePtr()->getTemplateName(),
3526 SpecTL.getTemplateNameLoc(),
3527 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003528 if (Template.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003529 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003530
3531 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003532 Template);
3533 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003534 DependentTemplateSpecializationTypeLoc SpecTL =
3535 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003536
Douglas Gregorb71d8212011-03-02 18:32:08 +00003537 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003538 = getDerived().RebuildTemplateName(SS,
3539 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003540 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003541 ObjectType, UnqualLookup);
3542 if (Template.isNull())
3543 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003544
3545 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003546 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003547 Template,
3548 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003549 } else {
3550 // Nothing special needs to be done for these.
3551 Result = getDerived().TransformType(TLB, TL);
3552 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003553
3554 if (Result.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003555 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003556
Douglas Gregorb71d8212011-03-02 18:32:08 +00003557 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3558}
3559
John McCalla2becad2009-10-21 00:40:46 +00003560template <class TyLoc> static inline
3561QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3562 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3563 NewT.setNameLoc(T.getNameLoc());
3564 return T.getType();
3565}
3566
John McCalla2becad2009-10-21 00:40:46 +00003567template<typename Derived>
3568QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003569 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003570 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3571 NewT.setBuiltinLoc(T.getBuiltinLoc());
3572 if (T.needsExtraLocalData())
3573 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3574 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003575}
Mike Stump1eb44332009-09-09 15:08:12 +00003576
Douglas Gregor577f75a2009-08-04 16:50:30 +00003577template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003578QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003579 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003580 // FIXME: recurse?
3581 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003582}
Mike Stump1eb44332009-09-09 15:08:12 +00003583
Douglas Gregor577f75a2009-08-04 16:50:30 +00003584template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003585QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003586 PointerTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003587 QualType PointeeType
3588 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003589 if (PointeeType.isNull())
3590 return QualType();
3591
3592 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003593 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003594 // A dependent pointer type 'T *' has is being transformed such
3595 // that an Objective-C class type is being replaced for 'T'. The
3596 // resulting pointer type is an ObjCObjectPointerType, not a
3597 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003598 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003599
John McCallc12c5bb2010-05-15 11:32:37 +00003600 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3601 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003602 return Result;
3603 }
John McCall43fed0d2010-11-12 08:19:04 +00003604
Douglas Gregor92e986e2010-04-22 16:44:27 +00003605 if (getDerived().AlwaysRebuild() ||
3606 PointeeType != TL.getPointeeLoc().getType()) {
3607 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3608 if (Result.isNull())
3609 return QualType();
3610 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003611
John McCallf85e1932011-06-15 23:02:42 +00003612 // Objective-C ARC can add lifetime qualifiers to the type that we're
3613 // pointing to.
3614 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003615
Douglas Gregor92e986e2010-04-22 16:44:27 +00003616 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3617 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003618 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003619}
Mike Stump1eb44332009-09-09 15:08:12 +00003620
3621template<typename Derived>
3622QualType
John McCalla2becad2009-10-21 00:40:46 +00003623TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003624 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003625 QualType PointeeType
Chad Rosier4a9d7952012-08-08 18:46:20 +00003626 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3627 if (PointeeType.isNull())
3628 return QualType();
3629
3630 QualType Result = TL.getType();
3631 if (getDerived().AlwaysRebuild() ||
3632 PointeeType != TL.getPointeeLoc().getType()) {
3633 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003634 TL.getSigilLoc());
3635 if (Result.isNull())
3636 return QualType();
3637 }
3638
Douglas Gregor39968ad2010-04-22 16:50:51 +00003639 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003640 NewT.setSigilLoc(TL.getSigilLoc());
3641 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003642}
3643
John McCall85737a72009-10-30 00:06:24 +00003644/// Transforms a reference type. Note that somewhat paradoxically we
3645/// don't care whether the type itself is an l-value type or an r-value
3646/// type; we only care if the type was *written* as an l-value type
3647/// or an r-value type.
3648template<typename Derived>
3649QualType
3650TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003651 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003652 const ReferenceType *T = TL.getTypePtr();
3653
3654 // Note that this works with the pointee-as-written.
3655 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3656 if (PointeeType.isNull())
3657 return QualType();
3658
3659 QualType Result = TL.getType();
3660 if (getDerived().AlwaysRebuild() ||
3661 PointeeType != T->getPointeeTypeAsWritten()) {
3662 Result = getDerived().RebuildReferenceType(PointeeType,
3663 T->isSpelledAsLValue(),
3664 TL.getSigilLoc());
3665 if (Result.isNull())
3666 return QualType();
3667 }
3668
John McCallf85e1932011-06-15 23:02:42 +00003669 // Objective-C ARC can add lifetime qualifiers to the type that we're
3670 // referring to.
3671 TLB.TypeWasModifiedSafely(
3672 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3673
John McCall85737a72009-10-30 00:06:24 +00003674 // r-value references can be rebuilt as l-value references.
3675 ReferenceTypeLoc NewTL;
3676 if (isa<LValueReferenceType>(Result))
3677 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3678 else
3679 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3680 NewTL.setSigilLoc(TL.getSigilLoc());
3681
3682 return Result;
3683}
3684
Mike Stump1eb44332009-09-09 15:08:12 +00003685template<typename Derived>
3686QualType
John McCalla2becad2009-10-21 00:40:46 +00003687TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003688 LValueReferenceTypeLoc TL) {
3689 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003690}
3691
Mike Stump1eb44332009-09-09 15:08:12 +00003692template<typename Derived>
3693QualType
John McCalla2becad2009-10-21 00:40:46 +00003694TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003695 RValueReferenceTypeLoc TL) {
3696 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003697}
Mike Stump1eb44332009-09-09 15:08:12 +00003698
Douglas Gregor577f75a2009-08-04 16:50:30 +00003699template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003700QualType
John McCalla2becad2009-10-21 00:40:46 +00003701TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003702 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003703 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003704 if (PointeeType.isNull())
3705 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003706
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003707 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3708 TypeSourceInfo* NewClsTInfo = 0;
3709 if (OldClsTInfo) {
3710 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3711 if (!NewClsTInfo)
3712 return QualType();
3713 }
3714
3715 const MemberPointerType *T = TL.getTypePtr();
3716 QualType OldClsType = QualType(T->getClass(), 0);
3717 QualType NewClsType;
3718 if (NewClsTInfo)
3719 NewClsType = NewClsTInfo->getType();
3720 else {
3721 NewClsType = getDerived().TransformType(OldClsType);
3722 if (NewClsType.isNull())
3723 return QualType();
3724 }
Mike Stump1eb44332009-09-09 15:08:12 +00003725
John McCalla2becad2009-10-21 00:40:46 +00003726 QualType Result = TL.getType();
3727 if (getDerived().AlwaysRebuild() ||
3728 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003729 NewClsType != OldClsType) {
3730 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003731 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003732 if (Result.isNull())
3733 return QualType();
3734 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003735
John McCalla2becad2009-10-21 00:40:46 +00003736 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3737 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003738 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003739
3740 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003741}
3742
Mike Stump1eb44332009-09-09 15:08:12 +00003743template<typename Derived>
3744QualType
John McCalla2becad2009-10-21 00:40:46 +00003745TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003746 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003747 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003748 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003749 if (ElementType.isNull())
3750 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003751
John McCalla2becad2009-10-21 00:40:46 +00003752 QualType Result = TL.getType();
3753 if (getDerived().AlwaysRebuild() ||
3754 ElementType != T->getElementType()) {
3755 Result = getDerived().RebuildConstantArrayType(ElementType,
3756 T->getSizeModifier(),
3757 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003758 T->getIndexTypeCVRQualifiers(),
3759 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003760 if (Result.isNull())
3761 return QualType();
3762 }
Eli Friedman457a3772012-01-25 22:19:07 +00003763
3764 // We might have either a ConstantArrayType or a VariableArrayType now:
3765 // a ConstantArrayType is allowed to have an element type which is a
3766 // VariableArrayType if the type is dependent. Fortunately, all array
3767 // types have the same location layout.
3768 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003769 NewTL.setLBracketLoc(TL.getLBracketLoc());
3770 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003771
John McCalla2becad2009-10-21 00:40:46 +00003772 Expr *Size = TL.getSizeExpr();
3773 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003774 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3775 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003776 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003777 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003778 }
3779 NewTL.setSizeExpr(Size);
3780
3781 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003782}
Mike Stump1eb44332009-09-09 15:08:12 +00003783
Douglas Gregor577f75a2009-08-04 16:50:30 +00003784template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003785QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003786 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003787 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003788 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003789 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003790 if (ElementType.isNull())
3791 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003792
John McCalla2becad2009-10-21 00:40:46 +00003793 QualType Result = TL.getType();
3794 if (getDerived().AlwaysRebuild() ||
3795 ElementType != T->getElementType()) {
3796 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003797 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003798 T->getIndexTypeCVRQualifiers(),
3799 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003800 if (Result.isNull())
3801 return QualType();
3802 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003803
John McCalla2becad2009-10-21 00:40:46 +00003804 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3805 NewTL.setLBracketLoc(TL.getLBracketLoc());
3806 NewTL.setRBracketLoc(TL.getRBracketLoc());
3807 NewTL.setSizeExpr(0);
3808
3809 return Result;
3810}
3811
3812template<typename Derived>
3813QualType
3814TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003815 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003816 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003817 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3818 if (ElementType.isNull())
3819 return QualType();
3820
John McCall60d7b3a2010-08-24 06:29:42 +00003821 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003822 = getDerived().TransformExpr(T->getSizeExpr());
3823 if (SizeResult.isInvalid())
3824 return QualType();
3825
John McCall9ae2f072010-08-23 23:25:46 +00003826 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003827
3828 QualType Result = TL.getType();
3829 if (getDerived().AlwaysRebuild() ||
3830 ElementType != T->getElementType() ||
3831 Size != T->getSizeExpr()) {
3832 Result = getDerived().RebuildVariableArrayType(ElementType,
3833 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003834 Size,
John McCalla2becad2009-10-21 00:40:46 +00003835 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003836 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003837 if (Result.isNull())
3838 return QualType();
3839 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003840
John McCalla2becad2009-10-21 00:40:46 +00003841 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3842 NewTL.setLBracketLoc(TL.getLBracketLoc());
3843 NewTL.setRBracketLoc(TL.getRBracketLoc());
3844 NewTL.setSizeExpr(Size);
3845
3846 return Result;
3847}
3848
3849template<typename Derived>
3850QualType
3851TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003852 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003853 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003854 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3855 if (ElementType.isNull())
3856 return QualType();
3857
Richard Smithf6702a32011-12-20 02:08:33 +00003858 // Array bounds are constant expressions.
3859 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3860 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003861
John McCall3b657512011-01-19 10:06:00 +00003862 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3863 Expr *origSize = TL.getSizeExpr();
3864 if (!origSize) origSize = T->getSizeExpr();
3865
3866 ExprResult sizeResult
3867 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003868 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003869 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003870 return QualType();
3871
John McCall3b657512011-01-19 10:06:00 +00003872 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003873
3874 QualType Result = TL.getType();
3875 if (getDerived().AlwaysRebuild() ||
3876 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003877 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003878 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3879 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003880 size,
John McCalla2becad2009-10-21 00:40:46 +00003881 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003882 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003883 if (Result.isNull())
3884 return QualType();
3885 }
John McCalla2becad2009-10-21 00:40:46 +00003886
3887 // We might have any sort of array type now, but fortunately they
3888 // all have the same location layout.
3889 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3890 NewTL.setLBracketLoc(TL.getLBracketLoc());
3891 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003892 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003893
3894 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003895}
Mike Stump1eb44332009-09-09 15:08:12 +00003896
3897template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003898QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003899 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003900 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003901 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003902
3903 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003904 QualType ElementType = getDerived().TransformType(T->getElementType());
3905 if (ElementType.isNull())
3906 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003907
Richard Smithf6702a32011-12-20 02:08:33 +00003908 // Vector sizes are constant expressions.
3909 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3910 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003911
John McCall60d7b3a2010-08-24 06:29:42 +00003912 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00003913 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003914 if (Size.isInvalid())
3915 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003916
John McCalla2becad2009-10-21 00:40:46 +00003917 QualType Result = TL.getType();
3918 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003919 ElementType != T->getElementType() ||
3920 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003921 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003922 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003923 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003924 if (Result.isNull())
3925 return QualType();
3926 }
John McCalla2becad2009-10-21 00:40:46 +00003927
3928 // Result might be dependent or not.
3929 if (isa<DependentSizedExtVectorType>(Result)) {
3930 DependentSizedExtVectorTypeLoc NewTL
3931 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3932 NewTL.setNameLoc(TL.getNameLoc());
3933 } else {
3934 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3935 NewTL.setNameLoc(TL.getNameLoc());
3936 }
3937
3938 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003939}
Mike Stump1eb44332009-09-09 15:08:12 +00003940
3941template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003942QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003943 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003944 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003945 QualType ElementType = getDerived().TransformType(T->getElementType());
3946 if (ElementType.isNull())
3947 return QualType();
3948
John McCalla2becad2009-10-21 00:40:46 +00003949 QualType Result = TL.getType();
3950 if (getDerived().AlwaysRebuild() ||
3951 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003952 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003953 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003954 if (Result.isNull())
3955 return QualType();
3956 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003957
John McCalla2becad2009-10-21 00:40:46 +00003958 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3959 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003960
John McCalla2becad2009-10-21 00:40:46 +00003961 return Result;
3962}
3963
3964template<typename Derived>
3965QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003966 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003967 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003968 QualType ElementType = getDerived().TransformType(T->getElementType());
3969 if (ElementType.isNull())
3970 return QualType();
3971
3972 QualType Result = TL.getType();
3973 if (getDerived().AlwaysRebuild() ||
3974 ElementType != T->getElementType()) {
3975 Result = getDerived().RebuildExtVectorType(ElementType,
3976 T->getNumElements(),
3977 /*FIXME*/ SourceLocation());
3978 if (Result.isNull())
3979 return QualType();
3980 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003981
John McCalla2becad2009-10-21 00:40:46 +00003982 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3983 NewTL.setNameLoc(TL.getNameLoc());
3984
3985 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003986}
Mike Stump1eb44332009-09-09 15:08:12 +00003987
David Blaikiedc84cd52013-02-20 22:23:23 +00003988template <typename Derived>
3989ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
3990 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
3991 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00003992 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003993 TypeSourceInfo *NewDI = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003994
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003995 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003996 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003997 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003998 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00003999 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004000
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004001 TypeLocBuilder TLB;
4002 TypeLoc NewTL = OldDI->getTypeLoc();
4003 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004004
4005 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004006 OldExpansionTL.getPatternLoc());
4007 if (Result.isNull())
4008 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004009
4010 Result = RebuildPackExpansionType(Result,
4011 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004012 OldExpansionTL.getEllipsisLoc(),
4013 NumExpansions);
4014 if (Result.isNull())
4015 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004016
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004017 PackExpansionTypeLoc NewExpansionTL
4018 = TLB.push<PackExpansionTypeLoc>(Result);
4019 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4020 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4021 } else
4022 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00004023 if (!NewDI)
4024 return 0;
4025
John McCallfb44de92011-05-01 22:35:37 +00004026 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00004027 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00004028
4029 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4030 OldParm->getDeclContext(),
4031 OldParm->getInnerLocStart(),
4032 OldParm->getLocation(),
4033 OldParm->getIdentifier(),
4034 NewDI->getType(),
4035 NewDI,
4036 OldParm->getStorageClass(),
John McCallfb44de92011-05-01 22:35:37 +00004037 /* DefArg */ NULL);
4038 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4039 OldParm->getFunctionScopeIndex() + indexAdjustment);
4040 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00004041}
4042
4043template<typename Derived>
4044bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00004045 TransformFunctionTypeParams(SourceLocation Loc,
4046 ParmVarDecl **Params, unsigned NumParams,
4047 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00004048 SmallVectorImpl<QualType> &OutParamTypes,
4049 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00004050 int indexAdjustment = 0;
4051
Douglas Gregora009b592011-01-07 00:20:55 +00004052 for (unsigned i = 0; i != NumParams; ++i) {
4053 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00004054 assert(OldParm->getFunctionScopeIndex() == i);
4055
David Blaikiedc84cd52013-02-20 22:23:23 +00004056 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004057 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004058 if (OldParm->isParameterPack()) {
4059 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00004060 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00004061
Douglas Gregor603cfb42011-01-05 23:12:31 +00004062 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004063 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00004064 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004065 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4066 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004067 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4068
Douglas Gregor603cfb42011-01-05 23:12:31 +00004069 // Determine whether we should expand the parameter packs.
4070 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004071 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004072 Optional<unsigned> OrigNumExpansions =
4073 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004074 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004075 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4076 Pattern.getSourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004077 Unexpanded,
4078 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004079 RetainExpansion,
4080 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004081 return true;
4082 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004083
Douglas Gregor603cfb42011-01-05 23:12:31 +00004084 if (ShouldExpand) {
4085 // Expand the function parameter pack into multiple, separate
4086 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00004087 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00004088 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004089 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004090 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004091 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004092 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004093 OrigNumExpansions,
4094 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004095 if (!NewParm)
4096 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004097
Douglas Gregora009b592011-01-07 00:20:55 +00004098 OutParamTypes.push_back(NewParm->getType());
4099 if (PVars)
4100 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004101 }
Douglas Gregord3731192011-01-10 07:32:04 +00004102
4103 // If we're supposed to retain a pack expansion, do so by temporarily
4104 // forgetting the partially-substituted parameter pack.
4105 if (RetainExpansion) {
4106 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004107 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004108 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004109 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004110 OrigNumExpansions,
4111 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00004112 if (!NewParm)
4113 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004114
Douglas Gregord3731192011-01-10 07:32:04 +00004115 OutParamTypes.push_back(NewParm->getType());
4116 if (PVars)
4117 PVars->push_back(NewParm);
4118 }
4119
John McCallfb44de92011-05-01 22:35:37 +00004120 // The next parameter should have the same adjustment as the
4121 // last thing we pushed, but we post-incremented indexAdjustment
4122 // on every push. Also, if we push nothing, the adjustment should
4123 // go down by one.
4124 indexAdjustment--;
4125
Douglas Gregor603cfb42011-01-05 23:12:31 +00004126 // We're done with the pack expansion.
4127 continue;
4128 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004129
4130 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004131 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004132 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4133 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004134 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004135 NumExpansions,
4136 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004137 } else {
David Blaikiedc84cd52013-02-20 22:23:23 +00004138 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie66874fb2013-02-21 01:47:18 +00004139 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004140 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004141
John McCall21ef0fa2010-03-11 09:03:00 +00004142 if (!NewParm)
4143 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004144
Douglas Gregora009b592011-01-07 00:20:55 +00004145 OutParamTypes.push_back(NewParm->getType());
4146 if (PVars)
4147 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004148 continue;
4149 }
John McCall21ef0fa2010-03-11 09:03:00 +00004150
4151 // Deal with the possibility that we don't have a parameter
4152 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004153 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004154 bool IsPackExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004155 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004156 QualType NewType;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004157 if (const PackExpansionType *Expansion
Douglas Gregor603cfb42011-01-05 23:12:31 +00004158 = dyn_cast<PackExpansionType>(OldType)) {
4159 // We have a function parameter pack that may need to be expanded.
4160 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004161 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004162 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004163
Douglas Gregor603cfb42011-01-05 23:12:31 +00004164 // Determine whether we should expand the parameter packs.
4165 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004166 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004167 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004168 Unexpanded,
4169 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004170 RetainExpansion,
4171 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004172 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004173 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004174
Douglas Gregor603cfb42011-01-05 23:12:31 +00004175 if (ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004176 // Expand the function parameter pack into multiple, separate
Douglas Gregor603cfb42011-01-05 23:12:31 +00004177 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004178 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004179 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4180 QualType NewType = getDerived().TransformType(Pattern);
4181 if (NewType.isNull())
4182 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004183
Douglas Gregora009b592011-01-07 00:20:55 +00004184 OutParamTypes.push_back(NewType);
4185 if (PVars)
4186 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004187 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004188
Douglas Gregor603cfb42011-01-05 23:12:31 +00004189 // We're done with the pack expansion.
4190 continue;
4191 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004192
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004193 // If we're supposed to retain a pack expansion, do so by temporarily
4194 // forgetting the partially-substituted parameter pack.
4195 if (RetainExpansion) {
4196 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4197 QualType NewType = getDerived().TransformType(Pattern);
4198 if (NewType.isNull())
4199 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004200
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004201 OutParamTypes.push_back(NewType);
4202 if (PVars)
4203 PVars->push_back(0);
4204 }
Douglas Gregord3731192011-01-10 07:32:04 +00004205
Chad Rosier4a9d7952012-08-08 18:46:20 +00004206 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004207 // expansion.
4208 OldType = Expansion->getPattern();
4209 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004210 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4211 NewType = getDerived().TransformType(OldType);
4212 } else {
4213 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004214 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004215
Douglas Gregor603cfb42011-01-05 23:12:31 +00004216 if (NewType.isNull())
4217 return true;
4218
4219 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004220 NewType = getSema().Context.getPackExpansionType(NewType,
4221 NumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004222
Douglas Gregora009b592011-01-07 00:20:55 +00004223 OutParamTypes.push_back(NewType);
4224 if (PVars)
4225 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004226 }
4227
John McCallfb44de92011-05-01 22:35:37 +00004228#ifndef NDEBUG
4229 if (PVars) {
4230 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4231 if (ParmVarDecl *parm = (*PVars)[i])
4232 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004233 }
John McCallfb44de92011-05-01 22:35:37 +00004234#endif
4235
4236 return false;
4237}
John McCall21ef0fa2010-03-11 09:03:00 +00004238
4239template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004240QualType
John McCalla2becad2009-10-21 00:40:46 +00004241TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004242 FunctionProtoTypeLoc TL) {
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004243 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4244}
4245
4246template<typename Derived>
4247QualType
4248TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4249 FunctionProtoTypeLoc TL,
4250 CXXRecordDecl *ThisContext,
4251 unsigned ThisTypeQuals) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004252 // Transform the parameters and return type.
4253 //
Richard Smithe6975e92012-04-17 00:58:00 +00004254 // We are required to instantiate the params and return type in source order.
Douglas Gregordab60ad2010-10-01 18:44:50 +00004255 // When the function has a trailing return type, we instantiate the
4256 // parameters before the return type, since the return type can then refer
4257 // to the parameters themselves (via decltype, sizeof, etc.).
4258 //
Chris Lattner686775d2011-07-20 06:58:45 +00004259 SmallVector<QualType, 4> ParamTypes;
4260 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004261 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004262
Douglas Gregordab60ad2010-10-01 18:44:50 +00004263 QualType ResultType;
4264
Richard Smith9fbf3272012-08-14 22:51:13 +00004265 if (T->hasTrailingReturn()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004266 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004267 TL.getParmArray(),
4268 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004269 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004270 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004271 return QualType();
4272
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004273 {
4274 // C++11 [expr.prim.general]p3:
Chad Rosier4a9d7952012-08-08 18:46:20 +00004275 // If a declaration declares a member function or member function
4276 // template of a class X, the expression this is a prvalue of type
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004277 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier4a9d7952012-08-08 18:46:20 +00004278 // and the end of the function-definition, member-declarator, or
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004279 // declarator.
4280 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004281
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004282 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4283 if (ResultType.isNull())
4284 return QualType();
4285 }
Douglas Gregordab60ad2010-10-01 18:44:50 +00004286 }
4287 else {
4288 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4289 if (ResultType.isNull())
4290 return QualType();
4291
Chad Rosier4a9d7952012-08-08 18:46:20 +00004292 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004293 TL.getParmArray(),
4294 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004295 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004296 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004297 return QualType();
4298 }
4299
Richard Smithe6975e92012-04-17 00:58:00 +00004300 // FIXME: Need to transform the exception-specification too.
4301
John McCalla2becad2009-10-21 00:40:46 +00004302 QualType Result = TL.getType();
4303 if (getDerived().AlwaysRebuild() ||
4304 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004305 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004306 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
Jordan Rosebea522f2013-03-08 21:51:21 +00004307 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00004308 T->getExtProtoInfo());
John McCalla2becad2009-10-21 00:40:46 +00004309 if (Result.isNull())
4310 return QualType();
4311 }
Mike Stump1eb44332009-09-09 15:08:12 +00004312
John McCalla2becad2009-10-21 00:40:46 +00004313 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004314 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004315 NewTL.setLParenLoc(TL.getLParenLoc());
4316 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004317 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004318 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4319 NewTL.setArg(i, ParamDecls[i]);
4320
4321 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004322}
Mike Stump1eb44332009-09-09 15:08:12 +00004323
Douglas Gregor577f75a2009-08-04 16:50:30 +00004324template<typename Derived>
4325QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004326 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004327 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004328 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004329 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4330 if (ResultType.isNull())
4331 return QualType();
4332
4333 QualType Result = TL.getType();
4334 if (getDerived().AlwaysRebuild() ||
4335 ResultType != T->getResultType())
4336 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4337
4338 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004339 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004340 NewTL.setLParenLoc(TL.getLParenLoc());
4341 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004342 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004343
4344 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004345}
Mike Stump1eb44332009-09-09 15:08:12 +00004346
John McCalled976492009-12-04 22:46:56 +00004347template<typename Derived> QualType
4348TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004349 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004350 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004351 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004352 if (!D)
4353 return QualType();
4354
4355 QualType Result = TL.getType();
4356 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4357 Result = getDerived().RebuildUnresolvedUsingType(D);
4358 if (Result.isNull())
4359 return QualType();
4360 }
4361
4362 // We might get an arbitrary type spec type back. We should at
4363 // least always get a type spec type, though.
4364 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4365 NewTL.setNameLoc(TL.getNameLoc());
4366
4367 return Result;
4368}
4369
Douglas Gregor577f75a2009-08-04 16:50:30 +00004370template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004371QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004372 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004373 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004374 TypedefNameDecl *Typedef
4375 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4376 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004377 if (!Typedef)
4378 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004379
John McCalla2becad2009-10-21 00:40:46 +00004380 QualType Result = TL.getType();
4381 if (getDerived().AlwaysRebuild() ||
4382 Typedef != T->getDecl()) {
4383 Result = getDerived().RebuildTypedefType(Typedef);
4384 if (Result.isNull())
4385 return QualType();
4386 }
Mike Stump1eb44332009-09-09 15:08:12 +00004387
John McCalla2becad2009-10-21 00:40:46 +00004388 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4389 NewTL.setNameLoc(TL.getNameLoc());
4390
4391 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004392}
Mike Stump1eb44332009-09-09 15:08:12 +00004393
Douglas Gregor577f75a2009-08-04 16:50:30 +00004394template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004395QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004396 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004397 // typeof expressions are not potentially evaluated contexts
Eli Friedman80bfa3d2012-09-26 04:34:21 +00004398 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4399 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00004400
John McCall60d7b3a2010-08-24 06:29:42 +00004401 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004402 if (E.isInvalid())
4403 return QualType();
4404
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004405 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4406 if (E.isInvalid())
4407 return QualType();
4408
John McCalla2becad2009-10-21 00:40:46 +00004409 QualType Result = TL.getType();
4410 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004411 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004412 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004413 if (Result.isNull())
4414 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004415 }
John McCalla2becad2009-10-21 00:40:46 +00004416 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004417
John McCalla2becad2009-10-21 00:40:46 +00004418 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004419 NewTL.setTypeofLoc(TL.getTypeofLoc());
4420 NewTL.setLParenLoc(TL.getLParenLoc());
4421 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004422
4423 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004424}
Mike Stump1eb44332009-09-09 15:08:12 +00004425
4426template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004427QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004428 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004429 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4430 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4431 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004432 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004433
John McCalla2becad2009-10-21 00:40:46 +00004434 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004435 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4436 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004437 if (Result.isNull())
4438 return QualType();
4439 }
Mike Stump1eb44332009-09-09 15:08:12 +00004440
John McCalla2becad2009-10-21 00:40:46 +00004441 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004442 NewTL.setTypeofLoc(TL.getTypeofLoc());
4443 NewTL.setLParenLoc(TL.getLParenLoc());
4444 NewTL.setRParenLoc(TL.getRParenLoc());
4445 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004446
4447 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004448}
Mike Stump1eb44332009-09-09 15:08:12 +00004449
4450template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004451QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004452 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004453 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004454
Douglas Gregor670444e2009-08-04 22:27:00 +00004455 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004456 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4457 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004458
John McCall60d7b3a2010-08-24 06:29:42 +00004459 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004460 if (E.isInvalid())
4461 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004462
Richard Smith76f3f692012-02-22 02:04:18 +00004463 E = getSema().ActOnDecltypeExpression(E.take());
4464 if (E.isInvalid())
4465 return QualType();
4466
John McCalla2becad2009-10-21 00:40:46 +00004467 QualType Result = TL.getType();
4468 if (getDerived().AlwaysRebuild() ||
4469 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004470 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004471 if (Result.isNull())
4472 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004473 }
John McCalla2becad2009-10-21 00:40:46 +00004474 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004475
John McCalla2becad2009-10-21 00:40:46 +00004476 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4477 NewTL.setNameLoc(TL.getNameLoc());
4478
4479 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004480}
4481
4482template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004483QualType TreeTransform<Derived>::TransformUnaryTransformType(
4484 TypeLocBuilder &TLB,
4485 UnaryTransformTypeLoc TL) {
4486 QualType Result = TL.getType();
4487 if (Result->isDependentType()) {
4488 const UnaryTransformType *T = TL.getTypePtr();
4489 QualType NewBase =
4490 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4491 Result = getDerived().RebuildUnaryTransformType(NewBase,
4492 T->getUTTKind(),
4493 TL.getKWLoc());
4494 if (Result.isNull())
4495 return QualType();
4496 }
4497
4498 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4499 NewTL.setKWLoc(TL.getKWLoc());
4500 NewTL.setParensRange(TL.getParensRange());
4501 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4502 return Result;
4503}
4504
4505template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004506QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4507 AutoTypeLoc TL) {
4508 const AutoType *T = TL.getTypePtr();
4509 QualType OldDeduced = T->getDeducedType();
4510 QualType NewDeduced;
4511 if (!OldDeduced.isNull()) {
4512 NewDeduced = getDerived().TransformType(OldDeduced);
4513 if (NewDeduced.isNull())
4514 return QualType();
4515 }
4516
4517 QualType Result = TL.getType();
Richard Smithdc7a4f52013-04-30 13:56:41 +00004518 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4519 T->isDependentType()) {
Richard Smitha2c36462013-04-26 16:15:35 +00004520 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith34b41d92011-02-20 03:19:35 +00004521 if (Result.isNull())
4522 return QualType();
4523 }
4524
4525 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4526 NewTL.setNameLoc(TL.getNameLoc());
4527
4528 return Result;
4529}
4530
4531template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004532QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004533 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004534 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004535 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004536 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4537 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004538 if (!Record)
4539 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004540
John McCalla2becad2009-10-21 00:40:46 +00004541 QualType Result = TL.getType();
4542 if (getDerived().AlwaysRebuild() ||
4543 Record != T->getDecl()) {
4544 Result = getDerived().RebuildRecordType(Record);
4545 if (Result.isNull())
4546 return QualType();
4547 }
Mike Stump1eb44332009-09-09 15:08:12 +00004548
John McCalla2becad2009-10-21 00:40:46 +00004549 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4550 NewTL.setNameLoc(TL.getNameLoc());
4551
4552 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004553}
Mike Stump1eb44332009-09-09 15:08:12 +00004554
4555template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004556QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004557 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004558 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004559 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004560 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4561 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004562 if (!Enum)
4563 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004564
John McCalla2becad2009-10-21 00:40:46 +00004565 QualType Result = TL.getType();
4566 if (getDerived().AlwaysRebuild() ||
4567 Enum != T->getDecl()) {
4568 Result = getDerived().RebuildEnumType(Enum);
4569 if (Result.isNull())
4570 return QualType();
4571 }
Mike Stump1eb44332009-09-09 15:08:12 +00004572
John McCalla2becad2009-10-21 00:40:46 +00004573 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4574 NewTL.setNameLoc(TL.getNameLoc());
4575
4576 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004577}
John McCall7da24312009-09-05 00:15:47 +00004578
John McCall3cb0ebd2010-03-10 03:28:59 +00004579template<typename Derived>
4580QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4581 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004582 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004583 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4584 TL.getTypePtr()->getDecl());
4585 if (!D) return QualType();
4586
4587 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4588 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4589 return T;
4590}
4591
Douglas Gregor577f75a2009-08-04 16:50:30 +00004592template<typename Derived>
4593QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004594 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004595 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004596 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004597}
4598
Mike Stump1eb44332009-09-09 15:08:12 +00004599template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004600QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004601 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004602 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004603 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004604
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004605 // Substitute into the replacement type, which itself might involve something
4606 // that needs to be transformed. This only tends to occur with default
4607 // template arguments of template template parameters.
4608 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4609 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4610 if (Replacement.isNull())
4611 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004612
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004613 // Always canonicalize the replacement type.
4614 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4615 QualType Result
Chad Rosier4a9d7952012-08-08 18:46:20 +00004616 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004617 Replacement);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004618
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004619 // Propagate type-source information.
4620 SubstTemplateTypeParmTypeLoc NewTL
4621 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4622 NewTL.setNameLoc(TL.getNameLoc());
4623 return Result;
4624
John McCall49a832b2009-10-18 09:09:24 +00004625}
4626
4627template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004628QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4629 TypeLocBuilder &TLB,
4630 SubstTemplateTypeParmPackTypeLoc TL) {
4631 return TransformTypeSpecType(TLB, TL);
4632}
4633
4634template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004635QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004636 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004637 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004638 const TemplateSpecializationType *T = TL.getTypePtr();
4639
Douglas Gregor1d752d72011-03-02 18:46:51 +00004640 // The nested-name-specifier never matters in a TemplateSpecializationType,
4641 // because we can't have a dependent nested-name-specifier anyway.
4642 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004643 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004644 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4645 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004646 if (Template.isNull())
4647 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004648
John McCall43fed0d2010-11-12 08:19:04 +00004649 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4650}
4651
Eli Friedmanb001de72011-10-06 23:00:33 +00004652template<typename Derived>
4653QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4654 AtomicTypeLoc TL) {
4655 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4656 if (ValueType.isNull())
4657 return QualType();
4658
4659 QualType Result = TL.getType();
4660 if (getDerived().AlwaysRebuild() ||
4661 ValueType != TL.getValueLoc().getType()) {
4662 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4663 if (Result.isNull())
4664 return QualType();
4665 }
4666
4667 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4668 NewTL.setKWLoc(TL.getKWLoc());
4669 NewTL.setLParenLoc(TL.getLParenLoc());
4670 NewTL.setRParenLoc(TL.getRParenLoc());
4671
4672 return Result;
4673}
4674
Chad Rosier4a9d7952012-08-08 18:46:20 +00004675 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004676 /// container that provides a \c getArgLoc() member function.
4677 ///
4678 /// This iterator is intended to be used with the iterator form of
4679 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4680 template<typename ArgLocContainer>
4681 class TemplateArgumentLocContainerIterator {
4682 ArgLocContainer *Container;
4683 unsigned Index;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004684
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004685 public:
4686 typedef TemplateArgumentLoc value_type;
4687 typedef TemplateArgumentLoc reference;
4688 typedef int difference_type;
4689 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004690
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004691 class pointer {
4692 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004693
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004694 public:
4695 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004696
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004697 const TemplateArgumentLoc *operator->() const {
4698 return &Arg;
4699 }
4700 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004701
4702
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004703 TemplateArgumentLocContainerIterator() {}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004704
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004705 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4706 unsigned Index)
4707 : Container(&Container), Index(Index) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004708
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004709 TemplateArgumentLocContainerIterator &operator++() {
4710 ++Index;
4711 return *this;
4712 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004713
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004714 TemplateArgumentLocContainerIterator operator++(int) {
4715 TemplateArgumentLocContainerIterator Old(*this);
4716 ++(*this);
4717 return Old;
4718 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004719
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004720 TemplateArgumentLoc operator*() const {
4721 return Container->getArgLoc(Index);
4722 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004723
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004724 pointer operator->() const {
4725 return pointer(Container->getArgLoc(Index));
4726 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004727
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004728 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004729 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004730 return X.Container == Y.Container && X.Index == Y.Index;
4731 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004732
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004733 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004734 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004735 return !(X == Y);
4736 }
4737 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004738
4739
John McCall43fed0d2010-11-12 08:19:04 +00004740template <typename Derived>
4741QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4742 TypeLocBuilder &TLB,
4743 TemplateSpecializationTypeLoc TL,
4744 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004745 TemplateArgumentListInfo NewTemplateArgs;
4746 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4747 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004748 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4749 ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004750 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004751 ArgIterator(TL, TL.getNumArgs()),
4752 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004753 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004754
John McCall833ca992009-10-29 08:12:44 +00004755 // FIXME: maybe don't rebuild if all the template arguments are the same.
4756
4757 QualType Result =
4758 getDerived().RebuildTemplateSpecializationType(Template,
4759 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004760 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004761
4762 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004763 // Specializations of template template parameters are represented as
4764 // TemplateSpecializationTypes, and substitution of type alias templates
4765 // within a dependent context can transform them into
4766 // DependentTemplateSpecializationTypes.
4767 if (isa<DependentTemplateSpecializationType>(Result)) {
4768 DependentTemplateSpecializationTypeLoc NewTL
4769 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004770 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004771 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004772 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004773 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004774 NewTL.setLAngleLoc(TL.getLAngleLoc());
4775 NewTL.setRAngleLoc(TL.getRAngleLoc());
4776 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4777 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4778 return Result;
4779 }
4780
John McCall833ca992009-10-29 08:12:44 +00004781 TemplateSpecializationTypeLoc NewTL
4782 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004783 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004784 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4785 NewTL.setLAngleLoc(TL.getLAngleLoc());
4786 NewTL.setRAngleLoc(TL.getRAngleLoc());
4787 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4788 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004789 }
Mike Stump1eb44332009-09-09 15:08:12 +00004790
John McCall833ca992009-10-29 08:12:44 +00004791 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004792}
Mike Stump1eb44332009-09-09 15:08:12 +00004793
Douglas Gregora88f09f2011-02-28 17:23:35 +00004794template <typename Derived>
4795QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4796 TypeLocBuilder &TLB,
4797 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004798 TemplateName Template,
4799 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004800 TemplateArgumentListInfo NewTemplateArgs;
4801 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4802 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4803 typedef TemplateArgumentLocContainerIterator<
4804 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004805 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004806 ArgIterator(TL, TL.getNumArgs()),
4807 NewTemplateArgs))
4808 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004809
Douglas Gregora88f09f2011-02-28 17:23:35 +00004810 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier4a9d7952012-08-08 18:46:20 +00004811
Douglas Gregora88f09f2011-02-28 17:23:35 +00004812 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4813 QualType Result
4814 = getSema().Context.getDependentTemplateSpecializationType(
4815 TL.getTypePtr()->getKeyword(),
4816 DTN->getQualifier(),
4817 DTN->getIdentifier(),
4818 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004819
Douglas Gregora88f09f2011-02-28 17:23:35 +00004820 DependentTemplateSpecializationTypeLoc NewTL
4821 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004822 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004823 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004824 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004825 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004826 NewTL.setLAngleLoc(TL.getLAngleLoc());
4827 NewTL.setRAngleLoc(TL.getRAngleLoc());
4828 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4829 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4830 return Result;
4831 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004832
4833 QualType Result
Douglas Gregora88f09f2011-02-28 17:23:35 +00004834 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004835 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004836 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004837
Douglas Gregora88f09f2011-02-28 17:23:35 +00004838 if (!Result.isNull()) {
4839 /// FIXME: Wrap this in an elaborated-type-specifier?
4840 TemplateSpecializationTypeLoc NewTL
4841 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004842 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004843 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004844 NewTL.setLAngleLoc(TL.getLAngleLoc());
4845 NewTL.setRAngleLoc(TL.getRAngleLoc());
4846 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4847 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4848 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004849
Douglas Gregora88f09f2011-02-28 17:23:35 +00004850 return Result;
4851}
4852
Mike Stump1eb44332009-09-09 15:08:12 +00004853template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004854QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004855TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004856 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004857 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004858
Douglas Gregor9e876872011-03-01 18:12:44 +00004859 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004860 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004861 if (TL.getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004862 QualifierLoc
Douglas Gregor9e876872011-03-01 18:12:44 +00004863 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4864 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004865 return QualType();
4866 }
Mike Stump1eb44332009-09-09 15:08:12 +00004867
John McCall43fed0d2010-11-12 08:19:04 +00004868 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4869 if (NamedT.isNull())
4870 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004871
Richard Smith3e4c6c42011-05-05 21:57:07 +00004872 // C++0x [dcl.type.elab]p2:
4873 // If the identifier resolves to a typedef-name or the simple-template-id
4874 // resolves to an alias template specialization, the
4875 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004876 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4877 if (const TemplateSpecializationType *TST =
4878 NamedT->getAs<TemplateSpecializationType>()) {
4879 TemplateName Template = TST->getTemplateName();
4880 if (TypeAliasTemplateDecl *TAT =
4881 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4882 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4883 diag::err_tag_reference_non_tag) << 4;
4884 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4885 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004886 }
4887 }
4888
John McCalla2becad2009-10-21 00:40:46 +00004889 QualType Result = TL.getType();
4890 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004891 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004892 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00004893 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004894 T->getKeyword(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004895 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004896 if (Result.isNull())
4897 return QualType();
4898 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004899
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004900 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004901 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004902 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004903 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004904}
Mike Stump1eb44332009-09-09 15:08:12 +00004905
4906template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004907QualType TreeTransform<Derived>::TransformAttributedType(
4908 TypeLocBuilder &TLB,
4909 AttributedTypeLoc TL) {
4910 const AttributedType *oldType = TL.getTypePtr();
4911 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4912 if (modifiedType.isNull())
4913 return QualType();
4914
4915 QualType result = TL.getType();
4916
4917 // FIXME: dependent operand expressions?
4918 if (getDerived().AlwaysRebuild() ||
4919 modifiedType != oldType->getModifiedType()) {
4920 // TODO: this is really lame; we should really be rebuilding the
4921 // equivalent type from first principles.
4922 QualType equivalentType
4923 = getDerived().TransformType(oldType->getEquivalentType());
4924 if (equivalentType.isNull())
4925 return QualType();
4926 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4927 modifiedType,
4928 equivalentType);
4929 }
4930
4931 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4932 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4933 if (TL.hasAttrOperand())
4934 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4935 if (TL.hasAttrExprOperand())
4936 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4937 else if (TL.hasAttrEnumOperand())
4938 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4939
4940 return result;
4941}
4942
4943template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004944QualType
4945TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4946 ParenTypeLoc TL) {
4947 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4948 if (Inner.isNull())
4949 return QualType();
4950
4951 QualType Result = TL.getType();
4952 if (getDerived().AlwaysRebuild() ||
4953 Inner != TL.getInnerLoc().getType()) {
4954 Result = getDerived().RebuildParenType(Inner);
4955 if (Result.isNull())
4956 return QualType();
4957 }
4958
4959 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4960 NewTL.setLParenLoc(TL.getLParenLoc());
4961 NewTL.setRParenLoc(TL.getRParenLoc());
4962 return Result;
4963}
4964
4965template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004966QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004967 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004968 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004969
Douglas Gregor2494dd02011-03-01 01:34:45 +00004970 NestedNameSpecifierLoc QualifierLoc
4971 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4972 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004973 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004974
John McCall33500952010-06-11 00:33:02 +00004975 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004976 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00004977 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004978 QualifierLoc,
4979 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004980 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004981 if (Result.isNull())
4982 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004983
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004984 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4985 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004986 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4987
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004988 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004989 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004990 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004991 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004992 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004993 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004994 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004995 NewTL.setNameLoc(TL.getNameLoc());
4996 }
John McCalla2becad2009-10-21 00:40:46 +00004997 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004998}
Mike Stump1eb44332009-09-09 15:08:12 +00004999
Douglas Gregor577f75a2009-08-04 16:50:30 +00005000template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00005001QualType TreeTransform<Derived>::
5002 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005003 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005004 NestedNameSpecifierLoc QualifierLoc;
5005 if (TL.getQualifierLoc()) {
5006 QualifierLoc
5007 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5008 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00005009 return QualType();
5010 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005011
John McCall43fed0d2010-11-12 08:19:04 +00005012 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005013 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00005014}
5015
5016template<typename Derived>
5017QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005018TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5019 DependentTemplateSpecializationTypeLoc TL,
5020 NestedNameSpecifierLoc QualifierLoc) {
5021 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005022
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005023 TemplateArgumentListInfo NewTemplateArgs;
5024 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5025 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005026
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005027 typedef TemplateArgumentLocContainerIterator<
5028 DependentTemplateSpecializationTypeLoc> ArgIterator;
5029 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5030 ArgIterator(TL, TL.getNumArgs()),
5031 NewTemplateArgs))
5032 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005033
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005034 QualType Result
5035 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5036 QualifierLoc,
5037 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005038 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005039 NewTemplateArgs);
5040 if (Result.isNull())
5041 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005042
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005043 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5044 QualType NamedT = ElabT->getNamedType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005045
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005046 // Copy information relevant to the template specialization.
5047 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005048 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005049 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005050 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005051 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5052 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005053 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005054 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005055
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005056 // Copy information relevant to the elaborated type.
5057 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005058 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005059 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005060 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5061 DependentTemplateSpecializationTypeLoc SpecTL
5062 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005063 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005064 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005065 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005066 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005067 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5068 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005069 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005070 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005071 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005072 TemplateSpecializationTypeLoc SpecTL
5073 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005074 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005075 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005076 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5077 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005078 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005079 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005080 }
5081 return Result;
5082}
5083
5084template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00005085QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5086 PackExpansionTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005087 QualType Pattern
5088 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005089 if (Pattern.isNull())
5090 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005091
5092 QualType Result = TL.getType();
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005093 if (getDerived().AlwaysRebuild() ||
5094 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005095 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005096 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00005097 TL.getEllipsisLoc(),
5098 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005099 if (Result.isNull())
5100 return QualType();
5101 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005102
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005103 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5104 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5105 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00005106}
5107
5108template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005109QualType
5110TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005111 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005112 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005113 TLB.pushFullCopy(TL);
5114 return TL.getType();
5115}
5116
5117template<typename Derived>
5118QualType
5119TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005120 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005121 // ObjCObjectType is never dependent.
5122 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005123 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005124}
Mike Stump1eb44332009-09-09 15:08:12 +00005125
5126template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005127QualType
5128TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005129 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005130 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005131 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005132 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005133}
5134
Douglas Gregor577f75a2009-08-04 16:50:30 +00005135//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005136// Statement transformation
5137//===----------------------------------------------------------------------===//
5138template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005139StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005140TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005141 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005142}
5143
5144template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005145StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005146TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5147 return getDerived().TransformCompoundStmt(S, false);
5148}
5149
5150template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005151StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005152TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005153 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005154 Sema::CompoundScopeRAII CompoundScope(getSema());
5155
John McCall7114cba2010-08-27 19:56:05 +00005156 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005157 bool SubStmtChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005158 SmallVector<Stmt*, 8> Statements;
Douglas Gregor43959a92009-08-20 07:17:43 +00005159 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5160 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005161 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005162 if (Result.isInvalid()) {
5163 // Immediately fail if this was a DeclStmt, since it's very
5164 // likely that this will cause problems for future statements.
5165 if (isa<DeclStmt>(*B))
5166 return StmtError();
5167
5168 // Otherwise, just keep processing substatements and fail later.
5169 SubStmtInvalid = true;
5170 continue;
5171 }
Mike Stump1eb44332009-09-09 15:08:12 +00005172
Douglas Gregor43959a92009-08-20 07:17:43 +00005173 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5174 Statements.push_back(Result.takeAs<Stmt>());
5175 }
Mike Stump1eb44332009-09-09 15:08:12 +00005176
John McCall7114cba2010-08-27 19:56:05 +00005177 if (SubStmtInvalid)
5178 return StmtError();
5179
Douglas Gregor43959a92009-08-20 07:17:43 +00005180 if (!getDerived().AlwaysRebuild() &&
5181 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005182 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005183
5184 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005185 Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00005186 S->getRBracLoc(),
5187 IsStmtExpr);
5188}
Mike Stump1eb44332009-09-09 15:08:12 +00005189
Douglas Gregor43959a92009-08-20 07:17:43 +00005190template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005191StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005192TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005193 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005194 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005195 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5196 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005197
Eli Friedman264c1f82009-11-19 03:14:00 +00005198 // Transform the left-hand case value.
5199 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005200 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005201 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005202 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005203
Eli Friedman264c1f82009-11-19 03:14:00 +00005204 // Transform the right-hand case value (for the GNU case-range extension).
5205 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005206 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005207 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005208 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005209 }
Mike Stump1eb44332009-09-09 15:08:12 +00005210
Douglas Gregor43959a92009-08-20 07:17:43 +00005211 // Build the case statement.
5212 // Case statements are always rebuilt so that they will attached to their
5213 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005214 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005215 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005216 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005217 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005218 S->getColonLoc());
5219 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005220 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005221
Douglas Gregor43959a92009-08-20 07:17:43 +00005222 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005223 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005224 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005225 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005226
Douglas Gregor43959a92009-08-20 07:17:43 +00005227 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005228 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005229}
5230
5231template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005232StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005233TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005234 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005235 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005236 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005237 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005238
Douglas Gregor43959a92009-08-20 07:17:43 +00005239 // Default statements are always rebuilt
5240 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005241 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005242}
Mike Stump1eb44332009-09-09 15:08:12 +00005243
Douglas Gregor43959a92009-08-20 07:17:43 +00005244template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005245StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005246TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005247 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005248 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005249 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005250
Chris Lattner57ad3782011-02-17 20:34:02 +00005251 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5252 S->getDecl());
5253 if (!LD)
5254 return StmtError();
Richard Smith534986f2012-04-14 00:33:13 +00005255
5256
Douglas Gregor43959a92009-08-20 07:17:43 +00005257 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005258 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005259 cast<LabelDecl>(LD), SourceLocation(),
5260 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005261}
Mike Stump1eb44332009-09-09 15:08:12 +00005262
Douglas Gregor43959a92009-08-20 07:17:43 +00005263template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005264StmtResult
Richard Smith534986f2012-04-14 00:33:13 +00005265TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5266 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5267 if (SubStmt.isInvalid())
5268 return StmtError();
5269
5270 // TODO: transform attributes
5271 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5272 return S;
5273
5274 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5275 S->getAttrs(),
5276 SubStmt.get());
5277}
5278
5279template<typename Derived>
5280StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005281TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005282 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005283 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005284 VarDecl *ConditionVar = 0;
5285 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005286 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005287 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005288 getDerived().TransformDefinition(
5289 S->getConditionVariable()->getLocation(),
5290 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005291 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005292 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005293 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005294 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005295
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005296 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005297 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005298
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005299 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005300 if (S->getCond()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005301 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005302 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005303 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005304 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005305
John McCall9ae2f072010-08-23 23:25:46 +00005306 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005307 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005308 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005309
John McCall9ae2f072010-08-23 23:25:46 +00005310 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5311 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005312 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005313
Douglas Gregor43959a92009-08-20 07:17:43 +00005314 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005315 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005316 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005317 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005318
Douglas Gregor43959a92009-08-20 07:17:43 +00005319 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005320 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005321 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005322 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005323
Douglas Gregor43959a92009-08-20 07:17:43 +00005324 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005325 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005326 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005327 Then.get() == S->getThen() &&
5328 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005329 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005330
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005331 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005332 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005333 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005334}
5335
5336template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005337StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005338TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005339 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005340 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005341 VarDecl *ConditionVar = 0;
5342 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005343 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005344 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005345 getDerived().TransformDefinition(
5346 S->getConditionVariable()->getLocation(),
5347 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005348 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005349 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005350 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005351 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005352
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005353 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005354 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005355 }
Mike Stump1eb44332009-09-09 15:08:12 +00005356
Douglas Gregor43959a92009-08-20 07:17:43 +00005357 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005358 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005359 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005360 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005361 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005362 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005363
Douglas Gregor43959a92009-08-20 07:17:43 +00005364 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005365 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005366 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005367 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005368
Douglas Gregor43959a92009-08-20 07:17:43 +00005369 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005370 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5371 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005372}
Mike Stump1eb44332009-09-09 15:08:12 +00005373
Douglas Gregor43959a92009-08-20 07:17:43 +00005374template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005375StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005376TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005377 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005378 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005379 VarDecl *ConditionVar = 0;
5380 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005381 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005382 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005383 getDerived().TransformDefinition(
5384 S->getConditionVariable()->getLocation(),
5385 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005386 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005387 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005388 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005389 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005390
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005391 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005392 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005393
5394 if (S->getCond()) {
5395 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005396 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005397 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005398 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005399 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005400 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005401 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005402 }
Mike Stump1eb44332009-09-09 15:08:12 +00005403
John McCall9ae2f072010-08-23 23:25:46 +00005404 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5405 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005406 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005407
Douglas Gregor43959a92009-08-20 07:17:43 +00005408 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005409 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005410 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005411 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005412
Douglas Gregor43959a92009-08-20 07:17:43 +00005413 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005414 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005415 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005416 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005417 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005418
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005419 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005420 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005421}
Mike Stump1eb44332009-09-09 15:08:12 +00005422
Douglas Gregor43959a92009-08-20 07:17:43 +00005423template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005424StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005425TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005426 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005427 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005428 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005429 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005430
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005431 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005432 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005433 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005434 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005435
Douglas Gregor43959a92009-08-20 07:17:43 +00005436 if (!getDerived().AlwaysRebuild() &&
5437 Cond.get() == S->getCond() &&
5438 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005439 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005440
John McCall9ae2f072010-08-23 23:25:46 +00005441 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5442 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005443 S->getRParenLoc());
5444}
Mike Stump1eb44332009-09-09 15:08:12 +00005445
Douglas Gregor43959a92009-08-20 07:17:43 +00005446template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005447StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005448TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005449 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005450 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005451 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005452 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005453
Douglas Gregor43959a92009-08-20 07:17:43 +00005454 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005455 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005456 VarDecl *ConditionVar = 0;
5457 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005458 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005459 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005460 getDerived().TransformDefinition(
5461 S->getConditionVariable()->getLocation(),
5462 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005463 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005464 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005465 } else {
5466 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005467
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005468 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005469 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005470
5471 if (S->getCond()) {
5472 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005473 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005474 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005475 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005476 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005477
John McCall9ae2f072010-08-23 23:25:46 +00005478 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005479 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005480 }
Mike Stump1eb44332009-09-09 15:08:12 +00005481
Chad Rosier4a9d7952012-08-08 18:46:20 +00005482 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCall9ae2f072010-08-23 23:25:46 +00005483 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005484 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005485
Douglas Gregor43959a92009-08-20 07:17:43 +00005486 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005487 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005488 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005489 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005490
Richard Smith41956372013-01-14 22:39:08 +00005491 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCall9ae2f072010-08-23 23:25:46 +00005492 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005493 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005494
Douglas Gregor43959a92009-08-20 07:17:43 +00005495 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005496 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005497 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005498 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005499
Douglas Gregor43959a92009-08-20 07:17:43 +00005500 if (!getDerived().AlwaysRebuild() &&
5501 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005502 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005503 Inc.get() == S->getInc() &&
5504 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005505 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005506
Douglas Gregor43959a92009-08-20 07:17:43 +00005507 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005508 Init.get(), FullCond, ConditionVar,
5509 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005510}
5511
5512template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005513StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005514TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005515 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5516 S->getLabel());
5517 if (!LD)
5518 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005519
Douglas Gregor43959a92009-08-20 07:17:43 +00005520 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005521 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005522 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005523}
5524
5525template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005526StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005527TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005528 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005529 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005530 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005531 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005532
Douglas Gregor43959a92009-08-20 07:17:43 +00005533 if (!getDerived().AlwaysRebuild() &&
5534 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005535 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005536
5537 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005538 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005539}
5540
5541template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005542StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005543TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005544 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005545}
Mike Stump1eb44332009-09-09 15:08:12 +00005546
Douglas Gregor43959a92009-08-20 07:17:43 +00005547template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005548StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005549TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005550 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005551}
Mike Stump1eb44332009-09-09 15:08:12 +00005552
Douglas Gregor43959a92009-08-20 07:17:43 +00005553template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005554StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005555TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005556 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005557 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005558 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005559
Mike Stump1eb44332009-09-09 15:08:12 +00005560 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005561 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005562 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005563}
Mike Stump1eb44332009-09-09 15:08:12 +00005564
Douglas Gregor43959a92009-08-20 07:17:43 +00005565template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005566StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005567TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005568 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005569 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005570 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5571 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005572 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5573 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005574 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005575 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005576
Douglas Gregor43959a92009-08-20 07:17:43 +00005577 if (Transformed != *D)
5578 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005579
Douglas Gregor43959a92009-08-20 07:17:43 +00005580 Decls.push_back(Transformed);
5581 }
Mike Stump1eb44332009-09-09 15:08:12 +00005582
Douglas Gregor43959a92009-08-20 07:17:43 +00005583 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005584 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005585
5586 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005587 S->getStartLoc(), S->getEndLoc());
5588}
Mike Stump1eb44332009-09-09 15:08:12 +00005589
Douglas Gregor43959a92009-08-20 07:17:43 +00005590template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005591StmtResult
Chad Rosierdf5faf52012-08-25 00:11:56 +00005592TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005593
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005594 SmallVector<Expr*, 8> Constraints;
5595 SmallVector<Expr*, 8> Exprs;
Chris Lattner686775d2011-07-20 06:58:45 +00005596 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005597
John McCall60d7b3a2010-08-24 06:29:42 +00005598 ExprResult AsmString;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005599 SmallVector<Expr*, 8> Clobbers;
Anders Carlsson703e3942010-01-24 05:50:09 +00005600
5601 bool ExprsChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005602
Anders Carlsson703e3942010-01-24 05:50:09 +00005603 // Go through the outputs.
5604 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005605 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005606
Anders Carlsson703e3942010-01-24 05:50:09 +00005607 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005608 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005609
Anders Carlsson703e3942010-01-24 05:50:09 +00005610 // Transform the output expr.
5611 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005612 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005613 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005614 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005615
Anders Carlsson703e3942010-01-24 05:50:09 +00005616 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005617
John McCall9ae2f072010-08-23 23:25:46 +00005618 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005619 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005620
Anders Carlsson703e3942010-01-24 05:50:09 +00005621 // Go through the inputs.
5622 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005623 Names.push_back(S->getInputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005624
Anders Carlsson703e3942010-01-24 05:50:09 +00005625 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005626 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005627
Anders Carlsson703e3942010-01-24 05:50:09 +00005628 // Transform the input expr.
5629 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005630 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005631 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005632 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005633
Anders Carlsson703e3942010-01-24 05:50:09 +00005634 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005635
John McCall9ae2f072010-08-23 23:25:46 +00005636 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005637 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005638
Anders Carlsson703e3942010-01-24 05:50:09 +00005639 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005640 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005641
5642 // Go through the clobbers.
5643 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosier5c7f5942012-08-27 23:28:41 +00005644 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005645
5646 // No need to transform the asm string literal.
5647 AsmString = SemaRef.Owned(S->getAsmString());
Chad Rosierdf5faf52012-08-25 00:11:56 +00005648 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5649 S->isVolatile(), S->getNumOutputs(),
5650 S->getNumInputs(), Names.data(),
5651 Constraints, Exprs, AsmString.get(),
5652 Clobbers, S->getRParenLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005653}
5654
Chad Rosier8cd64b42012-06-11 20:47:18 +00005655template<typename Derived>
5656StmtResult
5657TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier79efe242012-08-07 00:29:06 +00005658 ArrayRef<Token> AsmToks =
5659 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier62f22b82012-08-08 19:48:07 +00005660
John McCallaeeacf72013-05-03 00:10:13 +00005661 bool HadError = false, HadChange = false;
5662
5663 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5664 SmallVector<Expr*, 8> TransformedExprs;
5665 TransformedExprs.reserve(SrcExprs.size());
5666 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5667 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5668 if (!Result.isUsable()) {
5669 HadError = true;
5670 } else {
5671 HadChange |= (Result.get() != SrcExprs[i]);
5672 TransformedExprs.push_back(Result.take());
5673 }
5674 }
5675
5676 if (HadError) return StmtError();
5677 if (!HadChange && !getDerived().AlwaysRebuild())
5678 return Owned(S);
5679
Chad Rosier7bd092b2012-08-15 16:53:30 +00005680 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallaeeacf72013-05-03 00:10:13 +00005681 AsmToks, S->getAsmString(),
5682 S->getNumOutputs(), S->getNumInputs(),
5683 S->getAllConstraints(), S->getClobbers(),
5684 TransformedExprs, S->getEndLoc());
Chad Rosier8cd64b42012-06-11 20:47:18 +00005685}
Douglas Gregor43959a92009-08-20 07:17:43 +00005686
5687template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005688StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005689TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005690 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005691 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005692 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005693 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005694
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005695 // Transform the @catch statements (if present).
5696 bool AnyCatchChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005697 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005698 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005699 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005700 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005701 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005702 if (Catch.get() != S->getCatchStmt(I))
5703 AnyCatchChanged = true;
5704 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005705 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005706
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005707 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005708 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005709 if (S->getFinallyStmt()) {
5710 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5711 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005712 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005713 }
5714
5715 // If nothing changed, just retain this statement.
5716 if (!getDerived().AlwaysRebuild() &&
5717 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005718 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005719 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005720 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005721
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005722 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005723 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005724 CatchStmts, Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005725}
Mike Stump1eb44332009-09-09 15:08:12 +00005726
Douglas Gregor43959a92009-08-20 07:17:43 +00005727template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005728StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005729TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005730 // Transform the @catch parameter, if there is one.
5731 VarDecl *Var = 0;
5732 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5733 TypeSourceInfo *TSInfo = 0;
5734 if (FromVar->getTypeSourceInfo()) {
5735 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5736 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005737 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005738 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005739
Douglas Gregorbe270a02010-04-26 17:57:08 +00005740 QualType T;
5741 if (TSInfo)
5742 T = TSInfo->getType();
5743 else {
5744 T = getDerived().TransformType(FromVar->getType());
5745 if (T.isNull())
Chad Rosier4a9d7952012-08-08 18:46:20 +00005746 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005747 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005748
Douglas Gregorbe270a02010-04-26 17:57:08 +00005749 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5750 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005751 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005752 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005753
John McCall60d7b3a2010-08-24 06:29:42 +00005754 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005755 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005756 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005757
5758 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005759 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005760 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005761}
Mike Stump1eb44332009-09-09 15:08:12 +00005762
Douglas Gregor43959a92009-08-20 07:17:43 +00005763template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005764StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005765TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005766 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005767 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005768 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005769 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005770
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005771 // If nothing changed, just retain this statement.
5772 if (!getDerived().AlwaysRebuild() &&
5773 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005774 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005775
5776 // Build a new statement.
5777 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005778 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005779}
Mike Stump1eb44332009-09-09 15:08:12 +00005780
Douglas Gregor43959a92009-08-20 07:17:43 +00005781template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005782StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005783TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005784 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005785 if (S->getThrowExpr()) {
5786 Operand = getDerived().TransformExpr(S->getThrowExpr());
5787 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005788 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005789 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005790
Douglas Gregord1377b22010-04-22 21:44:01 +00005791 if (!getDerived().AlwaysRebuild() &&
5792 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005793 return getSema().Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005794
John McCall9ae2f072010-08-23 23:25:46 +00005795 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005796}
Mike Stump1eb44332009-09-09 15:08:12 +00005797
Douglas Gregor43959a92009-08-20 07:17:43 +00005798template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005799StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005800TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005801 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005802 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005803 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005804 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005805 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005806 Object =
5807 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5808 Object.get());
5809 if (Object.isInvalid())
5810 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005811
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005812 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005813 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005814 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005815 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005816
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005817 // If nothing change, just retain the current statement.
5818 if (!getDerived().AlwaysRebuild() &&
5819 Object.get() == S->getSynchExpr() &&
5820 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005821 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005822
5823 // Build a new statement.
5824 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005825 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005826}
5827
5828template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005829StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005830TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5831 ObjCAutoreleasePoolStmt *S) {
5832 // Transform the body.
5833 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5834 if (Body.isInvalid())
5835 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005836
John McCallf85e1932011-06-15 23:02:42 +00005837 // If nothing changed, just retain this statement.
5838 if (!getDerived().AlwaysRebuild() &&
5839 Body.get() == S->getSubStmt())
5840 return SemaRef.Owned(S);
5841
5842 // Build a new statement.
5843 return getDerived().RebuildObjCAutoreleasePoolStmt(
5844 S->getAtLoc(), Body.get());
5845}
5846
5847template<typename Derived>
5848StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005849TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005850 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005851 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005852 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005853 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005854 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005855
Douglas Gregorc3203e72010-04-22 23:10:45 +00005856 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005857 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005858 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005859 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005860
Douglas Gregorc3203e72010-04-22 23:10:45 +00005861 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005862 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005863 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005864 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005865
Douglas Gregorc3203e72010-04-22 23:10:45 +00005866 // If nothing changed, just retain this statement.
5867 if (!getDerived().AlwaysRebuild() &&
5868 Element.get() == S->getElement() &&
5869 Collection.get() == S->getCollection() &&
5870 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005871 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005872
Douglas Gregorc3203e72010-04-22 23:10:45 +00005873 // Build a new statement.
5874 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005875 Element.get(),
5876 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005877 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005878 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005879}
5880
5881
5882template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005883StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005884TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5885 // Transform the exception declaration, if any.
5886 VarDecl *Var = 0;
5887 if (S->getExceptionDecl()) {
5888 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005889 TypeSourceInfo *T = getDerived().TransformType(
5890 ExceptionDecl->getTypeSourceInfo());
5891 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005892 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005893
Douglas Gregor83cb9422010-09-09 17:09:21 +00005894 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005895 ExceptionDecl->getInnerLocStart(),
5896 ExceptionDecl->getLocation(),
5897 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005898 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005899 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005900 }
Mike Stump1eb44332009-09-09 15:08:12 +00005901
Douglas Gregor43959a92009-08-20 07:17:43 +00005902 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005903 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005904 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005905 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005906
Douglas Gregor43959a92009-08-20 07:17:43 +00005907 if (!getDerived().AlwaysRebuild() &&
5908 !Var &&
5909 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005910 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005911
5912 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5913 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005914 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005915}
Mike Stump1eb44332009-09-09 15:08:12 +00005916
Douglas Gregor43959a92009-08-20 07:17:43 +00005917template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005918StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005919TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5920 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005921 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005922 = getDerived().TransformCompoundStmt(S->getTryBlock());
5923 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005924 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005925
Douglas Gregor43959a92009-08-20 07:17:43 +00005926 // Transform the handlers.
5927 bool HandlerChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005928 SmallVector<Stmt*, 8> Handlers;
Douglas Gregor43959a92009-08-20 07:17:43 +00005929 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005930 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005931 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5932 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005933 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005934
Douglas Gregor43959a92009-08-20 07:17:43 +00005935 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5936 Handlers.push_back(Handler.takeAs<Stmt>());
5937 }
Mike Stump1eb44332009-09-09 15:08:12 +00005938
Douglas Gregor43959a92009-08-20 07:17:43 +00005939 if (!getDerived().AlwaysRebuild() &&
5940 TryBlock.get() == S->getTryBlock() &&
5941 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005942 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005943
John McCall9ae2f072010-08-23 23:25:46 +00005944 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005945 Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00005946}
Mike Stump1eb44332009-09-09 15:08:12 +00005947
Richard Smithad762fc2011-04-14 22:09:26 +00005948template<typename Derived>
5949StmtResult
5950TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5951 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5952 if (Range.isInvalid())
5953 return StmtError();
5954
5955 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5956 if (BeginEnd.isInvalid())
5957 return StmtError();
5958
5959 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5960 if (Cond.isInvalid())
5961 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005962 if (Cond.get())
5963 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
5964 if (Cond.isInvalid())
5965 return StmtError();
5966 if (Cond.get())
5967 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005968
5969 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5970 if (Inc.isInvalid())
5971 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005972 if (Inc.get())
5973 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005974
5975 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5976 if (LoopVar.isInvalid())
5977 return StmtError();
5978
5979 StmtResult NewStmt = S;
5980 if (getDerived().AlwaysRebuild() ||
5981 Range.get() != S->getRangeStmt() ||
5982 BeginEnd.get() != S->getBeginEndStmt() ||
5983 Cond.get() != S->getCond() ||
5984 Inc.get() != S->getInc() ||
Douglas Gregor39b60dc2013-05-02 18:35:56 +00005985 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smithad762fc2011-04-14 22:09:26 +00005986 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5987 S->getColonLoc(), Range.get(),
5988 BeginEnd.get(), Cond.get(),
5989 Inc.get(), LoopVar.get(),
5990 S->getRParenLoc());
Douglas Gregor39b60dc2013-05-02 18:35:56 +00005991 if (NewStmt.isInvalid())
5992 return StmtError();
5993 }
Richard Smithad762fc2011-04-14 22:09:26 +00005994
5995 StmtResult Body = getDerived().TransformStmt(S->getBody());
5996 if (Body.isInvalid())
5997 return StmtError();
5998
5999 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6000 // it now so we have a new statement to attach the body to.
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006001 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smithad762fc2011-04-14 22:09:26 +00006002 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6003 S->getColonLoc(), Range.get(),
6004 BeginEnd.get(), Cond.get(),
6005 Inc.get(), LoopVar.get(),
6006 S->getRParenLoc());
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006007 if (NewStmt.isInvalid())
6008 return StmtError();
6009 }
Richard Smithad762fc2011-04-14 22:09:26 +00006010
6011 if (NewStmt.get() == S)
6012 return SemaRef.Owned(S);
6013
6014 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6015}
6016
John Wiegley28bbe4b2011-04-28 01:08:34 +00006017template<typename Derived>
6018StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00006019TreeTransform<Derived>::TransformMSDependentExistsStmt(
6020 MSDependentExistsStmt *S) {
6021 // Transform the nested-name-specifier, if any.
6022 NestedNameSpecifierLoc QualifierLoc;
6023 if (S->getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006024 QualifierLoc
Douglas Gregorba0513d2011-10-25 01:33:02 +00006025 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6026 if (!QualifierLoc)
6027 return StmtError();
6028 }
6029
6030 // Transform the declaration name.
6031 DeclarationNameInfo NameInfo = S->getNameInfo();
6032 if (NameInfo.getName()) {
6033 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6034 if (!NameInfo.getName())
6035 return StmtError();
6036 }
6037
6038 // Check whether anything changed.
6039 if (!getDerived().AlwaysRebuild() &&
6040 QualifierLoc == S->getQualifierLoc() &&
6041 NameInfo.getName() == S->getNameInfo().getName())
6042 return S;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006043
Douglas Gregorba0513d2011-10-25 01:33:02 +00006044 // Determine whether this name exists, if we can.
6045 CXXScopeSpec SS;
6046 SS.Adopt(QualifierLoc);
6047 bool Dependent = false;
6048 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
6049 case Sema::IER_Exists:
6050 if (S->isIfExists())
6051 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006052
Douglas Gregorba0513d2011-10-25 01:33:02 +00006053 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6054
6055 case Sema::IER_DoesNotExist:
6056 if (S->isIfNotExists())
6057 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006058
Douglas Gregorba0513d2011-10-25 01:33:02 +00006059 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006060
Douglas Gregorba0513d2011-10-25 01:33:02 +00006061 case Sema::IER_Dependent:
6062 Dependent = true;
6063 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006064
Douglas Gregor65019ac2011-10-25 03:44:56 +00006065 case Sema::IER_Error:
6066 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00006067 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006068
Douglas Gregorba0513d2011-10-25 01:33:02 +00006069 // We need to continue with the instantiation, so do so now.
6070 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6071 if (SubStmt.isInvalid())
6072 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006073
Douglas Gregorba0513d2011-10-25 01:33:02 +00006074 // If we have resolved the name, just transform to the substatement.
6075 if (!Dependent)
6076 return SubStmt;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006077
Douglas Gregorba0513d2011-10-25 01:33:02 +00006078 // The name is still dependent, so build a dependent expression again.
6079 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6080 S->isIfExists(),
6081 QualifierLoc,
6082 NameInfo,
6083 SubStmt.get());
6084}
6085
6086template<typename Derived>
John McCall76da55d2013-04-16 07:28:30 +00006087ExprResult
6088TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6089 NestedNameSpecifierLoc QualifierLoc;
6090 if (E->getQualifierLoc()) {
6091 QualifierLoc
6092 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6093 if (!QualifierLoc)
6094 return ExprError();
6095 }
6096
6097 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6098 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6099 if (!PD)
6100 return ExprError();
6101
6102 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6103 if (Base.isInvalid())
6104 return ExprError();
6105
6106 return new (SemaRef.getASTContext())
6107 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6108 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6109 QualifierLoc, E->getMemberLoc());
6110}
6111
6112template<typename Derived>
Douglas Gregorba0513d2011-10-25 01:33:02 +00006113StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00006114TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
6115 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
6116 if(TryBlock.isInvalid()) return StmtError();
6117
6118 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
6119 if(!getDerived().AlwaysRebuild() &&
6120 TryBlock.get() == S->getTryBlock() &&
6121 Handler.get() == S->getHandler())
6122 return SemaRef.Owned(S);
6123
6124 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
6125 S->getTryLoc(),
6126 TryBlock.take(),
6127 Handler.take());
6128}
6129
6130template<typename Derived>
6131StmtResult
6132TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
6133 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6134 if(Block.isInvalid()) return StmtError();
6135
6136 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
6137 Block.take());
6138}
6139
6140template<typename Derived>
6141StmtResult
6142TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
6143 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
6144 if(FilterExpr.isInvalid()) return StmtError();
6145
6146 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6147 if(Block.isInvalid()) return StmtError();
6148
6149 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
6150 FilterExpr.take(),
6151 Block.take());
6152}
6153
6154template<typename Derived>
6155StmtResult
6156TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6157 if(isa<SEHFinallyStmt>(Handler))
6158 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6159 else
6160 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6161}
6162
Douglas Gregor43959a92009-08-20 07:17:43 +00006163//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00006164// Expression transformation
6165//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006166template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006167ExprResult
John McCall454feb92009-12-08 09:21:05 +00006168TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006169 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006170}
Mike Stump1eb44332009-09-09 15:08:12 +00006171
6172template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006173ExprResult
John McCall454feb92009-12-08 09:21:05 +00006174TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006175 NestedNameSpecifierLoc QualifierLoc;
6176 if (E->getQualifierLoc()) {
6177 QualifierLoc
6178 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6179 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006180 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006181 }
John McCalldbd872f2009-12-08 09:08:17 +00006182
6183 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006184 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6185 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006186 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006187 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006188
John McCallec8045d2010-08-17 21:27:17 +00006189 DeclarationNameInfo NameInfo = E->getNameInfo();
6190 if (NameInfo.getName()) {
6191 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6192 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006193 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006194 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006195
6196 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006197 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006198 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006199 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006200 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006201
6202 // Mark it referenced in the new context regardless.
6203 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006204 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006205
John McCall3fa5cae2010-10-26 07:05:15 +00006206 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006207 }
John McCalldbd872f2009-12-08 09:08:17 +00006208
6209 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006210 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006211 TemplateArgs = &TransArgs;
6212 TransArgs.setLAngleLoc(E->getLAngleLoc());
6213 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006214 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6215 E->getNumTemplateArgs(),
6216 TransArgs))
6217 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006218 }
6219
Chad Rosier4a9d7952012-08-08 18:46:20 +00006220 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregor40d96a62011-02-28 21:54:11 +00006221 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006222}
Mike Stump1eb44332009-09-09 15:08:12 +00006223
Douglas Gregorb98b1992009-08-11 05:31:07 +00006224template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006225ExprResult
John McCall454feb92009-12-08 09:21:05 +00006226TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006227 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006228}
Mike Stump1eb44332009-09-09 15:08:12 +00006229
Douglas Gregorb98b1992009-08-11 05:31:07 +00006230template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006231ExprResult
John McCall454feb92009-12-08 09:21:05 +00006232TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006233 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006234}
Mike Stump1eb44332009-09-09 15:08:12 +00006235
Douglas Gregorb98b1992009-08-11 05:31:07 +00006236template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006237ExprResult
John McCall454feb92009-12-08 09:21:05 +00006238TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006239 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006240}
Mike Stump1eb44332009-09-09 15:08:12 +00006241
Douglas Gregorb98b1992009-08-11 05:31:07 +00006242template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006243ExprResult
John McCall454feb92009-12-08 09:21:05 +00006244TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006245 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006246}
Mike Stump1eb44332009-09-09 15:08:12 +00006247
Douglas Gregorb98b1992009-08-11 05:31:07 +00006248template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006249ExprResult
John McCall454feb92009-12-08 09:21:05 +00006250TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006251 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006252}
6253
6254template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006255ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006256TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis391ca9f2013-04-09 01:17:02 +00006257 if (FunctionDecl *FD = E->getDirectCallee())
6258 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smith9fcce652012-03-07 08:35:16 +00006259 return SemaRef.MaybeBindToTemporary(E);
6260}
6261
6262template<typename Derived>
6263ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006264TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6265 ExprResult ControllingExpr =
6266 getDerived().TransformExpr(E->getControllingExpr());
6267 if (ControllingExpr.isInvalid())
6268 return ExprError();
6269
Chris Lattner686775d2011-07-20 06:58:45 +00006270 SmallVector<Expr *, 4> AssocExprs;
6271 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006272 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6273 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6274 if (TS) {
6275 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6276 if (!AssocType)
6277 return ExprError();
6278 AssocTypes.push_back(AssocType);
6279 } else {
6280 AssocTypes.push_back(0);
6281 }
6282
6283 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6284 if (AssocExpr.isInvalid())
6285 return ExprError();
6286 AssocExprs.push_back(AssocExpr.release());
6287 }
6288
6289 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6290 E->getDefaultLoc(),
6291 E->getRParenLoc(),
6292 ControllingExpr.release(),
Dmitri Gribenko80613222013-05-10 13:06:58 +00006293 AssocTypes,
6294 AssocExprs);
Peter Collingbournef111d932011-04-15 00:35:48 +00006295}
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 Smith82b00012013-05-21 23:29:46 +00006326 ExprResult SubExpr;
6327 if (E->getOpcode() == UO_AddrOf)
6328 SubExpr = TransformAddressOfOperand(E->getSubExpr());
6329 else
6330 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006331 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006332 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006333
Douglas Gregorb98b1992009-08-11 05:31:07 +00006334 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006335 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006336
Douglas Gregorb98b1992009-08-11 05:31:07 +00006337 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6338 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006339 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006340}
Mike Stump1eb44332009-09-09 15:08:12 +00006341
Douglas Gregorb98b1992009-08-11 05:31:07 +00006342template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006343ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006344TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6345 // Transform the type.
6346 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6347 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006348 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006349
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006350 // Transform all of the components into components similar to what the
6351 // parser uses.
Chad Rosier4a9d7952012-08-08 18:46:20 +00006352 // FIXME: It would be slightly more efficient in the non-dependent case to
6353 // just map FieldDecls, rather than requiring the rebuilder to look for
6354 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006355 // template code that we don't care.
6356 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006357 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006358 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006359 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006360 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6361 const Node &ON = E->getComponent(I);
6362 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006363 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006364 Comp.LocStart = ON.getSourceRange().getBegin();
6365 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006366 switch (ON.getKind()) {
6367 case Node::Array: {
6368 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006369 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006370 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006371 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006372
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006373 ExprChanged = ExprChanged || Index.get() != FromIndex;
6374 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006375 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006376 break;
6377 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006378
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006379 case Node::Field:
6380 case Node::Identifier:
6381 Comp.isBrackets = false;
6382 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006383 if (!Comp.U.IdentInfo)
6384 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006385
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006386 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006387
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006388 case Node::Base:
6389 // Will be recomputed during the rebuild.
6390 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006391 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006392
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006393 Components.push_back(Comp);
6394 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006395
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006396 // If nothing changed, retain the existing expression.
6397 if (!getDerived().AlwaysRebuild() &&
6398 Type == E->getTypeSourceInfo() &&
6399 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006400 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006401
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006402 // Build a new offsetof expression.
6403 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6404 Components.data(), Components.size(),
6405 E->getRParenLoc());
6406}
6407
6408template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006409ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006410TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6411 assert(getDerived().AlreadyTransformed(E->getType()) &&
6412 "opaque value expression requires transformation");
6413 return SemaRef.Owned(E);
6414}
6415
6416template<typename Derived>
6417ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006418TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006419 // Rebuild the syntactic form. The original syntactic form has
6420 // opaque-value expressions in it, so strip those away and rebuild
6421 // the result. This is a really awful way of doing this, but the
6422 // better solution (rebuilding the semantic expressions and
6423 // rebinding OVEs as necessary) doesn't work; we'd need
6424 // TreeTransform to not strip away implicit conversions.
6425 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6426 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006427 if (result.isInvalid()) return ExprError();
6428
6429 // If that gives us a pseudo-object result back, the pseudo-object
6430 // expression must have been an lvalue-to-rvalue conversion which we
6431 // should reapply.
6432 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6433 result = SemaRef.checkPseudoObjectRValue(result.take());
6434
6435 return result;
6436}
6437
6438template<typename Derived>
6439ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006440TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6441 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006442 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006443 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006444
John McCalla93c9342009-12-07 02:54:59 +00006445 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006446 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006447 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006448
John McCall5ab75172009-11-04 07:28:41 +00006449 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006450 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006451
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006452 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6453 E->getKind(),
6454 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006455 }
Mike Stump1eb44332009-09-09 15:08:12 +00006456
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006457 // C++0x [expr.sizeof]p1:
6458 // The operand is either an expression, which is an unevaluated operand
6459 // [...]
Eli Friedman80bfa3d2012-09-26 04:34:21 +00006460 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6461 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00006462
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006463 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6464 if (SubExpr.isInvalid())
6465 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006466
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006467 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6468 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006469
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006470 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6471 E->getOperatorLoc(),
6472 E->getKind(),
6473 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006474}
Mike Stump1eb44332009-09-09 15:08:12 +00006475
Douglas Gregorb98b1992009-08-11 05:31:07 +00006476template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006477ExprResult
John McCall454feb92009-12-08 09:21:05 +00006478TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006479 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006480 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006481 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006482
John McCall60d7b3a2010-08-24 06:29:42 +00006483 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006484 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006485 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006486
6487
Douglas Gregorb98b1992009-08-11 05:31:07 +00006488 if (!getDerived().AlwaysRebuild() &&
6489 LHS.get() == E->getLHS() &&
6490 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006491 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006492
John McCall9ae2f072010-08-23 23:25:46 +00006493 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006494 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006495 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006496 E->getRBracketLoc());
6497}
Mike Stump1eb44332009-09-09 15:08:12 +00006498
6499template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006500ExprResult
John McCall454feb92009-12-08 09:21:05 +00006501TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006502 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006503 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006504 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006505 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006506
6507 // Transform arguments.
6508 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006509 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006510 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006511 &ArgChanged))
6512 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006513
Douglas Gregorb98b1992009-08-11 05:31:07 +00006514 if (!getDerived().AlwaysRebuild() &&
6515 Callee.get() == E->getCallee() &&
6516 !ArgChanged)
Dmitri Gribenko1ad23d62012-09-10 21:20:09 +00006517 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006518
Douglas Gregorb98b1992009-08-11 05:31:07 +00006519 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006520 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006521 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006522 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006523 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006524 E->getRParenLoc());
6525}
Mike Stump1eb44332009-09-09 15:08:12 +00006526
6527template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006528ExprResult
John McCall454feb92009-12-08 09:21:05 +00006529TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006530 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006531 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006532 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006533
Douglas Gregor40d96a62011-02-28 21:54:11 +00006534 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006535 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006536 QualifierLoc
6537 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006538
Douglas Gregor40d96a62011-02-28 21:54:11 +00006539 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006540 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006541 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006542 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006543
Eli Friedmanf595cc42009-12-04 06:40:45 +00006544 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006545 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6546 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006547 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006548 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006549
John McCall6bb80172010-03-30 21:47:33 +00006550 NamedDecl *FoundDecl = E->getFoundDecl();
6551 if (FoundDecl == E->getMemberDecl()) {
6552 FoundDecl = Member;
6553 } else {
6554 FoundDecl = cast_or_null<NamedDecl>(
6555 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6556 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006557 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006558 }
6559
Douglas Gregorb98b1992009-08-11 05:31:07 +00006560 if (!getDerived().AlwaysRebuild() &&
6561 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006562 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006563 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006564 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006565 !E->hasExplicitTemplateArgs()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006566
Anders Carlsson1f240322009-12-22 05:24:09 +00006567 // Mark it referenced in the new context regardless.
6568 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006569 SemaRef.MarkMemberReferenced(E);
6570
John McCall3fa5cae2010-10-26 07:05:15 +00006571 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006572 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006573
John McCalld5532b62009-11-23 01:53:49 +00006574 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006575 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006576 TransArgs.setLAngleLoc(E->getLAngleLoc());
6577 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006578 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6579 E->getNumTemplateArgs(),
6580 TransArgs))
6581 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006582 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006583
Douglas Gregorb98b1992009-08-11 05:31:07 +00006584 // FIXME: Bogus source location for the operator
6585 SourceLocation FakeOperatorLoc
6586 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6587
John McCallc2233c52010-01-15 08:34:02 +00006588 // FIXME: to do this check properly, we will need to preserve the
6589 // first-qualifier-in-scope here, just in case we had a dependent
6590 // base (and therefore couldn't do the check) and a
6591 // nested-name-qualifier (and therefore could do the lookup).
6592 NamedDecl *FirstQualifierInScope = 0;
6593
John McCall9ae2f072010-08-23 23:25:46 +00006594 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006595 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006596 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006597 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006598 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006599 Member,
John McCall6bb80172010-03-30 21:47:33 +00006600 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006601 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006602 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006603 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006604}
Mike Stump1eb44332009-09-09 15:08:12 +00006605
Douglas Gregorb98b1992009-08-11 05:31:07 +00006606template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006607ExprResult
John McCall454feb92009-12-08 09:21:05 +00006608TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006609 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006610 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006611 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006612
John McCall60d7b3a2010-08-24 06:29:42 +00006613 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006614 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006615 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006616
Douglas Gregorb98b1992009-08-11 05:31:07 +00006617 if (!getDerived().AlwaysRebuild() &&
6618 LHS.get() == E->getLHS() &&
6619 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006620 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006621
Lang Hamesbe9af122012-10-02 04:45:10 +00006622 Sema::FPContractStateRAII FPContractState(getSema());
6623 getSema().FPFeatures.fp_contract = E->isFPContractable();
6624
Douglas Gregorb98b1992009-08-11 05:31:07 +00006625 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006626 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006627}
6628
Mike Stump1eb44332009-09-09 15:08:12 +00006629template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006630ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006631TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006632 CompoundAssignOperator *E) {
6633 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006634}
Mike Stump1eb44332009-09-09 15:08:12 +00006635
Douglas Gregorb98b1992009-08-11 05:31:07 +00006636template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006637ExprResult TreeTransform<Derived>::
6638TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6639 // Just rebuild the common and RHS expressions and see whether we
6640 // get any changes.
6641
6642 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6643 if (commonExpr.isInvalid())
6644 return ExprError();
6645
6646 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6647 if (rhs.isInvalid())
6648 return ExprError();
6649
6650 if (!getDerived().AlwaysRebuild() &&
6651 commonExpr.get() == e->getCommon() &&
6652 rhs.get() == e->getFalseExpr())
6653 return SemaRef.Owned(e);
6654
6655 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6656 e->getQuestionLoc(),
6657 0,
6658 e->getColonLoc(),
6659 rhs.get());
6660}
6661
6662template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006663ExprResult
John McCall454feb92009-12-08 09:21:05 +00006664TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006665 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006666 if (Cond.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 LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006670 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006671 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006672
John McCall60d7b3a2010-08-24 06:29:42 +00006673 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006674 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006675 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006676
Douglas Gregorb98b1992009-08-11 05:31:07 +00006677 if (!getDerived().AlwaysRebuild() &&
6678 Cond.get() == E->getCond() &&
6679 LHS.get() == E->getLHS() &&
6680 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006681 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006682
John McCall9ae2f072010-08-23 23:25:46 +00006683 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006684 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006685 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006686 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006687 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006688}
Mike Stump1eb44332009-09-09 15:08:12 +00006689
6690template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006691ExprResult
John McCall454feb92009-12-08 09:21:05 +00006692TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006693 // Implicit casts are eliminated during transformation, since they
6694 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006695 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006696}
Mike Stump1eb44332009-09-09 15:08:12 +00006697
Douglas Gregorb98b1992009-08-11 05:31:07 +00006698template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006699ExprResult
John McCall454feb92009-12-08 09:21:05 +00006700TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006701 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6702 if (!Type)
6703 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006704
John McCall60d7b3a2010-08-24 06:29:42 +00006705 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006706 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006707 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006708 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006709
Douglas Gregorb98b1992009-08-11 05:31:07 +00006710 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006711 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006712 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006713 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006714
John McCall9d125032010-01-15 18:39:57 +00006715 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006716 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006717 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006718 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006719}
Mike Stump1eb44332009-09-09 15:08:12 +00006720
Douglas Gregorb98b1992009-08-11 05:31:07 +00006721template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006722ExprResult
John McCall454feb92009-12-08 09:21:05 +00006723TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006724 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6725 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6726 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006727 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006728
John McCall60d7b3a2010-08-24 06:29:42 +00006729 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006730 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006731 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006732
Douglas Gregorb98b1992009-08-11 05:31:07 +00006733 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006734 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006735 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006736 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006737
John McCall1d7d8d62010-01-19 22:33:45 +00006738 // Note: the expression type doesn't necessarily match the
6739 // type-as-written, but that's okay, because it should always be
6740 // derivable from the initializer.
6741
John McCall42f56b52010-01-18 19:35:47 +00006742 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006743 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006744 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006745}
Mike Stump1eb44332009-09-09 15:08:12 +00006746
Douglas Gregorb98b1992009-08-11 05:31:07 +00006747template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006748ExprResult
John McCall454feb92009-12-08 09:21:05 +00006749TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006750 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006751 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006752 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006753
Douglas Gregorb98b1992009-08-11 05:31:07 +00006754 if (!getDerived().AlwaysRebuild() &&
6755 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006756 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006757
Douglas Gregorb98b1992009-08-11 05:31:07 +00006758 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006759 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006760 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006761 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006762 E->getAccessorLoc(),
6763 E->getAccessor());
6764}
Mike Stump1eb44332009-09-09 15:08:12 +00006765
Douglas Gregorb98b1992009-08-11 05:31:07 +00006766template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006767ExprResult
John McCall454feb92009-12-08 09:21:05 +00006768TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006769 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006770
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006771 SmallVector<Expr*, 4> Inits;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006772 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006773 Inits, &InitChanged))
6774 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006775
Douglas Gregorb98b1992009-08-11 05:31:07 +00006776 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006777 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006778
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006779 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00006780 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006781}
Mike Stump1eb44332009-09-09 15:08:12 +00006782
Douglas Gregorb98b1992009-08-11 05:31:07 +00006783template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006784ExprResult
John McCall454feb92009-12-08 09:21:05 +00006785TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006786 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006787
Douglas Gregor43959a92009-08-20 07:17:43 +00006788 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006789 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006790 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006791 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006792
Douglas Gregor43959a92009-08-20 07:17:43 +00006793 // transform the designators.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006794 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006795 bool ExprChanged = false;
6796 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6797 DEnd = E->designators_end();
6798 D != DEnd; ++D) {
6799 if (D->isFieldDesignator()) {
6800 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6801 D->getDotLoc(),
6802 D->getFieldLoc()));
6803 continue;
6804 }
Mike Stump1eb44332009-09-09 15:08:12 +00006805
Douglas Gregorb98b1992009-08-11 05:31:07 +00006806 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006807 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006808 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006809 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006810
6811 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006812 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006813
Douglas Gregorb98b1992009-08-11 05:31:07 +00006814 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6815 ArrayExprs.push_back(Index.release());
6816 continue;
6817 }
Mike Stump1eb44332009-09-09 15:08:12 +00006818
Douglas Gregorb98b1992009-08-11 05:31:07 +00006819 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006820 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006821 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6822 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006823 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006824
John McCall60d7b3a2010-08-24 06:29:42 +00006825 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006826 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006827 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006828
6829 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006830 End.get(),
6831 D->getLBracketLoc(),
6832 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006833
Douglas Gregorb98b1992009-08-11 05:31:07 +00006834 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6835 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006836
Douglas Gregorb98b1992009-08-11 05:31:07 +00006837 ArrayExprs.push_back(Start.release());
6838 ArrayExprs.push_back(End.release());
6839 }
Mike Stump1eb44332009-09-09 15:08:12 +00006840
Douglas Gregorb98b1992009-08-11 05:31:07 +00006841 if (!getDerived().AlwaysRebuild() &&
6842 Init.get() == E->getInit() &&
6843 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006844 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006845
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006846 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006847 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006848 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006849}
Mike Stump1eb44332009-09-09 15:08:12 +00006850
Douglas Gregorb98b1992009-08-11 05:31:07 +00006851template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006852ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006853TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006854 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006855 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006856
Douglas Gregor5557b252009-10-28 00:29:27 +00006857 // FIXME: Will we ever have proper type location here? Will we actually
6858 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006859 QualType T = getDerived().TransformType(E->getType());
6860 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006861 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006862
Douglas Gregorb98b1992009-08-11 05:31:07 +00006863 if (!getDerived().AlwaysRebuild() &&
6864 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006865 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006866
Douglas Gregorb98b1992009-08-11 05:31:07 +00006867 return getDerived().RebuildImplicitValueInitExpr(T);
6868}
Mike Stump1eb44332009-09-09 15:08:12 +00006869
Douglas Gregorb98b1992009-08-11 05:31:07 +00006870template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006871ExprResult
John McCall454feb92009-12-08 09:21:05 +00006872TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006873 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6874 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006875 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006876
John McCall60d7b3a2010-08-24 06:29:42 +00006877 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006878 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006879 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006880
Douglas Gregorb98b1992009-08-11 05:31:07 +00006881 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006882 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006883 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006884 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006885
John McCall9ae2f072010-08-23 23:25:46 +00006886 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006887 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006888}
6889
6890template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006891ExprResult
John McCall454feb92009-12-08 09:21:05 +00006892TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006893 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006894 SmallVector<Expr*, 4> Inits;
Douglas Gregoraa165f82011-01-03 19:04:46 +00006895 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6896 &ArgumentChanged))
6897 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006898
Douglas Gregorb98b1992009-08-11 05:31:07 +00006899 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006900 Inits,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006901 E->getRParenLoc());
6902}
Mike Stump1eb44332009-09-09 15:08:12 +00006903
Douglas Gregorb98b1992009-08-11 05:31:07 +00006904/// \brief Transform an address-of-label expression.
6905///
6906/// By default, the transformation of an address-of-label expression always
6907/// rebuilds the expression, so that the label identifier can be resolved to
6908/// the corresponding label statement by semantic analysis.
6909template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006910ExprResult
John McCall454feb92009-12-08 09:21:05 +00006911TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006912 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6913 E->getLabel());
6914 if (!LD)
6915 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006916
Douglas Gregorb98b1992009-08-11 05:31:07 +00006917 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006918 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006919}
Mike Stump1eb44332009-09-09 15:08:12 +00006920
6921template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00006922ExprResult
John McCall454feb92009-12-08 09:21:05 +00006923TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00006924 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00006925 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006926 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00006927 if (SubStmt.isInvalid()) {
6928 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00006929 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00006930 }
Mike Stump1eb44332009-09-09 15:08:12 +00006931
Douglas Gregorb98b1992009-08-11 05:31:07 +00006932 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00006933 SubStmt.get() == E->getSubStmt()) {
6934 // Calling this an 'error' is unintuitive, but it does the right thing.
6935 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00006936 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00006937 }
Mike Stump1eb44332009-09-09 15:08:12 +00006938
6939 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006940 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006941 E->getRParenLoc());
6942}
Mike Stump1eb44332009-09-09 15:08:12 +00006943
Douglas Gregorb98b1992009-08-11 05:31:07 +00006944template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006945ExprResult
John McCall454feb92009-12-08 09:21:05 +00006946TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006947 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006948 if (Cond.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 LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006952 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006953 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006954
John McCall60d7b3a2010-08-24 06:29:42 +00006955 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006956 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006957 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006958
Douglas Gregorb98b1992009-08-11 05:31:07 +00006959 if (!getDerived().AlwaysRebuild() &&
6960 Cond.get() == E->getCond() &&
6961 LHS.get() == E->getLHS() &&
6962 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006963 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006964
Douglas Gregorb98b1992009-08-11 05:31:07 +00006965 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006966 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006967 E->getRParenLoc());
6968}
Mike Stump1eb44332009-09-09 15:08:12 +00006969
Douglas Gregorb98b1992009-08-11 05:31:07 +00006970template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006971ExprResult
John McCall454feb92009-12-08 09:21:05 +00006972TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006973 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006974}
6975
6976template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006977ExprResult
John McCall454feb92009-12-08 09:21:05 +00006978TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006979 switch (E->getOperator()) {
6980 case OO_New:
6981 case OO_Delete:
6982 case OO_Array_New:
6983 case OO_Array_Delete:
6984 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier4a9d7952012-08-08 18:46:20 +00006985
Douglas Gregor668d6d92009-12-13 20:44:55 +00006986 case OO_Call: {
6987 // This is a call to an object's operator().
6988 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6989
6990 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006991 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006992 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006993 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006994
6995 // FIXME: Poor location information
6996 SourceLocation FakeLParenLoc
6997 = SemaRef.PP.getLocForEndOfToken(
6998 static_cast<Expr *>(Object.get())->getLocEnd());
6999
7000 // Transform the call arguments.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007001 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007002 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007003 Args))
7004 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00007005
John McCall9ae2f072010-08-23 23:25:46 +00007006 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007007 Args,
Douglas Gregor668d6d92009-12-13 20:44:55 +00007008 E->getLocEnd());
7009 }
7010
7011#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7012 case OO_##Name:
7013#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7014#include "clang/Basic/OperatorKinds.def"
7015 case OO_Subscript:
7016 // Handled below.
7017 break;
7018
7019 case OO_Conditional:
7020 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00007021
7022 case OO_None:
7023 case NUM_OVERLOADED_OPERATORS:
7024 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00007025 }
7026
John McCall60d7b3a2010-08-24 06:29:42 +00007027 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007028 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007029 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007030
Richard Smithefeeccf2012-10-21 03:28:35 +00007031 ExprResult First;
7032 if (E->getOperator() == OO_Amp)
7033 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7034 else
7035 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007036 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007037 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007038
John McCall60d7b3a2010-08-24 06:29:42 +00007039 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00007040 if (E->getNumArgs() == 2) {
7041 Second = getDerived().TransformExpr(E->getArg(1));
7042 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007043 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007044 }
Mike Stump1eb44332009-09-09 15:08:12 +00007045
Douglas Gregorb98b1992009-08-11 05:31:07 +00007046 if (!getDerived().AlwaysRebuild() &&
7047 Callee.get() == E->getCallee() &&
7048 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00007049 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00007050 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007051
Lang Hamesbe9af122012-10-02 04:45:10 +00007052 Sema::FPContractStateRAII FPContractState(getSema());
7053 getSema().FPFeatures.fp_contract = E->isFPContractable();
7054
Douglas Gregorb98b1992009-08-11 05:31:07 +00007055 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7056 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007057 Callee.get(),
7058 First.get(),
7059 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007060}
Mike Stump1eb44332009-09-09 15:08:12 +00007061
Douglas Gregorb98b1992009-08-11 05:31:07 +00007062template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007063ExprResult
John McCall454feb92009-12-08 09:21:05 +00007064TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7065 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007066}
Mike Stump1eb44332009-09-09 15:08:12 +00007067
Douglas Gregorb98b1992009-08-11 05:31:07 +00007068template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007069ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00007070TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7071 // Transform the callee.
7072 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7073 if (Callee.isInvalid())
7074 return ExprError();
7075
7076 // Transform exec config.
7077 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7078 if (EC.isInvalid())
7079 return ExprError();
7080
7081 // Transform arguments.
7082 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007083 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007084 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007085 &ArgChanged))
7086 return ExprError();
7087
7088 if (!getDerived().AlwaysRebuild() &&
7089 Callee.get() == E->getCallee() &&
7090 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00007091 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00007092
7093 // FIXME: Wrong source location information for the '('.
7094 SourceLocation FakeLParenLoc
7095 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7096 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007097 Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007098 E->getRParenLoc(), EC.get());
7099}
7100
7101template<typename Derived>
7102ExprResult
John McCall454feb92009-12-08 09:21:05 +00007103TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007104 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7105 if (!Type)
7106 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007107
John McCall60d7b3a2010-08-24 06:29:42 +00007108 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007109 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007110 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007111 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007112
Douglas Gregorb98b1992009-08-11 05:31:07 +00007113 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007114 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007115 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007116 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007117 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00007118 E->getStmtClass(),
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007119 E->getAngleBrackets().getBegin(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007120 Type,
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007121 E->getAngleBrackets().getEnd(),
7122 // FIXME. this should be '(' location
7123 E->getAngleBrackets().getEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00007124 SubExpr.get(),
Abramo Bagnara6cf7d7d2012-10-15 21:08:58 +00007125 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007126}
Mike Stump1eb44332009-09-09 15:08:12 +00007127
Douglas Gregorb98b1992009-08-11 05:31:07 +00007128template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007129ExprResult
John McCall454feb92009-12-08 09:21:05 +00007130TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7131 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007132}
Mike Stump1eb44332009-09-09 15:08:12 +00007133
7134template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007135ExprResult
John McCall454feb92009-12-08 09:21:05 +00007136TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7137 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007138}
7139
Douglas Gregorb98b1992009-08-11 05:31:07 +00007140template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007141ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007142TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007143 CXXReinterpretCastExpr *E) {
7144 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007145}
Mike Stump1eb44332009-09-09 15:08:12 +00007146
Douglas Gregorb98b1992009-08-11 05:31:07 +00007147template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007148ExprResult
John McCall454feb92009-12-08 09:21:05 +00007149TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7150 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007151}
Mike Stump1eb44332009-09-09 15:08:12 +00007152
Douglas Gregorb98b1992009-08-11 05:31:07 +00007153template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007154ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007155TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007156 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007157 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7158 if (!Type)
7159 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007160
John McCall60d7b3a2010-08-24 06:29:42 +00007161 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007162 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007163 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007164 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007165
Douglas Gregorb98b1992009-08-11 05:31:07 +00007166 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007167 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007168 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007169 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007170
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007171 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007172 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007173 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007174 E->getRParenLoc());
7175}
Mike Stump1eb44332009-09-09 15:08:12 +00007176
Douglas Gregorb98b1992009-08-11 05:31:07 +00007177template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007178ExprResult
John McCall454feb92009-12-08 09:21:05 +00007179TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007180 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007181 TypeSourceInfo *TInfo
7182 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7183 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007184 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007185
Douglas Gregorb98b1992009-08-11 05:31:07 +00007186 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007187 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007188 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007189
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007190 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7191 E->getLocStart(),
7192 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007193 E->getLocEnd());
7194 }
Mike Stump1eb44332009-09-09 15:08:12 +00007195
Eli Friedmanef331b72012-01-20 01:26:23 +00007196 // We don't know whether the subexpression is potentially evaluated until
7197 // after we perform semantic analysis. We speculatively assume it is
7198 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007199 // potentially evaluated.
Eli Friedman80bfa3d2012-09-26 04:34:21 +00007200 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7201 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00007202
John McCall60d7b3a2010-08-24 06:29:42 +00007203 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007204 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007205 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007206
Douglas Gregorb98b1992009-08-11 05:31:07 +00007207 if (!getDerived().AlwaysRebuild() &&
7208 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007209 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007210
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007211 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7212 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007213 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007214 E->getLocEnd());
7215}
7216
7217template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007218ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007219TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7220 if (E->isTypeOperand()) {
7221 TypeSourceInfo *TInfo
7222 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7223 if (!TInfo)
7224 return ExprError();
7225
7226 if (!getDerived().AlwaysRebuild() &&
7227 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007228 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007229
Douglas Gregor3c52a212011-03-06 17:40:41 +00007230 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007231 E->getLocStart(),
7232 TInfo,
7233 E->getLocEnd());
7234 }
7235
Francois Pichet01b7c302010-09-08 12:20:18 +00007236 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7237
7238 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7239 if (SubExpr.isInvalid())
7240 return ExprError();
7241
7242 if (!getDerived().AlwaysRebuild() &&
7243 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007244 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007245
7246 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7247 E->getLocStart(),
7248 SubExpr.get(),
7249 E->getLocEnd());
7250}
7251
7252template<typename Derived>
7253ExprResult
John McCall454feb92009-12-08 09:21:05 +00007254TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007255 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007256}
Mike Stump1eb44332009-09-09 15:08:12 +00007257
Douglas Gregorb98b1992009-08-11 05:31:07 +00007258template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007259ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007260TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007261 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007262 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007263}
Mike Stump1eb44332009-09-09 15:08:12 +00007264
Douglas Gregorb98b1992009-08-11 05:31:07 +00007265template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007266ExprResult
John McCall454feb92009-12-08 09:21:05 +00007267TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithcafeb942013-06-07 02:33:37 +00007268 QualType T = getSema().getCurrentThisType();
Mike Stump1eb44332009-09-09 15:08:12 +00007269
Douglas Gregorec79d872012-02-24 17:41:38 +00007270 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7271 // Make sure that we capture 'this'.
7272 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007273 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007274 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007275
Douglas Gregor828a1972010-01-07 23:12:05 +00007276 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007277}
Mike Stump1eb44332009-09-09 15:08:12 +00007278
Douglas Gregorb98b1992009-08-11 05:31:07 +00007279template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007280ExprResult
John McCall454feb92009-12-08 09:21:05 +00007281TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007282 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007283 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007284 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007285
Douglas Gregorb98b1992009-08-11 05:31:07 +00007286 if (!getDerived().AlwaysRebuild() &&
7287 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007288 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007289
Douglas Gregorbca01b42011-07-06 22:04:06 +00007290 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7291 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007292}
Mike Stump1eb44332009-09-09 15:08:12 +00007293
Douglas Gregorb98b1992009-08-11 05:31:07 +00007294template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007295ExprResult
John McCall454feb92009-12-08 09:21:05 +00007296TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007297 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007298 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7299 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007300 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007301 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007302
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007303 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007304 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007305 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007306
Douglas Gregor036aed12009-12-23 23:03:06 +00007307 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007308}
Mike Stump1eb44332009-09-09 15:08:12 +00007309
Douglas Gregorb98b1992009-08-11 05:31:07 +00007310template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007311ExprResult
Richard Smithc3bf52c2013-04-20 22:23:05 +00007312TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
7313 FieldDecl *Field
7314 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
7315 E->getField()));
7316 if (!Field)
7317 return ExprError();
7318
7319 if (!getDerived().AlwaysRebuild() && Field == E->getField())
7320 return SemaRef.Owned(E);
7321
7322 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
7323}
7324
7325template<typename Derived>
7326ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007327TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7328 CXXScalarValueInitExpr *E) {
7329 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7330 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007331 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007332
Douglas Gregorb98b1992009-08-11 05:31:07 +00007333 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007334 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007335 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007336
Chad Rosier4a9d7952012-08-08 18:46:20 +00007337 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregorab6677e2010-09-08 00:15:04 +00007338 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007339 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007340}
Mike Stump1eb44332009-09-09 15:08:12 +00007341
Douglas Gregorb98b1992009-08-11 05:31:07 +00007342template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007343ExprResult
John McCall454feb92009-12-08 09:21:05 +00007344TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007345 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007346 TypeSourceInfo *AllocTypeInfo
7347 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7348 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007349 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007350
Douglas Gregorb98b1992009-08-11 05:31:07 +00007351 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007352 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007353 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007354 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007355
Douglas Gregorb98b1992009-08-11 05:31:07 +00007356 // Transform the placement arguments (if any).
7357 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007358 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007359 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregoraa165f82011-01-03 19:04:46 +00007360 E->getNumPlacementArgs(), true,
7361 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007362 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007363
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007364 // Transform the initializer (if any).
7365 Expr *OldInit = E->getInitializer();
7366 ExprResult NewInit;
7367 if (OldInit)
7368 NewInit = getDerived().TransformExpr(OldInit);
7369 if (NewInit.isInvalid())
7370 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007371
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007372 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007373 FunctionDecl *OperatorNew = 0;
7374 if (E->getOperatorNew()) {
7375 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007376 getDerived().TransformDecl(E->getLocStart(),
7377 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007378 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007379 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007380 }
7381
7382 FunctionDecl *OperatorDelete = 0;
7383 if (E->getOperatorDelete()) {
7384 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007385 getDerived().TransformDecl(E->getLocStart(),
7386 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007387 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007388 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007389 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007390
Douglas Gregorb98b1992009-08-11 05:31:07 +00007391 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007392 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007393 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007394 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007395 OperatorNew == E->getOperatorNew() &&
7396 OperatorDelete == E->getOperatorDelete() &&
7397 !ArgumentChanged) {
7398 // Mark any declarations we need as referenced.
7399 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007400 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007401 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007402 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007403 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007404
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007405 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007406 QualType ElementType
7407 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7408 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7409 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7410 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007411 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007412 }
7413 }
7414 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007415
John McCall3fa5cae2010-10-26 07:05:15 +00007416 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007417 }
Mike Stump1eb44332009-09-09 15:08:12 +00007418
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007419 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007420 if (!ArraySize.get()) {
7421 // If no array size was specified, but the new expression was
7422 // instantiated with an array type (e.g., "new T" where T is
7423 // instantiated with "int[4]"), extract the outer bound from the
7424 // array type as our array size. We do this with constant and
7425 // dependently-sized array types.
7426 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7427 if (!ArrayT) {
7428 // Do nothing
7429 } else if (const ConstantArrayType *ConsArrayT
7430 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007431 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007432 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier4a9d7952012-08-08 18:46:20 +00007433 ConsArrayT->getSize(),
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007434 SemaRef.Context.getSizeType(),
7435 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007436 AllocType = ConsArrayT->getElementType();
7437 } else if (const DependentSizedArrayType *DepArrayT
7438 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7439 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007440 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007441 AllocType = DepArrayT->getElementType();
7442 }
7443 }
7444 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007445
Douglas Gregorb98b1992009-08-11 05:31:07 +00007446 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7447 E->isGlobalNew(),
7448 /*FIXME:*/E->getLocStart(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007449 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007450 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007451 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007452 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007453 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007454 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007455 E->getDirectInitRange(),
7456 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007457}
Mike Stump1eb44332009-09-09 15:08:12 +00007458
Douglas Gregorb98b1992009-08-11 05:31:07 +00007459template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007460ExprResult
John McCall454feb92009-12-08 09:21:05 +00007461TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007462 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007463 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007464 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007465
Douglas Gregor1af74512010-02-26 00:38:10 +00007466 // Transform the delete operator, if known.
7467 FunctionDecl *OperatorDelete = 0;
7468 if (E->getOperatorDelete()) {
7469 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007470 getDerived().TransformDecl(E->getLocStart(),
7471 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007472 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007473 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007474 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007475
Douglas Gregorb98b1992009-08-11 05:31:07 +00007476 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007477 Operand.get() == E->getArgument() &&
7478 OperatorDelete == E->getOperatorDelete()) {
7479 // Mark any declarations we need as referenced.
7480 // FIXME: instantiation-specific.
7481 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007482 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007483
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007484 if (!E->getArgument()->isTypeDependent()) {
7485 QualType Destroyed = SemaRef.Context.getBaseElementType(
7486 E->getDestroyedType());
7487 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7488 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007489 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedman5f2987c2012-02-02 03:46:19 +00007490 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007491 }
7492 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007493
John McCall3fa5cae2010-10-26 07:05:15 +00007494 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007495 }
Mike Stump1eb44332009-09-09 15:08:12 +00007496
Douglas Gregorb98b1992009-08-11 05:31:07 +00007497 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7498 E->isGlobalDelete(),
7499 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007500 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007501}
Mike Stump1eb44332009-09-09 15:08:12 +00007502
Douglas Gregorb98b1992009-08-11 05:31:07 +00007503template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007504ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007505TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007506 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007507 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007508 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007509 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007510
John McCallb3d87482010-08-24 05:47:05 +00007511 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007512 bool MayBePseudoDestructor = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007513 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007514 E->getOperatorLoc(),
7515 E->isArrow()? tok::arrow : tok::period,
7516 ObjectTypePtr,
7517 MayBePseudoDestructor);
7518 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007519 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007520
John McCallb3d87482010-08-24 05:47:05 +00007521 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007522 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7523 if (QualifierLoc) {
7524 QualifierLoc
7525 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7526 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007527 return ExprError();
7528 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007529 CXXScopeSpec SS;
7530 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007531
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007532 PseudoDestructorTypeStorage Destroyed;
7533 if (E->getDestroyedTypeInfo()) {
7534 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007535 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007536 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007537 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007538 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007539 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007540 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007541 // We aren't likely to be able to resolve the identifier down to a type
7542 // now anyway, so just retain the identifier.
7543 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7544 E->getDestroyedTypeLoc());
7545 } else {
7546 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007547 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007548 *E->getDestroyedTypeIdentifier(),
7549 E->getDestroyedTypeLoc(),
7550 /*Scope=*/0,
7551 SS, ObjectTypePtr,
7552 false);
7553 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007554 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007555
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007556 Destroyed
7557 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7558 E->getDestroyedTypeLoc());
7559 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007560
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007561 TypeSourceInfo *ScopeTypeInfo = 0;
7562 if (E->getScopeTypeInfo()) {
Douglas Gregor303b96f2013-03-08 21:25:01 +00007563 CXXScopeSpec EmptySS;
7564 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
7565 E->getScopeTypeInfo(), ObjectType, 0, EmptySS);
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007566 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007567 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007568 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007569
John McCall9ae2f072010-08-23 23:25:46 +00007570 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007571 E->getOperatorLoc(),
7572 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007573 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007574 ScopeTypeInfo,
7575 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007576 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007577 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007578}
Mike Stump1eb44332009-09-09 15:08:12 +00007579
Douglas Gregora71d8192009-09-04 17:36:40 +00007580template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007581ExprResult
John McCallba135432009-11-21 08:51:07 +00007582TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007583 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007584 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7585 Sema::LookupOrdinaryName);
7586
7587 // Transform all the decls.
7588 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7589 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007590 NamedDecl *InstD = static_cast<NamedDecl*>(
7591 getDerived().TransformDecl(Old->getNameLoc(),
7592 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007593 if (!InstD) {
7594 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7595 // This can happen because of dependent hiding.
7596 if (isa<UsingShadowDecl>(*I))
7597 continue;
7598 else
John McCallf312b1e2010-08-26 23:41:50 +00007599 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007600 }
John McCallf7a1a742009-11-24 19:00:30 +00007601
7602 // Expand using declarations.
7603 if (isa<UsingDecl>(InstD)) {
7604 UsingDecl *UD = cast<UsingDecl>(InstD);
7605 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7606 E = UD->shadow_end(); I != E; ++I)
7607 R.addDecl(*I);
7608 continue;
7609 }
7610
7611 R.addDecl(InstD);
7612 }
7613
7614 // Resolve a kind, but don't do any further analysis. If it's
7615 // ambiguous, the callee needs to deal with it.
7616 R.resolveKind();
7617
7618 // Rebuild the nested-name qualifier, if present.
7619 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007620 if (Old->getQualifierLoc()) {
7621 NestedNameSpecifierLoc QualifierLoc
7622 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7623 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007624 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007625
Douglas Gregor4c9be892011-02-28 20:01:57 +00007626 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007627 }
7628
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007629 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007630 CXXRecordDecl *NamingClass
7631 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7632 Old->getNameLoc(),
7633 Old->getNamingClass()));
7634 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007635 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007636
Douglas Gregor66c45152010-04-27 16:10:10 +00007637 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007638 }
7639
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007640 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7641
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007642 // If we have neither explicit template arguments, nor the template keyword,
7643 // it's a normal declaration name.
7644 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007645 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7646
7647 // If we have template arguments, rebuild them, then rebuild the
7648 // templateid expression.
7649 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola02e221b2012-08-28 04:13:54 +00007650 if (Old->hasExplicitTemplateArgs() &&
7651 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregorfcc12532010-12-20 17:31:10 +00007652 Old->getNumTemplateArgs(),
7653 TransArgs))
7654 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007655
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007656 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007657 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007658}
Mike Stump1eb44332009-09-09 15:08:12 +00007659
Douglas Gregorb98b1992009-08-11 05:31:07 +00007660template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007661ExprResult
John McCall454feb92009-12-08 09:21:05 +00007662TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007663 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7664 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007665 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007666
Douglas Gregorb98b1992009-08-11 05:31:07 +00007667 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007668 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007669 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007670
Mike Stump1eb44332009-09-09 15:08:12 +00007671 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007672 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007673 T,
7674 E->getLocEnd());
7675}
Mike Stump1eb44332009-09-09 15:08:12 +00007676
Douglas Gregorb98b1992009-08-11 05:31:07 +00007677template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007678ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007679TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7680 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7681 if (!LhsT)
7682 return ExprError();
7683
7684 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7685 if (!RhsT)
7686 return ExprError();
7687
7688 if (!getDerived().AlwaysRebuild() &&
7689 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7690 return SemaRef.Owned(E);
7691
7692 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7693 E->getLocStart(),
7694 LhsT, RhsT,
7695 E->getLocEnd());
7696}
7697
7698template<typename Derived>
7699ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007700TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7701 bool ArgChanged = false;
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00007702 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007703 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7704 TypeSourceInfo *From = E->getArg(I);
7705 TypeLoc FromTL = From->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00007706 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007707 TypeLocBuilder TLB;
7708 TLB.reserve(FromTL.getFullDataSize());
7709 QualType To = getDerived().TransformType(TLB, FromTL);
7710 if (To.isNull())
7711 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007712
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007713 if (To == From->getType())
7714 Args.push_back(From);
7715 else {
7716 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7717 ArgChanged = true;
7718 }
7719 continue;
7720 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007721
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007722 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007723
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007724 // We have a pack expansion. Instantiate it.
David Blaikie39e6ab42013-02-18 22:06:02 +00007725 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007726 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7727 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7728 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007729
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007730 // Determine whether the set of unexpanded parameter packs can and should
7731 // be expanded.
7732 bool Expand = true;
7733 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00007734 Optional<unsigned> OrigNumExpansions =
7735 ExpansionTL.getTypePtr()->getNumExpansions();
7736 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007737 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7738 PatternTL.getSourceRange(),
7739 Unexpanded,
7740 Expand, RetainExpansion,
7741 NumExpansions))
7742 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007743
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007744 if (!Expand) {
7745 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00007746 // transformation on the pack expansion, producing another pack
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007747 // expansion.
7748 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007749
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007750 TypeLocBuilder TLB;
7751 TLB.reserve(From->getTypeLoc().getFullDataSize());
7752
7753 QualType To = getDerived().TransformType(TLB, PatternTL);
7754 if (To.isNull())
7755 return ExprError();
7756
Chad Rosier4a9d7952012-08-08 18:46:20 +00007757 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007758 PatternTL.getSourceRange(),
7759 ExpansionTL.getEllipsisLoc(),
7760 NumExpansions);
7761 if (To.isNull())
7762 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007763
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007764 PackExpansionTypeLoc ToExpansionTL
7765 = TLB.push<PackExpansionTypeLoc>(To);
7766 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7767 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7768 continue;
7769 }
7770
7771 // Expand the pack expansion by substituting for each argument in the
7772 // pack(s).
7773 for (unsigned I = 0; I != *NumExpansions; ++I) {
7774 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7775 TypeLocBuilder TLB;
7776 TLB.reserve(PatternTL.getFullDataSize());
7777 QualType To = getDerived().TransformType(TLB, PatternTL);
7778 if (To.isNull())
7779 return ExprError();
7780
7781 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7782 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007783
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007784 if (!RetainExpansion)
7785 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007786
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007787 // If we're supposed to retain a pack expansion, do so by temporarily
7788 // forgetting the partially-substituted parameter pack.
7789 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7790
7791 TypeLocBuilder TLB;
7792 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007793
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007794 QualType To = getDerived().TransformType(TLB, PatternTL);
7795 if (To.isNull())
7796 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007797
7798 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007799 PatternTL.getSourceRange(),
7800 ExpansionTL.getEllipsisLoc(),
7801 NumExpansions);
7802 if (To.isNull())
7803 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007804
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007805 PackExpansionTypeLoc ToExpansionTL
7806 = TLB.push<PackExpansionTypeLoc>(To);
7807 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7808 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7809 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007810
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007811 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7812 return SemaRef.Owned(E);
7813
7814 return getDerived().RebuildTypeTrait(E->getTrait(),
7815 E->getLocStart(),
7816 Args,
7817 E->getLocEnd());
7818}
7819
7820template<typename Derived>
7821ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007822TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7823 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7824 if (!T)
7825 return ExprError();
7826
7827 if (!getDerived().AlwaysRebuild() &&
7828 T == E->getQueriedTypeSourceInfo())
7829 return SemaRef.Owned(E);
7830
7831 ExprResult SubExpr;
7832 {
7833 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7834 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7835 if (SubExpr.isInvalid())
7836 return ExprError();
7837
7838 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7839 return SemaRef.Owned(E);
7840 }
7841
7842 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7843 E->getLocStart(),
7844 T,
7845 SubExpr.get(),
7846 E->getLocEnd());
7847}
7848
7849template<typename Derived>
7850ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007851TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7852 ExprResult SubExpr;
7853 {
7854 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7855 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7856 if (SubExpr.isInvalid())
7857 return ExprError();
7858
7859 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7860 return SemaRef.Owned(E);
7861 }
7862
7863 return getDerived().RebuildExpressionTrait(
7864 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7865}
7866
7867template<typename Derived>
7868ExprResult
John McCall865d4472009-11-19 22:55:06 +00007869TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007870 DependentScopeDeclRefExpr *E) {
Richard Smithefeeccf2012-10-21 03:28:35 +00007871 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
7872}
7873
7874template<typename Derived>
7875ExprResult
7876TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
7877 DependentScopeDeclRefExpr *E,
7878 bool IsAddressOfOperand) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007879 NestedNameSpecifierLoc QualifierLoc
7880 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7881 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007882 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007883 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00007884
John McCall43fed0d2010-11-12 08:19:04 +00007885 // TODO: If this is a conversion-function-id, verify that the
7886 // destination type name (if present) resolves the same way after
7887 // instantiation as it did in the local scope.
7888
Abramo Bagnara25777432010-08-11 22:01:17 +00007889 DeclarationNameInfo NameInfo
7890 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7891 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007892 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007893
John McCallf7a1a742009-11-24 19:00:30 +00007894 if (!E->hasExplicitTemplateArgs()) {
7895 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007896 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007897 // Note: it is sufficient to compare the Name component of NameInfo:
7898 // if name has not changed, DNLoc has not changed either.
7899 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007900 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007901
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007902 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007903 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007904 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00007905 /*TemplateArgs*/ 0,
7906 IsAddressOfOperand);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007907 }
John McCalld5532b62009-11-23 01:53:49 +00007908
7909 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007910 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7911 E->getNumTemplateArgs(),
7912 TransArgs))
7913 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007914
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007915 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007916 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007917 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00007918 &TransArgs,
7919 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007920}
7921
7922template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007923ExprResult
John McCall454feb92009-12-08 09:21:05 +00007924TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithc83c2302012-12-19 01:39:02 +00007925 // CXXConstructExprs other than for list-initialization and
7926 // CXXTemporaryObjectExpr are always implicit, so when we have
7927 // a 1-argument construction we just transform that argument.
Richard Smith73ed67c2012-11-26 08:32:48 +00007928 if ((E->getNumArgs() == 1 ||
7929 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithc83c2302012-12-19 01:39:02 +00007930 (!getDerived().DropCallArgument(E->getArg(0))) &&
7931 !E->isListInitialization())
Douglas Gregor321725d2010-02-03 03:01:57 +00007932 return getDerived().TransformExpr(E->getArg(0));
7933
Douglas Gregorb98b1992009-08-11 05:31:07 +00007934 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7935
7936 QualType T = getDerived().TransformType(E->getType());
7937 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007938 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007939
7940 CXXConstructorDecl *Constructor
7941 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007942 getDerived().TransformDecl(E->getLocStart(),
7943 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007944 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007945 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007946
Douglas Gregorb98b1992009-08-11 05:31:07 +00007947 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007948 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007949 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007950 &ArgumentChanged))
7951 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007952
Douglas Gregorb98b1992009-08-11 05:31:07 +00007953 if (!getDerived().AlwaysRebuild() &&
7954 T == E->getType() &&
7955 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007956 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007957 // Mark the constructor as referenced.
7958 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007959 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007960 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007961 }
Mike Stump1eb44332009-09-09 15:08:12 +00007962
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007963 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7964 Constructor, E->isElidable(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007965 Args,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007966 E->hadMultipleCandidates(),
Richard Smithc83c2302012-12-19 01:39:02 +00007967 E->isListInitialization(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007968 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007969 E->getConstructionKind(),
7970 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007971}
Mike Stump1eb44332009-09-09 15:08:12 +00007972
Douglas Gregorb98b1992009-08-11 05:31:07 +00007973/// \brief Transform a C++ temporary-binding expression.
7974///
Douglas Gregor51326552009-12-24 18:51:59 +00007975/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7976/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007977template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007978ExprResult
John McCall454feb92009-12-08 09:21:05 +00007979TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007980 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007981}
Mike Stump1eb44332009-09-09 15:08:12 +00007982
John McCall4765fa02010-12-06 08:20:24 +00007983/// \brief Transform a C++ expression that contains cleanups that should
7984/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007985///
John McCall4765fa02010-12-06 08:20:24 +00007986/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007987/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007988template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007989ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007990TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007991 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007992}
Mike Stump1eb44332009-09-09 15:08:12 +00007993
Douglas Gregorb98b1992009-08-11 05:31:07 +00007994template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007995ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007996TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007997 CXXTemporaryObjectExpr *E) {
7998 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7999 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008000 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008001
Douglas Gregorb98b1992009-08-11 05:31:07 +00008002 CXXConstructorDecl *Constructor
8003 = cast_or_null<CXXConstructorDecl>(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008004 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008005 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008006 if (!Constructor)
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 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008010 SmallVector<Expr*, 8> Args;
Douglas Gregorb98b1992009-08-11 05:31:07 +00008011 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008012 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008013 &ArgumentChanged))
8014 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008015
Douglas Gregorb98b1992009-08-11 05:31:07 +00008016 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008017 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008018 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00008019 !ArgumentChanged) {
8020 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00008021 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00008022 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00008023 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008024
Richard Smithc83c2302012-12-19 01:39:02 +00008025 // FIXME: Pass in E->isListInitialization().
Douglas Gregorab6677e2010-09-08 00:15:04 +00008026 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8027 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008028 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008029 E->getLocEnd());
8030}
Mike Stump1eb44332009-09-09 15:08:12 +00008031
Douglas Gregorb98b1992009-08-11 05:31:07 +00008032template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008033ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00008034TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Douglas Gregordfca6f52012-02-13 22:00:16 +00008035 // Transform the type of the lambda parameters and start the definition of
8036 // the lambda itself.
8037 TypeSourceInfo *MethodTy
Chad Rosier4a9d7952012-08-08 18:46:20 +00008038 = TransformType(E->getCallOperator()->getTypeSourceInfo());
Douglas Gregordfca6f52012-02-13 22:00:16 +00008039 if (!MethodTy)
8040 return ExprError();
8041
Eli Friedman8da8a662012-09-19 01:18:11 +00008042 // Create the local class that will describe the lambda.
8043 CXXRecordDecl *Class
8044 = getSema().createLambdaClosureType(E->getIntroducerRange(),
8045 MethodTy,
8046 /*KnownDependent=*/false);
8047 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8048
Douglas Gregorc6889e72012-02-14 22:28:59 +00008049 // Transform lambda parameters.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008050 SmallVector<QualType, 4> ParamTypes;
8051 SmallVector<ParmVarDecl *, 4> Params;
Douglas Gregorc6889e72012-02-14 22:28:59 +00008052 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
8053 E->getCallOperator()->param_begin(),
8054 E->getCallOperator()->param_size(),
8055 0, ParamTypes, &Params))
Richard Smith612409e2012-07-25 03:56:55 +00008056 return ExprError();
Douglas Gregorc6889e72012-02-14 22:28:59 +00008057
Douglas Gregordfca6f52012-02-13 22:00:16 +00008058 // Build the call operator.
8059 CXXMethodDecl *CallOperator
8060 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00008061 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00008062 E->getCallOperator()->getLocEnd(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00008063 Params);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008064 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
Douglas Gregord5387e82012-02-14 00:00:48 +00008065
Richard Smith612409e2012-07-25 03:56:55 +00008066 return getDerived().TransformLambdaScope(E, CallOperator);
8067}
8068
8069template<typename Derived>
8070ExprResult
8071TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
8072 CXXMethodDecl *CallOperator) {
Richard Smith0d8e9642013-05-16 06:20:58 +00008073 bool Invalid = false;
8074
8075 // Transform any init-capture expressions before entering the scope of the
8076 // lambda.
8077 llvm::SmallVector<ExprResult, 8> InitCaptureExprs;
8078 InitCaptureExprs.resize(E->explicit_capture_end() -
8079 E->explicit_capture_begin());
8080 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8081 CEnd = E->capture_end();
8082 C != CEnd; ++C) {
8083 if (!C->isInitCapture())
8084 continue;
8085 InitCaptureExprs[C - E->capture_begin()] =
8086 getDerived().TransformExpr(E->getInitCaptureInit(C));
8087 }
8088
Douglas Gregord5387e82012-02-14 00:00:48 +00008089 // Introduce the context of the call operator.
8090 Sema::ContextRAII SavedContext(getSema(), CallOperator);
8091
Douglas Gregordfca6f52012-02-13 22:00:16 +00008092 // Enter the scope of the lambda.
8093 sema::LambdaScopeInfo *LSI
8094 = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(),
8095 E->getCaptureDefault(),
8096 E->hasExplicitParameters(),
8097 E->hasExplicitResultType(),
8098 E->isMutable());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008099
Douglas Gregordfca6f52012-02-13 22:00:16 +00008100 // Transform captures.
Douglas Gregordfca6f52012-02-13 22:00:16 +00008101 bool FinishedExplicitCaptures = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008102 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008103 CEnd = E->capture_end();
8104 C != CEnd; ++C) {
8105 // When we hit the first implicit capture, tell Sema that we've finished
8106 // the list of explicit captures.
8107 if (!FinishedExplicitCaptures && C->isImplicit()) {
8108 getSema().finishLambdaExplicitCaptures(LSI);
8109 FinishedExplicitCaptures = true;
8110 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008111
Douglas Gregordfca6f52012-02-13 22:00:16 +00008112 // Capturing 'this' is trivial.
8113 if (C->capturesThis()) {
8114 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8115 continue;
8116 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008117
Richard Smith0d8e9642013-05-16 06:20:58 +00008118 // Rebuild init-captures, including the implied field declaration.
8119 if (C->isInitCapture()) {
8120 ExprResult Init = InitCaptureExprs[C - E->capture_begin()];
8121 if (Init.isInvalid()) {
8122 Invalid = true;
8123 continue;
8124 }
8125 FieldDecl *OldFD = C->getInitCaptureField();
8126 FieldDecl *NewFD = getSema().checkInitCapture(
8127 C->getLocation(), OldFD->getType()->isReferenceType(),
8128 OldFD->getIdentifier(), Init.take());
8129 if (!NewFD)
8130 Invalid = true;
8131 else
8132 getDerived().transformedLocalDecl(OldFD, NewFD);
8133 continue;
8134 }
8135
8136 assert(C->capturesVariable() && "unexpected kind of lambda capture");
8137
Douglas Gregora7365242012-02-14 19:27:52 +00008138 // Determine the capture kind for Sema.
8139 Sema::TryCaptureKind Kind
8140 = C->isImplicit()? Sema::TryCapture_Implicit
8141 : C->getCaptureKind() == LCK_ByCopy
8142 ? Sema::TryCapture_ExplicitByVal
8143 : Sema::TryCapture_ExplicitByRef;
8144 SourceLocation EllipsisLoc;
8145 if (C->isPackExpansion()) {
8146 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8147 bool ShouldExpand = false;
8148 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008149 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008150 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8151 C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008152 Unexpanded,
8153 ShouldExpand, RetainExpansion,
Richard Smith0d8e9642013-05-16 06:20:58 +00008154 NumExpansions)) {
8155 Invalid = true;
8156 continue;
8157 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008158
Douglas Gregora7365242012-02-14 19:27:52 +00008159 if (ShouldExpand) {
8160 // The transform has determined that we should perform an expansion;
8161 // transform and capture each of the arguments.
8162 // expansion of the pattern. Do so.
8163 VarDecl *Pack = C->getCapturedVar();
8164 for (unsigned I = 0; I != *NumExpansions; ++I) {
8165 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8166 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008167 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008168 Pack));
8169 if (!CapturedVar) {
8170 Invalid = true;
8171 continue;
8172 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008173
Douglas Gregora7365242012-02-14 19:27:52 +00008174 // Capture the transformed variable.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008175 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8176 }
Douglas Gregora7365242012-02-14 19:27:52 +00008177 continue;
8178 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008179
Douglas Gregora7365242012-02-14 19:27:52 +00008180 EllipsisLoc = C->getEllipsisLoc();
8181 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008182
Douglas Gregordfca6f52012-02-13 22:00:16 +00008183 // Transform the captured variable.
8184 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008185 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008186 C->getCapturedVar()));
8187 if (!CapturedVar) {
8188 Invalid = true;
8189 continue;
8190 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008191
Douglas Gregordfca6f52012-02-13 22:00:16 +00008192 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00008193 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008194 }
8195 if (!FinishedExplicitCaptures)
8196 getSema().finishLambdaExplicitCaptures(LSI);
8197
Douglas Gregordfca6f52012-02-13 22:00:16 +00008198
8199 // Enter a new evaluation context to insulate the lambda from any
8200 // cleanups from the enclosing full-expression.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008201 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008202
8203 if (Invalid) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008204 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregordfca6f52012-02-13 22:00:16 +00008205 /*IsInstantiation=*/true);
8206 return ExprError();
8207 }
8208
8209 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00008210 StmtResult Body = getDerived().TransformStmt(E->getBody());
8211 if (Body.isInvalid()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008212 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregord5387e82012-02-14 00:00:48 +00008213 /*IsInstantiation=*/true);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008214 return ExprError();
Douglas Gregord5387e82012-02-14 00:00:48 +00008215 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00008216
Chad Rosier4a9d7952012-08-08 18:46:20 +00008217 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00008218 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00008219}
8220
8221template<typename Derived>
8222ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008223TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00008224 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00008225 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8226 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008227 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008228
Douglas Gregorb98b1992009-08-11 05:31:07 +00008229 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008230 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008231 Args.reserve(E->arg_size());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008232 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008233 &ArgumentChanged))
8234 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008235
Douglas Gregorb98b1992009-08-11 05:31:07 +00008236 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008237 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008238 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008239 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008240
Douglas Gregorb98b1992009-08-11 05:31:07 +00008241 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00008242 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008243 E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008244 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008245 E->getRParenLoc());
8246}
Mike Stump1eb44332009-09-09 15:08:12 +00008247
Douglas Gregorb98b1992009-08-11 05:31:07 +00008248template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008249ExprResult
John McCall865d4472009-11-19 22:55:06 +00008250TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008251 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008252 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008253 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008254 Expr *OldBase;
8255 QualType BaseType;
8256 QualType ObjectType;
8257 if (!E->isImplicitAccess()) {
8258 OldBase = E->getBase();
8259 Base = getDerived().TransformExpr(OldBase);
8260 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008261 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008262
John McCallaa81e162009-12-01 22:10:20 +00008263 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008264 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008265 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008266 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008267 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008268 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008269 ObjectTy,
8270 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008271 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008272 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008273
John McCallb3d87482010-08-24 05:47:05 +00008274 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008275 BaseType = ((Expr*) Base.get())->getType();
8276 } else {
8277 OldBase = 0;
8278 BaseType = getDerived().TransformType(E->getBaseType());
8279 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8280 }
Mike Stump1eb44332009-09-09 15:08:12 +00008281
Douglas Gregor6cd21982009-10-20 05:58:46 +00008282 // Transform the first part of the nested-name-specifier that qualifies
8283 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008284 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008285 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008286 E->getFirstQualifierFoundInScope(),
8287 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008288
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008289 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008290 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008291 QualifierLoc
8292 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8293 ObjectType,
8294 FirstQualifierInScope);
8295 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008296 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008297 }
Mike Stump1eb44332009-09-09 15:08:12 +00008298
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008299 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8300
John McCall43fed0d2010-11-12 08:19:04 +00008301 // TODO: If this is a conversion-function-id, verify that the
8302 // destination type name (if present) resolves the same way after
8303 // instantiation as it did in the local scope.
8304
Abramo Bagnara25777432010-08-11 22:01:17 +00008305 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008306 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008307 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008308 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008309
John McCallaa81e162009-12-01 22:10:20 +00008310 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008311 // This is a reference to a member without an explicitly-specified
8312 // template argument list. Optimize for this common case.
8313 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008314 Base.get() == OldBase &&
8315 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008316 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008317 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008318 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008319 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008320
John McCall9ae2f072010-08-23 23:25:46 +00008321 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008322 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008323 E->isArrow(),
8324 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008325 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008326 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008327 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008328 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008329 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008330 }
8331
John McCalld5532b62009-11-23 01:53:49 +00008332 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008333 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8334 E->getNumTemplateArgs(),
8335 TransArgs))
8336 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008337
John McCall9ae2f072010-08-23 23:25:46 +00008338 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008339 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008340 E->isArrow(),
8341 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008342 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008343 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008344 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008345 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008346 &TransArgs);
8347}
8348
8349template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008350ExprResult
John McCall454feb92009-12-08 09:21:05 +00008351TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008352 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008353 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008354 QualType BaseType;
8355 if (!Old->isImplicitAccess()) {
8356 Base = getDerived().TransformExpr(Old->getBase());
8357 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008358 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008359 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8360 Old->isArrow());
8361 if (Base.isInvalid())
8362 return ExprError();
8363 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008364 } else {
8365 BaseType = getDerived().TransformType(Old->getBaseType());
8366 }
John McCall129e2df2009-11-30 22:42:35 +00008367
Douglas Gregor4c9be892011-02-28 20:01:57 +00008368 NestedNameSpecifierLoc QualifierLoc;
8369 if (Old->getQualifierLoc()) {
8370 QualifierLoc
8371 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8372 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008373 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008374 }
8375
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008376 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8377
Abramo Bagnara25777432010-08-11 22:01:17 +00008378 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008379 Sema::LookupOrdinaryName);
8380
8381 // Transform all the decls.
8382 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8383 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008384 NamedDecl *InstD = static_cast<NamedDecl*>(
8385 getDerived().TransformDecl(Old->getMemberLoc(),
8386 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008387 if (!InstD) {
8388 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8389 // This can happen because of dependent hiding.
8390 if (isa<UsingShadowDecl>(*I))
8391 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008392 else {
8393 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008394 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008395 }
John McCall9f54ad42009-12-10 09:41:52 +00008396 }
John McCall129e2df2009-11-30 22:42:35 +00008397
8398 // Expand using declarations.
8399 if (isa<UsingDecl>(InstD)) {
8400 UsingDecl *UD = cast<UsingDecl>(InstD);
8401 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8402 E = UD->shadow_end(); I != E; ++I)
8403 R.addDecl(*I);
8404 continue;
8405 }
8406
8407 R.addDecl(InstD);
8408 }
8409
8410 R.resolveKind();
8411
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008412 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008413 if (Old->getNamingClass()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008414 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008415 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008416 Old->getMemberLoc(),
8417 Old->getNamingClass()));
8418 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008419 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008420
Douglas Gregor66c45152010-04-27 16:10:10 +00008421 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008422 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008423
John McCall129e2df2009-11-30 22:42:35 +00008424 TemplateArgumentListInfo TransArgs;
8425 if (Old->hasExplicitTemplateArgs()) {
8426 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8427 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008428 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8429 Old->getNumTemplateArgs(),
8430 TransArgs))
8431 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008432 }
John McCallc2233c52010-01-15 08:34:02 +00008433
8434 // FIXME: to do this check properly, we will need to preserve the
8435 // first-qualifier-in-scope here, just in case we had a dependent
8436 // base (and therefore couldn't do the check) and a
8437 // nested-name-qualifier (and therefore could do the lookup).
8438 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008439
John McCall9ae2f072010-08-23 23:25:46 +00008440 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008441 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008442 Old->getOperatorLoc(),
8443 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008444 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008445 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008446 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008447 R,
8448 (Old->hasExplicitTemplateArgs()
8449 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008450}
8451
8452template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008453ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008454TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008455 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008456 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8457 if (SubExpr.isInvalid())
8458 return ExprError();
8459
8460 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008461 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008462
8463 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8464}
8465
8466template<typename Derived>
8467ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008468TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008469 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8470 if (Pattern.isInvalid())
8471 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008472
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008473 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8474 return SemaRef.Owned(E);
8475
Douglas Gregor67fd1252011-01-14 21:20:45 +00008476 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8477 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008478}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008479
8480template<typename Derived>
8481ExprResult
8482TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8483 // If E is not value-dependent, then nothing will change when we transform it.
8484 // Note: This is an instantiation-centric view.
8485 if (!E->isValueDependent())
8486 return SemaRef.Owned(E);
8487
8488 // Note: None of the implementations of TryExpandParameterPacks can ever
8489 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier4a9d7952012-08-08 18:46:20 +00008490 // so
Douglas Gregoree8aff02011-01-04 17:33:58 +00008491 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8492 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008493 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008494 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008495 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008496 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008497 ShouldExpand, RetainExpansion,
8498 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008499 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008500
Douglas Gregor089e8932011-10-10 18:59:29 +00008501 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008502 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008503
Douglas Gregor089e8932011-10-10 18:59:29 +00008504 NamedDecl *Pack = E->getPack();
8505 if (!ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008506 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008507 Pack));
8508 if (!Pack)
8509 return ExprError();
8510 }
8511
Chad Rosier4a9d7952012-08-08 18:46:20 +00008512
Douglas Gregoree8aff02011-01-04 17:33:58 +00008513 // We now know the length of the parameter pack, so build a new expression
8514 // that stores that length.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008515 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8516 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008517 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008518}
8519
Douglas Gregorbe230c32011-01-03 17:17:50 +00008520template<typename Derived>
8521ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008522TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8523 SubstNonTypeTemplateParmPackExpr *E) {
8524 // Default behavior is to do nothing with this transformation.
8525 return SemaRef.Owned(E);
8526}
8527
8528template<typename Derived>
8529ExprResult
John McCall91a57552011-07-15 05:09:51 +00008530TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8531 SubstNonTypeTemplateParmExpr *E) {
8532 // Default behavior is to do nothing with this transformation.
8533 return SemaRef.Owned(E);
8534}
8535
8536template<typename Derived>
8537ExprResult
Richard Smith9a4db032012-09-12 00:56:43 +00008538TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8539 // Default behavior is to do nothing with this transformation.
8540 return SemaRef.Owned(E);
8541}
8542
8543template<typename Derived>
8544ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008545TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8546 MaterializeTemporaryExpr *E) {
8547 return getDerived().TransformExpr(E->GetTemporaryExpr());
8548}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008549
Douglas Gregor03e80032011-06-21 17:03:29 +00008550template<typename Derived>
8551ExprResult
John McCall454feb92009-12-08 09:21:05 +00008552TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008553 return SemaRef.MaybeBindToTemporary(E);
8554}
8555
8556template<typename Derived>
8557ExprResult
8558TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008559 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008560}
8561
8562template<typename Derived>
8563ExprResult
Patrick Beardeb382ec2012-04-19 00:25:12 +00008564TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8565 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8566 if (SubExpr.isInvalid())
8567 return ExprError();
8568
8569 if (!getDerived().AlwaysRebuild() &&
8570 SubExpr.get() == E->getSubExpr())
8571 return SemaRef.Owned(E);
8572
8573 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008574}
8575
8576template<typename Derived>
8577ExprResult
8578TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8579 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008580 SmallVector<Expr *, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008581 bool ArgChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008582 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008583 /*IsCall=*/false, Elements, &ArgChanged))
8584 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008585
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008586 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8587 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008588
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008589 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8590 Elements.data(),
8591 Elements.size());
8592}
8593
8594template<typename Derived>
8595ExprResult
8596TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008597 ObjCDictionaryLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008598 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008599 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008600 bool ArgChanged = false;
8601 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8602 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008603
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008604 if (OrigElement.isPackExpansion()) {
8605 // This key/value element is a pack expansion.
8606 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8607 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8608 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8609 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8610
8611 // Determine whether the set of unexpanded parameter packs can
8612 // and should be expanded.
8613 bool Expand = true;
8614 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008615 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8616 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008617 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8618 OrigElement.Value->getLocEnd());
8619 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8620 PatternRange,
8621 Unexpanded,
8622 Expand, RetainExpansion,
8623 NumExpansions))
8624 return ExprError();
8625
8626 if (!Expand) {
8627 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00008628 // transformation on the pack expansion, producing another pack
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008629 // expansion.
8630 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8631 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8632 if (Key.isInvalid())
8633 return ExprError();
8634
8635 if (Key.get() != OrigElement.Key)
8636 ArgChanged = true;
8637
8638 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8639 if (Value.isInvalid())
8640 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008641
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008642 if (Value.get() != OrigElement.Value)
8643 ArgChanged = true;
8644
Chad Rosier4a9d7952012-08-08 18:46:20 +00008645 ObjCDictionaryElement Expansion = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008646 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8647 };
8648 Elements.push_back(Expansion);
8649 continue;
8650 }
8651
8652 // Record right away that the argument was changed. This needs
8653 // to happen even if the array expands to nothing.
8654 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008655
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008656 // The transform has determined that we should perform an elementwise
8657 // expansion of the pattern. Do so.
8658 for (unsigned I = 0; I != *NumExpansions; ++I) {
8659 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8660 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8661 if (Key.isInvalid())
8662 return ExprError();
8663
8664 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8665 if (Value.isInvalid())
8666 return ExprError();
8667
Chad Rosier4a9d7952012-08-08 18:46:20 +00008668 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008669 Key.get(), Value.get(), SourceLocation(), NumExpansions
8670 };
8671
8672 // If any unexpanded parameter packs remain, we still have a
8673 // pack expansion.
8674 if (Key.get()->containsUnexpandedParameterPack() ||
8675 Value.get()->containsUnexpandedParameterPack())
8676 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008677
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008678 Elements.push_back(Element);
8679 }
8680
8681 // We've finished with this pack expansion.
8682 continue;
8683 }
8684
8685 // Transform and check key.
8686 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8687 if (Key.isInvalid())
8688 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008689
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008690 if (Key.get() != OrigElement.Key)
8691 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008692
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008693 // Transform and check value.
8694 ExprResult Value
8695 = getDerived().TransformExpr(OrigElement.Value);
8696 if (Value.isInvalid())
8697 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008698
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008699 if (Value.get() != OrigElement.Value)
8700 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008701
8702 ObjCDictionaryElement Element = {
David Blaikie66874fb2013-02-21 01:47:18 +00008703 Key.get(), Value.get(), SourceLocation(), None
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008704 };
8705 Elements.push_back(Element);
8706 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008707
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008708 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8709 return SemaRef.MaybeBindToTemporary(E);
8710
8711 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8712 Elements.data(),
8713 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008714}
8715
Mike Stump1eb44332009-09-09 15:08:12 +00008716template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008717ExprResult
John McCall454feb92009-12-08 09:21:05 +00008718TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008719 TypeSourceInfo *EncodedTypeInfo
8720 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8721 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008722 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008723
Douglas Gregorb98b1992009-08-11 05:31:07 +00008724 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008725 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008726 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008727
8728 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008729 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008730 E->getRParenLoc());
8731}
Mike Stump1eb44332009-09-09 15:08:12 +00008732
Douglas Gregorb98b1992009-08-11 05:31:07 +00008733template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00008734ExprResult TreeTransform<Derived>::
8735TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCall93b64572013-04-11 02:14:26 +00008736 // This is a kind of implicit conversion, and it needs to get dropped
8737 // and recomputed for the same general reasons that ImplicitCastExprs
8738 // do, as well a more specific one: this expression is only valid when
8739 // it appears *immediately* as an argument expression.
8740 return getDerived().TransformExpr(E->getSubExpr());
John McCallf85e1932011-06-15 23:02:42 +00008741}
8742
8743template<typename Derived>
8744ExprResult TreeTransform<Derived>::
8745TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008746 TypeSourceInfo *TSInfo
John McCallf85e1932011-06-15 23:02:42 +00008747 = getDerived().TransformType(E->getTypeInfoAsWritten());
8748 if (!TSInfo)
8749 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008750
John McCallf85e1932011-06-15 23:02:42 +00008751 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008752 if (Result.isInvalid())
John McCallf85e1932011-06-15 23:02:42 +00008753 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008754
John McCallf85e1932011-06-15 23:02:42 +00008755 if (!getDerived().AlwaysRebuild() &&
8756 TSInfo == E->getTypeInfoAsWritten() &&
8757 Result.get() == E->getSubExpr())
8758 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008759
John McCallf85e1932011-06-15 23:02:42 +00008760 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00008761 E->getBridgeKeywordLoc(), TSInfo,
John McCallf85e1932011-06-15 23:02:42 +00008762 Result.get());
8763}
8764
8765template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008766ExprResult
John McCall454feb92009-12-08 09:21:05 +00008767TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008768 // Transform arguments.
8769 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008770 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008771 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008772 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008773 &ArgChanged))
8774 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008775
Douglas Gregor92e986e2010-04-22 16:44:27 +00008776 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8777 // Class message: transform the receiver type.
8778 TypeSourceInfo *ReceiverTypeInfo
8779 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8780 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008781 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008782
Douglas Gregor92e986e2010-04-22 16:44:27 +00008783 // If nothing changed, just retain the existing message send.
8784 if (!getDerived().AlwaysRebuild() &&
8785 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008786 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008787
8788 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008789 SmallVector<SourceLocation, 16> SelLocs;
8790 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008791 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8792 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008793 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008794 E->getMethodDecl(),
8795 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008796 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008797 E->getRightLoc());
8798 }
8799
8800 // Instance message: transform the receiver
8801 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8802 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00008803 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00008804 = getDerived().TransformExpr(E->getInstanceReceiver());
8805 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008806 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00008807
8808 // If nothing changed, just retain the existing message send.
8809 if (!getDerived().AlwaysRebuild() &&
8810 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008811 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008812
Douglas Gregor92e986e2010-04-22 16:44:27 +00008813 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008814 SmallVector<SourceLocation, 16> SelLocs;
8815 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00008816 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00008817 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008818 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008819 E->getMethodDecl(),
8820 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008821 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008822 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008823}
8824
Mike Stump1eb44332009-09-09 15:08:12 +00008825template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008826ExprResult
John McCall454feb92009-12-08 09:21:05 +00008827TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008828 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008829}
8830
Mike Stump1eb44332009-09-09 15:08:12 +00008831template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008832ExprResult
John McCall454feb92009-12-08 09:21:05 +00008833TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008834 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008835}
8836
Mike Stump1eb44332009-09-09 15:08:12 +00008837template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008838ExprResult
John McCall454feb92009-12-08 09:21:05 +00008839TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008840 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008841 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008842 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008843 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008844
8845 // We don't need to transform the ivar; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008846
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008847 // If nothing changed, just retain the existing expression.
8848 if (!getDerived().AlwaysRebuild() &&
8849 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008850 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008851
John McCall9ae2f072010-08-23 23:25:46 +00008852 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008853 E->getLocation(),
8854 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008855}
8856
Mike Stump1eb44332009-09-09 15:08:12 +00008857template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008858ExprResult
John McCall454feb92009-12-08 09:21:05 +00008859TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00008860 // 'super' and types never change. Property never changes. Just
8861 // retain the existing expression.
8862 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00008863 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008864
Douglas Gregore3303542010-04-26 20:47:02 +00008865 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008866 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00008867 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008868 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008869
Douglas Gregore3303542010-04-26 20:47:02 +00008870 // We don't need to transform the property; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008871
Douglas Gregore3303542010-04-26 20:47:02 +00008872 // If nothing changed, just retain the existing expression.
8873 if (!getDerived().AlwaysRebuild() &&
8874 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008875 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008876
John McCall12f78a62010-12-02 01:19:52 +00008877 if (E->isExplicitProperty())
8878 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8879 E->getExplicitProperty(),
8880 E->getLocation());
8881
8882 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00008883 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00008884 E->getImplicitPropertyGetter(),
8885 E->getImplicitPropertySetter(),
8886 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008887}
8888
Mike Stump1eb44332009-09-09 15:08:12 +00008889template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008890ExprResult
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008891TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
8892 // Transform the base expression.
8893 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
8894 if (Base.isInvalid())
8895 return ExprError();
8896
8897 // Transform the key expression.
8898 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
8899 if (Key.isInvalid())
8900 return ExprError();
8901
8902 // If nothing changed, just retain the existing expression.
8903 if (!getDerived().AlwaysRebuild() &&
8904 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
8905 return SemaRef.Owned(E);
8906
Chad Rosier4a9d7952012-08-08 18:46:20 +00008907 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008908 Base.get(), Key.get(),
8909 E->getAtIndexMethodDecl(),
8910 E->setAtIndexMethodDecl());
8911}
8912
8913template<typename Derived>
8914ExprResult
John McCall454feb92009-12-08 09:21:05 +00008915TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008916 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008917 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008918 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008919 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008920
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008921 // If nothing changed, just retain the existing expression.
8922 if (!getDerived().AlwaysRebuild() &&
8923 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008924 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008925
John McCall9ae2f072010-08-23 23:25:46 +00008926 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00008927 E->getOpLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008928 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008929}
8930
Mike Stump1eb44332009-09-09 15:08:12 +00008931template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008932ExprResult
John McCall454feb92009-12-08 09:21:05 +00008933TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008934 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008935 SmallVector<Expr*, 8> SubExprs;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008936 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008937 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008938 SubExprs, &ArgumentChanged))
8939 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008940
Douglas Gregorb98b1992009-08-11 05:31:07 +00008941 if (!getDerived().AlwaysRebuild() &&
8942 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008943 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008944
Douglas Gregorb98b1992009-08-11 05:31:07 +00008945 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008946 SubExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008947 E->getRParenLoc());
8948}
8949
Mike Stump1eb44332009-09-09 15:08:12 +00008950template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008951ExprResult
John McCall454feb92009-12-08 09:21:05 +00008952TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008953 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008954
John McCallc6ac9c32011-02-04 18:33:18 +00008955 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8956 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8957
8958 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00008959 blockScope->TheDecl->setBlockMissingReturnType(
8960 oldBlock->blockMissingReturnType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008961
Chris Lattner686775d2011-07-20 06:58:45 +00008962 SmallVector<ParmVarDecl*, 4> params;
8963 SmallVector<QualType, 4> paramTypes;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008964
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008965 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008966 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8967 oldBlock->param_begin(),
8968 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008969 0, paramTypes, &params)) {
8970 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00008971 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008972 }
John McCallc6ac9c32011-02-04 18:33:18 +00008973
Jordan Rose09189892013-03-08 22:25:36 +00008974 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00008975 QualType exprResultType =
8976 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00008977
8978 // Don't allow returning a objc interface by value.
Eli Friedman84b007f2012-01-26 03:00:14 +00008979 if (exprResultType->isObjCObjectType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008980 getSema().Diag(E->getCaretLocation(),
8981 diag::err_object_cannot_be_passed_returned_by_value)
Eli Friedman84b007f2012-01-26 03:00:14 +00008982 << 0 << exprResultType;
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008983 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregora779d9c2011-01-19 21:32:01 +00008984 return ExprError();
8985 }
John McCall711c52b2011-01-05 12:14:39 +00008986
Jordan Rosebea522f2013-03-08 21:51:21 +00008987 QualType functionType =
8988 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rose09189892013-03-08 22:25:36 +00008989 exprFunctionType->getExtProtoInfo());
John McCallc6ac9c32011-02-04 18:33:18 +00008990 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00008991
8992 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00008993 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00008994 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00008995
8996 if (!oldBlock->blockMissingReturnType()) {
8997 blockScope->HasImplicitReturnType = false;
8998 blockScope->ReturnType = exprResultType;
8999 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00009000
John McCall711c52b2011-01-05 12:14:39 +00009001 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00009002 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009003 if (body.isInvalid()) {
9004 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00009005 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009006 }
John McCall711c52b2011-01-05 12:14:39 +00009007
John McCallc6ac9c32011-02-04 18:33:18 +00009008#ifndef NDEBUG
9009 // In builds with assertions, make sure that we captured everything we
9010 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00009011 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
9012 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
9013 e = oldBlock->capture_end(); i != e; ++i) {
9014 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00009015
Douglas Gregorfc921372011-05-20 15:32:55 +00009016 // Ignore parameter packs.
9017 if (isa<ParmVarDecl>(oldCapture) &&
9018 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9019 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00009020
Douglas Gregorfc921372011-05-20 15:32:55 +00009021 VarDecl *newCapture =
9022 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9023 oldCapture));
9024 assert(blockScope->CaptureMap.count(newCapture));
9025 }
Douglas Gregorec79d872012-02-24 17:41:38 +00009026 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00009027 }
9028#endif
9029
9030 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
9031 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009032}
9033
Mike Stump1eb44332009-09-09 15:08:12 +00009034template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009035ExprResult
Tanya Lattner61eee0c2011-06-04 00:47:47 +00009036TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00009037 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00009038}
Eli Friedman276b0612011-10-11 02:20:01 +00009039
9040template<typename Derived>
9041ExprResult
9042TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009043 QualType RetTy = getDerived().TransformType(E->getType());
9044 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00009045 SmallVector<Expr*, 8> SubExprs;
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009046 SubExprs.reserve(E->getNumSubExprs());
9047 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9048 SubExprs, &ArgumentChanged))
9049 return ExprError();
9050
9051 if (!getDerived().AlwaysRebuild() &&
9052 !ArgumentChanged)
9053 return SemaRef.Owned(E);
9054
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009055 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009056 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00009057}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009058
Douglas Gregorb98b1992009-08-11 05:31:07 +00009059//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00009060// Type reconstruction
9061//===----------------------------------------------------------------------===//
9062
Mike Stump1eb44332009-09-09 15:08:12 +00009063template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00009064QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9065 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00009066 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009067 getDerived().getBaseEntity());
9068}
9069
Mike Stump1eb44332009-09-09 15:08:12 +00009070template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00009071QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9072 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00009073 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009074 getDerived().getBaseEntity());
9075}
9076
Mike Stump1eb44332009-09-09 15:08:12 +00009077template<typename Derived>
9078QualType
John McCall85737a72009-10-30 00:06:24 +00009079TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9080 bool WrittenAsLValue,
9081 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00009082 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00009083 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009084}
9085
9086template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009087QualType
John McCall85737a72009-10-30 00:06:24 +00009088TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9089 QualType ClassType,
9090 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00009091 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00009092 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009093}
9094
9095template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009096QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00009097TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9098 ArrayType::ArraySizeModifier SizeMod,
9099 const llvm::APInt *Size,
9100 Expr *SizeExpr,
9101 unsigned IndexTypeQuals,
9102 SourceRange BracketsRange) {
9103 if (SizeExpr || !Size)
9104 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9105 IndexTypeQuals, BracketsRange,
9106 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00009107
9108 QualType Types[] = {
9109 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9110 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9111 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00009112 };
9113 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
9114 QualType SizeType;
9115 for (unsigned I = 0; I != NumTypes; ++I)
9116 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9117 SizeType = Types[I];
9118 break;
9119 }
Mike Stump1eb44332009-09-09 15:08:12 +00009120
Eli Friedman01f276d2012-01-25 23:20:27 +00009121 // Note that we can return a VariableArrayType here in the case where
9122 // the element type was a dependent VariableArrayType.
9123 IntegerLiteral *ArraySize
9124 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9125 /*FIXME*/BracketsRange.getBegin());
9126 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009127 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00009128 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009129}
Mike Stump1eb44332009-09-09 15:08:12 +00009130
Douglas Gregor577f75a2009-08-04 16:50:30 +00009131template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009132QualType
9133TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009134 ArrayType::ArraySizeModifier SizeMod,
9135 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00009136 unsigned IndexTypeQuals,
9137 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009138 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00009139 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009140}
9141
9142template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009143QualType
Mike Stump1eb44332009-09-09 15:08:12 +00009144TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009145 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00009146 unsigned IndexTypeQuals,
9147 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009148 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00009149 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009150}
Mike Stump1eb44332009-09-09 15:08:12 +00009151
Douglas Gregor577f75a2009-08-04 16:50:30 +00009152template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009153QualType
9154TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009155 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009156 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009157 unsigned IndexTypeQuals,
9158 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009159 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009160 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009161 IndexTypeQuals, BracketsRange);
9162}
9163
9164template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009165QualType
9166TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009167 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009168 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009169 unsigned IndexTypeQuals,
9170 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009171 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009172 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009173 IndexTypeQuals, BracketsRange);
9174}
9175
9176template<typename Derived>
9177QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00009178 unsigned NumElements,
9179 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00009180 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00009181 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009182}
Mike Stump1eb44332009-09-09 15:08:12 +00009183
Douglas Gregor577f75a2009-08-04 16:50:30 +00009184template<typename Derived>
9185QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9186 unsigned NumElements,
9187 SourceLocation AttributeLoc) {
9188 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9189 NumElements, true);
9190 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00009191 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9192 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00009193 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009194}
Mike Stump1eb44332009-09-09 15:08:12 +00009195
Douglas Gregor577f75a2009-08-04 16:50:30 +00009196template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009197QualType
9198TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00009199 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009200 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00009201 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009202}
Mike Stump1eb44332009-09-09 15:08:12 +00009203
Douglas Gregor577f75a2009-08-04 16:50:30 +00009204template<typename Derived>
Jordan Rosebea522f2013-03-08 21:51:21 +00009205QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9206 QualType T,
9207 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00009208 const FunctionProtoType::ExtProtoInfo &EPI) {
9209 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009210 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00009211 getDerived().getBaseEntity(),
Jordan Rose09189892013-03-08 22:25:36 +00009212 EPI);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009213}
Mike Stump1eb44332009-09-09 15:08:12 +00009214
Douglas Gregor577f75a2009-08-04 16:50:30 +00009215template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00009216QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9217 return SemaRef.Context.getFunctionNoProtoType(T);
9218}
9219
9220template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00009221QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9222 assert(D && "no decl found");
9223 if (D->isInvalidDecl()) return QualType();
9224
Douglas Gregor92e986e2010-04-22 16:44:27 +00009225 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00009226 TypeDecl *Ty;
9227 if (isa<UsingDecl>(D)) {
9228 UsingDecl *Using = cast<UsingDecl>(D);
9229 assert(Using->isTypeName() &&
9230 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9231
9232 // A valid resolved using typename decl points to exactly one type decl.
9233 assert(++Using->shadow_begin() == Using->shadow_end());
9234 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009235
John McCalled976492009-12-04 22:46:56 +00009236 } else {
9237 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9238 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9239 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9240 }
9241
9242 return SemaRef.Context.getTypeDeclType(Ty);
9243}
9244
9245template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009246QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9247 SourceLocation Loc) {
9248 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009249}
9250
9251template<typename Derived>
9252QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9253 return SemaRef.Context.getTypeOfType(Underlying);
9254}
9255
9256template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009257QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9258 SourceLocation Loc) {
9259 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009260}
9261
9262template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009263QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9264 UnaryTransformType::UTTKind UKind,
9265 SourceLocation Loc) {
9266 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9267}
9268
9269template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009270QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009271 TemplateName Template,
9272 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009273 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009274 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009275}
Mike Stump1eb44332009-09-09 15:08:12 +00009276
Douglas Gregordcee1a12009-08-06 05:28:30 +00009277template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009278QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9279 SourceLocation KWLoc) {
9280 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9281}
9282
9283template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009284TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009285TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009286 bool TemplateKW,
9287 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009288 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009289 Template);
9290}
9291
9292template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009293TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009294TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9295 const IdentifierInfo &Name,
9296 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009297 QualType ObjectType,
9298 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009299 UnqualifiedId TemplateName;
9300 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009301 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009302 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009303 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009304 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009305 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009306 /*EnteringContext=*/false,
9307 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009308 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009309}
Mike Stump1eb44332009-09-09 15:08:12 +00009310
Douglas Gregorb98b1992009-08-11 05:31:07 +00009311template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009312TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009313TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009314 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009315 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009316 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009317 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009318 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009319 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009320 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009321 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009322 Sema::TemplateTy Template;
9323 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009324 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009325 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009326 /*EnteringContext=*/false,
9327 Template);
9328 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009329}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009330
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009331template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009332ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009333TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9334 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009335 Expr *OrigCallee,
9336 Expr *First,
9337 Expr *Second) {
9338 Expr *Callee = OrigCallee->IgnoreParenCasts();
9339 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009340
Douglas Gregorb98b1992009-08-11 05:31:07 +00009341 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009342 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009343 if (!First->getType()->isOverloadableType() &&
9344 !Second->getType()->isOverloadableType())
9345 return getSema().CreateBuiltinArraySubscriptExpr(First,
9346 Callee->getLocStart(),
9347 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009348 } else if (Op == OO_Arrow) {
9349 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009350 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9351 } else if (Second == 0 || isPostIncDec) {
9352 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009353 // The argument is not of overloadable type, so try to create a
9354 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009355 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009356 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009357
John McCall9ae2f072010-08-23 23:25:46 +00009358 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009359 }
9360 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009361 if (!First->getType()->isOverloadableType() &&
9362 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009363 // Neither of the arguments is an overloadable type, so try to
9364 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009365 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009366 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009367 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009368 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009369 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009370
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009371 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009372 }
9373 }
Mike Stump1eb44332009-09-09 15:08:12 +00009374
9375 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009376 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009377 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009378
John McCall9ae2f072010-08-23 23:25:46 +00009379 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009380 assert(ULE->requiresADL());
9381
9382 // FIXME: Do we have to check
9383 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009384 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009385 } else {
Richard Smithf6411662012-11-28 21:47:39 +00009386 // If we've resolved this to a particular non-member function, just call
9387 // that function. If we resolved it to a member function,
9388 // CreateOverloaded* will find that function for us.
9389 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9390 if (!isa<CXXMethodDecl>(ND))
9391 Functions.addDecl(ND);
John McCallba135432009-11-21 08:51:07 +00009392 }
Mike Stump1eb44332009-09-09 15:08:12 +00009393
Douglas Gregorb98b1992009-08-11 05:31:07 +00009394 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009395 Expr *Args[2] = { First, Second };
9396 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009397
Douglas Gregorb98b1992009-08-11 05:31:07 +00009398 // Create the overloaded operator invocation for unary operators.
9399 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009400 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009401 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009402 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009403 }
Mike Stump1eb44332009-09-09 15:08:12 +00009404
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009405 if (Op == OO_Subscript) {
9406 SourceLocation LBrace;
9407 SourceLocation RBrace;
9408
9409 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9410 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9411 LBrace = SourceLocation::getFromRawEncoding(
9412 NameLoc.CXXOperatorName.BeginOpNameLoc);
9413 RBrace = SourceLocation::getFromRawEncoding(
9414 NameLoc.CXXOperatorName.EndOpNameLoc);
9415 } else {
9416 LBrace = Callee->getLocStart();
9417 RBrace = OpLoc;
9418 }
9419
9420 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9421 First, Second);
9422 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009423
Douglas Gregorb98b1992009-08-11 05:31:07 +00009424 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009425 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009426 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009427 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9428 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009429 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009430
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009431 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009432}
Mike Stump1eb44332009-09-09 15:08:12 +00009433
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009434template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00009435ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009436TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009437 SourceLocation OperatorLoc,
9438 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009439 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009440 TypeSourceInfo *ScopeType,
9441 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009442 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009443 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009444 QualType BaseType = Base->getType();
9445 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009446 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00009447 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009448 !BaseType->getAs<PointerType>()->getPointeeType()
9449 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009450 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009451 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009452 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009453 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009454 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009455 /*FIXME?*/true);
9456 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009457
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009458 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009459 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9460 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9461 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9462 NameInfo.setNamedTypeInfo(DestroyedType);
9463
Richard Smith6314db92012-05-15 06:15:11 +00009464 // The scope type is now known to be a valid nested name specifier
9465 // component. Tack it on to the end of the nested name specifier.
9466 if (ScopeType)
9467 SS.Extend(SemaRef.Context, SourceLocation(),
9468 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnara25777432010-08-11 22:01:17 +00009469
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009470 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009471 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009472 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009473 SS, TemplateKWLoc,
9474 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009475 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009476 /*TemplateArgs*/ 0);
9477}
9478
Tareq A. Siraj051303c2013-04-16 18:53:08 +00009479template<typename Derived>
9480StmtResult
9481TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan9fd6b8f2013-05-04 03:59:06 +00009482 SourceLocation Loc = S->getLocStart();
9483 unsigned NumParams = S->getCapturedDecl()->getNumParams();
9484 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/0,
9485 S->getCapturedRegionKind(), NumParams);
9486 StmtResult Body = getDerived().TransformStmt(S->getCapturedStmt());
9487
9488 if (Body.isInvalid()) {
9489 getSema().ActOnCapturedRegionError();
9490 return StmtError();
9491 }
9492
9493 return getSema().ActOnCapturedRegionEnd(Body.take());
Tareq A. Siraj051303c2013-04-16 18:53:08 +00009494}
9495
Douglas Gregor577f75a2009-08-04 16:50:30 +00009496} // end namespace clang
9497
9498#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H