blob: fda154820a177b0ccf65084a4dd40ce2605bf822 [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,
1193 ArrayRef<Token> AsmToks, SourceLocation EndLoc) {
Chad Rosier7bd092b2012-08-15 16:53:30 +00001194 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, EndLoc);
Chad Rosier8cd64b42012-06-11 20:47:18 +00001195 }
1196
James Dennett699c9042012-06-15 07:13:21 +00001197 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001198 ///
1199 /// By default, performs semantic analysis to build the new statement.
1200 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001201 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001202 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001203 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001204 Stmt *Finally) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001205 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001206 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001207 }
1208
Douglas Gregorbe270a02010-04-26 17:57:08 +00001209 /// \brief Rebuild an Objective-C exception declaration.
1210 ///
1211 /// By default, performs semantic analysis to build the new declaration.
1212 /// Subclasses may override this routine to provide different behavior.
1213 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1214 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001215 return getSema().BuildObjCExceptionDecl(TInfo, T,
1216 ExceptionDecl->getInnerLocStart(),
1217 ExceptionDecl->getLocation(),
1218 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001219 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001220
James Dennett699c9042012-06-15 07:13:21 +00001221 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorbe270a02010-04-26 17:57:08 +00001222 ///
1223 /// By default, performs semantic analysis to build the new statement.
1224 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001225 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001226 SourceLocation RParenLoc,
1227 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001228 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001229 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001230 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001231 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001232
James Dennett699c9042012-06-15 07:13:21 +00001233 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001234 ///
1235 /// By default, performs semantic analysis to build the new statement.
1236 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001237 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001238 Stmt *Body) {
1239 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001240 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001241
James Dennett699c9042012-06-15 07:13:21 +00001242 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001243 ///
1244 /// By default, performs semantic analysis to build the new statement.
1245 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001246 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001247 Expr *Operand) {
1248 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001249 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001250
James Dennett699c9042012-06-15 07:13:21 +00001251 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCall07524032011-07-27 21:50:02 +00001252 ///
1253 /// By default, performs semantic analysis to build the new statement.
1254 /// Subclasses may override this routine to provide different behavior.
1255 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1256 Expr *object) {
1257 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1258 }
1259
James Dennett699c9042012-06-15 07:13:21 +00001260 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001261 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001262 /// By default, performs semantic analysis to build the new statement.
1263 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001264 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall07524032011-07-27 21:50:02 +00001265 Expr *Object, Stmt *Body) {
1266 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001267 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001268
James Dennett699c9042012-06-15 07:13:21 +00001269 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCallf85e1932011-06-15 23:02:42 +00001270 ///
1271 /// By default, performs semantic analysis to build the new statement.
1272 /// Subclasses may override this routine to provide different behavior.
1273 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1274 Stmt *Body) {
1275 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1276 }
John McCall990567c2011-07-27 01:07:15 +00001277
Douglas Gregorc3203e72010-04-22 23:10:45 +00001278 /// \brief Build a new Objective-C fast enumeration statement.
1279 ///
1280 /// By default, performs semantic analysis to build the new statement.
1281 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001282 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001283 Stmt *Element,
1284 Expr *Collection,
1285 SourceLocation RParenLoc,
1286 Stmt *Body) {
Sam Panzerbc20bbb2012-08-16 21:47:25 +00001287 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001288 Element,
John McCall9ae2f072010-08-23 23:25:46 +00001289 Collection,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001290 RParenLoc);
1291 if (ForEachStmt.isInvalid())
1292 return StmtError();
1293
1294 return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001295 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001296
Douglas Gregor43959a92009-08-20 07:17:43 +00001297 /// \brief Build a new C++ exception declaration.
1298 ///
1299 /// By default, performs semantic analysis to build the new decaration.
1300 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001301 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001302 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001303 SourceLocation StartLoc,
1304 SourceLocation IdLoc,
1305 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001306 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1307 StartLoc, IdLoc, Id);
1308 if (Var)
1309 getSema().CurContext->addDecl(Var);
1310 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001311 }
1312
1313 /// \brief Build a new C++ catch statement.
1314 ///
1315 /// By default, performs semantic analysis to build the new statement.
1316 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001317 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001318 VarDecl *ExceptionDecl,
1319 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001320 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1321 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001322 }
Mike Stump1eb44332009-09-09 15:08:12 +00001323
Douglas Gregor43959a92009-08-20 07:17:43 +00001324 /// \brief Build a new C++ try statement.
1325 ///
1326 /// By default, performs semantic analysis to build the new statement.
1327 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001328 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001329 Stmt *TryBlock,
1330 MultiStmtArg Handlers) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001331 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00001332 }
Mike Stump1eb44332009-09-09 15:08:12 +00001333
Richard Smithad762fc2011-04-14 22:09:26 +00001334 /// \brief Build a new C++0x range-based for statement.
1335 ///
1336 /// By default, performs semantic analysis to build the new statement.
1337 /// Subclasses may override this routine to provide different behavior.
1338 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1339 SourceLocation ColonLoc,
1340 Stmt *Range, Stmt *BeginEnd,
1341 Expr *Cond, Expr *Inc,
1342 Stmt *LoopVar,
1343 SourceLocation RParenLoc) {
Douglas Gregor6f96f4b2013-04-08 18:40:13 +00001344 // If we've just learned that the range is actually an Objective-C
1345 // collection, treat this as an Objective-C fast enumeration loop.
1346 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1347 if (RangeStmt->isSingleDecl()) {
1348 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39b60dc2013-05-02 18:35:56 +00001349 if (RangeVar->isInvalidDecl())
1350 return StmtError();
1351
Douglas Gregor6f96f4b2013-04-08 18:40:13 +00001352 Expr *RangeExpr = RangeVar->getInit();
1353 if (!RangeExpr->isTypeDependent() &&
1354 RangeExpr->getType()->isObjCObjectPointerType())
1355 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1356 RParenLoc);
1357 }
1358 }
1359 }
1360
Richard Smithad762fc2011-04-14 22:09:26 +00001361 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smith8b533d92012-09-20 21:52:32 +00001362 Cond, Inc, LoopVar, RParenLoc,
1363 Sema::BFRK_Rebuild);
Richard Smithad762fc2011-04-14 22:09:26 +00001364 }
Douglas Gregorba0513d2011-10-25 01:33:02 +00001365
1366 /// \brief Build a new C++0x range-based for statement.
1367 ///
1368 /// By default, performs semantic analysis to build the new statement.
1369 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001370 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregorba0513d2011-10-25 01:33:02 +00001371 bool IsIfExists,
1372 NestedNameSpecifierLoc QualifierLoc,
1373 DeclarationNameInfo NameInfo,
1374 Stmt *Nested) {
1375 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1376 QualifierLoc, NameInfo, Nested);
1377 }
1378
Richard Smithad762fc2011-04-14 22:09:26 +00001379 /// \brief Attach body to a C++0x range-based for statement.
1380 ///
1381 /// By default, performs semantic analysis to finish the new statement.
1382 /// Subclasses may override this routine to provide different behavior.
1383 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1384 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1385 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001386
John Wiegley28bbe4b2011-04-28 01:08:34 +00001387 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1388 SourceLocation TryLoc,
1389 Stmt *TryBlock,
1390 Stmt *Handler) {
1391 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1392 }
1393
1394 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1395 Expr *FilterExpr,
1396 Stmt *Block) {
1397 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1398 }
1399
1400 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1401 Stmt *Block) {
1402 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1403 }
1404
Douglas Gregorb98b1992009-08-11 05:31:07 +00001405 /// \brief Build a new expression that references a declaration.
1406 ///
1407 /// By default, performs semantic analysis to build the new expression.
1408 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001409 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001410 LookupResult &R,
1411 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001412 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1413 }
1414
1415
1416 /// \brief Build a new expression that references a declaration.
1417 ///
1418 /// By default, performs semantic analysis to build the new expression.
1419 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001420 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001421 ValueDecl *VD,
1422 const DeclarationNameInfo &NameInfo,
1423 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001424 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001425 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001426
1427 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001428
1429 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001430 }
Mike Stump1eb44332009-09-09 15:08:12 +00001431
Douglas Gregorb98b1992009-08-11 05:31:07 +00001432 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001433 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001434 /// By default, performs semantic analysis to build the new expression.
1435 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001436 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001437 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001438 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001439 }
1440
Douglas Gregora71d8192009-09-04 17:36:40 +00001441 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001442 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001443 /// By default, performs semantic analysis to build the new expression.
1444 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001445 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001446 SourceLocation OperatorLoc,
1447 bool isArrow,
1448 CXXScopeSpec &SS,
1449 TypeSourceInfo *ScopeType,
1450 SourceLocation CCLoc,
1451 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001452 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001453
Douglas Gregorb98b1992009-08-11 05:31:07 +00001454 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001455 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001456 /// By default, performs semantic analysis to build the new expression.
1457 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001458 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001459 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001460 Expr *SubExpr) {
1461 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001462 }
Mike Stump1eb44332009-09-09 15:08:12 +00001463
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001464 /// \brief Build a new builtin offsetof expression.
1465 ///
1466 /// By default, performs semantic analysis to build the new expression.
1467 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001468 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001469 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001470 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001471 unsigned NumComponents,
1472 SourceLocation RParenLoc) {
1473 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1474 NumComponents, RParenLoc);
1475 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001476
1477 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001478 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001479 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001480 /// By default, performs semantic analysis to build the new expression.
1481 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001482 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1483 SourceLocation OpLoc,
1484 UnaryExprOrTypeTrait ExprKind,
1485 SourceRange R) {
1486 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001487 }
1488
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001489 /// \brief Build a new sizeof, alignof or vec step expression with an
1490 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001491 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001492 /// By default, performs semantic analysis to build the new expression.
1493 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001494 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1495 UnaryExprOrTypeTrait ExprKind,
1496 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001497 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001498 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001499 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001500 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001501
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001502 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001503 }
Mike Stump1eb44332009-09-09 15:08:12 +00001504
Douglas Gregorb98b1992009-08-11 05:31:07 +00001505 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001506 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001507 /// By default, performs semantic analysis to build the new expression.
1508 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001509 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001510 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001511 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001512 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001513 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1514 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001515 RBracketLoc);
1516 }
1517
1518 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001519 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001520 /// By default, performs semantic analysis to build the new expression.
1521 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001522 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001523 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001524 SourceLocation RParenLoc,
1525 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001526 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001527 Args, RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001528 }
1529
1530 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001531 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001532 /// By default, performs semantic analysis to build the new expression.
1533 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001534 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001535 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001536 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001537 SourceLocation TemplateKWLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001538 const DeclarationNameInfo &MemberNameInfo,
1539 ValueDecl *Member,
1540 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001541 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001542 NamedDecl *FirstQualifierInScope) {
Richard Smith9138b4e2011-10-26 19:06:56 +00001543 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1544 isArrow);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001545 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001546 // We have a reference to an unnamed field. This is always the
1547 // base of an anonymous struct/union member access, i.e. the
1548 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001549 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001550 assert(Member->getType()->isRecordType() &&
1551 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001552
Richard Smith9138b4e2011-10-26 19:06:56 +00001553 BaseResult =
1554 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley429bb272011-04-08 18:41:53 +00001555 QualifierLoc.getNestedNameSpecifier(),
1556 FoundDecl, Member);
1557 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001558 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001559 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001560 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001561 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001562 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001563 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001564 cast<FieldDecl>(Member)->getType(),
1565 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001566 return getSema().Owned(ME);
1567 }
Mike Stump1eb44332009-09-09 15:08:12 +00001568
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001569 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001570 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001571
John Wiegley429bb272011-04-08 18:41:53 +00001572 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001573 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001574
John McCall6bb80172010-03-30 21:47:33 +00001575 // FIXME: this involves duplicating earlier analysis in a lot of
1576 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001577 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001578 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001579 R.resolveKind();
1580
John McCall9ae2f072010-08-23 23:25:46 +00001581 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001582 SS, TemplateKWLoc,
1583 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001584 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001585 }
Mike Stump1eb44332009-09-09 15:08:12 +00001586
Douglas Gregorb98b1992009-08-11 05:31:07 +00001587 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001588 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001589 /// By default, performs semantic analysis to build the new expression.
1590 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001591 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001592 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001593 Expr *LHS, Expr *RHS) {
1594 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001595 }
1596
1597 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001598 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001599 /// By default, performs semantic analysis to build the new expression.
1600 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001601 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001602 SourceLocation QuestionLoc,
1603 Expr *LHS,
1604 SourceLocation ColonLoc,
1605 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001606 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1607 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001608 }
1609
Douglas Gregorb98b1992009-08-11 05:31:07 +00001610 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001611 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001612 /// By default, performs semantic analysis to build the new expression.
1613 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001614 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001615 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001616 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001617 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001618 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001619 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001620 }
Mike Stump1eb44332009-09-09 15:08:12 +00001621
Douglas Gregorb98b1992009-08-11 05:31:07 +00001622 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001623 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001624 /// By default, performs semantic analysis to build the new expression.
1625 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001626 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001627 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001628 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001629 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001630 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001631 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001632 }
Mike Stump1eb44332009-09-09 15:08:12 +00001633
Douglas Gregorb98b1992009-08-11 05:31:07 +00001634 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001635 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001636 /// By default, performs semantic analysis to build the new expression.
1637 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001638 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001639 SourceLocation OpLoc,
1640 SourceLocation AccessorLoc,
1641 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001642
John McCall129e2df2009-11-30 22:42:35 +00001643 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001644 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001645 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001646 OpLoc, /*IsArrow*/ false,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001647 SS, SourceLocation(),
1648 /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001649 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001650 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001651 }
Mike Stump1eb44332009-09-09 15:08:12 +00001652
Douglas Gregorb98b1992009-08-11 05:31:07 +00001653 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001654 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001655 /// By default, performs semantic analysis to build the new expression.
1656 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001657 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001658 MultiExprArg Inits,
1659 SourceLocation RBraceLoc,
1660 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001661 ExprResult Result
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001662 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregore48319a2009-11-09 17:16:50 +00001663 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001664 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00001665
Douglas Gregore48319a2009-11-09 17:16:50 +00001666 // Patch in the result type we were given, which may have been computed
1667 // when the initial InitListExpr was built.
1668 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1669 ILE->setType(ResultTy);
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001670 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001671 }
Mike Stump1eb44332009-09-09 15:08:12 +00001672
Douglas Gregorb98b1992009-08-11 05:31:07 +00001673 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001674 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001675 /// By default, performs semantic analysis to build the new expression.
1676 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001677 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001678 MultiExprArg ArrayExprs,
1679 SourceLocation EqualOrColonLoc,
1680 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001681 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001682 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001683 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001684 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001685 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001686 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001687
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001688 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001689 }
Mike Stump1eb44332009-09-09 15:08:12 +00001690
Douglas Gregorb98b1992009-08-11 05:31:07 +00001691 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001692 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001693 /// By default, builds the implicit value initialization without performing
1694 /// any semantic analysis. Subclasses may override this routine to provide
1695 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001696 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001697 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1698 }
Mike Stump1eb44332009-09-09 15:08:12 +00001699
Douglas Gregorb98b1992009-08-11 05:31:07 +00001700 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001701 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001702 /// By default, performs semantic analysis to build the new expression.
1703 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001704 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001705 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001706 SourceLocation RParenLoc) {
1707 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001708 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001709 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001710 }
1711
1712 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001713 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001714 /// By default, performs semantic analysis to build the new expression.
1715 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001716 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +00001717 MultiExprArg SubExprs,
1718 SourceLocation RParenLoc) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001719 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001720 }
Mike Stump1eb44332009-09-09 15:08:12 +00001721
Douglas Gregorb98b1992009-08-11 05:31:07 +00001722 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001723 ///
1724 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001725 /// rather than attempting to map the label statement itself.
1726 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001727 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001728 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001729 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001730 }
Mike Stump1eb44332009-09-09 15:08:12 +00001731
Douglas Gregorb98b1992009-08-11 05:31:07 +00001732 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001733 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001734 /// By default, performs semantic analysis to build the new expression.
1735 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001736 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001737 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001738 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001739 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001740 }
Mike Stump1eb44332009-09-09 15:08:12 +00001741
Douglas Gregorb98b1992009-08-11 05:31:07 +00001742 /// \brief Build a new __builtin_choose_expr expression.
1743 ///
1744 /// By default, performs semantic analysis to build the new expression.
1745 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001746 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001747 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001748 SourceLocation RParenLoc) {
1749 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001750 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001751 RParenLoc);
1752 }
Mike Stump1eb44332009-09-09 15:08:12 +00001753
Peter Collingbournef111d932011-04-15 00:35:48 +00001754 /// \brief Build a new generic selection expression.
1755 ///
1756 /// By default, performs semantic analysis to build the new expression.
1757 /// Subclasses may override this routine to provide different behavior.
1758 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1759 SourceLocation DefaultLoc,
1760 SourceLocation RParenLoc,
1761 Expr *ControllingExpr,
1762 TypeSourceInfo **Types,
1763 Expr **Exprs,
1764 unsigned NumAssocs) {
1765 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1766 ControllingExpr, Types, Exprs,
1767 NumAssocs);
1768 }
1769
Douglas Gregorb98b1992009-08-11 05:31:07 +00001770 /// \brief Build a new overloaded operator call expression.
1771 ///
1772 /// By default, performs semantic analysis to build the new expression.
1773 /// The semantic analysis provides the behavior of template instantiation,
1774 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001775 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001776 /// argument-dependent lookup, etc. Subclasses may override this routine to
1777 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001778 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001779 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001780 Expr *Callee,
1781 Expr *First,
1782 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001783
1784 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001785 /// reinterpret_cast.
1786 ///
1787 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001788 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001789 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001790 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001791 Stmt::StmtClass Class,
1792 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001793 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001794 SourceLocation RAngleLoc,
1795 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001796 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001797 SourceLocation RParenLoc) {
1798 switch (Class) {
1799 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001800 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001801 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001802 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001803
1804 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001805 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001806 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001807 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001808
Douglas Gregorb98b1992009-08-11 05:31:07 +00001809 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001810 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001811 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001812 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001813 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001814
Douglas Gregorb98b1992009-08-11 05:31:07 +00001815 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001816 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001817 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001818 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001819
Douglas Gregorb98b1992009-08-11 05:31:07 +00001820 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001821 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001822 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001823 }
Mike Stump1eb44332009-09-09 15:08:12 +00001824
Douglas Gregorb98b1992009-08-11 05:31:07 +00001825 /// \brief Build a new C++ static_cast expression.
1826 ///
1827 /// By default, performs semantic analysis to build the new expression.
1828 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001829 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001830 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001831 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001832 SourceLocation RAngleLoc,
1833 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001834 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001835 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001836 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001837 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001838 SourceRange(LAngleLoc, RAngleLoc),
1839 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001840 }
1841
1842 /// \brief Build a new C++ dynamic_cast expression.
1843 ///
1844 /// By default, performs semantic analysis to build the new expression.
1845 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001846 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001847 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001848 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001849 SourceLocation RAngleLoc,
1850 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001851 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001852 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001853 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001854 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001855 SourceRange(LAngleLoc, RAngleLoc),
1856 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001857 }
1858
1859 /// \brief Build a new C++ reinterpret_cast expression.
1860 ///
1861 /// By default, performs semantic analysis to build the new expression.
1862 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001863 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001864 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001865 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001866 SourceLocation RAngleLoc,
1867 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001868 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001869 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001870 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001871 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001872 SourceRange(LAngleLoc, RAngleLoc),
1873 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001874 }
1875
1876 /// \brief Build a new C++ const_cast expression.
1877 ///
1878 /// By default, performs semantic analysis to build the new expression.
1879 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001880 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001881 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001882 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001883 SourceLocation RAngleLoc,
1884 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001885 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001886 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001887 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001888 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001889 SourceRange(LAngleLoc, RAngleLoc),
1890 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001891 }
Mike Stump1eb44332009-09-09 15:08:12 +00001892
Douglas Gregorb98b1992009-08-11 05:31:07 +00001893 /// \brief Build a new C++ functional-style cast expression.
1894 ///
1895 /// By default, performs semantic analysis to build the new expression.
1896 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001897 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1898 SourceLocation LParenLoc,
1899 Expr *Sub,
1900 SourceLocation RParenLoc) {
1901 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001902 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001903 RParenLoc);
1904 }
Mike Stump1eb44332009-09-09 15:08:12 +00001905
Douglas Gregorb98b1992009-08-11 05:31:07 +00001906 /// \brief Build a new C++ typeid(type) expression.
1907 ///
1908 /// By default, performs semantic analysis to build the new expression.
1909 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001910 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001911 SourceLocation TypeidLoc,
1912 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001913 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001914 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001915 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001916 }
Mike Stump1eb44332009-09-09 15:08:12 +00001917
Francois Pichet01b7c302010-09-08 12:20:18 +00001918
Douglas Gregorb98b1992009-08-11 05:31:07 +00001919 /// \brief Build a new C++ typeid(expr) expression.
1920 ///
1921 /// By default, performs semantic analysis to build the new expression.
1922 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001923 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001924 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001925 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001926 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001927 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001928 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001929 }
1930
Francois Pichet01b7c302010-09-08 12:20:18 +00001931 /// \brief Build a new C++ __uuidof(type) expression.
1932 ///
1933 /// By default, performs semantic analysis to build the new expression.
1934 /// Subclasses may override this routine to provide different behavior.
1935 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1936 SourceLocation TypeidLoc,
1937 TypeSourceInfo *Operand,
1938 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001939 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet01b7c302010-09-08 12:20:18 +00001940 RParenLoc);
1941 }
1942
1943 /// \brief Build a new C++ __uuidof(expr) expression.
1944 ///
1945 /// By default, performs semantic analysis to build the new expression.
1946 /// Subclasses may override this routine to provide different behavior.
1947 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1948 SourceLocation TypeidLoc,
1949 Expr *Operand,
1950 SourceLocation RParenLoc) {
1951 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1952 RParenLoc);
1953 }
1954
Douglas Gregorb98b1992009-08-11 05:31:07 +00001955 /// \brief Build a new C++ "this" expression.
1956 ///
1957 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001958 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001959 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001960 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001961 QualType ThisType,
1962 bool isImplicit) {
Eli Friedmanb69b42c2012-01-11 02:36:31 +00001963 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001964 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001965 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1966 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001967 }
1968
1969 /// \brief Build a new C++ throw expression.
1970 ///
1971 /// By default, performs semantic analysis to build the new expression.
1972 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00001973 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1974 bool IsThrownVariableInScope) {
1975 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001976 }
1977
1978 /// \brief Build a new C++ default-argument expression.
1979 ///
1980 /// By default, builds a new default-argument expression, which does not
1981 /// require any semantic analysis. Subclasses may override this routine to
1982 /// provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001983 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001984 ParmVarDecl *Param) {
1985 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1986 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001987 }
1988
Richard Smithc3bf52c2013-04-20 22:23:05 +00001989 /// \brief Build a new C++11 default-initialization expression.
1990 ///
1991 /// By default, builds a new default field initialization expression, which
1992 /// does not require any semantic analysis. Subclasses may override this
1993 /// routine to provide different behavior.
1994 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
1995 FieldDecl *Field) {
1996 return getSema().Owned(CXXDefaultInitExpr::Create(getSema().Context, Loc,
1997 Field));
1998 }
1999
Douglas Gregorb98b1992009-08-11 05:31:07 +00002000 /// \brief Build a new C++ zero-initialization expression.
2001 ///
2002 /// By default, performs semantic analysis to build the new expression.
2003 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002004 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2005 SourceLocation LParenLoc,
2006 SourceLocation RParenLoc) {
2007 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Benjamin Kramer5354e772012-08-23 23:38:35 +00002008 MultiExprArg(), RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002009 }
Mike Stump1eb44332009-09-09 15:08:12 +00002010
Douglas Gregorb98b1992009-08-11 05:31:07 +00002011 /// \brief Build a new C++ "new" expression.
2012 ///
2013 /// By default, performs semantic analysis to build the new expression.
2014 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002015 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002016 bool UseGlobal,
2017 SourceLocation PlacementLParen,
2018 MultiExprArg PlacementArgs,
2019 SourceLocation PlacementRParen,
2020 SourceRange TypeIdParens,
2021 QualType AllocatedType,
2022 TypeSourceInfo *AllocatedTypeInfo,
2023 Expr *ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002024 SourceRange DirectInitRange,
2025 Expr *Initializer) {
Mike Stump1eb44332009-09-09 15:08:12 +00002026 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002027 PlacementLParen,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002028 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002029 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00002030 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002031 AllocatedType,
2032 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00002033 ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002034 DirectInitRange,
2035 Initializer);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002036 }
Mike Stump1eb44332009-09-09 15:08:12 +00002037
Douglas Gregorb98b1992009-08-11 05:31:07 +00002038 /// \brief Build a new C++ "delete" expression.
2039 ///
2040 /// By default, performs semantic analysis to build the new expression.
2041 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002042 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002043 bool IsGlobalDelete,
2044 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002045 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002046 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002047 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002048 }
Mike Stump1eb44332009-09-09 15:08:12 +00002049
Douglas Gregorb98b1992009-08-11 05:31:07 +00002050 /// \brief Build a new unary type trait expression.
2051 ///
2052 /// By default, performs semantic analysis to build the new expression.
2053 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002054 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00002055 SourceLocation StartLoc,
2056 TypeSourceInfo *T,
2057 SourceLocation RParenLoc) {
2058 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002059 }
2060
Francois Pichet6ad6f282010-12-07 00:08:36 +00002061 /// \brief Build a new binary type trait expression.
2062 ///
2063 /// By default, performs semantic analysis to build the new expression.
2064 /// Subclasses may override this routine to provide different behavior.
2065 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
2066 SourceLocation StartLoc,
2067 TypeSourceInfo *LhsT,
2068 TypeSourceInfo *RhsT,
2069 SourceLocation RParenLoc) {
2070 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
2071 }
2072
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00002073 /// \brief Build a new type trait expression.
2074 ///
2075 /// By default, performs semantic analysis to build the new expression.
2076 /// Subclasses may override this routine to provide different behavior.
2077 ExprResult RebuildTypeTrait(TypeTrait Trait,
2078 SourceLocation StartLoc,
2079 ArrayRef<TypeSourceInfo *> Args,
2080 SourceLocation RParenLoc) {
2081 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2082 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002083
John Wiegley21ff2e52011-04-28 00:16:57 +00002084 /// \brief Build a new array type trait expression.
2085 ///
2086 /// By default, performs semantic analysis to build the new expression.
2087 /// Subclasses may override this routine to provide different behavior.
2088 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2089 SourceLocation StartLoc,
2090 TypeSourceInfo *TSInfo,
2091 Expr *DimExpr,
2092 SourceLocation RParenLoc) {
2093 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2094 }
2095
John Wiegley55262202011-04-25 06:54:41 +00002096 /// \brief Build a new expression trait expression.
2097 ///
2098 /// By default, performs semantic analysis to build the new expression.
2099 /// Subclasses may override this routine to provide different behavior.
2100 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2101 SourceLocation StartLoc,
2102 Expr *Queried,
2103 SourceLocation RParenLoc) {
2104 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2105 }
2106
Mike Stump1eb44332009-09-09 15:08:12 +00002107 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002108 /// expression.
2109 ///
2110 /// By default, performs semantic analysis to build the new expression.
2111 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002112 ExprResult RebuildDependentScopeDeclRefExpr(
2113 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002114 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002115 const DeclarationNameInfo &NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00002116 const TemplateArgumentListInfo *TemplateArgs,
2117 bool IsAddressOfOperand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002118 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002119 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002120
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002121 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002122 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002123 NameInfo, TemplateArgs);
John McCallf7a1a742009-11-24 19:00:30 +00002124
Richard Smithefeeccf2012-10-21 03:28:35 +00002125 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo,
2126 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002127 }
2128
2129 /// \brief Build a new template-id expression.
2130 ///
2131 /// By default, performs semantic analysis to build the new expression.
2132 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002133 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002134 SourceLocation TemplateKWLoc,
2135 LookupResult &R,
2136 bool RequiresADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002137 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002138 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2139 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002140 }
2141
2142 /// \brief Build a new object-construction expression.
2143 ///
2144 /// By default, performs semantic analysis to build the new expression.
2145 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002146 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002147 SourceLocation Loc,
2148 CXXConstructorDecl *Constructor,
2149 bool IsElidable,
2150 MultiExprArg Args,
2151 bool HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002152 bool ListInitialization,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002153 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002154 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002155 SourceRange ParenRange) {
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00002156 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002157 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002158 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002159 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002160
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002161 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002162 ConvertedArgs,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002163 HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002164 ListInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002165 RequiresZeroInit, ConstructKind,
2166 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002167 }
2168
2169 /// \brief Build a new object-construction expression.
2170 ///
2171 /// By default, performs semantic analysis to build the new expression.
2172 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002173 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2174 SourceLocation LParenLoc,
2175 MultiExprArg Args,
2176 SourceLocation RParenLoc) {
2177 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002178 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002179 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002180 RParenLoc);
2181 }
2182
2183 /// \brief Build a new object-construction expression.
2184 ///
2185 /// By default, performs semantic analysis to build the new expression.
2186 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002187 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2188 SourceLocation LParenLoc,
2189 MultiExprArg Args,
2190 SourceLocation RParenLoc) {
2191 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002192 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002193 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002194 RParenLoc);
2195 }
Mike Stump1eb44332009-09-09 15:08:12 +00002196
Douglas Gregorb98b1992009-08-11 05:31:07 +00002197 /// \brief Build a new member reference expression.
2198 ///
2199 /// By default, performs semantic analysis to build the new expression.
2200 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002201 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002202 QualType BaseType,
2203 bool IsArrow,
2204 SourceLocation OperatorLoc,
2205 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002206 SourceLocation TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00002207 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002208 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002209 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002210 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002211 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002212
John McCall9ae2f072010-08-23 23:25:46 +00002213 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002214 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002215 SS, TemplateKWLoc,
2216 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002217 MemberNameInfo,
2218 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002219 }
2220
John McCall129e2df2009-11-30 22:42:35 +00002221 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002222 ///
2223 /// By default, performs semantic analysis to build the new expression.
2224 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002225 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2226 SourceLocation OperatorLoc,
2227 bool IsArrow,
2228 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002229 SourceLocation TemplateKWLoc,
Richard Smith9138b4e2011-10-26 19:06:56 +00002230 NamedDecl *FirstQualifierInScope,
2231 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002232 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002233 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002234 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002235
John McCall9ae2f072010-08-23 23:25:46 +00002236 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002237 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002238 SS, TemplateKWLoc,
2239 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00002240 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002241 }
Mike Stump1eb44332009-09-09 15:08:12 +00002242
Sebastian Redl2e156222010-09-10 20:55:43 +00002243 /// \brief Build a new noexcept expression.
2244 ///
2245 /// By default, performs semantic analysis to build the new expression.
2246 /// Subclasses may override this routine to provide different behavior.
2247 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2248 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2249 }
2250
Douglas Gregoree8aff02011-01-04 17:33:58 +00002251 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002252 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2253 SourceLocation PackLoc,
Douglas Gregoree8aff02011-01-04 17:33:58 +00002254 SourceLocation RParenLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002255 Optional<unsigned> Length) {
Douglas Gregor089e8932011-10-10 18:59:29 +00002256 if (Length)
Chad Rosier4a9d7952012-08-08 18:46:20 +00002257 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2258 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002259 RParenLoc, *Length);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002260
2261 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2262 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002263 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002264 }
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002265
Patrick Beardeb382ec2012-04-19 00:25:12 +00002266 /// \brief Build a new Objective-C boxed expression.
2267 ///
2268 /// By default, performs semantic analysis to build the new expression.
2269 /// Subclasses may override this routine to provide different behavior.
2270 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2271 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2272 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002273
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002274 /// \brief Build a new Objective-C array literal.
2275 ///
2276 /// By default, performs semantic analysis to build the new expression.
2277 /// Subclasses may override this routine to provide different behavior.
2278 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2279 Expr **Elements, unsigned NumElements) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002280 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002281 MultiExprArg(Elements, NumElements));
2282 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002283
2284 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002285 Expr *Base, Expr *Key,
2286 ObjCMethodDecl *getterMethod,
2287 ObjCMethodDecl *setterMethod) {
2288 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2289 getterMethod, setterMethod);
2290 }
2291
2292 /// \brief Build a new Objective-C dictionary literal.
2293 ///
2294 /// By default, performs semantic analysis to build the new expression.
2295 /// Subclasses may override this routine to provide different behavior.
2296 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2297 ObjCDictionaryElement *Elements,
2298 unsigned NumElements) {
2299 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2300 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002301
James Dennett699c9042012-06-15 07:13:21 +00002302 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregorb98b1992009-08-11 05:31:07 +00002303 ///
2304 /// By default, performs semantic analysis to build the new expression.
2305 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002306 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002307 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002308 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002309 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002310 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002311 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002312
Douglas Gregor92e986e2010-04-22 16:44:27 +00002313 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002314 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002315 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002316 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002317 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002318 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002319 MultiExprArg Args,
2320 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002321 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2322 ReceiverTypeInfo->getType(),
2323 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002324 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002325 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002326 }
2327
2328 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002329 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002330 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002331 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002332 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002333 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002334 MultiExprArg Args,
2335 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002336 return SemaRef.BuildInstanceMessage(Receiver,
2337 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002338 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002339 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002340 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002341 }
2342
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002343 /// \brief Build a new Objective-C ivar reference expression.
2344 ///
2345 /// By default, performs semantic analysis to build the new expression.
2346 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002347 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002348 SourceLocation IvarLoc,
2349 bool IsArrow, bool IsFreeIvar) {
2350 // FIXME: We lose track of the IsFreeIvar bit.
2351 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002352 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002353 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2354 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002355 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002356 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002357 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002358 false);
John Wiegley429bb272011-04-08 18:41:53 +00002359 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002360 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002361
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002362 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002363 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002364
John Wiegley429bb272011-04-08 18:41:53 +00002365 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002366 /*FIXME:*/IvarLoc, IsArrow,
2367 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002368 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002369 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002370 /*TemplateArgs=*/0);
2371 }
Douglas Gregore3303542010-04-26 20:47:02 +00002372
2373 /// \brief Build a new Objective-C property reference expression.
2374 ///
2375 /// By default, performs semantic analysis to build the new expression.
2376 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002377 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002378 ObjCPropertyDecl *Property,
2379 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002380 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002381 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002382 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2383 Sema::LookupMemberName);
2384 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002385 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002386 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002387 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002388 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002389 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002390
Douglas Gregore3303542010-04-26 20:47:02 +00002391 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002392 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002393
John Wiegley429bb272011-04-08 18:41:53 +00002394 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002395 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002396 SS, SourceLocation(),
Douglas Gregore3303542010-04-26 20:47:02 +00002397 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002398 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002399 /*TemplateArgs=*/0);
2400 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002401
John McCall12f78a62010-12-02 01:19:52 +00002402 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002403 ///
2404 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002405 /// Subclasses may override this routine to provide different behavior.
2406 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2407 ObjCMethodDecl *Getter,
2408 ObjCMethodDecl *Setter,
2409 SourceLocation PropertyLoc) {
2410 // Since these expressions can only be value-dependent, we do not
2411 // need to perform semantic analysis again.
2412 return Owned(
2413 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2414 VK_LValue, OK_ObjCProperty,
2415 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002416 }
2417
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002418 /// \brief Build a new Objective-C "isa" expression.
2419 ///
2420 /// By default, performs semantic analysis to build the new expression.
2421 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002422 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002423 SourceLocation OpLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002424 bool IsArrow) {
2425 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002426 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002427 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2428 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002429 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002430 OpLoc,
John McCalld226f652010-08-21 09:40:31 +00002431 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002432 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002433 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002434
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002435 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002436 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002437
John Wiegley429bb272011-04-08 18:41:53 +00002438 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002439 OpLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002440 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002441 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002442 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002443 /*TemplateArgs=*/0);
2444 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002445
Douglas Gregorb98b1992009-08-11 05:31:07 +00002446 /// \brief Build a new shuffle vector expression.
2447 ///
2448 /// By default, performs semantic analysis to build the new expression.
2449 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002450 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002451 MultiExprArg SubExprs,
2452 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002453 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002454 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002455 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2456 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2457 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikie3bc93e32012-12-19 00:45:41 +00002458 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002459
Douglas Gregorb98b1992009-08-11 05:31:07 +00002460 // Build a reference to the __builtin_shufflevector builtin
David Blaikie3bc93e32012-12-19 00:45:41 +00002461 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002462 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2463 SemaRef.Context.BuiltinFnTy,
2464 VK_RValue, BuiltinLoc);
2465 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2466 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
2467 CK_BuiltinFnToFnPtr).take();
Mike Stump1eb44332009-09-09 15:08:12 +00002468
2469 // Build the CallExpr
John Wiegley429bb272011-04-08 18:41:53 +00002470 ExprResult TheCall = SemaRef.Owned(
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002471 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, SubExprs,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002472 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002473 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002474 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002475
Douglas Gregorb98b1992009-08-11 05:31:07 +00002476 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002477 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002478 }
John McCall43fed0d2010-11-12 08:19:04 +00002479
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002480 /// \brief Build a new template argument pack expansion.
2481 ///
2482 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002483 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002484 /// different behavior.
2485 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002486 SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002487 Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002488 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002489 case TemplateArgument::Expression: {
2490 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002491 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2492 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002493 if (Result.isInvalid())
2494 return TemplateArgumentLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002495
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002496 return TemplateArgumentLoc(Result.get(), Result.get());
2497 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002498
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002499 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002500 return TemplateArgumentLoc(TemplateArgument(
2501 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002502 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002503 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002504 Pattern.getTemplateNameLoc(),
2505 EllipsisLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002506
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002507 case TemplateArgument::Null:
2508 case TemplateArgument::Integral:
2509 case TemplateArgument::Declaration:
2510 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002511 case TemplateArgument::TemplateExpansion:
Eli Friedmand7a6b162012-09-26 02:36:12 +00002512 case TemplateArgument::NullPtr:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002513 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002514
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002515 case TemplateArgument::Type:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002516 if (TypeSourceInfo *Expansion
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002517 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002518 EllipsisLoc,
2519 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002520 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2521 Expansion);
2522 break;
2523 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002524
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002525 return TemplateArgumentLoc();
2526 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002527
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002528 /// \brief Build a new expression pack expansion.
2529 ///
2530 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002531 /// for an expression. Subclasses may override this routine to provide
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002532 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002533 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002534 Optional<unsigned> NumExpansions) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002535 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002536 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002537
2538 /// \brief Build a new atomic operation expression.
2539 ///
2540 /// By default, performs semantic analysis to build the new expression.
2541 /// Subclasses may override this routine to provide different behavior.
2542 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2543 MultiExprArg SubExprs,
2544 QualType RetTy,
2545 AtomicExpr::AtomicOp Op,
2546 SourceLocation RParenLoc) {
2547 // Just create the expression; there is not any interesting semantic
2548 // analysis here because we can't actually build an AtomicExpr until
2549 // we are sure it is semantically sound.
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002550 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002551 RParenLoc);
2552 }
2553
John McCall43fed0d2010-11-12 08:19:04 +00002554private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002555 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2556 QualType ObjectType,
2557 NamedDecl *FirstQualifierInScope,
2558 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002559
2560 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2561 QualType ObjectType,
2562 NamedDecl *FirstQualifierInScope,
2563 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002564};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002565
Douglas Gregor43959a92009-08-20 07:17:43 +00002566template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002567StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002568 if (!S)
2569 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002570
Douglas Gregor43959a92009-08-20 07:17:43 +00002571 switch (S->getStmtClass()) {
2572 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002573
Douglas Gregor43959a92009-08-20 07:17:43 +00002574 // Transform individual statement nodes
2575#define STMT(Node, Parent) \
2576 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002577#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002578#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002579#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002580
Douglas Gregor43959a92009-08-20 07:17:43 +00002581 // Transform expressions by calling TransformExpr.
2582#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002583#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002584#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002585#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002586 {
John McCall60d7b3a2010-08-24 06:29:42 +00002587 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002588 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002589 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002590
Richard Smith41956372013-01-14 22:39:08 +00002591 return getSema().ActOnExprStmt(E);
Douglas Gregor43959a92009-08-20 07:17:43 +00002592 }
Mike Stump1eb44332009-09-09 15:08:12 +00002593 }
2594
John McCall3fa5cae2010-10-26 07:05:15 +00002595 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002596}
Mike Stump1eb44332009-09-09 15:08:12 +00002597
2598
Douglas Gregor670444e2009-08-04 22:27:00 +00002599template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002600ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002601 if (!E)
2602 return SemaRef.Owned(E);
2603
2604 switch (E->getStmtClass()) {
2605 case Stmt::NoStmtClass: break;
2606#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002607#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002608#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002609 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002610#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002611 }
2612
John McCall3fa5cae2010-10-26 07:05:15 +00002613 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002614}
2615
2616template<typename Derived>
Richard Smithc83c2302012-12-19 01:39:02 +00002617ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2618 bool CXXDirectInit) {
2619 // Initializers are instantiated like expressions, except that various outer
2620 // layers are stripped.
2621 if (!Init)
2622 return SemaRef.Owned(Init);
2623
2624 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2625 Init = ExprTemp->getSubExpr();
2626
2627 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2628 Init = Binder->getSubExpr();
2629
2630 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2631 Init = ICE->getSubExprAsWritten();
2632
Richard Smith5cf15892012-12-21 08:13:35 +00002633 // If this is not a direct-initializer, we only need to reconstruct
2634 // InitListExprs. Other forms of copy-initialization will be a no-op if
2635 // the initializer is already the right type.
2636 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2637 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2638 return getDerived().TransformExpr(Init);
2639
2640 // Revert value-initialization back to empty parens.
2641 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2642 SourceRange Parens = VIE->getSourceRange();
2643 return getDerived().RebuildParenListExpr(Parens.getBegin(), MultiExprArg(),
2644 Parens.getEnd());
2645 }
2646
2647 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2648 if (isa<ImplicitValueInitExpr>(Init))
2649 return getDerived().RebuildParenListExpr(SourceLocation(), MultiExprArg(),
2650 SourceLocation());
2651
2652 // Revert initialization by constructor back to a parenthesized or braced list
2653 // of expressions. Any other form of initializer can just be reused directly.
2654 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithc83c2302012-12-19 01:39:02 +00002655 return getDerived().TransformExpr(Init);
2656
2657 SmallVector<Expr*, 8> NewArgs;
2658 bool ArgChanged = false;
2659 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2660 /*IsCall*/true, NewArgs, &ArgChanged))
2661 return ExprError();
2662
2663 // If this was list initialization, revert to list form.
2664 if (Construct->isListInitialization())
2665 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2666 Construct->getLocEnd(),
2667 Construct->getType());
2668
Richard Smithc83c2302012-12-19 01:39:02 +00002669 // Build a ParenListExpr to represent anything else.
2670 SourceRange Parens = Construct->getParenRange();
2671 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2672 Parens.getEnd());
2673}
2674
2675template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00002676bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2677 unsigned NumInputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002678 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002679 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002680 bool *ArgChanged) {
2681 for (unsigned I = 0; I != NumInputs; ++I) {
2682 // If requested, drop call arguments that need to be dropped.
2683 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2684 if (ArgChanged)
2685 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002686
Douglas Gregoraa165f82011-01-03 19:04:46 +00002687 break;
2688 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002689
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002690 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2691 Expr *Pattern = Expansion->getPattern();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002692
Chris Lattner686775d2011-07-20 06:58:45 +00002693 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002694 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2695 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002696
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002697 // Determine whether the set of unexpanded parameter packs can and should
2698 // be expanded.
2699 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002700 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00002701 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2702 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002703 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2704 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002705 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002706 Expand, RetainExpansion,
2707 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002708 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002709
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002710 if (!Expand) {
2711 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00002712 // transformation on the pack expansion, producing another pack
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002713 // expansion.
2714 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2715 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2716 if (OutPattern.isInvalid())
2717 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002718
2719 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002720 Expansion->getEllipsisLoc(),
2721 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002722 if (Out.isInvalid())
2723 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002724
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002725 if (ArgChanged)
2726 *ArgChanged = true;
2727 Outputs.push_back(Out.get());
2728 continue;
2729 }
John McCallc8fc90a2011-07-06 07:30:07 +00002730
2731 // Record right away that the argument was changed. This needs
2732 // to happen even if the array expands to nothing.
2733 if (ArgChanged) *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002734
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002735 // The transform has determined that we should perform an elementwise
2736 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002737 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002738 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2739 ExprResult Out = getDerived().TransformExpr(Pattern);
2740 if (Out.isInvalid())
2741 return true;
2742
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002743 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002744 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2745 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002746 if (Out.isInvalid())
2747 return true;
2748 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002749
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002750 Outputs.push_back(Out.get());
2751 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002752
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002753 continue;
2754 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002755
Richard Smithc83c2302012-12-19 01:39:02 +00002756 ExprResult Result =
2757 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
2758 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregoraa165f82011-01-03 19:04:46 +00002759 if (Result.isInvalid())
2760 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002761
Douglas Gregoraa165f82011-01-03 19:04:46 +00002762 if (Result.get() != Inputs[I] && ArgChanged)
2763 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002764
2765 Outputs.push_back(Result.get());
Douglas Gregoraa165f82011-01-03 19:04:46 +00002766 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002767
Douglas Gregoraa165f82011-01-03 19:04:46 +00002768 return false;
2769}
2770
2771template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002772NestedNameSpecifierLoc
2773TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2774 NestedNameSpecifierLoc NNS,
2775 QualType ObjectType,
2776 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002777 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002778 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002779 Qualifier = Qualifier.getPrefix())
2780 Qualifiers.push_back(Qualifier);
2781
2782 CXXScopeSpec SS;
2783 while (!Qualifiers.empty()) {
2784 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2785 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002786
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002787 switch (QNNS->getKind()) {
2788 case NestedNameSpecifier::Identifier:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002789 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002790 *QNNS->getAsIdentifier(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002791 Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002792 Q.getLocalEndLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002793 ObjectType, false, SS,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002794 FirstQualifierInScope, false))
2795 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002796
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002797 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002798
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002799 case NestedNameSpecifier::Namespace: {
2800 NamespaceDecl *NS
2801 = cast_or_null<NamespaceDecl>(
2802 getDerived().TransformDecl(
2803 Q.getLocalBeginLoc(),
2804 QNNS->getAsNamespace()));
2805 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2806 break;
2807 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002808
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002809 case NestedNameSpecifier::NamespaceAlias: {
2810 NamespaceAliasDecl *Alias
2811 = cast_or_null<NamespaceAliasDecl>(
2812 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2813 QNNS->getAsNamespaceAlias()));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002814 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002815 Q.getLocalEndLoc());
2816 break;
2817 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002818
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002819 case NestedNameSpecifier::Global:
2820 // There is no meaningful transformation that one could perform on the
2821 // global scope.
2822 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2823 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002824
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002825 case NestedNameSpecifier::TypeSpecWithTemplate:
2826 case NestedNameSpecifier::TypeSpec: {
2827 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2828 FirstQualifierInScope, SS);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002829
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002830 if (!TL)
2831 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002832
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002833 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith80ad52f2013-01-02 11:42:31 +00002834 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002835 TL.getType()->isEnumeralType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002836 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002837 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002838 if (TL.getType()->isEnumeralType())
2839 SemaRef.Diag(TL.getBeginLoc(),
2840 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002841 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2842 Q.getLocalEndLoc());
2843 break;
2844 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002845 // If the nested-name-specifier is an invalid type def, don't emit an
2846 // error because a previous error should have already been emitted.
David Blaikie39e6ab42013-02-18 22:06:02 +00002847 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
2848 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002849 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieu00c93a12011-05-07 01:36:37 +00002850 << TL.getType() << SS.getRange();
2851 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002852 return NestedNameSpecifierLoc();
2853 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002854 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002855
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002856 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002857 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002858 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002859 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002860
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002861 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002862 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002863 !getDerived().AlwaysRebuild())
2864 return NNS;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002865
2866 // If we can re-use the source-location data from the original
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002867 // nested-name-specifier, do so.
2868 if (SS.location_size() == NNS.getDataLength() &&
2869 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2870 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2871
2872 // Allocate new nested-name-specifier location information.
2873 return SS.getWithLocInContext(SemaRef.Context);
2874}
2875
2876template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002877DeclarationNameInfo
2878TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002879::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002880 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002881 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002882 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002883
2884 switch (Name.getNameKind()) {
2885 case DeclarationName::Identifier:
2886 case DeclarationName::ObjCZeroArgSelector:
2887 case DeclarationName::ObjCOneArgSelector:
2888 case DeclarationName::ObjCMultiArgSelector:
2889 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002890 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002891 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002892 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002893
Douglas Gregor81499bb2009-09-03 22:13:48 +00002894 case DeclarationName::CXXConstructorName:
2895 case DeclarationName::CXXDestructorName:
2896 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002897 TypeSourceInfo *NewTInfo;
2898 CanQualType NewCanTy;
2899 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002900 NewTInfo = getDerived().TransformType(OldTInfo);
2901 if (!NewTInfo)
2902 return DeclarationNameInfo();
2903 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002904 }
2905 else {
2906 NewTInfo = 0;
2907 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002908 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002909 if (NewT.isNull())
2910 return DeclarationNameInfo();
2911 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2912 }
Mike Stump1eb44332009-09-09 15:08:12 +00002913
Abramo Bagnara25777432010-08-11 22:01:17 +00002914 DeclarationName NewName
2915 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2916 NewCanTy);
2917 DeclarationNameInfo NewNameInfo(NameInfo);
2918 NewNameInfo.setName(NewName);
2919 NewNameInfo.setNamedTypeInfo(NewTInfo);
2920 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002921 }
Mike Stump1eb44332009-09-09 15:08:12 +00002922 }
2923
David Blaikieb219cfc2011-09-23 05:06:16 +00002924 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00002925}
2926
2927template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002928TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002929TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2930 TemplateName Name,
2931 SourceLocation NameLoc,
2932 QualType ObjectType,
2933 NamedDecl *FirstQualifierInScope) {
2934 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2935 TemplateDecl *Template = QTN->getTemplateDecl();
2936 assert(Template && "qualified template name must refer to a template");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002937
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002938 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00002939 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002940 Template));
2941 if (!TransTemplate)
2942 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002943
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002944 if (!getDerived().AlwaysRebuild() &&
2945 SS.getScopeRep() == QTN->getQualifier() &&
2946 TransTemplate == Template)
2947 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002948
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002949 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2950 TransTemplate);
2951 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002952
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002953 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2954 if (SS.getScopeRep()) {
2955 // These apply to the scope specifier, not the template.
2956 ObjectType = QualType();
2957 FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002958 }
2959
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002960 if (!getDerived().AlwaysRebuild() &&
2961 SS.getScopeRep() == DTN->getQualifier() &&
2962 ObjectType.isNull())
2963 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002964
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002965 if (DTN->isIdentifier()) {
2966 return getDerived().RebuildTemplateName(SS,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002967 *DTN->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002968 NameLoc,
2969 ObjectType,
2970 FirstQualifierInScope);
2971 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002972
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002973 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2974 ObjectType);
2975 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002976
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002977 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2978 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00002979 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002980 Template));
2981 if (!TransTemplate)
2982 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002983
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002984 if (!getDerived().AlwaysRebuild() &&
2985 TransTemplate == Template)
2986 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002987
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002988 return TemplateName(TransTemplate);
2989 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002990
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002991 if (SubstTemplateTemplateParmPackStorage *SubstPack
2992 = Name.getAsSubstTemplateTemplateParmPack()) {
2993 TemplateTemplateParmDecl *TransParam
2994 = cast_or_null<TemplateTemplateParmDecl>(
2995 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2996 if (!TransParam)
2997 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002998
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002999 if (!getDerived().AlwaysRebuild() &&
3000 TransParam == SubstPack->getParameterPack())
3001 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003002
3003 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003004 SubstPack->getArgumentPack());
3005 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003006
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003007 // These should be getting filtered out before they reach the AST.
3008 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003009}
3010
3011template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00003012void TreeTransform<Derived>::InventTemplateArgumentLoc(
3013 const TemplateArgument &Arg,
3014 TemplateArgumentLoc &Output) {
3015 SourceLocation Loc = getDerived().getBaseLocation();
3016 switch (Arg.getKind()) {
3017 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003018 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00003019 break;
3020
3021 case TemplateArgument::Type:
3022 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00003023 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier4a9d7952012-08-08 18:46:20 +00003024
John McCall833ca992009-10-29 08:12:44 +00003025 break;
3026
Douglas Gregor788cd062009-11-11 01:00:40 +00003027 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003028 case TemplateArgument::TemplateExpansion: {
3029 NestedNameSpecifierLocBuilder Builder;
3030 TemplateName Template = Arg.getAsTemplate();
3031 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3032 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3033 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3034 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003035
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003036 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier4a9d7952012-08-08 18:46:20 +00003037 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003038 Builder.getWithLocInContext(SemaRef.Context),
3039 Loc);
3040 else
Chad Rosier4a9d7952012-08-08 18:46:20 +00003041 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003042 Builder.getWithLocInContext(SemaRef.Context),
3043 Loc, Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003044
Douglas Gregor788cd062009-11-11 01:00:40 +00003045 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003046 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003047
John McCall833ca992009-10-29 08:12:44 +00003048 case TemplateArgument::Expression:
3049 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3050 break;
3051
3052 case TemplateArgument::Declaration:
3053 case TemplateArgument::Integral:
3054 case TemplateArgument::Pack:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003055 case TemplateArgument::NullPtr:
John McCall828bff22009-10-29 18:45:58 +00003056 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00003057 break;
3058 }
3059}
3060
3061template<typename Derived>
3062bool TreeTransform<Derived>::TransformTemplateArgument(
3063 const TemplateArgumentLoc &Input,
3064 TemplateArgumentLoc &Output) {
3065 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00003066 switch (Arg.getKind()) {
3067 case TemplateArgument::Null:
3068 case TemplateArgument::Integral:
Eli Friedman511e3ae2012-09-25 01:02:42 +00003069 case TemplateArgument::Pack:
3070 case TemplateArgument::Declaration:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003071 case TemplateArgument::NullPtr:
3072 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump1eb44332009-09-09 15:08:12 +00003073
Douglas Gregor670444e2009-08-04 22:27:00 +00003074 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00003075 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00003076 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00003077 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00003078
3079 DI = getDerived().TransformType(DI);
3080 if (!DI) return true;
3081
3082 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3083 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003084 }
Mike Stump1eb44332009-09-09 15:08:12 +00003085
Douglas Gregor788cd062009-11-11 01:00:40 +00003086 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003087 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3088 if (QualifierLoc) {
3089 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3090 if (!QualifierLoc)
3091 return true;
3092 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003093
Douglas Gregor1d752d72011-03-02 18:46:51 +00003094 CXXScopeSpec SS;
3095 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00003096 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00003097 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3098 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00003099 if (Template.isNull())
3100 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003101
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003102 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00003103 Input.getTemplateNameLoc());
3104 return false;
3105 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003106
3107 case TemplateArgument::TemplateExpansion:
3108 llvm_unreachable("Caller should expand pack expansions");
3109
Douglas Gregor670444e2009-08-04 22:27:00 +00003110 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00003111 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00003112 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003113 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003114
John McCall833ca992009-10-29 08:12:44 +00003115 Expr *InputExpr = Input.getSourceExpression();
3116 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3117
Chris Lattner223de242011-04-25 20:37:58 +00003118 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003119 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00003120 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00003121 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00003122 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003123 }
Douglas Gregor670444e2009-08-04 22:27:00 +00003124 }
Mike Stump1eb44332009-09-09 15:08:12 +00003125
Douglas Gregor670444e2009-08-04 22:27:00 +00003126 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003127 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003128}
3129
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003130/// \brief Iterator adaptor that invents template argument location information
3131/// for each of the template arguments in its underlying iterator.
3132template<typename Derived, typename InputIterator>
3133class TemplateArgumentLocInventIterator {
3134 TreeTransform<Derived> &Self;
3135 InputIterator Iter;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003136
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003137public:
3138 typedef TemplateArgumentLoc value_type;
3139 typedef TemplateArgumentLoc reference;
3140 typedef typename std::iterator_traits<InputIterator>::difference_type
3141 difference_type;
3142 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003143
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003144 class pointer {
3145 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003146
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003147 public:
3148 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003149
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003150 const TemplateArgumentLoc *operator->() const { return &Arg; }
3151 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00003152
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003153 TemplateArgumentLocInventIterator() { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003154
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003155 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3156 InputIterator Iter)
3157 : Self(Self), Iter(Iter) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003158
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003159 TemplateArgumentLocInventIterator &operator++() {
3160 ++Iter;
3161 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003162 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003163
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003164 TemplateArgumentLocInventIterator operator++(int) {
3165 TemplateArgumentLocInventIterator Old(*this);
3166 ++(*this);
3167 return Old;
3168 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003169
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003170 reference operator*() const {
3171 TemplateArgumentLoc Result;
3172 Self.InventTemplateArgumentLoc(*Iter, Result);
3173 return Result;
3174 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003175
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003176 pointer operator->() const { return pointer(**this); }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003177
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003178 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3179 const TemplateArgumentLocInventIterator &Y) {
3180 return X.Iter == Y.Iter;
3181 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003182
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003183 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3184 const TemplateArgumentLocInventIterator &Y) {
3185 return X.Iter != Y.Iter;
3186 }
3187};
Chad Rosier4a9d7952012-08-08 18:46:20 +00003188
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003189template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003190template<typename InputIterator>
3191bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3192 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003193 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003194 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003195 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003196 TemplateArgumentLoc In = *First;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003197
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003198 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3199 // Unpack argument packs, which we translate them into separate
3200 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003201 // FIXME: We could do much better if we could guarantee that the
3202 // TemplateArgumentLocInfo for the pack expansion would be usable for
3203 // all of the template arguments in the argument pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003204 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003205 TemplateArgument::pack_iterator>
3206 PackLocIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003207 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003208 In.getArgument().pack_begin()),
3209 PackLocIterator(*this,
3210 In.getArgument().pack_end()),
3211 Outputs))
3212 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003213
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003214 continue;
3215 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003216
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003217 if (In.getArgument().isPackExpansion()) {
3218 // We have a pack expansion, for which we will be substituting into
3219 // the pattern.
3220 SourceLocation Ellipsis;
David Blaikiedc84cd52013-02-20 22:23:23 +00003221 Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003222 TemplateArgumentLoc Pattern
Chad Rosier4a9d7952012-08-08 18:46:20 +00003223 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
Douglas Gregorcded4f62011-01-14 17:04:44 +00003224 getSema().Context);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003225
Chris Lattner686775d2011-07-20 06:58:45 +00003226 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003227 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3228 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003229
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003230 // Determine whether the set of unexpanded parameter packs can and should
3231 // be expanded.
3232 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003233 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00003234 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003235 if (getDerived().TryExpandParameterPacks(Ellipsis,
3236 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003237 Unexpanded,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003238 Expand,
Douglas Gregord3731192011-01-10 07:32:04 +00003239 RetainExpansion,
3240 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003241 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003242
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003243 if (!Expand) {
3244 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00003245 // transformation on the pack expansion, producing another pack
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003246 // expansion.
3247 TemplateArgumentLoc OutPattern;
3248 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3249 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3250 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003251
Douglas Gregorcded4f62011-01-14 17:04:44 +00003252 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3253 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003254 if (Out.getArgument().isNull())
3255 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003256
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003257 Outputs.addArgument(Out);
3258 continue;
3259 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003260
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003261 // The transform has determined that we should perform an elementwise
3262 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003263 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003264 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3265
3266 if (getDerived().TransformTemplateArgument(Pattern, Out))
3267 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003268
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003269 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003270 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3271 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003272 if (Out.getArgument().isNull())
3273 return true;
3274 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003275
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003276 Outputs.addArgument(Out);
3277 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003278
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003279 // If we're supposed to retain a pack expansion, do so by temporarily
3280 // forgetting the partially-substituted parameter pack.
3281 if (RetainExpansion) {
3282 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003283
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003284 if (getDerived().TransformTemplateArgument(Pattern, Out))
3285 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003286
Douglas Gregorcded4f62011-01-14 17:04:44 +00003287 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3288 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003289 if (Out.getArgument().isNull())
3290 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003291
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003292 Outputs.addArgument(Out);
3293 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003294
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003295 continue;
3296 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003297
3298 // The simple case:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003299 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003300 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003301
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003302 Outputs.addArgument(Out);
3303 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003304
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003305 return false;
3306
3307}
3308
Douglas Gregor577f75a2009-08-04 16:50:30 +00003309//===----------------------------------------------------------------------===//
3310// Type transformation
3311//===----------------------------------------------------------------------===//
3312
3313template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003314QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003315 if (getDerived().AlreadyTransformed(T))
3316 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003317
John McCalla2becad2009-10-21 00:40:46 +00003318 // Temporary workaround. All of these transformations should
3319 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003320 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3321 getDerived().getBaseLocation());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003322
John McCall43fed0d2010-11-12 08:19:04 +00003323 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003324
John McCalla2becad2009-10-21 00:40:46 +00003325 if (!NewDI)
3326 return QualType();
3327
3328 return NewDI->getType();
3329}
3330
3331template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003332TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003333 // Refine the base location to the type's location.
3334 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3335 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003336 if (getDerived().AlreadyTransformed(DI->getType()))
3337 return DI;
3338
3339 TypeLocBuilder TLB;
3340
3341 TypeLoc TL = DI->getTypeLoc();
3342 TLB.reserve(TL.getFullDataSize());
3343
John McCall43fed0d2010-11-12 08:19:04 +00003344 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003345 if (Result.isNull())
3346 return 0;
3347
John McCalla93c9342009-12-07 02:54:59 +00003348 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003349}
3350
3351template<typename Derived>
3352QualType
John McCall43fed0d2010-11-12 08:19:04 +00003353TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003354 switch (T.getTypeLocClass()) {
3355#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie39e6ab42013-02-18 22:06:02 +00003356#define TYPELOC(CLASS, PARENT) \
3357 case TypeLoc::CLASS: \
3358 return getDerived().Transform##CLASS##Type(TLB, \
3359 T.castAs<CLASS##TypeLoc>());
John McCalla2becad2009-10-21 00:40:46 +00003360#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003361 }
Mike Stump1eb44332009-09-09 15:08:12 +00003362
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003363 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003364}
3365
3366/// FIXME: By default, this routine adds type qualifiers only to types
3367/// that can have qualifiers, and silently suppresses those qualifiers
3368/// that are not permitted (e.g., qualifiers on reference or function
3369/// types). This is the right thing for template instantiation, but
3370/// probably not for other clients.
3371template<typename Derived>
3372QualType
3373TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003374 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003375 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003376
John McCall43fed0d2010-11-12 08:19:04 +00003377 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003378 if (Result.isNull())
3379 return QualType();
3380
3381 // Silently suppress qualifiers if the result type can't be qualified.
3382 // FIXME: this is the right thing for template instantiation, but
3383 // probably not for other clients.
3384 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003385 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003386
John McCallf85e1932011-06-15 23:02:42 +00003387 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003388 // resulting type.
3389 if (Quals.hasObjCLifetime()) {
3390 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3391 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003392 else if (Result.getObjCLifetime()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003393 // Objective-C ARC:
Douglas Gregore559ca12011-06-17 22:11:49 +00003394 // A lifetime qualifier applied to a substituted template parameter
3395 // overrides the lifetime qualifier from the template argument.
Douglas Gregor92d13872013-01-17 23:59:28 +00003396 const AutoType *AutoTy;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003397 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore559ca12011-06-17 22:11:49 +00003398 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3399 QualType Replacement = SubstTypeParam->getReplacementType();
3400 Qualifiers Qs = Replacement.getQualifiers();
3401 Qs.removeObjCLifetime();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003402 Replacement
Douglas Gregore559ca12011-06-17 22:11:49 +00003403 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3404 Qs);
3405 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier4a9d7952012-08-08 18:46:20 +00003406 SubstTypeParam->getReplacedParameter(),
Douglas Gregore559ca12011-06-17 22:11:49 +00003407 Replacement);
3408 TLB.TypeWasModifiedSafely(Result);
Douglas Gregor92d13872013-01-17 23:59:28 +00003409 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3410 // 'auto' types behave the same way as template parameters.
3411 QualType Deduced = AutoTy->getDeducedType();
3412 Qualifiers Qs = Deduced.getQualifiers();
3413 Qs.removeObjCLifetime();
3414 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3415 Qs);
Richard Smitha2c36462013-04-26 16:15:35 +00003416 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto());
Douglas Gregor92d13872013-01-17 23:59:28 +00003417 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore559ca12011-06-17 22:11:49 +00003418 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003419 // Otherwise, complain about the addition of a qualifier to an
3420 // already-qualified type.
3421 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003422 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003423 << Result << R;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003424
Douglas Gregore559ca12011-06-17 22:11:49 +00003425 Quals.removeObjCLifetime();
3426 }
3427 }
3428 }
John McCall28654742010-06-05 06:41:15 +00003429 if (!Quals.empty()) {
3430 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smith9807a2e2013-03-27 23:36:39 +00003431 // BuildQualifiedType might not add qualifiers if they are invalid.
3432 if (Result.hasLocalQualifiers())
3433 TLB.push<QualifiedTypeLoc>(Result);
John McCall28654742010-06-05 06:41:15 +00003434 // No location information to preserve.
3435 }
John McCalla2becad2009-10-21 00:40:46 +00003436
3437 return Result;
3438}
3439
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003440template<typename Derived>
3441TypeLoc
3442TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3443 QualType ObjectType,
3444 NamedDecl *UnqualLookup,
3445 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003446 QualType T = TL.getType();
3447 if (getDerived().AlreadyTransformed(T))
3448 return TL;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003449
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003450 TypeLocBuilder TLB;
3451 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003452
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003453 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003454 TemplateSpecializationTypeLoc SpecTL =
3455 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003456
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003457 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003458 getDerived().TransformTemplateName(SS,
3459 SpecTL.getTypePtr()->getTemplateName(),
3460 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003461 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003462 if (Template.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003463 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003464
3465 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003466 Template);
3467 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003468 DependentTemplateSpecializationTypeLoc SpecTL =
3469 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003470
Douglas Gregora88f09f2011-02-28 17:23:35 +00003471 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003472 = getDerived().RebuildTemplateName(SS,
3473 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003474 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003475 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003476 if (Template.isNull())
3477 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003478
3479 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003480 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003481 Template,
3482 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003483 } else {
3484 // Nothing special needs to be done for these.
3485 Result = getDerived().TransformType(TLB, TL);
3486 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003487
3488 if (Result.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003489 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003490
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003491 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3492}
3493
Douglas Gregorb71d8212011-03-02 18:32:08 +00003494template<typename Derived>
3495TypeSourceInfo *
3496TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3497 QualType ObjectType,
3498 NamedDecl *UnqualLookup,
3499 CXXScopeSpec &SS) {
3500 // FIXME: Painfully copy-paste from the above!
Chad Rosier4a9d7952012-08-08 18:46:20 +00003501
Douglas Gregorb71d8212011-03-02 18:32:08 +00003502 QualType T = TSInfo->getType();
3503 if (getDerived().AlreadyTransformed(T))
3504 return TSInfo;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003505
Douglas Gregorb71d8212011-03-02 18:32:08 +00003506 TypeLocBuilder TLB;
3507 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003508
Douglas Gregorb71d8212011-03-02 18:32:08 +00003509 TypeLoc TL = TSInfo->getTypeLoc();
3510 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003511 TemplateSpecializationTypeLoc SpecTL =
3512 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003513
Douglas Gregorb71d8212011-03-02 18:32:08 +00003514 TemplateName Template
3515 = getDerived().TransformTemplateName(SS,
3516 SpecTL.getTypePtr()->getTemplateName(),
3517 SpecTL.getTemplateNameLoc(),
3518 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003519 if (Template.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003520 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003521
3522 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003523 Template);
3524 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003525 DependentTemplateSpecializationTypeLoc SpecTL =
3526 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003527
Douglas Gregorb71d8212011-03-02 18:32:08 +00003528 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003529 = getDerived().RebuildTemplateName(SS,
3530 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003531 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003532 ObjectType, UnqualLookup);
3533 if (Template.isNull())
3534 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003535
3536 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003537 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003538 Template,
3539 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003540 } else {
3541 // Nothing special needs to be done for these.
3542 Result = getDerived().TransformType(TLB, TL);
3543 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003544
3545 if (Result.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003546 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003547
Douglas Gregorb71d8212011-03-02 18:32:08 +00003548 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3549}
3550
John McCalla2becad2009-10-21 00:40:46 +00003551template <class TyLoc> static inline
3552QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3553 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3554 NewT.setNameLoc(T.getNameLoc());
3555 return T.getType();
3556}
3557
John McCalla2becad2009-10-21 00:40:46 +00003558template<typename Derived>
3559QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003560 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003561 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3562 NewT.setBuiltinLoc(T.getBuiltinLoc());
3563 if (T.needsExtraLocalData())
3564 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3565 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003566}
Mike Stump1eb44332009-09-09 15:08:12 +00003567
Douglas Gregor577f75a2009-08-04 16:50:30 +00003568template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003569QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003570 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003571 // FIXME: recurse?
3572 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003573}
Mike Stump1eb44332009-09-09 15:08:12 +00003574
Douglas Gregor577f75a2009-08-04 16:50:30 +00003575template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003576QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003577 PointerTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003578 QualType PointeeType
3579 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003580 if (PointeeType.isNull())
3581 return QualType();
3582
3583 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003584 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003585 // A dependent pointer type 'T *' has is being transformed such
3586 // that an Objective-C class type is being replaced for 'T'. The
3587 // resulting pointer type is an ObjCObjectPointerType, not a
3588 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003589 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003590
John McCallc12c5bb2010-05-15 11:32:37 +00003591 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3592 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003593 return Result;
3594 }
John McCall43fed0d2010-11-12 08:19:04 +00003595
Douglas Gregor92e986e2010-04-22 16:44:27 +00003596 if (getDerived().AlwaysRebuild() ||
3597 PointeeType != TL.getPointeeLoc().getType()) {
3598 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3599 if (Result.isNull())
3600 return QualType();
3601 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003602
John McCallf85e1932011-06-15 23:02:42 +00003603 // Objective-C ARC can add lifetime qualifiers to the type that we're
3604 // pointing to.
3605 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003606
Douglas Gregor92e986e2010-04-22 16:44:27 +00003607 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3608 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003609 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003610}
Mike Stump1eb44332009-09-09 15:08:12 +00003611
3612template<typename Derived>
3613QualType
John McCalla2becad2009-10-21 00:40:46 +00003614TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003615 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003616 QualType PointeeType
Chad Rosier4a9d7952012-08-08 18:46:20 +00003617 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3618 if (PointeeType.isNull())
3619 return QualType();
3620
3621 QualType Result = TL.getType();
3622 if (getDerived().AlwaysRebuild() ||
3623 PointeeType != TL.getPointeeLoc().getType()) {
3624 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003625 TL.getSigilLoc());
3626 if (Result.isNull())
3627 return QualType();
3628 }
3629
Douglas Gregor39968ad2010-04-22 16:50:51 +00003630 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003631 NewT.setSigilLoc(TL.getSigilLoc());
3632 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003633}
3634
John McCall85737a72009-10-30 00:06:24 +00003635/// Transforms a reference type. Note that somewhat paradoxically we
3636/// don't care whether the type itself is an l-value type or an r-value
3637/// type; we only care if the type was *written* as an l-value type
3638/// or an r-value type.
3639template<typename Derived>
3640QualType
3641TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003642 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003643 const ReferenceType *T = TL.getTypePtr();
3644
3645 // Note that this works with the pointee-as-written.
3646 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3647 if (PointeeType.isNull())
3648 return QualType();
3649
3650 QualType Result = TL.getType();
3651 if (getDerived().AlwaysRebuild() ||
3652 PointeeType != T->getPointeeTypeAsWritten()) {
3653 Result = getDerived().RebuildReferenceType(PointeeType,
3654 T->isSpelledAsLValue(),
3655 TL.getSigilLoc());
3656 if (Result.isNull())
3657 return QualType();
3658 }
3659
John McCallf85e1932011-06-15 23:02:42 +00003660 // Objective-C ARC can add lifetime qualifiers to the type that we're
3661 // referring to.
3662 TLB.TypeWasModifiedSafely(
3663 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3664
John McCall85737a72009-10-30 00:06:24 +00003665 // r-value references can be rebuilt as l-value references.
3666 ReferenceTypeLoc NewTL;
3667 if (isa<LValueReferenceType>(Result))
3668 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3669 else
3670 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3671 NewTL.setSigilLoc(TL.getSigilLoc());
3672
3673 return Result;
3674}
3675
Mike Stump1eb44332009-09-09 15:08:12 +00003676template<typename Derived>
3677QualType
John McCalla2becad2009-10-21 00:40:46 +00003678TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003679 LValueReferenceTypeLoc TL) {
3680 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003681}
3682
Mike Stump1eb44332009-09-09 15:08:12 +00003683template<typename Derived>
3684QualType
John McCalla2becad2009-10-21 00:40:46 +00003685TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003686 RValueReferenceTypeLoc TL) {
3687 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003688}
Mike Stump1eb44332009-09-09 15:08:12 +00003689
Douglas Gregor577f75a2009-08-04 16:50:30 +00003690template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003691QualType
John McCalla2becad2009-10-21 00:40:46 +00003692TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003693 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003694 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003695 if (PointeeType.isNull())
3696 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003697
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003698 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3699 TypeSourceInfo* NewClsTInfo = 0;
3700 if (OldClsTInfo) {
3701 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3702 if (!NewClsTInfo)
3703 return QualType();
3704 }
3705
3706 const MemberPointerType *T = TL.getTypePtr();
3707 QualType OldClsType = QualType(T->getClass(), 0);
3708 QualType NewClsType;
3709 if (NewClsTInfo)
3710 NewClsType = NewClsTInfo->getType();
3711 else {
3712 NewClsType = getDerived().TransformType(OldClsType);
3713 if (NewClsType.isNull())
3714 return QualType();
3715 }
Mike Stump1eb44332009-09-09 15:08:12 +00003716
John McCalla2becad2009-10-21 00:40:46 +00003717 QualType Result = TL.getType();
3718 if (getDerived().AlwaysRebuild() ||
3719 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003720 NewClsType != OldClsType) {
3721 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003722 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003723 if (Result.isNull())
3724 return QualType();
3725 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003726
John McCalla2becad2009-10-21 00:40:46 +00003727 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3728 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003729 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003730
3731 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003732}
3733
Mike Stump1eb44332009-09-09 15:08:12 +00003734template<typename Derived>
3735QualType
John McCalla2becad2009-10-21 00:40:46 +00003736TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003737 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003738 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003739 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003740 if (ElementType.isNull())
3741 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003742
John McCalla2becad2009-10-21 00:40:46 +00003743 QualType Result = TL.getType();
3744 if (getDerived().AlwaysRebuild() ||
3745 ElementType != T->getElementType()) {
3746 Result = getDerived().RebuildConstantArrayType(ElementType,
3747 T->getSizeModifier(),
3748 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003749 T->getIndexTypeCVRQualifiers(),
3750 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003751 if (Result.isNull())
3752 return QualType();
3753 }
Eli Friedman457a3772012-01-25 22:19:07 +00003754
3755 // We might have either a ConstantArrayType or a VariableArrayType now:
3756 // a ConstantArrayType is allowed to have an element type which is a
3757 // VariableArrayType if the type is dependent. Fortunately, all array
3758 // types have the same location layout.
3759 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003760 NewTL.setLBracketLoc(TL.getLBracketLoc());
3761 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003762
John McCalla2becad2009-10-21 00:40:46 +00003763 Expr *Size = TL.getSizeExpr();
3764 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003765 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3766 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003767 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003768 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003769 }
3770 NewTL.setSizeExpr(Size);
3771
3772 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003773}
Mike Stump1eb44332009-09-09 15:08:12 +00003774
Douglas Gregor577f75a2009-08-04 16:50:30 +00003775template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003776QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003777 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003778 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003779 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003780 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003781 if (ElementType.isNull())
3782 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003783
John McCalla2becad2009-10-21 00:40:46 +00003784 QualType Result = TL.getType();
3785 if (getDerived().AlwaysRebuild() ||
3786 ElementType != T->getElementType()) {
3787 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003788 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003789 T->getIndexTypeCVRQualifiers(),
3790 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003791 if (Result.isNull())
3792 return QualType();
3793 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003794
John McCalla2becad2009-10-21 00:40:46 +00003795 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3796 NewTL.setLBracketLoc(TL.getLBracketLoc());
3797 NewTL.setRBracketLoc(TL.getRBracketLoc());
3798 NewTL.setSizeExpr(0);
3799
3800 return Result;
3801}
3802
3803template<typename Derived>
3804QualType
3805TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003806 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003807 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003808 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3809 if (ElementType.isNull())
3810 return QualType();
3811
John McCall60d7b3a2010-08-24 06:29:42 +00003812 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003813 = getDerived().TransformExpr(T->getSizeExpr());
3814 if (SizeResult.isInvalid())
3815 return QualType();
3816
John McCall9ae2f072010-08-23 23:25:46 +00003817 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003818
3819 QualType Result = TL.getType();
3820 if (getDerived().AlwaysRebuild() ||
3821 ElementType != T->getElementType() ||
3822 Size != T->getSizeExpr()) {
3823 Result = getDerived().RebuildVariableArrayType(ElementType,
3824 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003825 Size,
John McCalla2becad2009-10-21 00:40:46 +00003826 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003827 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003828 if (Result.isNull())
3829 return QualType();
3830 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003831
John McCalla2becad2009-10-21 00:40:46 +00003832 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3833 NewTL.setLBracketLoc(TL.getLBracketLoc());
3834 NewTL.setRBracketLoc(TL.getRBracketLoc());
3835 NewTL.setSizeExpr(Size);
3836
3837 return Result;
3838}
3839
3840template<typename Derived>
3841QualType
3842TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003843 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003844 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003845 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3846 if (ElementType.isNull())
3847 return QualType();
3848
Richard Smithf6702a32011-12-20 02:08:33 +00003849 // Array bounds are constant expressions.
3850 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3851 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003852
John McCall3b657512011-01-19 10:06:00 +00003853 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3854 Expr *origSize = TL.getSizeExpr();
3855 if (!origSize) origSize = T->getSizeExpr();
3856
3857 ExprResult sizeResult
3858 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003859 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003860 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003861 return QualType();
3862
John McCall3b657512011-01-19 10:06:00 +00003863 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003864
3865 QualType Result = TL.getType();
3866 if (getDerived().AlwaysRebuild() ||
3867 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003868 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003869 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3870 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003871 size,
John McCalla2becad2009-10-21 00:40:46 +00003872 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003873 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003874 if (Result.isNull())
3875 return QualType();
3876 }
John McCalla2becad2009-10-21 00:40:46 +00003877
3878 // We might have any sort of array type now, but fortunately they
3879 // all have the same location layout.
3880 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3881 NewTL.setLBracketLoc(TL.getLBracketLoc());
3882 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003883 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003884
3885 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003886}
Mike Stump1eb44332009-09-09 15:08:12 +00003887
3888template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003889QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003890 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003891 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003892 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003893
3894 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003895 QualType ElementType = getDerived().TransformType(T->getElementType());
3896 if (ElementType.isNull())
3897 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003898
Richard Smithf6702a32011-12-20 02:08:33 +00003899 // Vector sizes are constant expressions.
3900 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3901 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003902
John McCall60d7b3a2010-08-24 06:29:42 +00003903 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00003904 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003905 if (Size.isInvalid())
3906 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003907
John McCalla2becad2009-10-21 00:40:46 +00003908 QualType Result = TL.getType();
3909 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003910 ElementType != T->getElementType() ||
3911 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003912 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003913 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003914 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003915 if (Result.isNull())
3916 return QualType();
3917 }
John McCalla2becad2009-10-21 00:40:46 +00003918
3919 // Result might be dependent or not.
3920 if (isa<DependentSizedExtVectorType>(Result)) {
3921 DependentSizedExtVectorTypeLoc NewTL
3922 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3923 NewTL.setNameLoc(TL.getNameLoc());
3924 } else {
3925 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3926 NewTL.setNameLoc(TL.getNameLoc());
3927 }
3928
3929 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003930}
Mike Stump1eb44332009-09-09 15:08:12 +00003931
3932template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003933QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003934 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003935 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003936 QualType ElementType = getDerived().TransformType(T->getElementType());
3937 if (ElementType.isNull())
3938 return QualType();
3939
John McCalla2becad2009-10-21 00:40:46 +00003940 QualType Result = TL.getType();
3941 if (getDerived().AlwaysRebuild() ||
3942 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003943 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003944 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003945 if (Result.isNull())
3946 return QualType();
3947 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003948
John McCalla2becad2009-10-21 00:40:46 +00003949 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3950 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003951
John McCalla2becad2009-10-21 00:40:46 +00003952 return Result;
3953}
3954
3955template<typename Derived>
3956QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003957 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003958 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003959 QualType ElementType = getDerived().TransformType(T->getElementType());
3960 if (ElementType.isNull())
3961 return QualType();
3962
3963 QualType Result = TL.getType();
3964 if (getDerived().AlwaysRebuild() ||
3965 ElementType != T->getElementType()) {
3966 Result = getDerived().RebuildExtVectorType(ElementType,
3967 T->getNumElements(),
3968 /*FIXME*/ SourceLocation());
3969 if (Result.isNull())
3970 return QualType();
3971 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003972
John McCalla2becad2009-10-21 00:40:46 +00003973 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3974 NewTL.setNameLoc(TL.getNameLoc());
3975
3976 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003977}
Mike Stump1eb44332009-09-09 15:08:12 +00003978
David Blaikiedc84cd52013-02-20 22:23:23 +00003979template <typename Derived>
3980ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
3981 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
3982 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00003983 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003984 TypeSourceInfo *NewDI = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003985
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003986 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003987 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003988 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003989 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00003990 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003991
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003992 TypeLocBuilder TLB;
3993 TypeLoc NewTL = OldDI->getTypeLoc();
3994 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003995
3996 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003997 OldExpansionTL.getPatternLoc());
3998 if (Result.isNull())
3999 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004000
4001 Result = RebuildPackExpansionType(Result,
4002 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004003 OldExpansionTL.getEllipsisLoc(),
4004 NumExpansions);
4005 if (Result.isNull())
4006 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004007
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004008 PackExpansionTypeLoc NewExpansionTL
4009 = TLB.push<PackExpansionTypeLoc>(Result);
4010 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4011 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4012 } else
4013 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00004014 if (!NewDI)
4015 return 0;
4016
John McCallfb44de92011-05-01 22:35:37 +00004017 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00004018 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00004019
4020 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4021 OldParm->getDeclContext(),
4022 OldParm->getInnerLocStart(),
4023 OldParm->getLocation(),
4024 OldParm->getIdentifier(),
4025 NewDI->getType(),
4026 NewDI,
4027 OldParm->getStorageClass(),
John McCallfb44de92011-05-01 22:35:37 +00004028 /* DefArg */ NULL);
4029 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4030 OldParm->getFunctionScopeIndex() + indexAdjustment);
4031 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00004032}
4033
4034template<typename Derived>
4035bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00004036 TransformFunctionTypeParams(SourceLocation Loc,
4037 ParmVarDecl **Params, unsigned NumParams,
4038 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00004039 SmallVectorImpl<QualType> &OutParamTypes,
4040 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00004041 int indexAdjustment = 0;
4042
Douglas Gregora009b592011-01-07 00:20:55 +00004043 for (unsigned i = 0; i != NumParams; ++i) {
4044 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00004045 assert(OldParm->getFunctionScopeIndex() == i);
4046
David Blaikiedc84cd52013-02-20 22:23:23 +00004047 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004048 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004049 if (OldParm->isParameterPack()) {
4050 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00004051 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00004052
Douglas Gregor603cfb42011-01-05 23:12:31 +00004053 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004054 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00004055 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004056 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4057 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004058 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4059
Douglas Gregor603cfb42011-01-05 23:12:31 +00004060 // Determine whether we should expand the parameter packs.
4061 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004062 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004063 Optional<unsigned> OrigNumExpansions =
4064 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004065 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004066 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4067 Pattern.getSourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004068 Unexpanded,
4069 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004070 RetainExpansion,
4071 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004072 return true;
4073 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004074
Douglas Gregor603cfb42011-01-05 23:12:31 +00004075 if (ShouldExpand) {
4076 // Expand the function parameter pack into multiple, separate
4077 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00004078 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00004079 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004080 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004081 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004082 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004083 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004084 OrigNumExpansions,
4085 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004086 if (!NewParm)
4087 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004088
Douglas Gregora009b592011-01-07 00:20:55 +00004089 OutParamTypes.push_back(NewParm->getType());
4090 if (PVars)
4091 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004092 }
Douglas Gregord3731192011-01-10 07:32:04 +00004093
4094 // If we're supposed to retain a pack expansion, do so by temporarily
4095 // forgetting the partially-substituted parameter pack.
4096 if (RetainExpansion) {
4097 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004098 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004099 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004100 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004101 OrigNumExpansions,
4102 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00004103 if (!NewParm)
4104 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004105
Douglas Gregord3731192011-01-10 07:32:04 +00004106 OutParamTypes.push_back(NewParm->getType());
4107 if (PVars)
4108 PVars->push_back(NewParm);
4109 }
4110
John McCallfb44de92011-05-01 22:35:37 +00004111 // The next parameter should have the same adjustment as the
4112 // last thing we pushed, but we post-incremented indexAdjustment
4113 // on every push. Also, if we push nothing, the adjustment should
4114 // go down by one.
4115 indexAdjustment--;
4116
Douglas Gregor603cfb42011-01-05 23:12:31 +00004117 // We're done with the pack expansion.
4118 continue;
4119 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004120
4121 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004122 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004123 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4124 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004125 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004126 NumExpansions,
4127 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004128 } else {
David Blaikiedc84cd52013-02-20 22:23:23 +00004129 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie66874fb2013-02-21 01:47:18 +00004130 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004131 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004132
John McCall21ef0fa2010-03-11 09:03:00 +00004133 if (!NewParm)
4134 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004135
Douglas Gregora009b592011-01-07 00:20:55 +00004136 OutParamTypes.push_back(NewParm->getType());
4137 if (PVars)
4138 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004139 continue;
4140 }
John McCall21ef0fa2010-03-11 09:03:00 +00004141
4142 // Deal with the possibility that we don't have a parameter
4143 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004144 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004145 bool IsPackExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004146 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004147 QualType NewType;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004148 if (const PackExpansionType *Expansion
Douglas Gregor603cfb42011-01-05 23:12:31 +00004149 = dyn_cast<PackExpansionType>(OldType)) {
4150 // We have a function parameter pack that may need to be expanded.
4151 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004152 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004153 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004154
Douglas Gregor603cfb42011-01-05 23:12:31 +00004155 // Determine whether we should expand the parameter packs.
4156 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004157 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004158 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004159 Unexpanded,
4160 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004161 RetainExpansion,
4162 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004163 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004164 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004165
Douglas Gregor603cfb42011-01-05 23:12:31 +00004166 if (ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004167 // Expand the function parameter pack into multiple, separate
Douglas Gregor603cfb42011-01-05 23:12:31 +00004168 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004169 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004170 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4171 QualType NewType = getDerived().TransformType(Pattern);
4172 if (NewType.isNull())
4173 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004174
Douglas Gregora009b592011-01-07 00:20:55 +00004175 OutParamTypes.push_back(NewType);
4176 if (PVars)
4177 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004178 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004179
Douglas Gregor603cfb42011-01-05 23:12:31 +00004180 // We're done with the pack expansion.
4181 continue;
4182 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004183
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004184 // If we're supposed to retain a pack expansion, do so by temporarily
4185 // forgetting the partially-substituted parameter pack.
4186 if (RetainExpansion) {
4187 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4188 QualType NewType = getDerived().TransformType(Pattern);
4189 if (NewType.isNull())
4190 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004191
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004192 OutParamTypes.push_back(NewType);
4193 if (PVars)
4194 PVars->push_back(0);
4195 }
Douglas Gregord3731192011-01-10 07:32:04 +00004196
Chad Rosier4a9d7952012-08-08 18:46:20 +00004197 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004198 // expansion.
4199 OldType = Expansion->getPattern();
4200 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004201 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4202 NewType = getDerived().TransformType(OldType);
4203 } else {
4204 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004205 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004206
Douglas Gregor603cfb42011-01-05 23:12:31 +00004207 if (NewType.isNull())
4208 return true;
4209
4210 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004211 NewType = getSema().Context.getPackExpansionType(NewType,
4212 NumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004213
Douglas Gregora009b592011-01-07 00:20:55 +00004214 OutParamTypes.push_back(NewType);
4215 if (PVars)
4216 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004217 }
4218
John McCallfb44de92011-05-01 22:35:37 +00004219#ifndef NDEBUG
4220 if (PVars) {
4221 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4222 if (ParmVarDecl *parm = (*PVars)[i])
4223 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004224 }
John McCallfb44de92011-05-01 22:35:37 +00004225#endif
4226
4227 return false;
4228}
John McCall21ef0fa2010-03-11 09:03:00 +00004229
4230template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004231QualType
John McCalla2becad2009-10-21 00:40:46 +00004232TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004233 FunctionProtoTypeLoc TL) {
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004234 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4235}
4236
4237template<typename Derived>
4238QualType
4239TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4240 FunctionProtoTypeLoc TL,
4241 CXXRecordDecl *ThisContext,
4242 unsigned ThisTypeQuals) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004243 // Transform the parameters and return type.
4244 //
Richard Smithe6975e92012-04-17 00:58:00 +00004245 // We are required to instantiate the params and return type in source order.
Douglas Gregordab60ad2010-10-01 18:44:50 +00004246 // When the function has a trailing return type, we instantiate the
4247 // parameters before the return type, since the return type can then refer
4248 // to the parameters themselves (via decltype, sizeof, etc.).
4249 //
Chris Lattner686775d2011-07-20 06:58:45 +00004250 SmallVector<QualType, 4> ParamTypes;
4251 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004252 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004253
Douglas Gregordab60ad2010-10-01 18:44:50 +00004254 QualType ResultType;
4255
Richard Smith9fbf3272012-08-14 22:51:13 +00004256 if (T->hasTrailingReturn()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004257 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004258 TL.getParmArray(),
4259 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004260 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004261 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004262 return QualType();
4263
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004264 {
4265 // C++11 [expr.prim.general]p3:
Chad Rosier4a9d7952012-08-08 18:46:20 +00004266 // If a declaration declares a member function or member function
4267 // template of a class X, the expression this is a prvalue of type
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004268 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier4a9d7952012-08-08 18:46:20 +00004269 // and the end of the function-definition, member-declarator, or
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004270 // declarator.
4271 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004272
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004273 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4274 if (ResultType.isNull())
4275 return QualType();
4276 }
Douglas Gregordab60ad2010-10-01 18:44:50 +00004277 }
4278 else {
4279 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4280 if (ResultType.isNull())
4281 return QualType();
4282
Chad Rosier4a9d7952012-08-08 18:46:20 +00004283 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004284 TL.getParmArray(),
4285 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004286 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004287 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004288 return QualType();
4289 }
4290
Richard Smithe6975e92012-04-17 00:58:00 +00004291 // FIXME: Need to transform the exception-specification too.
4292
John McCalla2becad2009-10-21 00:40:46 +00004293 QualType Result = TL.getType();
4294 if (getDerived().AlwaysRebuild() ||
4295 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004296 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004297 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
Jordan Rosebea522f2013-03-08 21:51:21 +00004298 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00004299 T->getExtProtoInfo());
John McCalla2becad2009-10-21 00:40:46 +00004300 if (Result.isNull())
4301 return QualType();
4302 }
Mike Stump1eb44332009-09-09 15:08:12 +00004303
John McCalla2becad2009-10-21 00:40:46 +00004304 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004305 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004306 NewTL.setLParenLoc(TL.getLParenLoc());
4307 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004308 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004309 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4310 NewTL.setArg(i, ParamDecls[i]);
4311
4312 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004313}
Mike Stump1eb44332009-09-09 15:08:12 +00004314
Douglas Gregor577f75a2009-08-04 16:50:30 +00004315template<typename Derived>
4316QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004317 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004318 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004319 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004320 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4321 if (ResultType.isNull())
4322 return QualType();
4323
4324 QualType Result = TL.getType();
4325 if (getDerived().AlwaysRebuild() ||
4326 ResultType != T->getResultType())
4327 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4328
4329 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004330 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004331 NewTL.setLParenLoc(TL.getLParenLoc());
4332 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004333 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004334
4335 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004336}
Mike Stump1eb44332009-09-09 15:08:12 +00004337
John McCalled976492009-12-04 22:46:56 +00004338template<typename Derived> QualType
4339TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004340 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004341 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004342 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004343 if (!D)
4344 return QualType();
4345
4346 QualType Result = TL.getType();
4347 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4348 Result = getDerived().RebuildUnresolvedUsingType(D);
4349 if (Result.isNull())
4350 return QualType();
4351 }
4352
4353 // We might get an arbitrary type spec type back. We should at
4354 // least always get a type spec type, though.
4355 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4356 NewTL.setNameLoc(TL.getNameLoc());
4357
4358 return Result;
4359}
4360
Douglas Gregor577f75a2009-08-04 16:50:30 +00004361template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004362QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004363 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004364 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004365 TypedefNameDecl *Typedef
4366 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4367 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004368 if (!Typedef)
4369 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004370
John McCalla2becad2009-10-21 00:40:46 +00004371 QualType Result = TL.getType();
4372 if (getDerived().AlwaysRebuild() ||
4373 Typedef != T->getDecl()) {
4374 Result = getDerived().RebuildTypedefType(Typedef);
4375 if (Result.isNull())
4376 return QualType();
4377 }
Mike Stump1eb44332009-09-09 15:08:12 +00004378
John McCalla2becad2009-10-21 00:40:46 +00004379 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4380 NewTL.setNameLoc(TL.getNameLoc());
4381
4382 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004383}
Mike Stump1eb44332009-09-09 15:08:12 +00004384
Douglas Gregor577f75a2009-08-04 16:50:30 +00004385template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004386QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004387 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004388 // typeof expressions are not potentially evaluated contexts
Eli Friedman80bfa3d2012-09-26 04:34:21 +00004389 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4390 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00004391
John McCall60d7b3a2010-08-24 06:29:42 +00004392 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004393 if (E.isInvalid())
4394 return QualType();
4395
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004396 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4397 if (E.isInvalid())
4398 return QualType();
4399
John McCalla2becad2009-10-21 00:40:46 +00004400 QualType Result = TL.getType();
4401 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004402 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004403 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004404 if (Result.isNull())
4405 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004406 }
John McCalla2becad2009-10-21 00:40:46 +00004407 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004408
John McCalla2becad2009-10-21 00:40:46 +00004409 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004410 NewTL.setTypeofLoc(TL.getTypeofLoc());
4411 NewTL.setLParenLoc(TL.getLParenLoc());
4412 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004413
4414 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004415}
Mike Stump1eb44332009-09-09 15:08:12 +00004416
4417template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004418QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004419 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004420 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4421 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4422 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004423 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004424
John McCalla2becad2009-10-21 00:40:46 +00004425 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004426 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4427 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004428 if (Result.isNull())
4429 return QualType();
4430 }
Mike Stump1eb44332009-09-09 15:08:12 +00004431
John McCalla2becad2009-10-21 00:40:46 +00004432 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004433 NewTL.setTypeofLoc(TL.getTypeofLoc());
4434 NewTL.setLParenLoc(TL.getLParenLoc());
4435 NewTL.setRParenLoc(TL.getRParenLoc());
4436 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004437
4438 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004439}
Mike Stump1eb44332009-09-09 15:08:12 +00004440
4441template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004442QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004443 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004444 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004445
Douglas Gregor670444e2009-08-04 22:27:00 +00004446 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004447 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4448 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004449
John McCall60d7b3a2010-08-24 06:29:42 +00004450 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004451 if (E.isInvalid())
4452 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004453
Richard Smith76f3f692012-02-22 02:04:18 +00004454 E = getSema().ActOnDecltypeExpression(E.take());
4455 if (E.isInvalid())
4456 return QualType();
4457
John McCalla2becad2009-10-21 00:40:46 +00004458 QualType Result = TL.getType();
4459 if (getDerived().AlwaysRebuild() ||
4460 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004461 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004462 if (Result.isNull())
4463 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004464 }
John McCalla2becad2009-10-21 00:40:46 +00004465 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004466
John McCalla2becad2009-10-21 00:40:46 +00004467 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4468 NewTL.setNameLoc(TL.getNameLoc());
4469
4470 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004471}
4472
4473template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004474QualType TreeTransform<Derived>::TransformUnaryTransformType(
4475 TypeLocBuilder &TLB,
4476 UnaryTransformTypeLoc TL) {
4477 QualType Result = TL.getType();
4478 if (Result->isDependentType()) {
4479 const UnaryTransformType *T = TL.getTypePtr();
4480 QualType NewBase =
4481 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4482 Result = getDerived().RebuildUnaryTransformType(NewBase,
4483 T->getUTTKind(),
4484 TL.getKWLoc());
4485 if (Result.isNull())
4486 return QualType();
4487 }
4488
4489 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4490 NewTL.setKWLoc(TL.getKWLoc());
4491 NewTL.setParensRange(TL.getParensRange());
4492 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4493 return Result;
4494}
4495
4496template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004497QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4498 AutoTypeLoc TL) {
4499 const AutoType *T = TL.getTypePtr();
4500 QualType OldDeduced = T->getDeducedType();
4501 QualType NewDeduced;
4502 if (!OldDeduced.isNull()) {
4503 NewDeduced = getDerived().TransformType(OldDeduced);
4504 if (NewDeduced.isNull())
4505 return QualType();
4506 }
4507
4508 QualType Result = TL.getType();
Richard Smithdc7a4f52013-04-30 13:56:41 +00004509 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4510 T->isDependentType()) {
Richard Smitha2c36462013-04-26 16:15:35 +00004511 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith34b41d92011-02-20 03:19:35 +00004512 if (Result.isNull())
4513 return QualType();
4514 }
4515
4516 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4517 NewTL.setNameLoc(TL.getNameLoc());
4518
4519 return Result;
4520}
4521
4522template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004523QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004524 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004525 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004526 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004527 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4528 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004529 if (!Record)
4530 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004531
John McCalla2becad2009-10-21 00:40:46 +00004532 QualType Result = TL.getType();
4533 if (getDerived().AlwaysRebuild() ||
4534 Record != T->getDecl()) {
4535 Result = getDerived().RebuildRecordType(Record);
4536 if (Result.isNull())
4537 return QualType();
4538 }
Mike Stump1eb44332009-09-09 15:08:12 +00004539
John McCalla2becad2009-10-21 00:40:46 +00004540 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4541 NewTL.setNameLoc(TL.getNameLoc());
4542
4543 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004544}
Mike Stump1eb44332009-09-09 15:08:12 +00004545
4546template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004547QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004548 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004549 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004550 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004551 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4552 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004553 if (!Enum)
4554 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004555
John McCalla2becad2009-10-21 00:40:46 +00004556 QualType Result = TL.getType();
4557 if (getDerived().AlwaysRebuild() ||
4558 Enum != T->getDecl()) {
4559 Result = getDerived().RebuildEnumType(Enum);
4560 if (Result.isNull())
4561 return QualType();
4562 }
Mike Stump1eb44332009-09-09 15:08:12 +00004563
John McCalla2becad2009-10-21 00:40:46 +00004564 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4565 NewTL.setNameLoc(TL.getNameLoc());
4566
4567 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004568}
John McCall7da24312009-09-05 00:15:47 +00004569
John McCall3cb0ebd2010-03-10 03:28:59 +00004570template<typename Derived>
4571QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4572 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004573 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004574 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4575 TL.getTypePtr()->getDecl());
4576 if (!D) return QualType();
4577
4578 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4579 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4580 return T;
4581}
4582
Douglas Gregor577f75a2009-08-04 16:50:30 +00004583template<typename Derived>
4584QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004585 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004586 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004587 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004588}
4589
Mike Stump1eb44332009-09-09 15:08:12 +00004590template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004591QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004592 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004593 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004594 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004595
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004596 // Substitute into the replacement type, which itself might involve something
4597 // that needs to be transformed. This only tends to occur with default
4598 // template arguments of template template parameters.
4599 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4600 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4601 if (Replacement.isNull())
4602 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004603
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004604 // Always canonicalize the replacement type.
4605 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4606 QualType Result
Chad Rosier4a9d7952012-08-08 18:46:20 +00004607 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004608 Replacement);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004609
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004610 // Propagate type-source information.
4611 SubstTemplateTypeParmTypeLoc NewTL
4612 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4613 NewTL.setNameLoc(TL.getNameLoc());
4614 return Result;
4615
John McCall49a832b2009-10-18 09:09:24 +00004616}
4617
4618template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004619QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4620 TypeLocBuilder &TLB,
4621 SubstTemplateTypeParmPackTypeLoc TL) {
4622 return TransformTypeSpecType(TLB, TL);
4623}
4624
4625template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004626QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004627 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004628 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004629 const TemplateSpecializationType *T = TL.getTypePtr();
4630
Douglas Gregor1d752d72011-03-02 18:46:51 +00004631 // The nested-name-specifier never matters in a TemplateSpecializationType,
4632 // because we can't have a dependent nested-name-specifier anyway.
4633 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004634 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004635 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4636 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004637 if (Template.isNull())
4638 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004639
John McCall43fed0d2010-11-12 08:19:04 +00004640 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4641}
4642
Eli Friedmanb001de72011-10-06 23:00:33 +00004643template<typename Derived>
4644QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4645 AtomicTypeLoc TL) {
4646 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4647 if (ValueType.isNull())
4648 return QualType();
4649
4650 QualType Result = TL.getType();
4651 if (getDerived().AlwaysRebuild() ||
4652 ValueType != TL.getValueLoc().getType()) {
4653 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4654 if (Result.isNull())
4655 return QualType();
4656 }
4657
4658 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4659 NewTL.setKWLoc(TL.getKWLoc());
4660 NewTL.setLParenLoc(TL.getLParenLoc());
4661 NewTL.setRParenLoc(TL.getRParenLoc());
4662
4663 return Result;
4664}
4665
Chad Rosier4a9d7952012-08-08 18:46:20 +00004666 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004667 /// container that provides a \c getArgLoc() member function.
4668 ///
4669 /// This iterator is intended to be used with the iterator form of
4670 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4671 template<typename ArgLocContainer>
4672 class TemplateArgumentLocContainerIterator {
4673 ArgLocContainer *Container;
4674 unsigned Index;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004675
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004676 public:
4677 typedef TemplateArgumentLoc value_type;
4678 typedef TemplateArgumentLoc reference;
4679 typedef int difference_type;
4680 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004681
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004682 class pointer {
4683 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004684
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004685 public:
4686 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004687
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004688 const TemplateArgumentLoc *operator->() const {
4689 return &Arg;
4690 }
4691 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004692
4693
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004694 TemplateArgumentLocContainerIterator() {}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004695
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004696 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4697 unsigned Index)
4698 : Container(&Container), Index(Index) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004699
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004700 TemplateArgumentLocContainerIterator &operator++() {
4701 ++Index;
4702 return *this;
4703 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004704
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004705 TemplateArgumentLocContainerIterator operator++(int) {
4706 TemplateArgumentLocContainerIterator Old(*this);
4707 ++(*this);
4708 return Old;
4709 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004710
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004711 TemplateArgumentLoc operator*() const {
4712 return Container->getArgLoc(Index);
4713 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004714
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004715 pointer operator->() const {
4716 return pointer(Container->getArgLoc(Index));
4717 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004718
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004719 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004720 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004721 return X.Container == Y.Container && X.Index == Y.Index;
4722 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004723
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004724 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004725 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004726 return !(X == Y);
4727 }
4728 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004729
4730
John McCall43fed0d2010-11-12 08:19:04 +00004731template <typename Derived>
4732QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4733 TypeLocBuilder &TLB,
4734 TemplateSpecializationTypeLoc TL,
4735 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004736 TemplateArgumentListInfo NewTemplateArgs;
4737 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4738 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004739 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4740 ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004741 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004742 ArgIterator(TL, TL.getNumArgs()),
4743 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004744 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004745
John McCall833ca992009-10-29 08:12:44 +00004746 // FIXME: maybe don't rebuild if all the template arguments are the same.
4747
4748 QualType Result =
4749 getDerived().RebuildTemplateSpecializationType(Template,
4750 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004751 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004752
4753 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004754 // Specializations of template template parameters are represented as
4755 // TemplateSpecializationTypes, and substitution of type alias templates
4756 // within a dependent context can transform them into
4757 // DependentTemplateSpecializationTypes.
4758 if (isa<DependentTemplateSpecializationType>(Result)) {
4759 DependentTemplateSpecializationTypeLoc NewTL
4760 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004761 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004762 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004763 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004764 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004765 NewTL.setLAngleLoc(TL.getLAngleLoc());
4766 NewTL.setRAngleLoc(TL.getRAngleLoc());
4767 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4768 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4769 return Result;
4770 }
4771
John McCall833ca992009-10-29 08:12:44 +00004772 TemplateSpecializationTypeLoc NewTL
4773 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004774 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004775 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4776 NewTL.setLAngleLoc(TL.getLAngleLoc());
4777 NewTL.setRAngleLoc(TL.getRAngleLoc());
4778 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4779 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004780 }
Mike Stump1eb44332009-09-09 15:08:12 +00004781
John McCall833ca992009-10-29 08:12:44 +00004782 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004783}
Mike Stump1eb44332009-09-09 15:08:12 +00004784
Douglas Gregora88f09f2011-02-28 17:23:35 +00004785template <typename Derived>
4786QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4787 TypeLocBuilder &TLB,
4788 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004789 TemplateName Template,
4790 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004791 TemplateArgumentListInfo NewTemplateArgs;
4792 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4793 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4794 typedef TemplateArgumentLocContainerIterator<
4795 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004796 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004797 ArgIterator(TL, TL.getNumArgs()),
4798 NewTemplateArgs))
4799 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004800
Douglas Gregora88f09f2011-02-28 17:23:35 +00004801 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier4a9d7952012-08-08 18:46:20 +00004802
Douglas Gregora88f09f2011-02-28 17:23:35 +00004803 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4804 QualType Result
4805 = getSema().Context.getDependentTemplateSpecializationType(
4806 TL.getTypePtr()->getKeyword(),
4807 DTN->getQualifier(),
4808 DTN->getIdentifier(),
4809 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004810
Douglas Gregora88f09f2011-02-28 17:23:35 +00004811 DependentTemplateSpecializationTypeLoc NewTL
4812 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004813 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004814 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004815 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004816 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004817 NewTL.setLAngleLoc(TL.getLAngleLoc());
4818 NewTL.setRAngleLoc(TL.getRAngleLoc());
4819 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4820 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4821 return Result;
4822 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004823
4824 QualType Result
Douglas Gregora88f09f2011-02-28 17:23:35 +00004825 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004826 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004827 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004828
Douglas Gregora88f09f2011-02-28 17:23:35 +00004829 if (!Result.isNull()) {
4830 /// FIXME: Wrap this in an elaborated-type-specifier?
4831 TemplateSpecializationTypeLoc NewTL
4832 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004833 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004834 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004835 NewTL.setLAngleLoc(TL.getLAngleLoc());
4836 NewTL.setRAngleLoc(TL.getRAngleLoc());
4837 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4838 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4839 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004840
Douglas Gregora88f09f2011-02-28 17:23:35 +00004841 return Result;
4842}
4843
Mike Stump1eb44332009-09-09 15:08:12 +00004844template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004845QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004846TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004847 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004848 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004849
Douglas Gregor9e876872011-03-01 18:12:44 +00004850 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004851 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004852 if (TL.getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004853 QualifierLoc
Douglas Gregor9e876872011-03-01 18:12:44 +00004854 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4855 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004856 return QualType();
4857 }
Mike Stump1eb44332009-09-09 15:08:12 +00004858
John McCall43fed0d2010-11-12 08:19:04 +00004859 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4860 if (NamedT.isNull())
4861 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004862
Richard Smith3e4c6c42011-05-05 21:57:07 +00004863 // C++0x [dcl.type.elab]p2:
4864 // If the identifier resolves to a typedef-name or the simple-template-id
4865 // resolves to an alias template specialization, the
4866 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004867 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4868 if (const TemplateSpecializationType *TST =
4869 NamedT->getAs<TemplateSpecializationType>()) {
4870 TemplateName Template = TST->getTemplateName();
4871 if (TypeAliasTemplateDecl *TAT =
4872 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4873 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4874 diag::err_tag_reference_non_tag) << 4;
4875 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4876 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004877 }
4878 }
4879
John McCalla2becad2009-10-21 00:40:46 +00004880 QualType Result = TL.getType();
4881 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004882 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004883 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00004884 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004885 T->getKeyword(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004886 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004887 if (Result.isNull())
4888 return QualType();
4889 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004890
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004891 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004892 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004893 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004894 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004895}
Mike Stump1eb44332009-09-09 15:08:12 +00004896
4897template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004898QualType TreeTransform<Derived>::TransformAttributedType(
4899 TypeLocBuilder &TLB,
4900 AttributedTypeLoc TL) {
4901 const AttributedType *oldType = TL.getTypePtr();
4902 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4903 if (modifiedType.isNull())
4904 return QualType();
4905
4906 QualType result = TL.getType();
4907
4908 // FIXME: dependent operand expressions?
4909 if (getDerived().AlwaysRebuild() ||
4910 modifiedType != oldType->getModifiedType()) {
4911 // TODO: this is really lame; we should really be rebuilding the
4912 // equivalent type from first principles.
4913 QualType equivalentType
4914 = getDerived().TransformType(oldType->getEquivalentType());
4915 if (equivalentType.isNull())
4916 return QualType();
4917 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4918 modifiedType,
4919 equivalentType);
4920 }
4921
4922 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4923 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4924 if (TL.hasAttrOperand())
4925 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4926 if (TL.hasAttrExprOperand())
4927 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4928 else if (TL.hasAttrEnumOperand())
4929 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4930
4931 return result;
4932}
4933
4934template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004935QualType
4936TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4937 ParenTypeLoc TL) {
4938 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4939 if (Inner.isNull())
4940 return QualType();
4941
4942 QualType Result = TL.getType();
4943 if (getDerived().AlwaysRebuild() ||
4944 Inner != TL.getInnerLoc().getType()) {
4945 Result = getDerived().RebuildParenType(Inner);
4946 if (Result.isNull())
4947 return QualType();
4948 }
4949
4950 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4951 NewTL.setLParenLoc(TL.getLParenLoc());
4952 NewTL.setRParenLoc(TL.getRParenLoc());
4953 return Result;
4954}
4955
4956template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004957QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004958 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004959 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004960
Douglas Gregor2494dd02011-03-01 01:34:45 +00004961 NestedNameSpecifierLoc QualifierLoc
4962 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4963 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004964 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004965
John McCall33500952010-06-11 00:33:02 +00004966 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004967 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00004968 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004969 QualifierLoc,
4970 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004971 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004972 if (Result.isNull())
4973 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004974
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004975 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4976 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004977 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4978
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004979 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004980 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004981 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004982 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004983 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004984 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004985 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004986 NewTL.setNameLoc(TL.getNameLoc());
4987 }
John McCalla2becad2009-10-21 00:40:46 +00004988 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004989}
Mike Stump1eb44332009-09-09 15:08:12 +00004990
Douglas Gregor577f75a2009-08-04 16:50:30 +00004991template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004992QualType TreeTransform<Derived>::
4993 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004994 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004995 NestedNameSpecifierLoc QualifierLoc;
4996 if (TL.getQualifierLoc()) {
4997 QualifierLoc
4998 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4999 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00005000 return QualType();
5001 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005002
John McCall43fed0d2010-11-12 08:19:04 +00005003 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005004 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00005005}
5006
5007template<typename Derived>
5008QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005009TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5010 DependentTemplateSpecializationTypeLoc TL,
5011 NestedNameSpecifierLoc QualifierLoc) {
5012 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005013
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005014 TemplateArgumentListInfo NewTemplateArgs;
5015 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5016 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005017
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005018 typedef TemplateArgumentLocContainerIterator<
5019 DependentTemplateSpecializationTypeLoc> ArgIterator;
5020 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5021 ArgIterator(TL, TL.getNumArgs()),
5022 NewTemplateArgs))
5023 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005024
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005025 QualType Result
5026 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5027 QualifierLoc,
5028 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005029 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005030 NewTemplateArgs);
5031 if (Result.isNull())
5032 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005033
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005034 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5035 QualType NamedT = ElabT->getNamedType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005036
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005037 // Copy information relevant to the template specialization.
5038 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005039 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005040 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005041 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005042 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5043 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005044 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005045 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005046
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005047 // Copy information relevant to the elaborated type.
5048 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005049 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005050 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005051 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5052 DependentTemplateSpecializationTypeLoc SpecTL
5053 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005054 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005055 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005056 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005057 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005058 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5059 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005060 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005061 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005062 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005063 TemplateSpecializationTypeLoc SpecTL
5064 = TLB.push<TemplateSpecializationTypeLoc>(Result);
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 }
5072 return Result;
5073}
5074
5075template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00005076QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5077 PackExpansionTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005078 QualType Pattern
5079 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005080 if (Pattern.isNull())
5081 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005082
5083 QualType Result = TL.getType();
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005084 if (getDerived().AlwaysRebuild() ||
5085 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005086 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005087 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00005088 TL.getEllipsisLoc(),
5089 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005090 if (Result.isNull())
5091 return QualType();
5092 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005093
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005094 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5095 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5096 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00005097}
5098
5099template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005100QualType
5101TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005102 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005103 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005104 TLB.pushFullCopy(TL);
5105 return TL.getType();
5106}
5107
5108template<typename Derived>
5109QualType
5110TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005111 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005112 // ObjCObjectType is never dependent.
5113 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005114 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005115}
Mike Stump1eb44332009-09-09 15:08:12 +00005116
5117template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005118QualType
5119TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005120 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005121 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005122 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005123 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005124}
5125
Douglas Gregor577f75a2009-08-04 16:50:30 +00005126//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005127// Statement transformation
5128//===----------------------------------------------------------------------===//
5129template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005130StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005131TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005132 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005133}
5134
5135template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005136StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005137TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5138 return getDerived().TransformCompoundStmt(S, false);
5139}
5140
5141template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005142StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005143TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005144 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005145 Sema::CompoundScopeRAII CompoundScope(getSema());
5146
John McCall7114cba2010-08-27 19:56:05 +00005147 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005148 bool SubStmtChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005149 SmallVector<Stmt*, 8> Statements;
Douglas Gregor43959a92009-08-20 07:17:43 +00005150 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5151 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005152 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005153 if (Result.isInvalid()) {
5154 // Immediately fail if this was a DeclStmt, since it's very
5155 // likely that this will cause problems for future statements.
5156 if (isa<DeclStmt>(*B))
5157 return StmtError();
5158
5159 // Otherwise, just keep processing substatements and fail later.
5160 SubStmtInvalid = true;
5161 continue;
5162 }
Mike Stump1eb44332009-09-09 15:08:12 +00005163
Douglas Gregor43959a92009-08-20 07:17:43 +00005164 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5165 Statements.push_back(Result.takeAs<Stmt>());
5166 }
Mike Stump1eb44332009-09-09 15:08:12 +00005167
John McCall7114cba2010-08-27 19:56:05 +00005168 if (SubStmtInvalid)
5169 return StmtError();
5170
Douglas Gregor43959a92009-08-20 07:17:43 +00005171 if (!getDerived().AlwaysRebuild() &&
5172 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005173 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005174
5175 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005176 Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00005177 S->getRBracLoc(),
5178 IsStmtExpr);
5179}
Mike Stump1eb44332009-09-09 15:08:12 +00005180
Douglas Gregor43959a92009-08-20 07:17:43 +00005181template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005182StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005183TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005184 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005185 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005186 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5187 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005188
Eli Friedman264c1f82009-11-19 03:14:00 +00005189 // Transform the left-hand case value.
5190 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005191 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005192 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005193 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005194
Eli Friedman264c1f82009-11-19 03:14:00 +00005195 // Transform the right-hand case value (for the GNU case-range extension).
5196 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005197 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005198 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005199 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005200 }
Mike Stump1eb44332009-09-09 15:08:12 +00005201
Douglas Gregor43959a92009-08-20 07:17:43 +00005202 // Build the case statement.
5203 // Case statements are always rebuilt so that they will attached to their
5204 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005205 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005206 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005207 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005208 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005209 S->getColonLoc());
5210 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005211 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005212
Douglas Gregor43959a92009-08-20 07:17:43 +00005213 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005214 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005215 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005216 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005217
Douglas Gregor43959a92009-08-20 07:17:43 +00005218 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005219 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005220}
5221
5222template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005223StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005224TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005225 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005226 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005227 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005228 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005229
Douglas Gregor43959a92009-08-20 07:17:43 +00005230 // Default statements are always rebuilt
5231 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005232 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005233}
Mike Stump1eb44332009-09-09 15:08:12 +00005234
Douglas Gregor43959a92009-08-20 07:17:43 +00005235template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005236StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005237TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005238 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005239 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005240 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005241
Chris Lattner57ad3782011-02-17 20:34:02 +00005242 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5243 S->getDecl());
5244 if (!LD)
5245 return StmtError();
Richard Smith534986f2012-04-14 00:33:13 +00005246
5247
Douglas Gregor43959a92009-08-20 07:17:43 +00005248 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005249 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005250 cast<LabelDecl>(LD), SourceLocation(),
5251 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005252}
Mike Stump1eb44332009-09-09 15:08:12 +00005253
Douglas Gregor43959a92009-08-20 07:17:43 +00005254template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005255StmtResult
Richard Smith534986f2012-04-14 00:33:13 +00005256TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5257 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5258 if (SubStmt.isInvalid())
5259 return StmtError();
5260
5261 // TODO: transform attributes
5262 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5263 return S;
5264
5265 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5266 S->getAttrs(),
5267 SubStmt.get());
5268}
5269
5270template<typename Derived>
5271StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005272TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005273 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005274 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005275 VarDecl *ConditionVar = 0;
5276 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005277 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005278 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005279 getDerived().TransformDefinition(
5280 S->getConditionVariable()->getLocation(),
5281 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005282 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005283 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005284 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005285 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005286
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005287 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005288 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005289
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005290 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005291 if (S->getCond()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005292 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005293 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005294 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005295 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005296
John McCall9ae2f072010-08-23 23:25:46 +00005297 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005298 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005299 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005300
John McCall9ae2f072010-08-23 23:25:46 +00005301 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5302 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005303 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005304
Douglas Gregor43959a92009-08-20 07:17:43 +00005305 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005306 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005307 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005308 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005309
Douglas Gregor43959a92009-08-20 07:17:43 +00005310 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005311 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005312 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005313 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005314
Douglas Gregor43959a92009-08-20 07:17:43 +00005315 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005316 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005317 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005318 Then.get() == S->getThen() &&
5319 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005320 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005321
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005322 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005323 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005324 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005325}
5326
5327template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005328StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005329TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005330 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005331 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005332 VarDecl *ConditionVar = 0;
5333 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005334 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005335 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005336 getDerived().TransformDefinition(
5337 S->getConditionVariable()->getLocation(),
5338 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005339 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005340 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005341 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005342 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005343
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005344 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005345 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005346 }
Mike Stump1eb44332009-09-09 15:08:12 +00005347
Douglas Gregor43959a92009-08-20 07:17:43 +00005348 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005349 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005350 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005351 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005352 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005353 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005354
Douglas Gregor43959a92009-08-20 07:17:43 +00005355 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005356 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005357 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005358 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005359
Douglas Gregor43959a92009-08-20 07:17:43 +00005360 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005361 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5362 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005363}
Mike Stump1eb44332009-09-09 15:08:12 +00005364
Douglas Gregor43959a92009-08-20 07:17:43 +00005365template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005366StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005367TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005368 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005369 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005370 VarDecl *ConditionVar = 0;
5371 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005372 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005373 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005374 getDerived().TransformDefinition(
5375 S->getConditionVariable()->getLocation(),
5376 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005377 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005378 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005379 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005380 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005381
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005382 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005383 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005384
5385 if (S->getCond()) {
5386 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005387 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005388 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005389 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005390 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005391 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005392 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005393 }
Mike Stump1eb44332009-09-09 15:08:12 +00005394
John McCall9ae2f072010-08-23 23:25:46 +00005395 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5396 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005397 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005398
Douglas Gregor43959a92009-08-20 07:17:43 +00005399 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005400 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005401 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005402 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005403
Douglas Gregor43959a92009-08-20 07:17:43 +00005404 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005405 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005406 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005407 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005408 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005409
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005410 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005411 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005412}
Mike Stump1eb44332009-09-09 15:08:12 +00005413
Douglas Gregor43959a92009-08-20 07:17:43 +00005414template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005415StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005416TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005417 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005418 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005419 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005420 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005421
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005422 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005423 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005424 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005425 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005426
Douglas Gregor43959a92009-08-20 07:17:43 +00005427 if (!getDerived().AlwaysRebuild() &&
5428 Cond.get() == S->getCond() &&
5429 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005430 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005431
John McCall9ae2f072010-08-23 23:25:46 +00005432 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5433 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005434 S->getRParenLoc());
5435}
Mike Stump1eb44332009-09-09 15:08:12 +00005436
Douglas Gregor43959a92009-08-20 07:17:43 +00005437template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005438StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005439TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005440 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005441 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005442 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005443 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005444
Douglas Gregor43959a92009-08-20 07:17:43 +00005445 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005446 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005447 VarDecl *ConditionVar = 0;
5448 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005449 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005450 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005451 getDerived().TransformDefinition(
5452 S->getConditionVariable()->getLocation(),
5453 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005454 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005455 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005456 } else {
5457 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005458
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005459 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005460 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005461
5462 if (S->getCond()) {
5463 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005464 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005465 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005466 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005467 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005468
John McCall9ae2f072010-08-23 23:25:46 +00005469 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005470 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005471 }
Mike Stump1eb44332009-09-09 15:08:12 +00005472
Chad Rosier4a9d7952012-08-08 18:46:20 +00005473 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCall9ae2f072010-08-23 23:25:46 +00005474 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005475 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005476
Douglas Gregor43959a92009-08-20 07:17:43 +00005477 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005478 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005479 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005480 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005481
Richard Smith41956372013-01-14 22:39:08 +00005482 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCall9ae2f072010-08-23 23:25:46 +00005483 if (S->getInc() && !FullInc.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 body
John McCall60d7b3a2010-08-24 06:29:42 +00005487 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005488 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005489 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005490
Douglas Gregor43959a92009-08-20 07:17:43 +00005491 if (!getDerived().AlwaysRebuild() &&
5492 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005493 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005494 Inc.get() == S->getInc() &&
5495 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005496 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005497
Douglas Gregor43959a92009-08-20 07:17:43 +00005498 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005499 Init.get(), FullCond, ConditionVar,
5500 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005501}
5502
5503template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005504StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005505TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005506 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5507 S->getLabel());
5508 if (!LD)
5509 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005510
Douglas Gregor43959a92009-08-20 07:17:43 +00005511 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005512 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005513 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005514}
5515
5516template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005517StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005518TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005519 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005520 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005521 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005522 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005523
Douglas Gregor43959a92009-08-20 07:17:43 +00005524 if (!getDerived().AlwaysRebuild() &&
5525 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005526 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005527
5528 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005529 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005530}
5531
5532template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005533StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005534TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005535 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005536}
Mike Stump1eb44332009-09-09 15:08:12 +00005537
Douglas Gregor43959a92009-08-20 07:17:43 +00005538template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005539StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005540TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005541 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005542}
Mike Stump1eb44332009-09-09 15:08:12 +00005543
Douglas Gregor43959a92009-08-20 07:17:43 +00005544template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005545StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005546TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005547 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005548 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005549 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005550
Mike Stump1eb44332009-09-09 15:08:12 +00005551 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005552 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005553 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005554}
Mike Stump1eb44332009-09-09 15:08:12 +00005555
Douglas Gregor43959a92009-08-20 07:17:43 +00005556template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005557StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005558TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005559 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005560 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005561 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5562 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005563 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5564 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005565 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005566 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005567
Douglas Gregor43959a92009-08-20 07:17:43 +00005568 if (Transformed != *D)
5569 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005570
Douglas Gregor43959a92009-08-20 07:17:43 +00005571 Decls.push_back(Transformed);
5572 }
Mike Stump1eb44332009-09-09 15:08:12 +00005573
Douglas Gregor43959a92009-08-20 07:17:43 +00005574 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005575 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005576
5577 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005578 S->getStartLoc(), S->getEndLoc());
5579}
Mike Stump1eb44332009-09-09 15:08:12 +00005580
Douglas Gregor43959a92009-08-20 07:17:43 +00005581template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005582StmtResult
Chad Rosierdf5faf52012-08-25 00:11:56 +00005583TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005584
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005585 SmallVector<Expr*, 8> Constraints;
5586 SmallVector<Expr*, 8> Exprs;
Chris Lattner686775d2011-07-20 06:58:45 +00005587 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005588
John McCall60d7b3a2010-08-24 06:29:42 +00005589 ExprResult AsmString;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005590 SmallVector<Expr*, 8> Clobbers;
Anders Carlsson703e3942010-01-24 05:50:09 +00005591
5592 bool ExprsChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005593
Anders Carlsson703e3942010-01-24 05:50:09 +00005594 // Go through the outputs.
5595 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005596 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005597
Anders Carlsson703e3942010-01-24 05:50:09 +00005598 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005599 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005600
Anders Carlsson703e3942010-01-24 05:50:09 +00005601 // Transform the output expr.
5602 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005603 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005604 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005605 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005606
Anders Carlsson703e3942010-01-24 05:50:09 +00005607 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005608
John McCall9ae2f072010-08-23 23:25:46 +00005609 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005610 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005611
Anders Carlsson703e3942010-01-24 05:50:09 +00005612 // Go through the inputs.
5613 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005614 Names.push_back(S->getInputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005615
Anders Carlsson703e3942010-01-24 05:50:09 +00005616 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005617 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005618
Anders Carlsson703e3942010-01-24 05:50:09 +00005619 // Transform the input expr.
5620 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005621 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005622 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005623 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005624
Anders Carlsson703e3942010-01-24 05:50:09 +00005625 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005626
John McCall9ae2f072010-08-23 23:25:46 +00005627 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005628 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005629
Anders Carlsson703e3942010-01-24 05:50:09 +00005630 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005631 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005632
5633 // Go through the clobbers.
5634 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosier5c7f5942012-08-27 23:28:41 +00005635 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005636
5637 // No need to transform the asm string literal.
5638 AsmString = SemaRef.Owned(S->getAsmString());
Chad Rosierdf5faf52012-08-25 00:11:56 +00005639 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5640 S->isVolatile(), S->getNumOutputs(),
5641 S->getNumInputs(), Names.data(),
5642 Constraints, Exprs, AsmString.get(),
5643 Clobbers, S->getRParenLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005644}
5645
Chad Rosier8cd64b42012-06-11 20:47:18 +00005646template<typename Derived>
5647StmtResult
5648TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier79efe242012-08-07 00:29:06 +00005649 ArrayRef<Token> AsmToks =
5650 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier62f22b82012-08-08 19:48:07 +00005651
Chad Rosier7bd092b2012-08-15 16:53:30 +00005652 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
5653 AsmToks, S->getEndLoc());
Chad Rosier8cd64b42012-06-11 20:47:18 +00005654}
Douglas Gregor43959a92009-08-20 07:17:43 +00005655
5656template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005657StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005658TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005659 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005660 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005661 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005662 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005663
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005664 // Transform the @catch statements (if present).
5665 bool AnyCatchChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005666 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005667 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005668 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005669 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005670 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005671 if (Catch.get() != S->getCatchStmt(I))
5672 AnyCatchChanged = true;
5673 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005674 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005675
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005676 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005677 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005678 if (S->getFinallyStmt()) {
5679 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5680 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005681 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005682 }
5683
5684 // If nothing changed, just retain this statement.
5685 if (!getDerived().AlwaysRebuild() &&
5686 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005687 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005688 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005689 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005690
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005691 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005692 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005693 CatchStmts, Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005694}
Mike Stump1eb44332009-09-09 15:08:12 +00005695
Douglas Gregor43959a92009-08-20 07:17:43 +00005696template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005697StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005698TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005699 // Transform the @catch parameter, if there is one.
5700 VarDecl *Var = 0;
5701 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5702 TypeSourceInfo *TSInfo = 0;
5703 if (FromVar->getTypeSourceInfo()) {
5704 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5705 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005706 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005707 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005708
Douglas Gregorbe270a02010-04-26 17:57:08 +00005709 QualType T;
5710 if (TSInfo)
5711 T = TSInfo->getType();
5712 else {
5713 T = getDerived().TransformType(FromVar->getType());
5714 if (T.isNull())
Chad Rosier4a9d7952012-08-08 18:46:20 +00005715 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005716 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005717
Douglas Gregorbe270a02010-04-26 17:57:08 +00005718 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5719 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005720 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005721 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005722
John McCall60d7b3a2010-08-24 06:29:42 +00005723 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005724 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005725 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005726
5727 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005728 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005729 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005730}
Mike Stump1eb44332009-09-09 15:08:12 +00005731
Douglas Gregor43959a92009-08-20 07:17:43 +00005732template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005733StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005734TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005735 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005736 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005737 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005738 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005739
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005740 // If nothing changed, just retain this statement.
5741 if (!getDerived().AlwaysRebuild() &&
5742 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005743 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005744
5745 // Build a new statement.
5746 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005747 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005748}
Mike Stump1eb44332009-09-09 15:08:12 +00005749
Douglas Gregor43959a92009-08-20 07:17:43 +00005750template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005751StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005752TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005753 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005754 if (S->getThrowExpr()) {
5755 Operand = getDerived().TransformExpr(S->getThrowExpr());
5756 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005757 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005758 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005759
Douglas Gregord1377b22010-04-22 21:44:01 +00005760 if (!getDerived().AlwaysRebuild() &&
5761 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005762 return getSema().Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005763
John McCall9ae2f072010-08-23 23:25:46 +00005764 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005765}
Mike Stump1eb44332009-09-09 15:08:12 +00005766
Douglas Gregor43959a92009-08-20 07:17:43 +00005767template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005768StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005769TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005770 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005771 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005772 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005773 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005774 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005775 Object =
5776 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5777 Object.get());
5778 if (Object.isInvalid())
5779 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005780
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005781 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005782 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005783 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005784 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005785
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005786 // If nothing change, just retain the current statement.
5787 if (!getDerived().AlwaysRebuild() &&
5788 Object.get() == S->getSynchExpr() &&
5789 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005790 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005791
5792 // Build a new statement.
5793 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005794 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005795}
5796
5797template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005798StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005799TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5800 ObjCAutoreleasePoolStmt *S) {
5801 // Transform the body.
5802 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5803 if (Body.isInvalid())
5804 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005805
John McCallf85e1932011-06-15 23:02:42 +00005806 // If nothing changed, just retain this statement.
5807 if (!getDerived().AlwaysRebuild() &&
5808 Body.get() == S->getSubStmt())
5809 return SemaRef.Owned(S);
5810
5811 // Build a new statement.
5812 return getDerived().RebuildObjCAutoreleasePoolStmt(
5813 S->getAtLoc(), Body.get());
5814}
5815
5816template<typename Derived>
5817StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005818TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005819 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005820 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005821 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005822 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005823 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005824
Douglas Gregorc3203e72010-04-22 23:10:45 +00005825 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005826 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005827 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005828 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005829
Douglas Gregorc3203e72010-04-22 23:10:45 +00005830 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005831 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005832 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005833 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005834
Douglas Gregorc3203e72010-04-22 23:10:45 +00005835 // If nothing changed, just retain this statement.
5836 if (!getDerived().AlwaysRebuild() &&
5837 Element.get() == S->getElement() &&
5838 Collection.get() == S->getCollection() &&
5839 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005840 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005841
Douglas Gregorc3203e72010-04-22 23:10:45 +00005842 // Build a new statement.
5843 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005844 Element.get(),
5845 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005846 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005847 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005848}
5849
5850
5851template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005852StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005853TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5854 // Transform the exception declaration, if any.
5855 VarDecl *Var = 0;
5856 if (S->getExceptionDecl()) {
5857 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005858 TypeSourceInfo *T = getDerived().TransformType(
5859 ExceptionDecl->getTypeSourceInfo());
5860 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005861 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005862
Douglas Gregor83cb9422010-09-09 17:09:21 +00005863 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005864 ExceptionDecl->getInnerLocStart(),
5865 ExceptionDecl->getLocation(),
5866 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005867 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005868 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005869 }
Mike Stump1eb44332009-09-09 15:08:12 +00005870
Douglas Gregor43959a92009-08-20 07:17:43 +00005871 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005872 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005873 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005874 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005875
Douglas Gregor43959a92009-08-20 07:17:43 +00005876 if (!getDerived().AlwaysRebuild() &&
5877 !Var &&
5878 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005879 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005880
5881 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5882 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005883 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005884}
Mike Stump1eb44332009-09-09 15:08:12 +00005885
Douglas Gregor43959a92009-08-20 07:17:43 +00005886template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005887StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005888TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5889 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005890 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005891 = getDerived().TransformCompoundStmt(S->getTryBlock());
5892 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005893 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005894
Douglas Gregor43959a92009-08-20 07:17:43 +00005895 // Transform the handlers.
5896 bool HandlerChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005897 SmallVector<Stmt*, 8> Handlers;
Douglas Gregor43959a92009-08-20 07:17:43 +00005898 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005899 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005900 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5901 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005902 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005903
Douglas Gregor43959a92009-08-20 07:17:43 +00005904 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5905 Handlers.push_back(Handler.takeAs<Stmt>());
5906 }
Mike Stump1eb44332009-09-09 15:08:12 +00005907
Douglas Gregor43959a92009-08-20 07:17:43 +00005908 if (!getDerived().AlwaysRebuild() &&
5909 TryBlock.get() == S->getTryBlock() &&
5910 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005911 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005912
John McCall9ae2f072010-08-23 23:25:46 +00005913 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005914 Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00005915}
Mike Stump1eb44332009-09-09 15:08:12 +00005916
Richard Smithad762fc2011-04-14 22:09:26 +00005917template<typename Derived>
5918StmtResult
5919TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5920 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5921 if (Range.isInvalid())
5922 return StmtError();
5923
5924 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5925 if (BeginEnd.isInvalid())
5926 return StmtError();
5927
5928 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5929 if (Cond.isInvalid())
5930 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005931 if (Cond.get())
5932 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
5933 if (Cond.isInvalid())
5934 return StmtError();
5935 if (Cond.get())
5936 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005937
5938 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5939 if (Inc.isInvalid())
5940 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005941 if (Inc.get())
5942 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005943
5944 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5945 if (LoopVar.isInvalid())
5946 return StmtError();
5947
5948 StmtResult NewStmt = S;
5949 if (getDerived().AlwaysRebuild() ||
5950 Range.get() != S->getRangeStmt() ||
5951 BeginEnd.get() != S->getBeginEndStmt() ||
5952 Cond.get() != S->getCond() ||
5953 Inc.get() != S->getInc() ||
Douglas Gregor39b60dc2013-05-02 18:35:56 +00005954 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smithad762fc2011-04-14 22:09:26 +00005955 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5956 S->getColonLoc(), Range.get(),
5957 BeginEnd.get(), Cond.get(),
5958 Inc.get(), LoopVar.get(),
5959 S->getRParenLoc());
Douglas Gregor39b60dc2013-05-02 18:35:56 +00005960 if (NewStmt.isInvalid())
5961 return StmtError();
5962 }
Richard Smithad762fc2011-04-14 22:09:26 +00005963
5964 StmtResult Body = getDerived().TransformStmt(S->getBody());
5965 if (Body.isInvalid())
5966 return StmtError();
5967
5968 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5969 // it now so we have a new statement to attach the body to.
Douglas Gregor39b60dc2013-05-02 18:35:56 +00005970 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smithad762fc2011-04-14 22:09:26 +00005971 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5972 S->getColonLoc(), Range.get(),
5973 BeginEnd.get(), Cond.get(),
5974 Inc.get(), LoopVar.get(),
5975 S->getRParenLoc());
Douglas Gregor39b60dc2013-05-02 18:35:56 +00005976 if (NewStmt.isInvalid())
5977 return StmtError();
5978 }
Richard Smithad762fc2011-04-14 22:09:26 +00005979
5980 if (NewStmt.get() == S)
5981 return SemaRef.Owned(S);
5982
5983 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5984}
5985
John Wiegley28bbe4b2011-04-28 01:08:34 +00005986template<typename Derived>
5987StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00005988TreeTransform<Derived>::TransformMSDependentExistsStmt(
5989 MSDependentExistsStmt *S) {
5990 // Transform the nested-name-specifier, if any.
5991 NestedNameSpecifierLoc QualifierLoc;
5992 if (S->getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005993 QualifierLoc
Douglas Gregorba0513d2011-10-25 01:33:02 +00005994 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
5995 if (!QualifierLoc)
5996 return StmtError();
5997 }
5998
5999 // Transform the declaration name.
6000 DeclarationNameInfo NameInfo = S->getNameInfo();
6001 if (NameInfo.getName()) {
6002 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6003 if (!NameInfo.getName())
6004 return StmtError();
6005 }
6006
6007 // Check whether anything changed.
6008 if (!getDerived().AlwaysRebuild() &&
6009 QualifierLoc == S->getQualifierLoc() &&
6010 NameInfo.getName() == S->getNameInfo().getName())
6011 return S;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006012
Douglas Gregorba0513d2011-10-25 01:33:02 +00006013 // Determine whether this name exists, if we can.
6014 CXXScopeSpec SS;
6015 SS.Adopt(QualifierLoc);
6016 bool Dependent = false;
6017 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
6018 case Sema::IER_Exists:
6019 if (S->isIfExists())
6020 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006021
Douglas Gregorba0513d2011-10-25 01:33:02 +00006022 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6023
6024 case Sema::IER_DoesNotExist:
6025 if (S->isIfNotExists())
6026 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006027
Douglas Gregorba0513d2011-10-25 01:33:02 +00006028 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006029
Douglas Gregorba0513d2011-10-25 01:33:02 +00006030 case Sema::IER_Dependent:
6031 Dependent = true;
6032 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006033
Douglas Gregor65019ac2011-10-25 03:44:56 +00006034 case Sema::IER_Error:
6035 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00006036 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006037
Douglas Gregorba0513d2011-10-25 01:33:02 +00006038 // We need to continue with the instantiation, so do so now.
6039 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6040 if (SubStmt.isInvalid())
6041 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006042
Douglas Gregorba0513d2011-10-25 01:33:02 +00006043 // If we have resolved the name, just transform to the substatement.
6044 if (!Dependent)
6045 return SubStmt;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006046
Douglas Gregorba0513d2011-10-25 01:33:02 +00006047 // The name is still dependent, so build a dependent expression again.
6048 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6049 S->isIfExists(),
6050 QualifierLoc,
6051 NameInfo,
6052 SubStmt.get());
6053}
6054
6055template<typename Derived>
John McCall76da55d2013-04-16 07:28:30 +00006056ExprResult
6057TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6058 NestedNameSpecifierLoc QualifierLoc;
6059 if (E->getQualifierLoc()) {
6060 QualifierLoc
6061 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6062 if (!QualifierLoc)
6063 return ExprError();
6064 }
6065
6066 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6067 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6068 if (!PD)
6069 return ExprError();
6070
6071 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6072 if (Base.isInvalid())
6073 return ExprError();
6074
6075 return new (SemaRef.getASTContext())
6076 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6077 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6078 QualifierLoc, E->getMemberLoc());
6079}
6080
6081template<typename Derived>
Douglas Gregorba0513d2011-10-25 01:33:02 +00006082StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00006083TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
6084 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
6085 if(TryBlock.isInvalid()) return StmtError();
6086
6087 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
6088 if(!getDerived().AlwaysRebuild() &&
6089 TryBlock.get() == S->getTryBlock() &&
6090 Handler.get() == S->getHandler())
6091 return SemaRef.Owned(S);
6092
6093 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
6094 S->getTryLoc(),
6095 TryBlock.take(),
6096 Handler.take());
6097}
6098
6099template<typename Derived>
6100StmtResult
6101TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
6102 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6103 if(Block.isInvalid()) return StmtError();
6104
6105 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
6106 Block.take());
6107}
6108
6109template<typename Derived>
6110StmtResult
6111TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
6112 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
6113 if(FilterExpr.isInvalid()) return StmtError();
6114
6115 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6116 if(Block.isInvalid()) return StmtError();
6117
6118 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
6119 FilterExpr.take(),
6120 Block.take());
6121}
6122
6123template<typename Derived>
6124StmtResult
6125TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6126 if(isa<SEHFinallyStmt>(Handler))
6127 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6128 else
6129 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6130}
6131
Douglas Gregor43959a92009-08-20 07:17:43 +00006132//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00006133// Expression transformation
6134//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006135template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006136ExprResult
John McCall454feb92009-12-08 09:21:05 +00006137TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006138 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006139}
Mike Stump1eb44332009-09-09 15:08:12 +00006140
6141template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006142ExprResult
John McCall454feb92009-12-08 09:21:05 +00006143TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006144 NestedNameSpecifierLoc QualifierLoc;
6145 if (E->getQualifierLoc()) {
6146 QualifierLoc
6147 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6148 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006149 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006150 }
John McCalldbd872f2009-12-08 09:08:17 +00006151
6152 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006153 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6154 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006155 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006156 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006157
John McCallec8045d2010-08-17 21:27:17 +00006158 DeclarationNameInfo NameInfo = E->getNameInfo();
6159 if (NameInfo.getName()) {
6160 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6161 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006162 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006163 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006164
6165 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006166 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006167 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006168 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006169 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006170
6171 // Mark it referenced in the new context regardless.
6172 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006173 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006174
John McCall3fa5cae2010-10-26 07:05:15 +00006175 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006176 }
John McCalldbd872f2009-12-08 09:08:17 +00006177
6178 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006179 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006180 TemplateArgs = &TransArgs;
6181 TransArgs.setLAngleLoc(E->getLAngleLoc());
6182 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006183 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6184 E->getNumTemplateArgs(),
6185 TransArgs))
6186 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006187 }
6188
Chad Rosier4a9d7952012-08-08 18:46:20 +00006189 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregor40d96a62011-02-28 21:54:11 +00006190 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006191}
Mike Stump1eb44332009-09-09 15:08:12 +00006192
Douglas Gregorb98b1992009-08-11 05:31:07 +00006193template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006194ExprResult
John McCall454feb92009-12-08 09:21:05 +00006195TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006196 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006197}
Mike Stump1eb44332009-09-09 15:08:12 +00006198
Douglas Gregorb98b1992009-08-11 05:31:07 +00006199template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006200ExprResult
John McCall454feb92009-12-08 09:21:05 +00006201TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006202 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006203}
Mike Stump1eb44332009-09-09 15:08:12 +00006204
Douglas Gregorb98b1992009-08-11 05:31:07 +00006205template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006206ExprResult
John McCall454feb92009-12-08 09:21:05 +00006207TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006208 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006209}
Mike Stump1eb44332009-09-09 15:08:12 +00006210
Douglas Gregorb98b1992009-08-11 05:31:07 +00006211template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006212ExprResult
John McCall454feb92009-12-08 09:21:05 +00006213TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006214 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006215}
Mike Stump1eb44332009-09-09 15:08:12 +00006216
Douglas Gregorb98b1992009-08-11 05:31:07 +00006217template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006218ExprResult
John McCall454feb92009-12-08 09:21:05 +00006219TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006220 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006221}
6222
6223template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006224ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006225TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis391ca9f2013-04-09 01:17:02 +00006226 if (FunctionDecl *FD = E->getDirectCallee())
6227 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smith9fcce652012-03-07 08:35:16 +00006228 return SemaRef.MaybeBindToTemporary(E);
6229}
6230
6231template<typename Derived>
6232ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006233TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6234 ExprResult ControllingExpr =
6235 getDerived().TransformExpr(E->getControllingExpr());
6236 if (ControllingExpr.isInvalid())
6237 return ExprError();
6238
Chris Lattner686775d2011-07-20 06:58:45 +00006239 SmallVector<Expr *, 4> AssocExprs;
6240 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006241 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6242 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6243 if (TS) {
6244 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6245 if (!AssocType)
6246 return ExprError();
6247 AssocTypes.push_back(AssocType);
6248 } else {
6249 AssocTypes.push_back(0);
6250 }
6251
6252 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6253 if (AssocExpr.isInvalid())
6254 return ExprError();
6255 AssocExprs.push_back(AssocExpr.release());
6256 }
6257
6258 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6259 E->getDefaultLoc(),
6260 E->getRParenLoc(),
6261 ControllingExpr.release(),
6262 AssocTypes.data(),
6263 AssocExprs.data(),
6264 E->getNumAssocs());
6265}
6266
6267template<typename Derived>
6268ExprResult
John McCall454feb92009-12-08 09:21:05 +00006269TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006270 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006271 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006272 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006273
Douglas Gregorb98b1992009-08-11 05:31:07 +00006274 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006275 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006276
John McCall9ae2f072010-08-23 23:25:46 +00006277 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006278 E->getRParen());
6279}
6280
Richard Smithefeeccf2012-10-21 03:28:35 +00006281/// \brief The operand of a unary address-of operator has special rules: it's
6282/// allowed to refer to a non-static member of a class even if there's no 'this'
6283/// object available.
6284template<typename Derived>
6285ExprResult
6286TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6287 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6288 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6289 else
6290 return getDerived().TransformExpr(E);
6291}
6292
Mike Stump1eb44332009-09-09 15:08:12 +00006293template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006294ExprResult
John McCall454feb92009-12-08 09:21:05 +00006295TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smithefeeccf2012-10-21 03:28:35 +00006296 ExprResult SubExpr = TransformAddressOfOperand(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006297 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006298 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006299
Douglas Gregorb98b1992009-08-11 05:31:07 +00006300 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006301 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006302
Douglas Gregorb98b1992009-08-11 05:31:07 +00006303 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6304 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006305 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006306}
Mike Stump1eb44332009-09-09 15:08:12 +00006307
Douglas Gregorb98b1992009-08-11 05:31:07 +00006308template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006309ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006310TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6311 // Transform the type.
6312 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6313 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006314 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006315
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006316 // Transform all of the components into components similar to what the
6317 // parser uses.
Chad Rosier4a9d7952012-08-08 18:46:20 +00006318 // FIXME: It would be slightly more efficient in the non-dependent case to
6319 // just map FieldDecls, rather than requiring the rebuilder to look for
6320 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006321 // template code that we don't care.
6322 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006323 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006324 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006325 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006326 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6327 const Node &ON = E->getComponent(I);
6328 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006329 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006330 Comp.LocStart = ON.getSourceRange().getBegin();
6331 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006332 switch (ON.getKind()) {
6333 case Node::Array: {
6334 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006335 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006336 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006337 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006338
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006339 ExprChanged = ExprChanged || Index.get() != FromIndex;
6340 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006341 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006342 break;
6343 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006344
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006345 case Node::Field:
6346 case Node::Identifier:
6347 Comp.isBrackets = false;
6348 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006349 if (!Comp.U.IdentInfo)
6350 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006351
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006352 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006353
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006354 case Node::Base:
6355 // Will be recomputed during the rebuild.
6356 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006357 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006358
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006359 Components.push_back(Comp);
6360 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006361
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006362 // If nothing changed, retain the existing expression.
6363 if (!getDerived().AlwaysRebuild() &&
6364 Type == E->getTypeSourceInfo() &&
6365 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006366 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006367
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006368 // Build a new offsetof expression.
6369 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6370 Components.data(), Components.size(),
6371 E->getRParenLoc());
6372}
6373
6374template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006375ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006376TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6377 assert(getDerived().AlreadyTransformed(E->getType()) &&
6378 "opaque value expression requires transformation");
6379 return SemaRef.Owned(E);
6380}
6381
6382template<typename Derived>
6383ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006384TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006385 // Rebuild the syntactic form. The original syntactic form has
6386 // opaque-value expressions in it, so strip those away and rebuild
6387 // the result. This is a really awful way of doing this, but the
6388 // better solution (rebuilding the semantic expressions and
6389 // rebinding OVEs as necessary) doesn't work; we'd need
6390 // TreeTransform to not strip away implicit conversions.
6391 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6392 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006393 if (result.isInvalid()) return ExprError();
6394
6395 // If that gives us a pseudo-object result back, the pseudo-object
6396 // expression must have been an lvalue-to-rvalue conversion which we
6397 // should reapply.
6398 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6399 result = SemaRef.checkPseudoObjectRValue(result.take());
6400
6401 return result;
6402}
6403
6404template<typename Derived>
6405ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006406TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6407 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006408 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006409 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006410
John McCalla93c9342009-12-07 02:54:59 +00006411 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006412 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006413 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006414
John McCall5ab75172009-11-04 07:28:41 +00006415 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006416 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006417
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006418 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6419 E->getKind(),
6420 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006421 }
Mike Stump1eb44332009-09-09 15:08:12 +00006422
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006423 // C++0x [expr.sizeof]p1:
6424 // The operand is either an expression, which is an unevaluated operand
6425 // [...]
Eli Friedman80bfa3d2012-09-26 04:34:21 +00006426 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6427 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00006428
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006429 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6430 if (SubExpr.isInvalid())
6431 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006432
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006433 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6434 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006435
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006436 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6437 E->getOperatorLoc(),
6438 E->getKind(),
6439 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006440}
Mike Stump1eb44332009-09-09 15:08:12 +00006441
Douglas Gregorb98b1992009-08-11 05:31:07 +00006442template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006443ExprResult
John McCall454feb92009-12-08 09:21:05 +00006444TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006445 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006446 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006447 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006448
John McCall60d7b3a2010-08-24 06:29:42 +00006449 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006450 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006451 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006452
6453
Douglas Gregorb98b1992009-08-11 05:31:07 +00006454 if (!getDerived().AlwaysRebuild() &&
6455 LHS.get() == E->getLHS() &&
6456 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006457 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006458
John McCall9ae2f072010-08-23 23:25:46 +00006459 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006460 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006461 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006462 E->getRBracketLoc());
6463}
Mike Stump1eb44332009-09-09 15:08:12 +00006464
6465template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006466ExprResult
John McCall454feb92009-12-08 09:21:05 +00006467TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006468 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006469 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006470 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006471 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006472
6473 // Transform arguments.
6474 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006475 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006476 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006477 &ArgChanged))
6478 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006479
Douglas Gregorb98b1992009-08-11 05:31:07 +00006480 if (!getDerived().AlwaysRebuild() &&
6481 Callee.get() == E->getCallee() &&
6482 !ArgChanged)
Dmitri Gribenko1ad23d62012-09-10 21:20:09 +00006483 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006484
Douglas Gregorb98b1992009-08-11 05:31:07 +00006485 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006486 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006487 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006488 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006489 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006490 E->getRParenLoc());
6491}
Mike Stump1eb44332009-09-09 15:08:12 +00006492
6493template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006494ExprResult
John McCall454feb92009-12-08 09:21:05 +00006495TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006496 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006497 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006498 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006499
Douglas Gregor40d96a62011-02-28 21:54:11 +00006500 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006501 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006502 QualifierLoc
6503 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006504
Douglas Gregor40d96a62011-02-28 21:54:11 +00006505 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006506 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006507 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006508 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006509
Eli Friedmanf595cc42009-12-04 06:40:45 +00006510 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006511 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6512 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006513 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006514 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006515
John McCall6bb80172010-03-30 21:47:33 +00006516 NamedDecl *FoundDecl = E->getFoundDecl();
6517 if (FoundDecl == E->getMemberDecl()) {
6518 FoundDecl = Member;
6519 } else {
6520 FoundDecl = cast_or_null<NamedDecl>(
6521 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6522 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006523 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006524 }
6525
Douglas Gregorb98b1992009-08-11 05:31:07 +00006526 if (!getDerived().AlwaysRebuild() &&
6527 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006528 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006529 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006530 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006531 !E->hasExplicitTemplateArgs()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006532
Anders Carlsson1f240322009-12-22 05:24:09 +00006533 // Mark it referenced in the new context regardless.
6534 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006535 SemaRef.MarkMemberReferenced(E);
6536
John McCall3fa5cae2010-10-26 07:05:15 +00006537 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006538 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006539
John McCalld5532b62009-11-23 01:53:49 +00006540 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006541 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006542 TransArgs.setLAngleLoc(E->getLAngleLoc());
6543 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006544 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6545 E->getNumTemplateArgs(),
6546 TransArgs))
6547 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006548 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006549
Douglas Gregorb98b1992009-08-11 05:31:07 +00006550 // FIXME: Bogus source location for the operator
6551 SourceLocation FakeOperatorLoc
6552 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6553
John McCallc2233c52010-01-15 08:34:02 +00006554 // FIXME: to do this check properly, we will need to preserve the
6555 // first-qualifier-in-scope here, just in case we had a dependent
6556 // base (and therefore couldn't do the check) and a
6557 // nested-name-qualifier (and therefore could do the lookup).
6558 NamedDecl *FirstQualifierInScope = 0;
6559
John McCall9ae2f072010-08-23 23:25:46 +00006560 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006561 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006562 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006563 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006564 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006565 Member,
John McCall6bb80172010-03-30 21:47:33 +00006566 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006567 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006568 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006569 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006570}
Mike Stump1eb44332009-09-09 15:08:12 +00006571
Douglas Gregorb98b1992009-08-11 05:31:07 +00006572template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006573ExprResult
John McCall454feb92009-12-08 09:21:05 +00006574TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006575 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006576 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006577 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006578
John McCall60d7b3a2010-08-24 06:29:42 +00006579 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006580 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006581 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006582
Douglas Gregorb98b1992009-08-11 05:31:07 +00006583 if (!getDerived().AlwaysRebuild() &&
6584 LHS.get() == E->getLHS() &&
6585 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006586 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006587
Lang Hamesbe9af122012-10-02 04:45:10 +00006588 Sema::FPContractStateRAII FPContractState(getSema());
6589 getSema().FPFeatures.fp_contract = E->isFPContractable();
6590
Douglas Gregorb98b1992009-08-11 05:31:07 +00006591 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006592 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006593}
6594
Mike Stump1eb44332009-09-09 15:08:12 +00006595template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006596ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006597TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006598 CompoundAssignOperator *E) {
6599 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006600}
Mike Stump1eb44332009-09-09 15:08:12 +00006601
Douglas Gregorb98b1992009-08-11 05:31:07 +00006602template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006603ExprResult TreeTransform<Derived>::
6604TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6605 // Just rebuild the common and RHS expressions and see whether we
6606 // get any changes.
6607
6608 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6609 if (commonExpr.isInvalid())
6610 return ExprError();
6611
6612 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6613 if (rhs.isInvalid())
6614 return ExprError();
6615
6616 if (!getDerived().AlwaysRebuild() &&
6617 commonExpr.get() == e->getCommon() &&
6618 rhs.get() == e->getFalseExpr())
6619 return SemaRef.Owned(e);
6620
6621 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6622 e->getQuestionLoc(),
6623 0,
6624 e->getColonLoc(),
6625 rhs.get());
6626}
6627
6628template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006629ExprResult
John McCall454feb92009-12-08 09:21:05 +00006630TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006631 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006632 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006633 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006634
John McCall60d7b3a2010-08-24 06:29:42 +00006635 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006636 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006637 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006638
John McCall60d7b3a2010-08-24 06:29:42 +00006639 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006640 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006641 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006642
Douglas Gregorb98b1992009-08-11 05:31:07 +00006643 if (!getDerived().AlwaysRebuild() &&
6644 Cond.get() == E->getCond() &&
6645 LHS.get() == E->getLHS() &&
6646 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006647 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006648
John McCall9ae2f072010-08-23 23:25:46 +00006649 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006650 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006651 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006652 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006653 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006654}
Mike Stump1eb44332009-09-09 15:08:12 +00006655
6656template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006657ExprResult
John McCall454feb92009-12-08 09:21:05 +00006658TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006659 // Implicit casts are eliminated during transformation, since they
6660 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006661 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006662}
Mike Stump1eb44332009-09-09 15:08:12 +00006663
Douglas Gregorb98b1992009-08-11 05:31:07 +00006664template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006665ExprResult
John McCall454feb92009-12-08 09:21:05 +00006666TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006667 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6668 if (!Type)
6669 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006670
John McCall60d7b3a2010-08-24 06:29:42 +00006671 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006672 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006673 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006674 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006675
Douglas Gregorb98b1992009-08-11 05:31:07 +00006676 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006677 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006678 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006679 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006680
John McCall9d125032010-01-15 18:39:57 +00006681 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006682 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006683 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006684 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006685}
Mike Stump1eb44332009-09-09 15:08:12 +00006686
Douglas Gregorb98b1992009-08-11 05:31:07 +00006687template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006688ExprResult
John McCall454feb92009-12-08 09:21:05 +00006689TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006690 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6691 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6692 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006693 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006694
John McCall60d7b3a2010-08-24 06:29:42 +00006695 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006696 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006697 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006698
Douglas Gregorb98b1992009-08-11 05:31:07 +00006699 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006700 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006701 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006702 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006703
John McCall1d7d8d62010-01-19 22:33:45 +00006704 // Note: the expression type doesn't necessarily match the
6705 // type-as-written, but that's okay, because it should always be
6706 // derivable from the initializer.
6707
John McCall42f56b52010-01-18 19:35:47 +00006708 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006709 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006710 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006711}
Mike Stump1eb44332009-09-09 15:08:12 +00006712
Douglas Gregorb98b1992009-08-11 05:31:07 +00006713template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006714ExprResult
John McCall454feb92009-12-08 09:21:05 +00006715TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006716 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006717 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006718 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006719
Douglas Gregorb98b1992009-08-11 05:31:07 +00006720 if (!getDerived().AlwaysRebuild() &&
6721 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006722 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006723
Douglas Gregorb98b1992009-08-11 05:31:07 +00006724 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006725 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006726 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006727 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006728 E->getAccessorLoc(),
6729 E->getAccessor());
6730}
Mike Stump1eb44332009-09-09 15:08:12 +00006731
Douglas Gregorb98b1992009-08-11 05:31:07 +00006732template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006733ExprResult
John McCall454feb92009-12-08 09:21:05 +00006734TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006735 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006736
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006737 SmallVector<Expr*, 4> Inits;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006738 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006739 Inits, &InitChanged))
6740 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006741
Douglas Gregorb98b1992009-08-11 05:31:07 +00006742 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006743 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006744
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006745 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00006746 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006747}
Mike Stump1eb44332009-09-09 15:08:12 +00006748
Douglas Gregorb98b1992009-08-11 05:31:07 +00006749template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006750ExprResult
John McCall454feb92009-12-08 09:21:05 +00006751TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006752 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006753
Douglas Gregor43959a92009-08-20 07:17:43 +00006754 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006755 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006756 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006757 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006758
Douglas Gregor43959a92009-08-20 07:17:43 +00006759 // transform the designators.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006760 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006761 bool ExprChanged = false;
6762 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6763 DEnd = E->designators_end();
6764 D != DEnd; ++D) {
6765 if (D->isFieldDesignator()) {
6766 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6767 D->getDotLoc(),
6768 D->getFieldLoc()));
6769 continue;
6770 }
Mike Stump1eb44332009-09-09 15:08:12 +00006771
Douglas Gregorb98b1992009-08-11 05:31:07 +00006772 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006773 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006774 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006775 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006776
6777 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006778 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006779
Douglas Gregorb98b1992009-08-11 05:31:07 +00006780 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6781 ArrayExprs.push_back(Index.release());
6782 continue;
6783 }
Mike Stump1eb44332009-09-09 15:08:12 +00006784
Douglas Gregorb98b1992009-08-11 05:31:07 +00006785 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006786 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006787 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6788 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006789 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006790
John McCall60d7b3a2010-08-24 06:29:42 +00006791 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006792 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006793 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006794
6795 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006796 End.get(),
6797 D->getLBracketLoc(),
6798 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006799
Douglas Gregorb98b1992009-08-11 05:31:07 +00006800 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6801 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006802
Douglas Gregorb98b1992009-08-11 05:31:07 +00006803 ArrayExprs.push_back(Start.release());
6804 ArrayExprs.push_back(End.release());
6805 }
Mike Stump1eb44332009-09-09 15:08:12 +00006806
Douglas Gregorb98b1992009-08-11 05:31:07 +00006807 if (!getDerived().AlwaysRebuild() &&
6808 Init.get() == E->getInit() &&
6809 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006810 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006811
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006812 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006813 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006814 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006815}
Mike Stump1eb44332009-09-09 15:08:12 +00006816
Douglas Gregorb98b1992009-08-11 05:31:07 +00006817template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006818ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006819TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006820 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006821 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006822
Douglas Gregor5557b252009-10-28 00:29:27 +00006823 // FIXME: Will we ever have proper type location here? Will we actually
6824 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006825 QualType T = getDerived().TransformType(E->getType());
6826 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006827 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006828
Douglas Gregorb98b1992009-08-11 05:31:07 +00006829 if (!getDerived().AlwaysRebuild() &&
6830 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006831 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006832
Douglas Gregorb98b1992009-08-11 05:31:07 +00006833 return getDerived().RebuildImplicitValueInitExpr(T);
6834}
Mike Stump1eb44332009-09-09 15:08:12 +00006835
Douglas Gregorb98b1992009-08-11 05:31:07 +00006836template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006837ExprResult
John McCall454feb92009-12-08 09:21:05 +00006838TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006839 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6840 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006841 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006842
John McCall60d7b3a2010-08-24 06:29:42 +00006843 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006844 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006845 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006846
Douglas Gregorb98b1992009-08-11 05:31:07 +00006847 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006848 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006849 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006850 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006851
John McCall9ae2f072010-08-23 23:25:46 +00006852 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006853 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006854}
6855
6856template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006857ExprResult
John McCall454feb92009-12-08 09:21:05 +00006858TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006859 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006860 SmallVector<Expr*, 4> Inits;
Douglas Gregoraa165f82011-01-03 19:04:46 +00006861 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6862 &ArgumentChanged))
6863 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006864
Douglas Gregorb98b1992009-08-11 05:31:07 +00006865 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006866 Inits,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006867 E->getRParenLoc());
6868}
Mike Stump1eb44332009-09-09 15:08:12 +00006869
Douglas Gregorb98b1992009-08-11 05:31:07 +00006870/// \brief Transform an address-of-label expression.
6871///
6872/// By default, the transformation of an address-of-label expression always
6873/// rebuilds the expression, so that the label identifier can be resolved to
6874/// the corresponding label statement by semantic analysis.
6875template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006876ExprResult
John McCall454feb92009-12-08 09:21:05 +00006877TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006878 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6879 E->getLabel());
6880 if (!LD)
6881 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006882
Douglas Gregorb98b1992009-08-11 05:31:07 +00006883 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006884 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006885}
Mike Stump1eb44332009-09-09 15:08:12 +00006886
6887template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00006888ExprResult
John McCall454feb92009-12-08 09:21:05 +00006889TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00006890 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00006891 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006892 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00006893 if (SubStmt.isInvalid()) {
6894 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00006895 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00006896 }
Mike Stump1eb44332009-09-09 15:08:12 +00006897
Douglas Gregorb98b1992009-08-11 05:31:07 +00006898 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00006899 SubStmt.get() == E->getSubStmt()) {
6900 // Calling this an 'error' is unintuitive, but it does the right thing.
6901 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00006902 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00006903 }
Mike Stump1eb44332009-09-09 15:08:12 +00006904
6905 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006906 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006907 E->getRParenLoc());
6908}
Mike Stump1eb44332009-09-09 15:08:12 +00006909
Douglas Gregorb98b1992009-08-11 05:31:07 +00006910template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006911ExprResult
John McCall454feb92009-12-08 09:21:05 +00006912TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006913 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006914 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006915 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006916
John McCall60d7b3a2010-08-24 06:29:42 +00006917 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006918 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006919 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006920
John McCall60d7b3a2010-08-24 06:29:42 +00006921 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006922 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006923 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006924
Douglas Gregorb98b1992009-08-11 05:31:07 +00006925 if (!getDerived().AlwaysRebuild() &&
6926 Cond.get() == E->getCond() &&
6927 LHS.get() == E->getLHS() &&
6928 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006929 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006930
Douglas Gregorb98b1992009-08-11 05:31:07 +00006931 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006932 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006933 E->getRParenLoc());
6934}
Mike Stump1eb44332009-09-09 15:08:12 +00006935
Douglas Gregorb98b1992009-08-11 05:31:07 +00006936template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006937ExprResult
John McCall454feb92009-12-08 09:21:05 +00006938TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006939 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006940}
6941
6942template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006943ExprResult
John McCall454feb92009-12-08 09:21:05 +00006944TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006945 switch (E->getOperator()) {
6946 case OO_New:
6947 case OO_Delete:
6948 case OO_Array_New:
6949 case OO_Array_Delete:
6950 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier4a9d7952012-08-08 18:46:20 +00006951
Douglas Gregor668d6d92009-12-13 20:44:55 +00006952 case OO_Call: {
6953 // This is a call to an object's operator().
6954 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6955
6956 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006957 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006958 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006959 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006960
6961 // FIXME: Poor location information
6962 SourceLocation FakeLParenLoc
6963 = SemaRef.PP.getLocForEndOfToken(
6964 static_cast<Expr *>(Object.get())->getLocEnd());
6965
6966 // Transform the call arguments.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006967 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006968 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006969 Args))
6970 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006971
John McCall9ae2f072010-08-23 23:25:46 +00006972 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006973 Args,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006974 E->getLocEnd());
6975 }
6976
6977#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6978 case OO_##Name:
6979#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6980#include "clang/Basic/OperatorKinds.def"
6981 case OO_Subscript:
6982 // Handled below.
6983 break;
6984
6985 case OO_Conditional:
6986 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006987
6988 case OO_None:
6989 case NUM_OVERLOADED_OPERATORS:
6990 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006991 }
6992
John McCall60d7b3a2010-08-24 06:29:42 +00006993 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006994 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006995 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006996
Richard Smithefeeccf2012-10-21 03:28:35 +00006997 ExprResult First;
6998 if (E->getOperator() == OO_Amp)
6999 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7000 else
7001 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007002 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007003 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007004
John McCall60d7b3a2010-08-24 06:29:42 +00007005 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00007006 if (E->getNumArgs() == 2) {
7007 Second = getDerived().TransformExpr(E->getArg(1));
7008 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007009 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007010 }
Mike Stump1eb44332009-09-09 15:08:12 +00007011
Douglas Gregorb98b1992009-08-11 05:31:07 +00007012 if (!getDerived().AlwaysRebuild() &&
7013 Callee.get() == E->getCallee() &&
7014 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00007015 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00007016 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007017
Lang Hamesbe9af122012-10-02 04:45:10 +00007018 Sema::FPContractStateRAII FPContractState(getSema());
7019 getSema().FPFeatures.fp_contract = E->isFPContractable();
7020
Douglas Gregorb98b1992009-08-11 05:31:07 +00007021 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7022 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007023 Callee.get(),
7024 First.get(),
7025 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007026}
Mike Stump1eb44332009-09-09 15:08:12 +00007027
Douglas Gregorb98b1992009-08-11 05:31:07 +00007028template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007029ExprResult
John McCall454feb92009-12-08 09:21:05 +00007030TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7031 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007032}
Mike Stump1eb44332009-09-09 15:08:12 +00007033
Douglas Gregorb98b1992009-08-11 05:31:07 +00007034template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007035ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00007036TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7037 // Transform the callee.
7038 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7039 if (Callee.isInvalid())
7040 return ExprError();
7041
7042 // Transform exec config.
7043 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7044 if (EC.isInvalid())
7045 return ExprError();
7046
7047 // Transform arguments.
7048 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007049 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007050 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007051 &ArgChanged))
7052 return ExprError();
7053
7054 if (!getDerived().AlwaysRebuild() &&
7055 Callee.get() == E->getCallee() &&
7056 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00007057 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00007058
7059 // FIXME: Wrong source location information for the '('.
7060 SourceLocation FakeLParenLoc
7061 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7062 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007063 Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007064 E->getRParenLoc(), EC.get());
7065}
7066
7067template<typename Derived>
7068ExprResult
John McCall454feb92009-12-08 09:21:05 +00007069TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007070 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7071 if (!Type)
7072 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007073
John McCall60d7b3a2010-08-24 06:29:42 +00007074 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007075 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007076 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007077 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007078
Douglas Gregorb98b1992009-08-11 05:31:07 +00007079 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007080 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007081 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007082 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007083 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00007084 E->getStmtClass(),
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007085 E->getAngleBrackets().getBegin(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007086 Type,
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007087 E->getAngleBrackets().getEnd(),
7088 // FIXME. this should be '(' location
7089 E->getAngleBrackets().getEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00007090 SubExpr.get(),
Abramo Bagnara6cf7d7d2012-10-15 21:08:58 +00007091 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007092}
Mike Stump1eb44332009-09-09 15:08:12 +00007093
Douglas Gregorb98b1992009-08-11 05:31:07 +00007094template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007095ExprResult
John McCall454feb92009-12-08 09:21:05 +00007096TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7097 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007098}
Mike Stump1eb44332009-09-09 15:08:12 +00007099
7100template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007101ExprResult
John McCall454feb92009-12-08 09:21:05 +00007102TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7103 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007104}
7105
Douglas Gregorb98b1992009-08-11 05:31:07 +00007106template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007107ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007108TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007109 CXXReinterpretCastExpr *E) {
7110 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007111}
Mike Stump1eb44332009-09-09 15:08:12 +00007112
Douglas Gregorb98b1992009-08-11 05:31:07 +00007113template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007114ExprResult
John McCall454feb92009-12-08 09:21:05 +00007115TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7116 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007117}
Mike Stump1eb44332009-09-09 15:08:12 +00007118
Douglas Gregorb98b1992009-08-11 05:31:07 +00007119template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007120ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007121TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007122 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007123 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7124 if (!Type)
7125 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007126
John McCall60d7b3a2010-08-24 06:29:42 +00007127 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007128 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007129 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007130 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007131
Douglas Gregorb98b1992009-08-11 05:31:07 +00007132 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007133 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007134 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007135 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007136
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007137 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007138 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007139 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007140 E->getRParenLoc());
7141}
Mike Stump1eb44332009-09-09 15:08:12 +00007142
Douglas Gregorb98b1992009-08-11 05:31:07 +00007143template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007144ExprResult
John McCall454feb92009-12-08 09:21:05 +00007145TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007146 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007147 TypeSourceInfo *TInfo
7148 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7149 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007150 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007151
Douglas Gregorb98b1992009-08-11 05:31:07 +00007152 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007153 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007154 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007155
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007156 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7157 E->getLocStart(),
7158 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007159 E->getLocEnd());
7160 }
Mike Stump1eb44332009-09-09 15:08:12 +00007161
Eli Friedmanef331b72012-01-20 01:26:23 +00007162 // We don't know whether the subexpression is potentially evaluated until
7163 // after we perform semantic analysis. We speculatively assume it is
7164 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007165 // potentially evaluated.
Eli Friedman80bfa3d2012-09-26 04:34:21 +00007166 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7167 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00007168
John McCall60d7b3a2010-08-24 06:29:42 +00007169 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007170 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007171 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007172
Douglas Gregorb98b1992009-08-11 05:31:07 +00007173 if (!getDerived().AlwaysRebuild() &&
7174 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007175 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007176
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007177 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7178 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007179 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007180 E->getLocEnd());
7181}
7182
7183template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007184ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007185TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7186 if (E->isTypeOperand()) {
7187 TypeSourceInfo *TInfo
7188 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7189 if (!TInfo)
7190 return ExprError();
7191
7192 if (!getDerived().AlwaysRebuild() &&
7193 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007194 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007195
Douglas Gregor3c52a212011-03-06 17:40:41 +00007196 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007197 E->getLocStart(),
7198 TInfo,
7199 E->getLocEnd());
7200 }
7201
Francois Pichet01b7c302010-09-08 12:20:18 +00007202 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7203
7204 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7205 if (SubExpr.isInvalid())
7206 return ExprError();
7207
7208 if (!getDerived().AlwaysRebuild() &&
7209 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007210 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007211
7212 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7213 E->getLocStart(),
7214 SubExpr.get(),
7215 E->getLocEnd());
7216}
7217
7218template<typename Derived>
7219ExprResult
John McCall454feb92009-12-08 09:21:05 +00007220TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007221 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007222}
Mike Stump1eb44332009-09-09 15:08:12 +00007223
Douglas Gregorb98b1992009-08-11 05:31:07 +00007224template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007225ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007226TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007227 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007228 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007229}
Mike Stump1eb44332009-09-09 15:08:12 +00007230
Douglas Gregorb98b1992009-08-11 05:31:07 +00007231template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007232ExprResult
John McCall454feb92009-12-08 09:21:05 +00007233TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007234 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00007235 QualType T;
7236 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
7237 T = MD->getThisType(getSema().Context);
Douglas Gregore4743be2013-03-08 22:43:48 +00007238 else if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(DC)) {
Richard Smith7a614d82011-06-11 17:19:42 +00007239 T = getSema().Context.getPointerType(
Douglas Gregore4743be2013-03-08 22:43:48 +00007240 getSema().Context.getRecordType(Record));
7241 } else {
7242 assert(SemaRef.Context.getDiagnostics().hasErrorOccurred() &&
7243 "this in the wrong scope?");
7244 return ExprError();
7245 }
Mike Stump1eb44332009-09-09 15:08:12 +00007246
Douglas Gregorec79d872012-02-24 17:41:38 +00007247 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7248 // Make sure that we capture 'this'.
7249 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007250 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007251 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007252
Douglas Gregor828a1972010-01-07 23:12:05 +00007253 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007254}
Mike Stump1eb44332009-09-09 15:08:12 +00007255
Douglas Gregorb98b1992009-08-11 05:31:07 +00007256template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007257ExprResult
John McCall454feb92009-12-08 09:21:05 +00007258TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007259 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007260 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007261 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007262
Douglas Gregorb98b1992009-08-11 05:31:07 +00007263 if (!getDerived().AlwaysRebuild() &&
7264 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007265 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007266
Douglas Gregorbca01b42011-07-06 22:04:06 +00007267 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7268 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007269}
Mike Stump1eb44332009-09-09 15:08:12 +00007270
Douglas Gregorb98b1992009-08-11 05:31:07 +00007271template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007272ExprResult
John McCall454feb92009-12-08 09:21:05 +00007273TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007274 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007275 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7276 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007277 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007278 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007279
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007280 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007281 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007282 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007283
Douglas Gregor036aed12009-12-23 23:03:06 +00007284 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007285}
Mike Stump1eb44332009-09-09 15:08:12 +00007286
Douglas Gregorb98b1992009-08-11 05:31:07 +00007287template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007288ExprResult
Richard Smithc3bf52c2013-04-20 22:23:05 +00007289TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
7290 FieldDecl *Field
7291 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
7292 E->getField()));
7293 if (!Field)
7294 return ExprError();
7295
7296 if (!getDerived().AlwaysRebuild() && Field == E->getField())
7297 return SemaRef.Owned(E);
7298
7299 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
7300}
7301
7302template<typename Derived>
7303ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007304TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7305 CXXScalarValueInitExpr *E) {
7306 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7307 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007308 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007309
Douglas Gregorb98b1992009-08-11 05:31:07 +00007310 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007311 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007312 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007313
Chad Rosier4a9d7952012-08-08 18:46:20 +00007314 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregorab6677e2010-09-08 00:15:04 +00007315 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007316 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007317}
Mike Stump1eb44332009-09-09 15:08:12 +00007318
Douglas Gregorb98b1992009-08-11 05:31:07 +00007319template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007320ExprResult
John McCall454feb92009-12-08 09:21:05 +00007321TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007322 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007323 TypeSourceInfo *AllocTypeInfo
7324 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7325 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007326 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007327
Douglas Gregorb98b1992009-08-11 05:31:07 +00007328 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007329 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007330 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007331 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007332
Douglas Gregorb98b1992009-08-11 05:31:07 +00007333 // Transform the placement arguments (if any).
7334 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007335 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007336 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregoraa165f82011-01-03 19:04:46 +00007337 E->getNumPlacementArgs(), true,
7338 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007339 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007340
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007341 // Transform the initializer (if any).
7342 Expr *OldInit = E->getInitializer();
7343 ExprResult NewInit;
7344 if (OldInit)
7345 NewInit = getDerived().TransformExpr(OldInit);
7346 if (NewInit.isInvalid())
7347 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007348
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007349 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007350 FunctionDecl *OperatorNew = 0;
7351 if (E->getOperatorNew()) {
7352 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007353 getDerived().TransformDecl(E->getLocStart(),
7354 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007355 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007356 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007357 }
7358
7359 FunctionDecl *OperatorDelete = 0;
7360 if (E->getOperatorDelete()) {
7361 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007362 getDerived().TransformDecl(E->getLocStart(),
7363 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007364 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007365 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007366 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007367
Douglas Gregorb98b1992009-08-11 05:31:07 +00007368 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007369 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007370 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007371 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007372 OperatorNew == E->getOperatorNew() &&
7373 OperatorDelete == E->getOperatorDelete() &&
7374 !ArgumentChanged) {
7375 // Mark any declarations we need as referenced.
7376 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007377 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007378 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007379 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007380 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007381
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007382 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007383 QualType ElementType
7384 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7385 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7386 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7387 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007388 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007389 }
7390 }
7391 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007392
John McCall3fa5cae2010-10-26 07:05:15 +00007393 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007394 }
Mike Stump1eb44332009-09-09 15:08:12 +00007395
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007396 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007397 if (!ArraySize.get()) {
7398 // If no array size was specified, but the new expression was
7399 // instantiated with an array type (e.g., "new T" where T is
7400 // instantiated with "int[4]"), extract the outer bound from the
7401 // array type as our array size. We do this with constant and
7402 // dependently-sized array types.
7403 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7404 if (!ArrayT) {
7405 // Do nothing
7406 } else if (const ConstantArrayType *ConsArrayT
7407 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007408 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007409 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier4a9d7952012-08-08 18:46:20 +00007410 ConsArrayT->getSize(),
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007411 SemaRef.Context.getSizeType(),
7412 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007413 AllocType = ConsArrayT->getElementType();
7414 } else if (const DependentSizedArrayType *DepArrayT
7415 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7416 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007417 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007418 AllocType = DepArrayT->getElementType();
7419 }
7420 }
7421 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007422
Douglas Gregorb98b1992009-08-11 05:31:07 +00007423 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7424 E->isGlobalNew(),
7425 /*FIXME:*/E->getLocStart(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007426 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007427 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007428 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007429 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007430 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007431 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007432 E->getDirectInitRange(),
7433 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007434}
Mike Stump1eb44332009-09-09 15:08:12 +00007435
Douglas Gregorb98b1992009-08-11 05:31:07 +00007436template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007437ExprResult
John McCall454feb92009-12-08 09:21:05 +00007438TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007439 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007440 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007441 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007442
Douglas Gregor1af74512010-02-26 00:38:10 +00007443 // Transform the delete operator, if known.
7444 FunctionDecl *OperatorDelete = 0;
7445 if (E->getOperatorDelete()) {
7446 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007447 getDerived().TransformDecl(E->getLocStart(),
7448 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007449 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007450 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007451 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007452
Douglas Gregorb98b1992009-08-11 05:31:07 +00007453 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007454 Operand.get() == E->getArgument() &&
7455 OperatorDelete == E->getOperatorDelete()) {
7456 // Mark any declarations we need as referenced.
7457 // FIXME: instantiation-specific.
7458 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007459 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007460
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007461 if (!E->getArgument()->isTypeDependent()) {
7462 QualType Destroyed = SemaRef.Context.getBaseElementType(
7463 E->getDestroyedType());
7464 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7465 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007466 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedman5f2987c2012-02-02 03:46:19 +00007467 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007468 }
7469 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007470
John McCall3fa5cae2010-10-26 07:05:15 +00007471 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007472 }
Mike Stump1eb44332009-09-09 15:08:12 +00007473
Douglas Gregorb98b1992009-08-11 05:31:07 +00007474 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7475 E->isGlobalDelete(),
7476 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007477 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007478}
Mike Stump1eb44332009-09-09 15:08:12 +00007479
Douglas Gregorb98b1992009-08-11 05:31:07 +00007480template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007481ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007482TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007483 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007484 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007485 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007486 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007487
John McCallb3d87482010-08-24 05:47:05 +00007488 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007489 bool MayBePseudoDestructor = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007490 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007491 E->getOperatorLoc(),
7492 E->isArrow()? tok::arrow : tok::period,
7493 ObjectTypePtr,
7494 MayBePseudoDestructor);
7495 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007496 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007497
John McCallb3d87482010-08-24 05:47:05 +00007498 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007499 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7500 if (QualifierLoc) {
7501 QualifierLoc
7502 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7503 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007504 return ExprError();
7505 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007506 CXXScopeSpec SS;
7507 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007508
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007509 PseudoDestructorTypeStorage Destroyed;
7510 if (E->getDestroyedTypeInfo()) {
7511 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007512 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007513 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007514 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007515 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007516 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007517 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007518 // We aren't likely to be able to resolve the identifier down to a type
7519 // now anyway, so just retain the identifier.
7520 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7521 E->getDestroyedTypeLoc());
7522 } else {
7523 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007524 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007525 *E->getDestroyedTypeIdentifier(),
7526 E->getDestroyedTypeLoc(),
7527 /*Scope=*/0,
7528 SS, ObjectTypePtr,
7529 false);
7530 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007531 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007532
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007533 Destroyed
7534 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7535 E->getDestroyedTypeLoc());
7536 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007537
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007538 TypeSourceInfo *ScopeTypeInfo = 0;
7539 if (E->getScopeTypeInfo()) {
Douglas Gregor303b96f2013-03-08 21:25:01 +00007540 CXXScopeSpec EmptySS;
7541 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
7542 E->getScopeTypeInfo(), ObjectType, 0, EmptySS);
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007543 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007544 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007545 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007546
John McCall9ae2f072010-08-23 23:25:46 +00007547 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007548 E->getOperatorLoc(),
7549 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007550 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007551 ScopeTypeInfo,
7552 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007553 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007554 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007555}
Mike Stump1eb44332009-09-09 15:08:12 +00007556
Douglas Gregora71d8192009-09-04 17:36:40 +00007557template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007558ExprResult
John McCallba135432009-11-21 08:51:07 +00007559TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007560 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007561 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7562 Sema::LookupOrdinaryName);
7563
7564 // Transform all the decls.
7565 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7566 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007567 NamedDecl *InstD = static_cast<NamedDecl*>(
7568 getDerived().TransformDecl(Old->getNameLoc(),
7569 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007570 if (!InstD) {
7571 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7572 // This can happen because of dependent hiding.
7573 if (isa<UsingShadowDecl>(*I))
7574 continue;
7575 else
John McCallf312b1e2010-08-26 23:41:50 +00007576 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007577 }
John McCallf7a1a742009-11-24 19:00:30 +00007578
7579 // Expand using declarations.
7580 if (isa<UsingDecl>(InstD)) {
7581 UsingDecl *UD = cast<UsingDecl>(InstD);
7582 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7583 E = UD->shadow_end(); I != E; ++I)
7584 R.addDecl(*I);
7585 continue;
7586 }
7587
7588 R.addDecl(InstD);
7589 }
7590
7591 // Resolve a kind, but don't do any further analysis. If it's
7592 // ambiguous, the callee needs to deal with it.
7593 R.resolveKind();
7594
7595 // Rebuild the nested-name qualifier, if present.
7596 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007597 if (Old->getQualifierLoc()) {
7598 NestedNameSpecifierLoc QualifierLoc
7599 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7600 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007601 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007602
Douglas Gregor4c9be892011-02-28 20:01:57 +00007603 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007604 }
7605
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007606 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007607 CXXRecordDecl *NamingClass
7608 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7609 Old->getNameLoc(),
7610 Old->getNamingClass()));
7611 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007612 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007613
Douglas Gregor66c45152010-04-27 16:10:10 +00007614 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007615 }
7616
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007617 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7618
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007619 // If we have neither explicit template arguments, nor the template keyword,
7620 // it's a normal declaration name.
7621 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007622 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7623
7624 // If we have template arguments, rebuild them, then rebuild the
7625 // templateid expression.
7626 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola02e221b2012-08-28 04:13:54 +00007627 if (Old->hasExplicitTemplateArgs() &&
7628 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregorfcc12532010-12-20 17:31:10 +00007629 Old->getNumTemplateArgs(),
7630 TransArgs))
7631 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007632
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007633 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007634 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007635}
Mike Stump1eb44332009-09-09 15:08:12 +00007636
Douglas Gregorb98b1992009-08-11 05:31:07 +00007637template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007638ExprResult
John McCall454feb92009-12-08 09:21:05 +00007639TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007640 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7641 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007642 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007643
Douglas Gregorb98b1992009-08-11 05:31:07 +00007644 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007645 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007646 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007647
Mike Stump1eb44332009-09-09 15:08:12 +00007648 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007649 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007650 T,
7651 E->getLocEnd());
7652}
Mike Stump1eb44332009-09-09 15:08:12 +00007653
Douglas Gregorb98b1992009-08-11 05:31:07 +00007654template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007655ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007656TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7657 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7658 if (!LhsT)
7659 return ExprError();
7660
7661 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7662 if (!RhsT)
7663 return ExprError();
7664
7665 if (!getDerived().AlwaysRebuild() &&
7666 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7667 return SemaRef.Owned(E);
7668
7669 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7670 E->getLocStart(),
7671 LhsT, RhsT,
7672 E->getLocEnd());
7673}
7674
7675template<typename Derived>
7676ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007677TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7678 bool ArgChanged = false;
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00007679 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007680 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7681 TypeSourceInfo *From = E->getArg(I);
7682 TypeLoc FromTL = From->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00007683 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007684 TypeLocBuilder TLB;
7685 TLB.reserve(FromTL.getFullDataSize());
7686 QualType To = getDerived().TransformType(TLB, FromTL);
7687 if (To.isNull())
7688 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007689
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007690 if (To == From->getType())
7691 Args.push_back(From);
7692 else {
7693 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7694 ArgChanged = true;
7695 }
7696 continue;
7697 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007698
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007699 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007700
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007701 // We have a pack expansion. Instantiate it.
David Blaikie39e6ab42013-02-18 22:06:02 +00007702 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007703 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7704 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7705 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007706
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007707 // Determine whether the set of unexpanded parameter packs can and should
7708 // be expanded.
7709 bool Expand = true;
7710 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00007711 Optional<unsigned> OrigNumExpansions =
7712 ExpansionTL.getTypePtr()->getNumExpansions();
7713 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007714 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7715 PatternTL.getSourceRange(),
7716 Unexpanded,
7717 Expand, RetainExpansion,
7718 NumExpansions))
7719 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007720
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007721 if (!Expand) {
7722 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00007723 // transformation on the pack expansion, producing another pack
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007724 // expansion.
7725 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007726
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007727 TypeLocBuilder TLB;
7728 TLB.reserve(From->getTypeLoc().getFullDataSize());
7729
7730 QualType To = getDerived().TransformType(TLB, PatternTL);
7731 if (To.isNull())
7732 return ExprError();
7733
Chad Rosier4a9d7952012-08-08 18:46:20 +00007734 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007735 PatternTL.getSourceRange(),
7736 ExpansionTL.getEllipsisLoc(),
7737 NumExpansions);
7738 if (To.isNull())
7739 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007740
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007741 PackExpansionTypeLoc ToExpansionTL
7742 = TLB.push<PackExpansionTypeLoc>(To);
7743 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7744 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7745 continue;
7746 }
7747
7748 // Expand the pack expansion by substituting for each argument in the
7749 // pack(s).
7750 for (unsigned I = 0; I != *NumExpansions; ++I) {
7751 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7752 TypeLocBuilder TLB;
7753 TLB.reserve(PatternTL.getFullDataSize());
7754 QualType To = getDerived().TransformType(TLB, PatternTL);
7755 if (To.isNull())
7756 return ExprError();
7757
7758 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7759 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007760
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007761 if (!RetainExpansion)
7762 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007763
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007764 // If we're supposed to retain a pack expansion, do so by temporarily
7765 // forgetting the partially-substituted parameter pack.
7766 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7767
7768 TypeLocBuilder TLB;
7769 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007770
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007771 QualType To = getDerived().TransformType(TLB, PatternTL);
7772 if (To.isNull())
7773 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007774
7775 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007776 PatternTL.getSourceRange(),
7777 ExpansionTL.getEllipsisLoc(),
7778 NumExpansions);
7779 if (To.isNull())
7780 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007781
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007782 PackExpansionTypeLoc ToExpansionTL
7783 = TLB.push<PackExpansionTypeLoc>(To);
7784 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7785 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7786 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007787
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007788 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7789 return SemaRef.Owned(E);
7790
7791 return getDerived().RebuildTypeTrait(E->getTrait(),
7792 E->getLocStart(),
7793 Args,
7794 E->getLocEnd());
7795}
7796
7797template<typename Derived>
7798ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007799TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7800 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7801 if (!T)
7802 return ExprError();
7803
7804 if (!getDerived().AlwaysRebuild() &&
7805 T == E->getQueriedTypeSourceInfo())
7806 return SemaRef.Owned(E);
7807
7808 ExprResult SubExpr;
7809 {
7810 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7811 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7812 if (SubExpr.isInvalid())
7813 return ExprError();
7814
7815 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7816 return SemaRef.Owned(E);
7817 }
7818
7819 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7820 E->getLocStart(),
7821 T,
7822 SubExpr.get(),
7823 E->getLocEnd());
7824}
7825
7826template<typename Derived>
7827ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007828TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7829 ExprResult SubExpr;
7830 {
7831 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7832 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7833 if (SubExpr.isInvalid())
7834 return ExprError();
7835
7836 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7837 return SemaRef.Owned(E);
7838 }
7839
7840 return getDerived().RebuildExpressionTrait(
7841 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7842}
7843
7844template<typename Derived>
7845ExprResult
John McCall865d4472009-11-19 22:55:06 +00007846TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007847 DependentScopeDeclRefExpr *E) {
Richard Smithefeeccf2012-10-21 03:28:35 +00007848 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
7849}
7850
7851template<typename Derived>
7852ExprResult
7853TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
7854 DependentScopeDeclRefExpr *E,
7855 bool IsAddressOfOperand) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007856 NestedNameSpecifierLoc QualifierLoc
7857 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7858 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007859 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007860 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00007861
John McCall43fed0d2010-11-12 08:19:04 +00007862 // TODO: If this is a conversion-function-id, verify that the
7863 // destination type name (if present) resolves the same way after
7864 // instantiation as it did in the local scope.
7865
Abramo Bagnara25777432010-08-11 22:01:17 +00007866 DeclarationNameInfo NameInfo
7867 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7868 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007869 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007870
John McCallf7a1a742009-11-24 19:00:30 +00007871 if (!E->hasExplicitTemplateArgs()) {
7872 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007873 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007874 // Note: it is sufficient to compare the Name component of NameInfo:
7875 // if name has not changed, DNLoc has not changed either.
7876 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007877 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007878
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007879 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007880 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007881 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00007882 /*TemplateArgs*/ 0,
7883 IsAddressOfOperand);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007884 }
John McCalld5532b62009-11-23 01:53:49 +00007885
7886 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007887 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7888 E->getNumTemplateArgs(),
7889 TransArgs))
7890 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007891
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007892 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007893 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007894 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00007895 &TransArgs,
7896 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007897}
7898
7899template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007900ExprResult
John McCall454feb92009-12-08 09:21:05 +00007901TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithc83c2302012-12-19 01:39:02 +00007902 // CXXConstructExprs other than for list-initialization and
7903 // CXXTemporaryObjectExpr are always implicit, so when we have
7904 // a 1-argument construction we just transform that argument.
Richard Smith73ed67c2012-11-26 08:32:48 +00007905 if ((E->getNumArgs() == 1 ||
7906 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithc83c2302012-12-19 01:39:02 +00007907 (!getDerived().DropCallArgument(E->getArg(0))) &&
7908 !E->isListInitialization())
Douglas Gregor321725d2010-02-03 03:01:57 +00007909 return getDerived().TransformExpr(E->getArg(0));
7910
Douglas Gregorb98b1992009-08-11 05:31:07 +00007911 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7912
7913 QualType T = getDerived().TransformType(E->getType());
7914 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007915 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007916
7917 CXXConstructorDecl *Constructor
7918 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007919 getDerived().TransformDecl(E->getLocStart(),
7920 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007921 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007922 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007923
Douglas Gregorb98b1992009-08-11 05:31:07 +00007924 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007925 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007926 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007927 &ArgumentChanged))
7928 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007929
Douglas Gregorb98b1992009-08-11 05:31:07 +00007930 if (!getDerived().AlwaysRebuild() &&
7931 T == E->getType() &&
7932 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007933 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007934 // Mark the constructor as referenced.
7935 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007936 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007937 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007938 }
Mike Stump1eb44332009-09-09 15:08:12 +00007939
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007940 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7941 Constructor, E->isElidable(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007942 Args,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007943 E->hadMultipleCandidates(),
Richard Smithc83c2302012-12-19 01:39:02 +00007944 E->isListInitialization(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007945 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007946 E->getConstructionKind(),
7947 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007948}
Mike Stump1eb44332009-09-09 15:08:12 +00007949
Douglas Gregorb98b1992009-08-11 05:31:07 +00007950/// \brief Transform a C++ temporary-binding expression.
7951///
Douglas Gregor51326552009-12-24 18:51:59 +00007952/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7953/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007954template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007955ExprResult
John McCall454feb92009-12-08 09:21:05 +00007956TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007957 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007958}
Mike Stump1eb44332009-09-09 15:08:12 +00007959
John McCall4765fa02010-12-06 08:20:24 +00007960/// \brief Transform a C++ expression that contains cleanups that should
7961/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007962///
John McCall4765fa02010-12-06 08:20:24 +00007963/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007964/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007965template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007966ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007967TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007968 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007969}
Mike Stump1eb44332009-09-09 15:08:12 +00007970
Douglas Gregorb98b1992009-08-11 05:31:07 +00007971template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007972ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007973TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007974 CXXTemporaryObjectExpr *E) {
7975 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7976 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007977 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007978
Douglas Gregorb98b1992009-08-11 05:31:07 +00007979 CXXConstructorDecl *Constructor
7980 = cast_or_null<CXXConstructorDecl>(
Chad Rosier4a9d7952012-08-08 18:46:20 +00007981 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007982 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007983 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007984 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007985
Douglas Gregorb98b1992009-08-11 05:31:07 +00007986 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007987 SmallVector<Expr*, 8> Args;
Douglas Gregorb98b1992009-08-11 05:31:07 +00007988 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007989 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007990 &ArgumentChanged))
7991 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007992
Douglas Gregorb98b1992009-08-11 05:31:07 +00007993 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007994 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007995 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007996 !ArgumentChanged) {
7997 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007998 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007999 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00008000 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008001
Richard Smithc83c2302012-12-19 01:39:02 +00008002 // FIXME: Pass in E->isListInitialization().
Douglas Gregorab6677e2010-09-08 00:15:04 +00008003 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8004 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008005 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008006 E->getLocEnd());
8007}
Mike Stump1eb44332009-09-09 15:08:12 +00008008
Douglas Gregorb98b1992009-08-11 05:31:07 +00008009template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008010ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00008011TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Douglas Gregordfca6f52012-02-13 22:00:16 +00008012 // Transform the type of the lambda parameters and start the definition of
8013 // the lambda itself.
8014 TypeSourceInfo *MethodTy
Chad Rosier4a9d7952012-08-08 18:46:20 +00008015 = TransformType(E->getCallOperator()->getTypeSourceInfo());
Douglas Gregordfca6f52012-02-13 22:00:16 +00008016 if (!MethodTy)
8017 return ExprError();
8018
Eli Friedman8da8a662012-09-19 01:18:11 +00008019 // Create the local class that will describe the lambda.
8020 CXXRecordDecl *Class
8021 = getSema().createLambdaClosureType(E->getIntroducerRange(),
8022 MethodTy,
8023 /*KnownDependent=*/false);
8024 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8025
Douglas Gregorc6889e72012-02-14 22:28:59 +00008026 // Transform lambda parameters.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008027 SmallVector<QualType, 4> ParamTypes;
8028 SmallVector<ParmVarDecl *, 4> Params;
Douglas Gregorc6889e72012-02-14 22:28:59 +00008029 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
8030 E->getCallOperator()->param_begin(),
8031 E->getCallOperator()->param_size(),
8032 0, ParamTypes, &Params))
Richard Smith612409e2012-07-25 03:56:55 +00008033 return ExprError();
Douglas Gregorc6889e72012-02-14 22:28:59 +00008034
Douglas Gregordfca6f52012-02-13 22:00:16 +00008035 // Build the call operator.
8036 CXXMethodDecl *CallOperator
8037 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00008038 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00008039 E->getCallOperator()->getLocEnd(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00008040 Params);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008041 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
Douglas Gregord5387e82012-02-14 00:00:48 +00008042
Richard Smith612409e2012-07-25 03:56:55 +00008043 return getDerived().TransformLambdaScope(E, CallOperator);
8044}
8045
8046template<typename Derived>
8047ExprResult
8048TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
8049 CXXMethodDecl *CallOperator) {
Douglas Gregord5387e82012-02-14 00:00:48 +00008050 // Introduce the context of the call operator.
8051 Sema::ContextRAII SavedContext(getSema(), CallOperator);
8052
Douglas Gregordfca6f52012-02-13 22:00:16 +00008053 // Enter the scope of the lambda.
8054 sema::LambdaScopeInfo *LSI
8055 = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(),
8056 E->getCaptureDefault(),
8057 E->hasExplicitParameters(),
8058 E->hasExplicitResultType(),
8059 E->isMutable());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008060
Douglas Gregordfca6f52012-02-13 22:00:16 +00008061 // Transform captures.
Richard Smith612409e2012-07-25 03:56:55 +00008062 bool Invalid = false;
Douglas Gregordfca6f52012-02-13 22:00:16 +00008063 bool FinishedExplicitCaptures = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008064 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008065 CEnd = E->capture_end();
8066 C != CEnd; ++C) {
8067 // When we hit the first implicit capture, tell Sema that we've finished
8068 // the list of explicit captures.
8069 if (!FinishedExplicitCaptures && C->isImplicit()) {
8070 getSema().finishLambdaExplicitCaptures(LSI);
8071 FinishedExplicitCaptures = true;
8072 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008073
Douglas Gregordfca6f52012-02-13 22:00:16 +00008074 // Capturing 'this' is trivial.
8075 if (C->capturesThis()) {
8076 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8077 continue;
8078 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008079
Douglas Gregora7365242012-02-14 19:27:52 +00008080 // Determine the capture kind for Sema.
8081 Sema::TryCaptureKind Kind
8082 = C->isImplicit()? Sema::TryCapture_Implicit
8083 : C->getCaptureKind() == LCK_ByCopy
8084 ? Sema::TryCapture_ExplicitByVal
8085 : Sema::TryCapture_ExplicitByRef;
8086 SourceLocation EllipsisLoc;
8087 if (C->isPackExpansion()) {
8088 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8089 bool ShouldExpand = false;
8090 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008091 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008092 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8093 C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008094 Unexpanded,
8095 ShouldExpand, RetainExpansion,
8096 NumExpansions))
8097 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008098
Douglas Gregora7365242012-02-14 19:27:52 +00008099 if (ShouldExpand) {
8100 // The transform has determined that we should perform an expansion;
8101 // transform and capture each of the arguments.
8102 // expansion of the pattern. Do so.
8103 VarDecl *Pack = C->getCapturedVar();
8104 for (unsigned I = 0; I != *NumExpansions; ++I) {
8105 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8106 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008107 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008108 Pack));
8109 if (!CapturedVar) {
8110 Invalid = true;
8111 continue;
8112 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008113
Douglas Gregora7365242012-02-14 19:27:52 +00008114 // Capture the transformed variable.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008115 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8116 }
Douglas Gregora7365242012-02-14 19:27:52 +00008117 continue;
8118 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008119
Douglas Gregora7365242012-02-14 19:27:52 +00008120 EllipsisLoc = C->getEllipsisLoc();
8121 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008122
Douglas Gregordfca6f52012-02-13 22:00:16 +00008123 // Transform the captured variable.
8124 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008125 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008126 C->getCapturedVar()));
8127 if (!CapturedVar) {
8128 Invalid = true;
8129 continue;
8130 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008131
Douglas Gregordfca6f52012-02-13 22:00:16 +00008132 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00008133 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008134 }
8135 if (!FinishedExplicitCaptures)
8136 getSema().finishLambdaExplicitCaptures(LSI);
8137
Douglas Gregordfca6f52012-02-13 22:00:16 +00008138
8139 // Enter a new evaluation context to insulate the lambda from any
8140 // cleanups from the enclosing full-expression.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008141 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008142
8143 if (Invalid) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008144 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregordfca6f52012-02-13 22:00:16 +00008145 /*IsInstantiation=*/true);
8146 return ExprError();
8147 }
8148
8149 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00008150 StmtResult Body = getDerived().TransformStmt(E->getBody());
8151 if (Body.isInvalid()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008152 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregord5387e82012-02-14 00:00:48 +00008153 /*IsInstantiation=*/true);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008154 return ExprError();
Douglas Gregord5387e82012-02-14 00:00:48 +00008155 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00008156
Chad Rosier4a9d7952012-08-08 18:46:20 +00008157 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00008158 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00008159}
8160
8161template<typename Derived>
8162ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008163TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00008164 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00008165 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8166 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008167 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008168
Douglas Gregorb98b1992009-08-11 05:31:07 +00008169 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008170 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008171 Args.reserve(E->arg_size());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008172 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008173 &ArgumentChanged))
8174 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008175
Douglas Gregorb98b1992009-08-11 05:31:07 +00008176 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008177 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008178 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008179 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008180
Douglas Gregorb98b1992009-08-11 05:31:07 +00008181 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00008182 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008183 E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008184 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008185 E->getRParenLoc());
8186}
Mike Stump1eb44332009-09-09 15:08:12 +00008187
Douglas Gregorb98b1992009-08-11 05:31:07 +00008188template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008189ExprResult
John McCall865d4472009-11-19 22:55:06 +00008190TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008191 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008192 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008193 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008194 Expr *OldBase;
8195 QualType BaseType;
8196 QualType ObjectType;
8197 if (!E->isImplicitAccess()) {
8198 OldBase = E->getBase();
8199 Base = getDerived().TransformExpr(OldBase);
8200 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008201 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008202
John McCallaa81e162009-12-01 22:10:20 +00008203 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008204 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008205 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008206 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008207 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008208 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008209 ObjectTy,
8210 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008211 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008212 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008213
John McCallb3d87482010-08-24 05:47:05 +00008214 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008215 BaseType = ((Expr*) Base.get())->getType();
8216 } else {
8217 OldBase = 0;
8218 BaseType = getDerived().TransformType(E->getBaseType());
8219 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8220 }
Mike Stump1eb44332009-09-09 15:08:12 +00008221
Douglas Gregor6cd21982009-10-20 05:58:46 +00008222 // Transform the first part of the nested-name-specifier that qualifies
8223 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008224 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008225 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008226 E->getFirstQualifierFoundInScope(),
8227 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008228
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008229 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008230 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008231 QualifierLoc
8232 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8233 ObjectType,
8234 FirstQualifierInScope);
8235 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008236 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008237 }
Mike Stump1eb44332009-09-09 15:08:12 +00008238
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008239 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8240
John McCall43fed0d2010-11-12 08:19:04 +00008241 // TODO: If this is a conversion-function-id, verify that the
8242 // destination type name (if present) resolves the same way after
8243 // instantiation as it did in the local scope.
8244
Abramo Bagnara25777432010-08-11 22:01:17 +00008245 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008246 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008247 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008248 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008249
John McCallaa81e162009-12-01 22:10:20 +00008250 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008251 // This is a reference to a member without an explicitly-specified
8252 // template argument list. Optimize for this common case.
8253 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008254 Base.get() == OldBase &&
8255 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008256 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008257 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008258 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008259 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008260
John McCall9ae2f072010-08-23 23:25:46 +00008261 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008262 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008263 E->isArrow(),
8264 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008265 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008266 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008267 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008268 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008269 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008270 }
8271
John McCalld5532b62009-11-23 01:53:49 +00008272 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008273 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8274 E->getNumTemplateArgs(),
8275 TransArgs))
8276 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008277
John McCall9ae2f072010-08-23 23:25:46 +00008278 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008279 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008280 E->isArrow(),
8281 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008282 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008283 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008284 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008285 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008286 &TransArgs);
8287}
8288
8289template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008290ExprResult
John McCall454feb92009-12-08 09:21:05 +00008291TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008292 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008293 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008294 QualType BaseType;
8295 if (!Old->isImplicitAccess()) {
8296 Base = getDerived().TransformExpr(Old->getBase());
8297 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008298 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008299 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8300 Old->isArrow());
8301 if (Base.isInvalid())
8302 return ExprError();
8303 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008304 } else {
8305 BaseType = getDerived().TransformType(Old->getBaseType());
8306 }
John McCall129e2df2009-11-30 22:42:35 +00008307
Douglas Gregor4c9be892011-02-28 20:01:57 +00008308 NestedNameSpecifierLoc QualifierLoc;
8309 if (Old->getQualifierLoc()) {
8310 QualifierLoc
8311 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8312 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008313 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008314 }
8315
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008316 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8317
Abramo Bagnara25777432010-08-11 22:01:17 +00008318 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008319 Sema::LookupOrdinaryName);
8320
8321 // Transform all the decls.
8322 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8323 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008324 NamedDecl *InstD = static_cast<NamedDecl*>(
8325 getDerived().TransformDecl(Old->getMemberLoc(),
8326 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008327 if (!InstD) {
8328 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8329 // This can happen because of dependent hiding.
8330 if (isa<UsingShadowDecl>(*I))
8331 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008332 else {
8333 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008334 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008335 }
John McCall9f54ad42009-12-10 09:41:52 +00008336 }
John McCall129e2df2009-11-30 22:42:35 +00008337
8338 // Expand using declarations.
8339 if (isa<UsingDecl>(InstD)) {
8340 UsingDecl *UD = cast<UsingDecl>(InstD);
8341 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8342 E = UD->shadow_end(); I != E; ++I)
8343 R.addDecl(*I);
8344 continue;
8345 }
8346
8347 R.addDecl(InstD);
8348 }
8349
8350 R.resolveKind();
8351
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008352 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008353 if (Old->getNamingClass()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008354 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008355 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008356 Old->getMemberLoc(),
8357 Old->getNamingClass()));
8358 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008359 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008360
Douglas Gregor66c45152010-04-27 16:10:10 +00008361 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008362 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008363
John McCall129e2df2009-11-30 22:42:35 +00008364 TemplateArgumentListInfo TransArgs;
8365 if (Old->hasExplicitTemplateArgs()) {
8366 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8367 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008368 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8369 Old->getNumTemplateArgs(),
8370 TransArgs))
8371 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008372 }
John McCallc2233c52010-01-15 08:34:02 +00008373
8374 // FIXME: to do this check properly, we will need to preserve the
8375 // first-qualifier-in-scope here, just in case we had a dependent
8376 // base (and therefore couldn't do the check) and a
8377 // nested-name-qualifier (and therefore could do the lookup).
8378 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008379
John McCall9ae2f072010-08-23 23:25:46 +00008380 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008381 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008382 Old->getOperatorLoc(),
8383 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008384 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008385 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008386 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008387 R,
8388 (Old->hasExplicitTemplateArgs()
8389 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008390}
8391
8392template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008393ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008394TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008395 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008396 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8397 if (SubExpr.isInvalid())
8398 return ExprError();
8399
8400 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008401 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008402
8403 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8404}
8405
8406template<typename Derived>
8407ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008408TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008409 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8410 if (Pattern.isInvalid())
8411 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008412
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008413 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8414 return SemaRef.Owned(E);
8415
Douglas Gregor67fd1252011-01-14 21:20:45 +00008416 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8417 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008418}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008419
8420template<typename Derived>
8421ExprResult
8422TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8423 // If E is not value-dependent, then nothing will change when we transform it.
8424 // Note: This is an instantiation-centric view.
8425 if (!E->isValueDependent())
8426 return SemaRef.Owned(E);
8427
8428 // Note: None of the implementations of TryExpandParameterPacks can ever
8429 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier4a9d7952012-08-08 18:46:20 +00008430 // so
Douglas Gregoree8aff02011-01-04 17:33:58 +00008431 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8432 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008433 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008434 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008435 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008436 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008437 ShouldExpand, RetainExpansion,
8438 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008439 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008440
Douglas Gregor089e8932011-10-10 18:59:29 +00008441 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008442 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008443
Douglas Gregor089e8932011-10-10 18:59:29 +00008444 NamedDecl *Pack = E->getPack();
8445 if (!ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008446 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008447 Pack));
8448 if (!Pack)
8449 return ExprError();
8450 }
8451
Chad Rosier4a9d7952012-08-08 18:46:20 +00008452
Douglas Gregoree8aff02011-01-04 17:33:58 +00008453 // We now know the length of the parameter pack, so build a new expression
8454 // that stores that length.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008455 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8456 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008457 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008458}
8459
Douglas Gregorbe230c32011-01-03 17:17:50 +00008460template<typename Derived>
8461ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008462TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8463 SubstNonTypeTemplateParmPackExpr *E) {
8464 // Default behavior is to do nothing with this transformation.
8465 return SemaRef.Owned(E);
8466}
8467
8468template<typename Derived>
8469ExprResult
John McCall91a57552011-07-15 05:09:51 +00008470TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8471 SubstNonTypeTemplateParmExpr *E) {
8472 // Default behavior is to do nothing with this transformation.
8473 return SemaRef.Owned(E);
8474}
8475
8476template<typename Derived>
8477ExprResult
Richard Smith9a4db032012-09-12 00:56:43 +00008478TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8479 // Default behavior is to do nothing with this transformation.
8480 return SemaRef.Owned(E);
8481}
8482
8483template<typename Derived>
8484ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008485TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8486 MaterializeTemporaryExpr *E) {
8487 return getDerived().TransformExpr(E->GetTemporaryExpr());
8488}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008489
Douglas Gregor03e80032011-06-21 17:03:29 +00008490template<typename Derived>
8491ExprResult
John McCall454feb92009-12-08 09:21:05 +00008492TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008493 return SemaRef.MaybeBindToTemporary(E);
8494}
8495
8496template<typename Derived>
8497ExprResult
8498TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008499 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008500}
8501
8502template<typename Derived>
8503ExprResult
Patrick Beardeb382ec2012-04-19 00:25:12 +00008504TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8505 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8506 if (SubExpr.isInvalid())
8507 return ExprError();
8508
8509 if (!getDerived().AlwaysRebuild() &&
8510 SubExpr.get() == E->getSubExpr())
8511 return SemaRef.Owned(E);
8512
8513 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008514}
8515
8516template<typename Derived>
8517ExprResult
8518TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8519 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008520 SmallVector<Expr *, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008521 bool ArgChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008522 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008523 /*IsCall=*/false, Elements, &ArgChanged))
8524 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008525
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008526 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8527 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008528
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008529 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8530 Elements.data(),
8531 Elements.size());
8532}
8533
8534template<typename Derived>
8535ExprResult
8536TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008537 ObjCDictionaryLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008538 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008539 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008540 bool ArgChanged = false;
8541 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8542 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008543
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008544 if (OrigElement.isPackExpansion()) {
8545 // This key/value element is a pack expansion.
8546 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8547 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8548 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8549 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8550
8551 // Determine whether the set of unexpanded parameter packs can
8552 // and should be expanded.
8553 bool Expand = true;
8554 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008555 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8556 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008557 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8558 OrigElement.Value->getLocEnd());
8559 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8560 PatternRange,
8561 Unexpanded,
8562 Expand, RetainExpansion,
8563 NumExpansions))
8564 return ExprError();
8565
8566 if (!Expand) {
8567 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00008568 // transformation on the pack expansion, producing another pack
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008569 // expansion.
8570 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8571 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8572 if (Key.isInvalid())
8573 return ExprError();
8574
8575 if (Key.get() != OrigElement.Key)
8576 ArgChanged = true;
8577
8578 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8579 if (Value.isInvalid())
8580 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008581
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008582 if (Value.get() != OrigElement.Value)
8583 ArgChanged = true;
8584
Chad Rosier4a9d7952012-08-08 18:46:20 +00008585 ObjCDictionaryElement Expansion = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008586 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8587 };
8588 Elements.push_back(Expansion);
8589 continue;
8590 }
8591
8592 // Record right away that the argument was changed. This needs
8593 // to happen even if the array expands to nothing.
8594 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008595
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008596 // The transform has determined that we should perform an elementwise
8597 // expansion of the pattern. Do so.
8598 for (unsigned I = 0; I != *NumExpansions; ++I) {
8599 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8600 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8601 if (Key.isInvalid())
8602 return ExprError();
8603
8604 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8605 if (Value.isInvalid())
8606 return ExprError();
8607
Chad Rosier4a9d7952012-08-08 18:46:20 +00008608 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008609 Key.get(), Value.get(), SourceLocation(), NumExpansions
8610 };
8611
8612 // If any unexpanded parameter packs remain, we still have a
8613 // pack expansion.
8614 if (Key.get()->containsUnexpandedParameterPack() ||
8615 Value.get()->containsUnexpandedParameterPack())
8616 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008617
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008618 Elements.push_back(Element);
8619 }
8620
8621 // We've finished with this pack expansion.
8622 continue;
8623 }
8624
8625 // Transform and check key.
8626 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8627 if (Key.isInvalid())
8628 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008629
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008630 if (Key.get() != OrigElement.Key)
8631 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008632
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008633 // Transform and check value.
8634 ExprResult Value
8635 = getDerived().TransformExpr(OrigElement.Value);
8636 if (Value.isInvalid())
8637 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008638
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008639 if (Value.get() != OrigElement.Value)
8640 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008641
8642 ObjCDictionaryElement Element = {
David Blaikie66874fb2013-02-21 01:47:18 +00008643 Key.get(), Value.get(), SourceLocation(), None
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008644 };
8645 Elements.push_back(Element);
8646 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008647
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008648 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8649 return SemaRef.MaybeBindToTemporary(E);
8650
8651 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8652 Elements.data(),
8653 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008654}
8655
Mike Stump1eb44332009-09-09 15:08:12 +00008656template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008657ExprResult
John McCall454feb92009-12-08 09:21:05 +00008658TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008659 TypeSourceInfo *EncodedTypeInfo
8660 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8661 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008662 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008663
Douglas Gregorb98b1992009-08-11 05:31:07 +00008664 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008665 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008666 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008667
8668 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008669 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008670 E->getRParenLoc());
8671}
Mike Stump1eb44332009-09-09 15:08:12 +00008672
Douglas Gregorb98b1992009-08-11 05:31:07 +00008673template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00008674ExprResult TreeTransform<Derived>::
8675TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCall93b64572013-04-11 02:14:26 +00008676 // This is a kind of implicit conversion, and it needs to get dropped
8677 // and recomputed for the same general reasons that ImplicitCastExprs
8678 // do, as well a more specific one: this expression is only valid when
8679 // it appears *immediately* as an argument expression.
8680 return getDerived().TransformExpr(E->getSubExpr());
John McCallf85e1932011-06-15 23:02:42 +00008681}
8682
8683template<typename Derived>
8684ExprResult TreeTransform<Derived>::
8685TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008686 TypeSourceInfo *TSInfo
John McCallf85e1932011-06-15 23:02:42 +00008687 = getDerived().TransformType(E->getTypeInfoAsWritten());
8688 if (!TSInfo)
8689 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008690
John McCallf85e1932011-06-15 23:02:42 +00008691 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008692 if (Result.isInvalid())
John McCallf85e1932011-06-15 23:02:42 +00008693 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008694
John McCallf85e1932011-06-15 23:02:42 +00008695 if (!getDerived().AlwaysRebuild() &&
8696 TSInfo == E->getTypeInfoAsWritten() &&
8697 Result.get() == E->getSubExpr())
8698 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008699
John McCallf85e1932011-06-15 23:02:42 +00008700 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00008701 E->getBridgeKeywordLoc(), TSInfo,
John McCallf85e1932011-06-15 23:02:42 +00008702 Result.get());
8703}
8704
8705template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008706ExprResult
John McCall454feb92009-12-08 09:21:05 +00008707TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008708 // Transform arguments.
8709 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008710 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008711 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008712 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008713 &ArgChanged))
8714 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008715
Douglas Gregor92e986e2010-04-22 16:44:27 +00008716 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8717 // Class message: transform the receiver type.
8718 TypeSourceInfo *ReceiverTypeInfo
8719 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8720 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008721 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008722
Douglas Gregor92e986e2010-04-22 16:44:27 +00008723 // If nothing changed, just retain the existing message send.
8724 if (!getDerived().AlwaysRebuild() &&
8725 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008726 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008727
8728 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008729 SmallVector<SourceLocation, 16> SelLocs;
8730 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008731 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8732 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008733 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008734 E->getMethodDecl(),
8735 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008736 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008737 E->getRightLoc());
8738 }
8739
8740 // Instance message: transform the receiver
8741 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8742 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00008743 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00008744 = getDerived().TransformExpr(E->getInstanceReceiver());
8745 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008746 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00008747
8748 // If nothing changed, just retain the existing message send.
8749 if (!getDerived().AlwaysRebuild() &&
8750 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008751 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008752
Douglas Gregor92e986e2010-04-22 16:44:27 +00008753 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008754 SmallVector<SourceLocation, 16> SelLocs;
8755 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00008756 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00008757 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008758 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008759 E->getMethodDecl(),
8760 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008761 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008762 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008763}
8764
Mike Stump1eb44332009-09-09 15:08:12 +00008765template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008766ExprResult
John McCall454feb92009-12-08 09:21:05 +00008767TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008768 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008769}
8770
Mike Stump1eb44332009-09-09 15:08:12 +00008771template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008772ExprResult
John McCall454feb92009-12-08 09:21:05 +00008773TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008774 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008775}
8776
Mike Stump1eb44332009-09-09 15:08:12 +00008777template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008778ExprResult
John McCall454feb92009-12-08 09:21:05 +00008779TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008780 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008781 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008782 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008783 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008784
8785 // We don't need to transform the ivar; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008786
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008787 // If nothing changed, just retain the existing expression.
8788 if (!getDerived().AlwaysRebuild() &&
8789 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008790 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008791
John McCall9ae2f072010-08-23 23:25:46 +00008792 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008793 E->getLocation(),
8794 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008795}
8796
Mike Stump1eb44332009-09-09 15:08:12 +00008797template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008798ExprResult
John McCall454feb92009-12-08 09:21:05 +00008799TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00008800 // 'super' and types never change. Property never changes. Just
8801 // retain the existing expression.
8802 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00008803 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008804
Douglas Gregore3303542010-04-26 20:47:02 +00008805 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008806 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00008807 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008808 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008809
Douglas Gregore3303542010-04-26 20:47:02 +00008810 // We don't need to transform the property; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008811
Douglas Gregore3303542010-04-26 20:47:02 +00008812 // If nothing changed, just retain the existing expression.
8813 if (!getDerived().AlwaysRebuild() &&
8814 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008815 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008816
John McCall12f78a62010-12-02 01:19:52 +00008817 if (E->isExplicitProperty())
8818 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8819 E->getExplicitProperty(),
8820 E->getLocation());
8821
8822 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00008823 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00008824 E->getImplicitPropertyGetter(),
8825 E->getImplicitPropertySetter(),
8826 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008827}
8828
Mike Stump1eb44332009-09-09 15:08:12 +00008829template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008830ExprResult
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008831TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
8832 // Transform the base expression.
8833 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
8834 if (Base.isInvalid())
8835 return ExprError();
8836
8837 // Transform the key expression.
8838 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
8839 if (Key.isInvalid())
8840 return ExprError();
8841
8842 // If nothing changed, just retain the existing expression.
8843 if (!getDerived().AlwaysRebuild() &&
8844 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
8845 return SemaRef.Owned(E);
8846
Chad Rosier4a9d7952012-08-08 18:46:20 +00008847 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008848 Base.get(), Key.get(),
8849 E->getAtIndexMethodDecl(),
8850 E->setAtIndexMethodDecl());
8851}
8852
8853template<typename Derived>
8854ExprResult
John McCall454feb92009-12-08 09:21:05 +00008855TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008856 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008857 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008858 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008859 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008860
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008861 // If nothing changed, just retain the existing expression.
8862 if (!getDerived().AlwaysRebuild() &&
8863 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008864 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008865
John McCall9ae2f072010-08-23 23:25:46 +00008866 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00008867 E->getOpLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008868 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008869}
8870
Mike Stump1eb44332009-09-09 15:08:12 +00008871template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008872ExprResult
John McCall454feb92009-12-08 09:21:05 +00008873TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008874 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008875 SmallVector<Expr*, 8> SubExprs;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008876 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008877 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008878 SubExprs, &ArgumentChanged))
8879 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008880
Douglas Gregorb98b1992009-08-11 05:31:07 +00008881 if (!getDerived().AlwaysRebuild() &&
8882 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008883 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008884
Douglas Gregorb98b1992009-08-11 05:31:07 +00008885 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008886 SubExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008887 E->getRParenLoc());
8888}
8889
Mike Stump1eb44332009-09-09 15:08:12 +00008890template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008891ExprResult
John McCall454feb92009-12-08 09:21:05 +00008892TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008893 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008894
John McCallc6ac9c32011-02-04 18:33:18 +00008895 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8896 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8897
8898 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00008899 blockScope->TheDecl->setBlockMissingReturnType(
8900 oldBlock->blockMissingReturnType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008901
Chris Lattner686775d2011-07-20 06:58:45 +00008902 SmallVector<ParmVarDecl*, 4> params;
8903 SmallVector<QualType, 4> paramTypes;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008904
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008905 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008906 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8907 oldBlock->param_begin(),
8908 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008909 0, paramTypes, &params)) {
8910 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00008911 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008912 }
John McCallc6ac9c32011-02-04 18:33:18 +00008913
Jordan Rose09189892013-03-08 22:25:36 +00008914 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00008915 QualType exprResultType =
8916 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00008917
8918 // Don't allow returning a objc interface by value.
Eli Friedman84b007f2012-01-26 03:00:14 +00008919 if (exprResultType->isObjCObjectType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008920 getSema().Diag(E->getCaretLocation(),
8921 diag::err_object_cannot_be_passed_returned_by_value)
Eli Friedman84b007f2012-01-26 03:00:14 +00008922 << 0 << exprResultType;
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008923 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregora779d9c2011-01-19 21:32:01 +00008924 return ExprError();
8925 }
John McCall711c52b2011-01-05 12:14:39 +00008926
Jordan Rosebea522f2013-03-08 21:51:21 +00008927 QualType functionType =
8928 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rose09189892013-03-08 22:25:36 +00008929 exprFunctionType->getExtProtoInfo());
John McCallc6ac9c32011-02-04 18:33:18 +00008930 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00008931
8932 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00008933 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00008934 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00008935
8936 if (!oldBlock->blockMissingReturnType()) {
8937 blockScope->HasImplicitReturnType = false;
8938 blockScope->ReturnType = exprResultType;
8939 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008940
John McCall711c52b2011-01-05 12:14:39 +00008941 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00008942 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008943 if (body.isInvalid()) {
8944 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00008945 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008946 }
John McCall711c52b2011-01-05 12:14:39 +00008947
John McCallc6ac9c32011-02-04 18:33:18 +00008948#ifndef NDEBUG
8949 // In builds with assertions, make sure that we captured everything we
8950 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00008951 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8952 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8953 e = oldBlock->capture_end(); i != e; ++i) {
8954 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00008955
Douglas Gregorfc921372011-05-20 15:32:55 +00008956 // Ignore parameter packs.
8957 if (isa<ParmVarDecl>(oldCapture) &&
8958 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8959 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00008960
Douglas Gregorfc921372011-05-20 15:32:55 +00008961 VarDecl *newCapture =
8962 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8963 oldCapture));
8964 assert(blockScope->CaptureMap.count(newCapture));
8965 }
Douglas Gregorec79d872012-02-24 17:41:38 +00008966 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00008967 }
8968#endif
8969
8970 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8971 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008972}
8973
Mike Stump1eb44332009-09-09 15:08:12 +00008974template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008975ExprResult
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008976TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00008977 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008978}
Eli Friedman276b0612011-10-11 02:20:01 +00008979
8980template<typename Derived>
8981ExprResult
8982TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008983 QualType RetTy = getDerived().TransformType(E->getType());
8984 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008985 SmallVector<Expr*, 8> SubExprs;
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008986 SubExprs.reserve(E->getNumSubExprs());
8987 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8988 SubExprs, &ArgumentChanged))
8989 return ExprError();
8990
8991 if (!getDerived().AlwaysRebuild() &&
8992 !ArgumentChanged)
8993 return SemaRef.Owned(E);
8994
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008995 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008996 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00008997}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008998
Douglas Gregorb98b1992009-08-11 05:31:07 +00008999//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00009000// Type reconstruction
9001//===----------------------------------------------------------------------===//
9002
Mike Stump1eb44332009-09-09 15:08:12 +00009003template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00009004QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9005 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00009006 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009007 getDerived().getBaseEntity());
9008}
9009
Mike Stump1eb44332009-09-09 15:08:12 +00009010template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00009011QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9012 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00009013 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009014 getDerived().getBaseEntity());
9015}
9016
Mike Stump1eb44332009-09-09 15:08:12 +00009017template<typename Derived>
9018QualType
John McCall85737a72009-10-30 00:06:24 +00009019TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9020 bool WrittenAsLValue,
9021 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00009022 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00009023 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009024}
9025
9026template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009027QualType
John McCall85737a72009-10-30 00:06:24 +00009028TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9029 QualType ClassType,
9030 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00009031 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00009032 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009033}
9034
9035template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009036QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00009037TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9038 ArrayType::ArraySizeModifier SizeMod,
9039 const llvm::APInt *Size,
9040 Expr *SizeExpr,
9041 unsigned IndexTypeQuals,
9042 SourceRange BracketsRange) {
9043 if (SizeExpr || !Size)
9044 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9045 IndexTypeQuals, BracketsRange,
9046 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00009047
9048 QualType Types[] = {
9049 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9050 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9051 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00009052 };
9053 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
9054 QualType SizeType;
9055 for (unsigned I = 0; I != NumTypes; ++I)
9056 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9057 SizeType = Types[I];
9058 break;
9059 }
Mike Stump1eb44332009-09-09 15:08:12 +00009060
Eli Friedman01f276d2012-01-25 23:20:27 +00009061 // Note that we can return a VariableArrayType here in the case where
9062 // the element type was a dependent VariableArrayType.
9063 IntegerLiteral *ArraySize
9064 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9065 /*FIXME*/BracketsRange.getBegin());
9066 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009067 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00009068 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009069}
Mike Stump1eb44332009-09-09 15:08:12 +00009070
Douglas Gregor577f75a2009-08-04 16:50:30 +00009071template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009072QualType
9073TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009074 ArrayType::ArraySizeModifier SizeMod,
9075 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00009076 unsigned IndexTypeQuals,
9077 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009078 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00009079 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009080}
9081
9082template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009083QualType
Mike Stump1eb44332009-09-09 15:08:12 +00009084TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009085 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00009086 unsigned IndexTypeQuals,
9087 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009088 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00009089 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009090}
Mike Stump1eb44332009-09-09 15:08:12 +00009091
Douglas Gregor577f75a2009-08-04 16:50:30 +00009092template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009093QualType
9094TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009095 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009096 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009097 unsigned IndexTypeQuals,
9098 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009099 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009100 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009101 IndexTypeQuals, BracketsRange);
9102}
9103
9104template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009105QualType
9106TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009107 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009108 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009109 unsigned IndexTypeQuals,
9110 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009111 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009112 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009113 IndexTypeQuals, BracketsRange);
9114}
9115
9116template<typename Derived>
9117QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00009118 unsigned NumElements,
9119 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00009120 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00009121 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009122}
Mike Stump1eb44332009-09-09 15:08:12 +00009123
Douglas Gregor577f75a2009-08-04 16:50:30 +00009124template<typename Derived>
9125QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9126 unsigned NumElements,
9127 SourceLocation AttributeLoc) {
9128 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9129 NumElements, true);
9130 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00009131 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9132 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00009133 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009134}
Mike Stump1eb44332009-09-09 15:08:12 +00009135
Douglas Gregor577f75a2009-08-04 16:50:30 +00009136template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009137QualType
9138TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00009139 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009140 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00009141 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009142}
Mike Stump1eb44332009-09-09 15:08:12 +00009143
Douglas Gregor577f75a2009-08-04 16:50:30 +00009144template<typename Derived>
Jordan Rosebea522f2013-03-08 21:51:21 +00009145QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9146 QualType T,
9147 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00009148 const FunctionProtoType::ExtProtoInfo &EPI) {
9149 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009150 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00009151 getDerived().getBaseEntity(),
Jordan Rose09189892013-03-08 22:25:36 +00009152 EPI);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009153}
Mike Stump1eb44332009-09-09 15:08:12 +00009154
Douglas Gregor577f75a2009-08-04 16:50:30 +00009155template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00009156QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9157 return SemaRef.Context.getFunctionNoProtoType(T);
9158}
9159
9160template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00009161QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9162 assert(D && "no decl found");
9163 if (D->isInvalidDecl()) return QualType();
9164
Douglas Gregor92e986e2010-04-22 16:44:27 +00009165 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00009166 TypeDecl *Ty;
9167 if (isa<UsingDecl>(D)) {
9168 UsingDecl *Using = cast<UsingDecl>(D);
9169 assert(Using->isTypeName() &&
9170 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9171
9172 // A valid resolved using typename decl points to exactly one type decl.
9173 assert(++Using->shadow_begin() == Using->shadow_end());
9174 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009175
John McCalled976492009-12-04 22:46:56 +00009176 } else {
9177 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9178 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9179 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9180 }
9181
9182 return SemaRef.Context.getTypeDeclType(Ty);
9183}
9184
9185template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009186QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9187 SourceLocation Loc) {
9188 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009189}
9190
9191template<typename Derived>
9192QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9193 return SemaRef.Context.getTypeOfType(Underlying);
9194}
9195
9196template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009197QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9198 SourceLocation Loc) {
9199 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009200}
9201
9202template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009203QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9204 UnaryTransformType::UTTKind UKind,
9205 SourceLocation Loc) {
9206 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9207}
9208
9209template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009210QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009211 TemplateName Template,
9212 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009213 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009214 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009215}
Mike Stump1eb44332009-09-09 15:08:12 +00009216
Douglas Gregordcee1a12009-08-06 05:28:30 +00009217template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009218QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9219 SourceLocation KWLoc) {
9220 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9221}
9222
9223template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009224TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009225TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009226 bool TemplateKW,
9227 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009228 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009229 Template);
9230}
9231
9232template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009233TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009234TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9235 const IdentifierInfo &Name,
9236 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009237 QualType ObjectType,
9238 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009239 UnqualifiedId TemplateName;
9240 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009241 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009242 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009243 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009244 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009245 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009246 /*EnteringContext=*/false,
9247 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009248 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009249}
Mike Stump1eb44332009-09-09 15:08:12 +00009250
Douglas Gregorb98b1992009-08-11 05:31:07 +00009251template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009252TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009253TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009254 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009255 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009256 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009257 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009258 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009259 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009260 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009261 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009262 Sema::TemplateTy Template;
9263 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009264 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009265 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009266 /*EnteringContext=*/false,
9267 Template);
9268 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009269}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009270
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009271template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009272ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009273TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9274 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009275 Expr *OrigCallee,
9276 Expr *First,
9277 Expr *Second) {
9278 Expr *Callee = OrigCallee->IgnoreParenCasts();
9279 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009280
Douglas Gregorb98b1992009-08-11 05:31:07 +00009281 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009282 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009283 if (!First->getType()->isOverloadableType() &&
9284 !Second->getType()->isOverloadableType())
9285 return getSema().CreateBuiltinArraySubscriptExpr(First,
9286 Callee->getLocStart(),
9287 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009288 } else if (Op == OO_Arrow) {
9289 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009290 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9291 } else if (Second == 0 || isPostIncDec) {
9292 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009293 // The argument is not of overloadable type, so try to create a
9294 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009295 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009296 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009297
John McCall9ae2f072010-08-23 23:25:46 +00009298 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009299 }
9300 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009301 if (!First->getType()->isOverloadableType() &&
9302 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009303 // Neither of the arguments is an overloadable type, so try to
9304 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009305 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009306 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009307 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009308 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009309 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009310
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009311 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009312 }
9313 }
Mike Stump1eb44332009-09-09 15:08:12 +00009314
9315 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009316 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009317 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009318
John McCall9ae2f072010-08-23 23:25:46 +00009319 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009320 assert(ULE->requiresADL());
9321
9322 // FIXME: Do we have to check
9323 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009324 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009325 } else {
Richard Smithf6411662012-11-28 21:47:39 +00009326 // If we've resolved this to a particular non-member function, just call
9327 // that function. If we resolved it to a member function,
9328 // CreateOverloaded* will find that function for us.
9329 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9330 if (!isa<CXXMethodDecl>(ND))
9331 Functions.addDecl(ND);
John McCallba135432009-11-21 08:51:07 +00009332 }
Mike Stump1eb44332009-09-09 15:08:12 +00009333
Douglas Gregorb98b1992009-08-11 05:31:07 +00009334 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009335 Expr *Args[2] = { First, Second };
9336 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009337
Douglas Gregorb98b1992009-08-11 05:31:07 +00009338 // Create the overloaded operator invocation for unary operators.
9339 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009340 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009341 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009342 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009343 }
Mike Stump1eb44332009-09-09 15:08:12 +00009344
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009345 if (Op == OO_Subscript) {
9346 SourceLocation LBrace;
9347 SourceLocation RBrace;
9348
9349 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9350 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9351 LBrace = SourceLocation::getFromRawEncoding(
9352 NameLoc.CXXOperatorName.BeginOpNameLoc);
9353 RBrace = SourceLocation::getFromRawEncoding(
9354 NameLoc.CXXOperatorName.EndOpNameLoc);
9355 } else {
9356 LBrace = Callee->getLocStart();
9357 RBrace = OpLoc;
9358 }
9359
9360 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9361 First, Second);
9362 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009363
Douglas Gregorb98b1992009-08-11 05:31:07 +00009364 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009365 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009366 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009367 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9368 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}
Mike Stump1eb44332009-09-09 15:08:12 +00009373
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009374template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00009375ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009376TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009377 SourceLocation OperatorLoc,
9378 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009379 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009380 TypeSourceInfo *ScopeType,
9381 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009382 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009383 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009384 QualType BaseType = Base->getType();
9385 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009386 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00009387 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009388 !BaseType->getAs<PointerType>()->getPointeeType()
9389 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009390 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009391 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009392 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009393 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009394 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009395 /*FIXME?*/true);
9396 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009397
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009398 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009399 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9400 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9401 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9402 NameInfo.setNamedTypeInfo(DestroyedType);
9403
Richard Smith6314db92012-05-15 06:15:11 +00009404 // The scope type is now known to be a valid nested name specifier
9405 // component. Tack it on to the end of the nested name specifier.
9406 if (ScopeType)
9407 SS.Extend(SemaRef.Context, SourceLocation(),
9408 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnara25777432010-08-11 22:01:17 +00009409
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009410 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009411 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009412 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009413 SS, TemplateKWLoc,
9414 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009415 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009416 /*TemplateArgs*/ 0);
9417}
9418
Tareq A. Siraj051303c2013-04-16 18:53:08 +00009419template<typename Derived>
9420StmtResult
9421TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
9422 llvm_unreachable("not implement yet");
9423}
9424
Douglas Gregor577f75a2009-08-04 16:50:30 +00009425} // end namespace clang
9426
9427#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H